Skip to content

Commit 6adb8bc

Browse files
committed
Support ad hoc(IBSS) mode
In this update, an ad hoc (IBSS) mode has been added. Add the 'NL80211_IFTYPE_ADHOC' interface type to wiphy, enabling it to switch to ad hoc (IBSS) mode through the 'vwifi_change_iface' operation. Implement 'vwifi_join_ibss' and 'vwifi_leave_ibss' based on the 'cfg80211_ops' structure to enable IBSS devices to join a specific IBSS cell and frequency band. In the global structure 'vwifi_context', add 'ibss_list' to facilitate finding IBSS devices. When a device joins, it will be added to the 'ibss_list', and when a device leaves, it will be removed. Implement the IBSS mode packet forwarding mechanism. Additionally, ad-hoc related test items have been added, and the IBSS devices are scannable. Update the README file to include information about IBSS mode. Additionally, WPA support for IBSS mode has been added. The 'wpa_supplicant_ibss.conf' is used to configure the IBSS network. Since using WPA to construct an IBSS network results in the BSSID being automatically generated by the system, the 'vwifi_join_ibss' function does not receive the BSSID parameter.
1 parent db7245e commit 6adb8bc

File tree

5 files changed

+536
-30
lines changed

5 files changed

+536
-30
lines changed

README.md

Lines changed: 214 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ $ pip3 install numpy matplotlib
3636
```
3737

3838
## Testing environment (non-virtio)
39+
To test the network environment, we can utilize the **Linux network namespace**.
40+
Linux network namespace allows us to isolate a network environment from the host system, providing its own routes, firewall rules, and network devices.
41+
Essentially, it creates a separate instance of the network stack.
42+
43+
Without network namespace, when virtual interfaces are created that share the same network namespace and start transmitting/receiving packets between them,
44+
the kernel will use the loopback device for packet transmission/reception. This behavior occurs because the kernel identifies that the sender and receiver are on the same host.
45+
46+
In conclusion, all the interfaces created by `vwifi` in the testing environment will be added to an isolated network namespace.
47+
### Infrastructure BSS
3948
<p align="center"><img src="assets/vwifi.png" alt="logo image" width=60%></p>
4049

4150
The testing environment consists of **one AP and two STAs**.
@@ -48,15 +57,12 @@ The AP then performs the following actions based on the packet type:
4857
2. Broadcast: The AP forwards the packet to all other STAs in the network, except for the source STA, and then passes it to the protocol stack.
4958
3. Multicast: The AP treats multicast packets the same way as broadcast packets.
5059

51-
To test the network environment, we can utilize the **Linux network namespace**.
52-
Linux network namespace allows us to isolate a network environment from the host system, providing its own routes, firewall rules, and network devices.
53-
Essentially, it creates a separate instance of the network stack.
54-
55-
Without network namespace, when virtual interfaces are created that share the same network namespace and start transmitting/receiving packets between them,
56-
the kernel will use the loopback device for packet transmission/reception. This behavior occurs because the kernel identifies that the sender and receiver are on the same host.
60+
### Independent BSS
61+
<p align="center"><img src="assets/ibss.png" alt="logo image" width=80%></p>
5762

58-
In conclusion, all the interfaces created by `vwifi` in the testing environment will be added to an isolated network namespace.
63+
The testing environment consists of **two IBSS devices**.
5964

65+
The testing environment operates in IEEE 802.11 independent BSS. IBSS devices can communicate with any device in the same IBSS network **without the need to establish a connection beforehand**. However, devices in different IBSS networks cannot communicate with each other.
6066
## Build and Run (non-virtio)
6167

6268
To build the kernel module, execute the following command:
@@ -72,7 +78,7 @@ $ sudo modprobe cfg80211
7278
Insert the `vwifi` driver.
7379
This will create three interfaces (the "station" parameter can be modified according to preference):
7480
```shell
75-
$ sudo insmod vwifi.ko station=3
81+
$ sudo insmod vwifi.ko station=5
7682
```
7783

7884
Please note that interfaces can only be created in station mode during the initialization phase.
@@ -85,7 +91,7 @@ To check the network interfaces, run the following command:
8591
$ ip link
8692
```
8793

88-
There should be entries starting with `vw0`, `vw1`, and `vw2`, which correspond to the interfaces created by `vwifi`.
94+
There should be entries starting with `vw0`, `vw1`, `vw2`, `vw3`, and `vw4`, which correspond to the interfaces created by `vwifi`.
8995

9096
To view the available wireless interfaces, execute the following command:
9197
```shell
@@ -94,24 +100,41 @@ $ sudo iw dev
94100

95101
You should see something similar to the following output:
96102
```
97-
phy#2
103+
phy#5
104+
Interface vw4
105+
ifindex 7
106+
wdev 0x500000001
107+
addr 00:76:77:34:00:00
108+
type managed
109+
txpower 0.00 dBm
110+
phy#4
111+
Interface vw3
112+
ifindex 6
113+
wdev 0x400000001
114+
addr 00:76:77:33:00:00
115+
type managed
116+
txpower 0.00 dBm
117+
phy#3
98118
Interface vw2
99119
ifindex 5
100-
wdev 0x200000001
101-
addr 00:6f:77:6c:32:00
120+
wdev 0x300000001
121+
addr 00:76:77:32:00:00
102122
type managed
103-
phy#1
123+
txpower 0.00 dBm
124+
phy#2
104125
Interface vw1
105126
ifindex 4
106-
wdev 0x100000001
107-
addr 00:6f:77:6c:31:00
127+
wdev 0x200000001
128+
addr 00:76:77:31:00:00
108129
type managed
109-
phy#0
130+
txpower 0.00 dBm
131+
phy#1
110132
Interface vw0
111133
ifindex 3
112-
wdev 0x1
113-
addr 00:6f:77:6c:30:00
134+
wdev 0x100000001
135+
addr 00:76:77:30:00:00
114136
type managed
137+
txpower 0.00 dBm
115138
```
116139

117140
As observed, each interface has its own phy (`struct wiphy`), allowing them to be placed into separate network namespaces.
@@ -125,6 +148,10 @@ $ sudo iw list
125148

126149
Reference output:
127150
```
151+
Wiphy vw_phy4
152+
(... omit)
153+
Wiphy vw_phy3
154+
(... omit)
128155
Wiphy vw_phy2
129156
(... omit)
130157
Wiphy vw_phy1
@@ -366,6 +393,175 @@ PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
366393
4 packets transmitted, 4 received, 0% packet loss, time 3058ms
367394
rtt min/avg/max/mdev = 0.054/0.141/0.342/0.117 ms
368395
```
396+
### IBSS mode
397+
398+
#### Creating Network Namespaces
399+
Create three network namespaces using the following commands:
400+
```shell
401+
$ sudo ip netns add ns3
402+
$ sudo ip netns add ns4
403+
```
404+
Find the `wiphy` name for the two interfaces.
405+
The index number for the `wiphy` name postfix might be different each time.
406+
Please use the following command for the ease of memorizing different index number everytime.
407+
```shell
408+
$ vw3_phy=$(sudo iw dev vw3 info | grep wiphy | awk '{print $2}')
409+
$ vw3_phy=$(sudo iw list | grep "wiphy index: $vw3_phy" -B 1 | grep Wiphy | awk '{print $2}')
410+
$ vw4_phy=$(sudo iw dev vw4 info | grep wiphy | awk '{print $2}')
411+
$ vw4_phy=$(sudo iw list | grep "wiphy index: $vw4_phy" -B 1 | grep Wiphy | awk '{print $2}')
412+
```
413+
Check whether the name of each `wiphy` is the same as the name listing under the command `sudo iw list`
414+
```shell
415+
$ echo $vw3_phy
416+
vw_phy3
417+
$ echo $vw4_phy
418+
vw_phy4
419+
```
420+
Assign the two interfaces to separate network namespaces.
421+
Please note that the `wiphy` is placed within the network namespace, and the interface associated with that wiphy will be contained within it.
422+
```shell
423+
$ sudo iw phy vw_phy3 set netns name ns3
424+
$ sudo iw phy vw_phy4 set netns name ns4
425+
```
426+
#### Assigning IP Addresses to Each Interface
427+
428+
Now, assign an IP address to both interfaces using the following commands:
429+
```shell
430+
$ sudo ip netns exec ns3 ip addr add 10.0.0.4/24 dev vw3
431+
$ sudo ip netns exec ns4 ip addr add 10.0.0.5/24 dev vw4
432+
```
433+
There are two methods to configure an IBSS network: manual configuration or using WPA.
434+
#### Option1 : Manual configuration
435+
##### Switch to IBSS mode
436+
Switch device to IBSS mode using the following command :
437+
438+
***iw dev [interface] set type ibss***
439+
440+
The following commands switch `vw3` and `vw4` to IBSS mode.
441+
```shell
442+
$ sudo ip netns exec ns3 iw dev vw3 set type ibss
443+
$ sudo ip netns exec ns4 iw dev vw4 set type ibss
444+
```
445+
Check the information of `vw3`.
446+
```shell
447+
$ sudo ip netns exec ns3 iw dev vw3 info
448+
```
449+
You should see output similar to the following:
450+
```
451+
Interface vw3
452+
ifindex 6
453+
wdev 0x400000001
454+
addr 00:76:77:33:00:00
455+
type IBSS
456+
wiphy 4
457+
txpower 0.00 dBm
458+
```
459+
##### Join IBSS network
460+
```shell
461+
$ sudo ip netns exec ns3 ip link set vw3 up
462+
$ sudo ip netns exec ns4 ip link set vw4 up
463+
```
464+
Users can join a specific IBSS cell and configure additional settings using the command :
465+
466+
***iw dev [interface] ibss join [SSID] [freq in MHz] [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz] [fixed-freq] [fixed-bssid] [beacon-interval <TU>] [basic-rates <rate in Mbps,rate2,…>] [mcast-rate <rate in Mbps>] [key d:0:abcde]***
467+
468+
If the IBSS cell does not already exist, it will be created.
469+
470+
The following command makes `vw3` and `vw4` join the same IBSS cell with the SSID `ibss1` and specifies the frequency as 2412 MHz:
471+
```shell
472+
$ sudo ip netns exec ns3 iw dev vw3 ibss join ibss1 2412 NOHT fixed-freq 00:76:77:33:00:00 beacon-interval 200
473+
$ sudo ip netns exec ns4 iw dev vw4 ibss join ibss1 2412 NOHT fixed-freq 00:76:77:33:00:00 beacon-interval 200
474+
```
475+
Check the information of `vw3`.
476+
```shell
477+
$ sudo ip netns exec ns3 iw dev vw3 info
478+
```
479+
You should see output similar to the following:
480+
```
481+
Interface vw3
482+
ifindex 6
483+
wdev 0x400000001
484+
addr 00:76:77:33:00:00
485+
ssid ibss1
486+
type IBSS
487+
wiphy 4
488+
txpower 0.00 dBm
489+
```
490+
#### Option2 : Using WPA
491+
```shell
492+
$ sudo ip netns exec ns3 ip link set vw3 up
493+
$ sudo ip netns exec ns4 ip link set vw4 up
494+
```
495+
Prepare the following script `wpa_supplicant_ibss.conf` (you can modify the script based on your needs):
496+
```shell
497+
network={
498+
ssid="ibss1"
499+
mode=1
500+
frequency=2412
501+
key_mgmt=WPA-PSK
502+
proto=RSN
503+
pairwise=CCMP
504+
group=CCMP
505+
psk="12345678"
506+
}
507+
```
508+
Using the command **wpa_supplicant**, configure `vw3` and `vw4` to join `ibss1`.
509+
```shell
510+
$ sudo ip netns exec ns3 wpa_supplicant -i vw3 -B -c scripts/wpa_supplicant_ibss.conf
511+
$ sudo ip netns exec ns4 wpa_supplicant -i vw4 -B -c scripts/wpa_supplicant_ibss.conf
512+
```
513+
Check the information of `vw3`.
514+
```shell
515+
$ sudo ip netns exec ns3 iw dev vw3 info
516+
```
517+
You should see output similar to the following:
518+
```
519+
Interface vw3
520+
ifindex 6
521+
wdev 0x400000001
522+
addr 00:76:77:33:00:00
523+
ssid ibss1
524+
type IBSS
525+
wiphy 4
526+
txpower 0.00 dBm
527+
```
528+
#### Transmission/Receivement test
529+
To perform a ping test between two IBSS devices (`vw3` and `vw4`) in the same ibss cell (`ibss1`), use the following command:
530+
```shell
531+
$ sudo ip netns exec ns3 ping -c 1 10.0.0.5
532+
```
533+
You should see output similar to the following:
534+
```
535+
PING 10.0.0.5 (10.0.0.5) 56(84) bytes of data.
536+
64 bytes from 10.0.0.5: icmp_seq=1 ttl=64 time=0.093 ms
537+
538+
--- 10.0.0.5 ping statistics ---
539+
1 packets transmitted, 1 received, 0% packet loss, time 0ms
540+
rtt min/avg/max/mdev = 0.093/0.093/0.093/0.000 ms
541+
```
542+
#### Leave IBSS network
543+
To leave the current IBSS cell, use ***iw dev [interface] ibss leave***.
544+
545+
The following command makes `vw3` and `vw4` leave `ibss1`:
546+
```shell
547+
$ sudo ip netns exec ns3 iw dev vw3 ibss leave
548+
$ sudo ip netns exec ns4 iw dev vw4 ibss leave
549+
```
550+
Check the information of `vw3`.
551+
```shell
552+
$ sudo ip netns exec ns3 iw dev vw3 info
553+
```
554+
You should see output similar to the following:
555+
```
556+
Interface vw3
557+
ifindex 6
558+
wdev 0x400000001
559+
addr 00:76:77:33:00:00
560+
type IBSS
561+
wiphy 4
562+
txpower 0.00 dBm
563+
```
564+
369565
### vwifi-tool
370566
A userspace tool which supports more user-specific utilization for vwifi.
371567
Aiming to provide more flexibility and customization for users of vwifi.

assets/ibss.png

153 KB
Loading

0 commit comments

Comments
 (0)