blob: a8e4f608a040661902807469950b9f0eeeb583f9 [file] [log] [blame]
Darin Petkov2a0614e2012-10-22 15:28:41 +02001#!/bin/bash
2#
3# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6#
7# Script that turns on useful logging for wpa_supplicant
8
9
10WPA_LEVEL_LIST="excessive msgdump debug info warning error"
11
12usage(){
13 echo "
14Usage: wpa_debug [level]|[--reset]|[--help][--list_valid_levels]
15
16 wpa_debug sets the debug level of wpa_supplicant.
17 Current debug level is displayed if no parameters are provided
18
19 level: The level is the level we want to set the debugging level to. The valid
20 levels can be viewed by using the --list_valid_levels flag
21
22 eg: wpa_debug msgdump
23 Sets the wpa_supplicant logging level to msgdump
24
25 --reset : Resets the level to 'info'
26
27 --help : Displays this output
28
29 --list_valid_levels: Displays the valid levels wpa_supplicant can be set to
30"
31}
32
33CMD_FLAG="<<cmd>>"
34
35WPA_CMD="dbus-send --system --dest=fi.w1.wpa_supplicant1 --print-reply /fi/w1/wpa_supplicant1 org.freedesktop.DBus.Properties.$CMD_FLAG string:fi.w1.wpa_supplicant1 string:DebugLevel"
36
37# Returns whether ot not $2 exists in $1 where $1 is a space
38# separated list of tags
39is_valid_tag(){
40 expr match " $1 " ".* $2 .*"> /dev/null
41}
42
43get_wpa_logging(){
44 set_cmd="`echo $WPA_CMD | sed "s/$CMD_FLAG/Get/"`"
45 $set_cmd | awk '/string/ { print substr($3, 2, length($3)-2); }'
46}
47
48set_wpa_logging(){
49 if ! is_valid_tag "$WPA_LEVEL_LIST" "$1"; then
50 return 1
51 fi
52
53 if [ $1 == `get_wpa_logging` ]; then
54 return 1
55 fi
56
57 set_cmd="`echo $WPA_CMD | sed "s/$CMD_FLAG/Set/"` variant:string:$1"
58 $set_cmd
59}
60
61
62if [ $# -gt 0 ]; then
63 for param in $@; do
64 case $param in
65 --reset)
66 set_wpa_logging "info"
67 ;;
68 --list*)
69 echo "Valid levels are: `echo $WPA_LEVEL_LIST| sed 's/ /, /g'`"
70 exit 0
71 ;;
72 --help|--*)
73 usage
74 exit 0
75 ;;
76 *)
77 old_level="`get_wpa_logging`"
78 set_wpa_logging "$param"
79 echo "Old wpa level: $old_level"
80 ;;
81 esac
82 done
83fi
84
85echo "Current wpa level: `get_wpa_logging`"
86