comparison megawifi.c @ 1962:16d46ff1f620

Implement CMD_HRNG_GET, CMD_GAMERTAG_GET and CMD_LOG.
author doragasu <doragasu@hotmail.com>
date Sun, 03 May 2020 12:40:37 -0700
parents d14630883b1d
children b3c2dcae7dfc
comparison
equal deleted inserted replaced
1961:d14630883b1d 1962:16d46ff1f620
12 #include <netinet/in.h> 12 #include <netinet/in.h>
13 #include <netdb.h> 13 #include <netdb.h>
14 #endif 14 #endif
15 #include <errno.h> 15 #include <errno.h>
16 #include <fcntl.h> 16 #include <fcntl.h>
17 #include <time.h>
17 #include "genesis.h" 18 #include "genesis.h"
18 #include "net.h" 19 #include "net.h"
19 20
20 enum { 21 enum {
21 TX_IDLE, 22 TX_IDLE,
308 309
309 err: 310 err:
310 freeaddrinfo(res); 311 freeaddrinfo(res);
311 printf("Connection to %s:%s failed, %s\n", host, dst_port, strerror(errno)); 312 printf("Connection to %s:%s failed, %s\n", host, dst_port, strerror(errno));
312 start_reply(mw, CMD_ERROR); 313 start_reply(mw, CMD_ERROR);
314 end_reply(mw);
315 }
316
317 #define AVATAR_BYTES (32 * 48 / 2)
318 static void cmd_gamertag_get(megawifi *mw)
319 {
320 uint32_t id = htonl(1);
321 char buf[AVATAR_BYTES];
322
323 start_reply(mw, CMD_OK);
324 // TODO Get items from config file
325 mw_putraw(mw, (const char*)&id, 4);
326 strncpy(buf, "doragasu on Blastem!", 32);
327 mw_putraw(mw, buf, 32);
328 strncpy(buf, "My cool password", 32);
329 mw_putraw(mw, buf, 32);
330 strncpy(buf, "All your WiFi are belong to me!", 32);
331 mw_putraw(mw, buf, 32);
332 memset(buf, 0, 64); // Telegram token
333 mw_putraw(mw, buf, 64);
334 mw_putraw(mw, buf, AVATAR_BYTES); // Avatar tiles
335 mw_putraw(mw, buf, 32); // Avatar palette
336 end_reply(mw);
337 }
338
339 static void cmd_hrng_get(megawifi *mw)
340 {
341 uint16_t len = (mw->transmit_buffer[4]<<8) + mw->transmit_buffer[5];
342 if (len > (MAX_RECV_SIZE - 4)) {
343 start_reply(mw, CMD_ERROR);
344 end_reply(mw);
345 return;
346 }
347 // Pseudo-random, but who cares
348 start_reply(mw, CMD_OK);
349 srand(time(NULL));
350 for (uint16_t i = 0; i < len; i++) {
351 mw_putc(mw, rand());
352 }
313 end_reply(mw); 353 end_reply(mw);
314 } 354 }
315 355
316 static void process_command(megawifi *mw) 356 static void process_command(megawifi *mw)
317 { 357 {
453 mw_putc(mw, mw->flags); 493 mw_putc(mw, mw->flags);
454 mw_putc(mw, mw->channel_flags >> 8); 494 mw_putc(mw, mw->channel_flags >> 8);
455 mw_putc(mw, mw->channel_flags); 495 mw_putc(mw, mw->channel_flags);
456 end_reply(mw); 496 end_reply(mw);
457 break; 497 break;
498 case CMD_GAMERTAG_GET:
499 cmd_gamertag_get(mw);
500 break;
501 case CMD_LOG:
502 start_reply(mw, CMD_OK);
503 puts((char*)&mw->transmit_buffer[4]);
504 end_reply(mw);
505 break;
506 case CMD_HRNG_GET:
507 cmd_hrng_get(mw);
508 break;
458 case CMD_SERVER_URL_GET: 509 case CMD_SERVER_URL_GET:
459 start_reply(mw, CMD_OK); 510 start_reply(mw, CMD_OK);
460 // FIXME: This should be get from config file 511 // FIXME: This should be get from config file
461 mw_puts(mw, "192.168.1.32"); 512 mw_puts(mw, "192.168.1.32");
462 end_reply(mw); 513 end_reply(mw);