MattSwarbrick
Posts: 27
Joined: Thu Oct 04, 2012 3:15 pm

netgear n150 adapter with ad-hoc and infrastructure mode

Tue Jan 15, 2013 1:13 pm

I'm using netgear n150 on wheezy and can connect to wireless networks no problem, by using wpa_cli and having sudo dhclient -1 wlan0 in /etc/rc.local to obtain ip from router. This works fine and am having no problems.
However I would also like to set up the pi as ad hoc so I can talk directly with it using ssh. I've tried setting the interface to adhoc mode and have had limited success. I've had it working by removing saved networks in wpa_cli, and add the following lines in rc.local:

Code: Select all

echo "Setting ad-hoc mode to wireless..."
sudo ifconfig wlan0 down
sudo iwconfig wlan0 mode ad-hoc
echo "ad-hoc mode set"
sudo iwconfig wlan0 essid "RPi"
echo "essid: RPi"
sudo ifconfig wlan0 192.168.1.1 netmask 255.255.255.0 up
echo "ip: 192.168.1.1"
This worked but died after a minute or so. I had just about enough time to connect from on iPhone. With ifconfig/iwconfig I could see that the adapter seemed to reset and change back to managed mode. Has anyone experience success with adhoc on pi?
My thoughts are to have two wireless interfaces for the one wireless device, namely wlan0 and wlan1, wlan0 for infrastructure and wlan1 for adhoc, has anyone done this? Is it possible with iw?
It was possible with Madwifi using the following commands:

Code: Select all

wlanconfig ath0 create wlandev wifi0 wlanmode adhoc
wlanconfig ath1 create wlandev wifi0 wlanmode managed
but Madwifi does not support usb adapters (according to their website)

MattSwarbrick
Posts: 27
Joined: Thu Oct 04, 2012 3:15 pm

Re: netgear n150 adapter with ad-hoc and infrastructure mode

Tue Jan 15, 2013 2:36 pm

So i think it is possible with iw, if you dont have iw get it by:

Code: Select all

sudo apt-get install iw
Then you can use iw to add a new interface by:

Code: Select all

sudo iw phy phy0 interface add wlan1 type adhoc
Where phy0 is the physical device. Note: to delete an interface use:

Code: Select all

sudo iw dev wlan1 del
where wlan1 is the device(interface) to delete
so if I type iwconfig I now get:

Code: Select all

lo        no wireless extensions.

wlan1     IEEE 802.11bgn  ESSID:off/any
          Mode:Ad-Hoc  Cell: Not-Associated   Tx-Power=20 dBm
          Retry  long limit:7   RTS thr:off   Fragment thr:off
          Power Management:off

wlan0     IEEE 802.11bgn  ESSID:"***********"
          Mode:Managed  Frequency:2.437 GHz  Access Point: **********************
          Bit Rate=72.2 Mb/s   Tx-Power=20 dBm
          Retry  long limit:7   RTS thr:off   Fragment thr:off
          Power Management:off
          Link Quality=63/70  Signal level=-47 dBm
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:4   Missed beacon:0

eth0      no wireless extensions.
This is not resetting so I'll now set it up on boot give it an ip and see if i can shell without connecting with infrastructure but at the same time maintain an infrastructure interface (which might or might not be connected to a router). This means one can easily ssh into a pi through adhoc and then connect to a wireless network

MattSwarbrick
Posts: 27
Joined: Thu Oct 04, 2012 3:15 pm

Re: netgear n150 adapter with ad-hoc and infrastructure mode

Tue Jan 15, 2013 4:36 pm

best I can do now is this:

Code: Select all

[email protected] ~ $ iwconfig
lo        no wireless extensions.

wlan1     IEEE 802.11bgn  ESSID:"RPi"
          Mode:Ad-Hoc  Frequency:2.412 GHz  Cell: Not-Associated
          Tx-Power=20 dBm
          Retry  long limit:7   RTS thr:off   Fragment thr:off
          Power Management:off

wlan0     IEEE 802.11bgn  ESSID:"**********"
          Mode:Managed  Frequency:2.437 GHz  Access Point: ******************
          Bit Rate=72.2 Mb/s   Tx-Power=20 dBm
          Retry  long limit:7   RTS thr:off   Fragment thr:off
          Power Management:off
          Link Quality=61/70  Signal level=-49 dBm
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:5   Missed beacon:0

eth0      no wireless extensions.
ifconfig shows:

Code: Select all

[email protected] ~ $ ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:fc:67:65
          inet addr:10.10.99.61  Bcast:10.10.99.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:640 errors:0 dropped:0 overruns:0 frame:0
          TX packets:984 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:44526 (43.4 KiB)  TX bytes:122735 (119.8 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr 00:12:7b:64:29:b4
          inet addr:10.10.98.58  Bcast:10.10.98.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:99 errors:0 dropped:1 overruns:0 frame:0
          TX packets:30 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:5931 (5.7 KiB)  TX bytes:4933 (4.8 KiB)

The /etc/rc.local looks like:

Code: Select all

 sudo dhclient -1 wlan0

echo "Creating adhoc interface on wireless device..."
sudo iw phy phy0 interface add wlan1 type adhoc
echo "[SUCCESSFUL]"
sudo ifconfig wlan1 down
echo "Setting ESSID..."
sudo iwconfig wlan1 essid "RPi"
echo "[SET] essid: RPi"
#echo "Setting IP..."
sudo ifconfig wlan1 192.168.1.1 netmask 255.255.255.0
echo "[SET] ip: 192.168.1.1"
The first line gives wlan0 (managed mode) an ip from the router. The problem I have are the last two lines as I get this error message:

Code: Select all

siocsifflags name not unique in network
Any suggestions? Is this because the MAC address of wlan0 and wlan1 are technically the same. I've looked at spoofing the address for wlan1 but I get an error which says "RTNETLINK answers: No buffer space available"

Return to “Networking and servers”