NetBurner 3.1
nbWifiMsgStructs.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 <wifi/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(NB::NBWifiAPIMessage::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 NB
38 {
39  namespace NBWifiAPIMessage
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_SetITUCountry = 0xC,
68  Type_GetStatus = 0xFD,
69  Type_GetDeviceInfo = 0xFE,
70  Type_GetOptionTable = 0xFF
71  } RequestTypes;
72  }
73  namespace Response
74  {
75  typedef enum {
76  Type_Scan_Result = 0x0,
77  Type_Status = 0x1,
78  Type_DeviceInfo = 0x2,
79  Type_OptionTableResp= 0x3,
80  } ResponseTypes;
81  }
82  namespace Internal
83  {
84  typedef enum {
85  Type_Internal_JoinAP = 0x0,
86  Type_Internal_SendStatus = 0x1,
87  Type_Internal_Reconnect = 0x2,
88  } InternalTypes;
89  }
90 
91  }
92 }
93 
95 //
96 // Structure Definitions
97 //
99 namespace NB
100 {
101  namespace NBWifiAPIMessage
102  {
103  // Header structures
104  namespace Header
105  {
106  struct _STRUCT_PACKED lenType {
107  beuint16_t val;
108  beuint16_t xorVal;
109  };
110  struct _STRUCT_PACKED APIRequest {
111  lenType lengthAndType;
112  uint8_t requestType;
113  uint8_t commandID;
114  uint8_t pData[];
115  };
116  struct _STRUCT_PACKED APIResponse {
117  lenType lengthAndType;
118  uint8_t responseType;
119  uint8_t commandID;
120  int32_t returnCode;
121  // beint32_t returnCode;
122  // uint8_t returnCode;
123  uint8_t pData[];
124  };
125  struct _STRUCT_PACKED CreditReport {
126  lenType lengthAndType;
127  uint8_t availableCredits;
128  };
129  struct _STRUCT_PACKED Data_Raw {
130  lenType lengthAndType;
131  uint8_t availableCredits;
132  uint8_t pData[];
133  };
134  struct _STRUCT_PACKED Data_CompressedIP {
135  lenType lengthAndType;
136  uint8_t connectionID;
137  uint8_t availableCredits;
138  uint8_t pData[];
139  };
140  struct _STRUCT_PACKED Internal {
141  lenType lengthAndType;
142  uint8_t messageType;
143  uint8_t commandID;
144  };
145  }
146 
147  // Request structures
148  namespace Request
149  {
150  struct _STRUCT_PACKED ConfigReq {
151  uint8_t optionCount;
152  uint8_t ssidLength;
153  uint8_t passwdLength;
154  uint8_t padding;
155  char options[]; // Placeholder for char array pobe_inter
156  };
157  struct _STRUCT_PACKED ConnectStart {
158  uint8_t configNum;
159  uint8_t flags;
160  uint8_t retryCount;
161  };
162  struct _STRUCT_PACKED Scan {
163  uint8_t optionCount;
164  uint8_t ssidLength;
165  char options[]; // Placeholder for char array pobe_inter
166  };
167  struct _STRUCT_PACKED SetMAC {
168  MACADR newMAC;
169  };
170  struct _STRUCT_PACKED SaveConfig {
171  uint8_t configNum;
172  };
173  struct _STRUCT_PACKED SetBusSpeed {
174  beuint32_t busSpeed;
175  };
176  struct _STRUCT_PACKED FirmwareChunk {
177  beuint32_t offset;
178  beuint16_t length;
179  beuint16_t checksum;
180  uint8_t pData[];
181  };
182  struct _STRUCT_PACKED VerifyAndProgFirm {
183  beuint32_t imageLength;
184  beuint32_t checksum[4];
185  };
186  struct _STRUCT_PACKED AddRemoveMulticast {
187  uint8_t flags;
188  MACADR theMac;
189  };
190  struct _STRUCT_PACKED SetITUCountry {
191  uint8_t length;
192  uint8_t pData[];
193  };
194  struct _STRUCT_PACKED GetTableReq {
195  uint8_t tableNum;
196  };
197  }
198 
199  // Response structures
200  namespace Response
201  {
202  struct _STRUCT_PACKED ScanResult {
203  uint8_t lastAndBand;
204  uint8_t bssType;
205  uint8_t channel;
206  uint8_t security;
207  uint8_t cipher;
208  uint8_t ssidLength;
209  beint16_t rssi;
210  MACADR bssid;
211  char ssid[]; // Placeholder for char array pobe_inter
212  };
213  struct _STRUCT_PACKED Status {
214  uint8_t connected;
215  uint8_t bssType;
216  uint8_t security;
217  uint8_t cipher;
218  beuint32_t maxTxRate;
219  beuint16_t rssi;
220  uint8_t band;
221  uint8_t channel;
222  beuint16_t txPower;
223  MACADR bssid;
224  uint8_t ssidLength;
225  char ssid[]; // Placeholder for char array pobe_inter
226  };
227  struct _STRUCT_PACKED DeviceInfo {
228  uint8_t hardwareMajorRev;
229  uint8_t hardwareMinorRev;
230  uint8_t softwareMajorRev;
231  uint8_t softwareMinorRev;
232  MACADR hardwareID;
233  uint8_t hardwareTypeLength;
234  char hardwareType[MAX_HARDWARE_TYPE_LENGTH + 1]; // allow extra space for null terminating char
235  };
236  struct _STRUCT_PACKED OptionTable {
237  struct Entry {
238  uint8_t value;
239  uint8_t labelLength;
240  char label[]; // Placeholder for char array
241  };
242  beuint16_t flagsAndEntryCount;
243  uint8_t tableNum;
244  Entry entries[];
245  };
246  }
247  }
248 }
249 
250 
252 //
253 // Function declarations
254 //
256 namespace NB
257 {
258  namespace NBWifiAPIMessage
259  {
260  namespace Header
261  {
262  void WriteHeader_APIRequest(
263  PoolPtr messageBuffer,
264  bool additionalFlag,
265  NB::NBWifiAPIMessage::Request::RequestTypes requestType,
266  uint8_t commandID
267  );
268  void WriteHeader_APIResponse(
269  PoolPtr messageBuffer,
270  bool additionalFlag,
271  NB::NBWifiAPIMessage::Response::ResponseTypes responseType,
272  uint8_t commandID,
273  int32_t returnCode
274  );
275  void FixHeader_Length( PoolPtr messageBuffer );
276  void WriteHeader_Data_Raw(
277  PoolPtr messageBuffer, bool additionalFlag, uint16_t length );
278  void WriteHeader_Data_CompressedIP(
279  PoolPtr messageBuffer,
280  bool additionalFlag,
281  uint16_t length,
282  uint8_t connectionID
283  );
284  void WriteCreditReport(
285  PoolPtr messageBuffer,
286  bool additionalFlag,
287  uint16_t length,
288  uint8_t availableCredits
289  );
290  bool VerifyChecksum( NB::NBWifiAPIMessage::Header::lenType lengthAndType );
291  }
292  namespace Request
293  {
294  void WriteMsg_ConfigReq(
295  PoolPtr messageBuffer, const char *ssid,
296  uint8_t ssidLength, const char *passwd,
297  uint8_t passwdLength, uint16_t *optionList,
298  uint8_t optionCount
299  );
300  void WriteMsg_ConnectStart(
301  PoolPtr messageBuffer, uint8_t configNumber,
302  bool scan, uint8_t retryCount
303  );
304  void WriteMsg_SetMAC( PoolPtr messageBuffer, const MACADR *newMAC );
305  void WriteMsg_SetITUCountry( PoolPtr messageBuffer,
306  NB::ITU_Country::CountryCode_t country);
307  void WriteMsg_SetBusSpeed( PoolPtr messageBuffer, uint32_t busSpeed );
308  void WriteMsg_SaveConfig( PoolPtr messageBuffer, uint32_t busSpeed );
309  void WriteMsg_FirmwareChunk(
310  PoolPtr messageBuffer, uint32_t offset,
311  uint16_t dataLen, uint16_t checksum,
312  const uint8_t *data
313  );
314  void WriteMsg_VerifyAndProgFirm(
315  PoolPtr messageBuffer, uint32_t imageLen,
316  const uint32_t *checksum
317  );
318  void WriteMsg_AddRemoveMulticast(
319  PoolPtr messageBuffer, bool AddNotRemove,
320  const MACADR *mac
321  );
322  void WriteMsg_Scan(
323  PoolPtr messageBuffer, uint8_t optionCount,
324  uint16_t *optionList, uint8_t ssidLength,
325  const char *ssid
326  );
327  }
328  namespace Response
329  {
330  void WriteMsg_ScanResult(
331  PoolPtr messageBuffer, bool last,
332  Constants::RadioBand band, Constants::BssType bssType,
333  uint8_t channel, uint8_t security,
334  uint8_t cipher, int16_t rssi,
335  const MACADR *pBssid, const char *ssid,
336  int ssidLength
337  );
338  void WriteMsg_Status(
339  PoolPtr messageBuffer, uint8_t connected,
340  int16_t txPower, int16_t rssi,
341  uint16_t channel, uint32_t maxTxRate,
342  uint32_t security, const MACADR *pBssid,
343  uint8_t bssType, const char *ssid,
344  uint8_t ssidLength
345  );
346  void WriteMsg_DeviceInfo(
347  PoolPtr messageBuffer, uint8_t hardwareMajorRev,
348  uint8_t hardwareMinorRev, uint8_t softwareMajorRev,
349  uint8_t softwareMinorRev, const MACADR *pHardwareID,
350  const char *hardwareType, uint8_t hardwareTypeLength
351  );
352  }
353  }
354 }
355 
356 #endif /* ----- #ifndef __NBWICEDMSGSTRUCTS_H ----- */
Definition: dhcpv6_internal.h:34