Making a usb wireless device config utility


Forum: Networking
Topic: Making a usb wireless device config utility
started by: SaidinUnleashed

Posted by SaidinUnleashed on Oct. 17 2004,06:28
Quote (Aiku @ Sep. 20 2004,01:19 (in the "Verified Wireless Cards" Thread))
Here is what I use for basic connection for my Netgear USB MA111

#!/bin/bash
wlanctl-ng wlan0 lnxreq_ifstate ifstate=enable
wlanctl-ng wlan0 lnxreq_autojoin ssid=YOUR_SSID authtype=opensystem
pump -i wlan0
kill `pidof wmnet`
wmnet -w -W wlan0 &

I mainly use it a public access points



I'm getting in the spirit of a real linux user and writing an app to do this easily.

It'll be in C++ as source, and I'll post the source here as well as emailing the binary to ke4nt1.

I'd write it in C, but I don't know how to use variables as a part of a system call in C, although I'm not 100% sure how to in C++, that's what I've been using lately. So deal.

Here's the incomplete source for what I have so far. far from finished, so it won't compile, but I wanted to share.

Code Sample
#include <iostream.h>
#include <string>
#include <stdlib.h>

int main()
{
// This program will configure your prism2_usb.o based USB wireless device for use in Damn Small Linux v.0.8.2
// This was thrown together by J.P. Nimmo, a.k.a. SaidinUnleased late at night, and as such may be buggy, crappy, ed up, or may not work all together. If you experience problems, fix it yourself.

 system ("clear");

 cout << "This program will configure and enable your prism2 based USB wireless device and restarts wmnet to monitor it.\n";

 short int menuchoice = 0;

 string devname = wlan0;

 string authtype = opensystem;

 string sid;

 while (menuchoice != 6)
  {
   cout << "--------MAKE SURE YOU DO 3--------\n";
   cout << "1 - run iwconfig \(so you can see the name of your USB wireless device, usually wlan0\)\n";
   cout << "2 - set your USB wireless device's name \(default wlan0\)\n";
   cout << "3 - set your SSID \(the name of the network, usually\)\n";
   cout << "4 - set your authtype \(default is opensystem\)\n";
   cout << "5 - execute the setup, according to your settings and exit\n";
   cout << "6 - Exit without doing anything\n"
   cout << "--------MAKE SURE YOU DO 3--------\n";
   cout << endl;
   cout << Enter your choice: ";

   cin >> menuchoice;

   if (menuchoice<1 || menuchoice>5)
    {
     cout << "THAT CHOICE IS NOT VALID!!!\n";
     cout << endl;
    }

   if (menuchoice == 1)
    {
     system ("sudo iwconfig");
     cout << endl;
    }

   if (menuchoice == 2)
    {
     cout << "Enter the name of the wireless device: ";
     cin >> devname;
     cout << endl;
    }

   if (menuchoice == 3)
    {
     cout << "Enter your SSID: ";
     cin ssid;
     cout << endl;
    }

   if (menuchoice == 5)
    {
     cout << "Executing config with Device name \"" << devname << "\" with SSID \" << ssid << "\" and authtype \"" << authtype << "\".\n";
     cout << "Is this correct? \(y or n\) ";

     char confirm;


Like I said, it's not finished, but it's a start. And it should work on all prism2_usb.o based devices, when it's done.

-J.P.
SaidinUnleashed

Posted by Aiku on Oct. 17 2004,06:49
It appears that 0.8.2 has a GUI for prims2 devices.
System->Net Setup->prism2

Posted by SaidinUnleashed on Oct. 17 2004,19:52
Yes, but it doesn't work with usb devices. Or, at least, I can't get it to work...

-J.P.
SaidinUnleashed

Posted by SaidinUnleashed on Oct. 17 2004,22:20
okay, it app is mostly done. Only thing is, I can't figure out how to use a variable's value in a system call, which is required to set the ssid.

so, this is my little attempt at getting some help.

the source code can be downloaded < here >/

In it's current form, the source won't compile, so unless you want to help me figure this out, please don't download it. very limited bandwidth there.

okay, here are the problems.

Lines 66 - 71: trying to make a confirm input that would accept Y and y as true, and N and n as false. Simple for someone with a lot of experience, which I don't have.

Lines 73 - 77: can't figure out how to use the value of a variable inside a system call.


anyways, I will continue to tinker with it next week untill someone fixes it here, or I figure it out.

Have fun.

-J.P.
SaidinUnleashed

Posted by somerville32@hotmail.com on Oct. 18 2004,00:55
Good job. Keep up the good work :)
Posted by SaidinUnleashed on Oct. 19 2004,17:22
figured out the confirmation part. well, more like ghtoo-rigged it. it's probably not right, but it'll do.

now just need to figure out how to use the value of a variable inside a system command...

-J.P.

Posted by SaidinUnleashed on Oct. 20 2004,02:42
-_- gave up on the C++ in favor of taking a crash course on shell scripting...

and IT WORKS!!!!

like a charm.

For those of you who want it NOW!!! it can be downloaded off of my filespace, < HERE >, also, the cpp file is no longer on my filespace.

I will be sending this to John, hopefully it will be in the next version of DSL, so that we dont have to remember the stuff from the original post...

-J.P.

Posted by zmef420 on Oct. 31 2004,09:56
is this in .8.3 ? i still don't have any luck.
Posted by mattjackets on Nov. 03 2004,23:00
if you're still interested in using c++, there are a few options depending on what you are trying to do...(for the system calls)

1)  create a temp string variable and append your different string litterals and variables in order to construct the system command.
this will only work if you only need string variables to be patched together.

2)  if you need, for example, and int variable to be in the middle of the string, the easiest way of do ing this is to setup an output stream...then it'll take formatted output just likd cout.
here's an example:  
Code Sample
command_string << "the command" << anInt << a_float << "whatever";



=====on another note=====

I'm using a prism3 usb card, andthe prism2 gui config tool works in 0.8.3 for me.

=====on another note=====

I'm working on a pretty raw sh script myself for setting up the network card....  it'll be able to jump from network to network without user intervention when i'm done......hopefuly.

do you have any idea on how to check if a certian ssid is within range?

+matt

Posted by SaidinUnleashed on Nov. 04 2004,00:58
no clue.

but when you're done, email the script to me, and i'll host it for you.

-J.P.

Posted by Nobody on Nov. 10 2004,11:48
# This script has worked well for me:
#!/bin/bash
linux:~/bin # ifconfig
modprobe prism2_usb prism2_doreset=1
wlanctl-ng wlan0 lnxreq_ifstate ifstate=enable
wlanctl-ng wlan0 lnxreq_autojoin ssid=gmtnet authtype=opensystem
# set up my IP
ifconfig wlan0 192.168.2.6

# And for encrypted wireless:
#!/bin/bash

ssid=gmtnet
wep="E2:74:5D:35:00"

modprobe prism2_usb prism2_doreset=1
wlanctl-ng wlan0 lnxreq_ifstate ifstate=enable

wlanctl-ng wlan0 lnxreq_hostwep decrypt=true encrypt=true
wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11WEPDefaultKeyID=0
wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11ExcludeUnencrypted=true
wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11PrivacyInvoked=true
wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11WEPDefaultKey0=$wep

wlanctl-ng wlan0 lnxreq_autojoin ssid=$ssid authtype="sharedkey"

# set up my IP
ifconfig wlan0 192.168.2.3 netmask 255.255.255.0
route add default gw 192.168.2.20

# And I stole both of those from the following post, thanks
#Gregory Toomey!!!!
# < http://www.w00tlinux.com/bb/sutra255903.html >

Posted by starcannon on Feb. 20 2006,02:40
Quote (Guest @ Nov. 10 2004,06:48)
# This script has worked well for me:
#!/bin/bash
linux:~/bin # ifconfig
modprobe prism2_usb prism2_doreset=1
wlanctl-ng wlan0 lnxreq_ifstate ifstate=enable
wlanctl-ng wlan0 lnxreq_autojoin ssid=gmtnet authtype=opensystem
# set up my IP
ifconfig wlan0 192.168.2.6

# And for encrypted wireless:
#!/bin/bash

ssid=gmtnet
wep="E2:74:5D:35:00"

modprobe prism2_usb prism2_doreset=1
wlanctl-ng wlan0 lnxreq_ifstate ifstate=enable

wlanctl-ng wlan0 lnxreq_hostwep decrypt=true encrypt=true
wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11WEPDefaultKeyID=0
wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11ExcludeUnencrypted=true
wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11PrivacyInvoked=true
wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11WEPDefaultKey0=$wep

wlanctl-ng wlan0 lnxreq_autojoin ssid=$ssid authtype="sharedkey"

# set up my IP
ifconfig wlan0 192.168.2.3 netmask 255.255.255.0
route add default gw 192.168.2.20

# And I stole both of those from the following post, thanks
#Gregory Toomey!!!!
# < http://www.w00tlinux.com/bb/sutra255903.html >

This works for the Averatec 3150p as well THANKS LOADS i was bangin my head on the wall, the wlan0 was showing up, I could mess with it even once got an ip addy onto it but couldnt ping anything on my lan, that little script fixed it though. Awesome thanks man!
Posted by xxooss on Feb. 20 2006,20:01
my problem is that DSL loses my wireless settings after a certain amount of time, i.e. i have to go in to DSL panel and reset the Prisim 2 channel to 10. it defaults to 11. Does someone know how to solve this?

peace

Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.