aboutsummaryrefslogtreecommitdiffstats
path: root/wpa_supplicant/examples/wps-ap-cli
blob: cc2cff2ebc24f2d6d78639a6dd0c14e041e5bb22 (plain)
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
#!/bin/sh

CLI=wpa_cli

pbc()
{
	echo "Starting PBC mode"
	echo "Push button on the station within two minutes"
	if ! $CLI wps_pbc | grep -q OK; then
		echo "Failed to enable PBC mode"
	fi
}

enter_pin()
{
	echo "Enter a PIN from a station to be enrolled to the network."
	echo -n "Enrollee PIN: "
	read pin
	cpin=`$CLI wps_check_pin "$pin" | tail -1`
	if [ "$cpin" = "FAIL-CHECKSUM" ]; then
		echo "Checksum digit is not valid"
		echo -n "Do you want to use this PIN (y/n)? "
		read resp
		case "$resp" in
			y*)
				cpin=`echo "$pin" | sed "s/[^1234567890]//g"`
				;;
			*)
				return 1
				;;
		esac
	fi
	if [ "$cpin" = "FAIL" ]; then
		echo "Invalid PIN: $pin"
		return 1
	fi
	echo "Enabling Enrollee PIN: $cpin"
	$CLI wps_pin any "$cpin"
}

show_config()
{
	$CLI status wps
}

main_menu()
{
	echo "WPS AP"
	echo "------"
	echo "1: Push button (activate PBC)"
	echo "2: Enter Enrollee PIN"
	echo "3: Show current configuration"
	echo "0: Exit wps-ap-cli"

	echo -n "Command: "
	read cmd

	case "$cmd" in
		1)
			pbc
			;;
		2)
			enter_pin
			;;
		3)
			show_config
			;;
		0)
			exit 0
			;;
		*)
			echo "Unknown command: $cmd"
			;;
	esac

	echo
	main_menu
}


main_menu