apSearch.pp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. program apSearch;
  2. {$mode objfpc}
  3. uses
  4. ctypes, nds9, dswifi9;
  5. procedure findAP(ap: pWifi_AccessPoint);
  6. var
  7. selected, i, count: integer;
  8. ap2: Wifi_AccessPoint;
  9. begin
  10. selected := 0;
  11. count := 0;
  12. Wifi_ScanMode(); //this allows us to search for APs
  13. while ((keysDown() and KEY_A) = 0) do
  14. begin
  15. scanKeys();
  16. //find out how many APs there are in the area
  17. count := Wifi_GetNumAP();
  18. consoleClear();
  19. iprintf('Number of APs found: %d'#10, count);
  20. //display the APs to the user
  21. for i := 0 to count - 1 do
  22. begin
  23. Wifi_GetAPData(i, @ap2);
  24. // display the name of the AP
  25. if i = selected then
  26. iprintf('%s %s'#10, '*', pcchar(ap2.ssid))
  27. else
  28. iprintf('%s %s'#10, ' ', pcchar(ap2.ssid));
  29. end;
  30. //move the selection asterick
  31. if ((keysDown() and KEY_UP) <> 0) and (selected > 0) then
  32. dec(selected);
  33. if ((keysDown() and KEY_DOWN) <> 0) and (selected < (count-1)) then
  34. inc(selected);
  35. swiWaitForVBlank();
  36. end;
  37. //user has made a choice so grab the ap and return it
  38. Wifi_GetAPData(selected, ap);
  39. end;
  40. //---------------------------------------------------------------------------------
  41. procedure keyPressed(c: cint);
  42. begin
  43. if (c > 0) then
  44. iprintf('%c', c);
  45. end;
  46. var
  47. ap3: pWifi_AccessPoint;
  48. status: integer;
  49. kb: pKeyboard;
  50. oldStatus: integer;
  51. url: array [0..255] of char;
  52. host: phostent;
  53. begin
  54. status := integer(ASSOCSTATUS_DISCONNECTED);
  55. consoleDemoInit();
  56. new(kb);
  57. kb := keyboardDemoInit();
  58. kb^.OnKeyPressed := @keyPressed;
  59. Wifi_InitDefault(false);
  60. findAP(ap3);
  61. iprintf('Connecting to %s'#10, pcchar(ap3^.ssid));
  62. //this tells the wifi lib to use dhcp for everything
  63. Wifi_SetIP(0,0,0,0,0);
  64. Wifi_ConnectAP(ap3, integer(WEPMODE_NONE), 0, nil);
  65. while (status <> integer(ASSOCSTATUS_ASSOCIATED)) and (status <> integer(ASSOCSTATUS_CANNOTCONNECT)) do
  66. begin
  67. oldStatus := status;
  68. status := Wifi_AssocStatus();
  69. if oldStatus <> status then
  70. iprintf('%s', pchar(@ASSOCSTATUS_STRINGS[status]))
  71. else
  72. iprintf('%s', '.');
  73. swiWaitForVBlank();
  74. end;
  75. consoleClear();
  76. consoleSetWindow(nil, 0,0,32,10);
  77. while true do
  78. begin
  79. iprintf('Url? ');
  80. scanf('%s', url);
  81. host := gethostbyname(url);
  82. if (host) <> nil then
  83. iprintf('IP (%s) : %s'#10, url, inet_ntoa(in_addr(host^.h_addr_list^)))
  84. else
  85. iprintf('Could not resolve'#10);
  86. swiWaitForVBlank();
  87. end;
  88. end.