xref: /aosp_15_r20/external/wmediumd/tests/func (revision 621120a22a0cd8ba80b131fe8bcb37c86ff453e3)
1function freq_to_chan {
2	local freq=$1
3
4	if [[ $freq -ge 2412 && $freq -le 2472 ]]; then
5		band="11g"
6		chan=$(( ($freq - 2412) / 5 + 1 ))
7	else
8		band="11a"
9		chan=$(( ($freq - 5000) / 5 ))
10	fi
11	echo "$chan $band"
12}
13
14
15function meshup-iw {
16	local if=$1
17	local meshid=$2
18	local freq=$3
19	local ip=$4
20
21	ip link set $if down
22	iw dev $if set type mp
23	ip link set $if up
24	iw dev $if mesh join $meshid freq $freq
25	ip addr add $ip/24 dev $if 2>/dev/null
26}
27
28function meshup-wpas-open {
29	local if=$1
30	local meshid=$2
31	local freq=$3
32	local ip=$4
33
34	ip link set $if down
35	iw dev $if set type mp
36	ip link set $if up
37
38	cat<<EOM > /tmp/wpas-$if.conf
39network={
40	ssid="wmediumd-mesh"
41	mode=5
42	frequency=$freq
43	key_mgmt=NONE
44}
45EOM
46	wpa_supplicant -i $if -c /tmp/wpas-$if.conf &
47	ip addr add $ip/24 dev $if 2>/dev/null
48}
49
50function meshup-wpas {
51	local if=$1;
52	local meshid=$2;
53	local freq=$3;
54	local ip=$4;
55
56	ip link set $if down
57	iw dev $if set type mp
58	ip link set $if up
59
60	cat<<EOM > /tmp/wpas-$if.conf
61network={
62	ssid="wmediumd-mesh-sec"
63	mode=5
64	frequency=$freq
65	key_mgmt=SAE
66	psk="some passphrase"
67}
68EOM
69	wpa_supplicant -i $if -c /tmp/wpas-$if.conf &
70	ip addr add $ip/24 dev $if 2>/dev/null
71}
72
73function meshup-authsae {
74	local if=$1;
75	local meshid=$2;
76	local freq=$3;
77	local ip=$4;
78
79	ip link set $if down
80	iw dev $if set type mp
81	ip link set $if up
82
83	chan_params=$(freq_to_chan $freq)
84	read -ra ch <<< "$chan_params"
85
86	cat<<EOM > /tmp/authsae-$if.conf
87authsae:
88{
89 sae:
90  {
91    debug = 480;
92    password = "some passphrase";
93    group = [19, 26, 21, 25, 20];
94    blacklist = 5;
95    thresh = 5;
96    lifetime = 3600;
97  };
98 meshd:
99  {
100    meshid = "wmediumd-mesh-sec";
101    interface = "wlan0";
102    passive = 0;
103    secured = 1;
104    debug = 1;
105    mediaopt = 1;
106    band = "${ch[1]}";
107    channel = ${ch[0]};
108  };
109};
110EOM
111	meshd-nl80211 -i $if -c /tmp/authsae-$if.conf &
112	ip addr add $ip/24 dev $if 2>/dev/null
113}
114
115function addr2phy {
116	local addr=$1;
117	grep -l $addr /sys/class/ieee80211/phy*/macaddress | \
118		awk -F '/' '{print $(NF-1)}'
119}
120