-
Notifications
You must be signed in to change notification settings - Fork 0
/
wireless_conf.sh
289 lines (253 loc) · 8.72 KB
/
wireless_conf.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/bin/bash
# -------------------- GROUP config verification --------------------- #
#TODO
# -------------------------- Wireless interface configuration -------------------------- #
# AP array parameters declaration
declare -a AP_CTRL_IP=()
declare -a AP_MCT_ADDR=()
declare -a AP_IF=()
declare -a AP_CONFIG=()
declare -a AP_HW_MODE=()
declare -a AP_CHANNEL=()
declare -a AP_ESSID=()
declare -a AP_TX_POWER=()
declare -a AP_IF_IP=()
AP_IF_CNT=0
# CLIENT array parameters declaration
declare -a CLIENT_CTRL_IP=()
declare -a CLIENT_MCT_ADDR=()
declare -a CLIENT_IF=()
declare -a CLIENT_CONFIG=()
declare -a CLIENT_ESSID=()
declare -a CLIENT_TX_POWER=()
declare -a CLIENT_IF_IP=()
CLIENT_IF_CNT=0
# ADHOC array parameters declaration
declare -a ADHOC_CTRL_IP=()
declare -a ADHOC_MCT_ADDR=()
declare -a ADHOC_IF=()
declare -a ADHOC_CHANNEL=()
declare -a ADHOC_ESSID=()
declare -a ADHOC_TX_POWER=()
declare -a ADHOC_IF_IP=()
ADHOC_IF_CNT=0
# MONITOR array parameters declaration
declare -a MONITOR_CTRL_IP=()
declare -a MONITOR_MCT_ADDR=()
declare -a MONITOR_IF=()
declare -a MONITOR_CHANNEL=()
MONITOR_IF_CNT=0
# GN array parameters declaration
declare -a GN_CTRL_IP=()
declare -a GN_MCT_ADDR=()
declare -a GN_IF=()
declare -a GN_PHY=()
declare -a GN_AFH_MODE=()
declare -a GN_IF_IP=()
GN_IF_CNT=0
# PANU array parameters declaration
declare -a PANU_CTRL_IP=()
declare -a PANU_MCT_ADDR=()
declare -a PANU_IF=()
declare -a PANU_PHY=()
declare -a PANU_AFH_MODE=()
declare -a PANU_REMOTE_IF=()
declare -a PANU_REMOTE_PHY=()
declare -a PANU_REMOTE_CTRL_IP=()
declare -a PANU_IF_IP=()
PANU_IF_CNT=0
# Retrieve all user defined GROUP names
GROUP_NAMEs=( $(declare -p | grep "declare -A GROUP_" | grep -vE GEDIT_CURRENT_LINE | grep -vE Dbg_source_* | cut -d_ -f 2- | cut -d= -f 1) )
for NAME in ${GROUP_NAMEs[*]}; do
# Per node configuration parameter
CTRL_IP=$(eval echo \${GROUP_$NAME[CTRL_IP]})
MCT_ADDR=$(eval echo \${GROUP_$NAME[MCT_ADDR]})
# Per interface configuration parameter
IF_STR=$(eval echo \${GROUP_$NAME[IF]})
# If interface is defined for the group
if [[ -n "$IF_STR" ]]; then
MODE_STR=$(eval echo \${GROUP_$NAME[MODE]})
CONFIG_STR=$(eval echo \${GROUP_$NAME[CONFIG]})
HW_MODE_STR=$(eval echo \${GROUP_$NAME[HW_MODE]})
CHANNEL_STR=$(eval echo \${GROUP_$NAME[CHANNEL]})
ESSID_STR=$(eval echo \${GROUP_$NAME[ESSID]})
TX_POWER_STR=$(eval echo \${GROUP_$NAME[TX_POWER]})
IF_IP_STR=$(eval echo \${GROUP_$NAME[IF_IP]})
AFH_MODE_STR=$(eval echo \${GROUP_$NAME[AFH_MODE]})
REMOTE_IF_STR=$(eval echo \${GROUP_$NAME[REMOTE_IF]})
REMOTE_CTRL_IP_STR=$(eval echo \${GROUP_$NAME[REMOTE_CTRL_IP]})
IF_ARRAY=(${IF_STR//:/ })
MODE_ARRAY=(${MODE_STR//:/ })
CONFIG_ARRAY=(${CONFIG_STR//:/ })
HW_MODE_ARRAY=(${HW_MODE_STR//:/ })
CHANNEL_ARRAY=(${CHANNEL_STR//:/ })
ESSID_ARRAY=(${ESSID_STR//:/ })
TX_POWER_ARRAY=(${TX_POWER_STR//:/ })
IF_IP_ARRAY=(${IF_IP_STR//:/ })
AFH_MODE_ARRAY=(${AFH_MODE_STR//:/ })
REMOTE_IF_ARRAY=(${REMOTE_IF_STR//:/ })
REMOTE_CTRL_IP_ARRAY=(${REMOTE_CTRL_IP_STR//:/ })
# Iterate through each interface of the group
for (( i = 0 ; i < ${#IF_ARRAY[@]} ; i++ )) do
IF=${IF_ARRAY[$i]}
MODE=${MODE_ARRAY[$i]}
CONFIG=${CONFIG_ARRAY[$i]}
HW_MODE=${HW_MODE_ARRAY[$i]}
CHANNEL=${CHANNEL_ARRAY[$i]}
ESSID=${ESSID_ARRAY[$i]}
TX_POWER=${TX_POWER_ARRAY[$i]}
IF_IP=${IF_IP_ARRAY[$i]}
AFH_MODE=${AFH_MODE_ARRAY[$i]}
REMOTE_IF=${REMOTE_IF_ARRAY[$i]}
REMOTE_CTRL_IP=${REMOTE_CTRL_IP_ARRAY[$i]}
if [[ $MODE == "master" ]]; then
# Fill up AP parameters
AP_CTRL_IP[AP_IF_CNT]=$CTRL_IP
AP_MCT_ADDR[AP_IF_CNT]=$MCT_ADDR
AP_IF[AP_IF_CNT]=$IF
AP_PHY[AP_IF_CNT]=phy${IF:${#IF}-1:1}
AP_CONFIG[AP_IF_CNT]=$CONFIG
AP_HW_MODE[AP_IF_CNT]=$HW_MODE
AP_CHANNEL[AP_IF_CNT]=$CHANNEL
AP_ESSID[AP_IF_CNT]=$ESSID
AP_TX_POWER[AP_IF_CNT]=$TX_POWER
AP_IF_IP[AP_IF_CNT]=$IF_IP
# Increment AP counter
AP_IF_CNT=$((AP_IF_CNT+1))
elif [[ $MODE == "managed" ]]; then
# Fill up CLIENT parameters
CLIENT_CTRL_IP[CLIENT_IF_CNT]=$CTRL_IP
CLIENT_MCT_ADDR[CLIENT_IF_CNT]=$MCT_ADDR
CLIENT_IF[CLIENT_IF_CNT]=$IF
CLIENT_PHY[CLIENT_IF_CNT]=phy${IF:${#IF}-1:1}
CLIENT_CONFIG[CLIENT_IF_CNT]=$CONFIG
CLIENT_ESSID[CLIENT_IF_CNT]=$ESSID
CLIENT_TX_POWER[CLIENT_IF_CNT]=$TX_POWER
CLIENT_IF_IP[CLIENT_IF_CNT]=$IF_IP
# Increment CLIENT counter
CLIENT_IF_CNT=$((CLIENT_IF_CNT+1))
elif [[ $MODE == "adhoc" ]]; then
# Fill up ADHOC parameters
ADHOC_CTRL_IP[ADHOC_IF_CNT]=$CTRL_IP
ADHOC_MCT_ADDR[ADHOC_IF_CNT]=$MCT_ADDR
ADHOC_IF[ADHOC_IF_CNT]=$IF
ADHOC_PHY[ADHOC_IF_CNT]=phy${IF:${#IF}-1:1}
ADHOC_CHANNEL[ADHOC_IF_CNT]=$CHANNEL
ADHOC_ESSID[ADHOC_IF_CNT]=$ESSID
ADHOC_TX_POWER[ADHOC_IF_CNT]=$TX_POWER
ADHOC_IF_IP[ADHOC_IF_CNT]=$IF_IP
# Increment ADHOC counter
ADHOC_IF_CNT=$((ADHOC_IF_CNT+1))
elif [[ $MODE == "monitor" ]]; then
# Fill up MONITOR parameters
MONITOR_CTRL_IP[MONITOR_IF_CNT]=$CTRL_IP
MONITOR_MCT_ADDR[MONITOR_IF_CNT]=$MCT_ADDR
MONITOR_IF[MONITOR_IF_CNT]=$IF
MONITOR_CHANNEL[AP_IF_CNT]=$CHANNEL
# Increment MONITOR counter
MONITOR_IF_CNT=$((MONITOR_IF_CNT+1))
elif [[ $MODE == "GN" ]]; then
# Fill up Bluetooth GN parameters
GN_CTRL_IP[GN_IF_CNT]=$CTRL_IP
GN_MCT_ADDR[GN_IF_CNT]=$MCT_ADDR
GN_IF[GN_IF_CNT]=$IF
GN_PHY[GN_IF_CNT]=hci${IF:${#IF}-1:1}
GN_AFH_MODE[GN_IF_CNT]=$AFH_MODE
GN_IF_IP[GN_IF_CNT]=$IF_IP
# Increment GN counter
GN_IF_CNT=$((GN_IF_CNT+1))
elif [[ $MODE == "PANU" ]]; then
# Fill up Bluetooth PANU parameters
PANU_CTRL_IP[PANU_IF_CNT]=$CTRL_IP
PANU_MCT_ADDR[PANU_IF_CNT]=$MCT_ADDR
PANU_IF[PANU_IF_CNT]=$IF
PANU_PHY[PANU_IF_CNT]=hci${IF:${#IF}-1:1}
PANU_AFH_MODE[PANU_IF_CNT]=$AFH_MODE
PANU_REMOTE_IF[PANU_IF_CNT]=$REMOTE_IF
PANU_REMOTE_PHY[PANU_IF_CNT]=hci${REMOTE_IF:${#REMOTE_IF}-1:1}
PANU_REMOTE_CTRL_IP[PANU_IF_CNT]=$REMOTE_CTRL_IP
PANU_IF_IP[PANU_IF_CNT]=$IF_IP
# Increment PANU counter
PANU_IF_CNT=$((PANU_IF_CNT+1))
fi
done
fi
done
# --------------------- GROUP_ALL_WIFI definition --------------------- #
WIFI_NODEs=($(printf "%s\n%s\n%s\n%s\n" ${AP_CTRL_IP[*]//,/ } ${CLIENT_CTRL_IP[*]//,/ } ${ADHOC_CTRL_IP[*]//,/ } ${MONITOR_CTRL_IP[*]//,/ } | sort -u))
if [[ ${#WIFI_NODEs[@]} -gt 0 ]]; then
declare -A GROUP_ALL_WIFI=(
[CTRL_IP]=$(IFS=, eval echo '"${WIFI_NODEs[*]}"')
[MCT_ADDR]=$(eval echo $RAND_MCT_ADDR)
)
GROUP_NAMEs+=("ALL_WIFI")
fi
# --------------------- GROUP_ALL_BT definition --------------------- #
BT_NODEs=($(printf "%s\n%s\n" ${GN_CTRL_IP[*]//,/ } ${PANU_CTRL_IP[*]//,/ } | sort -u))
if [[ ${#BT_NODEs[@]} -gt 0 ]]; then
declare -A GROUP_ALL_BT=(
[CTRL_IP]=$(IFS=, eval echo '"${BT_NODEs[*]}"')
[MCT_ADDR]=$(eval echo $RAND_MCT_ADDR)
)
GROUP_NAMEs+=("ALL_BT")
fi
# --------------------- GROUP_ALL_AP definition --------------------- #
if [[ $AP_IF_CNT -gt 0 ]]; then
declare -A GROUP_ALL_AP=(
[CTRL_IP]=$(IFS=, eval echo '"${AP_CTRL_IP[*]}"')
[MCT_ADDR]=$(eval echo $RAND_MCT_ADDR)
)
GROUP_NAMEs+=("ALL_AP")
fi
# --------------------- GROUP_ALL_CLIENT definition --------------------- #
if [[ $CLIENT_IF_CNT -gt 0 ]]; then
declare -A GROUP_ALL_CLIENT=(
[CTRL_IP]=$(IFS=, eval echo '"${CLIENT_CTRL_IP[*]}"')
[MCT_ADDR]=$(eval echo $RAND_MCT_ADDR)
)
GROUP_NAMEs+=("ALL_CLIENT")
fi
# --------------------- GROUP_ALL_ADHOC definition --------------------- #
if [[ $ADHOC_IF_CNT -gt 0 ]]; then
declare -A GROUP_ALL_ADHOC=(
[CTRL_IP]=$(IFS=, eval echo '"${ADHOC_CTRL_IP[*]}"')
[MCT_ADDR]=$(eval echo $RAND_MCT_ADDR)
)
GROUP_NAMEs+=("ALL_ADHOC")
fi
# --------------------- GROUP_ALL_MONITOR definition --------------------- #
if [[ $MONITOR_IF_CNT -gt 0 ]]; then
declare -A GROUP_ALL_MONITOR=(
[CTRL_IP]=$(IFS=, eval echo '"${MONITOR_CTRL_IP[*]}"')
[MCT_ADDR]=$(eval echo $RAND_MCT_ADDR)
)
GROUP_NAMEs+=("ALL_MONITOR")
fi
# --------------------- GROUP_ALL_GN definition --------------------- #
if [[ $GN_IF_CNT -gt 0 ]]; then
declare -A GROUP_ALL_GN=(
[CTRL_IP]=$(IFS=, eval echo '"${GN_CTRL_IP[*]}"')
[MCT_ADDR]=$(eval echo $RAND_MCT_ADDR)
)
GROUP_NAMEs+=("ALL_GN")
fi
# --------------------- GROUP_ALL_PANU definition --------------------- #
if [[ $PANU_IF_CNT -gt 0 ]]; then
declare -A GROUP_ALL_PANU=(
[CTRL_IP]=$(IFS=, eval echo '"${PANU_CTRL_IP[*]}"')
[MCT_ADDR]=$(eval echo $RAND_MCT_ADDR)
)
GROUP_NAMEs+=("ALL_PANU")
fi
# --------------------- GROUP_ALL definition --------------------- #
# From all defined GROUPs, retrieve control IPs
CTRL_IPs=()
for (( i = 0 ; i < ${#GROUP_NAMEs[@]} ; i++ )) do
CTRL_IPs[i]=`eval echo \\\${GROUP_${GROUP_NAMEs[$i]}[CTRL_IP]}`
done
# Create the GROUP_ALL associative array
declare -A GROUP_ALL=(
[CTRL_IP]=$(IFS=, eval echo '"${CTRL_IPs[*]}"')
[MCT_ADDR]=$(eval echo $RAND_MCT_ADDR)
[NAME]=$(IFS=, eval echo '"${GROUP_NAMEs[*]}"')
)