Skip to content

Commit

Permalink
If Wifi is not ready, wait
Browse files Browse the repository at this point in the history
... plus some cosmetics
  • Loading branch information
d0k3 committed Apr 18, 2016
1 parent 5022bac commit 4a9b2a1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
Binary file removed A9LHNetComp.cia
Binary file not shown.
35 changes: 28 additions & 7 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include "sochlp.h"
#include "hid.h"

#define PAYLOAD_PATH0 "/arm9testpayload.bin"
#define PAYLOAD_PATH1 "/aurei/payloads/left.bin"

#define NETWORK_PORT 17491
#define ARM9_PAYLOAD_MAX_SIZE 0x80000
#define ZLIB_CHUNK (16 * 1024)
Expand Down Expand Up @@ -108,10 +111,30 @@ s32 recv_arm9_payload (void) {
struct sockaddr_in client_addr;
socklen_t addrlen = sizeof(client_addr);
s32 sflags = 0;
u32 wifi = 0;

// init socket
soc_init();

// wait for wifi to be available
// from: https://github.com/mtheall/ftpd/blob/master/source/ftp.c#L1414
if ((ACU_GetWifiStatus(&wifi) != 0) || (!wifi)) {
wifi = 0;
printf("[x] Waiting for Wifi...\n");
while(aptMainLoop() && !wifi) {
hidScanInput();
if(hidKeysDown() & KEY_B) {
printf("[!] Aborted\n");
return 0;
}

/* update the wifi status */
if (ACU_GetWifiStatus(&wifi) != 0) wifi = 0;
}
if (!wifi)
return 0;
}

if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
printf("[!] Error: socket()\n");
return 0;
Expand Down Expand Up @@ -144,11 +167,9 @@ s32 recv_arm9_payload (void) {
fcntl(sockfd, F_SETFL, sflags | O_NONBLOCK);

hidScanInput();
u32 old_kDown = hidKeysDown();
do {
do {
hidScanInput();
u32 kDown = hidKeysDown();
if (kDown != old_kDown) {
if (hidKeysDown() & KEY_B) {
printf("[!] Aborted\n");
close(sockfd);
return 0;
Expand Down Expand Up @@ -213,8 +234,8 @@ s32 recv_arm9_payload (void) {

// transfer to file
if (arm9payload_size) {
write_to_file("/arm9testpayload.bin", arm9payload_buf, arm9payload_size);
write_to_file("/aurei/payloads/left.bin", arm9payload_buf, arm9payload_size);
write_to_file(PAYLOAD_PATH0, arm9payload_buf, arm9payload_size);
write_to_file(PAYLOAD_PATH1, arm9payload_buf, arm9payload_size);
printf("[x] Success!\n");
}
free(buf);
Expand All @@ -241,7 +262,7 @@ int main () {
gfxSet3D(false);
consoleInit(GFX_TOP, NULL);

printf("[+] A9LH Netload Companion v0.0.3\n\n");
printf("[+] A9LH Netload Companion v0.0.5\n\n");
if (recv_arm9_payload()) {
printf("\n[x] Now rebooting...\n");
quick_reboot();
Expand Down

0 comments on commit 4a9b2a1

Please sign in to comment.