/* * Network Control class * * Copyright (C) 2008 Alejandro Valenzuela Roca, * * http://mexinetica.com/~lanjoe9 * * This file is part of MotorJ, a free framework for videogame development. * * * * MotorJ is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MotorJ is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with MotorJ. If not, see . */ #include "networkctl-class.h" #ifdef NINTENDO_WII mjNetworkCTL::mjNetworkCTL(void) { net_init(); } #endif #ifdef NINTENDO_DS void arm9WifiSyncFunction(void) { REG_IPC_FIFO_TX = MSG_WIFI_SYNC; } mjNetworkCTL::mjNetworkCTL(void) { iStatus = NS_IPCNOTREADY; } void mjNetworkCTL::AppInitSetIPC(void) { if (iStatus == NS_IPCNOTREADY) { // the interprocessor FIFO must be enabled and clean REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR; // .. a FIFO IRQ handler must be set.. irqSet(IRQ_FIFO_NOT_EMPTY, fifoARM9HandlerFunction); // .. and its register enabled as well. REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_RECV_IRQ; irqEnable(IRQ_FIFO_NOT_EMPTY); iStatus = NS_INACTIVE; } } void mjNetworkCTL::dsStartAutoConnect() { // We must run Wifi_Init .. u32 wifi_passdata = Wifi_Init( WIFIINIT_OPTION_USELED ); // .. alert the ARM7 about some data it will receive (more on that later).. REG_IPC_FIFO_TX = MSG_WIFI_INITIALIZE; // .. and send it. REG_IPC_FIFO_TX = wifi_passdata; // The sync handler for the wifi library must be set Wifi_SetSyncHandler(arm9WifiSyncFunction); iStatus = NS_WAITINGFORINIT; } void mjNetworkCTL::dsContAutoConnect() { Wifi_EnableWifi(); Wifi_AutoConnect(); iStatus = NS_ASSOCIATING; } MJNETCTLSTATUS mjNetworkCTL::dsStatus() { // What is the control's status? // If status is either waiting for init or // associating to an AP, we'll first see if it has changed. // In all other values we'll simply return the internal variable switch (iStatus) { case NS_WAITINGFORINIT: if (Wifi_CheckInit()) iStatus = NS_READYTOASSOCIATE; break; case NS_ASSOCIATING: switch( Wifi_AssocStatus()) { case ASSOCSTATUS_CANNOTCONNECT: iStatus = NS_ASSOCIATIONERROR; break; case ASSOCSTATUS_ASSOCIATED: iStatus = NS_ASSOCIATED; break; } break; } return iStatus; } void mjNetworkCTL::dsDisconnect() { switch(iStatus) { case NS_ASSOCIATED: Wifi_DisconnectAP(); case NS_READYTOASSOCIATE: case NS_ASSOCIATING: case NS_ASSOCIATIONERROR: Wifi_DisableWifi(); iStatus = NS_READYTOASSOCIATE; break; default: break; } } #endif