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 > Comms Protocol

#152742 - iprice - Thu Mar 20, 2008 9:10 am

I am trying to communicate for in gaem multiplayer... is there a specific format to the messages for the hardware to recieve..... mac addresses at bit 10 etc?

#152855 - iprice - Fri Mar 21, 2008 7:55 pm

anyone else messing with WMB_Host?

#152954 - iprice - Sun Mar 23, 2008 10:24 am

No-one replys to my problems :(

I prepare the message:

Code:
   comms_data[10] = my_mac[0];
   comms_data[16] = my_mac[0];
   comms_data[24] = GAME_ID_CODE;
   comms_data[25] = MESSAGE_GAME_HOST;
   SendFrame(comms_data, 28);


I send the info

Code:
void SendFrame(unsigned char *data, int len)
{
   int i;
   int cf;
   
   cf = tx_base;
   for(i=0;i<12;i++) {
      tx_queue[cf][i] = 0;
   }

   tx_queue[cf][8] = 0x14; // Trans rate... a=1 14=2mbit
   
   // Data Size
   tx_queue[cf][10]   = (len+4)&0xFF;
   tx_queue[cf][11]   = ((len+4)&0xFF00)>>8;

   for(i=0;i<len;i++) {
      tx_queue[cf][i+12] = data[i];
   }

   tx_sizes[cf] = len+16;
   tx_base++;
   tx_count++;

   if(tx_base == 64) tx_base = 0;
}


I check for a reply in a timer

Code:
void MY_IRQ(void)
{
   if(REG_IF & IRQ_VBLANK)
   {
      VBLANK_INTR_WAIT_FLAGS |= IRQ_VBLANK;
      REG_IF |= IRQ_VBLANK;
      vblank_happened = 1;
      ReceiveUserData(); //check for reply here
   }
   if (REG_IF & IRQ_TIMER2)
   {
      REG_IF |= IRQ_TIMER2;
      Timer_Beacons();
   }
   REG_IF = REG_IF;
}


For these simple messages, do I have to ACK? Do I have to include rsa? Does the hardware have to check anything or is it all software? Anyone?

#152991 - yellowstar - Sun Mar 23, 2008 10:23 pm

iprice wrote:

I prepare the message:

Code:
   comms_data[10] = my_mac[0];//memcpy(&comms_data[10],mymac);
   comms_data[16] = my_mac[0];//memcpy(&comms_data[16],tomac);
   comms_data[24] = GAME_ID_CODE;
   comms_data[25] = MESSAGE_GAME_HOST;
   SendFrame(comms_data, 28);
//Replace the orginal code next to the comments with the code in comments


I send the info

Code:
void SendFrame(unsigned char *data, int len)
{
   int i;
   int cf;
   
   cf = tx_base;
   for(i=0;i<12;i++) {
      tx_queue[cf][i] = 0;
   }

   tx_queue[cf][8] = 0x14; // Trans rate... a=1 14=2mbit
   
   // Data Size
   tx_queue[cf][10]   = (len+4)&0xFF;
   tx_queue[cf][11]   = ((len+4)&0xFF00)>>8;

   for(i=0;i<len;i++) {
      tx_queue[cf][i+12] = data[i];
   }

   tx_sizes[cf] = len+16;
   tx_base++;
   tx_count++;

   if(tx_base == 64) tx_base = 0;
}


I check for a reply in a timer

Code:
void MY_IRQ(void)
{
   if(REG_IF & IRQ_VBLANK)
   {
      VBLANK_INTR_WAIT_FLAGS |= IRQ_VBLANK;
      REG_IF |= IRQ_VBLANK;
      vblank_happened = 1;
      ReceiveUserData(); //check for reply here
   }
   if (REG_IF & IRQ_TIMER2)
   {
      REG_IF |= IRQ_TIMER2;
      Timer_Beacons();
   }
   REG_IF = REG_IF;
}


For these simple messages, do I have to ACK? Do I have to include rsa? Does the hardware have to check anything or is it all software? Anyone?


You should replace the code at the top with the code in comments
You shouldn't need to ACK, that's for if you want to make sure the packets arrive. And implementing this would be difficult, so best not deal with it.(liblobby does ACK however)
I've heard that it's bad to use TCP/IP in multiplayer games,(big slowdown)
and TCP/IP would be similar to what you would be implementing, so avoid it.(I have even looked at packet captures of DS Wifi games, and they don't ACK for the actual gameplay)

I noticed TimerBeacons was in there... Fix that so it only sends out WMB beacons when searching for players, not when the actual gameplay started. No, you don't need RSA, that's only during the WMB transfer.
For what your doing, it mainly software, not hardware, that's the problem in your case.

What exactly is the problem? You should post the ReceiveUserData function, or at least part of it.

#152995 - iprice - Sun Mar 23, 2008 11:49 pm

Thanks for the reply... but when I am offering host and waiting for a client, I don't know the send to mac.

WMB_HOST uses the same mac, mymac....

Code:
copy_mac(&assocres[10], &mymac[0]);
copy_mac(&assocres[16], &mymac[0]);

#153000 - yellowstar - Mon Mar 24, 2008 2:20 am

In the original WMB_Host, on Line 567, there's this:
Code:

copy_mac(&authres[4], &fh->mac2[0]);


Copy authres to a global var called player_mac or something similar, and use that during gameplay.

#153017 - wintermute - Mon Mar 24, 2008 5:56 am

You're probably better off not wasting your time with this, sgstair has time to look at the new dswifi he was promising and liblobby is a bit on the broken side.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#153039 - iprice - Mon Mar 24, 2008 2:24 pm

I am trying to get download play and 2 cart play up and running for a game I have.... I can get either in-game comms OR download comms.... I am trying to use WMB_Host download comms and adapt them for in-game comms....

#153059 - wintermute - Mon Mar 24, 2008 5:29 pm

I realise that. What I said still applies.

The next couple of toolchain and library updates will break liblobby beyond repair. There's not really a lot we can do about it, most of the design is basically just a horrible hack.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#153128 - iprice - Tue Mar 25, 2008 12:55 pm

I am trying to write my own comms, based on liblobby idea using WMB_Host.... hopefully new updates will not stop my code.....

I have all the code in the right place but something is still wrong with the messages I am sending, even with the correct MAC.

Has anyone got some spare time to have a look at my code?

Cheers

#153287 - yellowstar - Thu Mar 27, 2008 7:20 pm

iprice wrote:

I have all the code in the right place but something is still wrong with the messages I am sending, even with the correct MAC.

Has anyone got some spare time to have a look at my code?

So, the packets you're sending, on the receiving end, they're not what they should be?(What supposed to be in the packet, from the sender, it isn't the same on the receiving end?)
It might by a corruption problem. liblobby takes care of this, but WMB_Host, does not, at least not by default.
You'd need to place a checksum before the actual packet data. You'd calculate this before sending the packet, and place it as said before.
Then on the receiving end, you'd calculate the checksum of the packet data, then compare the result of that checksum, and the checksum stored in the packet, from the sender. If they're the same, all is well, and the only problem could be some bug in your sending/receiving code. But, if not, it's corrupted, and you simply ignore that packet.(Trying to resend it would get into the complicated TCPIP stuff)
(Even when a packet does get corrupted, even when your code is fine, it's not you're fault - it's just how wireless, and every communication system is.)
As for calculating the checksum, try CRC32. But, you'll need to Google/search about this - I don't know the arthrogram for this.(But, you probably could grab the code for the checksum calc for the WMB_Host beacons. :-) )

As for looking at you're code... Well, my homebrew card is broken, so I can't run your program to see what's wrong.(On second thought, I couldn't even try it even if my card was working, since this is a homebrew Download Play game, and I only have DSes with original, NoFlashMe firmwares...)

Well, I have lots of spare time since my card is busted, so, go ahead and send the code.(You can either post here, or PM me, it's up to you)