Advertisement
xerpi

Untitled

Mar 19th, 2011
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.75 KB | None | 0 0
  1. //adhoc.c
  2.  
  3. #include <pspsdk.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <pspthreadman.h>
  7. #include <stdio.h>
  8. #include <pspnet.h>
  9. #include <pspwlan.h>
  10. #include <pspnet_adhoc.h>
  11. #include <pspnet_adhocctl.h>
  12. #include "std.h"
  13.  
  14.  
  15. char BROADCAST_MAC[6];
  16.  
  17. int pdpID = -1;
  18.  
  19. bool pdpInit = false;
  20.  
  21. int recvPDP(void *buffer, unsigned int *length)
  22. {
  23.     int port = 0;
  24.     char mac[20];
  25.     int pdpStatLength=20;
  26.     pdpStatStruct pspStat;
  27.  
  28.     sceNetAdhocGetPdpStat(&pdpStatLength, &pspStat);
  29.  
  30.     if(pspStat.rcvdData < 1)
  31.     {
  32.         sceNetAdhocPdpRecv(pdpID,mac,&port,buffer,length,0,0);
  33.         return 1;
  34.     }
  35.     else
  36.         return 0;
  37. }
  38.  
  39. int sendPDP(void *buffer, int length)
  40. {
  41.     sceNetAdhocPdpSend(pdpID,
  42.             &BROADCAST_MAC[0],
  43.             0x309,
  44.             buffer,
  45.             length,
  46.             0,  // 0 in lumines
  47.             0); // 1 in lumines
  48.  
  49.     return 0;
  50. }
  51.  
  52.  
  53. void sendMSG(char *MSG)
  54. {
  55.     sendPDP(&MSG, sizeof(MSG));
  56. }
  57.  
  58. void recvMSG(char *MSG)
  59. {
  60.     int recvLEN;
  61.  
  62.     recvPDP(&MSG, &recvLEN);
  63. }
  64.  
  65.  
  66. void initAll()
  67. {
  68.     struct productStruct product;
  69.  
  70.     //Set the product information to connect to the CTL
  71.     strcpy(product.product, "ULUS99999");
  72.     product.unknown = 0;
  73.  
  74.     //Init the net module for WLAN
  75.     sceNetInit(0x20000, 0x20, 0x1000, 0x20, 0x1000);
  76.  
  77.  
  78.  
  79.     //Init the adhoc libraries
  80.     sceNetAdhocInit();
  81.  
  82.     //Init the adhoc ctl libraries
  83.     sceNetAdhocctlInit(0x2000, 0x20, &product);
  84.  
  85.  
  86. }
  87. void termAll()
  88. {
  89.     sceNetAdhocctlTerm();
  90.     sceNetAdhocTerm();
  91.     sceNetTerm();
  92. }
  93. void connectAdhoc()
  94. {
  95.     char mac[6];
  96.     int err;
  97.  
  98.     //Connect to adhoc ctl
  99.     sceNetAdhocctlConnect("");
  100.  
  101.     //This is from BlackPhoenix's Adhoc Example
  102.     int stateLast = -1;
  103.     while (1)
  104.     {
  105.         int state;
  106.         err = sceNetAdhocctlGetState(&state);
  107.         if (state > stateLast)
  108.             stateLast = state;
  109.         if (state == 1)
  110.             break;  // connected
  111.         // wait a little before polling again
  112.         sceKernelDelayThread(50*1000); // 50ms
  113.     }
  114.    
  115.     //Get the MAC address
  116.     sceWlanGetEtherAddr(mac);
  117.  
  118.     //Create a PDP
  119.     pdpID = sceNetAdhocPdpCreate(mac, 0x309, 0x400, 0);
  120.  
  121.     if(pdpID >= 0)
  122.         pdpInit = true;
  123.  
  124.     int i;
  125.     for(i=0;i<7;i++)
  126.         BROADCAST_MAC[i] = 0xFF;
  127.  
  128. }
  129. void getmac(void *themac)
  130. {
  131.     unsigned char sVal[7];
  132.     memset(sVal, 0, 7);
  133.     sceWlanGetEtherAddr(sVal);
  134.     sprintf(themac,"%02X:%02X:%02X:%02X:%02X:%02X", sVal[0], sVal[1], sVal[2], sVal[3], sVal[4], sVal[5]);
  135.    
  136. }
  137. /*
  138.  
  139.  
  140. I believe that our ad-hoc system is working well for right now.. the way to do this better would probably be with
  141. Adhoc Matching... I think we should save this for a later release though because it's not needed right now and it
  142. just adds more to our plate.
  143.  
  144.  
  145. void creatadhoc(void *name)
  146. {
  147.    
  148.     char macad[6];
  149.  
  150.     //Get the MAC address
  151.     sceWlanGetEtherAddr(macad);
  152.     //Connect to adhoc ctl
  153.     sceNetAdhocctlCreateEnterGameMode(name, 1, 16, macad, 1000000, 0);
  154.        
  155.  
  156. }
  157. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement