data structures: add required mesh data fields

Modify and add necessary fields to hostapd and wpa_supplicant data
structures required by mesh networks wpa_supplicant module.

Signed-off-by: Javier Lopez <jlopex@gmail.com>
Signed-off-by: Jason Mobarak <x@jason.mobarak.name>
Signed-hostap: Thomas Pedersen <thomas@noack.us>
mesh: add mesh mode routines

Add routines to (de)initialize mesh interface data structures and
join and leave mesh networks.

Signed-off-by: Javier Lopez <jlopex@gmail.com>
Signed-off-by: Javier Cardona <javier@cozybit.com>
Signed-off-by: Jason Mobarak <x@jason.mobarak.name>
Signed-hostap: Thomas Pedersen <thomas@noack.us>
mesh_mpm: add mesh peering manager

The mesh peering manager establishes and maintains links among
mesh peers, tracking each peer link via a finite state machine.

This implementation supports open mesh peerings.

[assorted fixes from Yu Niiro <yu.niiro@gmail.com>]
Signed-off-by: Javier Lopez <jlopex@gmail.com>
Signed-off-by: Javier Cardona <javier@cozybit.com>
Signed-off-by: Ashok Nagarajan <ashok.dragon@gmail.com>
Signed-off-by: Jason Mobarak <x@jason.mobarak.name>
Signed-hostap: Bob Copeland <me@bobcopeland.com>
driver: add new NL80211 cmds to support mesh ifaces

- To support mesh mode, use u64 to fit all necessary driver flags.
- Create mesh_join and mesh_leave actions to kernel.
- Handle new_peer_candidate events from kernel.
- Register to receive necessary frames.
- Add plink_action_field and mesh_power_mode to hostapd_sta_add_params

Signed-off-by: Javier Lopez <jlopex@gmail.com>
Signed-off-by: Javier Cardona <javier@cozybit.com>
Signed-off-by: Jason Mobarak <x@jason.mobarak.name>
Signed-hostap: Bob Copeland <me@bobcopeland.com>

---

v2: - Split out the widing of the drv_flags / flags into separate patch.
    - Squash with "Clarify comment on TODO" https://github.com/cozybit/wpa_s_mesh_android/commit/95430203e0462eb1c275380b6fed172f5ce9daf1
    - Squash with "Add plink_action_field and mesh_power_mode to hostapd_sta_add_params" https://github.com/cozybit/wpa_s_mesh_android/commit/89d29f6a5c84a7b59ecfe1bb60c7271533bb6ea7
    - Squash with "Clarify comment (issue #10)" https://github.com/cozybit/wpa_s_mesh_android/commit/21734bc9b50190f06040ca26f0819cbb75c9c522
    - Squash with "closes #12" https://github.com/cozybit/wpa_s_mesh_android/commit/4d7209ed2d12a4eb1fbcafb26741f3b06f55149e
    - Squash with "Closes #16" https://github.com/cozybit/wpa_s_mesh_android/commit/fa05631616199fa48f61c7e58e44729e216d5d64
    - Squash with "No default mesh frequency. Closes #18" https://github.com/cozybit/wpa_s_mesh_android/commit/03f80b9c4ae3b9580d3759c3f564b257aa62022e
    - Squash with "Closes #19" https://github.com/cozybit/wpa_s_mesh_android/commit/3cf9b4c238037e6bba73048d6f221f8ea9b1f445
    - Squash with "Set mesh authentication protocol id in mesh config" https://github.com/cozybit/wpa_s_mesh_android/commit/caaf6ee68cc28cfde9400869440209b55c07a35f
    - Squash with "PLINK_CLOSE can have only MESHID and MPM IEs" https://github.com/cozybit/wpa_s_mesh_android/commit/6c4fd81f8cfa5f576fbaffae3654eb38bdf91016

v3: Remove workaround for NL80211_FEATURE_SK_TX_STATUS
v4: No changes
v5: Removed extraneous else for NL80211_FEATURE_SK_TX_STATUS change
v6: Updated email addresses, added signed-hostap for Bob
v7: remove blank lines
v8: add u64 driver flags
events: handle mesh events coming from driver

Handle EVENT_MGMT and EVENT_NEW_PEER_CANDIDATE for mesh interfaces.

Signed-off-by: Javier Lopez <jlopex@gmail.com>
Signed-hostap: Thomas Pedersen <thomas@noack.us>

---

v6: Updated email addresses, added signed-hostap
mesh: parse mesh-related information elements

Signed-hostap: Bob Copeland <me@bobcopeland.com>
config: add mesh mode, user_mpm, and no_auto_peer options

Modify network mode to support mode number 5 when CONFIG_MESH is
enabled.

Add user_mpm config parameter, when this is set to 1 (the default) the
peer link management is done on userspace, otherwise the peer management
will be done by the kernel.

Also add no_auto_peer parameter, which controls wheter a station will
automatically initiate peering to another mesh peer that comes into
range.

Signed-off-by: Javier Lopez <jlopex@gmail.com>
Signed-off-by: Jason Mobarak <x@jason.mobarak.name>
Signed-hostap: Thomas Pedersen <thomas@noack.us>

---
Still TODO: incorporate various fixes from Yu Niiro for
saving options
Makefile: add mesh support to wpa_s build

Signed-off-by: Javier Lopez <jlopex@gmail.com>
Signed-hostap: Thomas Pedersen <thomas@noack.us>

--
v8: squashed all makefile changes together, reordered, added android.mk
    bits
aes_siv: implement RFC 5297 AES-SIV

Add an implementation of Synthetic Initialization Vector (SIV)
Authenticated Encryption Using the Advanced Encryption Standard (AES).

This mode of AES is used to protect peering frames when using
the authenticated mesh peering exchange.

Signed-off-by: Javier Lopez <jlopex@gmail.com>
Signed-off-by: Jason Mobarak <x@jason.mobarak.name>
Signed-hostap: Bob Copeland <me@bobcopeland.com>
mesh_rsn: add mesh robust security network

This implementation provides:

- Mesh SAE authentication mechanism
- Key management (set/get PSK)
- Cryptographic key establishment
- Enhanced protection mechanisms for robust management frames

Signed-off-by: Javier Lopez <jlopex@gmail.com>
Signed-off-by: Javier Cardona <javier@cozybit.com>
Signed-off-by: Jason Mobarak <x@jason.mobarak.name>
Signed-hostap: Thomas Pedersen <thomas@noack.us>

---
v2: Squash with "Include user_mpm in global configuration dump" https://github.com/cozybit/wpa_s_mesh_android/commit/524391c7da144c2fb967c2719bfc60760df14b93
v4: Reordered to earlier in the patch series
v6: Updated email addresses, added signed-hostap
v7: remove blank lines before Signed-hostap
v8: split out unrelated stuff
auth: handle auth frames for mesh ifaces

Modify wpa_supplicant/hostapd logic to allow SAE auth on Mesh
interfaces.

Signed-off-by: Javier Lopez <jlopex@gmail.com>
Signed-off-by: Javier Cardona <javier@cozybit.com>
Signed-hostap: Thomas Pedersen <thomas@noack.us>
---
Still TODO: pick up Chun-Yeow Yeoh's changes
wpa_supplicant: implement mesh scanning

When mesh is configured in, include the wildcard
mesh id so that mesh networks are returned.  Tag any
returned mesh networks with [MESH].

Signed-off-by: Javier Lopez <jlopex@gmail.com>
Signed-hostap: Jason Abele <jason.abele@gmail.com>
wpa_s, ctrl_iface: Add mesh_group_{add,remove}

Parse MESH_GROUP_ADD/REMOVE commands on ctrl interface and call
wpa_supplicant routines.  These commands are used to start or
join a mesh network.

The mesh id is given in the configuration file, therefore there is
no need to scan before joining a mesh network.  We reuse the
connect_without_scan construct used by p2p for that same purpose.

Signed-off-by: Javier Cardona <javier@cozybit.com>
Signed-hostap: Javier Lopez <jlopex@gmail.com>
sample conf: add description for new mesh options

Modify sample wpa_supplicant.conf file to include user_mpm option
and new network mode (5), including open and secure mesh networking.

Signed-off-by: Javier Lopez <jlopex@gmail.com>
Signed-off-by: Jason Mobarak <x@jason.mobarak.name>
Signed-hostap: Thomas Pedersen <thomas@noack.us>

---
v5: Changed default, adjust the explanation for user_mpm=1 per Bob's
recommendation.
v6: Updated email address, added signed-hostap
v7: remove blank lines before Signed-hostap, fix description of
    variable default
hwsim_tests: add test_wpas_mesh test cases

This wpa_supplicant tests include basic tests for:

- Mesh scan
- Mesh group add/remove
- Mesh peer connected/disconnected
- Add/Set/Remove to test mesh mode network
- Open mesh connectivity test
- Secure mesh connectivity test
- no_auto_peer

Signed-off-by: Jason Mobarak <x@jason.mobarak.name>
[no_auto_peer test by: Javier Cardona <javier@cozybit.com>
Signed-hostap: Javier Lopez <jlopex@gmail.com>
wpa_s: enable mesh HT mode

Add a new option "mesh_ht_mode" that specifies the HT mode for the
mesh, with this option on, mesh beacons, actions frames, and probe
responses with include the appropriate HT information elements.

Change the mesh tests to check for the presence of HT in the scan
results, for this to work "disable_scan_offload" must be added to
p2p*.conf.

Signed-off-by: Ashok Nagarajan <ashok.dragon@gmail.com>
Signed-off-by: Javier Cardona <javier@cozybit.com>
[Original implementation by Chun-Yeow Yeoh <yeohchunyeow@gmail.com>]
Signed-hostap: Jason Mobarak <x@jason.mobarak.name>

---
v2: - Squash with "Turn on disable_scan_offload so that HT shows up in probe responses" https://github.com/cozybit/wpa_s_mesh_android/commit/eaf5cea5554cfb978bdf5c923effd36ba7ef4a87
    - Squash with "Check that mesh scan test still works with HT40+" https://github.com/cozybit/wpa_s_mesh_android/commit/660b373d28810809b226ef32210d49da8a7e657e
    - Squash with "Fix mesh scan test's failure condition detection" https://github.com/cozybit/wpa_s_mesh_android/commit/856b29ee4add6e5856c1de1b6a76fa8815cbf9db

v6: Updated email addresses, added signed-hostap

v7: remove blank lines before Signed-hostap
    reword commit messages, credit Chun-yeow
    put mesh stuff in CONFIG_MESH instead CONFIG_P2P
hostapd: check if mesh_conf struct is set

Modify hostapd.c logic to add checks for valid mconf data structure:

- For hostapd_setup_bss we don't need to flush old stations in case
  we're rejoining a mesh network.

- In hostapd_setup_interface_complete, we don't need to setup the
  interface until we join the mesh (same reasoning for
  hostapd_tx_queue_params).

Signed-off-by: Javier Lopez <jlopex@gmail.com>
Signed-off-by: Jason Mobarak <x@jason.mobarak.name>
Signed-hostap: Javier Lopez <jlopex@gmail.com>

---
v4: Reword commit per Thomas' suggestion, specify why we're checking
    mconf for null.
v6: Update email addresses, add signed-hostap.
v7: remove blank lines before Signed-hostap
NFU fix from javier on bssid
NFU Android.mk: add mesh support to wpa_s build

Signed-off-by: Javier Lopez <jlopex@gmail.com>
Signed-off-by: Jason Mobarak <x@jason.mobarak.name>
Signed-hostap: Thomas Pedersen <thomas@noack.us>

---
v5: - Fix the Android.mk files to actually build on Android.  Remove hunk
    that uncommented a debug config flag.

    - Split out the Android build fixes from the addition of mesh.

v6: Updated email adddresses, added signed-hostap

v7: remove blank lines before Signed-hostap
v8: split out the cozybit mesh version stuff
NFU hostapd, wpa_supplicant: fix android build

Signed-off-by: Javier Lopez <jlopex@gmail.com>
Signed-hostap: Jason Mobarak <x@jason.mobarak.name>

---
v5: Fix the Android.mk so it actually works
v6: Updated email addresses, added signed-hostap