100-add_rtwifi.patch 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. --- a/Makefile
  2. +++ b/Makefile
  3. @@ -15,6 +15,11 @@
  4. IWINFO_CLI_OBJ = iwinfo_cli.o
  5. +ifneq ($(filter rt,$(IWINFO_BACKENDS)),)
  6. + IWINFO_CFLAGS += -DUSE_RTWIFI
  7. + IWINFO_LIB_OBJ += iwinfo_rt_scan.o
  8. +endif
  9. +
  10. ifneq ($(filter wl,$(IWINFO_BACKENDS)),)
  11. IWINFO_CFLAGS += -DUSE_WL
  12. IWINFO_LIB_OBJ += iwinfo_wl.o
  13. --- a/iwinfo_wext.c
  14. +++ b/iwinfo_wext.c
  15. @@ -556,7 +559,11 @@
  16. .phyname = wext_get_phyname,
  17. .assoclist = wext_get_assoclist,
  18. .txpwrlist = wext_get_txpwrlist,
  19. +#ifdef USE_RTWIFI
  20. + .scanlist = rt_get_scanlist,
  21. +#else
  22. .scanlist = wext_get_scanlist,
  23. +#endif
  24. .freqlist = wext_get_freqlist,
  25. .countrylist = wext_get_countrylist,
  26. .close = wext_close
  27. --- /dev/null
  28. +++ b/iwinfo_rt_scan.c
  29. @@ -0,0 +1,147 @@
  30. +#include "iwinfo.h"
  31. +#include "iwinfo_wext.h"
  32. +
  33. +struct survey_table
  34. +{
  35. + char channel[4];
  36. + char ssid[33];
  37. + char bssid[20];
  38. + char security[23];
  39. + char *crypto;
  40. + char signal[6];
  41. +};
  42. +
  43. +struct survey_table st[64];
  44. +int survey_count = 0;
  45. +
  46. +#define RTPRIV_IOCTL_SET (SIOCIWFIRSTPRIV + 0x02)
  47. +void iwpriv(const char *name, const char *key, const char *val)
  48. +{
  49. + int socket_id;
  50. + struct iwreq wrq;
  51. + char data[64];
  52. + snprintf(data, 64, "%s=%s", key, val);
  53. + socket_id = socket(AF_INET, SOCK_DGRAM, 0);
  54. + strcpy(wrq.ifr_ifrn.ifrn_name, name);
  55. + wrq.u.data.length = strlen(data);
  56. + wrq.u.data.pointer = data;
  57. + wrq.u.data.flags = 0;
  58. + ioctl(socket_id, RTPRIV_IOCTL_SET, &wrq);
  59. + close(socket_id);
  60. +}
  61. +
  62. +static void next_field(char **line, char *output, int n) {
  63. + char *l = *line;
  64. + int i;
  65. +
  66. + memcpy(output, *line, n);
  67. + *line = &l[n];
  68. +
  69. + for (i = n - 1; i > 0; i--) {
  70. + if (output[i] != ' ')
  71. + break;
  72. + output[i] = '\0';
  73. + }
  74. +}
  75. +
  76. +#define RTPRIV_IOCTL_GSITESURVEY (SIOCIWFIRSTPRIV + 0x0D)
  77. +void wifi_site_survey(const char *ifname, char* essid, int print)
  78. +{
  79. + char *s = malloc(IW_SCAN_MAX_DATA);
  80. + int ret;
  81. + int socket_id;
  82. + struct iwreq wrq;
  83. + char *line, *start;
  84. + iwpriv(ifname, "SiteSurvey", (essid ? essid : ""));
  85. + sleep(5);
  86. + memset(s, 0x00, IW_SCAN_MAX_DATA);
  87. + strcpy(wrq.ifr_name, ifname);
  88. + wrq.u.data.length = IW_SCAN_MAX_DATA;
  89. + wrq.u.data.pointer = s;
  90. + wrq.u.data.flags = 0;
  91. + socket_id = socket(AF_INET, SOCK_DGRAM, 0);
  92. + ret = ioctl(socket_id, RTPRIV_IOCTL_GSITESURVEY, &wrq);
  93. + close(socket_id);
  94. + if(ret != 0)
  95. + goto out;
  96. + if(wrq.u.data.length < 1)
  97. + goto out;
  98. + /* ioctl result starts with a newline, for some reason */
  99. + start = s;
  100. + while (*start == '\n')
  101. + start++;
  102. + line = strtok((char *)start, "\n");
  103. + line = strtok(NULL, "\n");
  104. + survey_count = 0;
  105. + while(line && (survey_count < 64)) {
  106. + next_field(&line, st[survey_count].channel, sizeof(st->channel));
  107. + next_field(&line, st[survey_count].ssid, sizeof(st->ssid));
  108. + next_field(&line, st[survey_count].bssid, sizeof(st->bssid));
  109. + next_field(&line, st[survey_count].security, sizeof(st->security));
  110. + next_field(&line, st[survey_count].signal, sizeof(st->signal));
  111. + line = strtok(NULL, "\n");
  112. + st[survey_count].crypto = strstr(st[survey_count].security, "/");
  113. + if (st[survey_count].crypto) {
  114. + *st[survey_count].crypto = '\0';
  115. + st[survey_count].crypto++;
  116. + if (print) printf("%s|%s|%s|%s\n",
  117. + st[survey_count].channel, st[survey_count].ssid, st[survey_count].bssid, st[survey_count].security);
  118. + }
  119. + survey_count++;
  120. + }
  121. + if (survey_count == 0 && !print)
  122. + printf("No results");
  123. +out:
  124. + free(s);
  125. +}
  126. +
  127. +/*struct survey_table
  128. +{
  129. + char channel[4];
  130. + char ssid[33];
  131. + char bssid[20];
  132. + char security[23];
  133. + char *crypto;
  134. +};
  135. +*/
  136. +
  137. +int rt_get_scanlist(const char *ifname, char *buf, int *len)
  138. +{
  139. + struct iwinfo_scanlist_entry *e = (struct iwinfo_scanlist_entry *) buf;
  140. + int i = 0;
  141. +
  142. + survey_count = 0;
  143. +
  144. + wifi_site_survey(ifname, NULL, 0);
  145. +
  146. + for (i = 0; i < survey_count; i++) {
  147. + int j;
  148. + for (j = 0; j < 6; j++) {
  149. + e[i].mac[j] = (uint8_t) strtoul(&st[i].bssid[j * 3], NULL, 16);
  150. + }
  151. + strcpy(e[i].ssid, st[i].ssid);
  152. + e[i].channel = atoi(st[i].channel);
  153. + e[i].mode = IWINFO_OPMODE_MASTER;
  154. + e[i].quality = atoi(st[i].signal);
  155. + e[i].quality_max = 100;
  156. + memset(&e[i].crypto, 0, sizeof(struct iwinfo_crypto_entry));
  157. + if (strstr(st[i].security, "WPA")) {
  158. + e[i].crypto.enabled = 1;
  159. + e[i].crypto.auth_suites |= IWINFO_KMGMT_PSK;
  160. + }
  161. + if (!st[i].crypto)
  162. + continue;
  163. + if (strstr(st[i].crypto, "TKIP"))
  164. + e[i].crypto.group_ciphers |= IWINFO_CIPHER_TKIP;
  165. + if (strstr(st[i].crypto, "AES"))
  166. + e[i].crypto.group_ciphers |= IWINFO_CIPHER_AESOCB;
  167. + if (strstr(st[i].security, "WPA2"))
  168. + e[i].crypto.wpa_version = 2;
  169. + else if (strstr(st[i].security, "WPA"))
  170. + e[i].crypto.wpa_version = 1;
  171. + }
  172. + *len = survey_count * sizeof(struct iwinfo_scanlist_entry);
  173. +
  174. + return 0;
  175. +}
  176. +
  177. --- a/iwinfo_wext.h
  178. +++ b/iwinfo_wext.h
  179. @@ -378,5 +378,6 @@
  180. #define IW_IE_KEY_MGMT_NUM 3
  181. int wext_get_scanlist(const char *ifname, char *buf, int *len);
  182. +int rt_get_scanlist(const char *ifname, char *buf, int *len);
  183. #endif