Commit Graph

55 Commits

Author SHA1 Message Date
Denis Kenzior 7de5b4adef treewide: replace util_mem_is_zero with l_memeqzero 2021-03-09 15:40:35 -06:00
Denis Kenzior 0854592cc6 p2p: Do not leak 'str'
DeviceType setting is stored in 'str', but is never freed.  Fix that.
2021-02-08 16:02:42 -06:00
Denis Kenzior ccbd32503b scan: Pass the frequencies scanned to notify cb 2021-02-03 13:34:44 -06:00
James Prestwood b7e2a98628 ap: add error out param to ap_start
This allows the caller to extract a bit more information about what
exactly went wrong.
2020-10-26 14:30:34 -05:00
Andrew Zaborowski d5c7b47745 p2p: Respond to Probe Requests when in discovery
Since our DBus API and our use cases only support initiating connections
and not accepting incoming connections we don't really need to reply to
Probe Requests on the P2P-Device interface.  Start doing it firstly so
that we can test the scenario where we get discovered and pre-authorized
to connect in an autotest (wpa_supplicant doesn't seem to have a way to
authorize everyone, which is probably why most Wi-Fi Display dongles
don't do it and instead reply with "Fail: Information not available" and
then restart connection from their side) and secondly because the spec
wants us to do it.
2020-09-29 13:14:28 -05:00
Andrew Zaborowski ef902c5f7e p2p: Fix adding peers from Probe Request info
Make sure dev->peer_list is non-NULL before using l_queue_push_tail()
same as we do when the peer info comes from a Probe Response (active
scan in Find Phase).  Otherwise peers discovered through Probe Requests
before any Probe Responses are received will be lost.
2020-09-29 13:14:12 -05:00
Andrew Zaborowski 311e91b944 p2p: Free response frame payloads 2020-09-21 22:13:32 -05:00
Andrew Zaborowski c58b91dfd4 p2p: Free parsed frame data in p2p_go_negotiation_confirm_cb 2020-09-21 22:13:24 -05:00
Andrew Zaborowski 47596c67d3 p2p: Free peer->wfd in p2p_peer_free 2020-09-21 22:13:21 -05:00
Andrew Zaborowski ee4e1368d2 p2p: Try IP allocation during 4-Way handshake on client 2020-09-16 17:25:44 -05:00
Andrew Zaborowski 68cb9d38bf p2p: Start a basic P2P Group after GO Negotiation
Use the ap.c API to start an AP on a P2P_GO interface after we've been
selected as the GO in the GO Negotiation.
2020-09-16 17:25:44 -05:00
Andrew Zaborowski 4fa4cc5867 p2p: Add GO-side of GO Negotiation (responder)
Allow the possibility of becoming the Group-owner when we parse the GO
Negotiation Request, build GO Negotiation Response and parse the GO
Negotiation Confirmation, i.e. if we're responding to a negotiation
initiated by the peer after it needed to request user action.

Until now the code assumed we can't become the GO or we'd report error.
2020-09-14 11:39:25 -05:00
Andrew Zaborowski 52810ba445 p2p: Add GO-side of GO Negotiation (initiator)
Allow the possibility of becoming the Group-owner when we build the GO
Negotiation Request, parse GO Negotiation Response and build the GO
Negotiation Confirmation, i.e. if we're the initiator of the
negotiation.

Until now the code assumed we can't become the GO or we'd report error.
2020-09-14 11:39:25 -05:00
Andrew Zaborowski 0d2d34c353 p2p: Consistently use the conn_ prefix for variables
Prefix all the struct p2p_device members that are part of the connection
state with the "conn_" string for consistency.  If we needed to support
multiple client connections, these members are the ones that would
probably land in a separate structure, without that prefix.
2020-09-09 13:05:36 -05:00
Andrew Zaborowski d511b4b782 p2p: Free parsed frame data in p2p_go_negotiation_resp_cb 2020-09-09 13:05:07 -05:00
Andrew Zaborowski 6bba989913 p2p: Use WSC_RF_BAND_2_4_GHZ constant instead of 0x01 2020-09-09 13:05:01 -05:00
Andrew Zaborowski 0fc97d2674 p2p: Move p2p_device_discovery_stop calls to connect_failed
Move a few the calls to p2p_device_discovery_stop() done right after
p2p_connect_failed() directly to that function to reduce duplication.
2020-09-09 13:04:22 -05:00
Andrew Zaborowski 0fad5fef71 p2p: Do provisioning scan from the Interface Address
For WSC we should have been sending our probe requests from the same
address we're going to be doing EAP-WSC with the GO.  Somehow I was able
to connect to most devices without that but other implementations seem
to use the Interface Address (the P2P-Client's MAC), not the Device
Address (P2P-Device's MAC).  We could switch the order to first create
the new interface and scan from it is simpler to use the scan_context we
already have created on the device interface and set a different mac.
2020-09-09 13:04:18 -05:00
Andrew Zaborowski a4fa91a695 p2p: Build our Probe Response using connection data
When we're sending our probe response to the same peer that we're
currently connected or connecting to, use current WSC Configuration
Methods, UUID-E and WFD IE selected for this connection attempt, not the
ones we'd use when discovering peers or being discovered by peers.
In the case of the WFD IE, the "Available for WFD Session" flag is going
to differ between the two cases -- we may be unavailable for other peers
but we're still available for the peer we're trying to start the WFD
session with.
2020-08-25 16:52:41 -05:00
Andrew Zaborowski 619a5ed43b p2p: Fix the WSC Config Methods in GO Negotiation Response
When we send our GO Negotiation Response, send the Configuration Method
selected for the current connection rather than the accepted methods mask
that we hold in dev->device_info.
2020-08-25 16:52:29 -05:00
Andrew Zaborowski 19ab25f1d6 p2p: Send the right UUID-E in probe request WSC IEs
When building the scan IEs for our provisioning scans, use the UUID-E
based on the Interface Address, not the Device Address, as that is what
wsc.c will be using to in the registration protocol.

Eventually we may have to base the UUID-E on the Device Address or
something else that is persistent, and pass the actual UUID-E to wsc.c,
as the Interface Address is randomly generated on every connect attempt.
IIRC the UUID-E is supposed to be persistent.
2020-08-25 16:51:51 -05:00
Andrew Zaborowski 3910b9d9c3 p2p: Use a longer DHCP timeout
With some devices the 10 seconds are not enough for the P2P Group Owner
to give us an address but I think we still want to use a timeout as
short as possible so that the user doesn't wait too long if the
connection isn't working.
2020-07-31 10:38:59 -05:00
Andrew Zaborowski 2dea8bcc69 p2p: Set p2p_own_wfd->available by default
We need to set this flag true when the WFD service is first registered
as there's no WFD session and we're available for a new session.
2020-07-31 10:38:59 -05:00
Andrew Zaborowski c42de40a3b p2p: Add a null-check before use
p2p_connection_reset may be called as a result of a WFD service
unregistering and p2p_own_wfd is going to be NULL, don't update
p2p_own_wfd->available in this case.
2020-07-31 10:38:59 -05:00
Andrew Zaborowski 650e7715b1 p2p: Retry connect on "Previous authentication not valid"
With some WFD devices we occasionally get a Disconnect before or during
the DHCP setup on the first connection attempt to a newly formeg group,
with the reason code MMPDU_REASON_CODE_PREV_AUTH_NOT_VALID.  Retrying a
a few times makes the connections consistently successful.  Some
conditions are simplified/update in this patch because
conn_dhcp_timeout now implies conn_wsc_bss, and both imply
conn_retry_count.
2020-07-31 10:38:59 -05:00
Andrew Zaborowski 8faa0c1f0d frame-xchg: Re-add frame_xchg_stop
In 98cf2bf3ec frame_xchg_stop was removed
and its use in p2p.c was changed to frame_xchg_cancel with the slight
complication that the ID returned by frame_xchg_start had do be stored.
Re-add frame_xchg_stop, (renamed as frame_xchg_stop_wdev) to simplify
this bit in p2p.c.
2020-07-31 10:38:59 -05:00
Andrew Zaborowski 1f4b32ff53 p2p: Update call after frame-xchg changes 2020-07-21 08:59:24 -05:00
Andrew Zaborowski 07915485ed p2p: Add WFD IEs in GO Negotiation and association
This patch lets us establish WFD connections by parsing, validating and
acting on WFD IEs in received frames, and adding our own WFD IEs in the
GO Negotiation and Association frames.  Applications should assume that
any connection to a WFD-capable peer when we ourselves have a WFD
service registered, are WFD connections and should handle RTSP and
other IP-based protocols on those connections.

When connecting to a WFD-capable peer and when we have a WFD service
registered, the connection will fail if there are any conflicting or
invalid WFD parameters during GO Negotiation.
2020-07-16 10:48:43 -05:00
Andrew Zaborowski edf6b1b644 p2p: Add the p2p.Display interface on WFD-capable peers
If anyone's registered as implementing the WFD service, add the
net.connman.iwd.p2p.Display DBus interface on peer objects that are
WFD-capable and are available for a WFD Session.
2020-07-16 10:47:03 -05:00
Andrew Zaborowski 4cf5f5c4b6 p2p: Implement the p2p.ServiceManager interface
The net.connman.iwd.p2p.ServiceManager interface on the /net/connman/iwd
object lets user applications register/unregister the Wi-Fi Display
service.  In this commit all it does is it adds local WFD information
as given by the app, to the frames we send out during discovery.

Instead of accepting raw WFD IE contents from the app and exposing
peers' raw WFD IEs to the app, we build the WFD IEs in our code based on
the few meaningful DBus properties that we support and using default
values for the rest.  If an app ever needs any of the other WFD
capabilities more properties can be added.
2020-07-16 10:42:38 -05:00
Andrew Zaborowski 344fb528ab p2p: Add ConnectedInterface and ConnectedIP Peer properties
The are useful for P2P service implementations to know unambiguously
which network interface a new P2P connection is on and the peer's IPv4
address if they need to initiate an IP connection or validate an
incoming connection's address from the peer.
2020-07-13 14:53:38 -05:00
Andrew Zaborowski c8f4b9d98f p2p: Implement the Peer.Device property
Add the net.connman.iwd.p2p.Peer.Device property as listed in
doc/p2p-peer-api.txt
2020-07-13 14:12:44 -05:00
Andrew Zaborowski a09d7628dd p2p: Use nl80211_parse_attrs
Simplify p2p_device_update_from_genl by making use of nl80211_parse_attrs.
2020-07-13 14:11:07 -05:00
Andrew Zaborowski 09c9482045 p2p: Initialize dev->discovery_users in p2p_device_request_discovery
Make sure dev->discovery_users points at a queue before we try adding
user records to it.
2020-07-13 14:10:44 -05:00
Andrew Zaborowski 7d3092e1ca p2p: Update peer->device_addr when updating peer->bss
peer->device_addr is a pointer to the Device Address contained in
one of two possible places in peer->bss.  If during discovery we've
received a new beacon/probe response for an existing peer and we're
going to replace peer->bss, we also have to update peer->device_addr.
2020-07-13 14:09:42 -05:00
Andrew Zaborowski 122ea7a8aa p2p: Stop discovery after GO Negotiation Req error
If we were in discovery only to be able to receive the target peer's
GO Negotiation Request (i.e. we have no users requesting discovery)
and we've received the frame and decided that the connection has
failed, exit discovery.
2020-07-13 14:08:51 -05:00
James Prestwood 98cf2bf3ec frame-xchg: refactor to use wiphy work queue
In order to first integrate frame-xchg some refactoring needed to
be done. First it is useful to allow queueing frames up rather than
requiring the module (p2p, anqp etc) to wait for the last frame to
finish. This can be aided by radio management but frame-xchg needed
some refactoring as well.

First was getting rid of this fx pointer re-use. It looks like this
was done to save a bit of memory but things get pretty complex
needed to check if the pointer is stale or has been reset. Instead
of this we now just allocate a new pointer each frame-xchg. This
allows for the module to queue multiple requests as well as removes
the complexity of needed to check if the fx pointer is stale.

Next was adding the ability to track frame-xchgs by ID. If a module
can queue up multiple requests it also needs to be able to cancel
them individually vs per-wdev. This comes free with the wiphy work
queue since it returns an ID which can be given directly to the
caller.

Then radio management was simply piped in by adding the
insert/done APIs.
2020-07-09 09:58:16 -05:00
James Prestwood 05ad0120a8 frame-xchg: add destroy function to start() APIs
This makes things more consistent with other IWD APIs as well as
prepares for unifying frame-xchg and scanning.
2020-06-23 10:45:31 -05:00
Fabrice Fontaine 6bf5c3ddbd p2p: fix build with uclibc
explicit_bzero is used in src/p2p.c since commit
1675c765a3 but src/missing.h is not
included, as a result build with uclibc fails on:

/home/naourr/work/instance-0/output-1/per-package/iwd/host/opt/ext-toolchain/bin/../lib/gcc/mips64el-buildroot-linux-uclibc/5.5.0/../../../../mips64el-buildroot-linux-uclibc/bin/ld: src/p2p.o: in function `p2p_connection_reset':
p2p.c:(.text+0x2cf4): undefined reference to `explicit_bzero'
/home/naourr/work/instance-0/output-1/per-package/iwd/host/opt/ext-toolchain/bin/../lib/gcc/mips64el-buildroot-linux-uclibc/5.5.0/../../../../mips64el-buildroot-linux-uclibc/bin/ld: p2p.c:(.text+0x2cfc): undefined reference to `explicit_bzero'
2020-06-22 10:27:19 -05:00
Andrew Zaborowski c49b724a2e p2p: Do DHCP as part of connection setup
Use netconfig.c functions to unconditionally run DHCP negotiation,
fail the connection setup if DHCP fails.  Only report connection success
after netconfig returns.
2020-05-01 11:38:43 -05:00
Andrew Zaborowski 7a38085bf8 p2p: WSC client provisioning and connection
Add the final two steps of the connection setup, and corresponding
disconnect logic:

* the WSC connection to the GO to do the client provisioning,
* the netdev_connect call to use the provisioned credentials for the
  final WPA2 connection.
2020-04-27 13:53:15 -05:00
Andrew Zaborowski 85f09d9318 p2p: Create the P2P-Client interface
Once we've found the provisioning BSS create the P2P-Client interface
that we're going to use for the actual provisioning and the final P2P
connection.
2020-04-27 13:51:08 -05:00
Andrew Zaborowski d77fdd087b p2p: Scan for the provision BSS
Add the next step after Provision Discovery or GO Negotiation that is
scanning for the WSC BSS that the GO has set up for client provisioning.
2020-04-27 13:49:35 -05:00
Andrew Zaborowski ce4b1e1fcb p2p: Add the Provision Discovery frame sequence
When connecting to an existing group, use the Provision Discovery
Request/Response frame exchange before calling
p2p_start_client_provision().
2020-04-27 13:49:03 -05:00
Andrew Zaborowski fdf2b8a94c p2p: Respond to Probe Reqs when waiting for GO negotiation
Some devices (a Wi-Fi Display dongle in my case) will send us Probe
Requests and wait for a response before they send us the GO
Negotiation Request that we're waiting for after the peer initially
replied with "Fail: Information Not Available" to our GO Negotiation
attempt.  Curiously this specific device I tested would even accept
a Probe Response with a mangled body such that the IE sequence couldn't
be parsed.
2020-04-27 13:47:42 -05:00
Andrew Zaborowski bb4a3e8f84 p2p: Handle the Information Not Available response code
Handle the scenario where the peer's P2P state machine doesn't know
whether a connection has been authorized by the user and needs some time
to ask the user or a higher software layer whether to accept a
connection.  In that case their GO Negotiation Response to our GO
Negotiation Request will have the status code "Fail: Information Not
Available" and we need to give the peer 120s to start a new GO
Negotiation with us.  In this patch we handle the GO Negotiation
responder side where we parse the Request frame, build and send the
Response and finally parse the Confirmation.  The existing code so far
only did the initiator side.
2020-04-27 13:44:40 -05:00
Andrew Zaborowski bff4147d52 p2p: Handle GO Negotiation Response, send Confirmation
Parse the GO Negotiation Response frame and if no errors found send the
GO Negotiation Confirmation.  If that gets ACKed wait for the GO to set
up the group.
2020-04-27 13:43:21 -05:00
Andrew Zaborowski 3ef8688df5 p2p: Build and send the GO Negotiation Request 2020-04-27 13:43:12 -05:00
Andrew Zaborowski 1675c765a3 p2p: Add the WSC interface on peer DBus objects
Add net.connman.iwd.SimpleConfiguration interfaces to peer objects on
DBus and handle method calls.  Building and transmitting the actual
action frames to start the connection sequence is done in the following
commits.
2020-04-24 22:18:52 -05:00
Andrew Zaborowski 3d4725870d p2p: Add the Listen State
Start a remain-on-channel cmd implementing the Listen State, after each
the Scan Phase implemented as an active scan.
2020-04-24 22:16:43 -05:00