44 #define MAX_AP_ENTRIES 16
46 static int ApTableSize = 0;
50 #define MAX_AP_STORAGE_ENTRIES 16
52 static int ApStoreTableSize;
54 static aps TempApStorage;
56 static char BtSerialNo[13];
58 static char BrickName[NAME_LENGTH + 1];
60 static char MyIp4Address[16];
62 static char MyBroadCastAdr[16];
64 static char MyHwMacAddress[18];
66 static char LogicalIfName[6];
74 #define WPA_SUPPLICANT_GLOBAL_SOCKET "/var/run/wpa_supplicant-global"
75 #define WPA_SUPPLICANT_CONTROL_SOCKET "/var/run/wpa_supplicant"
82 #define HARDWARE_SEARCH_STRING "ID 0846:9030 NetGear, Inc."
84 #define WIFI_VENDOR_ID "0846"
85 #define WIFI_DONGLE_ID "9030"
93 #define WPA_APPLIKATION_PATH "" // Not defined yet
137 gettimeofday(&TimerStartVal,
NULL);
150 printf(
"We'll try to kill udhcpc\r\n");
152 strcpy(Cmd,
"killall udhcpc &> /dev/null");
157 printf(
"\r\nCmd = %s\r\n", Cmd);
165 printf(
"\r\nThe kill Cmd returns OK!!\r\n");
177 gettimeofday(&DongleCheckStartVal,
NULL);
200 printf(
"%s\n", message);
206 char command_return[10];
207 size_t len_command_return =
sizeof(command_return) - 1;
210 memset(command_return, 0x00, len_command_return);
222 command_return[len_command_return] =
'\0';
238 strcpy(StartCmd,
"./wpa_supplicant -Dwext -i");
239 strcat(StartCmd, IFName);
240 strcat(StartCmd,
" -c");
241 strcat(StartCmd, ConfigPath);
242 strcat(StartCmd,
" -B");
243 strcat(StartCmd,
"&> /dev/null");
247 printf(
"\r\nStart WPA_Supplicant: %s\r\n", StartCmd);
249 return system(StartCmd);
254 char OpenCtrlCmd[64];
255 strcpy(OpenCtrlCmd, CtrlPath);
256 strcat(OpenCtrlCmd, InterFace);
264 FILE *PersistentFile =
NULL;
265 int ArrayIterator = 0;
269 strcat(FileName,
"/");
272 ApStoreTableSize = 0;
273 PersistentFile = fopen(FileName,
"rb");
278 printf(
"\r\nKnownlist:\r\n");
281 if ( PersistentFile !=
NULL )
283 while (fread(&OneApRecord,
sizeof OneApRecord, 1, PersistentFile) == 1)
285 memcpy(&(ApStoreTable[ArrayIterator++]), &OneApRecord,
sizeof(
aps));
290 printf(
"Populating ApStoreTable[x] == KnownList\n\r");
291 printf(
"\r\nApStoreTable[%d].mac_address = %s\r\n", (ArrayIterator - 1), ApStoreTable[ArrayIterator - 1].mac_address);
292 printf(
"\r\nApStoreTable[%d].security = %s\r\n", (ArrayIterator - 1), ApStoreTable[ArrayIterator - 1].security);
293 printf(
"\r\nApStoreTable[%d].friendly_name = %s\r\n", (ArrayIterator - 1), ApStoreTable[ArrayIterator - 1].friendly_name);
294 printf(
"\r\nApStoreTable[%d].pre_shared_key = %s\r\n", (ArrayIterator - 1), ApStoreTable[ArrayIterator - 1].pre_shared_key);
295 printf(
"\r\nApStoreTable[%d].ap_flags = %d\r\n", (ArrayIterator - 1), ApStoreTable[ArrayIterator - 1].ap_flags);
298 fclose(PersistentFile);
299 ApStoreTableSize = ArrayIterator;
308 printf(
"\r\nSimulated KnownList:\r\n");
310 ApStoreTableSize = 5;
312 strcpy(ApStoreTable[0].mac_address,
"00:24:01:43:69:6e");
313 strcpy(ApStoreTable[0].security,
"[WPA2-PSK-CCMP][WPS][ESS]");
314 strcpy(ApStoreTable[0].friendly_name,
"FFF");
315 strcpy(ApStoreTable[0].pre_shared_key,
"dbc9c6cf6d4d8e9405842d2e4ab726f33f10de62c30254ff19512af0f");
318 strcpy(ApStoreTable[1].mac_address,
"00:24:01:43:69:01");
319 strcpy(ApStoreTable[1].security,
"[WPA2]");
320 strcpy(ApStoreTable[1].friendly_name,
"OOO");
321 strcpy(ApStoreTable[1].pre_shared_key,
"");
324 strcpy(ApStoreTable[2].mac_address,
"00:24:01:43:69:02");
325 strcpy(ApStoreTable[2].security,
"[WPA2-PSK-CCMP]");
326 strcpy(ApStoreTable[2].friendly_name,
"AAA");
327 strcpy(ApStoreTable[2].pre_shared_key,
"");
330 strcpy(ApStoreTable[3].mac_address,
"00:24:01:43:69:03");
331 strcpy(ApStoreTable[3].security,
"[WPA2-PSK-CCMP][ESS]");
332 strcpy(ApStoreTable[3].friendly_name,
"JJJ");
333 strcpy(ApStoreTable[3].pre_shared_key,
"");
336 strcpy(ApStoreTable[4].mac_address,
"00:24:01:43:69:04");
337 strcpy(ApStoreTable[4].security,
"[WPA2-PSK][ESS]");
338 strcpy(ApStoreTable[4].friendly_name,
"KKK");
339 strcpy(ApStoreTable[4].pre_shared_key,
"");
364 FILE *PersistentFile =
NULL;
365 int ArrayIterator = 0;
369 strcat(FileName,
"/");
376 printf(
"Persistent FileName = %s ApStoreTableSize = %d\n\r", FileName, ApStoreTableSize);
379 PersistentFile = fopen(FileName,
"wb");
380 if ( PersistentFile !=
NULL )
382 for(ArrayIterator = 0; ArrayIterator < ApStoreTableSize; ArrayIterator++)
385 memcpy(&OneApRecord, &(ApStoreTable[ArrayIterator]),
sizeof(
aps));
392 printf(
"cWiFiStoreKnownApList ApStoreTableSize = %d, ArrayIterator = %d\n\r", ApStoreTableSize, ArrayIterator);
393 printf(
"OneApRecord.ap_flags before: %X\n\r", OneApRecord.
ap_flags);
396 fwrite(&OneApRecord,
sizeof OneApRecord, 1, PersistentFile);
401 printf(
"OneApRecord.ap_flags after, just after save: %X\n\r", OneApRecord.
ap_flags);
402 printf(
"Writing KnownList I.e. ApStoreTable[x] to Persistent file\n\r");
403 printf(
"\r\nApStoreTable[%d].mac_address = %s\r\n", (ArrayIterator), ApStoreTable[ArrayIterator].mac_address);
404 printf(
"\r\nApStoreTable[%d].security = %s\r\n", (ArrayIterator), ApStoreTable[ArrayIterator].security);
405 printf(
"\r\nApStoreTable[%d].friendly_name = %s\r\n", (ArrayIterator), ApStoreTable[ArrayIterator].friendly_name);
406 printf(
"\r\nApStoreTable[%d].pre_shared_key = %s\r\n", (ArrayIterator), ApStoreTable[ArrayIterator].pre_shared_key);
407 printf(
"\r\nApStoreTable[%d].ap_flags = %d\r\n", (ArrayIterator), ApStoreTable[ArrayIterator].ap_flags);
410 RetVal = ApStoreTableSize;
411 fclose(PersistentFile);
419 printf(
"Handle to PersistentFile == NULL :-(\n\r");
429 memcpy(&(ApTable[Destination].mac_address), &TempApStorage,
sizeof(
aps));
434 memcpy(&TempApStorage, &(ApTable[Index].mac_address),
sizeof(
aps));
441 memcpy(&(ApStoreTable[Index - 1]), &(ApStoreTable[Index]),
sizeof(
aps));
448 memcpy(&(ApStoreTable[Index + 1]), &(ApStoreTable[Index]),
sizeof(
aps));
455 memcpy(&(ApTable[Index - 1]), &(ApTable[Index]),
sizeof(
aps));
462 memcpy(&(ApTable[Index + 1]), &(ApTable[Index]),
sizeof(
aps));
472 memcpy(&(ApTable[Index - 1]), &(ApTable[Index]),
sizeof(
aps));
482 size_t LenCmdReturn =
sizeof(CmdReturn) - 1;
487 printf(
"Remove Network called\n\r");
490 memset(CmdReturn, 0x00, LenCmdReturn);
492 if(ctrl_conn !=
NULL)
495 "REMOVE_NETWORK all",
496 strlen(
"REMOVE_NETWORK all"),
501 CmdReturn[LenCmdReturn] =
'\0';
506 printf(
"Remove returns %s - RetVal = %d\n\r", CmdReturn, RetVal);
509 if(strstr(CmdReturn,
"OK") !=
NULL)
514 printf(
"Remove Network returned OK\n\r");
523 printf(
"Remove Network was NOT OK :-(\n\r");
540 struct linger so_linger;
542 so_linger.l_onoff =
TRUE;
543 so_linger.l_linger = 0;
557 printf(
"In the do_while\r\n");
567 printf(
"\r\nError calling Tcp shutdown()\r\n");
592 memcpy(&(ApTable[Index + 1]), &(ApTable[Index]),
sizeof(
aps));
604 if((Index < ApTableSize) && ((ApTable[0].ap_flags &
CONNECTED) != CONNECTED))
606 for(i = Index + 1; i < (ApTableSize + 1); i++)
608 memcpy(&(ApTable[i - 1]), &(ApTable[i]),
sizeof(
aps));
620 if(Index < ApStoreTableSize)
622 for(i = Index; i < (ApStoreTableSize - 1); i++)
624 memcpy(&(ApStoreTable[i]), &(ApStoreTable[i + 1]),
sizeof(
aps));
634 i = SourcePointer - 1;
646 i = SourcePointer - 1;
656 memcpy(&(ApTable[StoreIndex]), &(ApStoreTable[ActualIndex]),
sizeof(
aps));
661 memcpy(&(ApStoreTable[StoreIndex]), &(ApTable[ActualIndex]),
sizeof(
aps));
670 for(i = 0; i < ApStoreTableSize; i++)
672 if(strcmp(ApTable[Index].mac_address, ApStoreTable[i].mac_address) == 0)
695 SourcePointer = ApStoreTableSize;
699 SourcePointer = ApStoreTableSize-1;
714 memcpy(&TempApStorage, &(ApStoreTable[Index].mac_address),
sizeof(
aps));
719 memcpy(&(ApStoreTable[Destination].mac_address), &TempApStorage,
sizeof(
aps));
730 int KnownListIterator;
731 int VisibleListIterator;
733 int KnownCounter = 0;
736 for (KnownListIterator = 0; KnownListIterator < ApStoreTableSize; KnownListIterator++)
738 VisibleListIterator = 0;
743 if(strcmp(ApTable[VisibleListIterator].mac_address, ApStoreTable[KnownListIterator].mac_address) == 0)
751 for(i = VisibleListIterator; i > KnownCounter; i--)
766 VisibleListIterator++;
780 while(Found == FAIL);
790 size_t LenCmdReturn =
sizeof(CmdReturn) - 1;
792 memset(CmdReturn, 0x00, LenCmdReturn);
794 if(ctrl_conn !=
NULL)
802 CmdReturn[LenCmdReturn] =
'\0';
807 printf(
"WiFi terminate : RetVal %d , CmdReturn %s\n\r", RetVal, CmdReturn);
810 if(strstr(CmdReturn,
"OK") !=
NULL)
821 char aCmdReturn[128];
823 size_t LenaCmdReturn =
sizeof(aCmdReturn) - 1;
825 memset(aCmdReturn, 0x00, LenaCmdReturn);
830 printf(
"Beginning of AddNetwork\n\r");
833 if(ctrl_conn !=
NULL)
838 printf(
"Internal in AddNetwork - before the real call\n\r");
843 strlen(
"ADD_NETWORK"),
848 aCmdReturn[LenaCmdReturn] =
'\0';
853 printf(
"Add returns %s - RetVal = %d\n\r", aCmdReturn, RetVal);
856 if((aCmdReturn[0] ==
'0') && (aCmdReturn[1] == 10))
861 printf(
"0 (zero) in return at AddNetwork\n\r");
871 printf(
"AddNetwork NOT OK 0 = %d, 1 = %d !!\r\n", aCmdReturn[0], aCmdReturn[1]);
884 size_t LenCmdReturn =
sizeof(CmdReturn) - 1;
887 memset(CmdReturn, 0x00, LenCmdReturn);
892 printf(
"\n\rEntry of SET_ScanSsidToOne to ONE\n\r");
895 if(ctrl_conn !=
NULL)
897 strcpy(Cmd,
"SET_NETWORK 0 scan_ssid 1");
906 CmdReturn[LenCmdReturn] =
'\0';
911 printf(
"ap_scan: CMD= %s, Return= %s", Cmd, CmdReturn);
914 if(strstr(CmdReturn,
"OK") !=
NULL)
933 size_t LenCmdReturn =
sizeof(CmdReturn) - 1;
936 memset(CmdReturn, 0x00, LenCmdReturn);
941 printf(
"\n\rEntry of SET_SSID in c_wifi\n\r");
944 if(ctrl_conn !=
NULL)
946 strcpy(Cmd,
"SET_NETWORK 0 ssid \"");
958 CmdReturn[LenCmdReturn] =
'\0';
963 printf(
"SetSSID: CMD= %s, Return= %s", Cmd, CmdReturn);
966 if(strstr(CmdReturn,
"OK") !=
NULL)
984 size_t LenCmdReturn =
sizeof(CmdReturn) - 1;
986 memset(CmdReturn, 0x00, LenCmdReturn);
988 if(ctrl_conn !=
NULL)
991 "SET_NETWORK 0 key_mgmt WPA-PSK",
992 strlen(
"SET_NETWORK 0 key_mgmt WPA-PSK"),
997 CmdReturn[LenCmdReturn] =
'\0';
998 if(strstr(CmdReturn,
"OK") !=
NULL)
1011 size_t LenCmdReturn =
sizeof(CmdReturn) - 1;
1013 memset(CmdReturn, 0x00, LenCmdReturn);
1015 if(ctrl_conn !=
NULL)
1018 "SET_NETWORK 0 key_mgmt NONE",
1019 strlen(
"SET_NETWORK 0 key_mgmt NONE"),
1024 CmdReturn[LenCmdReturn] =
'\0';
1025 if(strstr(CmdReturn,
"OK") !=
NULL)
1039 size_t LenCmdReturn =
sizeof(CmdReturn) - 1;
1041 memset(CmdReturn, 0x00, LenCmdReturn);
1043 if(ctrl_conn !=
NULL)
1045 strcpy(Cmd,
"SET_NETWORK 0 psk ");
1055 CmdReturn[LenCmdReturn] =
'\0';
1056 if(strstr(CmdReturn,
"OK") !=
NULL)
1067 RESULT Result = FAIL;
1068 if(!(Index > (ApTableSize - 1)))
1070 strcpy(MacAddr, ApTable[Index].mac_address);
1085 printf(
"\r\nApTable[Index = %d].security before = %s\r\n", Index, ApTable[Index].security);
1088 strcpy(ApTable[Index].security,
"WPA2");
1093 printf(
"\r\nApTable[Index = %d].security after = %s\r\n", Index, ApTable[Index].security);
1103 strcpy(ApTable[Index].security,
"NONE");
1121 RESULT Result = FAIL;
1122 int Index = ApTableSize;
1126 Index = ApTableSize++;
1137 strcpy(ApTable[Index].friendly_name, HiddenApName);
1139 if(strstr(Security,
"WPA2") !=
NULL)
1142 strcpy(ApTable[Index].security,
"WPA2");
1159 RESULT Result = FAIL;
1160 char IwConfigCmd[32];
1163 if(!(Index > (ApTableSize - 1)))
1166 strcpy(IwConfigCmd,
"iwconfig");
1167 strcat(IwConfigCmd,
" ");
1168 strcat(IwConfigCmd, LogicalIfName);
1169 FilePointer = popen(IwConfigCmd,
"r");
1172 char *OneLine =
NULL;
1174 size_t NumberOfBytes;
1176 while((getline(&OneLine, &NumberOfBytes, FilePointer) > 0) && OneLine)
1178 if((OneLine = strstr(OneLine,
"Access Point:")) > 0)
1181 TempPointer = OneLine + 17;
1182 *TempPointer =
'\0';
1183 strcpy(MacAddr, OneLine);
1189 pclose(FilePointer);
1191 strcpy(ApTable[Index].mac_address, MacAddr);
1199 RESULT Result = FAIL;
1201 if(strstr(MyIp4Address,
"???") ==
NULL)
1203 strcpy(IpAddress, MyIp4Address);
1211 RESULT Result = FAIL;
1213 if(strstr(MyHwMacAddress,
"??") ==
NULL)
1215 strcpy(MacAddress, MyHwMacAddress);
1227 RESULT Result = FAIL;
1228 char IfConfigCmd[32];
1229 strcpy(IfConfigCmd,
"ifconfig");
1230 strcat(IfConfigCmd,
" ");
1231 strcat(IfConfigCmd, LogicalIfName);
1232 FILE *FilePointer = popen(IfConfigCmd,
"r");
1240 char *OneLine =
NULL;
1242 size_t NumberOfBytes;
1244 while((getline(&OneLine, &NumberOfBytes, FilePointer) > 0) && OneLine)
1246 if((OneLine = strstr(OneLine,
"HWaddr")) > 0)
1249 TempPointer = OneLine + 17;
1250 *TempPointer =
'\0';
1253 Destination = OneLine;
1257 while(*Source ==
':')
1260 while((*Destination++ = *Source++) !=
'\0');
1261 strcpy(MyHwMacAddress, OneLine);
1267 printf(
"cWiFiFindMacAddr -> MAC adresse = %s\n\r", MyHwMacAddress);
1274 pclose(FilePointer);
1285 RESULT Result = FAIL;
1287 FILE *FilePointer =
NULL;
1288 char FindDongle[10];
1289 char *OneLine =
NULL;
1290 size_t NumberOfBytes;
1292 strcpy(FindDongle,
"lsusb");
1294 FilePointer = popen(FindDongle,
"r");
1298 while((getline(&OneLine, &NumberOfBytes, FilePointer) > 0) && OneLine)
1306 pclose(FilePointer);
1313 FILE *pIdVendor =
NULL;
1314 FILE *pIdProduct =
NULL;
1315 char VendorBuffer[64];
1316 char ProductBuffer[64];
1319 RESULT Result = FAIL;
1321 pIdVendor = fopen(
"/sys/bus/usb/devices/1-1/idVendor",
"r");
1323 pIdProduct = fopen(
"/sys/bus/usb/devices/1-1/idProduct",
"r");
1325 if((pIdVendor !=
NULL) && (pIdProduct !=
NULL))
1327 if(fgets(VendorBuffer,
sizeof (VendorBuffer), pIdVendor) !=
NULL)
1329 if(fgets(ProductBuffer,
sizeof (ProductBuffer), pIdProduct) !=
NULL)
1337 if(pIdVendor !=
NULL)
1340 if(pIdProduct !=
NULL)
1356 RESULT Result = FAIL;
1357 char IfConfigCmd[32];
1358 strcpy(IfConfigCmd,
"ifconfig");
1359 strcat(IfConfigCmd,
" ");
1360 strcat(IfConfigCmd, LogicalIfName);
1365 printf(
"\r\nIfConfigCmd = %s\r\n", IfConfigCmd);
1368 FILE *FilePointer = popen(IfConfigCmd,
"r");
1372 char *OneLine =
NULL;
1374 size_t NumberOfBytes;
1380 while((getline(&OneLine, &NumberOfBytes, FilePointer) > 0) && OneLine)
1382 if((OneLine = strstr(OneLine,
"inet addr:")) > 0)
1385 if ((TempPointer = strchr(OneLine,
' ')) > 0)
1387 *TempPointer =
'\0';
1388 strcpy(MyIp4Address, OneLine);
1390 OneLine = TempPointer + 1;
1391 if((OneLine = strstr(OneLine,
"Bcast:")) > 0)
1394 if ((TempPointer = strchr(OneLine,
' ')) > 0)
1396 *TempPointer =
'\0';
1397 strcpy(MyBroadCastAdr, OneLine);
1398 if(strstr(MyBroadCastAdr,
"0.0.0.0"))
1400 sscanf(MyIp4Address,
"%d.%d.%d.%d", &TempIp3, &TempIp2, &TempIp1, &TempIp0);
1401 sprintf(MyBroadCastAdr,
"%d.%d.%d.%d", TempIp3, TempIp2, TempIp1, 255);
1411 pclose(FilePointer);
1424 printf(
"\r\nIP address = %s\r\n", MyIp4Address);
1430 strcpy(Cmd,
"udhcpc -t5 -A2 -nq -i");
1431 strcat(Cmd, Interface);
1432 strcat(Cmd,
" &> /dev/null");
1437 printf(
"\r\nCmd = %s\r\n", Cmd);
1440 if(system(Cmd) == 0)
1445 printf(
"\r\nsystem(Cmd) == 0\r\n");
1453 printf(
"\r\nAfter cWiFiFindIpAddr()\r\n");
1466 size_t LenCmdReturn =
sizeof(CmdReturn) - 1;
1468 memset(CmdReturn, 0x00, LenCmdReturn);
1470 if(ctrl_conn !=
NULL)
1473 "SET_NETWORK 0 pairwise CCMP TKIP",
1474 strlen(
"SET_NETWORK 0 pairwise CCMP TKIP"),
1479 CmdReturn[LenCmdReturn] =
'\0';
1480 if(strstr(CmdReturn,
"OK") !=
NULL)
1493 size_t LenCmdReturn =
sizeof(CmdReturn) - 1;
1495 memset(CmdReturn, 0x00, LenCmdReturn);
1497 if(ctrl_conn !=
NULL)
1500 "SET_NETWORK 0 group CCMP TKIP",
1501 strlen(
"SET_NETWORK 0 group CCMP TKIP"),
1505 CmdReturn[LenCmdReturn] =
'\0';
1506 if(strstr(CmdReturn,
"OK") !=
NULL)
1521 size_t LenCmdReturn =
sizeof(CmdReturn) - 1;
1523 memset(CmdReturn, 0x00, LenCmdReturn);
1525 if(ctrl_conn !=
NULL)
1528 "SET_NETWORK 0 proto RSN",
1529 strlen(
"SET_NETWORK 0 proto RSN"),
1534 CmdReturn[LenCmdReturn] =
'\0';
1535 if(strstr(CmdReturn,
"OK") !=
NULL)
1548 size_t LenCmdReturn =
sizeof(CmdReturn) - 1;
1550 memset(CmdReturn, 0x00, LenCmdReturn);
1552 if(ctrl_conn !=
NULL)
1556 strlen(
"ENABLE_NETWORK 0"),
1561 CmdReturn[LenCmdReturn] =
'\0';
1562 if(strstr(CmdReturn,
"OK") !=
NULL)
1573 char CmdReturn[256];
1575 size_t LenCmdReturn =
sizeof(CmdReturn) - 1;
1577 memset(CmdReturn, 0x00, LenCmdReturn);
1582 if(ctrl_conn !=
NULL)
1591 CmdReturn[LenCmdReturn] =
'\0';
1596 printf(
"cWiFiWpaStatus = %s\n\r", CmdReturn);
1600 while(strstr(CmdReturn,
"bssid") ==
NULL);
1611 size_t LenCmdReturn =
sizeof(CmdReturn) - 1;
1613 memset(CmdReturn, 0x00, LenCmdReturn);
1615 if(ctrl_conn !=
NULL)
1619 strlen(
"DISCONNECT"),
1625 CmdReturn[LenCmdReturn] =
'\0';
1627 if(strstr(CmdReturn,
"OK") !=
NULL)
1632 printf(
"Disconnect OK\n\r");
1647 size_t LenCmdReturn =
sizeof(CmdReturn) - 1;
1649 memset(CmdReturn, 0x00, LenCmdReturn);
1654 printf(
"Start of Reconnect...\n\r");
1657 if(ctrl_conn !=
NULL)
1661 strlen(
"RECONNECT"),
1665 CmdReturn[LenCmdReturn] =
'\0';
1667 if(strstr(CmdReturn,
"OK") !=
NULL)
1672 printf(
"Reconnect OK\n\r");
1683 RESULT Result = FAIL;
1684 if(strlen(ApTable[Index].friendly_name) >= 1)
1686 strncpy(ApName, ApTable[Index].friendly_name, (
int)(Length - 1));
1691 printf(
"\r\ncWiFiGetName called with Index = %d => %s\r\n", Index, ApTable[Index].friendly_name);
1706 printf(
"\r\nApTable[Index = %d].friendly_name before = %s\r\n", Index, ApTable[Index].friendly_name);
1707 printf(
"\r\nSetName name = %s, Index = %d\r\n", ApName, Index);
1708 if(
WiFiStatus == BUSY) printf(
"\r\nWiFiStatus == BUSY\r\n");
1711 strcpy(ApTable[Index].friendly_name, ApName);
1719 printf(
"\r\nApTable[Index = %d].friendly_name after = %s\r\n", Index, ApTable[Index].friendly_name);
1737 for(j = 1; j < ApTableSize; j++)
1747 shutdown(iSocket, 2);
1751 res = read(iSocket, buffer, 100);
1778 RESULT Result = FAIL;
1779 RESULT LocalResult = FAIL;
1785 printf(
"cWiFiMakeConnectionToAp() with Index %d, WiFiStatus = %d\n\r", Index,
WiFiStatus);
1796 printf(
"Try no: %d\n\r", Tries);
1807 printf(
"AddNetwork returns garbage\n\r");
1816 while((Tries < 3) && (LocalResult == FAIL));
1818 if(LocalResult == FAIL)
1823 printf(
"\r\nERROR_001\r\n");
1835 printf(
"\r\nERROR_002\r\n");
1846 printf(
"\r\nERROR_cWiFiSetScanSsidToOne()\r\n");
1853 if((ApTable[Index].ap_flags &
WPA2) == WPA2)
1858 printf(
"\r\nWPA2 flag set\r\n");
1867 printf(
"\r\nERROR_003\r\n");
1874 if(strlen(ApTable[Index].pre_shared_key) < 1)
1879 printf(
"\r\nERROR_004 pre_shared_key = %s, Index = %d, friendly_name = %s\r\n", ApTable[Index].pre_shared_key, Index, ApTable[Index].friendly_name);
1886 if(
cWiFiSetPsk(ApTable[Index].pre_shared_key) != OK)
1891 printf(
"\r\nERROR_005 pre_shared_key = %s, Index = %d, friendly_name = %s\r\n", ApTable[Index].pre_shared_key, Index, ApTable[Index].friendly_name);
1904 printf(
"\r\nERROR_006\r\n");
1916 printf(
"\r\nERROR_007\r\n");
1928 printf(
"\r\nERROR_008\r\n");
1943 printf(
"\r\nERROR_009\r\n");
1957 printf(
"\r\nERROR_010\r\n");
1970 strcpy(MyIp4Address,
"???");
1981 printf(
"Here is the (new) IP address: %s\n\r", MyIp4Address);
1984 if(strstr(MyIp4Address,
"???") ==
NULL)
1989 printf(
"MyIp4Address is OK - and NOT set to ??? => %s", MyIp4Address);
1998 printf(
"\r\nDid we reach the end with an OK? cWiFiMakeConnectionToAp(Index)\r\n");
2000 printf(
"\r\nResult == OK\r\n");
2002 printf(
"\r\nResult == NOT!!!! OK\r\n");
2013 RESULT Result = FAIL;
2022 printf(
"\r\ncWiFiConnectToAp(int Index = %d)\r\n", Index);
2032 printf(
"\r\ncWiFiMakeConnectionToAp(Index = %d) == OK)\r\n", Index);
2071 printf(
"\r\nConnect FAILed.. READY_FOR_AP_SEARCH again\r\n");
2081 char WpaPassPhraseCmd[64];
2088 printf(
"\r\ncWiFiMakePsk\r\n");
2089 printf(
"\n\rSSID = %s, PassPhrase = %s, Index = %d\r\n", ApSsid, PassPhrase, Index);
2094 strcat(WpaPassPhraseCmd,
"./wpa_passphrase \"");
2095 strcat(WpaPassPhraseCmd, ApSsid);
2096 strcat(WpaPassPhraseCmd,
"\" ");
2097 strcat(WpaPassPhraseCmd, PassPhrase);
2102 printf(
"WpaPassPhraseCmd = ->%s<-\r\n", WpaPassPhraseCmd);
2105 FILE *FilePointer = popen(WpaPassPhraseCmd,
"r");
2110 char *PskLine =
NULL;
2111 size_t NumberOfBytes;
2113 for (i = 0; i < 4; i++)
2115 if(!((getline(&PskLine, &NumberOfBytes, FilePointer) > 0) && PskLine))
2132 printf(
"\r\nPre_Shared_Key Made = %s, %d\r\n", PskLine, NumberOfBytes);
2133 printf(
"\r\nApTable[Index = %d].pre_shared_key = %s before\r\n", Index, ApTable[Index].pre_shared_key);
2136 strcpy(ApTable[Index].pre_shared_key, PskLine + 5);
2137 ApTable[Index].
pre_shared_key[strlen(ApTable[Index].pre_shared_key)- 1] =
'\x0';
2142 printf(
"\r\nApTable[Index = %d].pre_shared_key = %s after store etc.\r\n", Index, ApTable[Index].pre_shared_key);
2143 printf(
"\r\nApTable[Index = %d].ap_flags = %d after store etc.\r\n", Index, ApTable[Index].ap_flags);
2147 pclose(FilePointer);
2156 RESULT Result = FAIL;
2164 printf(
"\r\nWiFiStatus == BUSY\r\n");
2166 printf(
"\r\nWiFiStatus == NOT!!!! BUSY\r\n");
2168 printf(
"\r\nName2Index = %s\r\n", Name);
2176 printf(
"\r\nApTable[%d].friendly_name = %s\r\n", i, ApTable[i].friendly_name);
2179 if(strcmp(ApTable[i].friendly_name, Name) == 0)
2187 printf(
"\r\nOK Index = %d\r\n", i);
2199 printf(
"\r\nName2Index Index = %d\r\n", i);
2210 for (j = 0; j < ApStoreTableSize; j++)
2212 if (strcmp(mac_address,ApStoreTable[j].mac_address) == 0)
2223 int HighestPower = -120;
2229 while(StartIndex < ApTableSize)
2231 for(i = StartIndex; i < ApTableSize; i++)
2233 if(atoi(ApTable[i].signal_level) > HighestPower)
2236 HighestPower = atoi(ApTable[i].signal_level);
2241 memcpy(&TempAp, &(ApTable[StartIndex].mac_address),
sizeof(
aps));
2242 memcpy(&(ApTable[StartIndex].mac_address), &(ApTable[SrcIndex].mac_address),
sizeof(
aps));
2243 memcpy(&(ApTable[SrcIndex].mac_address), &TempAp,
sizeof(
aps));
2246 HighestPower = -120;
2256 int TableEntryPointer = 0;
2257 RESULT Result = FAIL;
2259 char SubElement[129];
2260 char ScanResponse[2048];
2261 size_t LenScanResponse =
sizeof(ScanResponse) - 1;
2265 if (ctrl_conn !=
NULL)
2269 strlen(
"SCAN_RESULTS"),
2277 printf(
"\r\nScanresult:\r\n %s\r\n", ScanResponse);
2280 if((LenScanResponse > 32) && (Status == 0))
2282 ScanResponse[LenScanResponse] =
'\x0a';
2284 StrElement = strtok(ScanResponse,
"\x0a");
2288 StrElement = strtok (
NULL,
"\x09");
2289 if((StrElement !=
NULL) && (StrElement[2] ==
':'))
2291 strcpy(ApTable[TableEntryPointer].mac_address, StrElement);
2293 StrElement = strtok (
NULL,
"\x09");
2294 strcpy(ApTable[TableEntryPointer].frequency, StrElement);
2296 StrElement = strtok (
NULL,
"\x09");
2297 strcpy(ApTable[TableEntryPointer].signal_level, StrElement);
2300 StrElement = strtok (
NULL,
"\x0a");
2302 if(StrElement[strlen(StrElement) - 1] ==
'\x09')
2305 StrElement[strlen(StrElement) - 1] =
'\x00';
2306 strcpy(ApTable[TableEntryPointer].security, StrElement);
2307 strcpy(ApTable[TableEntryPointer].friendly_name,
"??????");
2312 sscanf( StrElement,
"%s", ApTable[TableEntryPointer].security);
2315 strncpy(SubElement, StrElement + strlen(ApTable[TableEntryPointer].security) + 1, (strlen(StrElement) - strlen(ApTable[TableEntryPointer].security)));
2317 SubElement[strlen(StrElement) + 1] = 0x00;
2319 strcpy(ApTable[TableEntryPointer].friendly_name, SubElement);
2323 ApTable[TableEntryPointer].
ap_flags = 0x00;
2329 if(strstr(ApTable[TableEntryPointer].security,
"WPA2") !=
NULL)
2340 TableEntryPointer++;
2347 else EndOfTable = 1;
2349 while(EndOfTable < 1);
2351 ApTableSize = TableEntryPointer;
2353 if(TableEntryPointer > 0)
2358 if(TableEntryPointer > 0)
2374 printf(
"\r\nSimulated Scanned List:\r\n");
2402 strcpy(ApTable[0].mac_address,
"00:24:01:43:69:14");
2403 strcpy(ApTable[0].security,
"[WPA2-PSK][ESS]");
2404 strcpy(ApTable[0].friendly_name,
"XXX");
2405 strcpy(ApTable[0].pre_shared_key,
"");
2408 strcpy(ApTable[1].mac_address,
"00:24:01:43:69:02");
2409 strcpy(ApTable[1].security,
"[WPA2-PSK-CCMP]");
2410 strcpy(ApTable[1].friendly_name,
"AAA");
2411 strcpy(ApTable[1].pre_shared_key,
"");
2414 strcpy(ApTable[2].mac_address,
"00:24:01:43:69:6e");
2415 strcpy(ApTable[2].security,
"[WPA2-PSK-CCMP][WPS][ESS]");
2416 strcpy(ApTable[2].friendly_name,
"FFF");
2417 strcpy(ApTable[2].pre_shared_key,
"dbc9c6cf6d4d8e9405842d2e4ab726f33f10de62c30254ff19512af0f");
2420 strcpy(ApTable[3].mac_address,
"00:24:01:43:69:01");
2421 strcpy(ApTable[3].security,
"[WPA2]");
2422 strcpy(ApTable[3].friendly_name,
"OOO");
2423 strcpy(ApTable[3].pre_shared_key,
"");
2426 strcpy(ApTable[4].mac_address,
"00:24:01:43:69:98");
2427 strcpy(ApTable[4].security,
"");
2428 strcpy(ApTable[4].friendly_name,
"HHH");
2429 strcpy(ApTable[4].pre_shared_key,
"");
2432 strcpy(ApTable[5].mac_address,
"00:24:01:43:69:99");
2433 strcpy(ApTable[5].security,
"");
2434 strcpy(ApTable[5].friendly_name,
"WWW");
2435 strcpy(ApTable[5].pre_shared_key,
"");
2438 printf(
"\rApTable before MERGE:\r\n");
2440 for(k = 0; k < ApTableSize; k++)
2442 printf(
"\rApTable[%d].mac_address = %s\r\n", k, ApTable[k].mac_address);
2443 printf(
"\rApTable[%d].security = %s\r\n", k, ApTable[k].security);
2444 printf(
"\rApTable[%d].friendly_name = %s\r\n", k, ApTable[k].friendly_name);
2445 printf(
"\rApTable[%d].pre_shared_key = %s\r\n", k, ApTable[k].pre_shared_key);
2446 printf(
"\rApTable[%d].ap_flags = %d\r\n", k, ApTable[k].ap_flags);
2451 printf(
"\r\nApTable after MERGE:\r\n");
2452 for(k = 0; k < ApTableSize; k++)
2454 printf(
"\rApTable[%d].mac_address = %s\r\n", k, ApTable[k].mac_address);
2455 printf(
"\rApTable[%d].security = %s\r\n", k, ApTable[k].security);
2456 printf(
"\rApTable[%d].friendly_name = %s\r\n", k, ApTable[k].friendly_name);
2457 printf(
"\rApTable[%d].pre_shared_key = %s\r\n", k, ApTable[k].pre_shared_key);
2458 printf(
"\rApTable[%d].ap_flags = %d\r\n", k, ApTable[k].ap_flags);
2471 printf(
"\r\nStored list OK - STATUS = OK\r\n");
2479 RESULT Result = FAIL;
2481 char ScanResponse[10];
2482 size_t LenScanResponse =
sizeof(ScanResponse) - 1;
2495 if (ctrl_conn !=
NULL)
2505 ScanResponse[LenScanResponse] =
'\0';
2507 if(strstr(ScanResponse,
"OK") !=
NULL)
2514 printf(
"\r\nSCAN list OK - STATUS = BUSY\r\n");
2527 printf(
"\r\nSCAN list FAILED - STATUS = FAIL\r\n");
2553 char PingResponse[32];
2554 size_t Len_PingResponse =
sizeof(PingResponse) - 1;
2556 if (ctrl_conn !=
NULL)
2565 PingResponse[Len_PingResponse] =
'\0';
2566 if(strcmp(PingResponse,
"PONG") == 0)
2577 RESULT Result = FAIL;
2578 char IwConfigCmd[32];
2579 strcpy(IwConfigCmd,
"./iwconfig");
2580 FILE *FilePointer = popen(IwConfigCmd,
"r");
2584 char *OneLine =
NULL;
2585 size_t NumberOfBytes;
2586 while((getline(&OneLine, &NumberOfBytes, FilePointer) > 0) && OneLine)
2588 if(strstr(OneLine,
"IEEE 802"))
2591 strcpy(LogicalIfName, OneLine);
2596 pclose(FilePointer);
2606 printf(
"WiFiStatus => GetResult = %d\n\r",
WiFiStatus);
2613 RESULT Result = FAIL;
2621 RESULT Result = FAIL;
2638 printf(
"Start of cWiFiInitTcpServer()...TCPListenServer = %d \n\r",
TCPListenServer);
2646 printf(
"TCPListenServer == 0 in cWiFiInitTcpServer()...\n\r");
2654 printf(
"\r\nError creating listening socket in cWiFiInitTcpServer()...\r\n");
2663 memset(&servaddr, 0,
sizeof(servaddr));
2664 servaddr.sin_family = AF_INET;
2665 servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
2666 servaddr.sin_port = htons(
TCP_PORT);
2676 Temp = setsockopt(
TCPListenServer, SOL_SOCKET, SO_REUSEADDR, &SetOn,
sizeof(SetOn));
2681 if ( bind(
TCPListenServer, (
struct sockaddr *) &servaddr,
sizeof(servaddr)) < 0 )
2686 printf(
"\r\nError calling bind()\r\n");
2687 printf(
"errno = %d\n\r", errno);
2699 printf(
"\r\nError calling listen()\r\n");
2709 printf(
"\r\nWAITING for a CLIENT.......\r\n");
2719 uint size =
sizeof(servaddr);
2720 RESULT Result = BUSY;
2744 printf(
"\r\nConnected.... :-) %s : %d\r\n", inet_ntoa(servaddr.sin_addr), ntohs(servaddr.sin_port));
2751 printf(
"\r\nNow we're waiting for input TCP ...\r\n");
2759 uint DataWritten = 0;
2760 struct timeval WriteTimeVal;
2768 printf(
"\r\ncWiFiWriteTcp Length: %d\r\n", Length);
2773 if((Buffer[0] == 0) && (Buffer[1] == 0))
2775 printf(
"\r\ncERROR in first 2 entries - WiFiWriteTcp Length: %d\r\n", Length);
2776 for (i = 0; i < Length; i++)
2778 printf(
"\r\nFAIL!!! Buffer[%d] = 0x%x\r\n", i, Buffer[i]);
2785 WriteTimeVal.tv_sec = 0;
2786 WriteTimeVal.tv_usec = 0;
2787 FD_ZERO(&WriteFdSet);
2799 if (DataWritten != Length)
2800 printf(
"\r\nDataWritten = %d, Length = %d\r\n", DataWritten, Length);
2812 RESULT Result = FAIL;
2817 printf(
"\r\nRESET - client disconnected!\r\n");
2828 struct timeval ReadTimeVal;
2833 ReadTimeVal.tv_sec = 0;
2834 ReadTimeVal.tv_usec = 0;
2835 FD_ZERO(&ReadFdSet);
2856 printf(
"TCP_WAIT_ON_START:\r\n");
2864 printf(
"\r\nDataRead = %d, Buffer = \r\n", DataRead);
2868 for (ii = 0; ii < DataRead; ii++)
2870 printf(
"0x%x, ", Buffer[ii]);
2874 printf(
"DataRead shows FAIL: %d", DataRead);
2884 if(strstr((
char*)Buffer,
"ET /target?sn=") > 0)
2889 printf(
"\r\nTCP_WAIT_ON_START and ET /target?sn= found :-) DataRead = %d, Length = %d, Buffer = %s\r\n", DataRead, Length, Buffer);
2912 printf(
"TCP_WAIT_ON_LENGTH:\r\n");
2935 printf(
"\n\r*************** NEW TX *************\r\n");
2936 printf(
"TCP_WAIT_ON_LENGTH TcpRestLen = %d, Length = %d\r\n",
TcpRestLen, Length);
2953 printf(
"DataRead = %d\r\n",DataRead);
2954 printf(
"BufferPointer = %p\r\n", &(Buffer[TcpReadBufPointer]));
2963 TcpReadBufPointer += DataRead;
2983 printf(
"ReadBuffer[%d] = 0x%x\r\n", i, Buffer[i]);
2990 printf(
"TcpRestLen = %d, DataRead incl. 2 = %d, Length = %d\r\n",
TcpRestLen, DataRead, Length);
2999 printf(
"TCP_WAIT_ON_FIRST_CHUNK:\r\n");
3012 printf(
"DataRead = %d\r\n", DataRead);
3022 printf(
"\r\nTCP_WAIT_ON_FIRST_CHUNK TcpRestLen = %d, DataRead incl. 2 = %d, Length = %d\r\n",
TcpRestLen, DataRead, Length);
3032 printf(
"TCP_WAIT_COLLECT_BYTES:\r\n");
3035 TcpReadBufPointer = 0;
3044 printf(
"DataRead = %d\r\n", DataRead);
3062 printf(
"\r\nTCP_WAIT_COLLECT_BYTES TcpRestLen = %d, DataRead incl. 2 = %d, Length = %d\r\n",
TcpRestLen, DataRead, Length);
3080 RESULT Result = FAIL;
3081 struct timeval TimeOutVal;
3083 TimeOutVal.tv_sec = 0;
3084 TimeOutVal.tv_usec = 0;
3086 ServerAddr.sin_addr.s_addr = htonl(INADDR_ANY);
3088 FD_ZERO(&ReadFdSet);
3102 printf(
"\r\nUDP Client - recvfrom() ERROR UdpRxCount < 0!!!!\r\n");
3111 printf(
"\r\nUDP client received the following: \"%s\" message\\r\n",
BufPtr);
3112 printf(
" \r\nfrom port %d, address %s\r\n", ntohs(
ServerAddr.sin_port), inet_ntoa(
ServerAddr.sin_addr));
3124 RESULT Result = FAIL;
3127 ServerAddr.sin_addr.s_addr = inet_addr(MyBroadCastAdr);
3132 printf(
"\r\nUDP BROADCAST to port %d, address %s\r\n", ntohs(
ServerAddr.sin_port), inet_ntoa(
ServerAddr.sin_addr));
3137 sprintf(
Buffer,
"Serial-Number: %s\r\nPort: %d\r\nName: %s\r\nProtocol: EV3\r\n", BtSerialNo,
TCP_PORT, BrickName);
3145 printf(
"\r\nUDP SendTo ERROR : %d\n\r",
UdpTxCount);
3155 printf(
"\r\nUDP Client - SendTo() is OK! UdpTxCount = %d\r\n",
UdpTxCount);
3156 printf(
"\r\nWaiting on a reply from UDP server...zzzzz zzzz - Send UNICAST only to me :-)\r\n");
3166 RESULT Result = FAIL;
3177 printf(
"\r\nUDP Client - socket() error\r\n");
3185 printf(
"\r\nUDP Client - socket() is OK!\r\n");
3186 printf(
"\r\nBroadCast Adr from Ifconfig = %s\r\n", MyBroadCastAdr);
3191 if((
ServerAddr.sin_addr.s_addr = inet_addr(MyBroadCastAdr)) == (
unsigned long)INADDR_NONE)
3196 printf(
"\r\nHOST addr == INADDR_NONE :-( \r\n");
3206 printf(
"\r\nCould not setsockopt SO_BROADCAST\r\n");
3217 printf(
"\r\nSet SOCKET NON-BLOCKING :-)...\r\n");
3227 printf(
"\r\nINIT UDP ServerAddr.sin_port = %d, ServerAddr.sin_addr.s_addr = %s\r\n", ntohs(
ServerAddr.sin_port), inet_ntoa(
ServerAddr.sin_addr));
3239 File = fopen(
"./settings/BTser",
"r");
3252 File = fopen(
"./settings/BrickName",
"r");
3263 char ReadBuffer[64];
3264 const char WhiteSpaces[] =
" ,-;:.";
3266 int RetResult =
FALSE;
3268 pProcModules = fopen(
"/proc/modules",
"r");
3270 while (fgets(ReadBuffer,
sizeof (ReadBuffer), pProcModules) !=
NULL)
3272 DriverName = strtok(ReadBuffer, WhiteSpaces);
3273 if(strcmp(DriverName, NameToCheck) == 0)
3278 printf(
"NameToCheck found: %s\r\n", NameToCheck);
3288 printf(
"NameToCheck NOT found: %s\r\n", NameToCheck);
3292 fclose(pProcModules);
3302 system(
"/sbin/insmod /lib/modules/2.6.33-rc4/kernel/compat/compat.ko");
3305 system(
"/sbin/insmod /lib/modules/2.6.33-rc4/kernel/compat/compat.ko &> /dev/null");
3312 system(
"/sbin/insmod /lib/modules/2.6.33-rc4/kernel/net/wireless/cfg80211.ko");
3315 system(
"/sbin/insmod /lib/modules/2.6.33-rc4/kernel/net/wireless/cfg80211.ko &> /dev/null");
3322 system(
"/sbin/insmod /lib/modules/2.6.33-rc4/kernel/net/mac80211/mac80211.ko");
3325 system(
"/sbin/insmod /lib/modules/2.6.33-rc4/kernel/net/mac80211/mac80211.ko &> /dev/null");
3332 system(
"/sbin/insmod /lib/modules/2.6.33-rc4/kernel/drivers/net/wireless/ath/ath.ko");
3335 system(
"/sbin/insmod /lib/modules/2.6.33-rc4/kernel/drivers/net/wireless/ath/ath.ko &> /dev/null");
3342 system(
"/sbin/insmod /lib/modules/2.6.33-rc4/kernel/drivers/net/wireless/ath/ath9k/ath9k_hw.ko");
3345 system(
"/sbin/insmod /lib/modules/2.6.33-rc4/kernel/drivers/net/wireless/ath/ath9k/ath9k_hw.ko &> /dev/null");
3352 system(
"/sbin/insmod /lib/modules/2.6.33-rc4/kernel/drivers/net/wireless/ath/ath9k/ath9k_common.ko");
3355 system(
"/sbin/insmod /lib/modules/2.6.33-rc4/kernel/drivers/net/wireless/ath/ath9k/ath9k_common.ko &> /dev/null");
3362 system(
"/sbin/insmod /lib/modules/2.6.33-rc4/kernel/drivers/net/wireless/ath/ath9k/ath9k.ko");
3365 system(
"/sbin/insmod /lib/modules/2.6.33-rc4/kernel/drivers/net/wireless/ath/ath9k/ath9k.ko &> /dev/null");
3372 system(
"/sbin/insmod /lib/modules/2.6.33-rc4/kernel/drivers/net/wireless/ath/ath9k/ath9k_htc.ko");
3375 system(
"/sbin/insmod /lib/modules/2.6.33-rc4/kernel/drivers/net/wireless/ath/ath9k/ath9k_htc.ko &> /dev/null");
3385 system(
"/sbin/rmmod ath9k_htc.ko");
3388 system(
"/sbin/rmmod ath9k_htc.ko &> /dev/null");
3395 system(
"/sbin/rmmod ath9k.ko");
3398 system(
"/sbin/rmmod ath9k.ko &> /dev/null");
3405 system(
"/sbin/rmmod ath9k_common.ko");
3408 system(
"/sbin/rmmod ath9k_common.ko &> /dev/null");
3415 system(
"/sbin/rmmod ath9k_hw.ko");
3418 system(
"/sbin/rmmod ath9k_hw.ko &> /dev/null");
3425 system(
"/sbin/rmmod ath.ko");
3428 system(
"/sbin/rmmod ath.ko &> /dev/null");
3435 system(
"/sbin/rmmod mac80211.ko");
3438 system(
"/sbin/rmmod mac80211.ko &> /dev/null");
3445 system(
"/sbin/rmmod cfg80211.ko");
3448 system(
"/sbin/rmmod cfg80211.ko &> /dev/null");
3455 system(
"/sbin/rmmod compat.ko");
3458 system(
"/sbin/rmmod compat.ko &> /dev/null");
3480 printf(
"\n\rOK beacon TX\n\r");
3511 printf(
"\r\nWIFI_INIT, NOT_INIT foer FindMacAddr... %d\r\n",
WiFiStatus);
3519 printf(
"\r\nWIFI_INIT, NOT_INIT efter FindMacAddr... %d\r\n",
WiFiStatus);
3527 printf(
"\r\nWIFI_INIT, NOT_INIT foer system... %d\r\n",
WiFiStatus);
3538 strcpy(Command,
"/var/run/wpa_supplicant/");
3539 strcat(Command, LogicalIfName);
3540 if(stat(Command, &st) == 0)
3545 printf(
"\r\nWIFI_INIT, LOAD_SUPPLICANT => STAT OK %d\r\n",
WiFiStatus);
3549 strcpy(Command,
"ifconfig ");
3550 strcat(Command, LogicalIfName);
3551 strcat(Command,
" down > /dev/null");
3555 strcpy(Command,
"ifconfig ");
3556 strcat(Command, LogicalIfName);
3557 strcat(Command,
" up > /dev/null");
3570 printf(
"\r\nWIFI_INIT, LOAD_SUPPLICANT => Timed out\r\n");
3581 strcpy(Command,
"/var/run/wpa_supplicant/");
3582 strcat(Command, LogicalIfName);
3591 printf(
"\r\nWIFI_INIT, WAIT_ON_INTERFACE => Ping OK %d\r\n",
WiFiStatus);
3604 printf(
"\r\nWIFI_INIT, WAIT_ON_INTERFACE => PING U/S\r\n");
3625 printf(
"\r\nWIFI_INITIATED %d\r\n",
WiFiStatus);
3633 printf(
"\r\nREADY for search -> %d\r\n",
WiFiStatus);
3647 printf(
"\r\nSEARCH_APS:\r\n");
3648 printf(
"\r\ncIndex = %d => %s\r\n", 0, ApTable[0].friendly_name);
3649 printf(
"\r\ncIndex = %d => %s\r\n", 1, ApTable[1].friendly_name);
3650 printf(
"\r\ncIndex = %d => %s\r\n", 2, ApTable[2].friendly_name);
3674 printf(
"\r\nSEARCH_PENDING:\r\n");
3675 printf(
"\r\ncIndex = %d => %s\r\n", 0, ApTable[0].friendly_name);
3676 printf(
"\r\ncIndex = %d => %s\r\n", 1, ApTable[1].friendly_name);
3677 printf(
"\r\ncIndex = %d => %s\r\n", 2, ApTable[2].friendly_name);
3683 printf(
"\r\nSTORED CORRECT:\r\n");
3684 printf(
"\r\ncIndex = %d => %s\r\n", 0, ApTable[0].friendly_name);
3685 printf(
"\r\ncIndex = %d => %s\r\n", 1, ApTable[1].friendly_name);
3686 printf(
"\r\ncIndex = %d => %s\r\n", 2, ApTable[2].friendly_name);
3692 printf(
"\r\nSEARCH DONE\r\n");
3702 printf(
"\r\nAP_LIST_UPDATED ApTableSize = %d:\r\n", ApTableSize);
3703 printf(
"\r\ncIndex = %d => %s\r\n", 0, ApTable[0].friendly_name);
3704 printf(
"\r\ncIndex = %d => %s\r\n", 1, ApTable[1].friendly_name);
3705 printf(
"\r\ncIndex = %d => %s\r\n", 2, ApTable[2].friendly_name);
3724 printf(
"\r\nHer er UDP_NOT_INITIATED\r\n");
3738 printf(
"\r\nLige foer cWiFiInitUdpConnection()\r\n");
3746 printf(
"\r\nUDP connection READY @ INIT_UDP_CONNECTION\r\n");
3766 printf(
"\r\nUDP connection FAILed @ INIT_UDP_CONNECTION\r\n");
3798 printf(
"\r\nTCP init OK @ UDP_CONNECTED\r\n");
3812 printf(
"\r\nTCP_CONNECTED @ TCP_NOT_CONNECTED\r\n");
3829 printf(
"\r\nTCP_CONNECTED @ TCP_CONNECTED.... And then.....\r\n");
3849 printf(
"Check for Dongle....");
3857 printf(
"FAIL!!\n\r");
3880 printf(
"cWiFiGetOnStatus returns: %d\r\n",
WiFiOnStatus);
3887 RESULT Result = FAIL;
3901 printf(
"\r\ncWiFiTurnOn and LOGIC NAME FOUND: %s\r\n", LogicalIfName);
3905 strcpy(Command,
"rm /var/run/wpa_supplicant/");
3906 strcat(Command, LogicalIfName);
3908 strcat(Command,
" &> /dev/null");
3921 printf(
"\r\ncWiFiTurnOn refused ALREADY ON or should be....\r\n");
3931 RESULT Result = FAIL;
3937 printf(
"cWiFiTurnOff called...\r\n");
3942 if (ctrl_conn !=
NULL)
3956 printf(
"cWiFiStoreKnownApList() returned %d\n\r", PC);
3969 printf(
"At TurnOff cWiFiTerminate()-> WiFiStatus == OK\n\r");
3971 printf(
"At TurnOff cWiFiTerminate()-> WiFiStatus == NOT ok\n\r");
3986 printf(
"At TurnOff -> WiFiStatus == OK\n\r");
3988 printf(
"At TurnOff -> WiFiStatus == NOT ok\n\r");
4000 RESULT Result = FAIL;
4008 RESULT Result = FAIL;
4013 printf(
"\r\ncWiFiInit START %d\r\n",
WiFiStatus);
4022 strcpy(MyIp4Address,
"???");
4024 strcpy(MyHwMacAddress,
"??:??:??:??:??:??");
4033 printf(
"\r\nWiFiStatus = %d\r\n",
WiFiStatus);
int cWiFiPopulateKnownApList(void)
void cWiFiSortBySignalLevel()
void cWiFiCleanUpOldStuff(void)
RESULT cWiFiInitTcpServer()
RESULT cWiFiSetProtoRsn(void)
UWORD cWiFiWriteTcp(UBYTE *Buffer, UWORD Length)
RESULT cWiFiGetLogicalName(void)
RESULT cWiFiGetStatus(void)
RESULT cWiFiFindMacAddr(void)
struct wpa_ctrl * cWiFiOpenCtrlInterFace(char *CtrlPath, char *InterFace)
RESULT cWiFiStoreActualApList()
RESULT cWiFiInitUdpConnection(void)
int cWiFiCheckTimer(void)
RESULT cWiFiGetName(char *ApName, int Index, char Length)
void cWiFiMoveDownInList(int Index)
RESULT cWiFiWaitForTcpConnection(void)
struct timeval TimerStartVal TimerCurrentVal
#define HARDWARE_SEARCH_STRING
#define WIFI_PERSISTENT_PATH
#define BRICK_HOSTNAME_LENGTH
#define BLUETOOTH_SER_LENGTH
RESULT cWiFiTcpClose(void)
struct sockaddr_in ServerAddr
#define WPA_APPLIKATION_PATH
void cWiFiSetBrickName(void)
void cWiFiCopyStoreToActual(int StoreIndex, int ActualIndex)
RESULT cWiFiReconnect(void)
RESULT cWiFiSetSsid(char *Ssid)
RESULT cWiFiSetKeyManagToWpa2(void)
RESULT cWiFiKnownDongleAttached(void)
void cWifiMoveAllActualDown(int SourcePointer)
RESULT cWiFiGetOnStatus(void)
RESULT cWiFiTxingBeacons(void)
void cWiFiMoveDownInActualList(int Index)
int cWiFiCheckForLoadedModule(char *NameToCheck)
void cWiFiLoadAthHwModules(void)
RESULT cWiFiSetKeyManagToNone(void)
void cWiFiStartDongleCheckTimer(void)
RESULT cWiFiSetScanSsidToOne(void)
RESULT cWiFiAddHidden(char *HiddenApName, char *Security, char *PassWord)
void cWiFiRestoreStorageApRecord(int Destination)
struct timeval DongleCheckStartVal DongleCheckCurrentVal
RESULT cWiFiDeepDongleSearch(void)
int cWiFiStartWpaSupplicant(char *ConfigPath, char *IFName)
void cWiFiMoveUpInActualList(int Index)
int do_wpa_command(struct wpa_ctrl *control, char *command)
#define AP_FLAG_ADJUST_FOR_STORAGE
RESULT cWiFiFindIpAddr(void)
void cWiFiDeleteInStoreList(int Index)
int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len, char *reply, size_t *reply_len, void(*msg_cb)(char *msg, size_t len))
void cWiFiRestoreActualApRecord(int Destination)
RESULT cWiFiCheckAndDelete(int Index)
void wpa_ctrl_close(struct wpa_ctrl *ctrl)
#define WIFI_INIT_TIMEOUT
void cWiFiUdpClientClose(void)
void cWiFiDeleteAsKnown(int LocalIndex)
RESULT cWiFiTerminate(void)
RESULT cWiFiGetIpAddr(char *IpAddress)
void cWiFiClearExceptZero()
struct sockaddr_in servaddr client_addr
void cWiFiAddToKnownApList(int Index)
void cWiFiSetKnown(int Index)
void cWiFiDeleteInList(int Index)
RESULT cWiFiSetName(char *ApName, int Index)
RESULT cWiFiSetEnableNetwork(void)
RESULT cWiFiMakeConnectionToAp(int Index)
struct wpa_ctrl * wpa_ctrl_open(const char *ctrl_path)
RESULT cWiFiConnectToAp(int Index)
RESULT cWiFiTransmitBeacon(void)
RESULT cWiFiRequestIpAdr(char *Interface)
RESULT cWiFiTurnOff(void)
void cWiFiSetBtSerialNo(void)
void cWiFiUnLoadAthHwModules(void)
void cWiFiStartTimer(void)
RESULT cWiFiDisconnect(void)
RESULT cWiFiRemoveNetwork(void)
RESULT cWiFiAddNetwork(void)
RESULT cWiFiKillUdHcPc(void)
unsigned char UBYTE
Basic Type used to symbolise 8 bit unsigned values.
int cWiFiIsItAFriend(char *mac_address)
char pre_shared_key[PSK_LENGTH]
RESULT cWiFiGetIndexFromName(char *Name, UBYTE *Index)
unsigned short UWORD
Basic Type used to symbolise 16 bit unsigned values.
RESULT cWiFiSetPairWiseCcmp(void)
#define MAX_AP_STORAGE_ENTRIES
RESULT cWiFiGetHiddenMacAddr(char *MacAddr, int Index)
int cWiFiTimeFromLastDongleCheck(void)
void cWiFiMoveUpInStoreList(int Index)
void cWiFiSetEncryptToNone(int Index)
void cWiFiMoveAllStoreDown(int SourcePointer)
void cWiFiCopyActualToStore(int ActualIndex, int StoreIndex)
int cWiFiGetApListSize(void)
RESULT cWiFiMakePsk(char *ApSsid, char *PassPhrase, int Index)
void cWiFiMoveUpInList(int Index)
unsigned char cWiFiGetFlags(int Index)
RESULT cWiFiSetGroupCcmp(void)
void cWiFiMoveDownInStoreList(int Index)
void cWiFiPreserveActualApRecord(int Index)
RESULT cWiFiMergeActualAndKnownTable(void)
void cWiFiSetEncryptToWpa2(int Index)
RESULT cWiFiGetMyMacAddr(char *MacAddress)
RESULT cWiFiResetTcp(void)
UWORD cWiFiReadTcp(UBYTE *Buffer, UWORD Length)
RESULT cWiFiSetPsk(char *Psk)
void cWiFiPreserveStorageApRecord(int Index)
UBYTE TcpReadBuffer[1024]
RESULT cWiFiBeaconAnswer(void)
void cWiFiIncApListSize(void)
int cWiFiStoreKnownApList(void)
#define TIME_FOR_WIFI_DONGLE_CHECK
RESULT cWiFiGetApMacAddr(char *MacAddr, int Index)
#define WIFI_PERSISTENT_FILENAME
void cWiFiTcpShutDown(int iSocket)
RESULT cWiFiTcpConnected(void)
void wpa_control_message_callback(char *message, size_t length)
RESULT cWiFiWpaStatus(void)