~ubuntu-branches/ubuntu/vivid/wpasupplicant/vivid

« back to all changes in this revision

Viewing changes to debian/ifupdown.sh

  • Committer: Bazaar Package Importer
  • Author(s): Kel Modderman
  • Date: 2006-10-05 08:04:01 UTC
  • mfrom: (1.1.5 upstream) (3 etch)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20061005080401-r8lqlix4390yos7b
Tags: 0.5.5-2
* Update madwifi headers to latest SVN. (Closes: #388316)
* Remove failed attempt at action locking. [debian/functions.sh,
  debian/wpa_action.sh]
* Add hysteresis checking functions, to avoid "event loops" while
  using wpa-roam. [debian/functions.sh, debian/wpa_action.sh]
* Change of co-maintainer email address.
* Add ishex() function to functions.sh to determine wpa-psk value type in
  plaintext or hex. This effectively eliminates the need for the bogus and
  somewhat confusing wpa-passphrase contruct specific to our scripts and
  allows wpa-psk to work with either a 8 to 63 character long plaintext
  string or 64 character long hex string.
* Adjust README.modes to not refer to the redundant wpa-passphrase stuff.
* Add big fat NOTE about acceptable wpa-psk's to top of example gallery.
* Strip surrounding quotes from wpa-ssid if present, instead of just whining
  about them.
* Update email address in copyright blurb of functions.sh, ifupdown.sh and
  wpa_action.sh.  

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/sh
2
2
 
3
 
# Copyright (C) 2006 Kel Modderman <kelrin@tpg.com.au>
 
3
# Copyright (C) 2006 Kel Modderman <kelmo@kanotixguide.org>
4
4
#
5
5
# This program is free software; you can redistribute it and/or
6
6
# modify it under the terms of the GNU General Public License
24
24
        exit 0
25
25
fi
26
26
 
27
 
WPA_SUP_BIN="/sbin/wpa_supplicant"
28
 
WPA_SUP_PNAME="wpa_supplicant"
29
 
WPA_SUP_PIDFILE="/var/run/wpa_supplicant.$IFACE.pid"
30
 
 
31
 
WPA_CLI_BIN="/sbin/wpa_cli"
32
 
WPA_CLI_PNAME="wpa_cli"
33
 
WPA_CLI_PIDFILE="/var/run/wpa_action.$IFACE.pid"
34
 
WPA_CLI_LOCKFILE="/var/lock/wpa_action.$IFACE.lock"
35
 
 
36
 
# path to common ctrl_interface socket for active interfaces
37
 
# this is the default path provided by upstream
38
 
WPA_CTRL_DIR="/var/run/wpa_supplicant"
 
27
if [ -f /etc/wpa_supplicant/functions.sh ]; then
 
28
        . /etc/wpa_supplicant/functions.sh
 
29
else
 
30
        exit 0
 
31
fi
39
32
 
40
33
# quit if executables are not installed
41
 
if [ ! -x "$WPA_SUP_BIN" -o ! -x "$WPA_CLI_BIN" ]; then
 
34
if [ ! -x "$WPA_SUP_BIN" ] || [ ! -x "$WPA_CLI_BIN" ]; then
42
35
        exit 0
43
36
fi
44
37
 
45
 
if [ -n "$IF_WPA_VERBOSITY" -o "$VERBOSITY" = "1" ]; then
46
 
        # show wpa_cli messages when VERBOSITY has been set
47
 
        TO_NULL="/dev/stdout"
48
 
        # start-stop-daemon verbosity
49
 
        DAEMON_VERBOSITY="--verbose"
50
 
else
51
 
        # hide infomational messages when VERBOSITY is not set
52
 
        TO_NULL="/dev/null"
53
 
        # start-stop-daemon is quiet
54
 
        DAEMON_VERBOSITY="--quiet"
55
 
fi
56
 
 
57
 
# error and verbose informational messages
58
 
wpa_msg () {
59
 
        case "$1" in 
60
 
                "verbose")
61
 
                        # verbose message terminated with newline
62
 
                        shift
63
 
                        echo "$WPA_SUP_PNAME: $@" >$TO_NULL
64
 
                        ;;
65
 
                "action")
66
 
                        # verbose action message with no trailing newline
67
 
                        # useful for displaying wpa_cli feedback (OK|FAILED)
68
 
                        shift
69
 
                        echo -n "$WPA_SUP_PNAME: $@ -- " >$TO_NULL
70
 
                        ;;
71
 
                "stderr")
72
 
                        # error message
73
 
                        # commonly followed by an exit statement
74
 
                        shift
75
 
                        echo "$WPA_SUP_PNAME: $@...aborting!" >/dev/stderr
76
 
                        ;;
77
 
                *)
78
 
                        ;;
79
 
        esac
80
 
}
81
 
 
82
 
test_daemon_pidfile () {
83
 
        local DAEMON PIDFILE
84
 
        # daemon executable is first argument
85
 
        if [ -n "$1" ]; then
86
 
                DAEMON="$1"
87
 
        fi
88
 
        # daemon pidfile to be tested
89
 
        if [ -f "$2" ]; then
90
 
                PIDFILE="$2"
91
 
        fi
92
 
        # do the test if both exist
93
 
        if [ -n "$DAEMON" -a -f "$PIDFILE" ]; then
94
 
                # return 0 when $PIDFILE was created by $DAEMON
95
 
                # return 1 otherwise
96
 
                if start-stop-daemon --stop --quiet --signal 0 \
97
 
                        --exec "$DAEMON" --pidfile "$PIDFILE"; then
98
 
                        return 0
99
 
                else
100
 
                        # pidfile is invalid, not created by $DAEMON
101
 
                        wpa_msg verbose "removing stale pidfile \"$PIDFILE\""
102
 
                        rm -f "$PIDFILE"
103
 
                        return 1
104
 
                fi
105
 
        else
106
 
                return 1
107
 
        fi
108
 
}
109
 
 
110
38
# quit if wpa_action is active
111
 
if test_daemon_pidfile "$WPA_CLI_BIN" "$WPA_CLI_PIDFILE"; then
 
39
if test_wpa_cli; then
112
40
        exit 0
113
41
fi
114
42
 
 
43
# preliminary sanity checks for roaming daemon
115
44
if [ -n "$IF_WPA_ROAM" ]; then
116
 
        # wpa-roam is only funtional in conjunction with the 'manual' inet METHOD
117
45
        if [ "$METHOD" != "manual" ]; then
118
46
                wpa_msg stderr "wpa-roam can only be used with the \"manual\" inet METHOD"
119
47
                exit 1
120
48
        fi
121
 
        # mapping script must exist
122
49
        if [ -n "$IF_WPA_MAPPING_SCRIPT" ]; then
123
50
                if ! type "$IF_WPA_MAPPING_SCRIPT" >/dev/null; then
124
 
                        wpa_msg stderr "mapping script \"$IF_WPA_MAPPING_SCRIPT\" is not valid"
 
51
                        wpa_msg stderr "wpa-mapping-script \"$IF_WPA_MAPPING_SCRIPT\" is not valid"
125
52
                        exit 1
126
53
                fi
127
54
        fi
128
 
        # if an external mapping script is to be used, one must be given
129
 
        if [ -n "$IF_WPA_MAPPING_SCRIPT_PRIORITY" -a -z "$IF_WPA_MAPPING_SCRIPT" ]; then
130
 
                wpa_msg stderr "cannot set \"wpa-mapping-script-priority 1\" without a valid \"wpa-mapping-script\""
 
55
        if [ -n "$IF_WPA_MAPPING_SCRIPT_PRIORITY" ] && [ -z "$IF_WPA_MAPPING_SCRIPT" ]; then
 
56
                wpa_msg stderr "\"wpa-mapping-script-priority 1\" is invalid without a wpa-mapping-script"
131
57
                exit 1
132
58
        fi
133
 
        # shunt roam conf to IF_WPA_CONF
134
59
        IF_WPA_CONF="$IF_WPA_ROAM"
135
 
        # action script is wpa_action
136
60
        WPA_ACTION_SCRIPT="/sbin/wpa_action"
137
61
fi
138
62
 
139
63
# master function; determines if ifupdown.sh should do something or not
140
64
if [ -s "$IF_WPA_CONF" ]; then
141
 
        # get ctrl_interface socket path defined in conf
142
 
        WPA_SUP_CONF_CTRL_DIR=$(sed -n -e \
 
65
        WPA_SUP_CONF_CTRL_DIR=$(sed --quiet \
143
66
                's/[[:space:]]*#.*//g;s/[[:space:]]\+.*$//g;s/^\(ctrl_interface\|DIR\)=\(.*\)/\2/p' "$IF_WPA_CONF")
144
 
        # use ctrl_interface socket path when defined in user supplied conf, overriding the pre-set default
145
67
        if [ -n "$WPA_SUP_CONF_CTRL_DIR" ]; then
146
68
                WPA_CTRL_DIR="$WPA_SUP_CONF_CTRL_DIR"
147
69
        fi
148
 
        # always supply ctrl_interface socket path to daemon
149
 
        # it may not be created when not explicitly specified in IF_WPA_CONF but we depend on it
150
70
        WPA_SUP_CONF="-c $IF_WPA_CONF -C $WPA_CTRL_DIR"
151
 
elif set | grep -q "^IF_WPA"; then
152
 
        # any wpa-* line causes wpa_supplicant to launch with an unconfigured ctrl_interface socket
153
 
        # the socket is later configured by a series of set_network cmd's in conf_wpa_supplicant()
 
71
elif set | grep --quiet "^IF_WPA"; then
154
72
        WPA_SUP_CONF="-C $WPA_CTRL_DIR"
155
73
else
156
74
        exit 0
157
75
fi
158
76
 
159
 
# wpa_cli wrapper function
160
 
# avoid language related interferences
161
 
# supply path to common ctrl_interface socket(s)
162
 
# supply IFACE as argument
163
 
wpa_cli () {
164
 
        LC_ALL=C $WPA_CLI_BIN -p $WPA_CTRL_DIR -i $IFACE "$@"
165
 
}
166
 
 
167
 
# wpa_cli_do <value> <type> <variable> [set_network variable] <desc>
168
 
# process environment variables resulting from wpa-* lines in the interfaces file
169
 
# $1 = envorinment variable
170
 
# $2 = data type of variable {raw|ascii}
171
 
# $3 = wpa_cli variable, if $3 is set_network, shift and take set_network subvariable
172
 
# $4 = wpa-* string as it would appear in interfaces file, enhances information messages
173
 
wpa_cli_do () {
174
 
        
175
 
        if [ -z "$1" ]; then
176
 
                # environment variable not defined, no-op
177
 
                return
178
 
        fi
179
 
        
180
 
        local WPACLISET_VALUE WPACLISET_VARIABLE WPACLISET_DESC
181
 
        
182
 
        # provide a method to disable the forced choice of ascii data type
183
 
        # using this option requires that strings are quoted as required in interfaces file
184
 
        if [ -n "$IF_WPA_INPUT_TYPE" ]; then
185
 
                WPACLISET_VALUE="$1"
186
 
        else
187
 
                # wpa_cli value and type
188
 
                case "$2" in
189
 
                        ascii)
190
 
                                # Double quote
191
 
                                WPACLISET_VALUE="\"$1\""
192
 
                                ;;
193
 
                        raw|*)
194
 
                                # Provide raw value
195
 
                                WPACLISET_VALUE="$1"
196
 
                                ;;
197
 
                esac
198
 
        fi
199
 
        
200
 
        # wpa_cli variable
201
 
        case "$3" in
202
 
                set_network)
203
 
                        if [ -z "$WPA_ID" ]; then
204
 
                                # WPA_ID is required for set_network commands
205
 
                                return
206
 
                        fi
207
 
                        # Shift to set_network variable
208
 
                        shift
209
 
                        WPACLISET_VARIABLE="set_network $WPA_ID $3"
210
 
                        ;;
211
 
                *)
212
 
                        WPACLISET_VARIABLE="$3"
213
 
                        ;;
214
 
        esac
215
 
        
216
 
        # display description of wpa_cli command, censor sensitive knowledge
217
 
        case "$4" in
218
 
                *-psk|*-passphrase|*-passwd*|*-wep-key*)
219
 
                        # For sensitive knowledge
220
 
                        WPACLISET_DESC="$4 *****"
221
 
                        ;;
222
 
                *)
223
 
                        # Echo actual value used
224
 
                        WPACLISET_DESC="$4 $WPACLISET_VALUE"
225
 
                        ;;
226
 
        esac
227
 
 
228
 
        # echo debug/verbosity messages
229
 
        wpa_msg action "$WPACLISET_DESC"
230
 
        
231
 
        # NB: $WPACLISET_VARIABLE must be unprotected and $WPACLISET_VALUE must be protected
232
 
        wpa_cli $WPACLISET_VARIABLE "$WPACLISET_VALUE" >$TO_NULL
233
 
}
234
 
 
235
 
init_wpa_supplicant () {
236
 
        if [ ! -S "$WPA_CTRL_DIR/$IFACE" ]; then
237
 
                
238
 
                if [ -n "$IF_WPA_ACTION" ]; then
239
 
                        wpa_msg stderr "wpa-action support has been removed, see wpa_action(8) manpage"
240
 
                        return 1
241
 
                fi
242
 
                
243
 
                local WPA_SUP_DRIVER WPA_SUP_OPTIONS
244
 
 
245
 
                # action script sanity checking
246
 
                if [ -n "$WPA_ACTION_SCRIPT" ]; then
247
 
                        if [ -x "$WPA_ACTION_SCRIPT" ]; then
248
 
                                # wait for wpa_cli to attach
249
 
                                WPA_SUP_OPTIONS="-W -B -P $WPA_SUP_PIDFILE -i $IFACE"
250
 
                                wpa_msg verbose "wait for wpa_cli to attach"
251
 
                        else
252
 
                                wpa_msg stderr "action script \"$WPA_ACTION_SCRIPT\" not executable"
253
 
                                return 1
254
 
                        fi
255
 
                else
256
 
                        # default options, daemonise, create pidfile, supply IFACE
257
 
                        WPA_SUP_OPTIONS="-B -P $WPA_SUP_PIDFILE -i $IFACE"
258
 
                fi
259
 
 
260
 
                if [ -n "$IF_WPA_BRIDGE" ]; then
261
 
                        WPA_SUP_OPTIONS="$WPA_SUP_OPTIONS -b $IF_WPA_BRIDGE"
262
 
                        wpa_msg verbose "wpa-bridge $IF_WPA_BRIDGE"
263
 
                fi
264
 
 
265
 
                # driver type of interface, defaults to wext when undefined
266
 
                if [ -n "$IF_WPA_DRIVER" ]; then
267
 
                        WPA_SUP_DRIVER="$IF_WPA_DRIVER"
268
 
                        wpa_msg verbose "wpa-driver $WPA_SUP_DRIVER"
269
 
                else
270
 
                        # wext is default/fallback
271
 
                        WPA_SUP_DRIVER="wext"
272
 
                        wpa_msg verbose "using default driver type: wpa-driver $WPA_SUP_DRIVER"
273
 
                fi
274
 
 
275
 
                # if we have passed the criteria, start wpa_supplicant
276
 
                if [ -n "$WPA_SUP_CONF" ]; then
277
 
                        
278
 
                        wpa_msg verbose "$WPA_SUP_BIN $WPA_SUP_OPTIONS -D $WPA_SUP_DRIVER $WPA_SUP_CONF"
279
 
                        
280
 
                        start-stop-daemon --start --oknodo $DAEMON_VERBOSITY \
281
 
                                --name $WPA_SUP_PNAME --startas $WPA_SUP_BIN --pidfile $WPA_SUP_PIDFILE \
282
 
                                -- $WPA_SUP_OPTIONS -D $WPA_SUP_DRIVER $WPA_SUP_CONF
283
 
                fi
284
 
                
285
 
                # loop wait until ctrl_interface socket exists for a max of 5 seconds
286
 
                # in some situations, init_wpa_cli() or conf_wpa_supplicant() were being launched
287
 
                # before wpa_supplicant had established the ctrl_interface socket
288
 
                # i cannot say for certain if this is absolutely required, but it cannot hurt to have a buffer
289
 
                local WPA_SOCKET_WAIT="0" MAX_WPA_SOCKET_WAIT="5"
290
 
                until [ -S "$WPA_CTRL_DIR/$IFACE" ]; do
291
 
                        if [ "$WPA_SOCKET_WAIT" -ge "$MAX_WPA_SOCKET_WAIT" ]; then
292
 
                                # socket should be created immediately after invocation
293
 
                                # a few seconds is ample time even on ancient hardware
294
 
                                wpa_msg stderr "ctrl_interface socket not found at $WPA_CTRL_DIR/$IFACE"
295
 
                                return 1
296
 
                        else
297
 
                                wpa_msg verbose "waiting for \"$WPA_CTRL_DIR/$IFACE\": $WPA_SOCKET_WAIT (max. $MAX_WPA_SOCKET_WAIT)"
298
 
                                WPA_SOCKET_WAIT=$(($WPA_SOCKET_WAIT+1))
299
 
                                sleep 1
300
 
                        fi
301
 
                done
302
 
                
303
 
                wpa_msg verbose "ctrl_interface socket located at $WPA_CTRL_DIR/$IFACE"
304
 
                return 0                        
305
 
        else
306
 
                wpa_msg stderr "unknown or stale ctrl_interface socket located at $WPA_CTRL_DIR/$IFACE"
307
 
                return 1
308
 
        fi
309
 
}
310
 
 
311
 
conf_wpa_supplicant () {
312
 
        
313
 
        # global settings
314
 
        wpa_cli_do "$IF_WPA_AP_SCAN" raw \
315
 
                ap_scan wpa-ap-scan
316
 
        
317
 
        wpa_cli_do "$IF_WPA_PREAUTHENTICATE" raw \
318
 
                preauthenticate wpa-preauthenticate
319
 
                
320
 
        # per ssid specific settings
321
 
        if [ -n "$IF_WPA_SSID" ]; then
322
 
                
323
 
                # initialize a new network block, record the unique WPA_ID
324
 
                WPA_ID=$(wpa_cli add_network)
325
 
                
326
 
                wpa_msg verbose "configuring network block -- $WPA_ID"
327
 
                
328
 
                # set an ssid
329
 
                wpa_cli_do "$IF_WPA_SSID" ascii \
330
 
                        set_network ssid wpa-ssid
331
 
                
332
 
                # configure the new network block
333
 
                wpa_cli_do "$IF_WPA_PRIORITY" raw \
334
 
                        set_network priority wpa-priority
335
 
                
336
 
                wpa_cli_do "$IF_WPA_BSSID" raw \
337
 
                        set_network bssid wpa-bssid
338
 
                
339
 
                if [ -s "$IF_WPA_PSK_FILE" ]; then
340
 
                        IF_WPA_PSK=$(cat "$IF_WPA_PSK_FILE")
341
 
                fi
342
 
                wpa_cli_do "$IF_WPA_PSK" raw \
343
 
                        set_network psk wpa-psk
344
 
                
345
 
                if [ -s "$IF_WPA_PASSPHRASE_FILE" ]; then
346
 
                        IF_WPA_PASSPHRASE=$(cat "$IF_WPA_PASSPHRASE_FILE")
347
 
                fi
348
 
                wpa_cli_do "$IF_WPA_PASSPHRASE" ascii \
349
 
                        set_network psk wpa-passphrase
350
 
                
351
 
                wpa_cli_do "$IF_WPA_PAIRWISE" raw \
352
 
                        set_network pairwise wpa-pairwise
353
 
                
354
 
                wpa_cli_do "$IF_WPA_GROUP" raw \
355
 
                        set_network group wpa-group
356
 
                
357
 
                wpa_cli_do "$IF_WPA_KEY_MGMT" raw \
358
 
                        set_network key_mgmt wpa-key-mgmt
359
 
                
360
 
                wpa_cli_do "$IF_WPA_PROTO" raw \
361
 
                        set_network proto wpa-proto
362
 
                
363
 
                wpa_cli_do "$IF_WPA_AUTH_ALG" raw \
364
 
                        set_network auth_alg wpa-auth-alg
365
 
                
366
 
                wpa_cli_do "$IF_WPA_SCAN_SSID" raw \
367
 
                        set_network scan_ssid wpa-scan-ssid
368
 
                
369
 
                wpa_cli_do "$IF_WPA_IDENTITY" ascii \
370
 
                        set_network identity wpa-identity
371
 
                
372
 
                wpa_cli_do "$IF_WPA_ANONYMOUS_IDENTITY" ascii \
373
 
                        set_network anonymous_identity wpa-anonymous-identity
374
 
                
375
 
                wpa_cli_do "$IF_WPA_EAP" raw \
376
 
                        set_network eap wpa-eap
377
 
                
378
 
                wpa_cli_do "$IF_WPA_EAPPSK" raw \
379
 
                        set_network eappsk wpa-eappsk
380
 
 
381
 
                wpa_cli_do "$IF_WPA_NAI" ascii \
382
 
                        set_network nai wpa-nai
383
 
 
384
 
                wpa_cli_do "$IF_WPA_PASSWORD" ascii \
385
 
                        set_network password wpa-password
386
 
 
387
 
                wpa_cli_do "$IF_WPA_CA_CERT" ascii \
388
 
                        set_network ca_cert wpa-ca-cert
389
 
 
390
 
                wpa_cli_do "$IF_WPA_CA_PATH" ascii \
391
 
                        set_network ca_path wpa-ca-path
392
 
 
393
 
                wpa_cli_do "$IF_WPA_CLIENT_CERT" ascii \
394
 
                        set_network client_cert wpa-client-cert
395
 
 
396
 
                wpa_cli_do "$IF_WPA_PRIVATE_KEY" ascii \
397
 
                        set_network private_key wpa-private-key
398
 
 
399
 
                wpa_cli_do "$IF_WPA_PRIVATE_KEY_PASSWD" ascii \
400
 
                        set_network private_key_passwd wpa-private-key-passwd
401
 
                
402
 
                wpa_cli_do "$IF_WPA_DH_FILE" ascii \
403
 
                        set_network dh_file wpa-dh-file
404
 
 
405
 
                wpa_cli_do "$IF_WPA_SUBJECT_MATCH" ascii \
406
 
                        set_network subject_match wpa-subject-match
407
 
 
408
 
                wpa_cli_do "$IF_WPA_ALTSUBJECT_MATCH" ascii \
409
 
                        set_network altsubject_match wpa-altsubject-match
410
 
 
411
 
                wpa_cli_do "$IF_WPA_CA_CERT2" ascii \
412
 
                        set_network ca_cert2 wpa-ca-cert2
413
 
 
414
 
                wpa_cli_do "$IF_WPA_CA_PATH2" ascii \
415
 
                        set_network ca_path2 wpa-ca-path2
416
 
 
417
 
                wpa_cli_do "$IF_WPA_CLIENT_CERT2" ascii \
418
 
                        set_network client_cert2 wpa-client-cert2
419
 
 
420
 
                wpa_cli_do "$IF_WPA_PRIVATE_KEY2" ascii \
421
 
                        set_network private_key2 wpa-private-key2
422
 
 
423
 
                wpa_cli_do "$IF_WPA_PRIVATE_KEY_PASSWD2" ascii \
424
 
                        set_network private_key_passwd2 wpa-private-key-passwd2
425
 
                
426
 
                wpa_cli_do "$IF_WPA_DH_FILE2" ascii \
427
 
                        set_network dh_file2 wpa-dh-file2
428
 
 
429
 
                wpa_cli_do "$IF_WPA_SUBJECT_MATCH2" ascii \
430
 
                        set_network subject_match2 wpa-subject-match2
431
 
 
432
 
                wpa_cli_do "$IF_WPA_ALTSUBJECT_MATCH2" ascii \
433
 
                        set_network altsubject_match2 wpa-altsubject-match2
434
 
                
435
 
                wpa_cli_do "$IF_WPA_EAP_METHODS" raw \
436
 
                        set_network eap_methods wpa-eap-methods
437
 
 
438
 
                wpa_cli_do "$IF_WPA_PHASE1" ascii \
439
 
                        set_network phase1 wpa-phase1
440
 
 
441
 
                wpa_cli_do "$IF_WPA_PHASE2" ascii \
442
 
                        set_network phase2 wpa-phase2
443
 
 
444
 
                wpa_cli_do "$IF_WPA_PCSC" raw \
445
 
                        set_network pcsc wpa-pcsc
446
 
 
447
 
                wpa_cli_do "$IF_WPA_PIN" ascii \
448
 
                        set_network pin wpa-pin
449
 
 
450
 
                wpa_cli_do "$IF_WPA_ENGINE" raw \
451
 
                        set_network engine wpa-engine
452
 
 
453
 
                wpa_cli_do "$IF_WPA_ENGINE_ID" ascii \
454
 
                        set_network engine_id wpa-engine-id
455
 
 
456
 
                wpa_cli_do "$IF_WPA_KEY_ID" ascii \
457
 
                        set_network key_id wpa-key-id
458
 
 
459
 
                wpa_cli_do "$IF_WPA_EAPOL_FLAGS" raw \
460
 
                        set_network eapol_flags wpa-eapol-flags
461
 
                
462
 
                wpa_cli_do "$IF_WPA_WEP_KEY0" raw \
463
 
                        set_network wep_key0 wpa-wep-key0
464
 
                
465
 
                wpa_cli_do "$IF_WPA_WEP_KEY1" raw \
466
 
                        set_network wep_key1 wpa-wep-key1
467
 
                
468
 
                wpa_cli_do "$IF_WPA_WEP_KEY2" raw \
469
 
                        set_network wep_key2 wpa-wep-key2
470
 
                
471
 
                wpa_cli_do "$IF_WPA_WEP_KEY3" raw \
472
 
                        set_network wep_key3 wpa-wep-key3
473
 
                
474
 
                wpa_cli_do "$IF_WPA_WEP_TX_KEYIDX" raw \
475
 
                        set_network wep_tx_keyidx wpa-wep-tx-keyidx
476
 
                
477
 
                wpa_cli_do "$IF_WPA_PROACTIVE_KEY_CACHING" raw \
478
 
                        set_network proactive_key_caching wpa-proactive-key-caching
479
 
                        
480
 
                wpa_cli_do "$IF_WPA_PAC_FILE" ascii \
481
 
                        set_network pac_file wpa-pac-file
482
 
                
483
 
                wpa_cli_do "$IF_WPA_MODE" raw \
484
 
                        set_network mode wpa-mode
485
 
                
486
 
                wpa_cli_do "$IF_WPA_STAKEY" raw \
487
 
                        set_network stakey wpa-stakey
488
 
                
489
 
                wpa_cli_do "$IF_WPA_PEERKEY" raw \
490
 
                        set_network peerkey wpa-peerkey
491
 
                        
492
 
                wpa_cli_do "$IF_FRAGMENT_SIZE" raw \
493
 
                        set_network fragment_size wpa-fragment-size
494
 
 
495
 
                wpa_cli_do "$IF_WPA_ID_STR" ascii \
496
 
                        set_network id_str wpa-id-str
497
 
                
498
 
                # finality: activate the new network block
499
 
                wpa_cli_do "$WPA_ID" raw \
500
 
                        enable_network "enabling network block"
501
 
        fi
502
 
}
503
 
 
504
 
kill_wpa_supplicant () {
505
 
        if test_daemon_pidfile "$WPA_SUP_BIN" "$WPA_SUP_PIDFILE"; then
506
 
                
507
 
                wpa_msg verbose "terminating $WPA_SUP_PNAME daemon via pidfile $WPA_SUP_PIDFILE"
508
 
 
509
 
                start-stop-daemon --stop --oknodo $DAEMON_VERBOSITY \
510
 
                        --exec $WPA_SUP_BIN --pidfile $WPA_SUP_PIDFILE
511
 
        
512
 
                if [ -f "$WPA_SUP_PIDFILE" ]; then
513
 
                        rm -f "$WPA_SUP_PIDFILE"
514
 
                fi
515
 
        elif [ -S "$WPA_CTRL_DIR/$IFACE" ]; then
516
 
 
517
 
                # terminate existing ctrl_interface socket
518
 
                wpa_msg action "terminating via ctrl_interface socket $WPA_CTRL_DIR/$IFACE"
519
 
 
520
 
                wpa_cli terminate >$TO_NULL
521
 
                
522
 
                # remove stale socket
523
 
                if [ -S "$WPA_CTRL_DIR/$IFACE" ]; then
524
 
                        rm -f "$WPA_CTRL_DIR/$IFACE"
525
 
                fi
526
 
        fi
527
 
}
528
 
 
529
 
init_wpa_cli () {
530
 
        if [ -n "$WPA_ACTION_SCRIPT" ]; then
531
 
 
532
 
                # default wpa_cli daemon options
533
 
                # daemonise, create pidfile, supply IFACE
534
 
                WPA_CLI_OPTIONS="-B -P $WPA_CLI_PIDFILE -i $IFACE"
535
 
 
536
 
                # ensure the lockfile does not exist
537
 
                if [ -e "$WPA_CLI_LOCKFILE" ]; then
538
 
                        rm -f "$WPA_CLI_LOCKFILE"
539
 
                fi
540
 
                        
541
 
                wpa_msg verbose "$WPA_CLI_BIN $WPA_CLI_OPTIONS -p $WPA_CTRL_DIR -a $WPA_ACTION_SCRIPT"
542
 
                        
543
 
                start-stop-daemon --start --oknodo $DAEMON_VERBOSITY \
544
 
                        --name $WPA_CLI_PNAME --startas $WPA_CLI_BIN --pidfile $WPA_CLI_PIDFILE \
545
 
                        -- $WPA_CLI_OPTIONS -p $WPA_CTRL_DIR -a $WPA_ACTION_SCRIPT
546
 
        fi
547
 
}
548
 
 
549
 
kill_wpa_cli () {
550
 
        if test_daemon_pidfile "$WPA_CLI_BIN" "$WPA_CLI_PIDFILE"; then
551
 
                
552
 
                wpa_msg action "sending disconnect signal to $WPA_CLI_PNAME daemon"
553
 
                
554
 
                # send DISCONNECTED signal first
555
 
                # allow wpa_action the opportunity to undo network settings
556
 
                wpa_cli disconnect >$TO_NULL
557
 
 
558
 
                wpa_msg verbose "terminating $WPA_CLI_PNAME daemon via pidfile $WPA_CLI_PIDFILE"
559
 
                
560
 
                start-stop-daemon --stop --oknodo $DAEMON_VERBOSITY \
561
 
                        --exec $WPA_CLI_BIN --pidfile $WPA_CLI_PIDFILE
562
 
                
563
 
                if [ -f "$WPA_CLI_PIDFILE" ]; then
564
 
                        rm -f "$WPA_CLI_PIDFILE"
565
 
                fi
566
 
 
567
 
                if [ -f "$WPA_CLI_LOCKFILE" ]; then
568
 
                        rm -f "$WPA_CLI_LOCKFILE"
569
 
                fi
570
 
        fi
571
 
}
572
 
 
573
77
case "$MODE" in 
574
78
        start)
575
79
                case "$PHASE" in
576
80
                        pre-up)
577
81
                                kill_wpa_supplicant
578
 
                                if init_wpa_supplicant; then
579
 
                                        init_wpa_cli
580
 
                                        conf_wpa_supplicant
581
 
                                else
582
 
                                        exit 1
583
 
                                fi
 
82
                                init_wpa_supplicant     || exit 1
 
83
                                conf_wpa_supplicant     || { kill_wpa_supplicant; exit 1; }
584
84
                                ;;
585
 
                        *)
586
 
                                wpa_msg stderr "unknown phase: \"$PHASE\""
587
 
                                exit 1
 
85
                        post-up)
 
86
                                init_wpa_cli            || { kill_wpa_supplicant; exit 1; }
588
87
                                ;;
589
88
                esac
590
89
                ;;