d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
a399b7655a1d835aa8606c2b29e4e777baac8635zf * Use is subject to license terms.
a399b7655a1d835aa8606c2b29e4e777baac8635zf * Copyright (c) 2004, Sam Leffler <sam@errno.com>
a399b7655a1d835aa8606c2b29e4e777baac8635zf * Sun elects to license this software under the BSD license.
a399b7655a1d835aa8606c2b29e4e777baac8635zf * See README for more details.
a399b7655a1d835aa8606c2b29e4e777baac8635zf#define WPA_STATUS(status) (status == DLADM_STATUS_OK? 0 : -1)
a399b7655a1d835aa8606c2b29e4e777baac8635zf * get_bssid - get the current BSSID
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * @linkid: linkid of the given interface
a399b7655a1d835aa8606c2b29e4e777baac8635zf * @bssid: buffer for BSSID (IEEE80211_ADDR_LEN = 6 bytes)
a399b7655a1d835aa8606c2b29e4e777baac8635zf * Returns: 0 on success, -1 on failure
a399b7655a1d835aa8606c2b29e4e777baac8635zf * Query kernel driver for the current BSSID and copy it to @bssid.
a399b7655a1d835aa8606c2b29e4e777baac8635zf * Setting @bssid to 00:00:00:00:00:00 is recommended if the STA is not
a399b7655a1d835aa8606c2b29e4e777baac8635zf * associated.
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskeywpa_driver_wifi_get_bssid(dladm_handle_t handle, datalink_id_t linkid,
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskey status = dladm_wlan_get_linkattr(handle, linkid, &attr);
a399b7655a1d835aa8606c2b29e4e777baac8635zf return (-1);
a399b7655a1d835aa8606c2b29e4e777baac8635zf return (-1);
a399b7655a1d835aa8606c2b29e4e777baac8635zf (void) memcpy(bssid, wl_attrp->wa_bssid.wb_bytes, DLADM_WLAN_BSSID_LEN);
a399b7655a1d835aa8606c2b29e4e777baac8635zf wpa_printf(MSG_DEBUG, "wpa_driver_wifi_get_bssid: " MACSTR,
a399b7655a1d835aa8606c2b29e4e777baac8635zf * get_ssid - get the current SSID
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * @linkid: linkid of the given interface
a399b7655a1d835aa8606c2b29e4e777baac8635zf * @ssid: buffer for SSID (at least 32 bytes)
a399b7655a1d835aa8606c2b29e4e777baac8635zf * Returns: length of the SSID on success, -1 on failure
a399b7655a1d835aa8606c2b29e4e777baac8635zf * Query kernel driver for the current SSID and copy it to @ssid.
a399b7655a1d835aa8606c2b29e4e777baac8635zf * Returning zero is recommended if the STA is not associated.
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskeywpa_driver_wifi_get_ssid(dladm_handle_t handle, datalink_id_t linkid,
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskey status = dladm_wlan_get_linkattr(handle, linkid, &attr);
a399b7655a1d835aa8606c2b29e4e777baac8635zf return (-1);
a399b7655a1d835aa8606c2b29e4e777baac8635zf return (-1);
a399b7655a1d835aa8606c2b29e4e777baac8635zf (void) memcpy(ssid, wl_attrp->wa_essid.we_bytes, MAX_ESSID_LENGTH);
a399b7655a1d835aa8606c2b29e4e777baac8635zf wpa_printf(MSG_DEBUG, "wpa_driver_wifi_get_ssid: ssid=%s len=%d",
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskeywpa_driver_wifi_set_wpa_ie(dladm_handle_t handle, datalink_id_t linkid,
a399b7655a1d835aa8606c2b29e4e777baac8635zf wpa_printf(MSG_DEBUG, "%s", "wpa_driver_wifi_set_wpa_ie");
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskey status = dladm_wlan_wpa_set_ie(handle, linkid, wpa_ie, wpa_ie_len);
a399b7655a1d835aa8606c2b29e4e777baac8635zf * set_wpa - enable/disable WPA support
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * @linkid: linkid of the given interface
a399b7655a1d835aa8606c2b29e4e777baac8635zf * @enabled: 1 = enable, 0 = disable
a399b7655a1d835aa8606c2b29e4e777baac8635zf * Returns: 0 on success, -1 on failure
a399b7655a1d835aa8606c2b29e4e777baac8635zf * Configure the kernel driver to enable/disable WPA support. This may
a399b7655a1d835aa8606c2b29e4e777baac8635zf * be empty function, if WPA support is always enabled. Common
a399b7655a1d835aa8606c2b29e4e777baac8635zf * configuration items are WPA IE (clearing it when WPA support is
a399b7655a1d835aa8606c2b29e4e777baac8635zf * disabled), Privacy flag for capability field, roaming mode (need to
a399b7655a1d835aa8606c2b29e4e777baac8635zf * allow wpa_supplicant to control roaming).
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskeywpa_driver_wifi_set_wpa(dladm_handle_t handle, datalink_id_t linkid,
a399b7655a1d835aa8606c2b29e4e777baac8635zf wpa_printf(MSG_DEBUG, "wpa_driver_wifi_set_wpa: enable=%d", enabled);
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskey if (!enabled && wpa_driver_wifi_set_wpa_ie(handle, linkid, NULL, 0) < 0)
a399b7655a1d835aa8606c2b29e4e777baac8635zf return (-1);
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskey status = dladm_wlan_wpa_set_wpa(handle, linkid, enabled);
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskeywpa_driver_wifi_del_key(dladm_handle_t handle, datalink_id_t linkid,
a399b7655a1d835aa8606c2b29e4e777baac8635zf wpa_printf(MSG_DEBUG, "%s: id=%d", "wpa_driver_wifi_del_key",
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskey status = dladm_wlan_wpa_del_key(handle, linkid, key_idx, &bss);
a399b7655a1d835aa8606c2b29e4e777baac8635zf * set_key - configure encryption key
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * @linkid: linkid of the given interface
a399b7655a1d835aa8606c2b29e4e777baac8635zf * @alg: encryption algorithm (%WPA_ALG_NONE, %WPA_ALG_WEP,
a399b7655a1d835aa8606c2b29e4e777baac8635zf * %WPA_ALG_TKIP, %WPA_ALG_CCMP); %WPA_ALG_NONE clears the key.
a399b7655a1d835aa8606c2b29e4e777baac8635zf * @addr: address of the peer STA or ff:ff:ff:ff:ff:ff for
a399b7655a1d835aa8606c2b29e4e777baac8635zf * @key_idx: key index (0..3), always 0 for unicast keys
a399b7655a1d835aa8606c2b29e4e777baac8635zf * @set_tx: configure this key as the default Tx key (only used when
a399b7655a1d835aa8606c2b29e4e777baac8635zf * driver does not support separate unicast/individual key
a399b7655a1d835aa8606c2b29e4e777baac8635zf * @seq: sequence number/packet number, @seq_len octets, the next
a399b7655a1d835aa8606c2b29e4e777baac8635zf * packet number to be used for in replay protection; configured
a399b7655a1d835aa8606c2b29e4e777baac8635zf * for Rx keys (in most cases, this is only used with broadcast
a399b7655a1d835aa8606c2b29e4e777baac8635zf * keys and set to zero for unicast keys)
a399b7655a1d835aa8606c2b29e4e777baac8635zf * @seq_len: length of the @seq, depends on the algorithm:
a399b7655a1d835aa8606c2b29e4e777baac8635zf * TKIP: 6 octets, CCMP: 6 octets
a399b7655a1d835aa8606c2b29e4e777baac8635zf * @key: key buffer; TKIP: 16-byte temporal key, 8-byte Tx Mic key,
a399b7655a1d835aa8606c2b29e4e777baac8635zf * 8-byte Rx Mic Key
a399b7655a1d835aa8606c2b29e4e777baac8635zf * @key_len: length of the key buffer in octets (WEP: 5 or 13,
a399b7655a1d835aa8606c2b29e4e777baac8635zf * TKIP: 32, CCMP: 16)
a399b7655a1d835aa8606c2b29e4e777baac8635zf * Returns: 0 on success, -1 on failure
a399b7655a1d835aa8606c2b29e4e777baac8635zf * Configure the given key for the kernel driver. If the driver
a399b7655a1d835aa8606c2b29e4e777baac8635zf * supports separate individual keys (4 default keys + 1 individual),
a399b7655a1d835aa8606c2b29e4e777baac8635zf * @addr can be used to determine whether the key is default or
a399b7655a1d835aa8606c2b29e4e777baac8635zf * individual. If only 4 keys are supported, the default key with key
a399b7655a1d835aa8606c2b29e4e777baac8635zf * index 0 is used as the individual key. STA must be configured to use
a399b7655a1d835aa8606c2b29e4e777baac8635zf * it as the default Tx key (@set_tx is set) and accept Rx for all the
a399b7655a1d835aa8606c2b29e4e777baac8635zf * key indexes. In most cases, WPA uses only key indexes 1 and 2 for
a399b7655a1d835aa8606c2b29e4e777baac8635zf * broadcast keys, so key index 0 is available for this kind of
a399b7655a1d835aa8606c2b29e4e777baac8635zf * configuration.
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskeywpa_driver_wifi_set_key(dladm_handle_t handle, datalink_id_t linkid,
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskey wpa_alg alg, unsigned char *addr, int key_idx, boolean_t set_tx,
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskey uint8_t *seq, uint32_t seq_len, uint8_t *key, uint32_t key_len)
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskey return (wpa_driver_wifi_del_key(handle, linkid, key_idx, addr));
a399b7655a1d835aa8606c2b29e4e777baac8635zf switch (alg) {
a399b7655a1d835aa8606c2b29e4e777baac8635zf return (-1);
a399b7655a1d835aa8606c2b29e4e777baac8635zf wpa_printf(MSG_DEBUG, "wpa_driver_wifi_set_key: alg=%s key_idx=%d"
a399b7655a1d835aa8606c2b29e4e777baac8635zf " set_tx=%d seq_len=%d seq=%d key_len=%d",
a399b7655a1d835aa8606c2b29e4e777baac8635zf return (-1);
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskey status = dladm_wlan_wpa_set_key(handle, linkid, cipher, &bss, set_tx,
a399b7655a1d835aa8606c2b29e4e777baac8635zf * disassociate - request driver to disassociate
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * @linkid: linkid of the given interface
a399b7655a1d835aa8606c2b29e4e777baac8635zf * @reason_code: 16-bit reason code to be sent in the disassociation
a399b7655a1d835aa8606c2b29e4e777baac8635zf * Return: 0 on success, -1 on failure
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskeywpa_driver_wifi_disassociate(dladm_handle_t handle, datalink_id_t linkid,
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskey status = dladm_wlan_wpa_set_mlme(handle, linkid,
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskey DLADM_WLAN_MLME_DISASSOC, reason_code, NULL);
a399b7655a1d835aa8606c2b29e4e777baac8635zf * associate - request driver to associate
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * @linkid: linkid of the given interface
a399b7655a1d835aa8606c2b29e4e777baac8635zf * @bssid: BSSID of the selected AP
a399b7655a1d835aa8606c2b29e4e777baac8635zf * @wpa_ie: WPA information element to be included in (Re)Association
a399b7655a1d835aa8606c2b29e4e777baac8635zf * Request (including information element id and length). Use of
a399b7655a1d835aa8606c2b29e4e777baac8635zf * this WPA IE is optional. If the driver generates the WPA IE, it
a399b7655a1d835aa8606c2b29e4e777baac8635zf * can use @pairwise_suite, @group_suite, and @key_mgmt_suite
a399b7655a1d835aa8606c2b29e4e777baac8635zf * to select proper algorithms. In this case, the driver has to
a399b7655a1d835aa8606c2b29e4e777baac8635zf * notify wpa_supplicant about the used WPA IE by generating an
a399b7655a1d835aa8606c2b29e4e777baac8635zf * event that the interface code will convert into EVENT_ASSOCINFO
a399b7655a1d835aa8606c2b29e4e777baac8635zf * data (see wpa_supplicant.h). When using WPA2/IEEE 802.11i,
a399b7655a1d835aa8606c2b29e4e777baac8635zf * @wpa_ie is used for RSN IE instead. The driver can determine
a399b7655a1d835aa8606c2b29e4e777baac8635zf * which version is used by looking at the first byte of the IE
a399b7655a1d835aa8606c2b29e4e777baac8635zf * (0xdd for WPA, 0x30 for WPA2/RSN).
a399b7655a1d835aa8606c2b29e4e777baac8635zf * @wpa_ie_len: length of the @wpa_ie
a399b7655a1d835aa8606c2b29e4e777baac8635zf * Return: 0 on success, -1 on failure
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskeywpa_driver_wifi_associate(dladm_handle_t handle, datalink_id_t linkid,
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskey const char *bssid, uint8_t *wpa_ie, uint32_t wpa_ie_len)
a399b7655a1d835aa8606c2b29e4e777baac8635zf * NB: Don't need to set the freq or cipher-related state as
a399b7655a1d835aa8606c2b29e4e777baac8635zf * this is implied by the bssid which is used to locate
a399b7655a1d835aa8606c2b29e4e777baac8635zf * the scanned node state which holds it.
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskey if (wpa_driver_wifi_set_wpa_ie(handle, linkid, wpa_ie, wpa_ie_len) < 0)
a399b7655a1d835aa8606c2b29e4e777baac8635zf return (-1);
a399b7655a1d835aa8606c2b29e4e777baac8635zf (void) memcpy(bss.wb_bytes, bssid, DLADM_WLAN_BSSID_LEN);
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskey status = dladm_wlan_wpa_set_mlme(handle, linkid, DLADM_WLAN_MLME_ASSOC,
a399b7655a1d835aa8606c2b29e4e777baac8635zf * scan - request the driver to initiate scan
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * @linkid: linkid of the given interface
a399b7655a1d835aa8606c2b29e4e777baac8635zf * Return: 0 on success, -1 on failure
a399b7655a1d835aa8606c2b29e4e777baac8635zf * Once the scan results are ready, the driver should report scan
a399b7655a1d835aa8606c2b29e4e777baac8635zf * results event for wpa_supplicant which will eventually request the
a399b7655a1d835aa8606c2b29e4e777baac8635zf * results with wpa_driver_get_scan_results().
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskeywpa_driver_wifi_scan(dladm_handle_t handle, datalink_id_t linkid)
a399b7655a1d835aa8606c2b29e4e777baac8635zf * We force the state to INIT before calling ieee80211_new_state
a399b7655a1d835aa8606c2b29e4e777baac8635zf * to get ieee80211_begin_scan called. We really want to scan w/o
a399b7655a1d835aa8606c2b29e4e777baac8635zf * altering the current state but that's not possible right now.
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskey (void) wpa_driver_wifi_disassociate(handle, linkid,
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskey status = dladm_wlan_scan(handle, linkid, NULL, NULL);
a399b7655a1d835aa8606c2b29e4e777baac8635zf wpa_printf(MSG_DEBUG, "%s: return", "wpa_driver_wifi_scan");
a399b7655a1d835aa8606c2b29e4e777baac8635zf * get_scan_results - fetch the latest scan results
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * @linkid: linkid of the given interface
a399b7655a1d835aa8606c2b29e4e777baac8635zf * @results: pointer to buffer for scan results
a399b7655a1d835aa8606c2b29e4e777baac8635zf * @max_size: maximum number of entries (buffer size)
a399b7655a1d835aa8606c2b29e4e777baac8635zf * Return: number of scan result entries used on success, -1 on failure
a399b7655a1d835aa8606c2b29e4e777baac8635zf * If scan results include more than @max_size BSSes, @max_size will be
a399b7655a1d835aa8606c2b29e4e777baac8635zf * returned and the remaining entries will not be included in the
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskeywpa_driver_wifi_get_scan_results(dladm_handle_t handle, datalink_id_t linkid,
4ac67f0276a8313b5cefec38af347b94b7bfb526Anurag S. Maskey if (dladm_wlan_wpa_get_sr(handle, linkid, results, max_size, &ret)
a399b7655a1d835aa8606c2b29e4e777baac8635zf return (-1);