wps-ap-cli 1.2 KB

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