Hi, I'm not entirely sure what I am doing. WEP key connect

Post Reply
funkadil
Posts: 6
Joined: Thu Aug 06, 2009 6:23 am

Hi, I'm not entirely sure what I am doing. WEP key connect

Post by funkadil » Thu Aug 06, 2009 6:32 am

Code: Select all

// Wifi_ConnectAP: Connect to an access point
//  Wifi_AccessPoint * apdata:  basic data on the AP
//  int wepmode:                                indicates whether wep is used, and what kind
//  int wepkeyid:                               indicates which wep key ID to use for transmitting
//  unsigned char * wepkey:             the wep key, to be used in all 4 key slots (should make this more flexible in the future)
//  Returns:                                    0 for ok, -1 for error with input data
extern int Wifi_ConnectAP(Wifi_AccessPoint * apdata, int wepmode, int wepkeyid, unsigned char * wepkey);
First question: Is the only documentation for dswifi found by looking at the file dswifi9.h? I found the libnds.devkitpro.org site which is really well made but is there an official documentation for dswifi?

Second question: What am I supposed to put in the Wifi_ConnectAP to get it to work? I guess I'm probably missing something obvious but I'm currently really confused. I have a program which shows a list of the Access Points and lets the user choose one. Then, if it it WEP, it will ask for a 10-digit key. The only thing I am confused about is what is a "wepkeyid", and how do I find it? I'm sure its something very simple but I don't know where to look. I'm assuming the actual key is the "wepkey" entry).

thanks guys!

elhobbs
Posts: 358
Joined: Thu Jul 02, 2009 1:19 pm

Re: Hi, I'm not entirely sure what I am doing. WEP key connect

Post by elhobbs » Thu Aug 06, 2009 1:28 pm

there are 4 wepkeys associated with an access point. the wepkeyid indicates which one you are using. this depend on which key you are using from your access point. I think most people tend to just use the first key - some software assumes this to always be true.

though you may already know this - 64bit wep has 10 digit wepkey and 128bit has a 26 character wepkey.

funkadil
Posts: 6
Joined: Thu Aug 06, 2009 6:23 am

Re: Hi, I'm not entirely sure what I am doing. WEP key connect

Post by funkadil » Thu Aug 06, 2009 8:42 pm

Ooooh... So I should probably just put 0 in there? Makes a lot of sense now, for some reason I thought it would be some complicated string I would have to get out the the access point struct or something.

EDIT: okay sorry, I have another question that might sound stupid. But for the WEP key, what should the unsigned char look like? Should it be hex numbers like 1-9 a-f, or integers, or something else? I'm trying to use scanf to get the 10-digit hex key(later there will be options for other lengths) from the user, if I use %u, I get a warning saying that is only for unsigned ints, if I use an x, I would have to store it in an integer, or array of integers. But I'm not really sure how to convert it because I don't really understand what the information is even supposed to look like when I send it off in the wif_connectAP function.

elhobbs
Posts: 358
Joined: Thu Jul 02, 2009 1:19 pm

Re: Hi, I'm not entirely sure what I am doing. WEP key connect

Post by elhobbs » Thu Aug 06, 2009 9:55 pm

the wepkey is a hex encoded string. no conversion needed. so either 10 or 26 characters in the string. 0-9 and a-f are valid characters.

funkadil
Posts: 6
Joined: Thu Aug 06, 2009 6:23 am

Re: Hi, I'm not entirely sure what I am doing. WEP key connect

Post by funkadil » Fri Aug 07, 2009 6:23 am

thanks elhobbs! Works wonders. I'm still not able to get a valid connection (ASSOCSTATUS_CANNOTCONNECT), but I think I'm on the right track. I'm modifying the example code for connecting to access points so I can use WEP. I'm pretty sure my error has something to do with the wepkey string. I looks like it is about to work(lots of ..............s), but it just ends up failing.

Code: Select all

  while(1)
    {
        int status = ASSOCSTATUS_DISCONNECTED;

        Wifi_AccessPoint* ap = findAP();

        iprintf("Connecting to %s\n", ap->ssid);

        //this tells the wifi lib to use dhcp for everything
        Wifi_SetIP(0,0,0,0,0);

        if(ap->flags & WFLAG_APDATA_WEP){
            unsigned char wepkey[256];
            iprintf("WEP code for %s: ", ap->ssid);
            scanf("%s", &wepkey[0]);

        consoleClear();
        iprintf("attempting to connect to %s using WEP key %s...\n", ap->ssid, wepkey);
        Wifi_ConnectAP(ap, WEPMODE_40BIT, 0, &wepkey[0]);
        }
        else{
            Wifi_ConnectAP(ap, WEPMODE_NONE, 0, 0);
        }
        while(status != ASSOCSTATUS_ASSOCIATED && status != ASSOCSTATUS_CANNOTCONNECT)
        {
            int oldStatus = status;

            status = Wifi_AssocStatus();            

             iprintf("%s", oldStatus != status ? ASSOCSTATUS_STRINGS[status] : ".");

            scanKeys();

            if(keysDown() & KEY_B) break;

            swiWaitForVBlank();
        }


        consoleClear();
        consoleSetWindow(NULL, 0,0,32,10);

        char url[256];

        if(status == ASSOCSTATUS_ASSOCIATED) while(1)
        {
            u32 ip = Wifi_GetIP();

            iprintf("ip: [%i.%i.%i.%i]", (ip ) & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, (ip >> 24) & 0xFF);

            scanf("%s", url);

            struct hostent *host = gethostbyname(url);

            if(host)
                iprintf("IP (%s) : %s\n",  url, inet_ntoa(*(struct in_addr *)host->h_addr_list[0]));
            else
                iprintf("Could not resolve\n");

            scanKeys();

            if(keysDown() & KEY_B) break;

   swiWaitForVBlank();
        }
        else {
            iprintf("status: %s\n", ASSOCSTATUS_STRINGS[status]);
            while(1){
                scanKeys();
                if(keysDown() & KEY_B) break;
            }
    }
    return 0;
}



elhobbs
Posts: 358
Joined: Thu Jul 02, 2009 1:19 pm

Re: Hi, I'm not entirely sure what I am doing. WEP key connect

Post by elhobbs » Fri Aug 07, 2009 1:21 pm

valid values for wepkeyid are 1,2,3,4 - I suspect you want to use 1 instead of 0.

funkadil
Posts: 6
Joined: Thu Aug 06, 2009 6:23 am

Re: Hi, I'm not entirely sure what I am doing. WEP key connect

Post by funkadil » Sat Aug 08, 2009 12:44 pm

Oh, okay cool, I kind of suspected that. I'll try that out tomorrow. Man, thanks elhobbs, I hope you don't find my questions annoying or stupid or anything, I've just been getting back into programming after a long break and I am a little bit out of my mind these days. Everything you have posted here has been helpful, I'm not as lazy as I might sound, I've been trying to look these things up but I get in these situations where I think I am just totally on the wrong track where really I could have just tried something simple that crossed my mind in the first place, but didn't end up trying.

EDIT: Dang, its still not working. I even tried putting a '\0' at wepkey[10] just to make sure the string was legit, which I think it was in the first place. I'm using 1 for the key ID. I think my problem lies elsewhere, in the connection, perhaps the router doesn't like my DS. If I enter the correct key, I get ASSOCSTATUS_AUTHENTICATING followed by ASSOCSTATUS_AQUIRINGDHCP, but when I enter a junk key, it goes straight into AQUIRINGDHCP.... So I think it is authenticating correctly now, but I'm still not getting anything, just "ASSOCSTATUS_CANNOTCONNECT", strange. I wish I had some open wireless networks I could try on just to see if my DSlite is sucking or something.

heres everything I've got as far as code, its just one file. http://pastebin.com/m3d66edd4, if anybody wants to compile this and try it to see if its just some connection problem on my end, that would be awesome!

funkadil
Posts: 6
Joined: Thu Aug 06, 2009 6:23 am

Re: Hi, I'm not entirely sure what I am doing. WEP key connect

Post by funkadil » Thu Aug 13, 2009 2:51 am

I can't connect to open OR closed networks. So something else is wrong with the code. I wonder if this example ever worked in the first place? When I tested it out, it was unreadable because the keyboard was on top of the text in the terminal, so I changed that. Its not my DS or my connection, DSorganize works flawlessly.

elhobbs
Posts: 358
Joined: Thu Jul 02, 2009 1:19 pm

Re: Hi, I'm not entirely sure what I am doing. WEP key connect

Post by elhobbs » Thu Aug 13, 2009 1:19 pm

are you sure the ap is using 40 bit wep? this setting and the wepkey itself are the most probable causes of your issues - particularly if dsoraganize is able to connect to the same ap.

funkadil
Posts: 6
Joined: Thu Aug 06, 2009 6:23 am

Re: Hi, I'm not entirely sure what I am doing. WEP key connect

Post by funkadil » Sun Aug 16, 2009 10:39 pm

I don't think so, I think the problem is that for some reason DHCP is failing. I can't connect to open networks either using this code. Yes, its most definitely 40-bit, the key is a 10-digit phone number. Anyways, for now I've moved on to just using the firmware settings to connect(which works perfectly so far), and I'm going to focus on the actual telnet communication aspect of my program. Once i figure out what was going wrong originally I will try to include the option to choose a network manually. I think perhaps something wasn't fully initialized in the wifi aspect of the program.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 6 guests