1# 2# 3# Copyright (C) 2012 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17# 18# Script that turns on useful logging for wpa_supplicant 19 20 21WPA_LEVEL_LIST="excessive msgdump debug info warning error" 22 23usage(){ 24 echo " 25Usage: wpa_debug [level]|[--reset]|[--help][--list_valid_levels] 26 27 wpa_debug sets the debug level of wpa_supplicant. 28 Current debug level is displayed if no parameters are provided 29 30 level: The level is the level we want to set the debugging level to. The valid 31 levels can be viewed by using the --list_valid_levels flag 32 33 eg: wpa_debug msgdump 34 Sets the wpa_supplicant logging level to msgdump 35 36 --reset : Resets the level to 'info' 37 38 --help : Displays this output 39 40 --list_valid_levels: Displays the valid levels wpa_supplicant can be set to 41" 42} 43 44CMD_FLAG="<<cmd>>" 45 46WPA_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" 47 48# Returns whether or not $2 exists in $1 where $1 is a space 49# separated list of tags 50is_valid_tag(){ 51 expr " $1 " : ".* $2 .*"> /dev/null 52} 53 54get_wpa_logging(){ 55 set_cmd="`echo $WPA_CMD | sed "s/$CMD_FLAG/Get/"`" 56 $set_cmd | sed -e '/string/!d; s/[[:space:]]\+/ /g' | cut -d "\"" -f 2 57} 58 59set_wpa_logging(){ 60 if ! is_valid_tag "$WPA_LEVEL_LIST" "$1"; then 61 return 1 62 fi 63 64 if [ $1 = `get_wpa_logging` ]; then 65 return 1 66 fi 67 68 set_cmd="`echo $WPA_CMD | sed "s/$CMD_FLAG/Set/"` variant:string:$1" 69 $set_cmd 70} 71 72 73if [ $# -gt 0 ]; then 74 for param in "$@"; do 75 case $param in 76 --reset) 77 set_wpa_logging "info" 78 ;; 79 --list*) 80 echo "Valid levels are: `echo $WPA_LEVEL_LIST| sed 's/ /, /g'`" 81 exit 0 82 ;; 83 --help|--*) 84 usage 85 exit 0 86 ;; 87 *) 88 old_level="`get_wpa_logging`" 89 set_wpa_logging "$param" 90 echo "Old wpa level: $old_level" 91 ;; 92 esac 93 done 94fi 95 96echo "Current wpa level: `get_wpa_logging`" 97 98