From owner-svn-src-all@freebsd.org Thu Jun 16 21:14:27 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 50408A77A87; Thu, 16 Jun 2016 21:14:27 +0000 (UTC) (envelope-from dteske@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0EB6C16FA; Thu, 16 Jun 2016 21:14:26 +0000 (UTC) (envelope-from dteske@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5GLEQZL051171; Thu, 16 Jun 2016 21:14:26 GMT (envelope-from dteske@FreeBSD.org) Received: (from dteske@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5GLEPa6051162; Thu, 16 Jun 2016 21:14:25 GMT (envelope-from dteske@FreeBSD.org) Message-Id: <201606162114.u5GLEPa6051162@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dteske set sender to dteske@FreeBSD.org using -f From: Devin Teske Date: Thu, 16 Jun 2016 21:14:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r301973 - in head/usr.sbin/bsdconfig: include networking networking/include networking/share share/media X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jun 2016 21:14:27 -0000 Author: dteske Date: Thu Jun 16 21:14:25 2016 New Revision: 301973 URL: https://svnweb.freebsd.org/changeset/base/301973 Log: Add bsdconfig `wifi' (aka `wireless' or `wlan') module Approved by: re (gjb) MFC after: 8 weeks Relnotes: yes Added: head/usr.sbin/bsdconfig/networking/wlanconfig (contents, props changed) head/usr.sbin/bsdconfig/share/media/wlan.subr (contents, props changed) Modified: head/usr.sbin/bsdconfig/include/messages.subr head/usr.sbin/bsdconfig/networking/INDEX head/usr.sbin/bsdconfig/networking/Makefile head/usr.sbin/bsdconfig/networking/include/messages.subr head/usr.sbin/bsdconfig/networking/networking head/usr.sbin/bsdconfig/networking/share/device.subr head/usr.sbin/bsdconfig/share/media/Makefile Modified: head/usr.sbin/bsdconfig/include/messages.subr ============================================================================== --- head/usr.sbin/bsdconfig/include/messages.subr Thu Jun 16 20:04:33 2016 (r301972) +++ head/usr.sbin/bsdconfig/include/messages.subr Thu Jun 16 21:14:25 2016 (r301973) @@ -66,9 +66,11 @@ msg_canada="Canada" msg_cancel="Cancel" msg_cancel_exit="Cancel/Exit" msg_cannot_create_permission_denied="%s: cannot create %s: Permission denied" +msg_cannot_edit_wireless_ssid="Cannot edit wireless configuration; no matches for\nSSID \`%s' in wpa_supplicants.conf(5)" msg_cannot_resolve_hostname="Cannot resolve \`%s'! Are you sure that your\nname server, gateway and network interface are correctly configured?" msg_cant_find_distribution="Warning: Can't find the \`%s' distribution on this\nFTP server. You may need to visit a different server for\nthe release you are trying to fetch or go to the Options\nmenu and set the release name to explicitly match what's\navailable on %s (or set to \"any\").\n\nWould you like to select another FTP server?" msg_cant_seem_to_write_out_resolv_conf="Can't seem to write out %s. Net cannot be used." +msg_cant_start_wpa_supplicant="Can't start wpa_supplicant(8). Please create a wlan(4)\ninterface from the \`wlans' option after selecting your\nfavorite wireless adapter (i.e., %s)." msg_cd_dvd="CD/DVD" msg_cdrom="CDROM" msg_checking_access_to="Checking access to\n %s" @@ -85,6 +87,9 @@ msg_client_error="Client error, you coul msg_command_failed_rest_of_script_aborted="Command \`%s' failed - rest of script aborted." msg_comms_desc="Communications utilities." msg_configuration_for_interface="Configuration for Interface" +msg_configured="Configured" +msg_configured_lc="configured" +msg_configured_ssids="Configured SSIDs" msg_converters_desc="Format conversion utilities." msg_could_not_unmount_the_cdrom_dvd="Could not unmount the CDROM/DVD from %s: %s" msg_could_not_unmount_the_dos_partition="Could not unmount the DOS partition from %s: %s" @@ -94,12 +99,15 @@ msg_couldnt_connect_to_ftp_server="Could msg_couldnt_connect_to_proxy="Couldn't connect to proxy" msg_couldnt_connect_to_server="Couldn't connect to server" msg_couldnt_open_ftp_connection="Couldn't open FTP connection to %s:\n %s." +msg_create_new="Create New" msg_created_path="Created %s" msg_czech_republic="Czech Republic" msg_databases_desc="Database software." msg_debugging="Debugging" msg_denmark="Denmark" msg_deskutils_desc="Various Desktop utilities." +msg_destroy="Destroy" +msg_details="Details" msg_devel_desc="Software development utilities and libraries." msg_device_is_not_configured="The %s device is not configured. You will need to do so\nin the Networking configuration menu before proceeding." msg_dhcp="DHCP" @@ -107,6 +115,7 @@ msg_dialog_mixedform_navigation_help="Us msg_directory="Directory" msg_directory_not_found="%s: Directory not found." msg_directory_where_package_temporary_files_go="The directory where package temporary files should go" +msg_discovered_ssids="Discovered SSIDs" msg_dns_desc="Domain Name Service tools." msg_docs_desc="Meta-ports for FreeBSD documentation." msg_done="Done" @@ -129,10 +138,15 @@ msg_exit="Exit" msg_exit_bsdconfig="Exit bsdconfig" msg_extra_options_to_ifconfig="Extra options to ifconfig (usually empty):" msg_failed_to_add_default_route="Failed to add a default route; please check your network configuration" +msg_failed_to_reach_wpa_supplicant="Failed to reach wpa_supplicant: %s" msg_file_system="File System" msg_finance_desc="Monetary, financial and related applications." msg_finland="Finland" msg_floppy="Floppy" +msg_forget_all="Forget All" +msg_forget_all_confirm="WARNING! Are you really sure you want to forget all known networks\nby re-initializing wpa_supplicants.conf(5)? This cannot be undone." +msg_forget_all_help="Reset wpa_supplicant(8) configuration, forgetting all known networks" +msg_found="found" msg_france="France" msg_french_desc="Ported software for French countries." msg_ftp="FTP" @@ -202,12 +216,15 @@ msg_linux_desc="Linux programs that can msg_lisp_desc="Software related to the Lisp language." msg_lithuania="Lithuania" msg_loading_of_dependent_package_failed="Loading of dependent package %s failed" +msg_loading_wireless_menu="Loading Wireless Menu..." msg_logging_in_to_user_at_host="Logging in to %s@%s.." msg_looking_for_keymap_files="Looking for keymap files..." msg_looking_up_host="Looking up host %s" msg_mail_desc="Electronic mail packages and utilities." msg_main_menu="Main Menu" msg_main_site="Main Site" +msg_manually_connect="Manually Connect" +msg_manually_connect_help="Connect to a wireless network that may be unlisted" msg_math_desc="Mathematical computation software." msg_mbone_desc="Applications and utilities for the MBONE." msg_media_timeout="Media Timeout" @@ -271,6 +288,7 @@ msg_parallel_desc="Applications dealing msg_pear_desc="Software related to the Pear PHP framework." msg_perl5_desc="Utilities/modules for the PERL5 language." msg_permission_denied="%s: %s: Permission denied" +msg_pick_an_interface_to_destroy="Pick an interface to destroy" msg_pkg_delete_failed="Warning: pkg-delete(8) of %s failed.\n Run with debugging for details." msg_pkg_install_apparently_did_not_like_the_package="pkg-install(8) apparently did not like the %s package." msg_pkg_not_yet_installed_install_now="pkg(8) not yet installed. Install now?" @@ -319,9 +337,12 @@ msg_reinstall_desc="Mark this package fo msg_release_name="Release Name" msg_required_package_not_found="Warning: %s is a required package but was not found." msg_rerun_bsdconfig_initial_device_probe="Re-run bsdconfig initial device probe" +msg_rescan_wireless="Rescan Wireless" +msg_rescan_wireless_help="Scan for new wireless networks" msg_rescan_devices="Re-scan Devices" msg_reset="RESET!" msg_reset_all_values_to_startup_defaults="Reset all values to startup defaults" +msg_return_to_previous_menu="Return to previous menu" msg_reuse_old_ftp_site_selection_values="Re-use old FTP site selection values?" msg_reuse_old_http_site_settings="Re-use old HTTP site settings?" msg_review="Review" @@ -334,6 +355,7 @@ msg_russia="Russia" msg_russian_desc="Ported software for the Russian market." msg_scanning_for_dhcp_servers="Scanning for DHCP servers..." msg_scanning_for_ra_servers="Scanning for RA servers..." +msg_scanning_wireless_pausing="Scanning Wireless... (pausing for %i seconds)" msg_scheme_desc="Software related to the Scheme language." msg_science_desc="Scientific software." msg_secure_mode_requires_root="Secure-mode requires root-access!" @@ -341,9 +363,18 @@ msg_secure_mode_requires_x11="Secure-mod msg_security_desc="System security software." msg_select="Select" msg_select_a_site_thats_close="Select a site that's close!" +msg_select_the_configuration_you_would_like="Select the configuration you would like to edit:\nAddional network information displayed in help line." +msg_select_wlan_interfaces_for="Select wlan interfaces for %s:" msg_selected="selected" msg_server_error_when_requesting_url="Server error when requesting %s, you could try an other server" msg_shells_desc="Various shells (tcsh, bash, etc)." +msg_show_all="Show All" +msg_show_all_help="Show wireless networks without an SSID and all BSSIDs" +msg_show_configured="Show Configured" +msg_show_configured_help="Show networks configured in wpa_supplicants.conf(5)" +msg_show_scan_results="Show Scan Results" +msg_show_scan_results_help="Show wpa_cli(8) scan results" +msg_skip="Skip" msg_slovak_republic="Slovak Republic" msg_slovenia="Slovenia" msg_sorry_invalid_url="Sorry, %s is an invalid URL!" @@ -378,6 +409,7 @@ msg_unable_to_initialize_media_type_for_ msg_unable_to_make_directory_mountpoint="Unable to make %s directory mountpoint for %s!" msg_unable_to_open="Unable to open %s" msg_unable_to_update_pkg_from_selected_media="Unable to update pkg(8) from selected media." +msg_unconfigured="Unconfigured" msg_uninstall="Uninstall" msg_uninstall_desc="Mark this package for deletion" msg_uninstalling_package_waiting_for_pkg_delete="Uninstalling %s package - waiting for pkg-delete(8)" @@ -397,11 +429,15 @@ msg_using_interface="Using interface %s" msg_using_usb_device="Using USB device: %s" msg_vietnamese_desc="Ported software for the Vietnamese market." msg_view_set_various_media_options="View/Set various media options" +msg_warning_no_wireless_devices="WARNING! No wireless devices found." msg_what_would_you_like_to_do_with="What would you like to do with %s?" msg_which_release_to_attempt_to_load="Which release to attempt to load from installation media" msg_which_text_editor_to_use="Which text editor to use during installation" +msg_wireless_networks_text="Select an unmarked ([ ]) entry to join that network.\nSelect a marked ([X]) entry to edit that configuration." msg_windowmaker_desc="Ports to support the WindowMaker window manager." +msg_wireless_network_configuration_for="Wireless network configuration for SSID \`%s'" msg_would_you_like_to_bring_interface_up="Would you like to bring the %s interface up right now?" +msg_wpa_cli_ping_failed="wpa_cli(8) ping failed" msg_www_desc="Web utilities (browsers, HTTP servers, etc)." msg_x11_clocks_desc="X Window System based clocks." msg_x11_desc="X Window System based utilities." Modified: head/usr.sbin/bsdconfig/networking/INDEX ============================================================================== --- head/usr.sbin/bsdconfig/networking/INDEX Thu Jun 16 20:04:33 2016 (r301972) +++ head/usr.sbin/bsdconfig/networking/INDEX Thu Jun 16 21:14:25 2016 (r301973) @@ -1,5 +1,5 @@ # Copyright (c) 2012 Ron McDowell -# Copyright (c) 2012 Devin Teske +# Copyright (c) 2012-2016 Devin Teske # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -50,6 +50,9 @@ menu_selection="defaultrouter|defaultrou menu_selection="hostname|hostname" menu_selection="nameservers|nameservers" menu_selection="netdev|devices" +menu_selection="wireless|wlanconfig" +menu_selection="wlan|wlanconfig" +menu_selection="wifi|wlanconfig" # # ------------ Items below this line do NOT need i18n translation ------------ Modified: head/usr.sbin/bsdconfig/networking/Makefile ============================================================================== --- head/usr.sbin/bsdconfig/networking/Makefile Thu Jun 16 20:04:33 2016 (r301972) +++ head/usr.sbin/bsdconfig/networking/Makefile Thu Jun 16 21:14:25 2016 (r301973) @@ -6,6 +6,7 @@ FILESDIR= ${LIBEXECDIR}/bsdconfig/120.ne FILES= INDEX USAGE SCRIPTSDIR= ${FILESDIR} -SCRIPTS= defaultrouter devices hostname nameservers networking +SCRIPTS= defaultrouter devices hostname nameservers networking \ + wlanconfig .include Modified: head/usr.sbin/bsdconfig/networking/include/messages.subr ============================================================================== --- head/usr.sbin/bsdconfig/networking/include/messages.subr Thu Jun 16 20:04:33 2016 (r301972) +++ head/usr.sbin/bsdconfig/networking/include/messages.subr Thu Jun 16 21:14:25 2016 (r301973) @@ -1,4 +1,4 @@ -# Copyright (c) 2012 Devin Teske +# Copyright (c) 2012-2016 Devin Teske # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -100,6 +100,8 @@ msg_scanning_for_dhcp="Scanning for DHCP msg_select_network_interface="Select a network interface to configure.\n\n* Interface is marked as \"active\"" msg_supported_media_options="Below is a list of supported media options for the %s interface. Please select the options that you would like to set for the %s network interface" msg_unknown_networking_menu_selection="Unknown networking menu selection" +msg_wireless_networks="Wireless Networks" +msg_wlans="wlans" xmsg_please_enter_fqhn="Please enter your fully qualified hostname (e.g. foo.bar.com).\n The domain portion of the hostname will be configured in resolv.conf(5)." xmsg_please_enter_nameserver_existing="Please enter the new IP address of the DNS nameserver\n(set to the NULL string to remove entry):" xmsg_supported_media_options="Below is a list of supported media options for the %s interface. Please\nselect the options that you would like to set for the %s network interface" Modified: head/usr.sbin/bsdconfig/networking/networking ============================================================================== --- head/usr.sbin/bsdconfig/networking/networking Thu Jun 16 20:04:33 2016 (r301972) +++ head/usr.sbin/bsdconfig/networking/networking Thu Jun 16 21:14:25 2016 (r301973) @@ -1,6 +1,6 @@ #!/bin/sh #- -# Copyright (c) 2006-2013 Devin Teske +# Copyright (c) 2006-2016 Devin Teske # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -53,8 +53,9 @@ dialog_menu_main() 'X' '$msg_exit' '1' '$msg_hostname_domain' '2' '$msg_network_interfaces' - '3' '$msg_default_router' - '4' '$msg_dns_nameservers' + '3' '$msg_wireless_networks' + '4' '$msg_default_router' + '5' '$msg_dns_nameservers' " # END-QUOTE local defaultitem= # Calculated below local hline="$hline_arrows_tab_enter" @@ -124,8 +125,9 @@ while :; do X) break ;; 1) command=hostname ;; # Hostname/Domain 2) command=devices ;; # Network Interfaces - 3) command=defaultrouter ;; # Default Router/Gateway - 4) command=nameservers ;; # DNS nameservers + 3) command=wlanconfig ;; # Wireless Networks + 4) command=defaultrouter ;; # Default Router/Gateway + 5) command=nameservers ;; # DNS nameservers esac if [ "$command" ]; then Modified: head/usr.sbin/bsdconfig/networking/share/device.subr ============================================================================== --- head/usr.sbin/bsdconfig/networking/share/device.subr Thu Jun 16 20:04:33 2016 (r301972) +++ head/usr.sbin/bsdconfig/networking/share/device.subr Thu Jun 16 21:14:25 2016 (r301973) @@ -1,6 +1,6 @@ if [ ! "$_NETWORKING_DEVICE_SUBR" ]; then _NETWORKING_DEVICE_SUBR=1 # -# Copyright (c) 2006-2015 Devin Teske +# Copyright (c) 2006-2016 Devin Teske # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -34,6 +34,7 @@ f_dprintf "%s: loading includes..." netw f_include $BSDCFG_SHARE/device.subr f_include $BSDCFG_SHARE/dialog.subr f_include $BSDCFG_SHARE/media/tcpip.subr +f_include $BSDCFG_SHARE/media/wlan.subr f_include $BSDCFG_SHARE/networking/common.subr f_include $BSDCFG_SHARE/networking/ipaddr.subr f_include $BSDCFG_SHARE/networking/media.subr @@ -194,15 +195,29 @@ f_dialog_menu_netdev_edit() # to ifconfig(8). # local defaultitem= + local wlans wlan_status while :; do local dhcp_status="$msg_disabled" [ "$dhcp" ] && dhcp_status="$msg_enabled" + if f_device_is_wireless "$interface"; then + wlans=$( f_sysrc_get "wlans_$interface" ) + wlan_status="$msg_unconfigured" + [ -e "$( f_sysrc_get wpa_supplicant_conf_file )" ] && + wlan_status="$msg_configured" + fi + # # Display configuration-edit menu # menu_list=" 'X $msg_save_exit' '$msg_return_to_previous_menu' + " # END-QUOTE + f_device_is_wireless "$interface" && menu_list="$menu_list + 'W $msg_wireless_networks' '$wlan_status' + '1 $msg_wlans' '$wlans' + " # END-QUOTE + menu_list="$menu_list '2 $msg_dhcp' '$dhcp_status' '3 $msg_ipaddr4' '$ipaddr' '4 $msg_netmask' '$netmask' @@ -251,6 +266,9 @@ f_dialog_menu_netdev_edit() # case "$tag" in X\ *) break ;; + W\ *) f_dialog_menu_wireless_edit ;; + 1\ *) f_dialog_menu_wlandev_edit \ + "$interface" "${wlans%%[$IFS]*}" ;; 2\ *) # # Proceed cautiously (confirm with the user) if/when NFS- # mounts are active. If the network on which these mounts Added: head/usr.sbin/bsdconfig/networking/wlanconfig ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.sbin/bsdconfig/networking/wlanconfig Thu Jun 16 21:14:25 2016 (r301973) @@ -0,0 +1,78 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# Copyright (c) 2013 Tom Rhodes +# Copyright (c) 2013-2016 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +# Prevent device.subr (included indirectly) from auto scanning on load +DEVICE_SELF_SCAN_ALL=NO + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/media/wlan.subr +f_include $BSDCFG_SHARE/mustberoot.subr + +BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking" +f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_wireless_networks" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Launch the wireless network menu +# +f_dialog_menu_wireless_edit + +################################################################################ +# END +################################################################################ Modified: head/usr.sbin/bsdconfig/share/media/Makefile ============================================================================== --- head/usr.sbin/bsdconfig/share/media/Makefile Thu Jun 16 20:04:33 2016 (r301972) +++ head/usr.sbin/bsdconfig/share/media/Makefile Thu Jun 16 21:14:25 2016 (r301973) @@ -3,6 +3,6 @@ FILESDIR= ${SHAREDIR}/bsdconfig/media FILES= any.subr cdrom.subr common.subr directory.subr dos.subr \ floppy.subr ftp.subr http.subr httpproxy.subr network.subr \ - nfs.subr options.subr tcpip.subr ufs.subr usb.subr + nfs.subr options.subr tcpip.subr ufs.subr usb.subr wlan.subr .include Added: head/usr.sbin/bsdconfig/share/media/wlan.subr ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.sbin/bsdconfig/share/media/wlan.subr Thu Jun 16 21:14:25 2016 (r301973) @@ -0,0 +1,1392 @@ +if [ ! "$_MEDIA_WLAN_SUBR" ]; then _MEDIA_WLAN_SUBR=1 +# +# Copyright (c) 2013-2016 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." media/wlan.subr +f_include $BSDCFG_SHARE/device.subr +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/strings.subr +f_include $BSDCFG_SHARE/sysrc.subr + +BSDCFG_LIBE="/usr/libexec/bsdconfig" +f_include_lang $BSDCFG_LIBE/include/messages.subr + +############################################################ GLOBALS + +NWIRELESS_CONFIGS=0 +NWSCAN_RESULTS=0 + +# +# Settings used while interacting with various dialog(1) menus +# +: ${DIALOG_MENU_WLAN_SCAN_DURATION:=5} +: ${DIALOG_MENU_WLAN_SHOW_ALL=} +: ${DIALOG_MENU_WLAN_SHOW_CONFIGURED=1} +: ${DIALOG_MENU_WLAN_SHOW_SCAN_RESULTS=1} + +# +# Structure to contain the wpa_supplicant.conf(5) default overrides +# +f_struct_define WPA_DEFAULTS \ + ap_scan \ + ctrl_interface \ + ctrl_interface_group \ + eapol_version \ + fast_reauth + +# +# Structure of wpa_supplicant.conf(5) network={ ... } entry +# +f_struct_define WPA_NETWORK \ + anonymous_identity \ + auth_alg \ + bssid \ + ca_cert \ + ca_cert2 \ + client_cert \ + client_cert2 \ + dh_file \ + dh_file2 \ + eap \ + eap_workaround \ + eapol_flags \ + eappsk \ + engine \ + engine_id \ + frequency \ + group \ + identity \ + key_id \ + key_mgmt \ + mixed_cell \ + mode \ + nai \ + pac_file \ + pairwise \ + password \ + pcsc \ + phase1 \ + phase2 \ + pin \ + priority \ + private_key \ + private_key2 \ + private_key2_passwd \ + private_key_passwd \ + proto \ + psk \ + scan_ssid \ + server_nai \ + ssid \ + subject_match \ + subject_match2 \ + wep_key0 \ + wep_key1 \ + wep_key2 \ + wep_key3 \ + wpa_ptk_rekey \ + wep_tx_keyidx + +# +# The following properties are ``Lists'' and as such should not be quoted. +# Everything else should be quoted. +# +WPA_NETWORK_LIST_PROPERTIES=" + auth_algo + eap + group + key_mgmt + pairwise + proto +" # END-QUOTE + +# +# Structure of wpa_cli(8) `scan_results' entry +# +f_struct_define WPA_SCAN_RESULT \ + bssid \ + flags \ + freq \ + siglev \ + ssid + +# +# Structure of a menu item in the wireless editor +# +f_struct_define WLAN_MENU_ITEM \ + letter \ + ssid \ + nconfigs \ + nfound \ + help + +############################################################ FUNCTIONS + +# f_wpa_supplicant_init $file +# +# Initialize $file with basic contents of new wpa_supplicant.conf(5). +# +f_wpa_supplicant_init() +{ + local funcname=f_wpa_supplicant_init + local conf_file="$1" tmpfile + + # Create a temporary file + f_eval_catch -k tmpfile $funcname mktemp 'mktemp -t "%s"' "$pgm" || + return $FAILURE + + # Make it unreadable by anyone but ourselves + f_eval_catch $funcname chmod \ + 'chmod 0600 "%s"' "$tmpfile" || return $FAILURE + + # Make it owned by root/wheel + f_eval_catch $funcname chown \ + 'chown 0:0 "%s"' "$tmpfile" || return $FAILURE + + # Populate it + cat <<-EOF >> "$tmpfile" + ctrl_interface=/var/run/wpa_supplicant + eapol_version=2 + ap_scan=1 + fast_reauth=1 + EOF + echo >> "$tmpfile" + + # Move it into place + f_eval_catch $funcname mv 'mv "%s" "%s"' "$tmpfile" "$conf_file" +} + +# f_wpa_supplicant_parse $file [struct_prefix [count_var]] +# +# Parse wpa_supplicant.conf(5) $file. Default overrides are stored in a struct +# (see struct.subr for additional details) named `{struct_prefix}defaults'. See +# WPA_DEFAULTS struct definition in the GLOBALS section above. +# +# In addition, for each one of the wireless networks we parse from $file, +# create a struct named `struct_prefixN' where `N' is a number starting from 1 +# and ending in $count_var (zero means no networks). See WPA_NETWORK struct +# definition in the GLOBALS section above. +# +# If a `blob-base64-*={ ... }' entry appears, a struct named +# `{struct_prefix}blob_base64_*' is created and the `data' property holds the +# base64 encoded binary data without whitespace. +# +# Custom `*={ ... }' definitions are also supported, but should be unique +# (unlike the `network' definition). A struct named `{struct_prefix}*' is +# created if at least one property is defined in the block. +# +f_wpa_supplicant_parse() +{ + local file="$1" struct_prefix="$2" count_var="$3" + + [ "$count_var" ] && setvar "$count_var" 0 + + [ "$file" ] || file=$( f_sysrc_get wpa_supplicant_conf_file ) + if [ ! -e "$file" ]; then + f_dprintf "%s: No such file or directory" "$file" + return $FAILURE + fi + + local list_properties + f_replaceall "$WPA_NETWORK_LIST_PROPERTIES" "$NL" "" list_properties + eval "$( awk \ + -v count_var="$count_var" \ + -v struct_prefix="$struct_prefix" \ + -v list_properties="$list_properties" ' + BEGIN { + if (!count_var && !struct_prefix) exit + blob = count = custom_struct = network = 0 + split(list_properties, lists, FS) + } + function set_value(struct, prop, value) + { + quoted = substr(value, 0, 1) == "\"" + for (l in lists) if (list = prop == lists[l]) break + # Remove data after whitespace if unquoted and not a list + if (!quoted && !list) sub("[[:space:]].*", "", value) + # Otherwise if quoted and not a list, remove the quotes + # NB: wep_keyN needs to retain quoting if/when present + else if (quoted && !list && prop !~ /^wep_key[[:digit:]]+/) { + sub("^\"", "", value) + sub("\".*", "", value) + } + gsub(/'\''/, "'\''\\'\'\''", value) # Sanitize the value + if (!created[struct]) { + print "debug= f_struct_free", struct + print "debug= f_struct_new WPA_NETWORK", struct + created[struct] = 1 + } + printf "debug= %s set %s '\'%s\''\n", struct, prop, value + } + { + if ($1 ~ /^network={/) { + empty = 1 # We do not increment count unless !empty + network = 1 + next + } else if (match($1, "^blob-base64-[[:alnum:]_./-]+={")) { + blob = 1 + blob_data = "" + struct = struct_prefix "blob_bas64_" + struct = struct substr($1, 13, RLENGTH - 14) + next + } else if (match($1, "^[[:alnum:]_./-]+={")) { + empty = 1 + custom_struct = 1 + struct = struct_prefix substr($1, 0, RLENGTH - 2) + gsub(/[^[:alnum:]_]/, "_", struct) + next + } else if ($1 ~ /^}/) { + if (blob) { + gsub("[[:space:]]", "", blob_data) + set_value(struct, "data", blob_data) + } + blob = custom_struct = network = 0 + next + } else if (!match($0, /^[[:space:]]*[[:alnum:]_]+=/)) + next + + if (blob) { + blob_data = blob_data $0 + next + } else if (network) { + if (empty) { count++; empty = 0 } + struct = struct_prefix count + } else if (!custom_struct) + struct = struct_prefix "defaults" + + if (!struct_prefix) next + + prop = substr($0, 0, RLENGTH - 1) + sub(/^[[:space:]]*/, "", prop) + value = substr($0, RSTART + RLENGTH) + + set_value(struct, prop, value) + } + END { if (count_var) print count_var "=" count }' "$file" )" +} + +# f_wpa_scan_results_parse [struct_prefix [count_var]] +# +# Parse the results of wpa_cli(8) `scan_results' into a series of structs (see +# struct.subr for additional details) named `struct_prefixN' where `N' is a +# number starting from 1 and ending in $count_var (zero means no results). See +# WPA_SCAN_RESULT struct definition in the GLOBALS section above. +# +f_wpa_scan_results_parse() +{ + local struct_prefix="$1" count_var="$2" + + [ "$count_var" ] && setvar "$count_var" 0 + + eval "$( wpa_cli scan_results 2> /dev/null | awk \ + -v count_var="$count_var" \ + -v struct_prefix="$struct_prefix" ' + BEGIN { + if (!count_var && !struct_prefix) exit + count = 0 + seg = "[[:xdigit:]][[:xdigit:]]" + bssid = seg":"seg":"seg":"seg":"seg":"seg + freq = siglev = flags = "[^[:space:]]+" + S = "[[:space:]]+" + line = bssid S freq S siglev S flags + line = "^[[:space:]]*" line "[[:space:]]*" + } + function set_value(struct, prop, value) + { + gsub(/'\''/, "'\''\\'\'\''", value) # Sanitize the value + if (!created[struct]) { + print "debug= f_struct_free", struct + print "debug= f_struct_new WPA_SCAN_RESULT", struct + created[struct] = 1 + } + printf "debug= %s set %s '\'%s\''\n", struct, prop, value + } + { + if (!match($0, line)) next + ssid = substr($0, RLENGTH + 1) + + count++ + if (!struct_prefix) next + + struct = struct_prefix count + set_value(struct, "ssid", ssid) + set_value(struct, "bssid", $1) + set_value(struct, "freq", $2) + set_value(struct, "siglev", $3) + set_value(struct, "flags", $4) + } + END { if (count_var) print count_var "=" count }' )" +} + +# f_wpa_scan_match_network WPA_SCAN_RESULT WPA_NETWORK +# +# Compares a WPA_SCAN_RESULT struct to a WPA_NETWORK struct. If they appear to +# be a match returns success, otherwise failure. +# +f_wpa_scan_match_network() +{ + local scan_struct="$1" wireless_struct="$2" + local cp debug= + + f_struct "$scan_struct" || return $FAILURE + f_struct "$wireless_struct" || return $FAILURE + + local scan_ssid scan_bssid + $scan_struct get ssid scan_ssid + $scan_struct get bssid scan_bssid + local wireless_ssid wireless_bssid + $wireless_struct get ssid wireless_ssid + $wireless_struct get bssid wireless_bssid + + local id_matched= + if [ "$wireless_ssid" -a "$wireless_bssid" ]; then + # Must match both SSID and BSSID + [ "$scan_ssid" = "$wireless_ssid" -a \ + "$scan_bssid" = "$wireless_bssid" ] && id_matched=1 + elif [ "$wireless_ssid" ]; then + # Must match SSID only + [ "$scan_ssid" = "$wireless_ssid" ] && id_matched=1 + elif [ "$wireless_bssid" ]; then + # Must match BSSID only + [ "$scan_bssid" = "$wireless_bssid" ] && id_matched=1 + fi + [ "$id_matched" ] || return $FAILURE + + + # + # Get the scanned flags for the next few comparisons + # + local flags + $scan_struct get flags flags + + # + # Compare configured key management against scanned network + # + if $wireless_struct get key_mgmt cp && [ "$cp" -a "$cp" != "NONE" ] + then + local mgmt mgmt_matched= + for mgmt in $cp; do + local mgmt2="$mgmt" + [ "$mgmt" != "${mgmt#WPA-}" ] && + mgmt2="WPA2${mgmt#WPA}" + case "$flags" in + "$mgmt"|"$mgmt"-*|*-"$mgmt"|*-"$mgmt"-*) + mgmt_matched=1 break ;; + "$mgmt2"|"$mgmt2"-*|*-"$mgmt2"|*-"$mgmt2"-*) + mgmt_matched=1 break ;; + esac + done + [ "$mgmt_matched" ] || return $FAILURE + fi + + local enc type flag + + # + # Compare configured encryption against scanned network + # + for enc in psk:PSK eap:EAP \ + wep_key0:WEP wep_key1:WEP wep_key2:WEP wep_key3:WEP + do + type=${enc%%:*} + flag=${enc#*:} + { debug= $wireless_struct get $type cp && [ "$cp" ]; } || + continue + # Configured network requires encryption + case "$flags" in "[$flag]"|*"-$flag-"*) + break # Success; stop after first match + esac + return $FAILURE + done + cp="" # sensitive info + + # + # Compare scanned network encryption against configuration + # NB: Scanned network flags indicates _one_ of PSK EAP or WEP + # NB: Otherwise, no encryption (so encryption won't match) + # + local enc_wanted= + for enc in -PSK-:psk -EAP-:eap; do + flag=${enc%%:*} + type=${enc#*:} + case "$flags" in *"$flag"*) + enc_wanted=1 + { debug= $wireless_struct get $type cp && + [ "$cp" ]; } || return $FAILURE + break # success + esac + done + case "$flags" in *"[WEP]"*) + enc_wanted=1 + local wep_found= + for type in wep_key0 wep_key1 wep_key2 wep_key3; do + debug= $wireless_struct get $type cp && [ "$cp" ] && + wep_found=1 break + done + [ "$wep_found" ] || return $FAILURE + esac + if [ ! "$enc_wanted" ]; then + # No match if the network specifies encryption + for type in psk eap wep_key0 wep_key1 wep_key2 wep_key3; do + debug= $wireless_struct get $type cp && [ "$cp" ] && + return $FAILURE + done + fi + cp="" # sensitive info + + return $SUCCESS +} + +# f_wpa_scan_find_matches scans_prefix $scans_count \ +# wireless_prefix $wireless_count +# +# For each struct from `{scans_prefix}1' up to `{scans_prefix}$scans_count' +# (see struct.subr for additional details) compare the wireless network info +# (defined as struct WPA_SCAN_RESULT) to that of each configured wireless +# stored in `{wireless_prefix}1' (defined as struct WPA_NETWORK) up to +# `{wireless_prefix}$wireless_count'. +# +# If a scanned network is deemed to be a match to a configured wireless +# network, a new `match' property is set on the WPA_NETWORK struct with a value +# of `{scans_prefix}N' (where N represents the scanned network that matched). +# At the same time, a new `matched' property is set on the WPA_SCAN_RESULT +# struct with a value of 1, indicating that this network has been matched to a +# stored [known] configuration and that it should not be displayed in menus. +# +# NB: If a matching entry is not correct, the user can optionally `Forget' the +# network and that will cause the WPA_SCAN_RESULT to no longer match anything, +# causing it to appear in the menus again. +# +# Return status should be ignored. +# +f_wpa_scan_find_matches() +{ + local scans_prefix="$1" scans_count="$2" + local wireless_prefix="$3" wireless_count="$4" + local matches + + [ "$scans_count" -a "$wireless_count" ] || return $SUCCESS + f_isinteger "$scans_count" || return $FAILURE + f_isinteger "$wireless_count" || return $FAILURE + + # + # Go through and eradicate any flags we set in a prior run, as things + # might have changed on us (either from the config side or scan side) + # + local w=1 + while [ $w -le $wireless_count ]; do + f_struct "$wireless_prefix$w" set matches "" + w=$(( $w + 1 )) + done + + # + # Find matches and set match data on structs + # + local s=1 + while [ $s -le $scans_count ]; do + f_struct "$scans_prefix$s" set matched "" + w=1 + while [ $w -le $wireless_count ]; do + if f_wpa_scan_match_network \ + "$scans_prefix$s" "$wireless_prefix$w" + then + f_struct "$scans_prefix$s" set matched 1 + debug= f_struct "$wireless_prefix$w" \ + get matches matches + matches="$matches${matches:+ }$scans_prefix$s" + f_struct "$wireless_prefix$w" \ + set matches "$matches" + break # to next scan result + fi + w=$(( $w + 1 )) + done + s=$(( $s + 1 )) + done +} + +# f_dialog_menu_wlandev_edit $wlandev [$defaultitem] +# +# Display a list of wireless network devices (wlan*) associated with +# $wlandev (e.g., `iwn0'). Allow the user to create and destroy wlan interfaces +# while selecting ones to be cloned at startup (by setting `wlans_$wlandev'). +# +f_dialog_menu_wlandev_edit() +{ + local funcname=f_dialog_menu_wlandev_edit + local wlandev="$1" defaultitem="$2" + local title="$DIALOG_TITLE" + local btitle="$DIALOG_BACKTITLE" + local prompt # Calculated below + local hline="$hline_arrows_tab_enter" + + [ "$wlandev" ] || return $FAILURE + + f_sprintf prompt "$msg_select_wlan_interfaces_for" "wlandev" + + # + # Initially mark wlan devices with a %parent of $wlandev + # + local dev devs if list_to_save= + f_device_find "" $DEVICE_TYPE_NETWORK devs + for dev in $devs; do + f_struct "$dev" get name if || continue + case "$if" in wlan[0-9]*) + parent=$( sysctl -n net.wlan.${if#wlan}.%parent \ + 2> /dev/null ) + if [ "$parent" = "$if" ]; then + local _wlanmark_$if="X" + list_to_save="$list_to_save $if" + fi + esac + done + list_to_save="${list_to_save# }" + + # + # Operate in a loop so we can create/destroy interfaces from here + # + while :; do + # + # Refresh list of wlan interfaces + # + local wlanlist= + f_device_rescan_network + f_device_find "" $DEVICE_TYPE_NETWORK devs + for dev in $devs; do + f_struct "$dev" get name if || continue + case "$if" in wlan[0-9]*) + wlanlist="$wlanlist $if" + esac + done + + # + # Build menu list of wlan devices + # + local menu_list=" + '> $msg_save_exit' '$msg_return_to_previous_menu' + '> $msg_create_new' 'wlan' + '> $msg_destroy' '...' + " # END-QUOTE + local parent X + for if in $wlanlist; do + f_getvar _wlanmark_$if-" " X + menu_list="$menu_list '[$X] $if' '%parent: $parent'" + [ "$defaultitem" = "$if" ] && defaultitem="[$X] $if" + done + + # + # Ask user to make a choice + # + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$title\" \"\$btitle\" \"\$prompt\" \"\$hline\" \ + $menu_list + local menu_choice + menu_choice=$( eval $DIALOG \ + --title \"\$title\" \ + --backtitle \"\$btitle\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_select\" \ *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***