NetBurner 3.0
nbWicedMsgStructs.h
Go to the documentation of this file.
1 /*NB_REVISION*/
2 
3 /*NB_COPYRIGHT*/
4 
9 #ifndef __NBWICEDMSGSTRUCTS_H
10 #define __NBWICEDMSGSTRUCTS_H
11 
12 #include <nettypes.h>
13 #include <string.h>
14 #include <nbwifi/nbWifiConstants.h>
15 
16 // #define HTONS(x) (x)
17 // #define HTONL(x) (x)
18 // #define htons(x) (x)
19 // #define htonl(x) (x)
20 
21 #define BufferToObjPtr(buffer, objType) ((objType *)((uint8_t *)((buffer)->pData) + (buffer)->usedsize))
22 #define AddToBuffLen(buffer, msgPtr) (buffer)->usedsize += sizeof(*msgPtr)
23 #define GetSafeLength(val, max) ((val) <= (max)) ? (val) : (max)
24 
25 #define MESSAGE_TYPE_BIT_OFFSET 4
26 #define TYPELEN_FIELD_LEN (sizeof(NBWifi::APIMessage::Header::lenType))
27 #define _STRUCT_PACKED __attribute__ ((__packed__))
28 #define MAX_HARDWARE_TYPE_LENGTH 64
29 
30 
31 
33 //
34 // Enum Definitions
35 //
37 namespace NBWifi
38 {
39  namespace APIMessage
40  {
41  namespace Header
42  {
43  typedef enum {
44  Type_API_Request = 0x0,
45  Type_API_Response = 0x1,
46  Type_Credit_Report = 0x2,
47  Type_Data_Raw = 0x3,
48  Type_Data_CompressedIP = 0x4,
49  Type_Internal = 0x7,
50  } ApiMessageTypes;
51  }
52  namespace Request
53  {
54  typedef enum {
55  Type_Config = 0x0,
56  Type_Connect_Start = 0x1,
57  Type_Disconnect_Stop = 0x2,
58  Type_Scan = 0x3,
59  Type_SetMAC = 0x4,
60  Type_SaveConfig = 0x5,
61  Type_GetCredits = 0x6,
62  Type_SetBusSpeed = 0x7,
63  Type_ReadyFirmware = 0x8,
64  Type_FirmwareChunk = 0x9,
65  Type_VerifyAndProgFirm = 0xA,
66  Type_AddRemoveMulticast = 0xB,
67  Type_GetStatus = 0xFD,
68  Type_GetDeviceInfo = 0xFE,
69  Type_GetOptionTable = 0xFF
70  } RequestTypes;
71  }
72  namespace Response
73  {
74  typedef enum {
75  Type_Scan_Result = 0x0,
76  Type_Status = 0x1,
77  Type_DeviceInfo = 0x2,
78  Type_OptionTableResp= 0x3,
79  } ResponseTypes;
80  }
81  namespace Internal
82  {
83  typedef enum {
84  Type_Internal_JoinAP = 0x0,
85  Type_Internal_SendStatus = 0x1,
86  Type_Internal_Reconnect = 0x2,
87  } InternalTypes;
88  }
89 
90  }
91 }
92 
94 //
95 // Structure Definitions
96 //
98 namespace NBWifi
99 {
100  namespace APIMessage
101  {
102  // Header structures
103  namespace Header
104  {
105  struct _STRUCT_PACKED lenType {
106  beuint16_t val;
107  beuint16_t xorVal;
108  };
109  struct _STRUCT_PACKED APIRequest {
110  lenType lengthAndType;
111  uint8_t requestType;
112  uint8_t commandID;
113  uint8_t pData[];
114  };
115  struct _STRUCT_PACKED APIResponse {
116  lenType lengthAndType;
117  uint8_t responseType;
118  uint8_t commandID;
119  int32_t returnCode;
120  // beint32_t returnCode;
121  // uint8_t returnCode;
122  uint8_t pData[];
123  };
124  struct _STRUCT_PACKED CreditReport {
125  lenType lengthAndType;
126  uint8_t availableCredits;
127  };
128  struct _STRUCT_PACKED Data_Raw {
129  lenType lengthAndType;
130  uint8_t availableCredits;
131  uint8_t pData[];
132  };
133  struct _STRUCT_PACKED Data_CompressedIP {
134  lenType lengthAndType;
135  uint8_t connectionID;
136  uint8_t availableCredits;
137  uint8_t pData[];
138  };
139  struct _STRUCT_PACKED Internal {
140  lenType lengthAndType;
141  uint8_t messageType;
142  uint8_t commandID;
143  };
144  }
145 
146  // Request structures
147  namespace Request
148  {
149  struct _STRUCT_PACKED ConfigReq {
150  uint8_t optionCount;
151  uint8_t ssidLength;
152  uint8_t passwdLength;
153  uint8_t padding;
154  char options[]; // Placeholder for char array pobe_inter
155  };
156  struct _STRUCT_PACKED ConnectStart {
157  uint8_t configNum;
158  uint8_t flags;
159  uint8_t retryCount;
160  };
161  struct _STRUCT_PACKED Scan {
162  uint8_t optionCount;
163  uint8_t ssidLength;
164  char options[]; // Placeholder for char array pobe_inter
165  };
166  struct _STRUCT_PACKED SetMAC {
167  MACADR newMAC;
168  };
169  struct _STRUCT_PACKED SaveConfig {
170  uint8_t configNum;
171  };
172  struct _STRUCT_PACKED SetBusSpeed {
173  beuint32_t busSpeed;
174  };
175  struct _STRUCT_PACKED FirmwareChunk {
176  beuint32_t offset;
177  beuint16_t length;
178  beuint16_t checksum;
179  uint8_t pData[];
180  };
181  struct _STRUCT_PACKED VerifyAndProgFirm {
182  beuint32_t imageLength;
183  beuint32_t checksum[4];
184  };
185  struct _STRUCT_PACKED AddRemoveMulticast {
186  uint8_t flags;
187  MACADR theMac;
188  };
189  struct _STRUCT_PACKED GetTableReq {
190  uint8_t tableNum;
191  };
192  }
193 
194  // Response structures
195  namespace Response
196  {
197  struct _STRUCT_PACKED ScanResult {
198  uint8_t lastAndBand;
199  uint8_t bssType;
200  uint8_t channel;
201  uint8_t security;
202  uint8_t cipher;
203  uint8_t ssidLength;
204  beint16_t rssi;
205  MACADR bssid;
206  char ssid[]; // Placeholder for char array pobe_inter
207  };
208  struct _STRUCT_PACKED Status {
209  uint8_t connected;
210  uint8_t bssType;
211  uint8_t security;
212  uint8_t cipher;
213  beuint32_t maxTxRate;
214  beuint16_t txPower;
215  beuint16_t rssi;
216  uint8_t band;
217  uint8_t channel;
218  MACADR bssid;
219  uint8_t ssidLength;
220  char ssid[]; // Placeholder for char array pobe_inter
221  };
222  struct _STRUCT_PACKED DeviceInfo {
223  uint8_t hardwareMajorRev;
224  uint8_t hardwareMinorRev;
225  uint8_t softwareMajorRev;
226  uint8_t softwareMinorRev;
227  MACADR hardwareID;
228  uint8_t hardwareTypeLength;
229  char hardwareType[MAX_HARDWARE_TYPE_LENGTH + 1]; // allow extra space for null terminating char
230  };
231  struct _STRUCT_PACKED OptionTable {
232  struct Entry {
233  uint8_t value;
234  uint8_t labelLength;
235  char label[]; // Placeholder for char array
236  };
237  beuint16_t flagsAndEntryCount;
238  uint8_t tableNum;
239  Entry entries[];
240  };
241  }
242  }
243 }
244 
245 
247 //
248 // Function declarations
249 //
251 namespace NBWifi
252 {
253  namespace APIMessage
254  {
255  namespace Header
256  {
257  void WriteHeader_APIRequest(
258  PoolPtr messageBuffer,
259  bool additionalFlag,
260  NBWifi::APIMessage::Request::RequestTypes requestType,
261  uint8_t commandID
262  );
263  void WriteHeader_APIResponse(
264  PoolPtr messageBuffer,
265  bool additionalFlag,
266  NBWifi::APIMessage::Response::ResponseTypes responseType,
267  uint8_t commandID,
268  int32_t returnCode
269  );
270  void FixHeader_Length( PoolPtr messageBuffer );
271  void WriteHeader_Data_Raw(
272  PoolPtr messageBuffer, bool additionalFlag, uint16_t length );
273  void WriteHeader_Data_CompressedIP(
274  PoolPtr messageBuffer,
275  bool additionalFlag,
276  uint16_t length,
277  uint8_t connectionID
278  );
279  void WriteCreditReport(
280  PoolPtr messageBuffer,
281  bool additionalFlag,
282  uint16_t length,
283  uint8_t availableCredits
284  );
285  bool VerifyChecksum( NBWifi::APIMessage::Header::lenType lengthAndType );
286  }
287  namespace Request
288  {
289  void WriteMsg_ConfigReq(
290  PoolPtr messageBuffer, const char *ssid,
291  uint8_t ssidLength, const char *passwd,
292  uint8_t passwdLength, uint16_t *optionList,
293  uint8_t optionCount
294  );
295  void WriteMsg_ConnectStart(
296  PoolPtr messageBuffer, uint8_t configNumber,
297  bool scan, uint8_t retryCount
298  );
299  void WriteMsg_SetMAC( PoolPtr messageBuffer, const MACADR *newMAC );
300  void WriteMsg_SetBusSpeed( PoolPtr messageBuffer, uint32_t busSpeed );
301  void WriteMsg_SaveConfig( PoolPtr messageBuffer, uint32_t busSpeed );
302  void WriteMsg_FirmwareChunk(
303  PoolPtr messageBuffer, uint32_t offset,
304  uint16_t dataLen, uint16_t checksum,
305  const uint8_t *data
306  );
307  void WriteMsg_VerifyAndProgFirm(
308  PoolPtr messageBuffer, uint32_t imageLen,
309  const uint32_t *checksum
310  );
311  void WriteMsg_AddRemoveMulticast(
312  PoolPtr messageBuffer, bool AddNotRemove,
313  const MACADR *mac
314  );
315  void WriteMsg_Scan(
316  PoolPtr messageBuffer, uint8_t optionCount,
317  uint16_t *optionList, uint8_t ssidLength,
318  const char *ssid
319  );
320  }
321  namespace Response
322  {
323  void WriteMsg_ScanResult(
324  PoolPtr messageBuffer, bool last,
325  Constants::RadioBand band, Constants::BssType bssType,
326  uint8_t channel, uint8_t security,
327  uint8_t cipher, int16_t rssi,
328  const MACADR *pBssid, const char *ssid,
329  int ssidLength
330  );
331  void WriteMsg_Status(
332  PoolPtr messageBuffer, uint8_t connected,
333  int16_t txPower, int16_t rssi,
334  uint16_t channel, uint32_t maxTxRate,
335  uint32_t security, const MACADR *pBssid,
336  uint8_t bssType, const char *ssid,
337  uint8_t ssidLength
338  );
339  void WriteMsg_DeviceInfo(
340  PoolPtr messageBuffer, uint8_t hardwareMajorRev,
341  uint8_t hardwareMinorRev, uint8_t softwareMajorRev,
342  uint8_t softwareMinorRev, const MACADR *pHardwareID,
343  const char *hardwareType, uint8_t hardwareTypeLength
344  );
345  }
346  }
347 }
348 
349 #endif /* ----- #ifndef __NBWICEDMSGSTRUCTS_H ----- */
NBWifi namespace that encompaces the WiFi driver.
Definition: nbWifiBsp.h:15