Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 40.47 KB | None | 0 0
  1. /*
  2. * Reaver - Command line processing functions
  3. * Copyright (c) 2011, Tactical Network Solutions, Craig Heffner <cheffner@tacnetsol.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. *
  20. * In addition, as a special exception, the copyright holders give
  21. * permission to link the code of portions of this program with the
  22. * OpenSSL library under certain conditions as described in each
  23. * individual source file, and distribute linked combinations
  24. * including the two.
  25. * You must obey the GNU General Public License in all respects
  26. * for all of the code used other than OpenSSL. * If you modify
  27. * file(s) with this exception, you may extend this exception to your
  28. * version of the file(s), but you are not obligated to do so. * If you
  29. * do not wish to do so, delete this exception statement from your
  30. * version. * If you delete this exception statement from all source
  31. * files in the program, then also delete it here.
  32. */
  33.  
  34. #include "argsparser.h"
  35. #include "pixie.h"
  36.  
  37. #include <stdio.h>
  38. #include <string.h>
  39. #include <stdbool.h>
  40. #include <math.h>
  41. #include <stdlib.h>
  42.  
  43. char* conv (unsigned int pin) {
  44.  
  45. char* c;
  46. c = (char *)malloc(10 * sizeof(char));
  47. int v = 0;
  48. while (pin > 9)
  49. {
  50. c[v++] = (pin % 10) + '0';
  51. pin = pin / 10;
  52. }
  53. c[v++] = pin + '0';
  54. c[v] = '\0';
  55. char t;
  56. int i;
  57. for (i = 0; i < v / 2; i++)
  58. {
  59. t = c[i];
  60. c[i] = c[v - 1 - i];
  61. c[v - 1 - i] = t;
  62. }
  63. v = 0;
  64.  
  65. return c;
  66. free(c);
  67. }
  68.  
  69. bool startsWith(const char *pre, const char *str)
  70. {
  71. size_t lenpre = strlen(pre),
  72. lenstr = strlen(str);
  73. return lenstr < lenpre ? false : strncmp(pre, str, lenpre) == 0;
  74. }
  75.  
  76. int ipow(int base, int exp) {
  77. int result = 1;
  78. while (exp) {
  79. if (exp & 1) {
  80. result *=base;
  81. }
  82. exp >>= 1;
  83. base *= base;
  84. }
  85.  
  86. return result;
  87. }
  88.  
  89. unsigned int nic_from_mac(unsigned int values[6])
  90. {
  91. unsigned int s = 0;
  92. int k = 0;
  93. int i;
  94. for (i = 3; i <= 5; i++) {
  95. s += values[8 - i] * ipow(16, k);
  96. k += 2;
  97. }
  98. return s;
  99. }
  100.  
  101. unsigned int wpss_pin_checksum(unsigned int pin)
  102. {
  103. unsigned int accum = 0;
  104. while (pin)
  105. {
  106. accum += 3 * (pin % 10);
  107. pin /= 10;
  108. accum += pin % 10;
  109. pin /= 10;
  110. }
  111. return (10 - accum % 10) % 10;
  112. }
  113.  
  114. unsigned int dlinkpin(unsigned int nic, bool modified_algorithm)
  115. {
  116. int pin;
  117. if (modified_algorithm) {
  118. pin = ((nic + 1) ^ 0x55AA55);
  119. } else {
  120. pin = (nic ^ 0x55AA55);
  121. }
  122. pin = pin ^ (((pin & 0x0F) << 4) +
  123. ((pin & 0x0F) << 8) +
  124. ((pin & 0x0F) << 12) +
  125. ((pin & 0x0F) << 16) +
  126. ((pin & 0x0F) << 20));
  127.  
  128.  
  129. pin = pin % 10000000;
  130.  
  131. if (pin < 1000000)
  132. {
  133. pin += ((pin % 9) * 1000000) + 1000000;
  134. }
  135.  
  136. pin = ((pin * 10) + wpss_pin_checksum(pin));
  137.  
  138.  
  139. return pin;
  140. }
  141.  
  142. unsigned int twenty_four_bitpin(unsigned int values[6])
  143. {
  144. unsigned int pin = 0;
  145. int k = 0;
  146. int i;
  147. for (i = 3; i <= 5; i++) {
  148. pin += values[8 - i] * ipow(16, k);
  149. k += 2;
  150. }
  151. if (pin >= 10000000) {
  152. pin %= 10000000;
  153. }
  154. pin = ((pin * 10) + wpss_pin_checksum(pin));
  155. return pin;
  156. }
  157.  
  158. unsigned int twenty_eight_bitpin(unsigned int values[6])
  159. {
  160. unsigned int pin = 0;
  161. int k = 0;
  162. int i;
  163. for (i = 3; i <= 5; i++) {
  164. pin += values[8 - i] * ipow(16, k);
  165. k += 2;
  166. }
  167.  
  168. pin += (values[2] % 16) * ipow(16, k);
  169.  
  170. if (pin >= 10000000) {
  171. pin %= 10000000;
  172. }
  173. pin = ((pin * 10) + wpss_pin_checksum(pin));
  174. return pin;
  175. }
  176.  
  177. unsigned int thirty_two_bitpin(unsigned int values[6])
  178. {
  179. unsigned int pin = 0;
  180. int k = 0;
  181. int i;
  182. for (i = 3; i <= 6; i++) {
  183. pin += values[8 - i] * ipow(16, k);
  184. k += 2;
  185. }
  186.  
  187. if (pin >= 10000000) {
  188. pin %= 10000000;
  189. }
  190. pin = ((pin * 10) + wpss_pin_checksum(pin));
  191. return pin;
  192. }
  193.  
  194. unsigned int airocon_realtek(unsigned int values[6])
  195. {
  196. unsigned int p[7], pin = 0;
  197. int i;
  198. for (i = 0; i <= 6; i++) {
  199. p[i] = (values[(i % 6)] + values[(i + 1) % 6]) % 10;
  200. }
  201. for (i = 0; i <= 6; i++) {
  202. pin += p[6 - i] * ipow(10, i);
  203. }
  204.  
  205. pin = ((pin * 10) + wpss_pin_checksum(pin));
  206. return pin;
  207. }
  208.  
  209.  
  210. unsigned int asus_pin(unsigned int values[6])
  211. {
  212. unsigned int p[7], pin = 0;
  213. int i, s = 0;
  214. for (i = 1; i <= 5; i++) {
  215. s += values[i];
  216. }
  217. for (i = 0; i <= 6; i++) {
  218. p[i] = (values[i % 6] + values[5]) % (10 - (i + s) % 7);
  219. }
  220. for (i = 0; i <= 6; i++) {
  221. pin += p[6 - i] * ipow(10, i);
  222. }
  223.  
  224. pin = ((pin * 10) + wpss_pin_checksum(pin));
  225. return pin;
  226. }
  227.  
  228.  
  229. /* Processes Reaver command line options */
  230. int process_arguments(int argc, char **argv)
  231. {
  232. int ret_val = EXIT_SUCCESS;
  233. int c = 0, channel = 0;
  234. int long_opt_index = 0;
  235. char bssid[MAC_ADDR_LEN] = { 0 };
  236. char mac[MAC_ADDR_LEN] = { 0 };
  237. char *short_options = "KZb:e:m:i:t:d:c:T:x:r:g:l:o:p:z:s:C:A5ELfnqvDShwN";
  238. struct option long_options[] = {
  239. { "pixie-dust", no_argument, NULL, 'K' },
  240. { "interface", required_argument, NULL, 'i' },
  241. { "bssid", required_argument, NULL, 'b' },
  242. { "essid", required_argument, NULL, 'e' },
  243. { "mac", required_argument, NULL, 'm' },
  244. { "timeout", required_argument, NULL, 't' },
  245. { "m57-timeout", required_argument, NULL, 'T' },
  246. { "delay", required_argument, NULL, 'd' },
  247. { "lock-delay", required_argument, NULL, 'l' },
  248. { "fail-wait", required_argument, NULL, 'x' },
  249. { "channel", required_argument, NULL, 'c' },
  250. { "session", required_argument, NULL, 's' },
  251. { "recurring-delay", required_argument, NULL, 'r' },
  252. { "max-attempts", required_argument, NULL, 'g' },
  253. { "out-file", required_argument, NULL, 'o' },
  254. { "pin", required_argument, NULL, 'p' },
  255. { "helen", required_argument, NULL, 'z'},
  256. { "exec", required_argument, NULL, 'C' },
  257. { "no-associate", no_argument, NULL, 'A' },
  258. { "ignore-locks", no_argument, NULL, 'L' },
  259. { "no-nacks", no_argument, NULL, 'N' },
  260. { "eap-terminate", no_argument, NULL, 'E' },
  261. { "dh-small", no_argument, NULL, 'S' },
  262. { "fixed", no_argument, NULL, 'f' },
  263. { "daemonize", no_argument, NULL, 'D' },
  264. { "5ghz", no_argument, NULL, '5' },
  265. { "nack", no_argument, NULL, 'n' },
  266. { "quiet", no_argument, NULL, 'q' },
  267. { "verbose", no_argument, NULL, 'v' },
  268. { "win7", no_argument, NULL, 'w' },
  269. { "help", no_argument, NULL, 'h' },
  270. { 0, 0, 0, 0 }
  271. };
  272.  
  273. /* Since this function may be called multiple times, be sure to set opt index to 0 each time */
  274. optind = 0;
  275.  
  276. while((c = getopt_long(argc, argv, short_options, long_options, &long_opt_index)) != -1)
  277. {
  278. switch(c)
  279. {
  280. case 'Z':
  281. case 'K':
  282. pixie.do_pixie = 1;
  283. break;
  284. case 'i':
  285. set_iface(optarg);
  286. break;
  287. case 'b':
  288. str2mac(optarg, (unsigned char *) &bssid);
  289. set_bssid((unsigned char *) &bssid);
  290. break;
  291. case 'e':
  292. set_ssid(optarg);
  293. break;
  294. case 'm':
  295. str2mac(optarg, (unsigned char *) &mac);
  296. set_mac((unsigned char *) &mac);
  297. break;
  298. case 't':
  299. set_rx_timeout(atoi(optarg));
  300. break;
  301. case 'T':
  302. set_m57_timeout(strtof(optarg, NULL) * SEC_TO_US);
  303. break;
  304. case 'c':
  305. channel = strtod(optarg, NULL);
  306. set_fixed_channel(1);
  307. break;
  308. case '5':
  309. set_wifi_band(AN_BAND);
  310. break;
  311. case 'd':
  312. set_delay(atoi(optarg));
  313. break;
  314. case 'l':
  315. set_lock_delay(atoi(optarg));
  316. break;
  317. case 'p':
  318. parse_static_pin(optarg);
  319. break;
  320. case 'z':
  321.  
  322.  
  323. if ((startsWith("F8:D1:11", optarg)) || (startsWith("F8:1A:67", optarg)) ||
  324. (startsWith("B0:48:7A", optarg)) || (startsWith("64:70:02", optarg)) ||
  325. (startsWith("00:A0:26", optarg)) || (startsWith("E4:7C:F9", optarg)) ||
  326. (startsWith("DC:71:44", optarg)) || (startsWith("08:BE:AC", optarg)) ||
  327. (startsWith("D8:6C:E9", optarg)) || (startsWith("5C:A3:9D", optarg)) ||
  328. (startsWith("E2:41:36", optarg)) || (startsWith("B2:46:FC", optarg)) ||
  329. (startsWith("E0:41:36", optarg)) || (startsWith("98:97:D1", optarg)) ||
  330. (startsWith("00:26:CE", optarg)) || (startsWith("72:E8:7B", optarg)) ||
  331. (startsWith("72:D1:5E", optarg)) || (startsWith("00:1C:DF", optarg)) ||
  332. (startsWith("72:CD:BE", optarg)) || (startsWith("72:CB:A8", optarg)) ||
  333. (startsWith("72:C7:14", optarg)) || (startsWith("72:C6:1F", optarg)) ||
  334. (startsWith("72:C0:6F", optarg)) || (startsWith("72:A8:E4", optarg)) ||
  335. (startsWith("72:96:BF", optarg)) || (startsWith("72:7D:5E", optarg)) ||
  336. (startsWith("72:6B:D3", optarg)) || (startsWith("72:55:9C", optarg)) ||
  337. (startsWith("72:53:D4", optarg)) || (startsWith("72:3D:FF", optarg)) ||
  338. (startsWith("72:3C:E4", optarg)) || (startsWith("72:23:3D", optarg)) ||
  339. (startsWith("72:1D:67", optarg)) || (startsWith("6A:D1:67", optarg)) ||
  340. (startsWith("6A:D1:5E", optarg)) || (startsWith("6A:CD:BE", optarg)) ||
  341. (startsWith("6A:CB:A8", optarg)) || (startsWith("6A:C7:14", optarg)) ||
  342. (startsWith("6A:C6:1F", optarg)) || (startsWith("6A:C0:6F", optarg)) ||
  343. (startsWith("6A:A8:E4", optarg)) || (startsWith("6A:7D:5E", optarg)) ||
  344. (startsWith("6A:96:BF", optarg)) || (startsWith("6A:6B:D3", optarg)) ||
  345. (startsWith("6A:55:9C", optarg)) || (startsWith("6A:53:D4", optarg)) ||
  346. (startsWith("6A:3D:FF", optarg)) || (startsWith("6A:23:3D", optarg)) ||
  347. (startsWith("6A:1D:67", optarg)) || (startsWith("64:16:F0", optarg)) ||
  348. (startsWith("62:E8:7B", optarg)) || (startsWith("62:CD:BE", optarg)) ||
  349. (startsWith("62:CB:A8", optarg)) || (startsWith("62:C7:14", optarg)) ||
  350. (startsWith("62:C6:1F", optarg)) || (startsWith("62:C0:6F", optarg)) ||
  351. (startsWith("62:B6:86", optarg)) || (startsWith("62:A8:E4", optarg)) ||
  352. (startsWith("62:96:BF", optarg)) || (startsWith("62:7D:5E", optarg)) ||
  353. (startsWith("62:6B:D3", optarg)) || (startsWith("62:55:9C", optarg)) ||
  354. (startsWith("62:53:D4", optarg)) || (startsWith("62:3D:FF", optarg)) ||
  355. (startsWith("62:3C:E4", optarg)) || (startsWith("62:23:3D", optarg)) ||
  356. (startsWith("5C:4C:A9", optarg)) || (startsWith("30:87:30", optarg)) ||
  357. (startsWith("20:2B:C1", optarg)) || (startsWith("BC:14:01", optarg)) ||
  358. (startsWith("78:8D:F7", optarg)) || (startsWith("68:B6:CF", optarg)) ||
  359. (startsWith("00:26:5B", optarg)) || (startsWith("00:1F:1F", optarg)) ||
  360. (startsWith("00:22:F7", optarg)) || (startsWith("C8:3A:35", optarg)) ||
  361. (startsWith("08:10:75", optarg)) || (startsWith("00:B0:0C", optarg)) ||
  362. (startsWith("08:86:3B", optarg)) || (startsWith("00:22:75", optarg)) ||
  363. (startsWith("90:E6:BA", optarg)) || (startsWith("00:00:B4", optarg)) ||
  364. (startsWith("F4:9F:F3", optarg)) || (startsWith("EC:CB:30", optarg)) ||
  365. (startsWith("D4:6E:5C", optarg)) || (startsWith("24:DF:6A", optarg)) ||
  366. (startsWith("4C:ED:DE", optarg)) || (startsWith("20:08:ED", optarg)) ||
  367. (startsWith("08:7A:4C", optarg)) || (startsWith("00:50:FC", optarg)) ||
  368. (startsWith("BC:F6:85", optarg)) || (startsWith("90:94:E4", optarg)) ||
  369. (startsWith("FE:F5:28", optarg)) || (startsWith("10:7B:EF", optarg)) ||
  370. (startsWith("FC:F5:28", optarg)) || (startsWith("F2:B2:DC", optarg)) ||
  371. (startsWith("EE:43:F6", optarg)) || (startsWith("EC:43:F6", optarg)) ||
  372. (startsWith("EA:28:5D", optarg)) || (startsWith("CC:5D:4E", optarg)) ||
  373. (startsWith("C8:6C:87", optarg)) || (startsWith("B0:B2:DC", optarg)) ||
  374. (startsWith("AA:28:5D", optarg)) || (startsWith("6A:28:5D", optarg)) ||
  375. (startsWith("5C:F4:AB", optarg)) || (startsWith("50:67:F0", optarg)) ||
  376. (startsWith("28:28:5D", optarg)) || (startsWith("14:A9:E3", optarg)) ||
  377. (startsWith("00:E0:18", optarg)) || (startsWith("C0:A0:BB", optarg)) ||
  378. (startsWith("00:0C:6E", optarg)) || (startsWith("00:15:F2", optarg)) ||
  379. (startsWith("00:05:FC", optarg)) || (startsWith("00:11:2F", optarg)) ||
  380. (startsWith("00:11:D8", optarg)) || (startsWith("F4:6D:04", optarg)) ||
  381. (startsWith("00:17:31", optarg)) || (startsWith("00:04:0F", optarg)) ||
  382. (startsWith("10:7B:44", optarg)) || (startsWith("00:13:D4", optarg)) ||
  383. (startsWith("B0:6E:BF", optarg)) || (startsWith("00:1A:92", optarg)) ||
  384. (startsWith("00:1D:60", optarg)) || (startsWith("B8:A3:86", optarg)) ||
  385. (startsWith("EC:22:80", optarg)) || (startsWith("74:DA:38", optarg)) ||
  386. (startsWith("78:F5:FD", optarg)) || (startsWith("80:B6:86", optarg)) ||
  387. (startsWith("40:4D:8E", optarg)) || (startsWith("3C:DF:BD", optarg)) ||
  388. (startsWith("80:71:7A", optarg)) || (startsWith("84:DB:AC", optarg)) ||
  389. (startsWith("E0:19:1D", optarg)) || (startsWith("B8:BC:1B", optarg)) ||
  390. (startsWith("F4:55:9C", optarg)) || (startsWith("04:C0:6F", optarg)) ||
  391. (startsWith("68:A0:F6", optarg)) || (startsWith("B4:30:52", optarg)) ||
  392. (startsWith("58:2A:F7", optarg)) || (startsWith("24:69:A5", optarg)) ||
  393. (startsWith("F4:8E:92", optarg)) || (startsWith("F8:3D:FF", optarg)) ||
  394. (startsWith("40:CB:A8", optarg)) || (startsWith("C8:D1:5E", optarg)) ||
  395. (startsWith("24:00:BA", optarg)) || (startsWith("24:09:95", optarg)) ||
  396. (startsWith("F4:E3:FB", optarg)) || (startsWith("D0:2D:B3", optarg)) ||
  397. (startsWith("5C:7D:5E", optarg)) || (startsWith("4C:8B:EF", optarg)) ||
  398. (startsWith("20:F3:A3", optarg)) || (startsWith("AC:E8:7B", optarg)) ||
  399. (startsWith("F4:C7:14", optarg)) || (startsWith("7C:7D:3D", optarg))) {
  400. unsigned int values[6];
  401.  
  402. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  403.  
  404. parse_static_pin(conv(twenty_four_bitpin(values)));
  405.  
  406.  
  407. } else if ((startsWith("80:1F:02", optarg)) || (startsWith("D4:40:F0", optarg)) ||
  408. (startsWith("CC:96:A0", optarg))) {
  409. unsigned int values[6];
  410.  
  411. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  412.  
  413. parse_static_pin(conv(twenty_eight_bitpin(values)));
  414.  
  415. } else if ((startsWith("30:85:A9", optarg)) || (startsWith("FC:8B:97", optarg)) ||
  416. (startsWith("54:04:A6", optarg)) || (startsWith("14:DA:E9", optarg)) ||
  417. (startsWith("2C:AB:25", optarg)) || (startsWith("C4:A8:1D", optarg)) ||
  418. (startsWith("10:62:EB", optarg)) || (startsWith("00:07:26", optarg))) {
  419. unsigned int values[6];
  420.  
  421. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  422.  
  423. parse_static_pin(conv(thirty_two_bitpin(values)));
  424.  
  425. } else if ((startsWith("FC:75:16", optarg)) ||
  426. (startsWith("00:14:D1", optarg)) || (startsWith("D8:EB:97", optarg)) ||
  427. (startsWith("78:2D:7E", optarg))) {
  428. unsigned int values[6];
  429.  
  430. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  431.  
  432. parse_static_pin(conv(dlinkpin(nic_from_mac(values), false)));
  433.  
  434. } else if ((startsWith("00:18:E7", optarg)) || (startsWith("00:19:5B", optarg)) ||
  435. (startsWith("00:1C:F0", optarg)) || (startsWith("00:1E:58", optarg)) ||
  436. (startsWith("00:21:91", optarg)) || (startsWith("00:22:B0", optarg)) ||
  437. (startsWith("00:24:01", optarg)) || (startsWith("00:26:5A", optarg)) ||
  438. (startsWith("14:D6:4D", optarg)) || (startsWith("C8:BE:19", optarg)) ||
  439. (startsWith("00:50:BA", optarg)) || (startsWith("00:17:9A", optarg)) ||
  440. (startsWith("34:08:04", optarg)) || (startsWith("C8:D3:A3", optarg)) ||
  441. (startsWith("00:80:C8", optarg)) || (startsWith("40:9B:CD", optarg)) ||
  442. (startsWith("00:0F:3D", optarg)) || (startsWith("00:11:95", optarg)) ||
  443. (startsWith("00:15:E9", optarg)) || (startsWith("00:05:5D", optarg)) ||
  444. (startsWith("78:32:1B", optarg)) || (startsWith("00:0D:88", optarg)) ||
  445. (startsWith("00:13:46", optarg)) || (startsWith("74:DA:DA", optarg))) {
  446. unsigned int values[6];
  447.  
  448. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  449.  
  450. parse_static_pin(conv(dlinkpin(nic_from_mac(values), true)));
  451.  
  452. } else if ((startsWith("08:60:6E", optarg)) || (startsWith("08:62:66", optarg)) ||
  453. (startsWith("10:BF:48", optarg)) || (startsWith("10:C3:7B", optarg)) ||
  454. (startsWith("14:DD:A9", optarg)) || (startsWith("1C:87:2C", optarg)) ||
  455. (startsWith("1C:B7:2C", optarg)) || (startsWith("2C:56:DC", optarg)) ||
  456. (startsWith("30:5A:3A", optarg)) || (startsWith("38:2C:4A", optarg)) ||
  457. (startsWith("40:16:7E", optarg)) || (startsWith("50:46:5D", optarg)) ||
  458. (startsWith("54:A0:50", optarg)) || (startsWith("60:45:CB", optarg)) ||
  459. (startsWith("60:A4:4C", optarg)) || (startsWith("74:D0:2B", optarg)) ||
  460. (startsWith("78:24:AF", optarg)) || (startsWith("9C:5C:8E", optarg)) ||
  461. (startsWith("AC:22:0B", optarg)) || (startsWith("AC:9E:17", optarg)) ||
  462. (startsWith("BC:EE:7B", optarg)) || (startsWith("C8:60:00", optarg)) ||
  463. (startsWith("D8:50:E6", optarg)) || (startsWith("E0:3F:49", optarg)) ||
  464. (startsWith("F0:79:59", optarg)) || (startsWith("F8:32:E4", optarg)) ||
  465. (startsWith("00:08:A1", optarg)) || (startsWith("10:FE:ED", optarg)) ||
  466. (startsWith("00:1E:A6", optarg)) || (startsWith("00:30:4F", optarg)) ||
  467. (startsWith("04:8D:38", optarg)) || (startsWith("F4:28:53", optarg)) ||
  468. (startsWith("08:10:78", optarg)) || (startsWith("08:10:79", optarg)) ||
  469. (startsWith("3C:1E:04", optarg)) || (startsWith("C4:12:F5", optarg)) ||
  470. (startsWith("48:EE:0C", optarg)) || (startsWith("54:B8:0A", optarg)) ||
  471. (startsWith("58:7B:E9", optarg)) || (startsWith("60:D1:AA", optarg)) ||
  472. (startsWith("64:51:7E", optarg)) || (startsWith("64:D9:54", optarg)) ||
  473. (startsWith("6C:19:8F", optarg)) || (startsWith("6C:72:20", optarg)) ||
  474. (startsWith("6C:FD:B9", optarg)) || (startsWith("78:D9:9F", optarg)) ||
  475. (startsWith("8C:88:2B", optarg)) || (startsWith("90:F6:52", optarg)) ||
  476. (startsWith("A0:F3:C1", optarg)) || (startsWith("A8:F7:E0", optarg)) ||
  477. (startsWith("AC:A2:13", optarg)) || (startsWith("B8:55:10", optarg)) ||
  478. (startsWith("BC:34:00", optarg)) || (startsWith("70:62:B8", optarg)) ||
  479. (startsWith("D0:0E:D9", optarg)) || (startsWith("D8:FE:E3", optarg)) ||
  480. (startsWith("E8:94:F6", optarg)) || (startsWith("EC:1A:59", optarg)) ||
  481. (startsWith("E8:CC:18", optarg)) || (startsWith("90:8D:78", optarg)) ||
  482. (startsWith("F8:E9:03", optarg)) || (startsWith("E4:6F:13", optarg)) ||
  483. (startsWith("70:4D:7B", optarg)) || (startsWith("88:D7:F6", optarg)) ||
  484. (startsWith("D0:17:C2", optarg)) || (startsWith("38:D5:47", optarg)) ||
  485. (startsWith("2C:4D:54", optarg)) || (startsWith("70:8B:CD", optarg)) ||
  486. (startsWith("B0:C5:54", optarg)) || (startsWith("1C:5F:2B", optarg)) ||
  487. (startsWith("34:97:F6", optarg)) || (startsWith("10:BE:F5", optarg)) ||
  488. (startsWith("A0:AB:1B", optarg)) || (startsWith("80:26:89", optarg))) {
  489. unsigned int values[6];
  490.  
  491. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  492.  
  493. parse_static_pin(conv(asus_pin(values)));
  494.  
  495. } else if ((startsWith("F4:3E:61", optarg)) || (startsWith("78:8C:54", optarg)) ||
  496. (startsWith("94:FB:B2", optarg)) || (startsWith("08:10:73", optarg)) ||
  497. (startsWith("10:13:EE", optarg)) || (startsWith("00:0B:2B", optarg)) ||
  498. (startsWith("02:10:18", optarg)) || (startsWith("00:E0:4B", optarg)) ||
  499. (startsWith("00:1A:EF", optarg)) || (startsWith("00:17:7C", optarg)) ||
  500. (startsWith("00:13:33", optarg)) || (startsWith("00:0E:F4", optarg))) {
  501. unsigned int values[6];
  502.  
  503. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  504.  
  505. parse_static_pin(conv(airocon_realtek(values)));
  506.  
  507. } else if ((startsWith("00:24:8C", optarg)) || (startsWith("00:26:18", optarg)) ||
  508. (startsWith("34:4D:EB", optarg)) || (startsWith("70:71:BC", optarg)) ||
  509. (startsWith("E0:69:95", optarg)) || (startsWith("84:C9:B2", optarg)) ||
  510. (startsWith("E0:CB:4E", optarg)) || (startsWith("00:1B:FC", optarg)) ||
  511. (startsWith("00:1E:8C", optarg)) || (startsWith("00:23:54", optarg)) ||
  512. (startsWith("00:1F:C6", optarg)) || (startsWith("00:18:F3", optarg)) ||
  513. (startsWith("48:5B:39", optarg)) || (startsWith("BC:AE:C5", optarg)) ||
  514. (startsWith("00:0E:A6", optarg)) || (startsWith("20:CF:30", optarg)) ||
  515. (startsWith("00:22:15", optarg)) || (startsWith("00:0E:2E", optarg)) ||
  516. (startsWith("9C:D6:43", optarg)) || (startsWith("48:AD:08", optarg)) ||
  517. (startsWith("2C:AB:00", optarg)) || (startsWith("80:38:BC", optarg)) ||
  518. (startsWith("0C:45:BA", optarg)) || (startsWith("AC:85:3D", optarg)) ||
  519. (startsWith("74:88:2A", optarg)) || (startsWith("78:D7:52", optarg)) ||
  520. (startsWith("E0:24:7F", optarg)) || (startsWith("00:46:4B", optarg)) ||
  521. (startsWith("70:7B:E8", optarg)) || (startsWith("54:89:98", optarg)) ||
  522. (startsWith("08:19:A6", optarg)) || (startsWith("3C:F8:08", optarg)) ||
  523. (startsWith("B4:15:13", optarg)) || (startsWith("28:31:52", optarg)) ||
  524. (startsWith("DC:D2:FC", optarg)) || (startsWith("78:1D:BA", optarg)) ||
  525. (startsWith("D0:3E:5C", optarg)) || (startsWith("F8:98:B9", optarg)) ||
  526. (startsWith("2C:CF:58", optarg)) || (startsWith("E4:C2:D1", optarg)) ||
  527. (startsWith("88:A2:D7", optarg)) || (startsWith("D0:D0:4B", optarg)) ||
  528. (startsWith("90:03:25", optarg)) || (startsWith("58:60:5F", optarg)) ||
  529. (startsWith("2C:9D:1E", optarg)) || (startsWith("C8:8D:83", optarg)) ||
  530. (startsWith("F0:98:38", optarg)) || (startsWith("18:DE:D7", optarg)) ||
  531. (startsWith("04:25:C5", optarg)) || (startsWith("A8:CA:7B", optarg)) ||
  532. (startsWith("EC:4D:47", optarg)) || (startsWith("88:CF:98", optarg)) ||
  533. (startsWith("D8:49:0B", optarg)) || (startsWith("88:86:03", optarg)) ||
  534. (startsWith("F8:E8:11", optarg)) || (startsWith("E0:97:96", optarg)) ||
  535. (startsWith("CC:CC:81", optarg)) || (startsWith("10:1B:54", optarg)) ||
  536. (startsWith("70:54:F5", optarg)) || (startsWith("C0:70:09", optarg)) ||
  537. (startsWith("08:E8:4F", optarg)) || (startsWith("04:BD:70", optarg)) ||
  538. (startsWith("18:C5:8A", optarg)) || (startsWith("00:25:9E", optarg)) ||
  539. (startsWith("D4:94:E8", optarg)) || (startsWith("44:55:B1", optarg)) ||
  540. (startsWith("30:F3:35", optarg)) || (startsWith("74:5A:AA", optarg)) ||
  541. (startsWith("7C:1C:F1", optarg)) || (startsWith("94:DB:DA", optarg)) ||
  542. (startsWith("38:4C:4F", optarg)) || (startsWith("E4:A8:B6", optarg)) ||
  543. (startsWith("24:4C:07", optarg)) || (startsWith("08:C0:21", optarg)) ||
  544. (startsWith("48:43:5A", optarg)) || (startsWith("9C:E3:74", optarg)) ||
  545. (startsWith("04:9F:CA", optarg)) || (startsWith("C8:1F:BE", optarg)) ||
  546. (startsWith("20:3D:B2", optarg)) || (startsWith("48:D5:39", optarg)) ||
  547. (startsWith("A4:C6:4F", optarg)) || (startsWith("48:7B:6B", optarg)) ||
  548. (startsWith("80:D4:A5", optarg)) || (startsWith("38:BC:01", optarg)) ||
  549. (startsWith("04:B0:E7", optarg)) || (startsWith("D4:6A:A8", optarg)) ||
  550. (startsWith("44:6A:2E", optarg)) || (startsWith("48:46:FB", optarg)) ||
  551. (startsWith("2C:55:D3", optarg)) || (startsWith("20:0B:C7", optarg)) ||
  552. (startsWith("54:39:DF", optarg)) || (startsWith("10:47:80", optarg)) ||
  553. (startsWith("30:D1:7E", optarg)) || (startsWith("9C:28:EF", optarg)) ||
  554. (startsWith("7C:60:97", optarg)) || (startsWith("60:DE:44", optarg)) ||
  555. (startsWith("34:00:A3", optarg)) || (startsWith("64:3E:8C", optarg)) ||
  556. (startsWith("E0:36:76", optarg)) || (startsWith("7C:A2:3E", optarg)) ||
  557. (startsWith("E8:BD:D1", optarg)) || (startsWith("FC:E3:3C", optarg)) ||
  558. (startsWith("24:9E:AB", optarg)) || (startsWith("74:A0:63", optarg)) ||
  559. (startsWith("54:51:1B", optarg)) || (startsWith("9C:74:1A", optarg)) ||
  560. (startsWith("04:27:58", optarg)) || (startsWith("48:FD:8E", optarg)) ||
  561. (startsWith("24:44:27", optarg)) || (startsWith("4C:F9:5D", optarg)) ||
  562. (startsWith("70:79:90", optarg)) || (startsWith("C0:BF:C0", optarg)) ||
  563. (startsWith("A0:8C:F8", optarg)) || (startsWith("F8:75:88", optarg)) ||
  564. (startsWith("E8:4D:D0", optarg)) || (startsWith("68:8F:84", optarg)) ||
  565. (startsWith("54:A5:1B", optarg)) || (startsWith("28:6E:D4", optarg)) ||
  566. (startsWith("04:F9:38", optarg)) || (startsWith("FC:48:EF", optarg)) ||
  567. (startsWith("80:FB:06", optarg)) || (startsWith("D4:B1:10", optarg)) ||
  568. (startsWith("CC:53:B5", optarg)) || (startsWith("EC:38:8F", optarg)) ||
  569. (startsWith("BC:9C:31", optarg)) || (startsWith("E4:35:C8", optarg)) ||
  570. (startsWith("F8:BF:09", optarg)) || (startsWith("9C:37:F4", optarg)) ||
  571. (startsWith("BC:62:0E", optarg)) || (startsWith("78:F5:57", optarg)) ||
  572. (startsWith("78:F5:57", optarg)) || (startsWith("E0:28:61", optarg)) ||
  573. (startsWith("C4:47:3F", optarg)) || (startsWith("34:A2:A2", optarg)) ||
  574. (startsWith("20:F1:7C", optarg)) || (startsWith("34:B3:54", optarg)) ||
  575. (startsWith("74:9D:8F", optarg)) || (startsWith("34:6A:C2", optarg)) ||
  576. (startsWith("9C:7D:A3", optarg)) || (startsWith("F0:2F:A7", optarg)) ||
  577. (startsWith("F8:4A:BF", optarg)) || (startsWith("88:3F:D3", optarg)) ||
  578. (startsWith("44:82:E5", optarg)) || (startsWith("70:A8:E3", optarg)) ||
  579. (startsWith("4C:B1:6C", optarg)) || (startsWith("4C:1F:CC", optarg)) ||
  580. (startsWith("48:62:76", optarg)) || (startsWith("AC:4E:91", optarg)) ||
  581. (startsWith("E4:68:A3", optarg))) {
  582. unsigned int values[6];
  583.  
  584. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  585. int pin = 1234567;
  586. pin = (12345670 + wpss_pin_checksum(pin));
  587. parse_static_pin(conv(pin));
  588.  
  589. } else if ((startsWith("AC:F1:DF", optarg)) || (startsWith("EC:62:64", optarg)) ||
  590. (startsWith("98:8B:5D", optarg)) || (startsWith("00:1A:A9", optarg)) ||
  591. (startsWith("14:14:4B", optarg))) {
  592. unsigned int values[6];
  593.  
  594. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  595. int pin = 2017252;
  596. pin = (20172520 + wpss_pin_checksum(pin));
  597. parse_static_pin(conv(pin));
  598.  
  599. } else if ((startsWith("1C:7E:E5", optarg)) || (startsWith("28:10:7B", optarg)) ||
  600. (startsWith("78:54:2E", optarg)) || (startsWith("CC:B2:55", optarg))) {
  601. unsigned int values[6];
  602.  
  603. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  604. int pin = 4626484;
  605. pin = (46264840 + wpss_pin_checksum(pin));
  606. parse_static_pin(conv(pin));
  607.  
  608. } else if ((startsWith("4C:17:EB", optarg)) || (startsWith("20:4E:7F", optarg))) {
  609. unsigned int values[6];
  610.  
  611. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  612. int pin = 6232714;
  613. pin = (62327140 + wpss_pin_checksum(pin));
  614. parse_static_pin(conv(pin));
  615.  
  616. } else if ((startsWith("1C:BD:B9", optarg)) || (startsWith("5C:D9:98", optarg)) ||
  617. (startsWith("F0:7D:68", optarg))) {
  618. unsigned int values[6];
  619.  
  620. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  621. int pin = 6817554;
  622. pin = (68175540 + wpss_pin_checksum(pin));
  623. parse_static_pin(conv(pin));
  624.  
  625. } else if ((startsWith("00:0C:42", optarg)) || (startsWith("00:0E:E8", optarg))) {
  626. unsigned int values[6];
  627.  
  628. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  629. int pin = 9566146;
  630. pin = (95661460 + wpss_pin_checksum(pin));
  631. parse_static_pin(conv(pin));
  632.  
  633. } else if ((startsWith("F8:C0:91", optarg)) || (startsWith("78:44:76", optarg)) ||
  634. (startsWith("3C:8C:F8", optarg)) || (startsWith("D4:BF:7F", optarg))) {
  635. unsigned int values[6];
  636.  
  637. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  638. int pin = 9995604;
  639. pin = (99956040 + wpss_pin_checksum(pin));
  640. parse_static_pin(conv(pin));
  641.  
  642. } else if ((startsWith("00:26:24", optarg)) || (startsWith("44:32:C8", optarg)) ||
  643. (startsWith("88:F7:C7", optarg)) || (startsWith("CC:03:FA", optarg)) ||
  644. (startsWith("00:1D:68", optarg)) || (startsWith("00:1E:69", optarg)) ||
  645. (startsWith("00:14:7F", optarg)) || (startsWith("00:07:C3", optarg))) {
  646. unsigned int values[6];
  647.  
  648. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  649. int pin = 6795814;
  650. pin = (67958140 + wpss_pin_checksum(pin));
  651. parse_static_pin(conv(pin));
  652.  
  653. } else if (startsWith("78:6A:89", optarg)) {
  654. unsigned int values[6];
  655.  
  656. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  657. int pin = 9756922;
  658. pin = (97569220 + wpss_pin_checksum(pin));
  659. parse_static_pin(conv(pin));
  660.  
  661. } else if (startsWith("50:A7:2B", optarg)) {
  662. unsigned int values[6];
  663.  
  664. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  665. int pin = 2079327;
  666. pin = (20793270 + wpss_pin_checksum(pin));
  667. parse_static_pin(conv(pin));
  668.  
  669. } else if (startsWith("00:E0:4C", optarg)) {
  670. unsigned int values[6];
  671.  
  672. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  673. int pin = 4062466;
  674. pin = (40624660 + wpss_pin_checksum(pin));
  675. parse_static_pin(conv(pin));
  676.  
  677. } else if (startsWith("80:3F:5D", optarg)) {
  678. unsigned int values[6];
  679.  
  680. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  681. int pin = 0026686;
  682. pin = (00266860 + wpss_pin_checksum(pin));
  683. parse_static_pin(conv(pin));
  684.  
  685. } else if (startsWith("28:5F:DB", optarg)) {
  686. unsigned int values[6];
  687.  
  688. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  689. int pin = 0582967;
  690. pin = (05829670 + wpss_pin_checksum(pin));
  691. parse_static_pin(conv(pin));
  692.  
  693. } else if (startsWith("08:10:77", optarg)) {
  694. unsigned int values[6];
  695.  
  696. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  697. int pin = 8242515;
  698. pin = (82425150 + wpss_pin_checksum(pin));
  699. parse_static_pin(conv(pin));
  700.  
  701. } else if (startsWith("64:A6:51", optarg)) {
  702. unsigned int values[6];
  703.  
  704. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  705. int pin = 4284174;
  706. pin = (42841740 + wpss_pin_checksum(pin));
  707. parse_static_pin(conv(pin));
  708.  
  709. } else if ((startsWith("10:C6:1F", optarg)) || (startsWith("88:53:D4", optarg)) ||
  710. (startsWith("BC:76:70", optarg))) {
  711. unsigned int values[6];
  712.  
  713. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  714. int pin = 5238273;
  715. pin = (52382730 + wpss_pin_checksum(pin));
  716. parse_static_pin(conv(pin));
  717.  
  718. } else if (startsWith("BC:96:80", optarg)) {
  719. unsigned int values[6];
  720.  
  721. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  722. int pin = 1209418;
  723. pin = (12094180 + wpss_pin_checksum(pin));
  724. parse_static_pin(conv(pin));
  725.  
  726. } else if ((startsWith("88:CE:FA", optarg)) || (startsWith("24:7F:3C", optarg)) ||
  727. (startsWith("00:34:FE", optarg)) || (startsWith("B0:5B:67", optarg)) ||
  728. (startsWith("F4:DC:F9", optarg))) {
  729. unsigned int values[6];
  730.  
  731. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  732. int pin = 0000000;
  733. pin = (00000000 + wpss_pin_checksum(pin));
  734. parse_static_pin(conv(pin));
  735.  
  736. } else if ((startsWith("00:66:4B", optarg)) || (startsWith("08:63:61", optarg)) ||
  737. (startsWith("0C:96:BF", optarg)) || (startsWith("14:B9:68", optarg)) ||
  738. (startsWith("34:6B:D3", optarg)) || (startsWith("60:E7:01", optarg)) ||
  739. (startsWith("88:E3:AB", optarg)) || (startsWith("28:3C:E4", optarg)) ||
  740. (startsWith("9C:C1:72", optarg)) || (startsWith("AC:E2:15", optarg)) ||
  741. (startsWith("D0:7A:B5", optarg)) || (startsWith("CC:A2:23", optarg)) ||
  742. (startsWith("EC:23:3D", optarg)) || (startsWith("E8:CD:2D", optarg)) ||
  743. (startsWith("F8:01:13", optarg)) || (startsWith("34:CD:BE", optarg)) ||
  744. (startsWith("70:72:3C", optarg))) {
  745. unsigned int values[6];
  746.  
  747. sscanf(optarg, "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]);
  748. int pin = 3425928;
  749. pin = (34259280 + wpss_pin_checksum(pin));
  750. parse_static_pin(conv(pin));
  751.  
  752. }
  753.  
  754. break;
  755. case 's':
  756. set_session(optarg);
  757. break;
  758. case 'C':
  759. set_exec_string(optarg);
  760. break;
  761. case 'A':
  762. set_external_association(1);
  763. break;
  764. case 'L':
  765. set_ignore_locks(1);
  766. break;
  767. case 'o':
  768. set_log_file(fopen(optarg, "w"));
  769. break;
  770. case 'x':
  771. set_fail_delay(atoi(optarg));
  772. break;
  773. case 'r':
  774. parse_recurring_delay(optarg);
  775. break;
  776. case 'g':
  777. set_max_pin_attempts(atoi(optarg));
  778. break;
  779. case 'D':
  780. daemonize();
  781. break;
  782. case 'E':
  783. set_eap_terminate(1);
  784. break;
  785. case 'S':
  786. set_dh_small(1);
  787. break;
  788. case 'n':
  789. set_timeout_is_nack(0);
  790. break;
  791. case 'f':
  792. set_fixed_channel(1);
  793. break;
  794. case 'v':
  795. set_debug(get_debug() + 1);
  796. break;
  797. case 'q':
  798. set_debug(CRITICAL);
  799. break;
  800. case 'w':
  801. set_win7_compat(1);
  802. break;
  803. case 'N':
  804. set_oo_send_nack(0);
  805. break;
  806. default:
  807. ret_val = EXIT_FAILURE;
  808. }
  809. }
  810.  
  811. if(channel)
  812. {
  813. change_channel(channel);
  814. }
  815.  
  816. return ret_val;
  817. }
  818.  
  819. /* Initialize some basic config settings */
  820. void init_default_settings(void)
  821. {
  822. set_log_file(stdout);
  823. set_max_pin_attempts(P1_SIZE + P2_SIZE);
  824. set_delay(DEFAULT_DELAY);
  825. set_lock_delay(DEFAULT_LOCK_DELAY);
  826. set_debug(INFO);
  827. set_auto_channel_select(1);
  828. set_timeout_is_nack(1);
  829. set_oo_send_nack(1);
  830. set_wifi_band(BG_BAND);
  831. pixie.do_pixie = 0;
  832. set_pin_string_mode(0);
  833. }
  834.  
  835. /* Parses the recurring delay optarg */
  836. void parse_recurring_delay(char *arg)
  837. {
  838. char *x = NULL, *y = NULL;
  839.  
  840. x = strdup(arg);
  841. y = strchr(x, ':');
  842.  
  843. if(y)
  844. {
  845. memset(y, 0, 1);
  846. y++;
  847.  
  848. set_recurring_delay_count(atoi(x));
  849. set_recurring_delay(atoi(y));
  850. }
  851.  
  852. free(x);
  853. }
  854.  
  855. int is_valid_pin(char *pin)
  856. {
  857. if(!pin)
  858. return 0;
  859.  
  860. int i;
  861. for (i = 0; i < strlen(pin); i++)
  862. {
  863. if(!isdigit(pin[i]))
  864. return 0;
  865. }
  866. if(strlen(pin) == 8)
  867. {
  868. char pin7[8] = { 0 };
  869. char pin8[9] = { 0 };
  870. memcpy((void *) &pin7, pin, sizeof(pin7)-1);
  871. snprintf(pin8, 9, "%s%d", pin7, wps_pin_checksum(atoi(pin7)));
  872. if (strcmp(pin, pin8) != 0)
  873. return 0;
  874. }
  875. return 1;
  876. }
  877.  
  878.  
  879. /* Parse the WPS pin to use into p1 and p2 */
  880. void parse_static_pin(char *pin)
  881. {
  882. int len = 0;
  883. char p1[5] = { 0 };
  884. char p2[4] = { 0 };
  885.  
  886. if(pin)
  887. {
  888. len = strlen(pin);
  889.  
  890. if((len == 4 || len == 7 || len == 8) && is_valid_pin(pin) != 0)
  891. {
  892. memcpy((void *) &p1, pin, sizeof(p1)-1);
  893. set_static_p1((char *) &p1);
  894. set_key_status(KEY2_WIP);
  895.  
  896. if(len > 4)
  897. {
  898. memcpy((void *) &p2, pin+sizeof(p1)-1, sizeof(p2)-1);
  899. set_static_p2((char *) &p2);
  900. }
  901. }
  902. else
  903. {
  904. //cprintf(CRITICAL, "[X] ERROR: Invalid pin specified! Ignoring '%s'.\n", pin);
  905. set_max_pin_attempts(1);
  906. set_pin_string_mode(1);
  907. set_static_p1(pin);
  908. }
  909. }
  910. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement