| … | |
… | |
| 66 | local key=$( iwconfig "$1" | grep -i -o "Encryption key:[0-9,A-F]" ) |
66 | local key=$( iwconfig "$1" | grep -i -o "Encryption key:[0-9,A-F]" ) |
| 67 | local mode status="disabled" |
67 | local mode status="disabled" |
| 68 | |
68 | |
| 69 | if [[ -n ${key} ]]; then |
69 | if [[ -n ${key} ]]; then |
| 70 | status="enabled" |
70 | status="enabled" |
| 71 | mode=" - $( iwconfig "$1" | sed -n -e 's/^.*Security mode:\(.*[^ ]\).*/\1/p' )" |
71 | mode="$( iwconfig $1 | sed -n -e 's/^.*Security mode:\(.*[^ ]\).*/\1/p' )" |
|
|
72 | [[ -n ${mode} ]] && mode=" - ${mode}" |
| 72 | fi |
73 | fi |
| 73 | |
74 | |
| 74 | echo "(WEP ${status}${mode})" |
75 | echo "(WEP ${status}${mode})" |
| 75 | } |
76 | } |
| 76 | |
77 | |
| … | |
… | |
| 79 | # Gets the current ESSID of the iface |
80 | # Gets the current ESSID of the iface |
| 80 | iwconfig_get_essid() { |
81 | iwconfig_get_essid() { |
| 81 | local i essid |
82 | local i essid |
| 82 | |
83 | |
| 83 | for (( i=0; i<5; i++ )); do |
84 | for (( i=0; i<5; i++ )); do |
| 84 | essid=$( iwgetid "$1" 2>/dev/null | sed -n -e 's/^.*ESSID:"\(.*\)"$/\1/p' ) |
85 | essid="$( iwgetid $1 2>/dev/null | sed -n -e 's/^.*ESSID:"\(.*\)"$/\1/p' )" |
| 85 | if [[ -n ${essid} ]]; then |
86 | if [[ -n ${essid} ]]; then |
| 86 | echo "${essid}" |
87 | echo "${essid}" |
| 87 | return 0 |
88 | return 0 |
| 88 | fi |
89 | fi |
| 89 | sleep 1 |
90 | sleep 1 |
| … | |
… | |
| 150 | key="mac_key_${mac//:/}" |
151 | key="mac_key_${mac//:/}" |
| 151 | [[ -z ${!key} ]] && key="key_${ESSIDVAR}" |
152 | [[ -z ${!key} ]] && key="key_${ESSIDVAR}" |
| 152 | echo "${!key:-off}" |
153 | echo "${!key:-off}" |
| 153 | } |
154 | } |
| 154 | |
155 | |
| 155 | # void iwconfig_user_config(char *iface) |
156 | # void iwconfig_user_config(char *iface, char *ifvar) |
| 156 | # |
157 | # |
| 157 | # Applies the user configuration to the interface |
158 | # Applies the user configuration to the interface |
| 158 | iwconfig_user_config() { |
159 | iwconfig_user_config() { |
| 159 | local iface="$1" conf ifvar=$( bash_variable "$1" ) |
160 | local iface="$1" conf aconf ifvar="$2" |
|
|
161 | [[ -z ${ifvar} ]] && ifvar=$( bash_variable "$1" ) |
| 160 | |
162 | |
| 161 | # Apply the user configuration |
163 | # Apply the user configuration |
| 162 | conf="iwconfig_${ifvar}" |
164 | conf="iwconfig_${ifvar}" |
| 163 | if [[ -n ${!conf} ]]; then |
165 | if [[ -n ${!conf} ]]; then |
|
|
166 | aconf=( "${!conf} ") |
|
|
167 | for conf in "${aconf[@]}" ; do |
| 164 | if ! eval iwconfig "${iface}" "${!conf}" ; then |
168 | if ! eval iwconfig "${iface}" "${conf}" ; then |
| 165 | ewarn "${iface} does not support the following configuration commands" |
169 | ewarn "${iface} does not support the following configuration commands" |
| 166 | eval ewarn " ${!conf}" |
170 | ewarn " ${conf}" |
| 167 | fi |
171 | fi |
|
|
172 | done |
| 168 | fi |
173 | fi |
| 169 | |
174 | |
| 170 | conf="iwpriv_${ifvar}" |
175 | conf="iwpriv_${ifvar}[@]" |
| 171 | if [[ -n ${!conf} ]]; then |
176 | if [[ -n ${!conf} ]]; then |
|
|
177 | aconf=( "${!conf}" ) |
|
|
178 | for conf in "${aconf[@]}" ; do |
| 172 | if ! eval iwpriv "${iface}" "${!conf}" ; then |
179 | if ! eval iwpriv "${iface}" "${conf}" ; then |
| 173 | ewarn "${iface} does not support the following private ioctls" |
180 | ewarn "${iface} does not support the following private ioctls" |
| 174 | ewarn " ${!conf}" |
181 | ewarn " ${conf}" |
| 175 | fi |
182 | fi |
|
|
183 | done |
| 176 | fi |
184 | fi |
| 177 | } |
185 | } |
| 178 | |
186 | |
| 179 | # bool iwconfig_setup_specific(char *iface) |
187 | # bool iwconfig_setup_specific(char *iface) |
| 180 | # |
188 | # |
| … | |
… | |
| 215 | ewarn "${iface} does not support setting keys" |
223 | ewarn "${iface} does not support setting keys" |
| 216 | ewarn "or the parameter \"mac_key_${ESSIDVAR}\" or \"key_${ESSIDVAR}\" is incorrect" |
224 | ewarn "or the parameter \"mac_key_${ESSIDVAR}\" or \"key_${ESSIDVAR}\" is incorrect" |
| 217 | fi |
225 | fi |
| 218 | fi |
226 | fi |
| 219 | |
227 | |
|
|
228 | iwconfig_user_config "${iface}" "${ESSIDVAR}" |
|
|
229 | |
| 220 | # Finally set the ESSID |
230 | # Finally set the ESSID |
| 221 | if ! iwconfig "${iface}" essid "${ESSID}" ; then |
231 | if ! iwconfig "${iface}" essid "${ESSID}" ; then |
| 222 | eerror "${iface} does not support setting ESSID to \"${dessid}\"" |
232 | eerror "${iface} does not support setting ESSID to \"${dessid}\"" |
| 223 | return 1 |
233 | return 1 |
| 224 | fi |
234 | fi |
| 225 | iwconfig "${iface}" nick "${ESSID}" 2>/dev/null |
235 | iwconfig "${iface}" nick "${ESSID}" 2>/dev/null |
| 226 | |
236 | |
| 227 | iwconfig_user_config "${iface}" |
|
|
| 228 | iwconfig_report "${iface}" |
237 | iwconfig_report "${iface}" |
| 229 | |
238 | |
| 230 | return 0 |
239 | return 0 |
| 231 | } |
240 | } |
| 232 | |
241 | |
| … | |
… | |
| 329 | unset ESSIDVAR |
338 | unset ESSIDVAR |
| 330 | else |
339 | else |
| 331 | ESSIDVAR=$( bash_variable "${ESSID}" ) |
340 | ESSIDVAR=$( bash_variable "${ESSID}" ) |
| 332 | key=$( iwconfig_get_wep_key "${mac}" ) |
341 | key=$( iwconfig_get_wep_key "${mac}" ) |
| 333 | if [[ ${wep_required} == "on" && ${key} == "off" ]]; then |
342 | if [[ ${wep_required} == "on" && ${key} == "off" ]]; then |
| 334 | vewarn "WEP key is not set for \"${dessid}\" - not connecting" |
343 | ewarn "WEP key is not set for \"${dessid}\"" |
| 335 | return 1 |
|
|
| 336 | fi |
344 | fi |
| 337 | if [[ ${wep_required} == "off" && ${key} != "off" ]]; then |
345 | if [[ ${wep_required} == "off" && ${key} != "off" ]]; then |
| 338 | key="off" |
346 | key="off" |
| 339 | vewarn "\"${dessid}\" is not WEP enabled - ignoring setting" |
347 | ewarn "\"${dessid}\" is not WEP enabled - ignoring setting" |
| 340 | fi |
348 | fi |
| 341 | |
349 | |
| 342 | if ! eval iwconfig "${iface}" key "${key}" ; then |
350 | if ! eval iwconfig "${iface}" key "${key}" ; then |
| 343 | if [[ ${key} != "off" ]]; then |
351 | if [[ ${key} != "off" ]]; then |
| 344 | ewarn "${iface} does not support setting keys" |
352 | ewarn "${iface} does not support setting keys" |
| … | |
… | |
| 346 | return 1 |
354 | return 1 |
| 347 | fi |
355 | fi |
| 348 | fi |
356 | fi |
| 349 | [[ ${key} != "off" ]] && w=$( iwconfig_get_wep_status "${iface}" ) |
357 | [[ ${key} != "off" ]] && w=$( iwconfig_get_wep_status "${iface}" ) |
| 350 | fi |
358 | fi |
|
|
359 | |
|
|
360 | iwconfig_user_config "${iface}" "${ESSIDVAR}" |
| 351 | |
361 | |
| 352 | if ! iwconfig "${iface}" essid "${ESSID}" ; then |
362 | if ! iwconfig "${iface}" essid "${ESSID}" ; then |
| 353 | if [[ ${ESSID} != "any" ]]; then |
363 | if [[ ${ESSID} != "any" ]]; then |
| 354 | ewarn "${iface} does not support setting ESSID to \"${dessid}\"" |
364 | ewarn "${iface} does not support setting ESSID to \"${dessid}\"" |
| 355 | fi |
365 | fi |
| … | |
… | |
| 380 | ESSID=$( iwconfig_get_essid "${iface}" ) |
390 | ESSID=$( iwconfig_get_essid "${iface}" ) |
| 381 | iwconfig_associate "${iface}" |
391 | iwconfig_associate "${iface}" |
| 382 | return $? |
392 | return $? |
| 383 | fi |
393 | fi |
| 384 | |
394 | |
| 385 | iwconfig_user_config "${iface}" |
|
|
| 386 | iwconfig_report "${iface}" |
395 | iwconfig_report "${iface}" |
| 387 | |
396 | |
| 388 | if is_function postassociate ; then |
397 | if is_function postassociate ; then |
| 389 | veinfo "Running postassociate function" |
398 | veinfo "Running postassociate function" |
| 390 | eindent |
399 | eindent |