Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Convert to UNIX line endings like the rest of the source is

  • Loading branch information...
commit 6df03e8330321cbe3cfb02499bb55f29f1265d4f 1 parent 965ed56
@CapnBry authored
View
166 avrlibdefs.h
@@ -1,83 +1,83 @@
-/*! \file avrlibdefs.h \brief AVRlib global defines and macros. */
-//*****************************************************************************
-//
-// File Name : 'avrlibdefs.h'
-// Title : AVRlib global defines and macros include file
-// Author : Pascal Stang
-// Created : 7/12/2001
-// Revised : 9/30/2002
-// Version : 1.1
-// Target MCU : Atmel AVR series
-// Editor Tabs : 4
-//
-// Description : This include file is designed to contain items useful to all
-// code files and projects, regardless of specific implementation.
-//
-// This code is distributed under the GNU Public License
-// which can be found at http://www.gnu.org/licenses/gpl.txt
-//
-//*****************************************************************************
-
-
-#ifndef AVRLIBDEFS_H
-#define AVRLIBDEFS_H
-
-// Code compatibility to new AVR-libc
-// outb(), inb(), inw(), outw(), BV(), sbi(), cbi(), sei(), cli()
-#ifndef outb
- #define outb(addr, data) addr = (data)
-#endif
-#ifndef inb
- #define inb(addr) (addr)
-#endif
-#ifndef outw
- #define outw(addr, data) addr = (data)
-#endif
-#ifndef inw
- #define inw(addr) (addr)
-#endif
-#ifndef BV
- #define BV(bit) (1<<(bit))
-#endif
-#ifndef cbi
- #define cbi(reg,bit) reg &= ~(BV(bit))
-#endif
-#ifndef sbi
- #define sbi(reg,bit) reg |= (BV(bit))
-#endif
-#ifndef cli
- #define cli() __asm__ __volatile__ ("cli" ::)
-#endif
-#ifndef sei
- #define sei() __asm__ __volatile__ ("sei" ::)
-#endif
-
-// support for individual port pin naming in the mega128
-// see port128.h for details
-#ifdef __AVR_ATmega128__
-// not currently necessary due to inclusion
-// of these defines in newest AVR-GCC
-// do a quick test to see if include is needed
-#ifndef PD0
- #include "port128.h"
-#endif
-#endif
-
-// use this for packed structures
-// (this is seldom necessary on an 8-bit architecture like AVR,
-// but can assist in code portability to AVR)
-#define GNUC_PACKED __attribute__((packed))
-
-// port address helpers
-#define DDR(x) ((x)-1) // address of data direction register of port x
-#define PIN(x) ((x)-2) // address of input register of port x
-
-// MIN/MAX/ABS macros
-#define MIN(a,b) ((a<b)?(a):(b))
-#define MAX(a,b) ((a>b)?(a):(b))
-#define ABS(x) ((x>0)?(x):(-x))
-
-// constants
-#define PI 3.14159265359
-
-#endif
+/*! \file avrlibdefs.h \brief AVRlib global defines and macros. */
+//*****************************************************************************
+//
+// File Name : 'avrlibdefs.h'
+// Title : AVRlib global defines and macros include file
+// Author : Pascal Stang
+// Created : 7/12/2001
+// Revised : 9/30/2002
+// Version : 1.1
+// Target MCU : Atmel AVR series
+// Editor Tabs : 4
+//
+// Description : This include file is designed to contain items useful to all
+// code files and projects, regardless of specific implementation.
+//
+// This code is distributed under the GNU Public License
+// which can be found at http://www.gnu.org/licenses/gpl.txt
+//
+//*****************************************************************************
+
+
+#ifndef AVRLIBDEFS_H
+#define AVRLIBDEFS_H
+
+// Code compatibility to new AVR-libc
+// outb(), inb(), inw(), outw(), BV(), sbi(), cbi(), sei(), cli()
+#ifndef outb
+ #define outb(addr, data) addr = (data)
+#endif
+#ifndef inb
+ #define inb(addr) (addr)
+#endif
+#ifndef outw
+ #define outw(addr, data) addr = (data)
+#endif
+#ifndef inw
+ #define inw(addr) (addr)
+#endif
+#ifndef BV
+ #define BV(bit) (1<<(bit))
+#endif
+#ifndef cbi
+ #define cbi(reg,bit) reg &= ~(BV(bit))
+#endif
+#ifndef sbi
+ #define sbi(reg,bit) reg |= (BV(bit))
+#endif
+#ifndef cli
+ #define cli() __asm__ __volatile__ ("cli" ::)
+#endif
+#ifndef sei
+ #define sei() __asm__ __volatile__ ("sei" ::)
+#endif
+
+// support for individual port pin naming in the mega128
+// see port128.h for details
+#ifdef __AVR_ATmega128__
+// not currently necessary due to inclusion
+// of these defines in newest AVR-GCC
+// do a quick test to see if include is needed
+#ifndef PD0
+ #include "port128.h"
+#endif
+#endif
+
+// use this for packed structures
+// (this is seldom necessary on an 8-bit architecture like AVR,
+// but can assist in code portability to AVR)
+#define GNUC_PACKED __attribute__((packed))
+
+// port address helpers
+#define DDR(x) ((x)-1) // address of data direction register of port x
+#define PIN(x) ((x)-2) // address of input register of port x
+
+// MIN/MAX/ABS macros
+#define MIN(a,b) ((a<b)?(a):(b))
+#define MAX(a,b) ((a>b)?(a):(b))
+#define ABS(x) ((x>0)?(x):(-x))
+
+// constants
+#define PI 3.14159265359
+
+#endif
View
168 avrlibtypes.h
@@ -1,84 +1,84 @@
-/*! \file avrlibtypes.h \brief AVRlib global types and typedefines. */
-//*****************************************************************************
-//
-// File Name : 'avrlibtypes.h'
-// Title : AVRlib global types and typedefines include file
-// Author : Pascal Stang
-// Created : 7/12/2001
-// Revised : 9/30/2002
-// Version : 1.0
-// Target MCU : Atmel AVR series
-// Editor Tabs : 4
-//
-// Description : Type-defines required and used by AVRlib. Most types are also
-// generally useful.
-//
-// This code is distributed under the GNU Public License
-// which can be found at http://www.gnu.org/licenses/gpl.txt
-//
-//*****************************************************************************
-
-
-#ifndef AVRLIBTYPES_H
-#define AVRLIBTYPES_H
-
-#ifndef WIN32
- // true/false defines
- #define FALSE 0
- #define TRUE -1
-#endif
-
-// datatype definitions macros
-typedef unsigned char u08;
-typedef signed char s08;
-typedef unsigned short u16;
-typedef signed short s16;
-typedef unsigned long u32;
-typedef signed long s32;
-typedef unsigned long long u64;
-typedef signed long long s64;
-
-/* use inttypes.h instead
-// C99 standard integer type definitions
-typedef unsigned char uint8_t;
-typedef signed char int8_t;
-typedef unsigned short uint16_t;
-typedef signed short int16_t;
-typedef unsigned long uint32_t;
-typedef signed long int32_t;
-typedef unsigned long uint64_t;
-typedef signed long int64_t;
-*/
-// maximum value that can be held
-// by unsigned data types (8,16,32bits)
-#define MAX_U08 255
-#define MAX_U16 65535
-#define MAX_U32 4294967295
-
-// maximum values that can be held
-// by signed data types (8,16,32bits)
-#define MIN_S08 -128
-#define MAX_S08 127
-#define MIN_S16 -32768
-#define MAX_S16 32767
-#define MIN_S32 -2147483648
-#define MAX_S32 2147483647
-
-#ifndef WIN32
- // more type redefinitions
- typedef unsigned char BOOL;
- typedef unsigned char BYTE;
- typedef unsigned int WORD;
- typedef unsigned long DWORD;
-
- typedef unsigned char UCHAR;
- typedef unsigned int UINT;
- typedef unsigned short USHORT;
- typedef unsigned long ULONG;
-
- typedef char CHAR;
- typedef int INT;
- typedef long LONG;
-#endif
-
-#endif
+/*! \file avrlibtypes.h \brief AVRlib global types and typedefines. */
+//*****************************************************************************
+//
+// File Name : 'avrlibtypes.h'
+// Title : AVRlib global types and typedefines include file
+// Author : Pascal Stang
+// Created : 7/12/2001
+// Revised : 9/30/2002
+// Version : 1.0
+// Target MCU : Atmel AVR series
+// Editor Tabs : 4
+//
+// Description : Type-defines required and used by AVRlib. Most types are also
+// generally useful.
+//
+// This code is distributed under the GNU Public License
+// which can be found at http://www.gnu.org/licenses/gpl.txt
+//
+//*****************************************************************************
+
+
+#ifndef AVRLIBTYPES_H
+#define AVRLIBTYPES_H
+
+#ifndef WIN32
+ // true/false defines
+ #define FALSE 0
+ #define TRUE -1
+#endif
+
+// datatype definitions macros
+typedef unsigned char u08;
+typedef signed char s08;
+typedef unsigned short u16;
+typedef signed short s16;
+typedef unsigned long u32;
+typedef signed long s32;
+typedef unsigned long long u64;
+typedef signed long long s64;
+
+/* use inttypes.h instead
+// C99 standard integer type definitions
+typedef unsigned char uint8_t;
+typedef signed char int8_t;
+typedef unsigned short uint16_t;
+typedef signed short int16_t;
+typedef unsigned long uint32_t;
+typedef signed long int32_t;
+typedef unsigned long uint64_t;
+typedef signed long int64_t;
+*/
+// maximum value that can be held
+// by unsigned data types (8,16,32bits)
+#define MAX_U08 255
+#define MAX_U16 65535
+#define MAX_U32 4294967295
+
+// maximum values that can be held
+// by signed data types (8,16,32bits)
+#define MIN_S08 -128
+#define MAX_S08 127
+#define MIN_S16 -32768
+#define MAX_S16 32767
+#define MIN_S32 -2147483648
+#define MAX_S32 2147483647
+
+#ifndef WIN32
+ // more type redefinitions
+ typedef unsigned char BOOL;
+ typedef unsigned char BYTE;
+ typedef unsigned int WORD;
+ typedef unsigned long DWORD;
+
+ typedef unsigned char UCHAR;
+ typedef unsigned int UINT;
+ typedef unsigned short USHORT;
+ typedef unsigned long ULONG;
+
+ typedef char CHAR;
+ typedef int INT;
+ typedef long LONG;
+#endif
+
+#endif
View
120 config.h
@@ -1,60 +1,60 @@
-
-/******************************************************************************
-
- Filename: config.h
- Description: Wireless configuration parameters for the WiShield 1.0
-
- ******************************************************************************
-
- TCP/IP stack and driver for the WiShield 1.0 wireless devices
-
- Copyright(c) 2009 Async Labs Inc. All rights reserved.
-
- This program is free software; you can redistribute it and/or modify it
- under the terms of version 2 of the GNU General Public License as
- published by the Free Software Foundation.
-
- This program is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- more details.
-
- You should have received a copy of the GNU General Public License along with
- this program; if not, write to the Free Software Foundation, Inc., 59
- Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
- Contact Information:
- <asynclabs@asynclabs.com>
-
- Author Date Comment
- ---------------------------------------------------------------
- AsyncLabs 05/01/2009 Initial version
- AsyncLabs 05/29/2009 Adding support for new library
-
- *****************************************************************************/
-
-#ifndef CONFIG_H_
-#define CONFIG_H_
-
-#include "witypes.h"
-
-extern U8 local_ip[];
-extern U8 gateway_ip[];
-extern U8 subnet_mask[];
-extern char ssid[];
-extern U8 ssid_len;
-extern const prog_char security_passphrase[];
-extern U8 security_passphrase_len;
-extern U8 security_type;
-extern U8 wireless_mode;
-
-extern prog_uchar wep_keys[];
-
-extern const prog_char webpage[];
-extern const prog_char twitter[];
-extern unsigned char mfg_id[4];
-
-#define WIRELESS_MODE_INFRA 1
-#define WIRELESS_MODE_ADHOC 2
-
-#endif /* CONFIG_H_ */
+
+/******************************************************************************
+
+ Filename: config.h
+ Description: Wireless configuration parameters for the WiShield 1.0
+
+ ******************************************************************************
+
+ TCP/IP stack and driver for the WiShield 1.0 wireless devices
+
+ Copyright(c) 2009 Async Labs Inc. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program; if not, write to the Free Software Foundation, Inc., 59
+ Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Contact Information:
+ <asynclabs@asynclabs.com>
+
+ Author Date Comment
+ ---------------------------------------------------------------
+ AsyncLabs 05/01/2009 Initial version
+ AsyncLabs 05/29/2009 Adding support for new library
+
+ *****************************************************************************/
+
+#ifndef CONFIG_H_
+#define CONFIG_H_
+
+#include "witypes.h"
+
+extern U8 local_ip[];
+extern U8 gateway_ip[];
+extern U8 subnet_mask[];
+extern char ssid[];
+extern U8 ssid_len;
+extern const prog_char security_passphrase[];
+extern U8 security_passphrase_len;
+extern U8 security_type;
+extern U8 wireless_mode;
+
+extern prog_uchar wep_keys[];
+
+extern const prog_char webpage[];
+extern const prog_char twitter[];
+extern unsigned char mfg_id[4];
+
+#define WIRELESS_MODE_INFRA 1
+#define WIRELESS_MODE_ADHOC 2
+
+#endif /* CONFIG_H_ */
View
1,424 g2100.c
@@ -1,715 +1,715 @@
-
-/*****************************************************************************
-
- Filename: g2100.c
- Description: Driver for the ZeroG Wireless G2100 series devices
-
+
+/*****************************************************************************
+
+ Filename: g2100.c
+ Description: Driver for the ZeroG Wireless G2100 series devices
+
*****************************************************************************
-
- Driver for the WiShield 1.0 wireless devices
-
- Copyright(c) 2009 Async Labs Inc. All rights reserved.
-
- This program is free software; you can redistribute it and/or modify it
- under the terms of version 2 of the GNU General Public License as
- published by the Free Software Foundation.
-
- This program is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- more details.
-
- You should have received a copy of the GNU General Public License along with
- this program; if not, write to the Free Software Foundation, Inc., 59
- Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
- Contact Information:
+
+ Driver for the WiShield 1.0 wireless devices
+
+ Copyright(c) 2009 Async Labs Inc. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program; if not, write to the Free Software Foundation, Inc., 59
+ Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Contact Information:
<asynclabs@asynclabs.com>
-
- Author Date Comment
- ----------------------------------------------------------------------------
- AsyncLabs 02/25/2009 Initial port
+
+ Author Date Comment
+ ----------------------------------------------------------------------------
+ AsyncLabs 02/25/2009 Initial port
AsyncLabs 05/29/2009 Adding support for new library
-
- *****************************************************************************/
-
-#include <string.h>
-#include "witypes.h"
-#include "config.h"
-#include "global-conf.h"
-#include "g2100.h"
-#include "spi.h"
-
-static U8 mac[6];
-static U8 zg_conn_status;
-
-static U8 hdr[5];
-static U8 intr_occured;
-static U8 intr_valid;
-static U8 zg_drv_state;
-static U8 tx_ready;
-static U8 rx_ready;
-static U8 cnf_pending;
-static U8* zg_buf;
-static U16 zg_buf_len;
-static U16 lastRssi;
-static U8 scan_cnt;
-static U8 wpa_psk_key[32];
-
-void zg_init()
-{
- U8 clr;
-
- ZG2100_SpiInit();
- clr = SPSR;
- clr = SPDR;
-
- intr_occured = 0;
- intr_valid = 0;
- lastRssi = 0;
- zg_drv_state = DRV_STATE_INIT;
- zg_conn_status = 0;
- tx_ready = 0;
- rx_ready = 0;
- cnf_pending = 0;
- zg_buf = uip_buf;
- zg_buf_len = UIP_BUFSIZE;
-
- zg_chip_reset();
- zg_interrupt2_reg();
- zg_interrupt_reg(0xff, 0);
- zg_interrupt_reg(0x80|0x40, 1);
-
- ssid_len = (U8)strlen(ssid);
- security_passphrase_len = (U8)strlen_P(security_passphrase);
-}
-
-void spi_transfer(volatile U8* buf, U16 len, U8 toggle_cs)
-{
- U16 i;
-
- ZG2100_CSoff();
-
- for (i = 0; i < len; i++) {
- ZG2100_SpiSendData(buf[i]); // Start the transmission
- buf[i] = ZG2100_SpiRecvData();
- }
-
- if (toggle_cs)
- ZG2100_CSon();
-
- return;
-}
-
-void zg_chip_reset()
-{
- U8 loop_cnt = 0;
-
- do {
- // write reset register addr
- hdr[0] = ZG_INDEX_ADDR_REG;
- hdr[1] = 0x00;
- hdr[2] = ZG_RESET_REG;
- spi_transfer(hdr, 3, 1);
-
- hdr[0] = ZG_INDEX_DATA_REG;
- hdr[1] = (loop_cnt == 0)?(0x80):(0x0f);
- hdr[2] = 0xff;
- spi_transfer(hdr, 3, 1);
- } while(loop_cnt++ < 1);
-
- // write reset register data
- hdr[0] = ZG_INDEX_ADDR_REG;
- hdr[1] = 0x00;
- hdr[2] = ZG_RESET_STATUS_REG;
- spi_transfer(hdr, 3, 1);
-
- do {
- hdr[0] = 0x40 | ZG_INDEX_DATA_REG;
- hdr[1] = 0x00;
- hdr[2] = 0x00;
- spi_transfer(hdr, 3, 1);
- } while((hdr[1] & ZG_RESET_MASK) == 0);
-
- do {
- hdr[0] = 0x40 | ZG_BYTE_COUNT_REG;
- hdr[1] = 0x00;
- hdr[2] = 0x00;
- spi_transfer(hdr, 3, 1);
- } while((hdr[1] == 0) && (hdr[2] == 0));
-}
-
-void zg_interrupt2_reg()
-{
- // read the interrupt2 mask register
- hdr[0] = 0x40 | ZG_INTR2_MASK_REG;
- hdr[1] = 0x00;
- hdr[2] = 0x00;
- spi_transfer(hdr, 3, 1);
-
- // modify the interrupt mask value and re-write the value to the interrupt
- // mask register clearing the interrupt register first
- hdr[0] = ZG_INTR2_REG;
- hdr[1] = 0xff;
- hdr[2] = 0xff;
- hdr[3] = 0;
- hdr[4] = 0;
- spi_transfer(hdr, 5, 1);
-
- return;
-}
-
-void zg_interrupt_reg(U8 mask, U8 state)
-{
- // read the interrupt register
- hdr[0] = 0x40 | ZG_INTR_MASK_REG;
- hdr[1] = 0x00;
- spi_transfer(hdr, 2, 1);
-
- // now regBuf[0] contains the current setting for the
- // interrupt mask register
- // this is to clear any currently set interrupts of interest
- hdr[0] = ZG_INTR_REG;
- hdr[2] = (hdr[1] & ~mask) | ( (state == 0)? 0 : mask );
- hdr[1] = mask;
- spi_transfer(hdr, 3, 1);
-
- return;
-}
-
-void zg_isr()
-{
- ZG2100_ISR_DISABLE();
- intr_occured = 1;
-}
-
-void zg_process_isr()
-{
- U8 intr_state = 0;
- U8 next_cmd = 0;
-
- hdr[0] = 0x40 | ZG_INTR_REG;
- hdr[1] = 0x00;
- hdr[2] = 0x00;
- spi_transfer(hdr, 3, 1);
-
- intr_state = ZG_INTR_ST_RD_INTR_REG;
-
- do {
- switch(intr_state) {
- case ZG_INTR_ST_RD_INTR_REG:
- {
- U8 intr_val = hdr[1] & hdr[2];
-
- if ( (intr_val & ZG_INTR_MASK_FIFO1) == ZG_INTR_MASK_FIFO1) {
- hdr[0] = ZG_INTR_REG;
- hdr[1] = ZG_INTR_MASK_FIFO1;
- spi_transfer(hdr, 2, 1);
-
- intr_state = ZG_INTR_ST_WT_INTR_REG;
- next_cmd = ZG_BYTE_COUNT_FIFO1_REG;
- }
- else if ( (intr_val & ZG_INTR_MASK_FIFO0) == ZG_INTR_MASK_FIFO0) {
- hdr[0] = ZG_INTR_REG;
- hdr[1] = ZG_INTR_MASK_FIFO0;
- spi_transfer(hdr, 2, 1);
-
- intr_state = ZG_INTR_ST_WT_INTR_REG;
- next_cmd = ZG_BYTE_COUNT_FIFO0_REG;
- }
- else if (intr_val) {
- intr_state = 0;
- }
- else {
- intr_state = 0;
- }
-
- break;
- }
- case ZG_INTR_ST_WT_INTR_REG:
- {
- hdr[0] = 0x40 | next_cmd;
- hdr[1] = 0x00;
- hdr[2] = 0x00;
- spi_transfer(hdr, 3, 1);
-
- intr_state = ZG_INTR_ST_RD_CTRL_REG;
- break;
- }
- // *************************************************************************************
- // Released version of WiShield library code (ZG_INTR_ST_RD_CTRL_REG)
- // susceptible to "packet too large issue" but allows
- // WiServer/WebServer to work. Needs to be replaced with
- // good fix.
- case ZG_INTR_ST_RD_CTRL_REG:
- {
- U16 rx_byte_cnt = (0x0000 | (hdr[1] << 8) | hdr[2]) & 0x0fff;
-
- zg_buf[0] = ZG_CMD_RD_FIFO;
- spi_transfer(zg_buf, rx_byte_cnt + 1, 1);
-
- hdr[0] = ZG_CMD_RD_FIFO_DONE;
- spi_transfer(hdr, 1, 1);
-
- intr_valid = 1;
-
- intr_state = 0;
- break;
- }
- // Bad "packet too large" fix - killed WiServer WebServer
- /*
- case ZG_INTR_ST_RD_CTRL_REG:
- {
- // Get the size of the incoming packet
- U16 rx_byte_cnt = (0x0000 | (hdr[1] << 8) | hdr[2]) & 0x0fff;
-
- // Check if our buffer is large enough for packet
- if(rx_byte_cnt + 1 < (U16)UIP_BUFSIZE ) {
- zg_buf[0] = ZG_CMD_RD_FIFO;
- // Copy ZG2100 buffer contents into zg_buf (uip_buf)
- spi_transfer(zg_buf, rx_byte_cnt + 1, 1);
- // interrupt from zg2100 was meaningful and requires further processing
- intr_valid = 1;
- }
- else {
- // Too Big, ignore it and continue
- intr_valid = 0;
- }
-
- // Tell ZG2100 we're done reading from its buffer
- hdr[0] = ZG_CMD_RD_FIFO_DONE;
- spi_transfer(hdr, 1, 1);
-
- // Done reading interrupt from ZG2100
- intr_state = 0;
- break;
- }
- */
- // *************************************************************************************
- }
- } while (intr_state);
-#ifdef USE_DIG8_INTR
- // PCINT0 supports only edge triggered INT
- if (PORTB & 0x01) {
- intr_occured = 0;
- ZG2100_ISR_ENABLE();
- }
- else {
- intr_occured = 1;
- }
-#else
- intr_occured = 0;
- ZG2100_ISR_ENABLE();
-#endif
-}
-
-void zg_send(U8* buf, U16 len)
-{
- hdr[0] = ZG_CMD_WT_FIFO_DATA;
- hdr[1] = ZG_MAC_TYPE_TXDATA_REQ;
- hdr[2] = ZG_MAC_SUBTYPE_TXDATA_REQ_STD;
- hdr[3] = 0x00;
- hdr[4] = 0x00;
- spi_transfer(hdr, 5, 0);
-
- buf[6] = 0xaa;
- buf[7] = 0xaa;
- buf[8] = 0x03;
- buf[9] = buf[10] = buf[11] = 0x00;
- spi_transfer(buf, len, 1);
-
- hdr[0] = ZG_CMD_WT_FIFO_DONE;
- spi_transfer(hdr, 1, 1);
-}
-
-void zg_recv(U8* buf, U16* len)
-{
- zg_rx_data_ind_t* ptr = (zg_rx_data_ind_t*)&(zg_buf[3]);
- *len = ZGSTOHS( ptr->dataLen );
- lastRssi = ZGSTOHS( ptr->rssi );
-
- memcpy(&zg_buf[0], &zg_buf[5], 6);
- memcpy(&zg_buf[6], &zg_buf[11], 6);
- memcpy(&zg_buf[12], &zg_buf[29], *len);
-
- *len += 12;
-}
-
-U16 zg_get_rx_status()
-{
- if (rx_ready) {
- rx_ready = 0;
- return zg_buf_len;
- }
- else {
- return 0;
- }
-}
-
-void zg_clear_rx_status()
-{
- rx_ready = 0;
-}
-
-void zg_set_tx_status(U8 status)
-{
- tx_ready = status;
-}
-
-U8 zg_get_conn_state()
-{
- return zg_conn_status;
-}
-
-void zg_set_buf(U8* buf, U16 buf_len)
-{
- zg_buf = buf;
- zg_buf_len = buf_len;
-}
-
-U8* zg_get_mac()
-{
- return mac;
-}
-
-void zg_write_wep_key(U8* cmd_buf)
-{
- zg_wep_key_req_t* cmd = (zg_wep_key_req_t*)cmd_buf;
-
- cmd->slot = 3; // WEP key slot
- cmd->keyLen = UIP_WEP_KEY_LEN; // Key length: 5 bytes (64-bit WEP); 13 bytes (128-bit WEP)
- cmd->defID = UIP_WEP_KEY_DEFAULT; // Default key ID: Key 0, 1, 2, 3
- cmd->ssidLen = ssid_len;
- memset(cmd->ssid, 0x00, 32);
- memcpy(cmd->ssid, ssid, ssid_len);
- memcpy_P(cmd->key, wep_keys, ZG_MAX_ENCRYPTION_KEYS * ZG_MAX_ENCRYPTION_KEY_SIZE);
-
- return;
-}
-
-static void zg_calc_psk_key(U8* cmd_buf)
-{
- zg_psk_calc_req_t* cmd = (zg_psk_calc_req_t*)cmd_buf;
-
- cmd->configBits = 0;
- cmd->phraseLen = security_passphrase_len;
- cmd->ssidLen = ssid_len;
- cmd->reserved = 0;
- memset(cmd->ssid, 0x00, 32);
- memcpy(cmd->ssid, ssid, ssid_len);
- memset(cmd->passPhrase, 0x00, 64);
- memcpy_P(cmd->passPhrase, security_passphrase, security_passphrase_len);
-
- return;
-}
-
-static void zg_write_psk_key(U8* cmd_buf)
-{
- zg_pmk_key_req_t* cmd = (zg_pmk_key_req_t*)cmd_buf;
-
- cmd->slot = 0; // WPA/WPA2 PSK slot
- cmd->ssidLen = ssid_len;
- memset(cmd->ssid, 0x00, 32);
- memcpy(cmd->ssid, ssid, cmd->ssidLen);
- memcpy(cmd->keyData, wpa_psk_key, ZG_MAX_PMK_LEN);
-
- return;
-}
-
-U16 zg_get_rssi(){
- return lastRssi;
-}
-
-// =================================================================================================
-#ifdef UIP_SCAN
-
-tZGScanResult* zg_scan_results(void)
-{
- return &uip_buf[3];
-}
-
-tZGBssDesc* zg_scan_desc(U8 item)
-{
- return &uip_buf[7 + (item * sizeof(tZGBssDesc))];
-}
-
-U16 get_scan_cnt(){
- return scan_cnt;
-}
-
-void zg_scan_start()
-{
- scan_cnt = 0;
- tZGScanReq* ptr = (tZGScanReq*)&zg_buf[3];
-
- zg_buf[0] = ZG_CMD_WT_FIFO_MGMT;
- zg_buf[1] = ZG_MAC_TYPE_MGMT_REQ;
- zg_buf[2] = ZG_MAC_SUBTYPE_MGMT_SCAN;
-
- // Number of usec to delay before transmitting a probe
- // request following the channel change event
- ptr->probeDelay = ( U16 ) HSTOZGS( ( U16 ) 20);
- // the minimum time to spend on each channel in units
- // of TU (1024 usec)
- ptr->minChannelTime = ( U16 ) HSTOZGS(( U16 ) 400);
- // Maximum time to spend on each channel in units
- // of TU (1024 usec)
- ptr->maxChannelTime = ( U16 ) HSTOZGS( ( U16 ) 800);
- // Bssid to restrict the scan too. Or ff:ff:ff:ff:ff:ff
- // to not restrict the scan by bssid
- ptr->bssid[0] = 0xFF;
- ptr->bssid[1] = 0xFF;
- ptr->bssid[2] = 0xFF;
- ptr->bssid[3] = 0xFF;
- ptr->bssid[4] = 0xFF;
- ptr->bssid[5] = 0xFF;
- // Type of networks to be scanned. 1==Infrastructure, 2==Ad-hoc, 3==Any
- ptr->bss = 3;
- // Scan Type. 1==Active (probe requests), 2==Passive (just listens)
- ptr->snType = 1;
- // set ssid length to 0 to do discovery scan
- ptr->ssidLen = 0;
- // State based scan only scans a single channel at a time
- ptr->chnlLen = 11;
- // Zero-terminated list of channels to scan
- //ptr->channelList[0] = 3;
- //ptr->channelList[1] = 6;
- //ptr->channelList[2] = 11;
- //ptr->channelList[3] = 0;
- U8 b;
- for ( b=0; b<11; b++ ){
- ptr->channelList[b] = b+1;
- }
- ptr->channelList[13] = 0;
- // Actually send command to zg2100 over SPI
- spi_transfer( zg_buf, 65, 1 );
-
- zg_buf[0] = ZG_CMD_WT_FIFO_DONE;
- spi_transfer(zg_buf, 1, 1);
-
- //zg_drv_state = DRV_STATE_IDLE;
-}
-
-#endif // UIP_SCAN
-// =================================================================================================
-
-void zg_drv_process()
-{
- // TX frame
- if (tx_ready && !cnf_pending) {
- zg_send(zg_buf, zg_buf_len);
- tx_ready = 0;
- cnf_pending = 1;
- }
-
- // process interrupt
- if (intr_occured) {
- zg_process_isr();
- }
-
- if (intr_valid) {
- switch (zg_buf[1]) {
- case ZG_MAC_TYPE_TXDATA_CONFIRM:
- cnf_pending = 0;
- break;
- case ZG_MAC_TYPE_MGMT_CONFIRM:
- if (zg_buf[3] == ZG_RESULT_SUCCESS) {
- switch (zg_buf[2]) {
- case ZG_MAC_SUBTYPE_MGMT_SCAN:
- scan_cnt = 1;
- break;
- case ZG_MAC_SUBTYPE_MGMT_REQ_GET_PARAM:
- mac[0] = zg_buf[7];
- mac[1] = zg_buf[8];
- mac[2] = zg_buf[9];
- mac[3] = zg_buf[10];
- mac[4] = zg_buf[11];
- mac[5] = zg_buf[12];
- zg_drv_state = DRV_STATE_SETUP_SECURITY;
- break;
- case ZG_MAC_SUBTYPE_MGMT_REQ_WEP_KEY:
- zg_drv_state = DRV_STATE_ENABLE_CONN_MANAGE;
- break;
- case ZG_MAC_SUBTYPE_MGMT_REQ_CALC_PSK:
- memcpy(wpa_psk_key, ((zg_psk_calc_cnf_t*)&zg_buf[3])->psk, 32);
- zg_drv_state = DRV_STATE_INSTALL_PSK;
- break;
- case ZG_MAC_SUBTYPE_MGMT_REQ_PMK_KEY:
- zg_drv_state = DRV_STATE_ENABLE_CONN_MANAGE;
- break;
- case ZG_MAC_SUBTYPE_MGMT_REQ_CONNECT_MANAGE:
- zg_drv_state = DRV_STATE_START_CONN;
- break;
- case ZG_MAC_SUBTYPE_MGMT_REQ_CONNECT:
- LEDConn_on();
- zg_conn_status = 1; // connected
- break;
- default:
- break;
- }
- }
- break;
- case ZG_MAC_TYPE_RXDATA_INDICATE:
- zg_drv_state = DRV_STATE_PROCESS_RX;
- break;
- case ZG_MAC_TYPE_MGMT_INDICATE:
- switch (zg_buf[2]) {
- case ZG_MAC_SUBTYPE_MGMT_IND_DISASSOC:
- case ZG_MAC_SUBTYPE_MGMT_IND_DEAUTH:
- LEDConn_off();
- zg_conn_status = 0; // lost connection
-
- //try to reconnect
- zg_drv_state = DRV_STATE_START_CONN;
- break;
- case ZG_MAC_SUBTYPE_MGMT_IND_CONN_STATUS:
- {
- U16 status = (((U16)(zg_buf[3]))<<8)|zg_buf[4];
-
- if (status == 1 || status == 5) {
- LEDConn_off();
- zg_conn_status = 0; // not connected
- }
- else if (status == 2 || status == 6) {
- LEDConn_on();
- zg_conn_status = 1; // connected
- }
- }
- break;
- }
- break;
- }
-
- intr_valid = 0;
- }
-
- switch (zg_drv_state) {
- case DRV_STATE_INIT:
- zg_drv_state = DRV_STATE_GET_MAC;
- break;
- case DRV_STATE_GET_MAC:
- // get MAC address
- zg_buf[0] = ZG_CMD_WT_FIFO_MGMT;
- zg_buf[1] = ZG_MAC_TYPE_MGMT_REQ;
- zg_buf[2] = ZG_MAC_SUBTYPE_MGMT_REQ_GET_PARAM;
- zg_buf[3] = 0;
- zg_buf[4] = ZG_PARAM_MAC_ADDRESS;
- spi_transfer(zg_buf, 5, 1);
-
- zg_buf[0] = ZG_CMD_WT_FIFO_DONE;
- spi_transfer(zg_buf, 1, 1);
-
- zg_drv_state = DRV_STATE_IDLE;
- break;
- case DRV_STATE_SETUP_SECURITY:
- switch (security_type) {
- case ZG_SECURITY_TYPE_NONE:
- zg_drv_state = DRV_STATE_ENABLE_CONN_MANAGE;
- break;
- case ZG_SECURITY_TYPE_WEP:
- // Install all four WEP keys on G2100
- zg_buf[0] = ZG_CMD_WT_FIFO_MGMT;
- zg_buf[1] = ZG_MAC_TYPE_MGMT_REQ;
- zg_buf[2] = ZG_MAC_SUBTYPE_MGMT_REQ_WEP_KEY;
- zg_write_wep_key(&zg_buf[3]);
- spi_transfer(zg_buf, ZG_WEP_KEY_REQ_SIZE+3, 1);
-
- zg_buf[0] = ZG_CMD_WT_FIFO_DONE;
- spi_transfer(zg_buf, 1, 1);
-
- zg_drv_state = DRV_STATE_IDLE;
- break;
- case ZG_SECURITY_TYPE_WPA:
- case ZG_SECURITY_TYPE_WPA2:
- // Initiate PSK calculation on G2100
- zg_buf[0] = ZG_CMD_WT_FIFO_MGMT;
- zg_buf[1] = ZG_MAC_TYPE_MGMT_REQ;
- zg_buf[2] = ZG_MAC_SUBTYPE_MGMT_REQ_CALC_PSK;
- zg_calc_psk_key(&zg_buf[3]);
- spi_transfer(zg_buf, ZG_PSK_CALC_REQ_SIZE+3, 1);
-
- zg_buf[0] = ZG_CMD_WT_FIFO_DONE;
- spi_transfer(zg_buf, 1, 1);
-
- zg_drv_state = DRV_STATE_IDLE;
- break;
- default:
- break;
- }
- break;
- case DRV_STATE_INSTALL_PSK:
- // Install the PSK key on G2100
- zg_buf[0] = ZG_CMD_WT_FIFO_MGMT;
- zg_buf[1] = ZG_MAC_TYPE_MGMT_REQ;
- zg_buf[2] = ZG_MAC_SUBTYPE_MGMT_REQ_PMK_KEY;
- zg_write_psk_key(&zg_buf[3]);
- spi_transfer(zg_buf, ZG_PMK_KEY_REQ_SIZE+3, 1);
-
- zg_buf[0] = ZG_CMD_WT_FIFO_DONE;
- spi_transfer(zg_buf, 1, 1);
-
- zg_drv_state = DRV_STATE_IDLE;
- break;
- case DRV_STATE_ENABLE_CONN_MANAGE:
- // enable connection manager
- zg_buf[0] = ZG_CMD_WT_FIFO_MGMT;
- zg_buf[1] = ZG_MAC_TYPE_MGMT_REQ;
- zg_buf[2] = ZG_MAC_SUBTYPE_MGMT_REQ_CONNECT_MANAGE;
- zg_buf[3] = 0x01; // 0x01 - enable; 0x00 - disable
- zg_buf[4] = 10; // num retries to reconnect
- zg_buf[5] = 0x10 | 0x02 | 0x01; // 0x10 - enable start and stop indication messages
- // from G2100 during reconnection
- // 0x02 - start reconnection on receiving a deauthentication
- // message from the AP
- // 0x01 - start reconnection when the missed beacon count
- // exceeds the threshold. uses default value of
- // 100 missed beacons if not set during initialization
- zg_buf[6] = 0;
- spi_transfer(zg_buf, 7, 1);
-
- zg_buf[0] = ZG_CMD_WT_FIFO_DONE;
- spi_transfer(zg_buf, 1, 1);
-
- zg_drv_state = DRV_STATE_IDLE;
- break;
- case DRV_STATE_START_CONN:
- {
- zg_connect_req_t* cmd = (zg_connect_req_t*)&zg_buf[3];
-
- // start connection to AP
- zg_buf[0] = ZG_CMD_WT_FIFO_MGMT;
- zg_buf[1] = ZG_MAC_TYPE_MGMT_REQ;
- zg_buf[2] = ZG_MAC_SUBTYPE_MGMT_REQ_CONNECT;
-
- cmd->secType = security_type;
-
- cmd->ssidLen = ssid_len;
- memset(cmd->ssid, 0, 32);
- memcpy(cmd->ssid, ssid, ssid_len);
-
- // units of 100 milliseconds
- cmd->sleepDuration = 0;
-
- if (wireless_mode == WIRELESS_MODE_INFRA)
- cmd->modeBss = 1;
- else if (wireless_mode == WIRELESS_MODE_ADHOC)
- cmd->modeBss = 2;
-
- spi_transfer(zg_buf, ZG_CONNECT_REQ_SIZE+3, 1);
-
- zg_buf[0] = ZG_CMD_WT_FIFO_DONE;
- spi_transfer(zg_buf, 1, 1);
-
- zg_drv_state = DRV_STATE_IDLE;
- break;
- }
- case DRV_STATE_PROCESS_RX:
- zg_recv(zg_buf, &zg_buf_len);
- rx_ready = 1;
-
- zg_drv_state = DRV_STATE_IDLE;
- break;
- case DRV_STATE_IDLE:
- break;
- }
-}
+
+ *****************************************************************************/
+
+#include <string.h>
+#include "witypes.h"
+#include "config.h"
+#include "global-conf.h"
+#include "g2100.h"
+#include "spi.h"
+
+static U8 mac[6];
+static U8 zg_conn_status;
+
+static U8 hdr[5];
+static U8 intr_occured;
+static U8 intr_valid;
+static U8 zg_drv_state;
+static U8 tx_ready;
+static U8 rx_ready;
+static U8 cnf_pending;
+static U8* zg_buf;
+static U16 zg_buf_len;
+static U16 lastRssi;
+static U8 scan_cnt;
+static U8 wpa_psk_key[32];
+
+void zg_init()
+{
+ U8 clr;
+
+ ZG2100_SpiInit();
+ clr = SPSR;
+ clr = SPDR;
+
+ intr_occured = 0;
+ intr_valid = 0;
+ lastRssi = 0;
+ zg_drv_state = DRV_STATE_INIT;
+ zg_conn_status = 0;
+ tx_ready = 0;
+ rx_ready = 0;
+ cnf_pending = 0;
+ zg_buf = uip_buf;
+ zg_buf_len = UIP_BUFSIZE;
+
+ zg_chip_reset();
+ zg_interrupt2_reg();
+ zg_interrupt_reg(0xff, 0);
+ zg_interrupt_reg(0x80|0x40, 1);
+
+ ssid_len = (U8)strlen(ssid);
+ security_passphrase_len = (U8)strlen_P(security_passphrase);
+}
+
+void spi_transfer(volatile U8* buf, U16 len, U8 toggle_cs)
+{
+ U16 i;
+
+ ZG2100_CSoff();
+
+ for (i = 0; i < len; i++) {
+ ZG2100_SpiSendData(buf[i]); // Start the transmission
+ buf[i] = ZG2100_SpiRecvData();
+ }
+
+ if (toggle_cs)
+ ZG2100_CSon();
+
+ return;
+}
+
+void zg_chip_reset()
+{
+ U8 loop_cnt = 0;
+
+ do {
+ // write reset register addr
+ hdr[0] = ZG_INDEX_ADDR_REG;
+ hdr[1] = 0x00;
+ hdr[2] = ZG_RESET_REG;
+ spi_transfer(hdr, 3, 1);
+
+ hdr[0] = ZG_INDEX_DATA_REG;
+ hdr[1] = (loop_cnt == 0)?(0x80):(0x0f);
+ hdr[2] = 0xff;
+ spi_transfer(hdr, 3, 1);
+ } while(loop_cnt++ < 1);
+
+ // write reset register data
+ hdr[0] = ZG_INDEX_ADDR_REG;
+ hdr[1] = 0x00;
+ hdr[2] = ZG_RESET_STATUS_REG;
+ spi_transfer(hdr, 3, 1);
+
+ do {
+ hdr[0] = 0x40 | ZG_INDEX_DATA_REG;
+ hdr[1] = 0x00;
+ hdr[2] = 0x00;
+ spi_transfer(hdr, 3, 1);
+ } while((hdr[1] & ZG_RESET_MASK) == 0);
+
+ do {
+ hdr[0] = 0x40 | ZG_BYTE_COUNT_REG;
+ hdr[1] = 0x00;
+ hdr[2] = 0x00;
+ spi_transfer(hdr, 3, 1);
+ } while((hdr[1] == 0) && (hdr[2] == 0));
+}
+
+void zg_interrupt2_reg()
+{
+ // read the interrupt2 mask register
+ hdr[0] = 0x40 | ZG_INTR2_MASK_REG;
+ hdr[1] = 0x00;
+ hdr[2] = 0x00;
+ spi_transfer(hdr, 3, 1);
+
+ // modify the interrupt mask value and re-write the value to the interrupt
+ // mask register clearing the interrupt register first
+ hdr[0] = ZG_INTR2_REG;
+ hdr[1] = 0xff;
+ hdr[2] = 0xff;
+ hdr[3] = 0;
+ hdr[4] = 0;
+ spi_transfer(hdr, 5, 1);
+
+ return;
+}
+
+void zg_interrupt_reg(U8 mask, U8 state)
+{
+ // read the interrupt register
+ hdr[0] = 0x40 | ZG_INTR_MASK_REG;
+ hdr[1] = 0x00;
+ spi_transfer(hdr, 2, 1);
+
+ // now regBuf[0] contains the current setting for the
+ // interrupt mask register
+ // this is to clear any currently set interrupts of interest
+ hdr[0] = ZG_INTR_REG;
+ hdr[2] = (hdr[1] & ~mask) | ( (state == 0)? 0 : mask );
+ hdr[1] = mask;
+ spi_transfer(hdr, 3, 1);
+
+ return;
+}
+
+void zg_isr()
+{
+ ZG2100_ISR_DISABLE();
+ intr_occured = 1;
+}
+
+void zg_process_isr()
+{
+ U8 intr_state = 0;
+ U8 next_cmd = 0;
+
+ hdr[0] = 0x40 | ZG_INTR_REG;
+ hdr[1] = 0x00;
+ hdr[2] = 0x00;
+ spi_transfer(hdr, 3, 1);
+
+ intr_state = ZG_INTR_ST_RD_INTR_REG;
+
+ do {
+ switch(intr_state) {
+ case ZG_INTR_ST_RD_INTR_REG:
+ {
+ U8 intr_val = hdr[1] & hdr[2];
+
+ if ( (intr_val & ZG_INTR_MASK_FIFO1) == ZG_INTR_MASK_FIFO1) {
+ hdr[0] = ZG_INTR_REG;
+ hdr[1] = ZG_INTR_MASK_FIFO1;
+ spi_transfer(hdr, 2, 1);
+
+ intr_state = ZG_INTR_ST_WT_INTR_REG;
+ next_cmd = ZG_BYTE_COUNT_FIFO1_REG;
+ }
+ else if ( (intr_val & ZG_INTR_MASK_FIFO0) == ZG_INTR_MASK_FIFO0) {
+ hdr[0] = ZG_INTR_REG;
+ hdr[1] = ZG_INTR_MASK_FIFO0;
+ spi_transfer(hdr, 2, 1);
+
+ intr_state = ZG_INTR_ST_WT_INTR_REG;
+ next_cmd = ZG_BYTE_COUNT_FIFO0_REG;
+ }
+ else if (intr_val) {
+ intr_state = 0;
+ }
+ else {
+ intr_state = 0;
+ }
+
+ break;
+ }
+ case ZG_INTR_ST_WT_INTR_REG:
+ {
+ hdr[0] = 0x40 | next_cmd;
+ hdr[1] = 0x00;
+ hdr[2] = 0x00;
+ spi_transfer(hdr, 3, 1);
+
+ intr_state = ZG_INTR_ST_RD_CTRL_REG;
+ break;
+ }
+ // *************************************************************************************
+ // Released version of WiShield library code (ZG_INTR_ST_RD_CTRL_REG)
+ // susceptible to "packet too large issue" but allows
+ // WiServer/WebServer to work. Needs to be replaced with
+ // good fix.
+ case ZG_INTR_ST_RD_CTRL_REG:
+ {
+ U16 rx_byte_cnt = (0x0000 | (hdr[1] << 8) | hdr[2]) & 0x0fff;
+
+ zg_buf[0] = ZG_CMD_RD_FIFO;
+ spi_transfer(zg_buf, rx_byte_cnt + 1, 1);
+
+ hdr[0] = ZG_CMD_RD_FIFO_DONE;
+ spi_transfer(hdr, 1, 1);
+
+ intr_valid = 1;
+
+ intr_state = 0;
+ break;
+ }
+ // Bad "packet too large" fix - killed WiServer WebServer
+ /*
+ case ZG_INTR_ST_RD_CTRL_REG:
+ {
+ // Get the size of the incoming packet
+ U16 rx_byte_cnt = (0x0000 | (hdr[1] << 8) | hdr[2]) & 0x0fff;
+
+ // Check if our buffer is large enough for packet
+ if(rx_byte_cnt + 1 < (U16)UIP_BUFSIZE ) {
+ zg_buf[0] = ZG_CMD_RD_FIFO;
+ // Copy ZG2100 buffer contents into zg_buf (uip_buf)
+ spi_transfer(zg_buf, rx_byte_cnt + 1, 1);
+ // interrupt from zg2100 was meaningful and requires further processing
+ intr_valid = 1;
+ }
+ else {
+ // Too Big, ignore it and continue
+ intr_valid = 0;
+ }
+
+ // Tell ZG2100 we're done reading from its buffer
+ hdr[0] = ZG_CMD_RD_FIFO_DONE;
+ spi_transfer(hdr, 1, 1);
+
+ // Done reading interrupt from ZG2100
+ intr_state = 0;
+ break;
+ }
+ */
+ // *************************************************************************************
+ }
+ } while (intr_state);
+#ifdef USE_DIG8_INTR
+ // PCINT0 supports only edge triggered INT
+ if (PORTB & 0x01) {
+ intr_occured = 0;
+ ZG2100_ISR_ENABLE();
+ }
+ else {
+ intr_occured = 1;
+ }
+#else
+ intr_occured = 0;
+ ZG2100_ISR_ENABLE();
+#endif
+}
+
+void zg_send(U8* buf, U16 len)
+{
+ hdr[0] = ZG_CMD_WT_FIFO_DATA;
+ hdr[1] = ZG_MAC_TYPE_TXDATA_REQ;
+ hdr[2] = ZG_MAC_SUBTYPE_TXDATA_REQ_STD;
+ hdr[3] = 0x00;
+ hdr[4] = 0x00;
+ spi_transfer(hdr, 5, 0);
+
+ buf[6] = 0xaa;
+ buf[7] = 0xaa;
+ buf[8] = 0x03;
+ buf[9] = buf[10] = buf[11] = 0x00;
+ spi_transfer(buf, len, 1);
+
+ hdr[0] = ZG_CMD_WT_FIFO_DONE;
+ spi_transfer(hdr, 1, 1);
+}
+
+void zg_recv(U8* buf, U16* len)
+{
+ zg_rx_data_ind_t* ptr = (zg_rx_data_ind_t*)&(zg_buf[3]);
+ *len = ZGSTOHS( ptr->dataLen );
+ lastRssi = ZGSTOHS( ptr->rssi );
+
+ memcpy(&zg_buf[0], &zg_buf[5], 6);
+ memcpy(&zg_buf[6], &zg_buf[11], 6);
+ memcpy(&zg_buf[12], &zg_buf[29], *len);
+
+ *len += 12;
+}
+
+U16 zg_get_rx_status()
+{
+ if (rx_ready) {
+ rx_ready = 0;
+ return zg_buf_len;
+ }
+ else {
+ return 0;
+ }
+}
+
+void zg_clear_rx_status()
+{
+ rx_ready = 0;
+}
+
+void zg_set_tx_status(U8 status)
+{
+ tx_ready = status;
+}
+
+U8 zg_get_conn_state()
+{
+ return zg_conn_status;
+}
+
+void zg_set_buf(U8* buf, U16 buf_len)
+{
+ zg_buf = buf;
+ zg_buf_len = buf_len;
+}
+
+U8* zg_get_mac()
+{
+ return mac;
+}
+
+void zg_write_wep_key(U8* cmd_buf)
+{
+ zg_wep_key_req_t* cmd = (zg_wep_key_req_t*)cmd_buf;
+
+ cmd->slot = 3; // WEP key slot
+ cmd->keyLen = UIP_WEP_KEY_LEN; // Key length: 5 bytes (64-bit WEP); 13 bytes (128-bit WEP)
+ cmd->defID = UIP_WEP_KEY_DEFAULT; // Default key ID: Key 0, 1, 2, 3
+ cmd->ssidLen = ssid_len;
+ memset(cmd->ssid, 0x00, 32);
+ memcpy(cmd->ssid, ssid, ssid_len);
+ memcpy_P(cmd->key, wep_keys, ZG_MAX_ENCRYPTION_KEYS * ZG_MAX_ENCRYPTION_KEY_SIZE);
+
+ return;
+}
+
+static void zg_calc_psk_key(U8* cmd_buf)
+{
+ zg_psk_calc_req_t* cmd = (zg_psk_calc_req_t*)cmd_buf;
+
+ cmd->configBits = 0;
+ cmd->phraseLen = security_passphrase_len;
+ cmd->ssidLen = ssid_len;
+ cmd->reserved = 0;
+ memset(cmd->ssid, 0x00, 32);
+ memcpy(cmd->ssid, ssid, ssid_len);
+ memset(cmd->passPhrase, 0x00, 64);
+ memcpy_P(cmd->passPhrase, security_passphrase, security_passphrase_len);
+
+ return;
+}
+
+static void zg_write_psk_key(U8* cmd_buf)
+{
+ zg_pmk_key_req_t* cmd = (zg_pmk_key_req_t*)cmd_buf;
+
+ cmd->slot = 0; // WPA/WPA2 PSK slot
+ cmd->ssidLen = ssid_len;
+ memset(cmd->ssid, 0x00, 32);
+ memcpy(cmd->ssid, ssid, cmd->ssidLen);
+ memcpy(cmd->keyData, wpa_psk_key, ZG_MAX_PMK_LEN);
+
+ return;
+}
+
+U16 zg_get_rssi(){
+ return lastRssi;
+}
+
+// =================================================================================================
+#ifdef UIP_SCAN
+
+tZGScanResult* zg_scan_results(void)
+{
+ return &uip_buf[3];
+}
+
+tZGBssDesc* zg_scan_desc(U8 item)
+{
+ return &uip_buf[7 + (item * sizeof(tZGBssDesc))];
+}
+
+U16 get_scan_cnt(){
+ return scan_cnt;
+}
+
+void zg_scan_start()
+{
+ scan_cnt = 0;
+ tZGScanReq* ptr = (tZGScanReq*)&zg_buf[3];
+
+ zg_buf[0] = ZG_CMD_WT_FIFO_MGMT;
+ zg_buf[1] = ZG_MAC_TYPE_MGMT_REQ;
+ zg_buf[2] = ZG_MAC_SUBTYPE_MGMT_SCAN;
+
+ // Number of usec to delay before transmitting a probe
+ // request following the channel change event
+ ptr->probeDelay = ( U16 ) HSTOZGS( ( U16 ) 20);
+ // the minimum time to spend on each channel in units
+ // of TU (1024 usec)
+ ptr->minChannelTime = ( U16 ) HSTOZGS(( U16 ) 400);
+ // Maximum time to spend on each channel in units
+ // of TU (1024 usec)
+ ptr->maxChannelTime = ( U16 ) HSTOZGS( ( U16 ) 800);
+ // Bssid to restrict the scan too. Or ff:ff:ff:ff:ff:ff
+ // to not restrict the scan by bssid
+ ptr->bssid[0] = 0xFF;
+ ptr->bssid[1] = 0xFF;
+ ptr->bssid[2] = 0xFF;
+ ptr->bssid[3] = 0xFF;
+ ptr->bssid[4] = 0xFF;
+ ptr->bssid[5] = 0xFF;
+ // Type of networks to be scanned. 1==Infrastructure, 2==Ad-hoc, 3==Any
+ ptr->bss = 3;
+ // Scan Type. 1==Active (probe requests), 2==Passive (just listens)
+ ptr->snType = 1;
+ // set ssid length to 0 to do discovery scan
+ ptr->ssidLen = 0;
+ // State based scan only scans a single channel at a time
+ ptr->chnlLen = 11;
+ // Zero-terminated list of channels to scan
+ //ptr->channelList[0] = 3;
+ //ptr->channelList[1] = 6;
+ //ptr->channelList[2] = 11;
+ //ptr->channelList[3] = 0;
+ U8 b;
+ for ( b=0; b<11; b++ ){
+ ptr->channelList[b] = b+1;
+ }
+ ptr->channelList[13] = 0;
+ // Actually send command to zg2100 over SPI
+ spi_transfer( zg_buf, 65, 1 );
+
+ zg_buf[0] = ZG_CMD_WT_FIFO_DONE;
+ spi_transfer(zg_buf, 1, 1);
+
+ //zg_drv_state = DRV_STATE_IDLE;
+}
+
+#endif // UIP_SCAN
+// =================================================================================================
+
+void zg_drv_process()
+{
+ // TX frame
+ if (tx_ready && !cnf_pending) {
+ zg_send(zg_buf, zg_buf_len);
+ tx_ready = 0;
+ cnf_pending = 1;
+ }
+
+ // process interrupt
+ if (intr_occured) {
+ zg_process_isr();
+ }
+
+ if (intr_valid) {
+ switch (zg_buf[1]) {
+ case ZG_MAC_TYPE_TXDATA_CONFIRM:
+ cnf_pending = 0;
+ break;
+ case ZG_MAC_TYPE_MGMT_CONFIRM:
+ if (zg_buf[3] == ZG_RESULT_SUCCESS) {
+ switch (zg_buf[2]) {
+ case ZG_MAC_SUBTYPE_MGMT_SCAN:
+ scan_cnt = 1;
+ break;
+ case ZG_MAC_SUBTYPE_MGMT_REQ_GET_PARAM:
+ mac[0] = zg_buf[7];
+ mac[1] = zg_buf[8];
+ mac[2] = zg_buf[9];
+ mac[3] = zg_buf[10];
+ mac[4] = zg_buf[11];
+ mac[5] = zg_buf[12];
+ zg_drv_state = DRV_STATE_SETUP_SECURITY;
+ break;
+ case ZG_MAC_SUBTYPE_MGMT_REQ_WEP_KEY:
+ zg_drv_state = DRV_STATE_ENABLE_CONN_MANAGE;
+ break;
+ case ZG_MAC_SUBTYPE_MGMT_REQ_CALC_PSK:
+ memcpy(wpa_psk_key, ((zg_psk_calc_cnf_t*)&zg_buf[3])->psk, 32);
+ zg_drv_state = DRV_STATE_INSTALL_PSK;
+ break;
+ case ZG_MAC_SUBTYPE_MGMT_REQ_PMK_KEY:
+ zg_drv_state = DRV_STATE_ENABLE_CONN_MANAGE;
+ break;
+ case ZG_MAC_SUBTYPE_MGMT_REQ_CONNECT_MANAGE:
+ zg_drv_state = DRV_STATE_START_CONN;
+ break;
+ case ZG_MAC_SUBTYPE_MGMT_REQ_CONNECT:
+ LEDConn_on();
+ zg_conn_status = 1; // connected
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ case ZG_MAC_TYPE_RXDATA_INDICATE:
+ zg_drv_state = DRV_STATE_PROCESS_RX;
+ break;
+ case ZG_MAC_TYPE_MGMT_INDICATE:
+ switch (zg_buf[2]) {
+ case ZG_MAC_SUBTYPE_MGMT_IND_DISASSOC:
+ case ZG_MAC_SUBTYPE_MGMT_IND_DEAUTH:
+ LEDConn_off();
+ zg_conn_status = 0; // lost connection
+
+ //try to reconnect
+ zg_drv_state = DRV_STATE_START_CONN;
+ break;
+ case ZG_MAC_SUBTYPE_MGMT_IND_CONN_STATUS:
+ {
+ U16 status = (((U16)(zg_buf[3]))<<8)|zg_buf[4];
+
+ if (status == 1 || status == 5) {
+ LEDConn_off();
+ zg_conn_status = 0; // not connected
+ }
+ else if (status == 2 || status == 6) {
+ LEDConn_on();
+ zg_conn_status = 1; // connected
+ }
+ }
+ break;
+ }
+ break;
+ }
+
+ intr_valid = 0;
+ }
+
+ switch (zg_drv_state) {
+ case DRV_STATE_INIT:
+ zg_drv_state = DRV_STATE_GET_MAC;
+ break;
+ case DRV_STATE_GET_MAC:
+ // get MAC address
+ zg_buf[0] = ZG_CMD_WT_FIFO_MGMT;
+ zg_buf[1] = ZG_MAC_TYPE_MGMT_REQ;
+ zg_buf[2] = ZG_MAC_SUBTYPE_MGMT_REQ_GET_PARAM;
+ zg_buf[3] = 0;
+ zg_buf[4] = ZG_PARAM_MAC_ADDRESS;
+ spi_transfer(zg_buf, 5, 1);
+
+ zg_buf[0] = ZG_CMD_WT_FIFO_DONE;
+ spi_transfer(zg_buf, 1, 1);
+
+ zg_drv_state = DRV_STATE_IDLE;
+ break;
+ case DRV_STATE_SETUP_SECURITY:
+ switch (security_type) {
+ case ZG_SECURITY_TYPE_NONE:
+ zg_drv_state = DRV_STATE_ENABLE_CONN_MANAGE;
+ break;
+ case ZG_SECURITY_TYPE_WEP:
+ // Install all four WEP keys on G2100
+ zg_buf[0] = ZG_CMD_WT_FIFO_MGMT;
+ zg_buf[1] = ZG_MAC_TYPE_MGMT_REQ;
+ zg_buf[2] = ZG_MAC_SUBTYPE_MGMT_REQ_WEP_KEY;
+ zg_write_wep_key(&zg_buf[3]);
+ spi_transfer(zg_buf, ZG_WEP_KEY_REQ_SIZE+3, 1);
+
+ zg_buf[0] = ZG_CMD_WT_FIFO_DONE;
+ spi_transfer(zg_buf, 1, 1);
+
+ zg_drv_state = DRV_STATE_IDLE;
+ break;
+ case ZG_SECURITY_TYPE_WPA:
+ case ZG_SECURITY_TYPE_WPA2:
+ // Initiate PSK calculation on G2100
+ zg_buf[0] = ZG_CMD_WT_FIFO_MGMT;
+ zg_buf[1] = ZG_MAC_TYPE_MGMT_REQ;
+ zg_buf[2] = ZG_MAC_SUBTYPE_MGMT_REQ_CALC_PSK;
+ zg_calc_psk_key(&zg_buf[3]);
+ spi_transfer(zg_buf, ZG_PSK_CALC_REQ_SIZE+3, 1);
+
+ zg_buf[0] = ZG_CMD_WT_FIFO_DONE;
+ spi_transfer(zg_buf, 1, 1);
+
+ zg_drv_state = DRV_STATE_IDLE;
+ break;
+ default:
+ break;
+ }
+ break;
+ case DRV_STATE_INSTALL_PSK:
+ // Install the PSK key on G2100
+ zg_buf[0] = ZG_CMD_WT_FIFO_MGMT;
+ zg_buf[1] = ZG_MAC_TYPE_MGMT_REQ;
+ zg_buf[2] = ZG_MAC_SUBTYPE_MGMT_REQ_PMK_KEY;
+ zg_write_psk_key(&zg_buf[3]);
+ spi_transfer(zg_buf, ZG_PMK_KEY_REQ_SIZE+3, 1);
+
+ zg_buf[0] = ZG_CMD_WT_FIFO_DONE;
+ spi_transfer(zg_buf, 1, 1);
+
+ zg_drv_state = DRV_STATE_IDLE;
+ break;
+ case DRV_STATE_ENABLE_CONN_MANAGE:
+ // enable connection manager
+ zg_buf[0] = ZG_CMD_WT_FIFO_MGMT;
+ zg_buf[1] = ZG_MAC_TYPE_MGMT_REQ;
+ zg_buf[2] = ZG_MAC_SUBTYPE_MGMT_REQ_CONNECT_MANAGE;
+ zg_buf[3] = 0x01; // 0x01 - enable; 0x00 - disable
+ zg_buf[4] = 10; // num retries to reconnect
+ zg_buf[5] = 0x10 | 0x02 | 0x01; // 0x10 - enable start and stop indication messages
+ // from G2100 during reconnection
+ // 0x02 - start reconnection on receiving a deauthentication
+ // message from the AP
+ // 0x01 - start reconnection when the missed beacon count
+ // exceeds the threshold. uses default value of
+ // 100 missed beacons if not set during initialization
+ zg_buf[6] = 0;
+ spi_transfer(zg_buf, 7, 1);
+
+ zg_buf[0] = ZG_CMD_WT_FIFO_DONE;
+ spi_transfer(zg_buf, 1, 1);
+
+ zg_drv_state = DRV_STATE_IDLE;
+ break;
+ case DRV_STATE_START_CONN:
+ {
+ zg_connect_req_t* cmd = (zg_connect_req_t*)&zg_buf[3];
+
+ // start connection to AP
+ zg_buf[0] = ZG_CMD_WT_FIFO_MGMT;
+ zg_buf[1] = ZG_MAC_TYPE_MGMT_REQ;
+ zg_buf[2] = ZG_MAC_SUBTYPE_MGMT_REQ_CONNECT;
+
+ cmd->secType = security_type;
+
+ cmd->ssidLen = ssid_len;
+ memset(cmd->ssid, 0, 32);
+ memcpy(cmd->ssid, ssid, ssid_len);
+
+ // units of 100 milliseconds
+ cmd->sleepDuration = 0;
+
+ if (wireless_mode == WIRELESS_MODE_INFRA)
+ cmd->modeBss = 1;
+ else if (wireless_mode == WIRELESS_MODE_ADHOC)
+ cmd->modeBss = 2;
+
+ spi_transfer(zg_buf, ZG_CONNECT_REQ_SIZE+3, 1);
+
+ zg_buf[0] = ZG_CMD_WT_FIFO_DONE;
+ spi_transfer(zg_buf, 1, 1);
+
+ zg_drv_state = DRV_STATE_IDLE;
+ break;
+ }
+ case DRV_STATE_PROCESS_RX:
+ zg_recv(zg_buf, &zg_buf_len);
+ rx_ready = 1;
+
+ zg_drv_state = DRV_STATE_IDLE;
+ break;
+ case DRV_STATE_IDLE:
+ break;
+ }
+}
View
778 g2100.h
@@ -1,392 +1,392 @@
-
-/*****************************************************************************
-
- Filename: g2100.h
- Description: Driver for the ZeroG Wireless G2100 series devices
-
+
+/*****************************************************************************
+
+ Filename: g2100.h
+ Description: Driver for the ZeroG Wireless G2100 series devices
+
*****************************************************************************
-
- Driver for the WiShield 1.0 wireless devices
-
- Copyright(c) 2009 Async Labs Inc. All rights reserved.
-
- This program is free software; you can redistribute it and/or modify it
- under the terms of version 2 of the GNU General Public License as
- published by the Free Software Foundation.
-
- This program is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- more details.
-
- You should have received a copy of the GNU General Public License along with
- this program; if not, write to the Free Software Foundation, Inc., 59
- Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
- Contact Information:
+
+ Driver for the WiShield 1.0 wireless devices
+
+ Copyright(c) 2009 Async Labs Inc. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program; if not, write to the Free Software Foundation, Inc., 59
+ Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Contact Information:
<asynclabs@asynclabs.com>
-
- Author Date Comment
- ----------------------------------------------------------------------------
- AsyncLabs 02/25/2009 Initial port
+
+ Author Date Comment
+ ----------------------------------------------------------------------------
+ AsyncLabs 02/25/2009 Initial port
AsyncLabs 05/29/2009 Adding support for new library
-
- *****************************************************************************/
-
-#ifndef G2100_H_
-#define G2100_H_
-
-#define DRV_STATE_INIT 0
-#define DRV_STATE_GET_MAC 2
-#define DRV_STATE_START_CONN 3
-#define DRV_STATE_PROCESS_RX 4
-#define DRV_STATE_IDLE 5
-#define DRV_STATE_SETUP_SECURITY 6
-#define DRV_STATE_INSTALL_PSK 7
-#define DRV_STATE_ENABLE_CONN_MANAGE 8
-
-//Host to Zero G long
-#define HTOZGL(a) ( ((a & 0x000000ff)<<24) \
- |((a & 0x0000ff00)<<8) \
- |((a & 0x00ff0000)>>8) \
- |((a & 0xff000000)>>24) )
-#define ZGTOHL(a) HTOZGL(a)
-
-// Host to Zero G short
-#define HSTOZGS(a) (u16)(((a)<<8) | ((a)>>8))
-#define ZGSTOHS(a) HSTOZGS(a)
-//#define HTONS(a) HSTOZGS(a)
-
-#define ZG_INTERRUPT_PIN 0 // Pin on Arduino
-
-// Command values which appear in ZG_PREAMBLE_CMD_IDX for each SPI message
-#define ZG_CMD_FIFO_ACCESS (0x80)
-#define ZG_CMD_WT_FIFO_DATA (ZG_CMD_FIFO_ACCESS | 0x20)
-#define ZG_CMD_WT_FIFO_MGMT (ZG_CMD_FIFO_ACCESS | 0x30)
-#define ZG_CMD_RD_FIFO (ZG_CMD_FIFO_ACCESS | 0x00)
-#define ZG_CMD_WT_FIFO_DONE (ZG_CMD_FIFO_ACCESS | 0x40)
-#define ZG_CMD_RD_FIFO_DONE (ZG_CMD_FIFO_ACCESS | 0x50)
-#define ZG_CMD_WT_REG (0x00)
-#define ZG_CMD_RD_REG (0x40)
-
-// Type values which appear in ZG_PREAMBLE_TYPE_IDX for each SPI message
-#define ZG_MAC_TYPE_TXDATA_REQ ((u8)1)
-#define ZG_MAC_TYPE_MGMT_REQ ((u8)2)
-
-#define ZG_MAC_TYPE_TXDATA_CONFIRM ((u8)1)
-#define ZG_MAC_TYPE_MGMT_CONFIRM ((u8)2)
-#define ZG_MAC_TYPE_RXDATA_INDICATE ((u8)3)
-#define ZG_MAC_TYPE_MGMT_INDICATE ((u8)4)
-
-// Subtype values which appear in ZG_PREAMBLE_SUBTYPE_IDX for each SPI message
-// Subtype for ZG_MAC_TYPE_TXDATA_REQ and ZG_MAC_TYPE_TXDATA_CONFIRM
-#define ZG_MAC_SUBTYPE_TXDATA_REQ_STD ((u8)1)
-
-// Subtype for ZG_MAC_TYPE_MGMT_REQ and ZG_MAC_TYPE_MGMT_CONFIRM
-#define ZG_MAC_SUBTYPE_MGMT_SCAN ((u8)1)
-#define ZG_MAC_SUBTYPE_MGMT_REQ_PMK_KEY ((u8)8)
-#define ZG_MAC_SUBTYPE_MGMT_REQ_WEP_KEY ((u8)10)
-#define ZG_MAC_SUBTYPE_MGMT_REQ_CALC_PSK ((u8)12)
-#define ZG_MAC_SUBTYPE_MGMT_REQ_SET_PARAM ((u8)15)
-#define ZG_MAC_SUBTYPE_MGMT_REQ_GET_PARAM ((u8)16)
-#define ZG_MAC_SUBTYPE_MGMT_REQ_ADHOC_START ((u8)18)
-#define ZG_MAC_SUBTYPE_MGMT_REQ_CONNECT ((u8)19)
-#define ZG_MAC_SUBTYPE_MGMT_REQ_CONNECT_MANAGE ((u8)20)
-
-// Subtype for ZG_MAC_TYPE_RXDATA_INDICATE
-#define ZG_MAC_SUBTYPE_RXDATA_IND_STD ((u8)1)
-
-// Subtype for ZG_MAC_TYPE_MGMT_INDICATE
-#define ZG_MAC_SUBTYPE_MGMT_IND_DISASSOC ((u8)1)
-#define ZG_MAC_SUBTYPE_MGMT_IND_DEAUTH ((u8)2)
-#define ZG_MAC_SUBTYPE_MGMT_IND_CONN_STATUS ((u8)4)
-
-// Parameter IDs for ZG_MAC_SUBTYPE_MGMT_REQ_SET_PARAM
-#define ZG_PARAM_MAC_ADDRESS (1)
-
-// MAC result code
-enum {
- ZG_RESULT_SUCCESS = 1,
- ZG_RESULT_INVALID_SUBTYPE,
- ZG_RESULT_CANCELLED,
- ZG_RESULT_FRAME_EOL,
- ZG_RESULT_FRAME_RETRY_LIMIT,
- ZG_RESULT_FRAME_NO_BSS,
- ZG_RESULT_FRAME_TOO_BIG,
- ZG_RESULT_FRAME_ENCRYPT_FAILURE,
- ZG_RESULT_INVALID_PARAMS,
- ZG_RESULT_ALREADY_AUTH,
- ZG_RESULT_ALREADY_ASSOC,
- ZG_RESULT_INSUFFICIENT_RSRCS,
- ZG_RESULT_TIMEOUT,
- ZG_RESULT_BAD_EXCHANGE, // frame exchange problem with peer (AP or STA)
- ZG_RESULT_AUTH_REFUSED, // authenticating node refused our request
- ZG_RESULT_ASSOC_REFUSED, // associating node refused our request
- ZG_RESULT_REQ_IN_PROGRESS, // only one mlme request at a time allowed
- ZG_RESULT_NOT_JOINED, // operation requires that device be joined
- // with target
- ZG_RESULT_NOT_ASSOC, // operation requires that device be
- // associated with target
- ZG_RESULT_NOT_AUTH, // operation requires that device be
- // authenticated with target
- ZG_RESULT_SUPPLICANT_FAILED,
- ZG_RESULT_UNSUPPORTED_FEATURE,
- ZG_RESULT_REQUEST_OUT_OF_SYNC // Returned when a request is recognized
- // but invalid given the current state
- // of the MAC
-};
-
-/*
- * G2100 command registers
- */
-#define ZG_INTR_REG (0x01) // 8-bit register containing interrupt bits
-#define ZG_INTR_MASK_REG (0x02) // 8-bit register containing interrupt mask
-#define ZG_SYS_INFO_DATA_REG (0x21) // 8-bit register to read system info data window
-#define ZG_SYS_INFO_IDX_REG (0x2b)
-#define ZG_INTR2_REG (0x2d) // 16-bit register containing interrupt bits
-#define ZG_INTR2_MASK_REG (0x2e) // 16-bit register containing interrupt mask
-#define ZG_BYTE_COUNT_REG (0x2f) // 16-bit register containing available write size for fifo0
-#define ZG_BYTE_COUNT_FIFO0_REG (0x33) // 16-bit register containing bytes ready to read on fifo0
-#define ZG_BYTE_COUNT_FIFO1_REG (0x35) // 16-bit register containing bytes ready to read on fifo1
-#define ZG_PWR_CTRL_REG (0x3d) // 16-bit register used to control low power mode
-#define ZG_INDEX_ADDR_REG (0x3e) // 16-bit register to move the data window
-#define ZG_INDEX_DATA_REG (0x3f) // 16-bit register to read the address in the ZG_INDEX_ADDR_REG
-
-#define ZG_INTR_REG_LEN (1)
-#define ZG_INTR_MASK_REG_LEN (1)
-#define ZG_SYS_INFO_DATA_REG_LEN (1)
-#define ZG_SYS_INFO_IDX_REG_LEN (2)
-#define ZG_INTR2_REG_LEN (2)
-#define ZG_INTR2_MASK_REG_LEN (2)
-#define ZG_BYTE_COUNT_REG_LEN (2)
-#define ZG_BYTE_COUNT_FIFO0_REG_LEN (2)
-#define ZG_BYTE_COUNT_FIFO1_REG_LEN (2)
-#define ZG_PWR_CTRL_REG_LEN (2)
-#define ZG_INDEX_ADDR_REG_LEN (2)
-#define ZG_INDEX_DATA_REG_LEN (2)
-
-// Registers accessed through ZG_INDEX_ADDR_REG
-#define ZG_RESET_STATUS_REG (0x2a) // 16-bit read only register providing HW status bits
-#define ZG_RESET_REG (0x2e) // 16-bit register used to initiate hard reset
-#define ZG_PWR_STATUS_REG (0x3e) // 16-bit register read to determine when device
- // out of sleep state
-
-#define ZG_RESET_MASK (0x10) // the first byte of the ZG_RESET_STATUS_REG
- // used to determine when the G2100 is in reset
-
-#define ZG_ENABLE_LOW_PWR_MASK (0x01) // used by the Host to enable/disable sleep state
- // indicates to G2100 that the Host has completed
- // transactions and the device can go into sleep
- // state if possible
-
-// states for interrupt state machine
-#define ZG_INTR_ST_RD_INTR_REG (1)
-#define ZG_INTR_ST_WT_INTR_REG (2)
-#define ZG_INTR_ST_RD_CTRL_REG (3)
-
-// interrupt state
-#define ZG_INTR_DISABLE ((u8)0)
-#define ZG_INTR_ENABLE ((u8)1)
-
-// mask values for ZG_INTR_REG and ZG_INTR2_REG
-#define ZG_INTR_MASK_FIFO1 (0x80)
-#define ZG_INTR_MASK_FIFO0 (0x40)
-#define ZG_INTR_MASK_ALL (0xff)
-#define ZG_INTR2_MASK_ALL (0xffff)
-
-// Buffer size
-#ifdef UIP_SCAN
-#define ZG_BUFFER_SIZE 800
-#else
-#define ZG_BUFFER_SIZE 450
-#endif // UIP_SCAN
-
-// Types of networks
-#define ZG_BSS_INFRA (1) // infrastructure only
-#define ZG_BSS_ADHOC (2) // Ad-hoc only (ibss)
-
-// Max characters in network SSID
-#define ZG_MAX_SSID_LENGTH 32
-
-// Security keys
-#define ZG_MAX_ENCRYPTION_KEYS 4
-#define ZG_MAX_ENCRYPTION_KEY_SIZE 13
-#define ZG_MAX_WPA_PASSPHRASE_LEN 64
-#define ZG_MAX_PMK_LEN 32
-
-#define ZG_SECURITY_TYPE_NONE 0
-#define ZG_SECURITY_TYPE_WEP 1
-#define ZG_SECURITY_TYPE_WPA 2
-#define ZG_SECURITY_TYPE_WPA2 3
-
-typedef struct
-{
- u8 slot; /* slot index */
- u8 keyLen;
- u8 defID; /* the default wep key id */
- u8 ssidLen; /* num valid bytes in ssid */
- u8 ssid[ZG_MAX_SSID_LENGTH]; /* ssid of network */
- u8 key[ZG_MAX_ENCRYPTION_KEYS][ZG_MAX_ENCRYPTION_KEY_SIZE]; /* wep key data for 4 default keys */
-} zg_wep_key_req_t;
-
-#define ZG_WEP_KEY_REQ_SIZE (4 + ZG_MAX_SSID_LENGTH + ZG_MAX_ENCRYPTION_KEYS*ZG_MAX_ENCRYPTION_KEY_SIZE)
-
-typedef struct
-{
- u8 configBits;
- u8 phraseLen; /* number of valid bytes in passphrase */
- u8 ssidLen; /* number of valid bytes in ssid */
- u8 reserved; /* alignment byte */
- u8 ssid[ZG_MAX_SSID_LENGTH]; /* the string of characters representing the ssid */
- u8 passPhrase[ZG_MAX_WPA_PASSPHRASE_LEN]; /* the string of characters representing the passphrase */
-} zg_psk_calc_req_t;
-
-#define ZG_PSK_CALC_REQ_SIZE (4 + ZG_MAX_SSID_LENGTH + ZG_MAX_WPA_PASSPHRASE_LEN) /* 100 bytes */
-
-typedef struct
-{
- u8 result; /* indicating success or other */
- u8 macState; /* current State of the on-chip MAC */
- u8 keyReturned; /* 1 if psk contains key data, 0 otherwise */
- u8 reserved; /* pad byte */
- u8 psk[ZG_MAX_PMK_LEN]; /* the psk bytes */
-} zg_psk_calc_cnf_t;
-
-typedef struct
-{
- u8 slot;
- u8 ssidLen;
- u8 ssid[ZG_MAX_SSID_LENGTH];
- u8 keyData[ZG_MAX_PMK_LEN];
-} zg_pmk_key_req_t;
-
-#define ZG_PMK_KEY_REQ_SIZE (2 + ZG_MAX_SSID_LENGTH + ZG_MAX_PMK_LEN)
-
-typedef struct
-{
- u16 rssi; /* the value of the G1000 RSSI when the data frame was received */
- u8 dstAddr[6]; /* MAC Address to which the data frame was directed. */
- u8 srcAddr[6]; /* MAC Address of the Station that sent the Data frame. */
- u16 arrivalTime_th; /* the value of the 32-bit G1000 system clock when the frame arrived */
- u16 arrivalTime_bh;
- u16 dataLen; /* the length in bytes of the payload which immediately follows this data structure */
-} zg_rx_data_ind_t;
-
-typedef struct
-{
- u8 secType; /* security type : 0 - none; 1 - wep; 2 - wpa; 3 - wpa2; 0xff - best available */
- u8 ssidLen; /* num valid bytes in ssid */
- u8 ssid[ZG_MAX_SSID_LENGTH]; /* the ssid of the target */
- u16 sleepDuration; /* power save sleep duration in units of 100 milliseconds */
- u8 modeBss; /* 1 - infra; 2 - adhoc */
- u8 reserved;
-} zg_connect_req_t;
-
-#define ZG_CONNECT_REQ_SIZE (38)
-
-// =================================================================================================
-#ifdef UIP_SCAN
-
-/* completely describes the details of a BSS (access point) */
-/* This structure is used as a single entry in a Scan result */
-typedef struct
-{
- u8 bssid[6]; /* network BSSID value */
- u8 ssid[32]; /* network SSID value */
- u8 capInfo[2]; /* capability info bits */
- u16 beaconPeriod; /* network Beacon interval */
- u16 atimWindow; /* only valid if .bssType == Ibss */
- u8 basicRateSet[8]; /* list of network basic rates */
- u8 rssi; /* signal strength of rx'd
- * frame beacon, probe resp */
- u8 numRates; /* num entries in basicRateSet */
- u8 DtimPeriod; /* (part of TIM element) */
- u8 bssType; /* ad-hoc or infrastructure. */
- u8 channel; /* phy param set */
- u8 ssidLen; /* number of bytes in ssid */
-} tZGBssDesc; /* 58 bytes */
-
-typedef tZGBssDesc *tZGBssDescPtr;
-
-/* use #define size to represent the number of bytes in the structure
- * because not all compilers have an appropriate calculation when using sizeof() */
-#define kZGBssDescSZ (58)
-
-/* Represents the input parameters required to
- * conduct a Scan operation */
-typedef struct
-{
- u16 probeDelay; /* the number of usec to delay before transmitting a probe
- * request following the channel change event */
- u16 minChannelTime; /* the minimum time to spend on each channel in units
- * of TU (1024 usec) */
- u16 maxChannelTime; /* the maximum time to spend on each channel in units
- * of TU (1024 usec) */
- u8 bssid[6]; /* limits the scan to a specific Bss or Broadcast
- * (FF:FF:FF:FF:FF:FF) */
- u8 bss; /* limits the type of networks to include in scan results.
- * Can be one of; kBssInfra kBssAdHoc kBssAny*/
- u8 snType; /* one of kZGMACSnTypeActive or kZGMACSnTypePassive where
- * active indicates the use of Probe Request frames */
- u8 ssidLen; /* num chars in ssid */
- u8 chnlLen; /* num channels to scan */
- u8 ssid[32]; /* limits the scan to a specific Service Set (SSID) or
- // * broadcast ("\0") */
- u8 channelList[14]; /* zero terminated list of channels
- * to scan */
-} tZGScanReq; /* 62 bytes */
-
-typedef tZGScanReq *tZGScanReqPtr;
-
-/* use #define size to represent the number of bytes in the structure
- * because not all compilers have an appropriate calculation when using sizeof() */
-#define kZGScanReqSZ (62)
-
-/* The structure used to return the scan results back to the host system */
-typedef struct
-{
- u8 result; /* the result of the scan */
- u8 macState; /* current state of the on-chip MAC */
- u8 lastChnl; /* the last channel scanned */
- u8 numBssDesc; /* The number of tZGMACBssDesc objects that
- * immediately follows this structure in memory */
-} tZGScanResult; /* 4 bytes */
-
-typedef tZGScanResult *tZGScanResultPtr;
-
-#define kZGScanResultSZ (4)
-
-#endif // UIP_SCAN
-// =================================================================================================
-
-void zg_init();
-void zg_reset();
-void spi_transfer(volatile U8* buf, U16 len, U8 toggle_cs);
-void zg_chip_reset();
-void zg_interrupt2_reg();
-void zg_interrupt_reg(U8 mask, U8 state);
-void zg_isr();
-void zg_process_isr();
-void zg_send(U8* buf, U16 len);
-void zg_recv(U8* buf, U16* len);
-U16 zg_get_rx_status();
-void zg_clear_rx_status();
-void zg_set_tx_status(U8 status);
-U8 zg_get_conn_state();
-void zg_set_buf(U8* buf, U16 buf_len);
-U8* zg_get_mac();
-void zg_set_ssid(U8* ssid, U8 ssid_len);
-void zg_set_sec(U8 sec_type, U8* sec_key, U8 sec_key_len);
-void zg_drv_process();
-
-// User Contributed ================================================================================
-U16 zg_get_rssi();
-
-#ifdef UIP_SCAN
-void zg_scan_start();
-tZGScanResult* zg_scan_results();
-tZGBssDesc* zg_scan_desc(U8 item);
-U16 get_scan_cnt();
-#endif // UIP_SCAN
-
-#endif /* G2100_H_ */
+
+ *****************************************************************************/
+
+#ifndef G2100_H_
+#define G2100_H_
+
+#define DRV_STATE_INIT 0
+#define DRV_STATE_GET_MAC 2
+#define DRV_STATE_START_CONN 3
+#define DRV_STATE_PROCESS_RX 4
+#define DRV_STATE_IDLE 5
+#define DRV_STATE_SETUP_SECURITY 6
+#define DRV_STATE_INSTALL_PSK 7
+#define DRV_STATE_ENABLE_CONN_MANAGE 8
+
+//Host to Zero G long
+#define HTOZGL(a) ( ((a & 0x000000ff)<<24) \
+ |((a & 0x0000ff00)<<8) \
+ |((a & 0x00ff0000)>>8) \
+ |((a & 0xff000000)>>24) )
+#define ZGTOHL(a) HTOZGL(a)
+
+// Host to Zero G short
+#define HSTOZGS(a) (u16)(((a)<<8) | ((a)>>8))
+#define ZGSTOHS(a) HSTOZGS(a)
+//#define HTONS(a) HSTOZGS(a)
+
+#define ZG_INTERRUPT_PIN 0 // Pin on Arduino
+
+// Command values which appear in ZG_PREAMBLE_CMD_IDX for each SPI message
+#define ZG_CMD_FIFO_ACCESS (0x80)
+#define ZG_CMD_WT_FIFO_DATA (ZG_CMD_FIFO_ACCESS | 0x20)
+#define ZG_CMD_WT_FIFO_MGMT (ZG_CMD_FIFO_ACCESS | 0x30)
+#define ZG_CMD_RD_FIFO (ZG_CMD_FIFO_ACCESS | 0x00)
+#define ZG_CMD_WT_FIFO_DONE (ZG_CMD_FIFO_ACCESS | 0x40)
+#define ZG_CMD_RD_FIFO_DONE (ZG_CMD_FIFO_ACCESS | 0x50)
+#define ZG_CMD_WT_REG (0x00)
+#define ZG_CMD_RD_REG (0x40)
+
+// Type values which appear in ZG_PREAMBLE_TYPE_IDX for each SPI message
+#define ZG_MAC_TYPE_TXDATA_REQ ((u8)1)
+#define ZG_MAC_TYPE_MGMT_REQ ((u8)2)
+
+#define ZG_MAC_TYPE_TXDATA_CONFIRM ((u8)1)
+#define ZG_MAC_TYPE_MGMT_CONFIRM ((u8)2)
+#define ZG_MAC_TYPE_RXDATA_INDICATE ((u8)3)
+#define ZG_MAC_TYPE_MGMT_INDICATE ((u8)4)
+
+// Subtype values which appear in ZG_PREAMBLE_SUBTYPE_IDX for each SPI message
+// Subtype for ZG_MAC_TYPE_TXDATA_REQ and ZG_MAC_TYPE_TXDATA_CONFIRM
+#define ZG_MAC_SUBTYPE_TXDATA_REQ_STD ((u8)1)
+
+// Subtype for ZG_MAC_TYPE_MGMT_REQ and ZG_MAC_TYPE_MGMT_CONFIRM
+#define ZG_MAC_SUBTYPE_MGMT_SCAN ((u8)1)
+#define ZG_MAC_SUBTYPE_MGMT_REQ_PMK_KEY ((u8)8)
+#define ZG_MAC_SUBTYPE_MGMT_REQ_WEP_KEY ((u8)10)
+#define ZG_MAC_SUBTYPE_MGMT_REQ_CALC_PSK ((u8)12)
+#define ZG_MAC_SUBTYPE_MGMT_REQ_SET_PARAM ((u8)15)
+#define ZG_MAC_SUBTYPE_MGMT_REQ_GET_PARAM ((u8)16)
+#define ZG_MAC_SUBTYPE_MGMT_REQ_ADHOC_START ((u8)18)
+#define ZG_MAC_SUBTYPE_MGMT_REQ_CONNECT ((u8)19)
+#define ZG_MAC_SUBTYPE_MGMT_REQ_CONNECT_MANAGE ((u8)20)
+
+// Subtype for ZG_MAC_TYPE_RXDATA_INDICATE
+#define ZG_MAC_SUBTYPE_RXDATA_IND_STD ((u8)1)
+
+// Subtype for ZG_MAC_TYPE_MGMT_INDICATE
+#define ZG_MAC_SUBTYPE_MGMT_IND_DISASSOC ((u8)1)
+#define ZG_MAC_SUBTYPE_MGMT_IND_DEAUTH ((u8)2)
+#define ZG_MAC_SUBTYPE_MGMT_IND_CONN_STATUS ((u8)4)
+
+// Parameter IDs for ZG_MAC_SUBTYPE_MGMT_REQ_SET_PARAM
+#define ZG_PARAM_MAC_ADDRESS (1)
+
+// MAC result code
+enum {
+ ZG_RESULT_SUCCESS = 1,
+ ZG_RESULT_INVALID_SUBTYPE,
+ ZG_RESULT_CANCELLED,
+ ZG_RESULT_FRAME_EOL,
+ ZG_RESULT_FRAME_RETRY_LIMIT,
+ ZG_RESULT_FRAME_NO_BSS,
+ ZG_RESULT_FRAME_TOO_BIG,
+ ZG_RESULT_FRAME_ENCRYPT_FAILURE,
+ ZG_RESULT_INVALID_PARAMS,
+ ZG_RESULT_ALREADY_AUTH,
+ ZG_RESULT_ALREADY_ASSOC,
+ ZG_RESULT_INSUFFICIENT_RSRCS,
+ ZG_RESULT_TIMEOUT,
+ ZG_RESULT_BAD_EXCHANGE, // frame exchange problem with peer (AP or STA)
+ ZG_RESULT_AUTH_REFUSED, // authenticating node refused our request
+ ZG_RESULT_ASSOC_REFUSED, // associating node refused our request
+ ZG_RESULT_REQ_IN_PROGRESS, // only one mlme request at a time allowed
+ ZG_RESULT_NOT_JOINED, // operation requires that device be joined
+ // with target
+ ZG_RESULT_NOT_ASSOC, // operation requires that device be
+ // associated with target
+ ZG_RESULT_NOT_AUTH, // operation requires that device be
+ // authenticated with target
+ ZG_RESULT_SUPPLICANT_FAILED,
+ ZG_RESULT_UNSUPPORTED_FEATURE,
+ ZG_RESULT_REQUEST_OUT_OF_SYNC // Returned when a request is recognized
+ // but invalid given the current state
+ // of the MAC
+};
+
+/*
+ * G2100 command registers
+ */
+#define ZG_INTR_REG (0x01) // 8-bit register containing interrupt bits
+#define ZG_INTR_MASK_REG (0x02) // 8-bit register containing interrupt mask
+#define ZG_SYS_INFO_DATA_REG (0x21) // 8-bit register to read system info data window
+#define ZG_SYS_INFO_IDX_REG (0x2b)
+#define ZG_INTR2_REG (0x2d) // 16-bit register containing interrupt bits
+#define ZG_INTR2_MASK_REG (0x2e) // 16-bit register containing interrupt mask
+#define ZG_BYTE_COUNT_REG (0x2f) // 16-bit register containing available write size for fifo0
+#define ZG_BYTE_COUNT_FIFO0_REG (0x33) // 16-bit register containing bytes ready to read on fifo0
+#define ZG_BYTE_COUNT_FIFO1_REG (0x35) // 16-bit register containing bytes ready to read on fifo1
+#define ZG_PWR_CTRL_REG (0x3d) // 16-bit register used to control low power mode
+#define ZG_INDEX_ADDR_REG (0x3e) // 16-bit register to move the data window
+#define ZG_INDEX_DATA_REG (0x3f) // 16-bit register to read the address in the ZG_INDEX_ADDR_REG
+
+#define ZG_INTR_REG_LEN (1)
+#define ZG_INTR_MASK_REG_LEN (1)
+#define ZG_SYS_INFO_DATA_REG_LEN (1)
+#define ZG_SYS_INFO_IDX_REG_LEN (2)
+#define ZG_INTR2_REG_LEN (2)
+#define ZG_INTR2_MASK_REG_LEN (2)
+#define ZG_BYTE_COUNT_REG_LEN (2)
+#define ZG_BYTE_COUNT_FIFO0_REG_LEN (2)
+#define ZG_BYTE_COUNT_FIFO1_REG_LEN (2)
+#define ZG_PWR_CTRL_REG_LEN (2)
+#define ZG_INDEX_ADDR_REG_LEN (2)
+#define ZG_INDEX_DATA_REG_LEN (2)
+
+// Registers accessed through ZG_INDEX_ADDR_REG
+#define ZG_RESET_STATUS_REG (0x2a) // 16-bit read only register providing HW status bits
+#define ZG_RESET_REG (0x2e) // 16-bit register used to initiate hard reset
+#define ZG_PWR_STATUS_REG (0x3e) // 16-bit register read to determine when device
+ // out of sleep state
+
+#define ZG_RESET_MASK (0x10) // the first byte of the ZG_RESET_STATUS_REG
+ // used to determine when the G2100 is in reset
+
+#define ZG_ENABLE_LOW_PWR_MASK (0x01) // used by the Host to enable/disable sleep state
+ // indicates to G2100 that the Host has completed
+ // transactions and the device can go into sleep
+ // state if possible
+
+// states for interrupt state machine
+#define ZG_INTR_ST_RD_INTR_REG (1)
+#define ZG_INTR_ST_WT_INTR_REG (2)
+#define ZG_INTR_ST_RD_CTRL_REG (3)
+
+// interrupt state
+#define ZG_INTR_DISABLE ((u8)0)
+#define ZG_INTR_ENABLE ((u8)1)
+
+// mask values for ZG_INTR_REG and ZG_INTR2_REG
+#define ZG_INTR_MASK_FIFO1 (0x80)
+#define ZG_INTR_MASK_FIFO0 (0x40)
+#define ZG_INTR_MASK_ALL (0xff)
+#define ZG_INTR2_MASK_ALL (0xffff)
+
+// Buffer size
+#ifdef UIP_SCAN
+#define ZG_BUFFER_SIZE 800
+#else
+#define ZG_BUFFER_SIZE 450
+#endif // UIP_SCAN
+
+// Types of networks
+#define ZG_BSS_INFRA (1) // infrastructure only
+#define ZG_BSS_ADHOC (2) // Ad-hoc only (ibss)
+
+// Max characters in network SSID
+#define ZG_MAX_SSID_LENGTH 32
+
+// Security keys
+#define ZG_MAX_ENCRYPTION_KEYS 4
+#define ZG_MAX_ENCRYPTION_KEY_SIZE 13
+#define ZG_MAX_WPA_PASSPHRASE_LEN 64
+#define ZG_MAX_PMK_LEN 32
+
+#define ZG_SECURITY_TYPE_NONE 0
+#define ZG_SECURITY_TYPE_WEP 1
+#define ZG_SECURITY_TYPE_WPA 2
+#define ZG_SECURITY_TYPE_WPA2 3
+
+typedef struct
+{
+ u8 slot; /* slot index */
+ u8 keyLen;
+ u8 defID; /* the default wep key id */
+ u8 ssidLen; /* num valid bytes in ssid */
+ u8 ssid[ZG_MAX_SSID_LENGTH]; /* ssid of network */
+ u8 key[ZG_MAX_ENCRYPTION_KEYS][ZG_MAX_ENCRYPTION_KEY_SIZE]; /* wep key data for 4 default keys */
+} zg_wep_key_req_t;
+
+#define ZG_WEP_KEY_REQ_SIZE (4 + ZG_MAX_SSID_LENGTH + ZG_MAX_ENCRYPTION_KEYS*ZG_MAX_ENCRYPTION_KEY_SIZE)
+
+typedef struct
+{
+ u8 configBits;
+ u8 phraseLen; /* number of valid bytes in passphrase */
+ u8 ssidLen; /* number of valid bytes in ssid */
+ u8 reserved; /* alignment byte */
+ u8 ssid[ZG_MAX_SSID_LENGTH]; /* the string of characters representing the ssid */
+ u8 passPhrase[ZG_MAX_WPA_PASSPHRASE_LEN]; /* the string of characters representing the passphrase */
+} zg_psk_calc_req_t;
+
+#define ZG_PSK_CALC_REQ_SIZE (4 + ZG_MAX_SSID_LENGTH + ZG_MAX_WPA_PASSPHRASE_LEN) /* 100 bytes */
+
+typedef struct
+{
+ u8 result; /* indicating success or other */
+ u8 macState; /* current State of the on-chip MAC */
+ u8 keyReturned; /* 1 if psk contains key data, 0 otherwise */
+ u8 reserved; /* pad byte */
+ u8 psk[ZG_MAX_PMK_LEN]; /* the psk bytes */
+} zg_psk_calc_cnf_t;
+
+typedef struct
+{
+ u8 slot;
+ u8 ssidLen;
+ u8 ssid[ZG_MAX_SSID_LENGTH];
+ u8 keyData[ZG_MAX_PMK_LEN];
+} zg_pmk_key_req_t;
+
+#define ZG_PMK_KEY_REQ_SIZE (2 + ZG_MAX_SSID_LENGTH + ZG_MAX_PMK_LEN)
+
+typedef struct
+{
+ u16 rssi; /* the value of the G1000 RSSI when the data frame was received */
+ u8 dstAddr[6]; /* MAC Address to which the data frame was directed. */
+ u8 srcAddr[6]; /* MAC Address of the Station that sent the Data frame. */
+ u16 arrivalTime_th; /* the value of the 32-bit G1000 system clock when the frame arrived */
+ u16 arrivalTime_bh;
+ u16 dataLen; /* the length in bytes of the payload which immediately follows this data structure */
+} zg_rx_data_ind_t;
+
+typedef struct
+{
+ u8 secType; /* security type : 0 - none; 1 - wep; 2 - wpa; 3 - wpa2; 0xff - best available */
+ u8 ssidLen; /* num valid bytes in ssid */
+ u8 ssid[ZG_MAX_SSID_LENGTH]; /* the ssid of the target */
+ u16 sleepDuration; /* power save sleep duration in units of 100 milliseconds */
+ u8 modeBss; /* 1 - infra; 2 - adhoc */
+ u8 reserved;
+} zg_connect_req_t;
+
+#define ZG_CONNECT_REQ_SIZE (38)
+
+// =================================================================================================
+#ifdef UIP_SCAN
+
+/* completely describes the details of a BSS (access point) */
+/* This structure is used as a single entry in a Scan result */
+typedef struct
+{
+ u8 bssid[6]; /* network BSSID value */
+ u8 ssid[32]; /* network SSID value */
+ u8 capInfo[2]; /* capability info bits */
+ u16 beaconPeriod; /* network Beacon interval */
+ u16 atimWindow; /* only valid if .bssType == Ibss */
+ u8 basicRateSet[8]; /* list of network basic rates */
+ u8 rssi; /* signal strength of rx'd
+ * frame beacon, probe resp */
+ u8 numRates; /* num entries in basicRateSet */
+ u8 DtimPeriod; /* (part of TIM element) */
+ u8 bssType; /* ad-hoc or infrastructure. */
+ u8 channel; /* phy param set */
+ u8 ssidLen; /* number of bytes in ssid */
+} tZGBssDesc; /* 58 bytes */
+
+typedef tZGBssDesc *tZGBssDescPtr;
+
+/* use #define size to represent the number of bytes in the structure
+ * because not all compilers have an appropriate calculation when using sizeof() */
+#define kZGBssDescSZ (58)
+
+/* Represents the input parameters required to
+ * conduct a Scan operation */
+typedef struct
+{
+ u16 probeDelay; /* the number of usec to delay before transmitting a probe
+ * request following the channel change event */
+ u16 minChannelTime; /* the minimum time to spend on each channel in units
+ * of TU (1024 usec) */
+ u16 maxChannelTime; /* the maximum time to spend on each channel in units
+ * of TU (1024 usec) */
+ u8 bssid[6]; /* limits the scan to a specific Bss or Broadcast
+ * (FF:FF:FF:FF:FF:FF) */
+ u8 bss; /* limits the type of networks to include in scan results.
+ * Can be one of; kBssInfra kBssAdHoc kBssAny*/
+ u8 snType; /* one of kZGMACSnTypeActive or kZGMACSnTypePassive where
+ * active indicates the use of Probe Request frames */
+ u8 ssidLen; /* num chars in ssid */
+ u8 chnlLen; /* num channels to scan */
+ u8 ssid[32]; /* limits the scan to a specific Service Set (SSID) or
+ // * broadcast ("\0") */
+ u8 channelList[14]; /* zero terminated list of channels
+ * to scan */
+} tZGScanReq; /* 62 bytes */
+
+typedef tZGScanReq *tZGScanReqPtr;
+