xref: /freebsd/contrib/wpa/wpa_supplicant/examples/wps-ap-cli (revision 6be3386466ab79a84b48429ae66244f21526d3df)
1#!/bin/sh
2
3CLI=wpa_cli
4
5pbc()
6{
7	echo "Starting PBC mode"
8	echo "Push button on the station within two minutes"
9	if ! $CLI wps_pbc | grep -q OK; then
10		echo "Failed to enable PBC mode"
11	fi
12}
13
14enter_pin()
15{
16	echo "Enter a PIN from a station to be enrolled to the network."
17	printf "Enrollee PIN: "
18	read pin
19	cpin=`$CLI wps_check_pin "$pin" | tail -1`
20	if [ "$cpin" = "FAIL-CHECKSUM" ]; then
21		echo "Checksum digit is not valid"
22		printf "Do you want to use this PIN (y/n)? "
23		read resp
24		case "$resp" in
25			y*)
26				cpin=`echo "$pin" | sed "s/[^1234567890]//g"`
27				;;
28			*)
29				return 1
30				;;
31		esac
32	fi
33	if [ "$cpin" = "FAIL" ]; then
34		echo "Invalid PIN: $pin"
35		return 1
36	fi
37	echo "Enabling Enrollee PIN: $cpin"
38	$CLI wps_pin any "$cpin"
39}
40
41show_config()
42{
43	$CLI status wps
44}
45
46main_menu()
47{
48	echo "WPS AP"
49	echo "------"
50	echo "1: Push button (activate PBC)"
51	echo "2: Enter Enrollee PIN"
52	echo "3: Show current configuration"
53	echo "0: Exit wps-ap-cli"
54
55	printf "Command: "
56	read cmd
57
58	case "$cmd" in
59		1)
60			pbc
61			;;
62		2)
63			enter_pin
64			;;
65		3)
66			show_config
67			;;
68		0)
69			exit 0
70			;;
71		*)
72			echo "Unknown command: $cmd"
73			;;
74	esac
75
76	echo
77	main_menu
78}
79
80
81main_menu
82