gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Help! Wireless and Download Play Client

#135607 - yellowstar - Tue Jul 24, 2007 11:32 pm

I have some questions and problems.
These questions and problems
have to do with wireless and a Download Play Client.

NOTE:
I have moved this problem,
from my "Help! Wireless, bootloader, icon and Download Play Client",
to here,
since the total size of that starting post was very long.

1.

I am trying to make a DS Download Play Client,
for Juglak's WMB Host.

All these problems are in this client.

My client is based on Juglak's WMB Host,
for local wireless.

Like Juglak's WMB Host,
my program's graphics is an console.



The following is a problem with the wireless communication
part of the client.(The downloading and etc.)

My client never makes it past the Authication step.

According to the CFTP version of DSFTP,
in the Packet Capture tool,
it says it(my client) never sends out the Authication requests.

The only thing it detected was the host's Download Play ad/beacon.

Here's the things I have tried:

I tried typecasting the framehead struct to
a pointer, whichs points to an unsigned char array,
then sending that.

That failed.

I tried allocating a dynamic unsigned char array.

I then copied the contents of the framehead struct
into that array.

Then I would have it sent.

That failed.


Here's my code:

This only has the code for the ARM9.
Since this app is based on Juglak's WMB Host,
this app has the same ARM7 code as the WMB Host.

After initializing,
my app goes into a loop.

A timer,(gets triggered evey second)
handles detecting the Download Play ads/beacons.

If one was detected at least once,
in a 5 second time frame,
it displays information about the ad/beacon.

Other wise,
it clears that info,
and stops displaying it.


When a ad is detected,
to start downloading,
you press A.

It will then ask if you are sure
you want to download.
With A for yes, B for no.

After that,
it will go into another infinite loop.

In this loop,
a function which handles the actual downloading and ect. ,
is called.

Here is that function:
(Note: I cut out the rest of the steps which handles
the steps after Authication, since I didn't get to those
steps, and beacuse it never makes it past Authication.)

Code:

void downloadMain()
{



   int i, ds, j=0, k;
   unsigned char *datapkt;
   struct nds_rsaframe *rsa;
   unsigned char *nds_data;
   tNDSHeader *nds_head;
   tNDSBanner *banner;
   unsigned char *d,*dr;
   struct iee80211_framehead FH;
   struct iee80211_framehead *fh = &FH;
   bool gotrsa=0;
   int mode = 1;
   unsigned short curdata=0;
   unsigned char *dataacked;

consoleClear();

if (mode == 1) {
         //Wifi_SetRetry(4);
         //dr = RXNextFrame(&ds);
         //if (dr != NULL) {
            //for(int i=0;i<10;i++)
            //{
            //fh = (struct iee80211_framehead *) malloc(66);//(unsigned int) dr;
               
            
               
            memset(fh,sizeof(fh),0);
               
            // check against macs later to see if its really to us
            //Right here, in WMB Host,
            //fh->frame_control always = 4272
            
            fh->frame_control = 4272;//4272,3,15
            
            for(int i = 0; i < 6; i++)
            fh->mac3[i] = the_ad.host_mac[i];
            
            for(int i = 0; i < 6; i++)
            fh->mac2[i] = mymac[i];
            
            //if (((FH_FC_TYPE(fh->frame_control) == 0) && (FH_FC_SUBTYPE(fh->frame_control) == 11)) &&
            //CompareMAC(my_mac, fh->mac3)) {
            
            for(int i=0;i<10;i++)
            {
            
            unsigned char *buff = (unsigned char*)malloc(sizeof(fh));
            
            memset(buff,sizeof(buff),0);
            
            memcpy((unsigned char*)fh,buff,sizeof(buff));
            
            SendFrame(buff,sizeof(buff));
            //free(fh);
            
            free(buff);
            }
            
            //}
            
               iprintf("\x1b[18;0H                                ");
               iprintf("\x1b[18;0H* Sent Authentication request\n");
               
               //return;
               
               //iprintf("\x1b[19;0HMAC1: "); for(i=0;i<6;i++) iprintf("%2.2X ",fh->mac1[i]);
               //iprintf("\x1b[20;0HMAC2: "); for(i=0;i<6;i++) iprintf("%2.2X ",fh->mac2[i]);
               //iprintf("\x1b[21;0HMAC3: "); for(i=0;i<6;i++) iprintf("%2.2X ",fh->mac3[i]);
               //iprintf("\x1b[21;0HMAC3: "); for(i=0;i<6;i++) iprintf("%2.2X ",fh->mac3[i]);
                  
               // ack it
               
               
               if(!GetACK(mymac))
               return;
               
               iprintf("\x1b[18;0H* ACKED!\n");
               //mac2 is the MAC of the client. That is,
               //the DS that is running this app.
                  
               /*copy_mac(&authres[4], &fh->mac2[0]);
               copy_mac(&authres[10], &mymac[0]);
               copy_mac(&authres[16], &mymac[0]);
               fh = (struct iee80211_framehead *) (unsigned int) &authres[0];
               fh->sequence_control = bec_seq<<4;
               */
               bec_seq++;            
               //SendFrame(authres,30);
               
               while(1)
               {
               
               fh = (struct iee80211_framehead *)RXNextFrame(&sz);
               
               if(sz==30 && fh!=NULL)
               {
                if(((unsigned char*)fh)[4]==mymac[0] && ((unsigned char*)fh)[10]==the_ad.host_mac[0] && ((unsigned char*)fh)[16]==the_ad.host_mac[0])
                {
                break;
                }
                else
                {
                return;
                }
               }
               else
               {
               return;
               }
               
               iprintf("\x1b[18;0H* Authenicated!\n");
               
               }


}


Here is the GetACK function.

Basicly, it waits for an ACK with the specified mac.
It goes into a for loop,
and if it doesn't find it,
it returns 0.

Otherwise,
it returns 1.

Code:

bool GetACK(unsigned char *wanted_mac)
{

unsigned char *dat = NULL;

 for(int i=0; i<10; i++)
 {
 
 dat = RXNextFrame(&sz);
 
  if(sz==6)
  {
 
   if(CompareMAC(wanted_mac,dat))
   {
   return 1;
   }
 
  }
 
  return 0;
 
 }

}

#135611 - yellowstar - Tue Jul 24, 2007 11:42 pm

This post has been moved from my other topic,
the topic which this problem was moved from.

Download Play Client Auth bug:

I have found out that for some reason,
my app won't send anything.

But recieving works fine.

I tried sending an ACK.(a packet which contains a MAC
address, in this case it was the client's MAC.)

That failed.

I guess I'll need to replace the ARM7 code with the ARM7
code in Juglak's WMB Host.

Then if that dosen't work,
I'll have to replace the functions in the the ARM9 main source
code file.
(The functions I copied from WMB Host,
I'll have to copy them again unto the ones I have.)

EDIT:
I tried the above,
but that didn't fix it.

When it starts the download process,
it dosen't set the current channel to the host's channel.

This might one of the problems that is causing this,
but packet capture programs don't detect anything
while it is sending anything,
on any channel.

EDIT2:
I tried the above,
but that didn't work.

I also tried to have it print the current channel,
but that didn't work.

For some reason,
it wouldn't print that.

I have it printing before it sets the current channel.

I have it printing the value the channel it
is going to be set to.

EDIT3:
Never mind about
the print bug in the above edit,
it was clearing the screen before
I could see the printed text.

Now it prints the channel and ect.
correctly at that point.

Now,
for some reason,
now the host is broadcasting
on channel 10,
instead of 11,
like it was before.

But that dosen't
affect my client,
since it sets the current channel
to the host's channel,
before the download process is started.

#136429 - yellowstar - Wed Aug 01, 2007 5:53 pm

I tried sending a packet which is
1 byte in size.
I am having it send it in the timer handler
which handles recieving the beacons.

That worked.

Next I tried sending a packet the size
of the struct for an Auth request.(framehead struct)

That failed.

#136439 - pas - Wed Aug 01, 2007 9:01 pm

PM Juglak ?
_________________
Starcraft DS ?

#137250 - Moby Disk - Thu Aug 09, 2007 2:35 pm

If you do PM him, let us know the reply. There are other peopel who (well...me!) would like to do this, but I haven't even started yet so I can't help. But I can cheer you on.

Rah rah rah!
DSWifi!
yaaaay!
(good luck)

#137253 - simonjhall - Thu Aug 09, 2007 2:45 pm

I PMed him about this when I started RE-ing the p-2-p wifi but the mail never left the outbox so I guess he just never picked it up. And I send the message *ages* ago, so maybe he's not been at gbadev for a while...
_________________
Big thanks to everyone who donated for Quake2

#137299 - yellowstar - Fri Aug 10, 2007 12:16 am

simonjhall wrote:
And I send the message *ages* ago, so maybe he's not been at gbadev for a while...

I thought he wasn't on here in a long time.


I tried calling RXNextFrame,
1000 times,(in a for loop)
before sending frames for the download process.
(I tried calling RXNextFrame in a while loop,
untill the receive quene was empty.
But it never exited that loop.
Apparently, the frames kept comming in.)

That didn't work.

This probably isn't possible, but:
Is it possible to temporarly make
the wireless WiFi hardware to stop receiving
frames, and only send frames?

EDIT:
I have PMed Juglak.
No way of knowing when he will reply...