static void adhocDisconnect(void) { char message[256]; sprintf(message, TEXT(DISCONNECTING_FROM_x), TEXT(LOBBY)); adhoc_init_progress(8, message); sceNetAdhocMatchingStop(matchingId); update_progress(); sceNetAdhocMatchingDelete(matchingId); update_progress(); sceNetAdhocMatchingTerm(); update_progress(); sceNetAdhocctlDisconnect(); update_progress(); sceNetAdhocPdpDelete(pdpId, 0); update_progress(); sceNetAdhocctlTerm(); update_progress(); sceNetAdhocTerm(); update_progress(); sceNetTerm(); update_progress(); show_progress(TEXT(DISCONNECTED)); adhoc_initialized = 0; }
int AdhocMatchingShutdown(void) { int ret = sceNetAdhocMatchingStop(AdhocMatchingId); if(ret < 0) { printf("Adhoc error: sceNetAdhocMatchingStop\n"); return 0; } ret = sceNetAdhocMatchingDelete(AdhocMatchingId); if(ret < 0) { printf("Adhoc error: sceNetAdhocMatchingDelete\n"); return 0; } ret = sceNetAdhocMatchingTerm(); if(ret < 0) { printf("Adhoc error: sceNetAdhocMatchingTerm\n"); return 0; } return 1; }
int pspAdhocShutdown() { if (_net_init) { if (_net_adhoc_init) { if (_net_adhoc_ctl_init) { if (_net_adhoc_ctl_connect) { if (_net_adhoc_pdp_create) { if (_net_adhoc_matching_init) { if (_net_adhoc_matching_create) { if (_net_adhoc_matching_start) { sceNetAdhocMatchingStop(_matching_id); _net_adhoc_matching_start = 0; } sceNetAdhocMatchingDelete(_matching_id); _net_adhoc_matching_create = 0; } sceNetAdhocMatchingTerm(); _net_adhoc_matching_init = 0; } sceNetAdhocPdpDelete(_pdp_id, 0); _net_adhoc_pdp_create = 0; } sceNetAdhocctlDisconnect(); _net_adhoc_ctl_connect = 0; } sceNetAdhocctlTerm(); _net_adhoc_ctl_init = 0; } sceNetAdhocTerm(); _net_adhoc_init = 0; } sceNetTerm(); _net_init = 0; } return 1; }
// The order that procedures are called was taken by patching // Lumines network procs int adhocTerm() { u32 err; if(g_NetAdhocctlConnect) { printf2("sceNetAdhocctlDisconnect\n"); err = sceNetAdhocctlDisconnect(); if(err != 0) { pspDebugScreenInit(); printf(" returned %x\n", err); } g_NetAdhocctlConnect = false; } if(g_NetAdhocPdpCreate) { printf2("sceNetAdhocPdpDelete\n"); err = sceNetAdhocPdpDelete(pdpId,0); if(err != 0) { pspDebugScreenInit(); printf("sceNetAdhocPdpDelete returned %x\n", err); } g_NetAdhocPdpCreate = false; } if(g_NetAdhocMatchingStart) { printf2("sceNetAdhocMatchingStop\n"); err = sceNetAdhocMatchingStop(matchingId); if(err != 0) { pspDebugScreenInit(); printf("sceNetAdhocMatchingStop returned %x\n", err); } g_NetAdhocMatchingStart = false; } if(g_NetAdhocMatchingCreate) { printf2("sceNetAdhocMatchingDelete\n"); err = sceNetAdhocMatchingDelete(matchingId); if(err != 0) { pspDebugScreenInit(); printf("sceNetAdhocMatchingDelete returned %x\n", err); } g_NetAdhocMatchingCreate = false; } if(g_NetAdhocMatchingInit) { printf2("sceNetAdhocMatchingTerm\n"); err = sceNetAdhocMatchingTerm(); if(err != 0) { pspDebugScreenInit(); printf("sceNetAdhocMatchingTerm returned %x\n", err); } g_NetAdhocMatchingInit = false; } if(g_NetAdhocctlInit) { printf2("sceNetAdhocctlTerm\n"); err = sceNetAdhocctlTerm(); if(err != 0) { pspDebugScreenInit(); printf("sceNetAdhocctlTerm returned %x\n", err); } g_NetAdhocctlInit = false; } if(g_NetAdhocInit) { printf2("sceNetAdhocTerm\n"); err = sceNetAdhocTerm(); if(err != 0) { pspDebugScreenInit(); printf("sceNetAdhocTerm returned %x\n", err); } g_NetAdhocInit = false; } if(g_NetInit) { printf2("sceNetTerm\n"); err = sceNetTerm(); if(err != 0) { pspDebugScreenInit(); printf("sceNetTerm returned %x\n", err); } g_NetInit = false; } return 0; // assume it worked }
int adhocReconnect(char *ssid) { int err = 0; // Disconnect Wifi if(g_NetAdhocctlConnect) { printf2("sceNetAdhocctlDisconnect\n"); err = sceNetAdhocctlDisconnect(); if(err != 0) { pspDebugScreenInit(); printf(" returned %x\n", err); } g_NetAdhocctlConnect = false; } if(g_NetAdhocPdpCreate) { printf2("sceNetAdhocPdpDelete\n"); err = sceNetAdhocPdpDelete(pdpId,0); if(err != 0) { pspDebugScreenInit(); printf("sceNetAdhocPdpDelete returned %x\n", err); } g_NetAdhocPdpCreate = false; } if(g_NetAdhocMatchingStart) { printf2("sceNetAdhocMatchingStop\n"); err = sceNetAdhocMatchingStop(matchingId); if(err != 0) { pspDebugScreenInit(); printf("sceNetAdhocMatchingStop returned %x\n", err); } g_NetAdhocMatchingStart = false; } if(g_NetAdhocMatchingCreate) { printf2("sceNetAdhocMatchingDelete\n"); err = sceNetAdhocMatchingDelete(matchingId); if(err != 0) { pspDebugScreenInit(); printf("sceNetAdhocMatchingDelete returned %x\n", err); } g_NetAdhocMatchingCreate = false; } if(g_NetAdhocMatchingInit) { printf2("sceNetAdhocMatchingTerm\n"); err = sceNetAdhocMatchingTerm(); if(err != 0) { pspDebugScreenInit(); printf("sceNetAdhocMatchingTerm returned %x\n", err); } g_NetAdhocMatchingInit = false; } int stateLast = -1; while (1) { int state; err = sceNetAdhocctlGetState(&state); if (err != 0) { pspDebugScreenInit(); printf("sceNetApctlGetState returns $%x\n", err); sceKernelDelayThread(10*1000000); // 10sec to read before exit return -1; } if (state > stateLast) { sprintf(temp," connection state %d of 1\n", state); printf2(temp); stateLast = state; } if (state == 0) break; // connected // wait a little before polling again sceKernelDelayThread(50*1000); // 50ms } // Now connect to the PSP using a new SSID // Connect err = sceNetAdhocctlConnect(ssid); if (err != 0) { pspDebugScreenInit(); printf("err=%x\n", err); for(;;) sceDisplayWaitVblankStart(); return err; } g_NetAdhocctlConnect = true; stateLast = -1; printf2("Connecting...\n"); while (1) { int state; err = sceNetAdhocctlGetState(&state); if (err != 0) { pspDebugScreenInit(); printf("sceNetApctlGetState returns $%x\n", err); sceKernelDelayThread(10*1000000); // 10sec to read before exit return -1; } if (state > stateLast) { sprintf(temp," connection state %d of 1\n", state); printf2(temp); stateLast = state; } if (state == 1) break; // connected // wait a little before polling again sceKernelDelayThread(50*1000); // 50ms } char macAddr[10]; sceWlanGetEtherAddr(macAddr); printf2("sceNetAdhocPdpCreate\n"); pdpId = sceNetAdhocPdpCreate(macAddr, 0x309, // 0x309 in lumines 0x800, // 0x400 in lumines 0); // 0 in lumines if(pdpId <= 0) { pspDebugScreenInit(); printf("pdpId = %x\n", pdpId); return -1; } g_NetAdhocPdpCreate = true; }
static int adhocStartP2P(void) { int error = 0, state = 1; unsigned char mac[6]; char message[256]; sprintf(message, TEXT(DISCONNECTING_FROM_x), TEXT(LOBBY)); adhoc_init_progress(6, message); sceNetAdhocMatchingStop(matchingId); update_progress(); sceNetAdhocMatchingDelete(matchingId); update_progress(); sceNetAdhocMatchingTerm(); update_progress(); sceNetAdhocPdpDelete(pdpId, 0); update_progress(); sceNetAdhocctlDisconnect(); update_progress(); do { if ((error = sceNetAdhocctlGetState(&state)) != 0) break; sceKernelDelayThread(1000000/60); } while (state == 1); update_progress(); show_progress(TEXT(DISCONNECTED)); mode = MODE_P2P; sprintf(message, TEXT(CONNECTING_TO_x), Server ? TEXT(CLIENT) : TEXT(SERVER)); adhoc_init_progress(4, message); if ((error = sceNetAdhocctlConnect((int *)g_ssid)) == 0) { update_progress(); do { if ((error = sceNetAdhocctlGetState(&state)) != 0) break; sceKernelDelayThread(1000000/60); } while (state != 1); if (!error) { update_progress(); sceWlanGetEtherAddr(mac); memcpy(g_mymac, mac, 6); update_progress(); if ((pdpId = sceNetAdhocPdpCreate(mac, PDP_PORT, PDP_BUFFER_SIZE, 0)) > 0) { update_progress(); adhoc_initialized = 2; show_progress(TEXT(WAITING_FOR_SYNCHRONIZATION)); if ((error = adhocSync()) == 0) return Server; } else { error = 1; } } sceNetAdhocctlDisconnect(); if (state == 1) { do { if ((error = sceNetAdhocctlGetState(&state)) != 0) break; sceKernelDelayThread(1000000/60); } while (state == 1); } } sceNetAdhocctlTerm(); sceNetAdhocTerm(); sceNetTerm(); adhoc_initialized = 0; switch (error) { case 1: sprintf(message, "%s (PDP ID = %08x)", TEXT(FAILED), pdpId); break; default: sprintf(message, "%s (Error Code = %08x)", TEXT(FAILED), error); break; } show_progress(message); pad_wait_clear(); pad_wait_press(PAD_WAIT_INFINITY); return -1; }
int pspAdhocConnect(const PspMAC mac) { int err, state = 0; char temp[64]; char ssid[10]; sceNetEtherNtostr((unsigned char*)mac, temp); ssid[0] = temp[9]; ssid[1] = temp[10]; ssid[2] = temp[12]; ssid[3] = temp[13]; ssid[4] = temp[15]; ssid[5] = temp[16]; ssid[6] = '\0'; if (_net_adhoc_ctl_connect) { if (_net_adhoc_pdp_create) { if (_net_adhoc_matching_init) { if (_net_adhoc_matching_create) { if (_net_adhoc_matching_start) { sceNetAdhocMatchingStop(_matching_id); _net_adhoc_matching_start = 0; } sceNetAdhocMatchingDelete(_matching_id); _net_adhoc_matching_create = 0; } sceNetAdhocMatchingTerm(); _net_adhoc_matching_init = 0; } sceNetAdhocPdpDelete(_pdp_id, 0); _net_adhoc_pdp_create = 0; } sceNetAdhocctlDisconnect(); _net_adhoc_ctl_connect = 0; } do { if ((err = sceNetAdhocctlGetState(&state)) != 0) break; sceKernelDelayThread(1000000/60); } while (state == 1); if ((err = sceNetAdhocctlConnect((void*)ssid)) == 0) { do { if ((err = sceNetAdhocctlGetState(&state)) != 0) break; sceKernelDelayThread(1000000/60); } while (state != 1); if (!err) { if ((_pdp_id = sceNetAdhocPdpCreate(_own_mac, 0x309, 0x800, 0)) > 0) { if (pspAdhocIsMACEqual(mac, _own_mac)) sceKernelDelayThread(1000000); return 1; } } if (_net_adhoc_ctl_connect) { sceNetAdhocctlDisconnect(); _net_adhoc_ctl_connect = 0; } if (state == 1) { do { if ((err = sceNetAdhocctlGetState(&state)) != 0) break; sceKernelDelayThread(1000000/60); } while (state == 1); } } if (_net_init) { if (_net_adhoc_init) { if (_net_adhoc_ctl_init) { sceNetAdhocctlTerm(); _net_adhoc_ctl_init = 0; } sceNetAdhocTerm(); _net_adhoc_init = 0; } sceNetTerm(); _net_init = 0; } return 0; }