You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.4 KiB

  1. #!/bin/sh
  2. [ -n "$INCLUDE_ONLY" ] || {
  3. . /lib/functions.sh
  4. . /lib/functions/network.sh
  5. . ../netifd-proto.sh
  6. init_proto "$@"
  7. }
  8. cfg_format() {
  9. echo "$1" | sed -r 's/^[[:blank:]]+//;/^[[:space:]]*$/d'
  10. }
  11. ieee8021xclient_exitcode_tostring() {
  12. local errorcode=$1
  13. [ -n "$errorcode" ] || errorcode=5
  14. case "$errorcode" in
  15. 0) echo "OK" ;;
  16. 1) echo "FATAL_ERROR" ;;
  17. 5) echo "USER_REQUEST" ;;
  18. *) echo "UNKNOWN_ERROR" ;;
  19. esac
  20. }
  21. _wpa_supplicant_common() {
  22. local ifname="$1"
  23. _config="/var/run/wpa_supplicant-$ifname.conf"
  24. _pid="/var/run/wpa_supplicant-$ifname.pid"
  25. }
  26. proto_ieee8021xclient_setup() {
  27. local cfg="$1"
  28. local ifname="$2"
  29. local eapol_version
  30. local identity anonymous_identity password
  31. local ca_cert client_cert private_key private_key_passwd dh_file subject_match
  32. local phase1 phase2 ca_cert2 client_cert2 private_key2 private_key_passwd2 dh_file2 subject_match2
  33. local eap_workaround
  34. json_get_vars eapol_version
  35. json_get_vars identity anonymous_identity password
  36. json_get_vars ca_cert client_cert private_key private_key_passwd dh_file subject_match
  37. json_get_vars phase1 phase2 ca_cert2 client_cert2 private_key2 private_key_passwd2 dh_file2 subject_match2
  38. json_get_vars eap_workaround
  39. # launch
  40. local _config _pid
  41. _wpa_supplicant_common "$ifname"
  42. cat > "${_config}" << EOF
  43. ${eapol_version:+eapol_version=${eapol_version}}
  44. network={
  45. ${identity:+identity=${identity}}
  46. ${anonymous_identity:+anonymous_identity=${anonymous_identity}}
  47. ${password:+password=${password}}
  48. ${ca_cert:+ca_cert=${ca_cert}}
  49. ${client_cert:+client_cert=${client_cert}}
  50. ${private_key:+private_key=${private_key}}
  51. ${private_key_passwd:+private_key_passwd=${private_key_passwd}}
  52. ${dh_file:+dh_file=${dh_file}}
  53. ${subject_match:+subject_match=${subject_match}}
  54. ${phase1:+phase1=${phase1}}
  55. ${phase2:+phase2=${phase2}}
  56. ${ca_cert2:+ca_cert2=${ca_cert2}}
  57. ${client_cert2:+client_cert2=${client_cert2}}
  58. ${private_key2:+private_key2=${private_key2}}
  59. ${private_key_passwd2:+private_key_passwd2=${private_key_passwd2}}
  60. ${dh_file2:+dh_file2=${dh_file2}}
  61. ${subject_match2:+subject_match2=${subject_match2}}
  62. ${eap_workaround:+eap_workaround=1}
  63. }
  64. EOF
  65. ubus wait_for wpa_supplicant
  66. ubus call wpa_supplicant config_add "{ \"driver\":\"wired\", \"iface\": \"$ifname\", \"config\": \"$_config\" }"
  67. }
  68. proto_ieee8021xclient_teardown() {
  69. local ifname="$1"
  70. local errorstring=$(ieee8021xclient_exitcode_tostring $ERROR)
  71. case "$ERROR" in
  72. 0)
  73. ;;
  74. 2)
  75. proto_notify_error "$ifname" "$errorstring"
  76. proto_block_restart "$ifname"
  77. ;;
  78. *)
  79. proto_notify_error "$ifname" "$errorstring"
  80. ;;
  81. esac
  82. ubus call wpa_supplicant config_remove "{\"iface\":\"$ifname\"}"
  83. }
  84. proto_ieee8021xclient_init_config() {
  85. proto_config_add_int eapol_version
  86. proto_config_add_string identity
  87. proto_config_add_string anonymous_identity
  88. proto_config_add_string password
  89. proto_config_add_string 'ca_cert:file'
  90. proto_config_add_string 'client_cert:file'
  91. proto_config_add_string 'private_key:file'
  92. proto_config_add_string private_key_passwd
  93. proto_config_add_string 'dh_file:file'
  94. proto_config_add_string subject_match
  95. proto_config_add_string phase1
  96. proto_config_add_string phase2
  97. proto_config_add_string 'ca_cert2:file'
  98. proto_config_add_string 'client_cert2:file'
  99. proto_config_add_string 'private_key2:file'
  100. proto_config_add_string private_key_passwd2
  101. proto_config_add_string 'dh_file2:file'
  102. proto_config_add_string subject_match2
  103. proto_config_add_boolean eap_workaround
  104. }
  105. [ -n "$INCLUDE_ONLY" ] || add_protocol ieee8021xclient