Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers/atwinc15x0: support dynamic scanning and connection to AP #19387

Merged
merged 10 commits into from
Aug 21, 2023

Conversation

fabian18
Copy link
Contributor

Contribution description

We currently only support static Wi-Fi credentials using WIFI_SSID and WIFI_PASS.
This PR implements a way of dynamic scanning and connecting to Access Points using new netopts NETOPT_SCAN, NETOPT_CONNECT, and NETOPT_DISCONNECT.

  • The atwinc15x0 driver is adapted to support these options.
    • new pseudomodule atwinc15x0_static_connect can be activated to show the old behaviour
    • new pseudomodule atwinc15x0_dynamic_connect can be activated to support dynamic connection requests
    • new pseudomodule atwinc15x0_dynamic_scan can be activated to support dynamic scanning

You can enable whatever pseudomodules you want or even none.

  • A l2scan_listdata structure is added to deliver scan results in a list, sorted by their RSSI.

  • A new shell command iw is added as an interface to interact with Wi-Fi interfaces

Testing procedure

Test l2scan_list:

cd tests/l2scan_list
make
make term
RIOT native interrupts/signals initialized.
RIOT native board initialized.
RIOT native hardware initialization complete.

main(): This is RIOT! (Version: 2019.10-devel-19942-g71c2d-drivers_atwinc1510_scan_result)
...
OK (3 tests)

Test: gnrc_networking:

My wrapping Makefile:

Makefile_same54_xpro.mk
BOARD=same54-xpro

USEMODULE += shell_cmd_iw
USEMODULE += atwinc15x0
USEMODULE += atwinc15x0_static_connect
USEMODULE += atwinc15x0_dynamic_connect
USEMODULE += atwinc15x0_dynamic_scan
CFLAGS += -DDEBUG_ASSERT_VERBOSE=1

CFLAGS += -DATWINC15X0_PARAM_SSN_PIN="GPIO_PIN(1, 28)" \
          -DATWINC15X0_PARAM_RESET_PIN="GPIO_PIN(0, 6)" \
          -DATWINC15X0_PARAM_IRQ_PIN="GPIO_PIN(1, 7)" \
          -DATWINC15X0_PARAM_CHIP_EN_PIN="GPIO_PIN(0, 27)" \
          -DATWINC15X0_PARAM_WAKE_PIN="GPIO_PIN(0, 7)" \
          -DATWINC15X0_PARAM_SPI_CLK="MHZ(48)"

include Makefile

Try out iw command.

Test: gnrc_border router

My wrapping Makefile:

Makefile_same54_xpro.mk
BOARD ?= same54-xpro

CFLAGS += -DDEBUG_ASSERT_VERBOSE

UPLINK=wifi
CFLAGS += -DCONFIG_GNRC_DHCPV6_CLIENT_6LBR_UPSTREAM=5

USEMODULE += shell_cmd_iw
USEMODULE+=atwinc15x0_dynamic_connect
USEMODULE+=atwinc15x0_dynamic_scan
USEMODULE+=atwinc15x0
CFLAGS += -DATWINC15X0_PARAM_SSN_PIN="GPIO_PIN(1, 28)" \
          -DATWINC15X0_PARAM_RESET_PIN="GPIO_PIN(0, 6)" \
          -DATWINC15X0_PARAM_IRQ_PIN="GPIO_PIN(1, 7)" \
          -DATWINC15X0_PARAM_CHIP_EN_PIN="GPIO_PIN(0, 27)" \
          -DATWINC15X0_PARAM_WAKE_PIN="GPIO_PIN(0, 7)" \
          -DATWINC15X0_PARAM_SPI_CLK="MHZ(48)"

include Makefile
2023-03-14 12:28:09,044 # main(): This is RIOT! (Version: 2019.10-devel-19942-g71c2d-drivers_atwinc1510_scan_result)
2023-03-14 12:28:09,045 # RIOT border router example application
2023-03-14 12:28:09,045 # All up, running the shell now
iw 5 connect ... -k ...
2023-03-14 12:28:23,940 # iw 5 connect ... -k ...
2023-03-14 12:28:24,056 # [atwinc15x0] WiFi connected
2023-03-14 12:28:24,061 # connected to ...
2023-03-14 12:28:24,062 # iw: ok
> ifconfig
2023-03-14 12:28:33,190 # ifconfig
2023-03-14 12:28:33,221 # Iface  5  HWaddr: F8:F0:05:AD:B2:94  Channel: 0  RSSI: -52  Link: up 
2023-03-14 12:28:33,223 #            State: IDLE 
2023-03-14 12:28:33,227 #           L2-PDU:1500  MTU:1500  HL:64  RTR  
2023-03-14 12:28:33,230 #           Source address length: 6
2023-03-14 12:28:33,233 #           Link type: wireless
2023-03-14 12:28:33,240 #           inet6 addr: 2a0c:d242:4482:3a00:faf0:5ff:fead:b294  scope: global  VAL
2023-03-14 12:28:33,243 #           inet6 group: ff02::2
2023-03-14 12:28:33,245 #           inet6 group: ff02::1
2023-03-14 12:28:33,249 #           inet6 group: ff02::1:ffad:b294
2023-03-14 12:28:33,250 #           
2023-03-14 12:28:33,253 # Iface  6  HWaddr: FC:C2:3D:2F:8E:90 
2023-03-14 12:28:33,258 #           L2-PDU:1500  MTU:1500  HL:64  RTR  
2023-03-14 12:28:33,261 #           Source address length: 6
2023-03-14 12:28:33,263 #           Link type: wired
2023-03-14 12:28:33,269 #           inet6 addr: fe80::fec2:3dff:fe2f:8e90  scope: link  VAL
2023-03-14 12:28:33,272 #           inet6 group: ff02::2
2023-03-14 12:28:33,274 #           inet6 group: ff02::1
2023-03-14 12:28:33,278 #           inet6 group: ff02::1:ff2f:8e90
2023-03-14 12:28:33,279 #

Somehow the uplink does not configure a link-local address.
I will investigate on this problem.

Issues/PRs references

@github-actions github-actions bot added Area: build system Area: Build system Area: drivers Area: Device drivers Area: examples Area: Example Applications Area: Kconfig Area: Kconfig integration Area: network Area: Networking Area: sys Area: System Area: tests Area: tests and testing framework labels Mar 14, 2023
@benpicco benpicco requested a review from gschorcht March 14, 2023 14:07
Copy link
Contributor

@gschorcht gschorcht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some first comments.

sys/include/net/wifi.h Outdated Show resolved Hide resolved
drivers/atwinc15x0/atwinc15x0_netdev.c Outdated Show resolved Hide resolved
drivers/atwinc15x0/atwinc15x0_netdev.c Outdated Show resolved Hide resolved
drivers/atwinc15x0/atwinc15x0_netdev.c Outdated Show resolved Hide resolved
drivers/atwinc15x0/atwinc15x0_netdev.c Outdated Show resolved Hide resolved
drivers/atwinc15x0/atwinc15x0_netdev.c Outdated Show resolved Hide resolved
drivers/atwinc15x0/atwinc15x0_netdev.c Outdated Show resolved Hide resolved
drivers/atwinc15x0/atwinc15x0_netdev.c Outdated Show resolved Hide resolved
drivers/atwinc15x0/atwinc15x0_netdev.c Outdated Show resolved Hide resolved
drivers/atwinc15x0/atwinc15x0_netdev.c Outdated Show resolved Hide resolved
@gschorcht
Copy link
Contributor

Thanks for contribution this feature.

Some additional remarks:

  • You have a lot of preprocessor conditionals #if IS_USED(...) in your code. I stopped commenting them. Please check which could be used as C conditionals if (IS_USED(...= { instead.
  • WPA2 Enterprise mode should never be called WIFI_SECURITY_MODE_EAP_USER but WIFI_SECURITY_MODE_WPA2_ENTERPRISE.
  • `EAP user and password are used for inner authentification in WPA2 Enterprise mode. For the outer authentification you could usually define a identity. Is there something in the driver for using that?

@gschorcht
Copy link
Contributor

BTW, we should have this feature also in our prime WiFi platform ESP32x 😉

sys/shell/cmds/iw.c Outdated Show resolved Hide resolved
@benpicco
Copy link
Contributor

Your eMail address looks a bit mangled - you want to run

git config --global user.email

on that machine.

Comment on lines 44 to 56
#define ATWINC15X0_FLAG_SCANNING (((atwinc15x0_flags_t)1) << 0)

/**
* @brief Flag to indicate that the transceiver is trying to connect to an AP
* at the moment and is thus not able to process another connect
* request concurrently
*/
#define ATWINC1510_FLAG_CONNECTING (((atwinc15x0_flags_t)1) << 1)

/**
* @brief Flag to indicate that the transceiver is connected to an AP
*/
#define ATWINC15X0_FLAG_CONNECTED (((atwinc15x0_flags_t)1) << 2)
Copy link
Contributor

@benpicco benpicco Mar 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can those be set at the same time?
From a glance it feels like distinct states like

typedef enum {
    ATWINC1510_STATE_DISCONNECTED,
    ATWINC1510_STATE_DISCONNECTED_SCANNING,
    ATWINC1510_STATE_CONNECTING,
    ATWINC1510_STATE_CONNECTED,
    ATWINC1510_STATE_CONNECTED_SCANNING,
} atwinc15x0_state_t;

would be easier to handle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since

    if (IS_USED(MODULE_ATWINC15X0_STATIC_CONNECT)) {
        /* try to connect and return */
        res = _atwinc15x0_static_connect();
    }
    if (IS_USED(MODULE_ATWINC15X0_DYNAMIC_SCAN)) {
        wifi_scan_request_t request = WIFI_SCAN_REQUEST_INITIALIZER(NETOPT_SCAN_REQ_ALL_CH,
                                                                    _wifi_scan_cb, 0);
        _atwinc15x0_scan(&request);
    }

did not work when both modules were enabled, ATWINC1510_STATE_CONNECTING_SCANNING would not be a valid state, so I think your state analysis is right. Maybe it requires one more is_connected check to distinguish between ATWINC1510_STATE_DISCONNECTED_SCANNING and ATWINC1510_STATE_CONNECTED_SCANNING, but I can try to reformulate it with states.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am trying to turn netopt_state_t state into atwinc15x0_state_t state in atwinc15x0_t. It is a bit more effort than I thought, to think about what operation can be performed in which state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must still test a bit with the state handling

*/
typedef struct netopt_connect_request {
netopt_on_connect_result_t conn_cb; /**< On connect callback */
netopt_on_disconnect_result_t disconn_cb; /**< On disconnect callback */
Copy link
Contributor

@benpicco benpicco Mar 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see some redundancy with NETDEV_EVENT_LINK_UP/NETDEV_EVENT_LINK_DOWN with those - could #17902 be a generic alternative here?

On the other hand the only use case seems to be to make the shell commands block until completion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative maybe, but not sure.
An improvement for interested threads who did not request the action definately!
Giving a callback is not enforced, and also I would not exclude the case to send a message in the callback.
If #17902 gets merged before, I would also try with this, but I´m not sure if both ways are mutually exclusive.

@fabian18
Copy link
Contributor Author

git config --global user.email

Thank you for the hint. I applied the command with my new email.

@fabian18
Copy link
Contributor Author

EAP user and password are used for inner authentification in WPA2 Enterprise mode. For the outer authentification you could usually define a identity. Is there something in the driver for using that?

In m2m_types.h

typedef enum {
	M2M_WIFI_SEC_INVALID = 0,
	/*!< Invalid security type.
	*/
	M2M_WIFI_SEC_OPEN,
	/*!< Wi-Fi network is not secured.
	*/
	M2M_WIFI_SEC_WPA_PSK,
	/*!< Wi-Fi network is secured with WPA/WPA2 personal(PSK).
	*/
	M2M_WIFI_SEC_WEP,
	/*!< Security type WEP (40 or 104) OPEN OR SHARED.
	*/
	M2M_WIFI_SEC_802_1X
	/*!< Wi-Fi network is secured with WPA/WPA2 Enterprise.IEEE802.1x user-name/password authentication.
	 */
}tenuM2mSecType;
#define M2M_1X_USR_NAME_MAX								21
/*!< The maximum size of the user name including the NULL termination.
	It is used for RADIUS authentication in case of connecting the device to
	an AP secured with WPA-Enterprise.
*/


#define M2M_1X_PWD_MAX									41
/*!< The maximum size of the password including the NULL termination.
	It is used for RADIUS authentication in case of connecting the device to
	an AP secured with WPA-Enterprise.
*/
/*!
@struct	\
	tstr1xAuthCredentials

@brief
	Credentials for the user to authenticate with the AAA server (WPA-Enterprise Mode IEEE802.1x).
*/
typedef struct{
	uint8	au8UserName[M2M_1X_USR_NAME_MAX];
	/*!< User Name. It must be Null terminated string.
	*/
	uint8	au8Passwd[M2M_1X_PWD_MAX];
	/*!< Password corresponding to the user name. It must be Null terminated string.
	*/
}tstr1xAuthCredentials;
/*!
@union	\
	tuniM2MWifiAuth

@brief
	Wi-Fi Security Parameters for all supported security modes.
*/
typedef union{
	uint8				au8PSK[M2M_MAX_PSK_LEN];
	/*!< Pre-Shared Key in case of WPA-Personal security.
	*/
	tstr1xAuthCredentials	strCred1x;
	/*!< Credentials for RADIUS server authentication in case of WPA-Enterprise security.
	*/
	tstrM2mWifiWepParams	strWepInfo;
	/*!< WEP key parameters in case of WEP security.
	*/
}tuniM2MWifiAuth;

I am not so much familiar with WPA2 Enterprise but I have read that it can also deal with certificates and in your original PR you said you were having problems to connect to an Enterprise AP. I put the latest FW 19.7.7 on my module so maybe it works. I have not tried to connect to an Enterprise AP so far, but I think we have one in the office.

@fabian18
Copy link
Contributor Author

@gschorcht I think I addressed your comments.
Some stats:

# static connect only
   text    data     bss     dec     hex filename
  99876     252   31936  132064   203e0 /home/[email protected]/RIOT/examples/gnrc_networking/bin/same54-xpro/gnrc_networking.elf

cosy_static_connect_only

# static connect and dynamic connect
   text    data     bss     dec     hex filename
 100388     252   32000  132640   20620 /home/[email protected]/RIOT/examples/gnrc_networking/bin/same54-xpro/gnrc_networking.elf

cosy_static_connect_and_dynamic_connect

 # static connect and dynamic connect and dynamic scan
    text    data     bss     dec     hex filename
 100648     252   32032  132932   20744 /home/[email protected]/RIOT/examples/gnrc_networking/bin/same54-xpro/gnrc_networking.elf

cosy_static_connect_dynamic_connect_dynamic_scan

@benpicco I will try to change the flags to states and have a look at #17902

sys/include/net/wifi.h Outdated Show resolved Hide resolved
sys/shell/cmds/iw.c Outdated Show resolved Hide resolved
sys/shell/cmds/iw.c Outdated Show resolved Hide resolved
@fabian18 fabian18 force-pushed the drivers_atwinc1510_scan_result branch from 613499e to c6ba3fe Compare July 15, 2023 18:36
Copy link
Contributor

@gschorcht gschorcht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good an works as expected.

@gschorcht
Copy link
Contributor

Please squash. Use a shorter commit message for commit f932a3b, it exhausts the maximum of 72 characters.

@fabian18 fabian18 force-pushed the drivers_atwinc1510_scan_result branch from c6ba3fe to 283c206 Compare August 18, 2023 22:49
@fabian18
Copy link
Contributor Author

Awesome, thanks!

@fabian18 fabian18 added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Aug 19, 2023
@riot-ci
Copy link

riot-ci commented Aug 19, 2023

Murdock results

✔️ PASSED

8e122e9 drivers/atwinc15x0: handle M2M errors of m2m_wifi_enable_mac_mcast

Success Failures Total Runtime
7939 0 7939 13m:33s

Artifacts

@fabian18 fabian18 force-pushed the drivers_atwinc1510_scan_result branch from 283c206 to 63497a8 Compare August 19, 2023 20:07
Fabian Hüßler and others added 7 commits August 19, 2023 23:23
There are new pseudomodules for this driver:

- atwinc15x0_static_connect: Should behave as before, by trying to connect to an AP
by specified WIFI_SSIS and WIFI_PASS

- atwinc15x0_dynamic_connect: takes connection request via NETOPT_CONNECT
and provides the connection result via callback

- atwinc15x0_dynamic_scan: takes network scan requests via NETOPT_SCAN
and provides the scan result as a sorted list via callback
@fabian18 fabian18 force-pushed the drivers_atwinc1510_scan_result branch from 63497a8 to 8e122e9 Compare August 19, 2023 21:23
@fabian18
Copy link
Contributor Author

@gschorcht are you fine with the force pushed changes which showed to be necessary from the Murdock run?

@gschorcht
Copy link
Contributor

@gschorcht are you fine with the force pushed changes which showed to be necessary from the Murdock run?

Yes, I'm fine with squashing changes directly to make Murdock happy.

@gschorcht gschorcht added Type: new feature The issue requests / The PR implemements a new feature for RIOT CI: ready for merge train 🚃 PR is ready to be merged and awaiting the next merge train labels Aug 21, 2023
@gschorcht
Copy link
Contributor

Maybe @benpicco can merge it together with other PRs that are already approved. I don't know whether setting the label CI: read for merge train is enough. BTW, the label seems to have a typo, I guess it should be CI: ready for merge train.

@benpicco
Copy link
Contributor

The merge process is still very manual, re-triggering #19253 gives some time to write

bors merge

beneath all PRs that should be merged. The label is just to ease filtering for PRs to include in the merge train.

bors bot added a commit that referenced this pull request Aug 21, 2023
19387: drivers/atwinc15x0: support dynamic scanning and connection to AP r=benpicco a=fabian18



19874: coap: add missing option numbers r=benpicco a=JKRhb



19875: coap: add missing Content-Format definitions r=benpicco a=JKRhb



19876: sys/net/ipv4/addr: fix typos r=benpicco a=Enoch247

### Contribution description

This patch fixes some typos in the doxygen doc.

### Testing procedure

Nothing to test. No change to code.

### Issues/PRs references

- None known


19878: makefiles/usb_board_reset.mk: declare term-delay target with test target r=benpicco a=aabadie



19886: cpu/efm32: fix DAC configuration r=benpicco a=gschorcht

### Contribution description

The EFM32 MCU allows the reference voltage to be configured per DAC device, not per DAC channel. Also, the DAC reference voltage was defined in the configuration but not used anywhere.

At the moment we have only defined one board (`stwstk6220a`) that uses the DAC, so changing the configuration interface shouldn't be critical.

### Testing procedure

`tests/periph/dac` should still work for the `stwstk6220a`
```
BOARD=slwstk6220a make -j8 -C tests/periph/dac flash
```
I don't have a `stwstk6220a` board (EFM32 Series 0) so that I can't test it. I could only test it for the `sltb009a` board (EFM32 Series 1) with the change for VDAC in PR #19887.

### Issues/PRs references


19888: boards/sltb009a: complete and fix documentation r=benpicco a=gschorcht

### Contribution description

This PR completes and fixes the documentation which was still in the state as generated automatically by `efm2riot`.

The PR also includes a fix of the configuration of the second UART device that was find out while completing the documentation.

### Testing procedure

Green CI

### Issues/PRs references


Co-authored-by: Fabian Hüßler <[email protected]@MLPA-NB119.(none)>
Co-authored-by: Fabian Hüßler <[email protected]>
Co-authored-by: Jan Romann <[email protected]>
Co-authored-by: Joshua DeWeese <[email protected]>
Co-authored-by: Alexandre Abadie <[email protected]>
Co-authored-by: Gunar Schorcht <[email protected]>
@bors
Copy link
Contributor

bors bot commented Aug 21, 2023

Build failed (retrying...):

@bors
Copy link
Contributor

bors bot commented Aug 21, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot merged commit e56353c into RIOT-OS:master Aug 21, 2023
@MrKevinWeiss MrKevinWeiss added this to the Release 2023.10 milestone Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: build system Area: Build system Area: drivers Area: Device drivers Area: examples Area: Example Applications Area: Kconfig Area: Kconfig integration Area: network Area: Networking Area: sys Area: System Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: ready for merge train 🚃 PR is ready to be merged and awaiting the next merge train Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants