NetBurner 3.0
NBWilcDriver.h
Go to the documentation of this file.
1 /*NB_REVISION*/
2 
3 /*NB_COPYRIGHT*/
4 
9 #ifndef NBWILCDRIVER_H_
10 #define NBWILCDRIVER_H_
11 
12 #include <nbwifi/nbWifidriver.h>
13 #include <nbwifi/wilc/atmel/driver/m2m_types.h>
14 #include <constants.h>
15 
16 #define WILC_Q_SIZE 220
17 #define WIFI_RX_FLOW_OFF_COUNT BUFFER_POOL_SIZE/2
18 
19 #define DEFAULT_WIFI_SCAN_SLOTS_PER_CHANNEL 6
20 #define DEFAULT_WIFI_SCAN_SLOT_TIME 50
21 
22 #define WIFI_RX_FLAG (0x01)
23 #define WIFI_TX_FLAG (0x02)
24 #define WIFI_STA_CON_FLAG (0x04)
25 #define WIFI_STA_DISCON_FLAG (0x08)
26 #define WIFI_AP_START_FLAG (0x0F)
27 #define WIFI_AP_STOP_FLAG (0x10)
28 #define WIFI_CON_INFO_FLAG (0x20)
29 #define WIFI_ANY_FLAG (0xFF)
30 
31 struct lastConnected
32 {
33  uint8_t ssid[SSID_MAX_LEN];
34  uint8_t ssidLen;
35  uint8_t psk[PASS_MAX_LEN];
36  uint8_t securityType;
37 };
38 
39 
40 namespace NBWifi
41 {
42  class WILC1000 : public Master
43  {
44  public:
45  static NBWifi::Master* GetNewWilcDriver();
46 
47  // static functions for use with interface blocks
48  static void TransmitBuffer_0( PoolPtr txBuffer );
49  static void TransmitBuffer_1( PoolPtr txBuffer );
50  static void kill_0();
51  static void kill_1();
52  static BOOL linkActive_0();
53  static BOOL linkActive_1();
54  static void enab_multicast_0( MACADR macAddress, BOOL addAddress );
55  static void enab_multicast_1( MACADR macAddress, BOOL addAddress );
56 
57  void TransmitBuffer( PoolPtr txBuffer ) override;
58  bool GetLinkStatus() override; // does not perform a bus communication, fast
59  void enab_multicast( MACADR macAddress, BOOL addAddress ) override;
60  int APIStart() override;
61 
62  // RXTask control methods
63  int Start() override;
64  void Pause() override;
65  void Resume() override;
66  void Kill() override;
67 
68  int ConnectToAP(
69  const char * ssid = nullptr, const char * passwd = "",
70  uint8_t retryCount = CONNECT_RETRIES,
71  uint8_t security = DEFAULT_WIFI_SEC_ALL
72  ) override;
73  int ConnectToAP( nbWifiConnect connect ) override;
74  int StartAP(
75  const char * ssid = nullptr,
76  const char * passwd = "",
77  uint8_t channel = DEFAULT_TABLE_LABEL_CHANNEL,
78  uint8_t security = DEFAULT_TABLE_LABEL_SEC,
79  uint8_t cipher = DEFAULT_TABLE_LABEL_CIPH,
80  uint8_t ssidLen = 0
81  ) override;
82 
83  int StartConfigAP(uint8_t channel = DEFAULT_TABLE_LABEL_CHANNEL) override;
84 
85  // Results of Scan are valid until the next call to 'Scan' or 'FreeScanList'
86  nbWifiScanResult * Scan( const char * ssid = nullptr, uint8_t optionCount = 0, uint16_t *optionList = nullptr) override;
87  void FreeScanList();
88 
89  void Disconnect() override;
90  int StartAsyncScan( uint8_t channel = DEFAULT_WIFI_CH_ALL, const char * ssid = nullptr, uint8_t optionCount = 0, uint16_t *optionList = nullptr);
91  void SetScanResult(tstrM2mWifiscanResult * scanResult, uint8_t numAPFound);
92  void StopAP();
93 
94  // Utility Functions
95  int StoreSSIDPWToConfig( char *ssid, char *password, int ssidLen = 0) override;
96  int GetSSIDFromConfig( char *returnBuf, int maxLen ) override;
97  int GetKeyFromConfig( char *returnBuf, int maxLen ) override;
98 
99  bool isRegistered() const override;
100  int GetWifiInterfaceNumber() const override; // Get WiFi driver number
101  int GetSystemInterfaceNumber() const override; // Get Wifi Interface number
102 
103  //Status functions:
104  int GetCurSSID(char * buf, int maxlen) override;
105  MACADR GetCurBSSID() override;
106  void GetCurrentAP(driverStatusStruct *ap) override;
107  void GetDeviceInformation(nbWifiDeviceInfo *ap) override;
108  bool Connected() override; // performs a bus communication to query the module, slow
109  int GetSignalStrength() override;
110  uint8_t GetCurChannel() override;
111  uint8_t GetSecurity() override;
112  uint8_t GetCipher() override;
113  void GetMACAddress(MACADR* macAddr);
114 
115  void SetWifiEventFlag(uint8_t flag, bool setNotClear);
116  void SetConnectState(tstrM2MConnInfo * ConnInfo, bool connected, int ssidLen, MACADR * mac, bool STAmode);
117  virtual bool SetBusSpeed( uint32_t busSpeed ) = 0;
118  friend void ::SetWifiSPISpeed( int busSpeed );
119 
121  volatile bool gbConnectedWifi;
122  volatile bool processingConnectRequest;
124  bool gbAPStarted;
126  bool gbDhcpServerStarted;
127 
128  volatile unsigned char gu8ChipMode;
129  volatile unsigned char gu8ChipSleep;
130  volatile unsigned char gu8HifSizeDone;
131 
132  private:
133  NBWifi::APIMessage::Response::DeviceInfo devInfo;
134 
135  void ReadyInterface();
136  PoolPtr GetDeviceInformation();
137  int AddWaitingCommand( uint8_t requestType, uint8_t commandID, OS_MBOX *pmbox );
138 
139  protected:
140  static uint32_t DriverStk[MAX_WIFI_INTERFACES][USER_TASK_STK_SIZE];
141  volatile bool bFatalError;
142 
143  friend class Master;
144 
145 
146  void TransmitBuffer_Core( PoolPtr txBuffer, uint8_t credits ); //TODO: change back to virtual
147 
148  int RegisterDriver();
149  virtual void WifiTask() = 0;
150  static void WifiTaskLauncher(void *wifiDriverObj);
151 
152  uint32_t numAPFound;
153  uint32_t scanResultIndex;
154  uint32_t sta_connected;
155 
156  int myWifiNum;
157  OS_Q wifiMsgQueue;
158  CommBus busType;
159  OS_SEM WifiTxFlowCtrl;
160  OS_SEM taskPauseSem;
161  OS_FLAGS wifiEventFlag;
162  bool hardwareInitialized;
163  int myInterfaceNumber;
164  uint8_t nChipsetIntfNum;
165  char softAPName[SSID_MAX_LEN + 1];
166  volatile lastConnected lastConnection;
167 
168  /* ---- Constructors ---- */
169  WILC1000(CommBus busType, int resetPinConnector, int resetPinMum, const char * name); // , int resetPinConnector, int resetPinMum);
170  ~WILC1000();
171  };
172 }
173 
174 extern NBWifi::Master * theWifiIntf;
175 
176 #endif // NBWILCDRIVER_H_
void SetWifiSPISpeed(int busSpeed)
Set SPI bus speed.
Semaphores are used to control access to shared resource critical section, or to communicate between ...
Definition: nbrtos.h:289
NetBurner Wifi API.
NetBurner System Constants.
A queue functions as a fixed size FIFO for communication between tasks.
Definition: nbrtos.h:502
NBWifi namespace that encompaces the WiFi driver.
Definition: nbWifiBsp.h:15
Mailboxes are used to communicate between tasks.
Definition: nbrtos.h:362
An OS_FLAGS object is used to set, clear, and pend on a set of flags that is held and maintained by t...
Definition: nbrtos.h:956