Skip to content

Commit b3786f1

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.
1 parent db7245e commit b3786f1

File tree

4 files changed

+487
-30
lines changed

4 files changed

+487
-30
lines changed

README.md

Lines changed: 174 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,135 @@ 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+
#### Switch to IBSS mode
434+
Switch device to IBSS mode using the following command :
435+
436+
***iw dev [interface] set type ibss***
437+
438+
The following commands switch `vw3` and `vw4` to IBSS mode.
439+
```shell
440+
$ sudo ip netns exec ns3 iw dev vw3 set type ibss
441+
$ sudo ip netns exec ns4 iw dev vw4 set type ibss
442+
```
443+
Check the information of `vw3`.
444+
```shell
445+
$ sudo ip netns exec ns3 iw dev vw3 info
446+
```
447+
You should see output similar to the following:
448+
```
449+
Interface vw3
450+
ifindex 6
451+
wdev 0x400000001
452+
addr 00:76:77:33:00:00
453+
type IBSS
454+
wiphy 4
455+
txpower 0.00 dBm
456+
```
457+
#### Join IBSS network
458+
```shell
459+
$ sudo ip netns exec ns3 ip link set vw3 up
460+
$ sudo ip netns exec ns4 ip link set vw4 up
461+
```
462+
Users can join a specific IBSS cell and configure additional settings using the command :
463+
464+
***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]***
465+
466+
If the IBSS cell does not already exist, it will be created.
467+
468+
The following command makes `vw3` and `vw4` join the same IBSS cell with the SSID `ibss1` and specifies the frequency as 2412 MHz:
469+
```shell
470+
$ sudo ip netns exec ns3 iw dev vw3 ibss join ibss1 2412 NOHT fixed-freq 00:76:77:33:00:00 beacon-interval 200
471+
$ sudo ip netns exec ns4 iw dev vw4 ibss join ibss1 2412 NOHT fixed-freq 00:76:77:33:00:00 beacon-interval 200
472+
```
473+
Check the information of `vw3`.
474+
```shell
475+
$ sudo ip netns exec ns3 iw dev vw3 info
476+
```
477+
You should see output similar to the following:
478+
```
479+
Interface vw3
480+
ifindex 6
481+
wdev 0x400000001
482+
addr 00:76:77:33:00:00
483+
ssid ibss1
484+
type IBSS
485+
wiphy 4
486+
txpower 0.00 dBm
487+
```
488+
#### Transmission/Receivement test
489+
To perform a ping test between two IBSS devices (`vw3` and `vw4`) in the same ibss cell (`ibss1`), use the following command:
490+
```shell
491+
$ sudo ip netns exec ns3 ping -c 1 10.0.0.5
492+
```
493+
You should see output similar to the following:
494+
```
495+
PING 10.0.0.5 (10.0.0.5) 56(84) bytes of data.
496+
64 bytes from 10.0.0.5: icmp_seq=1 ttl=64 time=0.093 ms
497+
498+
--- 10.0.0.5 ping statistics ---
499+
1 packets transmitted, 1 received, 0% packet loss, time 0ms
500+
rtt min/avg/max/mdev = 0.093/0.093/0.093/0.000 ms
501+
```
502+
#### Leave IBSS network
503+
To leave the current IBSS cell, use ***iw dev [interface] ibss leave***.
504+
505+
The following command makes `vw3` and `vw4` leave `ibss1`:
506+
```shell
507+
$ sudo ip netns exec ns3 iw dev vw3 ibss leave
508+
$ sudo ip netns exec ns4 iw dev vw4 ibss leave
509+
```
510+
Check the information of `vw3`.
511+
```shell
512+
$ sudo ip netns exec ns3 iw dev vw3 info
513+
```
514+
You should see output similar to the following:
515+
```
516+
Interface vw3
517+
ifindex 6
518+
wdev 0x400000001
519+
addr 00:76:77:33:00:00
520+
type IBSS
521+
wiphy 4
522+
txpower 0.00 dBm
523+
```
524+
369525
### vwifi-tool
370526
A userspace tool which supports more user-specific utilization for vwifi.
371527
Aiming to provide more flexibility and customization for users of vwifi.

assets/ibss.png

153 KB
Loading

0 commit comments

Comments
 (0)