wps 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/sh
  2. wps_catch_credentials() {
  3. local iface ifaces ifc ifname ssid encryption key radio radios
  4. local found=0
  5. . /usr/share/libubox/jshn.sh
  6. ubus -S -t 30 listen wps_credentials | while read creds; do
  7. json_init
  8. json_load "$creds"
  9. json_select wps_credentials || continue
  10. json_get_vars ifname ssid key encryption
  11. local ifcname="$ifname"
  12. json_init
  13. json_load "$(ubus -S call network.wireless status)"
  14. json_get_keys radios
  15. for radio in $radios; do
  16. json_select $radio
  17. json_select interfaces
  18. json_get_keys ifaces
  19. for ifc in $ifaces; do
  20. json_select $ifc
  21. json_get_vars ifname
  22. [ "$ifname" = "$ifcname" ] && {
  23. ubus -S call uci set "{\"config\":\"wireless\", \"type\":\"wifi-iface\", \
  24. \"match\": { \"device\": \"$radio\", \"encryption\": \"wps\" }, \
  25. \"values\": { \"encryption\": \"$encryption\", \
  26. \"ssid\": \"$ssid\", \
  27. \"key\": \"$key\" } }"
  28. ubus -S call uci commit '{"config": "wireless"}'
  29. ubus -S call uci apply
  30. }
  31. json_select ..
  32. done
  33. json_select ..
  34. json_select ..
  35. done
  36. done
  37. }
  38. # from mk6 reset script
  39. #########################
  40. if [ -f "/etc/pineapple/setupRequired" ]; then
  41. if [ -f /etc/pineapple/init ]; then
  42. exit
  43. fi
  44. if [ ! -f /tmp/button_setup ]; then
  45. if [ "$SEEN" -lt 2 ]; then
  46. logger "First Setup: Disable WiFi"
  47. wifi down
  48. ifconfig wlan0 down && ifconfig wlan0-1 down
  49. /sbin/led blue on
  50. else
  51. logger "First Setup: Keep WiFi On"
  52. fi
  53. touch /tmp/button_setup
  54. fi
  55. exit
  56. fi
  57. #########################
  58. if [ "$ACTION" = "pressed" -a "$BUTTON" = "wps" ]; then
  59. wps_done=0
  60. ubusobjs="$( ubus -S list hostapd.* )"
  61. for ubusobj in $ubusobjs; do
  62. ubus -S call $ubusobj wps_start && wps_done=1
  63. done
  64. [ $wps_done = 0 ] || return 0
  65. wps_done=0
  66. ubusobjs="$( ubus -S list wpa_supplicant.* )"
  67. for ubusobj in $ubusobjs; do
  68. ifname="$(echo $ubusobj | cut -d'.' -f2 )"
  69. multi_ap=""
  70. if [ -e "/var/run/wpa_supplicant-${ifname}.conf.is_multiap" ]; then
  71. ubus -S call $ubusobj wps_start '{ "multi_ap": true }' && wps_done=1
  72. else
  73. ubus -S call $ubusobj wps_start && wps_done=1
  74. fi
  75. done
  76. [ $wps_done = 0 ] || wps_catch_credentials &
  77. fi
  78. return 0