#157893 - Mohammad - Sun Jun 01, 2008 1:56 am
Does anyone have an example on how to use WiFi Lib, I'm going to use it to connect to a MySQL DB through PHP though...
#157896 - Lazy1 - Sun Jun 01, 2008 6:10 am
There should be examples provided in the dswifi download, if there isn't wifi_lib_test will show you how to initialize the wifi library.
Here is my modified startup/stop code, should get a cleaning though:
(Warning: Horrible preprocessor abuse)
Code: |
#define InitStage( StageTitle, InitCode ) { \
iprintf( "%s... ", StageTitle ); \
InitCode; \
iprintf( "%s\n", StageResult == 1 ? "OK" : "FAIL" ); \
if ( StageResult == 0 ) return 0; \
}
void IRQTimer3( void ) {
Wifi_Timer( 50 );
}
void IRQFifoNotEmpty( void ) {
u32 FifoData = 0;
if ( ( FifoData = REG_IPC_FIFO_RX ) == 0x87654321 )
Wifi_Sync( );
}
void Arm9Arm7Sync( void ) {
REG_IPC_FIFO_TX = 0x87654321;
}
int StartupWifi( void ) {
int StageResult = 0;
int Status = 0;
int VBlanks = 0;
u32 WifiPass = 0;
InitStage( "Initialize wifi", {
REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR;
WifiPass = Wifi_Init( WIFIINIT_OPTION_USELED );
REG_IPC_FIFO_TX = 0x12345678;
REG_IPC_FIFO_TX = WifiPass;
TIMER3_CR = 0;
TIMER3_DATA = 0;
irqSet( IRQ_TIMER3, IRQTimer3 );
irqEnable( IRQ_TIMER3 );
irqSet( IRQ_FIFO_NOT_EMPTY, IRQFifoNotEmpty );
irqEnable( IRQ_FIFO_NOT_EMPTY );
REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_RECV_IRQ;
Wifi_SetSyncHandler( Arm9Arm7Sync );
TIMER3_DATA = -6553;
TIMER3_CR = TIMER_ENABLE | TIMER_DIV_256 | TIMER_IRQ_REQ;
while ( Wifi_CheckInit( ) == 0 ) {
swiWaitForVBlank( );
VBlanks++;
// ARM7 Did not init. Don't hang, just fail
if ( VBlanks >= 240 )
break;
}
StageResult = VBlanks < 240 ? 1 : 0;
}
);
if ( StageResult == 1 ) {
InitStage( "Connect via wfc data", {
Wifi_AutoConnect( );
while ( 1 ) {
Status = Wifi_AssocStatus( );
if ( Status == ASSOCSTATUS_ASSOCIATED ) {
StageResult = 1;
break;
}
if ( Status == ASSOCSTATUS_CANNOTCONNECT ) {
StageResult = 0;
break;
}
if ( VBlanks >= 600 ) {
StageResult = 0;
break;
}
swiWaitForVBlank( );
VBlanks++;
}
}
);
return StageResult;
}
return 0;
}
int StopWifi( void ) {
Wifi_DisconnectAP( );
Wifi_DisableWifi( );
swiWaitForVBlank( );
swiWaitForVBlank( );
swiWaitForVBlank( );
swiWaitForVBlank( );
return 1;
}
|
EDIT:
Forgot ARM7 Code!
Code: |
//---------------------------------------------------------------------------------
void VblankHandler(void) {
//---------------------------------------------------------------------------------
u32 i;
//sound code :)
TransferSound *snd = IPC->soundData;
IPC->soundData = 0;
if (0 != snd) {
for (i=0; i<snd->count; i++) {
s32 chan = getFreeSoundChannel();
if (chan >= 0) {
startSound(snd->data[i].rate, snd->data[i].data, snd->data[i].len, chan, snd->data[i].vol, snd->data[i].pan, snd->data[i].format);
}
}
}
Wifi_Update( );
}
static __inline__ void FifoWaitWhileEmpty( void ) {
while ( REG_IPC_FIFO_CR & IPC_FIFO_RECV_EMPTY )
swiWaitForVBlank( );
}
void IRQFifoNotEmpty( void ) {
u32 FifoData = 0;
if ( ( FifoData = REG_IPC_FIFO_RX ) == 0x87654321 )
Wifi_Sync( );
}
void Arm7Arm9Sync( void ) {
REG_IPC_FIFO_TX = 0x87654321;
}
void SetupWifiHardware( void ) {
u32 FifoData = 0;
irqSet( IRQ_WIFI, Wifi_Interrupt );
irqEnable( IRQ_WIFI );
while ( 1 ) {
FifoWaitWhileEmpty( );
if ( ( FifoData = REG_IPC_FIFO_RX ) == 0x12345678 )
break;
swiWaitForVBlank( );
}
FifoWaitWhileEmpty( );
FifoData = REG_IPC_FIFO_RX;
Wifi_Init( FifoData );
irqSet( IRQ_FIFO_NOT_EMPTY, IRQFifoNotEmpty );
irqEnable( IRQ_FIFO_NOT_EMPTY );
REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_RECV_IRQ;
Wifi_SetSyncHandler( Arm7Arm9Sync );
}
//---------------------------------------------------------------------------------
int main(int argc, char ** argv) {
//---------------------------------------------------------------------------------
REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR;
// read User Settings from firmware
readUserSettings();
//enable sound
powerON(POWER_SOUND);
writePowerManagement(PM_CONTROL_REG, ( readPowerManagement(PM_CONTROL_REG) & ~PM_SOUND_MUTE ) | PM_SOUND_AMP );
SOUND_CR = SOUND_ENABLE | SOUND_VOL(0x7F);
irqInit();
// Start the RTC tracking IRQ
initClockIRQ();
SetYtrigger(80);
irqSet(IRQ_VCOUNT, VcountHandler);
irqSet(IRQ_VBLANK, VblankHandler);
irqEnable( IRQ_VBLANK | IRQ_VCOUNT);
SetupWifiHardware( );
// Keep the ARM7 mostly idle
while (1) swiWaitForVBlank();
}
|
Last edited by Lazy1 on Sun Jun 01, 2008 8:01 pm; edited 1 time in total
#157901 - Mohammad - Sun Jun 01, 2008 4:22 pm
but now how would I download the text from my website so like
http://www.mysite.com/mygame/nds/game.php?sql="SELECT * FROM monsters"
#157902 - simonjhall - Sun Jun 01, 2008 4:24 pm
That code's lacking the ARM7 stuff...it won't work without it!
And have a look for the actual sample, as that shows you how to do a dash of http. I'm sure you can get it through the DKP updater.
_________________
Big thanks to everyone who donated for Quake2
#157903 - Maxxie - Sun Jun 01, 2008 4:47 pm
Well, you better don't as this will open your server for sql based attacks.
On the question of how to access hypertext base web content
#157904 - Mohammad - Sun Jun 01, 2008 5:01 pm
first it will have to authenticate its self and be added to the trusted MAC address DB. Also the URL will be a lot longer then that with random gibberish.
#157907 - Maxxie - Sun Jun 01, 2008 7:11 pm
Mohammad wrote: |
first it will have to authenticate its self and be added to the trusted MAC address DB.
|
Which will not prevent injection into the authentificated machine.
Quote: |
Also the URL will be a lot longer then that with random gibberish. |
No random gibberisch will add to security. Everyone on the way that logs requested pages will be able to get into, and i am not even thinking about bots. I strongly advise to use predefined, well formed SQL commands in your php you only pass _checked_ parameters to.
Please help keeping zombies out, thanks.
#157908 - Cydrak - Sun Jun 01, 2008 7:12 pm
Quote: |
Also the URL will be a lot longer then that with random gibberish.
|
Maybe you can't imagine "decoding" such things. But if it can't be guessed, I assure you it's not impractical to read assembler (nevermind amazing tools like IDA Pro). As such, your game code may provide a nice tutorial. :-)
Quote: |
first it will have to authenticate its self and be added to the trusted MAC address DB. |
I'm not really a PHP/SQL guy, but... what guarantee is the MAC your client claims to have? As for logins, remember you're doing this over wifi... see Defcon's infamous Wall of Sheep. (So, you say you're on a secure network? How about your players?)
Just to further the point: I used to run a small Apache server. Though not linked or publicised at all, I remember lots of exploit attempts (probably worms) in the access logs. It was fairly routine--and this was years ago. I don't think it's paranoid to be skeptical of your input, whether you trust your clients or not.
Finally, at some point you might wish to change the tables. Would you rather patch the server or the game?
#157909 - Mohammad - Sun Jun 01, 2008 7:28 pm
this isn't anything public, it's just for four of us people to keep a DB up to date on some stuff, if it gets hacked, no one cares. But is there a MySQL header for NDSLIB?
#157921 - DensitY - Sun Jun 01, 2008 11:49 pm
Mohammad wrote: |
this isn't anything public, it's just for four of us people to keep a DB up to date on some stuff, if it gets hacked, no one cares. But is there a MySQL header for NDSLIB? |
not to my knowledge. But I can think of 3 ways of doing it,
Firstly you could write it so your DS application issues commands to a PC applicaiton which'll do the SQL queries for you, and return the result (just requires you to create custom simple TCP (well last time I checked TCP packets had problems, might have to send UDP with libwifi :s) protocol between your pc app and the DS app, no biggy), I'd possibly recommend this because you can make it as secure as you want (if you want to write your own SSL Client for DS that is). Secondly you could write a full SQL client layer on the DS, which will not be fun and something I don't advice.
The third way is possibly implementing a basic HTTP client on the ds, and connect to a host web address (on pc) which'll run a CGI app that'll return the results, not very secure.
#158012 - Mohammad - Tue Jun 03, 2008 11:23 am
simonjhall wrote: |
That code's lacking the ARM7 stuff...it won't work without it!
And have a look for the actual sample, as that shows you how to do a dash of http. I'm sure you can get it through the DKP updater. |
They took that stuff out sadly, because "everyone already has it" sorta thing. *grunt* could someone try to just zip it and put it on rapidshare.com or megaupload, sorry to be a nuisance
#158013 - simonjhall - Tue Jun 03, 2008 11:30 am
So what's in the sample then? Just turning on and off wifi? That's not a sample!
_________________
Big thanks to everyone who donated for Quake2
#158014 - Mohammad - Tue Jun 03, 2008 3:08 pm
there is no sample... did I miss something? (uhh oh)
#158044 - Lazy1 - Tue Jun 03, 2008 10:22 pm
All you really need to know is how to enable the wifi hardware, if you don't know socket programming the DS is not the place to start learning.
#158052 - Mohammad - Tue Jun 03, 2008 11:28 pm
hmm can't say that I do I did UDP/TCP MMORPG games (that never got that first M) but I honestly don't think it will be that hard. Yellowstar people can learn, sometimes the hardest is the most rewarding, and in the long run the best (because everything else is so easy). Well I can't run DKPupdater.exe for w/e reason. /me is fon of zips so if anyone knows where to get it zipped lemme know until then, trying to get to the bottom of the updater.
#158053 - silent_code - Tue Jun 03, 2008 11:44 pm
all devkitpro related components and support libraries can be found zipped at the project's sourceforge page. :^)
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
#158107 - tepples - Thu Jun 05, 2008 1:21 am
Mohammad wrote: |
Well I can't run DKPupdater.exe for w/e reason. |
Does the updater open and close without displaying anything? Or is it that you can't run .exe files in general?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#158140 - melw - Thu Jun 05, 2008 3:36 pm
If you're using PHP as a server backend there's no need to mix SQL in any of your DS code. Just make a PHP page that responds to queries sent from DS and returns something back corresponding what you need. This way you can optimize the packets sent between the client and server to minimum, e.g. use the first byte(s) for identifying what kind of data is being sent/queried according to game situation and the rest of the packets for parameters and data.
Making a MySQL client for DS might be a fun project, but for games I don't see much point in going that direction... Just my two cents on this topic.