Commit Graph

311 Commits

Author SHA1 Message Date
Denis Kenzior 15620721b0 wiphy: Store connected_network on netdev object
Instead of storing the network pointer for each BSS, store it on the
netdev object.  This saves space inside struct bss and makes longer term
refactoring simpler.
2015-04-30 16:21:56 -05:00
Denis Kenzior 67a895c95f wiphy: Simplify code that removes lost networks
The current code is quite complicated and can be made simpler by using
the newly introduced l_hashmap_foreach_remove function.
2015-04-30 16:21:56 -05:00
Denis Kenzior 4c11845198 wiphy: Fix memory leak
==4249== 231 (32 direct, 199 indirect) bytes in 1 blocks are definitely
lost in loss record 10 of 10
==4249==    at 0x4C2B970: malloc (vg_replace_malloc.c:296)
==4249==    by 0x40CF5D: l_malloc (util.c:62)
==4249==    by 0x40F4DA: l_settings_new (settings.c:82)
==4249==    by 0x40CE9E: storage_network_open (storage.c:180)
==4249==    by 0x40499E: network_connect_psk (wiphy.c:307)
==4249==    by 0x40499E: network_connect (wiphy.c:359)
==4249==    by 0x41D85E: _dbus_object_tree_dispatch (dbus-service.c:845)
==4249==    by 0x416A86: message_read_handler (dbus.c:297)
==4249==    by 0x4119F4: io_callback (io.c:120)
==4249==    by 0x411032: l_main_run (main.c:346)
==4249==    by 0x40253E: main (main.c:171)
2015-04-30 16:21:56 -05:00
Denis Kenzior 93aaf21459 wiphy: Add initial preference management
This patch saves off the PSK generated based on the passphrase provided
by the agent/user.  The PSK is saved only if the connection is
successful.

Subsequent connection attempts to the known AP use the PSK saved on the
filesystem (default /var/lib/iwd/<ssid>.psk).  If the connection fails,
the agent will again be asked for the passphrase on the next attempt.
2015-04-27 07:55:13 -05:00
Denis Kenzior a28f3fa3ec wiphy: Parse ciphers supported by the phy 2015-04-17 13:02:32 -05:00
Denis Kenzior 431cadb7aa wiphy: Optimize storage 2015-04-17 12:49:56 -05:00
Denis Kenzior c9f1090380 wiphy: If connection failed, reset the PSK
This allows us to retry the agent for the correct passphrase
2015-04-08 15:07:02 -05:00
Denis Kenzior 0b48ba3a4a wiphy: Use CMD_DISCONNECT, not CMD_DEAUTHENTICATE
CMD_DEAUTHENTICATE seems to carry only the management frame pdu
information.  CMD_DISCONNECT is carrying the information that is
actually needed by us:
> Event: Disconnect (0x30) len 28		1140.118545
    Wiphy: 0 (0x00000000)
    Interface Index: 3 (0x00000003)
    Reason Code: 2 (0x0002)
    Disconnect by AP: true
2015-04-08 15:04:22 -05:00
Denis Kenzior 313dcbb8ff wiphy: Rework Device.Disconnect() logic 2015-04-08 15:03:28 -05:00
Denis Kenzior 6921e239a4 wiphy: Only support UTF-8 SSIDs
We will ignore non-UTF8 based SSIDs.  Support for non-UTF8 SSIDs seems
to be of dubious value in the real world as the vast majority of
consumer devices would not even allow such SSIDs to be configured or
used.

There also seems to be no compelling argument to support such SSIDs, so
until that argument arrives, non-UTF8 SSIDs will be filtered out.  This
makes the D-Bus API and implementation much easier.
2015-04-08 13:38:41 -05:00
Denis Kenzior b2e1c36cbb wiphy: Stop eapol state machine if disconnecting 2015-03-29 22:50:34 -05:00
Denis Kenzior ecede21c1e wiphy: Handle handshake failures 2015-03-29 22:32:11 -05:00
Denis Kenzior 3a6c06e85b wiphy: De-auth if setting key transaction fails 2015-03-29 22:32:11 -05:00
Denis Kenzior 85a5d7ba98 wiphy: Keep track of new/set key command ids 2015-03-29 22:32:11 -05:00
Denis Kenzior b81e22f809 wiphy: Move reason codes to mpdu.h 2015-03-29 20:27:57 -05:00
Jukka Rissanen 7b945d948f wiphy: Set the linkmode and operstate of the link
We need to set the linkmode and operstate after successful
authentication.

Initial value for linkmode is 1 (user space controlled) and
IF_OPER_DORMANT for opermode. After successful authentication,
the operstate is set to IF_OPER_UP.

More specific details can be seen in kernel sources at
https://www.kernel.org/doc/Documentation/networking/operstates.txt
2015-03-27 13:14:31 -05:00
Jukka Rissanen 42622525d2 wiphy: Send NL80211_CMD_SET_STATION command to kernel
After we have authenticated successfully, send the Set Station
command to kernel so that AP gets authorized.
2015-03-27 13:12:47 -05:00
Denis Kenzior 86ea449cd1 wiphy: Make sure to set user_data
This is needed for TK/GTK installation
2015-03-25 23:28:45 -05:00
Denis Kenzior 0412360d77 wiphy: Install group key 2015-03-25 23:28:40 -05:00
Denis Kenzior 75bacbb896 wiphy: Install pairwise key 2015-03-25 23:28:18 -05:00
Denis Kenzior 842eb643eb wiphy: Return an error if agent request fails
If there is no agent registered, then the caller should not be hanging
without a response forever.
2015-03-20 15:42:50 -05:00
Denis Kenzior 709b94587e wiphy: Print an error if PMK generation fails 2015-03-20 15:22:44 -05:00
Denis Kenzior 2598a1efed wiphy: call eapol_init and eapol_exit 2015-03-20 12:30:24 -05:00
Denis Kenzior 4c351196a9 wiphy: Print errno if read fails 2015-03-20 12:30:11 -05:00
Denis Kenzior 25af920563 wiphy: Separate out the ell include
To make it clear it is not a system include
2015-03-20 12:29:50 -05:00
Marcel Holtmann 2c061e6394 wiphy: Fix compiler warning with sizeof function
CC       src/wiphy.o
src/wiphy.c: In function ‘eapol_read’:
src/wiphy.c:172:24: error: argument to ‘sizeof’ in ‘memset’ call is the same expression as the destination; did you mean to remove the addressof? [-Werror=sizeof-pointer-memaccess]
  memset(&sll, 0, sizeof(&sll));
                        ^
2015-03-20 06:43:54 +01:00
Denis Kenzior 96cd2391da wiphy: Start 4-way handshake 2015-03-20 00:27:38 -05:00
Denis Kenzior 2a41fe6dd2 eapol: Add read handler for PAE frames 2015-03-20 00:27:38 -05:00
Denis Kenzior 7835eb8b88 wiphy: Fix style 2015-03-19 23:57:37 -05:00
Jukka Rissanen 24e79280a9 wiphy: DBus reply was sent too early when connecting PSK network
We can give reply to connect DBus call in associating event only
when we are connecting to Open network. For PSK AP, the reply can
only be sent after we have finished 4-way handshaking.
2015-03-19 23:57:37 -05:00
Ravi kumar Veeramally 02b501b4f0 core: Find WPA BSS from scan results
Parse vendor specific IE and BSS scan results, find it AP has
WPA security details.
2015-03-16 12:15:23 -05:00
Jukka Rissanen 56c4dc1a8c wiphy: Add enumeration of reason codes
When disconnecting, use a properly documented reason code.  These codes
come from the ieee80211.h file which is part of the Linux Kernel.
2015-03-12 11:19:27 -05:00
Tomasz Bursztyka 279ed50441 wiphy: Don't parse attributes of scan reply
The success or not of a scan command is found from the message directly.
There's no need to look for any attribute from the scan netlink answer.
The message is an error message or not, and that tells if the scan has
been started or not.
2015-03-11 10:24:34 -05:00
Tomasz Bursztyka 9c1780c0a1 wiphy: Use dbus object path as network key in hash
Modifying a bit how networks are stored inside the hashtable:
1 - instead of the network id, the network's object path is used
2 - network holds the pointer of the object path
3 - the hashtable does not free the key (network_free() will)

This permits to optimize on:
1 - one memory allocation used for 2 distinct things
2 - remove the need to re-compute the object path (and the id) when it's
needed, it can use dircetly the one stored in the network structure.
2015-03-10 09:32:58 -05:00
Patrik Flykt 1637f3519a wiphy: Request passphrase when connecting
Request a passphrase via Agent if none is set at the time network is
being connected. When freeing a network, cancel any outstanding Agent
requests and free allocated memory.
2015-03-06 12:51:51 -06:00
Ravi kumar Veeramally e24b18accd wiphy: Handle failed netlink requests
l_genl_family_send only returns request id. If request
failed at low level, current implementation does not handle that.
In case of request failure clear pending dbus messages.
2015-03-03 09:43:48 -06:00
Tomasz Bursztyka ab07091f8c util: Move msg_append_attr into util part 2015-03-02 20:44:02 -06:00
Denis Kenzior 1d8b330261 wiphy: Use new l_genl send() APIs 2015-02-27 11:00:45 -06:00
Ravi kumar Veeramally 67cdc80753 wiphy: Open PAE socket when an interface is found
Open a PAE socket to retrieve eapol frames for 4-way handshake.
2015-02-26 10:55:01 -06:00
Tomasz Bursztyka 6b018ca6f7 wiphy: Reduce static allocation size
iwd_device_get_path() is not going to produce longer string than 12
bytes (/ + maximum of uint32_t expressed as a string + '\0').
2015-02-26 10:05:16 -06:00
Denis Kenzior b067c08cfe wiphy: Remove unneeded initialization 2015-02-26 10:03:51 -06:00
Denis Kenzior e69b21ccdf wiphy: Don't store rsne unless needed
Open networks do not contain a RSN element, so storing a 256 byte buffer
was too expensive.

This patch also has the side-effect of fixing detection of Open
Networks.  Prior to this, if the scan results did not contain an RSN IE,
the 'rsne' variable would be set to all zeros.  scan_get_ssid_security
would then be called, but instead of a NULL struct ie_rsn_info, a
non-null, but zerod out ie_rsn_info would be passed in.  This caused the
code to work, but for the wrong reasons.
2015-02-25 21:13:24 -06:00
Denis Kenzior 458ad2af77 wiphy: Set authentication parameters for WPA2 2015-02-25 20:56:46 -06:00
Ravi kumar Veeramally 19957f1162 wiphy: Remove extra white space 2015-02-25 11:34:42 -06:00
Ravi kumar Veeramally 46cdef5f7b wiphy: Fix deauthenticate event from AP
If AP issued deauthenticate event, netdev->connect_pending is null.
iwd crashes without this check.
2015-02-25 11:23:46 -06:00
Denis Kenzior 97a92a9d02 wiphy: Don't connect to networks we don't support 2015-02-24 23:19:27 -06:00
Denis Kenzior 975953dd89 wiphy: Store RSN IE inside struct bss 2015-02-24 23:11:48 -06:00
Denis Kenzior c9bab96237 wiphy: Store ssid in static buffer
Instead of mallocing the ssid buffer, use a static array.  This removes an
extra couple of malloc/free operations and should result in less memory
utilization on average.
2015-02-24 23:03:15 -06:00
Ravi kumar Veeramally 8f5ca9dc73 wiphy: Implement initial disconnect functionality
Adding initial network disconnection implementation. Sends
deauthentication and reply through dbus depends upon its response.
2015-02-20 09:47:50 -06:00
Ravi kumar Veeramally f63b8b2ec9 wiphy: Fix open network connection
Authenticate event on wiphy mlme notification does not provide
enough information on which network/bss authentication command
was sent. BSS and network information is required to send associate
command to AP. So cache bss pointer in netdev struct and retrieve
on wiphy mlme notifications.
2015-02-13 17:04:31 -06:00
Ravi kumar Veeramally b1af2b6fe5 wiphy: Handle scan pending properly in netdev_free
If the device scan call reply is pending still on netdev_free call,
reply operation aborted.
2015-02-13 17:01:35 -06:00
Denis Kenzior 26010b8459 wiphy: Optimize scanning data structures
Instead of storing multiple copies of the same BSS (one hanging off the
netdev object and one hanging off the network object), we instead store
the BSS list only on the netdev object.

The network object gets a pointer to the BSS structure on the netdev
list.  As a side effect, the BSS list is always sorted properly.
2015-01-28 21:23:17 -06:00
Denis Kenzior 6f3e4ef594 wiphy: Restructure lost_bss() function
- Remove unneeded nesting
- Rework logic slightly
2015-01-28 21:23:17 -06:00
Jukka Rissanen 4c5498d4cd wiphy: Remove those networks that do not have any BSS
If all the BSSs having same SSID and security have disappeared
from network, then the network can be removed also.
2015-01-28 21:23:16 -06:00
Denis Kenzior c283557215 wiphy: Remove unneeded brackets 2015-01-28 21:23:16 -06:00
Denis Kenzior 1894b75a18 wiphy: Remove unneeded nesting 2015-01-28 21:23:16 -06:00
Denis Kenzior 0303a095aa wiphy: Remove unneeded variable
Instead of always mallocing space for the ssid array, and then freeing
it in most circumstances, do the opposite.  Only allocate the array once
it is actually needed.  This has the side effect of removing an unneeded
variable and making the code simpler.
2015-01-28 21:23:16 -06:00
Denis Kenzior 9f042ff1b8 wiphy: Ignore BSSes with no SSID 2015-01-28 21:23:16 -06:00
Denis Kenzior b342f819f9 wiphy: Make const correct 2015-01-28 21:23:16 -06:00
Jukka Rissanen d27c947209 wiphy: expose network objects instead of BSSes
The idea here is that network object will contain a list of BSS
that have the same SSID and security setting. From user point of view,
we will connect to a certain SSID instead of connecting directly to
a BSS. We pick the best BSS automatically from the BSS list when
connecting to a SSID.
2015-01-28 21:23:16 -06:00
Jukka Rissanen 9e655106fa wiphy: MLME warning message text incorrect
MLME notify function prints error if wiphy or netdev is missing.
The error text in this case talks about scan notification instead
of more proper MLME notification.
2015-01-28 11:49:03 -06:00
Jukka Rissanen 275d067123 wiphy: Use l_memdup instead of l_malloc and memcpy
Converting l_malloc() and memcpy() function pairs to use new
l_memdup() function.
2015-01-16 10:54:54 -06:00
Jukka Rissanen 7ec9c468f5 wiphy: Express SSID as an array of chars
Handle SSIDs as if they would contain up to 32 octets of opaque data.
2015-01-16 10:54:28 -06:00
Jukka Rissanen cb78798857 scan: Refactor scan result fetching to scan.c
No functionality changes by this commit.
2015-01-12 23:09:31 -06:00
Jukka Rissanen f73708e1d7 scan: Refactor scheduled scan code to scan.c
Move the implementation details of triggering scheduled wifi scans
over netlink to scan.c from wiphy.c.  No functionality is affected
by this commit.
2015-01-12 23:09:31 -06:00
Jukka Rissanen 35d0c519d7 scan: Refactor scan start details to scan.c
Move the implementation details of triggering wifi scans over netlink
to scan.c from wiphy.c.  No functionality is changed by this commit.
2015-01-12 23:09:31 -06:00
Jukka Rissanen 08d31e3b1b wiphy: Fixes due to nl80211.h changes 2014-12-22 11:48:26 -06:00
Jukka Rissanen d0cb0aedc6 wiphy: Check return value when appending attributes
Make sure to print some errors if attributes cannot be appended
to a message. It is dangerous to ignore the return code from
l_genl_msg_append_attr() because the kernel might act weirdly
if some attribute is missing.
2014-11-12 08:10:58 -06:00
Jukka Rissanen fcda15c587 wiphy: Scheduled scan startup message was too short
The length needs to be at least 20 bytes so that the third
attribute fits in.
2014-11-12 08:09:25 -06:00
Denis Kenzior ad86c91b38 wiphy: Fix memory leak
Whenever we find an existing BSS, we should free the old object since it
is being removed from the old_bss_list via l_queue_remove_if
2014-11-07 22:44:30 -06:00
Denis Kenzior 9de7c92429 wiphy: Remove unneeded wiphy_set_ssid function 2014-11-07 22:44:27 -06:00
Jukka Rissanen 672be730c3 wiphy: Add scheduled scan support
Add rudimentary support for mac80211 scheduled scan feature.
This is done so that kernel support for task called "Bind
NL80211_CMD_START_SCHED_SCAN to netlink socket" from TODO
file can be tested. The current scan interval is set to 60
seconds which is probably too fast for the final version.
2014-11-07 20:42:11 -06:00
Denis Kenzior ca18b395e2 wiphy: Fix valgrind complaint
The network list must be destroyed before the BSS list as that is used
inside network_free
2014-11-05 08:29:33 -06:00
Denis Kenzior 84765ac4db wiphy: Add GetNetworks method 2014-11-03 15:37:08 -06:00
Denis Kenzior e7bd2276de wiphy: Make const correct 2014-11-03 15:36:52 -06:00
Denis Kenzior 2f852d2954 wiphy: Add missing signals to introspection 2014-11-03 15:24:34 -06:00
Denis Kenzior 8e3a17cf56 wiphy: Add rudimentary Connect method 2014-10-30 00:27:06 -05:00
Denis Kenzior e51cac7f74 wiphy: Fix uninitialized var warnings 2014-10-30 00:26:49 -05:00
Denis Kenzior 5b2e34b5b6 wiphy: add network_emit_removed 2014-10-30 00:09:29 -05:00
Denis Kenzior 0d59e91a2b wiphy: Add network_emit_added 2014-10-30 00:09:16 -05:00
Denis Kenzior 3a8eb753a3 wiphy: Expose rudimentary network information 2014-10-30 00:01:52 -05:00
Denis Kenzior 64e9ad91ed wiphy: Track bss as a network object in a hashmap 2014-10-29 23:20:43 -05:00
Denis Kenzior b484197470 wiphy: Keep track of seen BSS 2014-10-29 22:50:27 -05:00
Denis Kenzior 39fde81dba wiphy: Refactor get_scan 2014-10-28 11:15:26 -05:00
Denis Kenzior 6917824be9 wiphy: refactor parse_bss 2014-10-28 11:04:31 -05:00
Denis Kenzior 0a71163c3f wiphy: Add Scan() method 2014-10-28 09:43:36 -05:00
Denis Kenzior 051f49ea85 wiphy: Tweak netdev structure creation order
Because none of the attributes are assigned until after the DeviceAdded
signal is emitted, the signal appears with invalid properties.  For now,
move the netdev structure fill-out into the if statement.

If the netdev attributes can change, then these need to be handled
separately and appropriate signals to be sent.
2014-10-23 22:44:59 -05:00
Denis Kenzior 2d6babc3f8 wiphy: Expose iwd_device_get_path 2014-10-23 22:40:32 -05:00
Denis Kenzior 2d6a50bb27 wiphy: add __iwd_device_foreach 2014-10-23 21:47:38 -05:00
Denis Kenzior c13103974c wiphy: Expose Name property of netdevs 2014-10-23 20:29:36 -05:00
Denis Kenzior 9ba3cc408e wiphy: Add __iwd_device_append_properties 2014-10-23 16:53:36 -05:00
Denis Kenzior 28f33d210d wiphy: add skeleton for DeviceAdded signal 2014-10-23 15:11:17 -05:00
Denis Kenzior daa0b6768f wiphy: add DeviceRemoved signal implementation 2014-10-23 15:11:01 -05:00
Denis Kenzior 4a4d094d8e wiphy: Add device_get_path() utility 2014-10-23 15:09:52 -05:00
Denis Kenzior 852072e836 dbus: Move Device interface #define to dbus.h 2014-10-23 14:34:17 -05:00
Denis Kenzior f9363748f0 wiphy: Expose netdevs to DBus 2014-10-23 14:32:12 -05:00
Marcel Holtmann dfc059d757 core: Send MLME associate request when authenticated 2014-08-09 00:01:22 -07:00
Marcel Holtmann 966a58d67f core: Send MLME authenticate request when SSID is found 2014-08-08 23:45:15 -07:00
Marcel Holtmann 0aabd9744d core: Parse scan results and store BSS information when SSID matches 2014-08-08 23:23:56 -07:00
Marcel Holtmann 9c7c23ce90 core: Trigger initial passive scan when SSID is provided 2014-08-08 22:21:30 -07:00
Marcel Holtmann c13d50fab9 core: Add command line option to provide SSID 2014-08-08 22:19:47 -07:00
Marcel Holtmann 218e38aa87 core: Store feature flags of wiphy devices 2014-08-07 15:41:30 -07:00
Marcel Holtmann c9b3adbbcf core: Request current regulatory setting when starting up 2014-08-07 13:23:02 -07:00
Marcel Holtmann a17584e680 core: First command should be to read protocol features 2014-08-07 13:13:31 -07:00
Marcel Holtmann b7a421673c core: Add sanity check to sync RTNL link deletion with nl80211 2014-08-06 23:52:42 -07:00
Marcel Holtmann 46b9f4a0a8 core: Subscribe to all nl80211 multicast groups 2014-08-06 23:52:08 -07:00
Marcel Holtmann 442ba2412d core: Add network interface to beginning of list 2014-08-06 23:51:25 -07:00
Marcel Holtmann f400e9dd44 core: Request list of all network interfaces 2014-08-07 06:27:32 +02:00
Marcel Holtmann 32c415e4e8 core: Track wiphy devices and its network interfaces 2014-08-07 05:15:20 +02:00
Marcel Holtmann d04ecde554 core: Only enable netlink debugging when IWD_GENL_DEBUG is set 2014-08-07 01:06:51 +02:00
Marcel Holtmann 999ba12f31 core: Add skeleton for nl80211 setup 2014-07-29 21:25:01 +02:00