mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Nina driver updates, bug fixes.
This commit is contained in:
parent
9c15742eb2
commit
5c127078ca
@ -11,6 +11,7 @@ print("Scanning...")
|
||||
while (True):
|
||||
scan_result = wlan.scan()
|
||||
for ap in scan_result:
|
||||
print("Channel:%d RSSI:%d Auth:%d BSSID:%s SSID:%s"%(ap))
|
||||
print("SSID: %s BSSID: %s Channel: %d RSSI: %d Auth: %d"
|
||||
%(ap[0], ":".join(["%X"%i for i in ap[1]]), ap[2], ap[3], ap[4]))
|
||||
print()
|
||||
time.sleep_ms(1000)
|
||||
|
||||
@ -8,9 +8,11 @@ wlan = network.WLAN(network.STA_IF)
|
||||
wlan.deinit()
|
||||
wlan.active(True)
|
||||
|
||||
print("Scanning...")
|
||||
while (True):
|
||||
scan_result = wlan.scan()
|
||||
for ap in scan_result:
|
||||
print(ap)
|
||||
print("SSID: %s BSSID: %s Channel: %d RSSI: %d Auth: %d"
|
||||
%(ap[0], ":".join(["%X"%i for i in ap[1]]), ap[2], ap[3], ap[4]))
|
||||
print()
|
||||
time.sleep_ms(1000)
|
||||
|
||||
@ -6,10 +6,11 @@
|
||||
*
|
||||
* This work is licensed under the MIT license, see the file LICENSE for details.
|
||||
*
|
||||
* NINA-W10 driver.
|
||||
* NINA-W10 WiFi driver.
|
||||
*/
|
||||
#ifndef __NINA_H__
|
||||
#define __NINA_H__
|
||||
|
||||
#define NINA_FW_VER_LEN (6)
|
||||
#define NINA_IPV4_ADDR_LEN (4)
|
||||
#define NINA_MAC_ADDR_LEN (6)
|
||||
@ -47,7 +48,6 @@ typedef enum {
|
||||
NINA_ERROR_TIMEOUT = -2,
|
||||
} nina_error_t;
|
||||
|
||||
|
||||
typedef enum {
|
||||
NINA_WIFI_MODE_STA = 0,
|
||||
NINA_WIFI_MODE_AP,
|
||||
@ -61,7 +61,7 @@ typedef struct {
|
||||
} nina_ifconfig_t;
|
||||
|
||||
typedef struct {
|
||||
int8_t rssi;
|
||||
int32_t rssi;
|
||||
uint8_t security;
|
||||
uint8_t channel;
|
||||
uint8_t bssid[NINA_MAC_ADDR_LEN];
|
||||
@ -69,7 +69,7 @@ typedef struct {
|
||||
} nina_scan_result_t;
|
||||
|
||||
typedef struct {
|
||||
int8_t rssi;
|
||||
int32_t rssi;
|
||||
uint8_t security;
|
||||
char ssid[NINA_MAX_SSID_LEN];
|
||||
uint8_t bssid[NINA_MAC_ADDR_LEN];
|
||||
@ -77,18 +77,18 @@ typedef struct {
|
||||
|
||||
typedef int (*nina_scan_callback_t)(nina_scan_result_t *, void *);
|
||||
|
||||
int nina_init();
|
||||
int nina_deinit();
|
||||
int nina_init(void);
|
||||
int nina_deinit(void);
|
||||
int nina_connect(const char *ssid, uint8_t security, const char *key, uint16_t channel);
|
||||
int nina_start_ap(const char *ssid, uint8_t security, const char *key, uint16_t channel);
|
||||
int nina_disconnect();
|
||||
int nina_isconnected();
|
||||
int nina_disconnect(void);
|
||||
int nina_isconnected(void);
|
||||
int nina_connected_sta(uint32_t *sta_ip);
|
||||
int nina_wait_for_sta(uint32_t *sta_ip, uint32_t timeout);
|
||||
int nina_ifconfig(nina_ifconfig_t *ifconfig, bool set);
|
||||
int nina_netinfo(nina_netinfo_t *netinfo);
|
||||
int nina_scan(nina_scan_callback_t scan_callback, void *arg, uint32_t timeout);
|
||||
int nina_get_rssi();
|
||||
int nina_get_rssi(void);
|
||||
int nina_fw_version(uint8_t *fw_ver);
|
||||
int nina_set_hostname(const char *name);
|
||||
int nina_gethostbyname(const char *name, uint8_t *out_ip);
|
||||
|
||||
@ -6,17 +6,18 @@
|
||||
*
|
||||
* This work is licensed under the MIT license, see the file LICENSE for details.
|
||||
*
|
||||
* NINA-W10 driver.
|
||||
* NINA-W10 WiFi driver.
|
||||
*/
|
||||
#include "py/mphal.h"
|
||||
|
||||
#if MICROPY_PY_NINAW10
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "py/mphal.h"
|
||||
#include "nina.h"
|
||||
#include "nina_bsp.h"
|
||||
|
||||
#define DATA_FLAG (0x40)
|
||||
#include "nina_bsp.h"
|
||||
#include "nina.h"
|
||||
|
||||
#define SPI_ACK (1)
|
||||
#define SPI_ERR (0xFF)
|
||||
@ -40,7 +41,7 @@
|
||||
#define NINA_VALS(...) (nina_vals_t []) {__VA_ARGS__}
|
||||
|
||||
#define NINA_SSELECT_TIMEOUT (10000)
|
||||
#define NINA_RESP_TIMEOUT (1000)
|
||||
#define NINA_RESPONSE_TIMEOUT (1000)
|
||||
#define NINA_CONNECT_TIMEOUT (10000)
|
||||
|
||||
#if NINA_DEBUG
|
||||
@ -49,6 +50,10 @@
|
||||
#define debug_printf(...)
|
||||
#endif
|
||||
|
||||
#ifndef __REVSH
|
||||
#define __REVSH(x) ((((uint16_t)x) << 8) | (((uint16_t)x) >> 8))
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint16_t size;
|
||||
const void *data;
|
||||
@ -60,91 +65,101 @@ typedef struct {
|
||||
} nina_vals_t;
|
||||
|
||||
typedef enum {
|
||||
SET_NET_CMD = 0x10,
|
||||
SET_PASSPHRASE_CMD = 0x11,
|
||||
SET_KEY_CMD = 0x12,
|
||||
//TEST_CMD = 0x13,
|
||||
SET_IP_CONFIG_CMD = 0x14,
|
||||
SET_DNS_CONFIG_CMD = 0x15,
|
||||
SET_HOSTNAME_CMD = 0x16,
|
||||
SET_POWER_MODE_CMD = 0x17,
|
||||
SET_AP_NET_CMD = 0x18,
|
||||
SET_AP_PASSPHRASE_CMD = 0x19,
|
||||
SET_DEBUG_CMD = 0x1A,
|
||||
GET_TEMPERATURE_CMD = 0x1B,
|
||||
GET_REASON_CODE_CMD = 0x1F,
|
||||
// STA mode commands.
|
||||
NINA_CMD_CONNECT_OPEN = 0x10,
|
||||
NINA_CMD_CONNECT_WEP = 0x11,
|
||||
NINA_CMD_CONNECT_WPA = 0x12,
|
||||
NINA_CMD_GET_SSID = 0x23,
|
||||
NINA_CMD_GET_BSSID = 0x24,
|
||||
NINA_CMD_GET_RSSI = 0x25,
|
||||
NINA_CMD_GET_ENCRYPT = 0x26,
|
||||
|
||||
GET_CONN_STATUS_CMD = 0x20,
|
||||
GET_IPADDR_CMD = 0x21,
|
||||
GET_MACADDR_CMD = 0x22,
|
||||
GET_CURR_SSID_CMD = 0x23,
|
||||
GET_CURR_BSSID_CMD = 0x24,
|
||||
GET_CURR_RSSI_CMD = 0x25,
|
||||
GET_CURR_ENCT_CMD = 0x26,
|
||||
SCAN_NETWORKS = 0x27,
|
||||
START_SERVER_TCP_CMD = 0x28,
|
||||
GET_STATE_TCP_CMD = 0x29,
|
||||
DATA_SENT_TCP_CMD = 0x2A,
|
||||
AVAIL_DATA_TCP_CMD = 0x2B,
|
||||
GET_DATA_TCP_CMD = 0x2C,
|
||||
START_CLIENT_TCP_CMD = 0x2D,
|
||||
STOP_CLIENT_TCP_CMD = 0x2E,
|
||||
GET_CLIENT_STATE_TCP_CMD= 0x2F,
|
||||
DISCONNECT_CMD = 0x30,
|
||||
//GET_IDX_SSID_CMD = 0x31,
|
||||
GET_IDX_RSSI_CMD = 0x32,
|
||||
GET_IDX_ENCT_CMD = 0x33,
|
||||
REQ_HOST_BY_NAME_CMD = 0x34,
|
||||
GET_HOST_BY_NAME_CMD = 0x35,
|
||||
START_SCAN_NETWORKS = 0x36,
|
||||
GET_FW_VERSION_CMD = 0x37,
|
||||
//GET_TEST_CMD = 0x38,
|
||||
SEND_DATA_UDP_CMD = 0x39,
|
||||
GET_REMOTE_DATA_CMD = 0x3A,
|
||||
GET_TIME_CMD = 0x3B,
|
||||
GET_IDX_BSSID_CMD = 0x3C,
|
||||
GET_IDX_CHANNEL_CMD = 0x3D,
|
||||
PING_CMD = 0x3E,
|
||||
GET_SOCKET_CMD = 0x3F,
|
||||
// AP mode commands.
|
||||
NINA_CMD_START_AP_OPEN = 0x18,
|
||||
NINA_CMD_START_AP_WEP = 0x19,
|
||||
|
||||
// All command with DATA_FLAG 0x40 send a 16bit Len
|
||||
SET_ENT_CMD = 0x40,
|
||||
SEND_DATA_TCP_CMD = 0x44,
|
||||
GET_DATABUF_TCP_CMD = 0x45,
|
||||
INSERT_DATABUF_CMD = 0x46,
|
||||
// AP mode scan commands.
|
||||
NINA_CMD_AP_START_SCAN = 0x36,
|
||||
NINA_CMD_AP_SCAN_RESULT = 0x27,
|
||||
NINA_CMD_AP_GET_RSSI = 0x32,
|
||||
NINA_CMD_AP_GET_ENCRYPT = 0x33,
|
||||
NINA_CMD_AP_GET_BSSID = 0x3C,
|
||||
NINA_CMD_AP_GET_CHANNEL = 0x3D,
|
||||
|
||||
// regular format commands
|
||||
SET_PIN_MODE = 0x50,
|
||||
SET_DIGITAL_WRITE = 0x51,
|
||||
SET_ANALOG_WRITE = 0x52,
|
||||
GET_DIGITAL_READ = 0x53,
|
||||
GET_ANALOG_READ = 0x54,
|
||||
// Disonnect/status commands.
|
||||
NINA_CMD_DISCONNECT = 0x30,
|
||||
NINA_CMD_CONN_STATUS = 0x20,
|
||||
|
||||
// regular format commands
|
||||
CMD_WRITE_FILE = 0x60,
|
||||
CMD_READ_FILE = 0x61,
|
||||
CMD_DELETE_FILE = 0x62,
|
||||
CMD_EXISTS_FILE = 0x63,
|
||||
CMD_DOWNLOAD_FILE = 0x64,
|
||||
CMD_APPLY_OTA_COMMAND = 0x65,
|
||||
CMD_RENAME_FILE = 0x66,
|
||||
CMD_DOWNLOAD_OTA = 0x67,
|
||||
// Interface config commands.
|
||||
NINA_CMD_SET_IF_CONFIG = 0x14,
|
||||
NINA_CMD_GET_IF_CONFIG = 0x21,
|
||||
NINA_CMD_SET_DNS_CONFIG = 0x15,
|
||||
|
||||
// Hostname/Resolv commands.
|
||||
NINA_CMD_SET_HOSTNAME = 0x16,
|
||||
NINA_CMD_HOST_BY_NAME = 0x34,
|
||||
NINA_CMD_GET_HOST_BY_NAME = 0x35,
|
||||
|
||||
// Misc commands.
|
||||
NINA_CMD_SET_POWER = 0x17,
|
||||
NINA_CMD_PING = 0x3E,
|
||||
NINA_CMD_GET_TIME = 0x3B,
|
||||
NINA_CMD_GET_FW_VERSION = 0x37,
|
||||
NINA_CMD_DEBUG_MODE = 0x1A,
|
||||
NINA_CMD_TEMP_SENSOR = 0x1B,
|
||||
NINA_CMD_GET_MAC_ADDR = 0x22,
|
||||
|
||||
// Sockets commands.
|
||||
NINA_CMD_SOCKET_OPEN = 0x3F,
|
||||
NINA_CMD_SOCKET_CLOSE = 0x2E,
|
||||
NINA_CMD_SOCKET_CONNECT = 0x2D,
|
||||
NINA_CMD_SOCKET_ACCEPT = 0x2B,
|
||||
NINA_CMD_SOCKET_BIND = 0x28,
|
||||
NINA_CMD_SOCKET_STATE = 0x2F,
|
||||
NINA_CMD_SOCKET_REMOTE_ADDR = 0x3A,
|
||||
|
||||
// TCP commands
|
||||
NINA_CMD_TCP_SEND = 0x44,
|
||||
NINA_CMD_TCP_RECV = 0x45,
|
||||
NINA_CMD_TCP_ACK = 0x2A,
|
||||
|
||||
// UDP commands.
|
||||
NINA_CMD_UDP_SEND = 0x46,
|
||||
NINA_CMD_UDP_RECV = 0x45,
|
||||
NINA_CMD_UDP_ACK = 0x39,
|
||||
|
||||
// Pin control commands.
|
||||
NINA_CMD_SET_PIN_MODE = 0x50,
|
||||
NINA_CMD_SET_DIGITAL_WRITE = 0x51,
|
||||
NINA_CMD_GET_DIGITAL_READ = 0x53,
|
||||
NINA_CMD_SET_ANALOG_WRITE = 0x52,
|
||||
NINA_CMD_GET_ANALOG_READ = 0x54,
|
||||
|
||||
// File send/recv commands.
|
||||
NINA_CMD_CMD_WRITE_FILE = 0x60,
|
||||
NINA_CMD_CMD_READ_FILE = 0x61,
|
||||
NINA_CMD_CMD_DELETE_FILE = 0x62,
|
||||
NINA_CMD_CMD_EXISTS_FILE = 0x63,
|
||||
NINA_CMD_CMD_DOWNLOAD_FILE = 0x64,
|
||||
|
||||
// OTA upgrade commands.
|
||||
NINA_CMD_CMD_APPLY_OTA = 0x65,
|
||||
NINA_CMD_CMD_RENAME_FILE = 0x66,
|
||||
NINA_CMD_CMD_DOWNLOAD_OTA = 0x67,
|
||||
} nina_cmd_t;
|
||||
|
||||
typedef enum {
|
||||
WL_NO_SHIELD = 255,
|
||||
WL_NO_MODULE = WL_NO_SHIELD,
|
||||
WL_IDLE_STATUS = 0,
|
||||
WL_NO_SSID_AVAIL,
|
||||
WL_SCAN_COMPLETED,
|
||||
WL_CONNECTED,
|
||||
WL_CONNECT_FAILED,
|
||||
WL_CONNECTION_LOST,
|
||||
WL_DISCONNECTED,
|
||||
WL_AP_LISTENING,
|
||||
WL_AP_CONNECTED,
|
||||
WL_AP_FAILED
|
||||
} nina_wl_status_t;
|
||||
NINA_STATUS_IDLE = 0,
|
||||
NINA_STATUS_NO_SSID_AVAIL,
|
||||
NINA_STATUS_SCAN_COMPLETED,
|
||||
NINA_STATUS_CONNECTED,
|
||||
NINA_STATUS_CONNECT_FAILED,
|
||||
NINA_STATUS_CONNECTION_LOST,
|
||||
NINA_STATUS_DISCONNECTED,
|
||||
NINA_STATUS_AP_LISTENING,
|
||||
NINA_STATUS_AP_CONNECTED,
|
||||
NINA_STATUS_AP_FAILED
|
||||
} nina_status_t;
|
||||
|
||||
typedef enum {
|
||||
SOCKET_STATE_CLOSED = 0,
|
||||
@ -160,15 +175,13 @@ typedef enum {
|
||||
SOCKET_STATE_TIME_WAIT
|
||||
} nina_sock_state_t;
|
||||
|
||||
static uint8_t nina_bsp_spi_read_byte()
|
||||
{
|
||||
static uint8_t nina_bsp_spi_read_byte(void) {
|
||||
uint8_t byte = 0;
|
||||
nina_bsp_spi_transfer(NULL, &byte, 1);
|
||||
return byte;
|
||||
}
|
||||
|
||||
static int nina_wait_for_cmd(uint8_t cmd, uint32_t timeout)
|
||||
{
|
||||
static int nina_wait_for_cmd(uint8_t cmd, uint32_t timeout) {
|
||||
uint8_t buf = 0;
|
||||
for (mp_uint_t start = mp_hal_ticks_ms(); ;) {
|
||||
buf = nina_bsp_spi_read_byte();
|
||||
@ -179,11 +192,10 @@ static int nina_wait_for_cmd(uint8_t cmd, uint32_t timeout)
|
||||
mp_hal_delay_ms(1);
|
||||
}
|
||||
|
||||
return ((buf == cmd) ? 0 : -1);
|
||||
return (buf == cmd) ? 0 : -1;
|
||||
}
|
||||
|
||||
static int nina_send_command(uint32_t cmd, uint32_t nargs, uint32_t width, nina_args_t *args)
|
||||
{
|
||||
static int nina_send_command(uint32_t cmd, uint32_t nargs, uint32_t width, nina_args_t *args) {
|
||||
int ret = -1;
|
||||
uint32_t length = 4; // 3 bytes header + 1 end byte
|
||||
|
||||
@ -231,8 +243,7 @@ error_out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int nina_read_response(uint32_t cmd, uint32_t nvals, uint32_t width, nina_vals_t *vals)
|
||||
{
|
||||
static int nina_read_response(uint32_t cmd, uint32_t nvals, uint32_t width, nina_vals_t *vals) {
|
||||
int ret = -1;
|
||||
|
||||
debug_printf("nina_read_response(cmd 0x%x nvals %d width %d): ", cmd, nvals, width);
|
||||
@ -243,7 +254,7 @@ static int nina_read_response(uint32_t cmd, uint32_t nvals, uint32_t width, nina
|
||||
}
|
||||
|
||||
// Wait for CMD_START
|
||||
if (nina_wait_for_cmd(CMD_START, NINA_RESP_TIMEOUT) != 0) {
|
||||
if (nina_wait_for_cmd(CMD_START, NINA_RESPONSE_TIMEOUT) != 0) {
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
@ -294,8 +305,7 @@ error_out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int nina_send_command_read_ack(uint32_t cmd, uint32_t nargs, uint32_t width, nina_args_t *args)
|
||||
{
|
||||
static int nina_send_command_read_ack(uint32_t cmd, uint32_t nargs, uint32_t width, nina_args_t *args) {
|
||||
uint16_t size = 1;
|
||||
uint8_t rval = SPI_ERR;
|
||||
if (nina_send_command(cmd, nargs, width, args) != 0 ||
|
||||
@ -306,8 +316,7 @@ static int nina_send_command_read_ack(uint32_t cmd, uint32_t nargs, uint32_t wid
|
||||
}
|
||||
|
||||
static int nina_send_command_read_vals(uint32_t cmd, uint32_t nargs,
|
||||
uint32_t argsw, nina_args_t *args, uint32_t nvals, uint32_t valsw, nina_vals_t *vals)
|
||||
{
|
||||
uint32_t argsw, nina_args_t *args, uint32_t nvals, uint32_t valsw, nina_vals_t *vals) {
|
||||
|
||||
if (nina_send_command(cmd, nargs, argsw, args) != 0 ||
|
||||
nina_read_response(cmd, nvals, valsw, vals) != 0) {
|
||||
@ -316,38 +325,40 @@ static int nina_send_command_read_vals(uint32_t cmd, uint32_t nargs,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nina_init()
|
||||
{
|
||||
static void nina_fix_mac_addr(uint8_t *mac) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
uint8_t b = mac[i];
|
||||
mac[i] = mac[5 - i];
|
||||
mac[5 - i] = b;
|
||||
}
|
||||
}
|
||||
|
||||
int nina_init(void) {
|
||||
// Initialize the BSP.
|
||||
nina_bsp_init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nina_deinit()
|
||||
{
|
||||
int nina_deinit(void) {
|
||||
return nina_bsp_deinit();
|
||||
}
|
||||
|
||||
static int nina_connection_status()
|
||||
{
|
||||
return nina_send_command_read_ack(GET_CONN_STATUS_CMD, 0, ARG_8BITS, NULL);
|
||||
static int nina_connection_status() {
|
||||
return nina_send_command_read_ack(NINA_CMD_CONN_STATUS, 0, ARG_8BITS, NULL);
|
||||
}
|
||||
|
||||
static int nina_socket_status(uint8_t fd)
|
||||
{
|
||||
return nina_send_command_read_ack(GET_CLIENT_STATE_TCP_CMD,
|
||||
static int nina_socket_status(uint8_t fd) {
|
||||
return nina_send_command_read_ack(NINA_CMD_SOCKET_STATE,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_BYTE(fd)));
|
||||
}
|
||||
|
||||
static int nina_server_socket_status(uint8_t fd)
|
||||
{
|
||||
return nina_send_command_read_ack(GET_STATE_TCP_CMD,
|
||||
static int nina_server_socket_status(uint8_t fd) {
|
||||
return nina_send_command_read_ack(NINA_CMD_SOCKET_STATE & 0xF9,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_BYTE(fd)));
|
||||
}
|
||||
|
||||
int nina_connect(const char *ssid, uint8_t security, const char *key, uint16_t channel)
|
||||
{
|
||||
uint8_t status = WL_CONNECT_FAILED;
|
||||
int nina_connect(const char *ssid, uint8_t security, const char *key, uint16_t channel) {
|
||||
uint8_t status = NINA_STATUS_CONNECT_FAILED;
|
||||
|
||||
if (key == NULL && security != NINA_SEC_OPEN) {
|
||||
return -1;
|
||||
@ -355,19 +366,19 @@ int nina_connect(const char *ssid, uint8_t security, const char *key, uint16_t c
|
||||
|
||||
switch (security) {
|
||||
case NINA_SEC_OPEN:
|
||||
if (nina_send_command_read_ack(SET_NET_CMD,
|
||||
if (nina_send_command_read_ack(NINA_CMD_CONNECT_OPEN,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_STR(ssid))) != SPI_ACK) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case NINA_SEC_WEP:
|
||||
if (nina_send_command_read_ack(SET_PASSPHRASE_CMD,
|
||||
if (nina_send_command_read_ack(NINA_CMD_CONNECT_WEP,
|
||||
2, ARG_8BITS, NINA_ARGS(ARG_STR(ssid), ARG_STR(key))) != SPI_ACK) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case NINA_SEC_WPA_PSK:
|
||||
if (nina_send_command_read_ack(SET_KEY_CMD,
|
||||
if (nina_send_command_read_ack(NINA_CMD_CONNECT_WPA,
|
||||
3, ARG_8BITS, NINA_ARGS(ARG_STR(ssid), ARG_BYTE(0), ARG_STR(key))) != SPI_ACK) {
|
||||
return -1;
|
||||
}
|
||||
@ -378,7 +389,7 @@ int nina_connect(const char *ssid, uint8_t security, const char *key, uint16_t c
|
||||
|
||||
for (mp_uint_t start = mp_hal_ticks_ms(); ; mp_hal_delay_ms(10)) {
|
||||
status = nina_connection_status();
|
||||
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
|
||||
if ((status != NINA_STATUS_IDLE) && (status != NINA_STATUS_NO_SSID_AVAIL) && (status != NINA_STATUS_SCAN_COMPLETED)) {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -387,12 +398,11 @@ int nina_connect(const char *ssid, uint8_t security, const char *key, uint16_t c
|
||||
}
|
||||
}
|
||||
|
||||
return (status == WL_CONNECTED) ? 0 : -1;
|
||||
return (status == NINA_STATUS_CONNECTED) ? 0 : -1;
|
||||
}
|
||||
|
||||
int nina_start_ap(const char *ssid, uint8_t security, const char *key, uint16_t channel)
|
||||
{
|
||||
uint8_t status = WL_AP_FAILED;
|
||||
int nina_start_ap(const char *ssid, uint8_t security, const char *key, uint16_t channel) {
|
||||
uint8_t status = NINA_STATUS_AP_FAILED;
|
||||
|
||||
if ((key == NULL && security != NINA_SEC_OPEN) ||
|
||||
(security != NINA_SEC_OPEN && security != NINA_SEC_WEP)) {
|
||||
@ -401,13 +411,13 @@ int nina_start_ap(const char *ssid, uint8_t security, const char *key, uint16_t
|
||||
|
||||
switch (security) {
|
||||
case NINA_SEC_OPEN:
|
||||
if (nina_send_command_read_ack(SET_AP_NET_CMD,
|
||||
if (nina_send_command_read_ack(NINA_CMD_START_AP_OPEN,
|
||||
2, ARG_8BITS, NINA_ARGS(ARG_STR(ssid), ARG_BYTE(channel))) != SPI_ACK) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case NINA_SEC_WEP:
|
||||
if (nina_send_command_read_ack(SET_AP_PASSPHRASE_CMD,
|
||||
if (nina_send_command_read_ack(NINA_CMD_START_AP_WEP,
|
||||
3, ARG_8BITS, NINA_ARGS(ARG_STR(ssid), ARG_STR(key), ARG_BYTE(channel))) != SPI_ACK) {
|
||||
return -1;
|
||||
}
|
||||
@ -418,7 +428,7 @@ int nina_start_ap(const char *ssid, uint8_t security, const char *key, uint16_t
|
||||
|
||||
for (mp_uint_t start = mp_hal_ticks_ms(); ; mp_hal_delay_ms(10)) {
|
||||
status = nina_connection_status();
|
||||
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
|
||||
if ((status != NINA_STATUS_IDLE) && (status != NINA_STATUS_NO_SSID_AVAIL) && (status != NINA_STATUS_SCAN_COMPLETED)) {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -427,46 +437,41 @@ int nina_start_ap(const char *ssid, uint8_t security, const char *key, uint16_t
|
||||
}
|
||||
}
|
||||
|
||||
return (status == WL_AP_LISTENING) ? 0 : -1;
|
||||
return (status == NINA_STATUS_AP_LISTENING) ? 0 : -1;
|
||||
}
|
||||
|
||||
int nina_disconnect()
|
||||
{
|
||||
if (nina_send_command_read_ack(DISCONNECT_CMD,
|
||||
int nina_disconnect(void) {
|
||||
if (nina_send_command_read_ack(NINA_CMD_DISCONNECT,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_BYTE(0xFF))) != SPI_ACK) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nina_isconnected()
|
||||
{
|
||||
int nina_isconnected(void) {
|
||||
int status = nina_connection_status();
|
||||
if (status == -1) {
|
||||
return -1;
|
||||
}
|
||||
return (status == WL_CONNECTED);
|
||||
return status == NINA_STATUS_CONNECTED;
|
||||
}
|
||||
|
||||
int nina_connected_sta(uint32_t *sta_ip)
|
||||
{
|
||||
int nina_connected_sta(uint32_t *sta_ip) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int nina_wait_for_sta(uint32_t *sta_ip, uint32_t timeout)
|
||||
{
|
||||
int nina_wait_for_sta(uint32_t *sta_ip, uint32_t timeout) {
|
||||
return NINA_ERROR_TIMEOUT;
|
||||
}
|
||||
|
||||
int nina_ifconfig(nina_ifconfig_t *ifconfig, bool set)
|
||||
{
|
||||
int nina_ifconfig(nina_ifconfig_t *ifconfig, bool set) {
|
||||
uint16_t ip_len = NINA_IPV4_ADDR_LEN;
|
||||
uint16_t sub_len = NINA_IPV4_ADDR_LEN;
|
||||
uint16_t gw_len = NINA_IPV4_ADDR_LEN;
|
||||
uint16_t dns_len = NINA_IPV4_ADDR_LEN;
|
||||
|
||||
if (set) {
|
||||
if (nina_send_command_read_ack(SET_IP_CONFIG_CMD,
|
||||
if (nina_send_command_read_ack(NINA_CMD_SET_IF_CONFIG,
|
||||
4, ARG_8BITS,
|
||||
NINA_ARGS(
|
||||
ARG_BYTE(3), // Valid number of args.
|
||||
@ -476,7 +481,7 @@ int nina_ifconfig(nina_ifconfig_t *ifconfig, bool set)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nina_send_command_read_ack(SET_DNS_CONFIG_CMD,
|
||||
if (nina_send_command_read_ack(NINA_CMD_SET_DNS_CONFIG,
|
||||
3, ARG_8BITS,
|
||||
NINA_ARGS(
|
||||
ARG_BYTE(1), // Valid number of args.
|
||||
@ -486,7 +491,7 @@ int nina_ifconfig(nina_ifconfig_t *ifconfig, bool set)
|
||||
}
|
||||
|
||||
} else {
|
||||
if (nina_send_command_read_vals(GET_IPADDR_CMD,
|
||||
if (nina_send_command_read_vals(NINA_CMD_GET_IF_CONFIG,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_BYTE(0xFF)),
|
||||
3, ARG_8BITS,
|
||||
NINA_VALS(
|
||||
@ -501,42 +506,45 @@ int nina_ifconfig(nina_ifconfig_t *ifconfig, bool set)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nina_netinfo(nina_netinfo_t *netinfo)
|
||||
{
|
||||
int nina_netinfo(nina_netinfo_t *netinfo) {
|
||||
uint16_t rssi_len = 4;
|
||||
uint16_t sec_len = 1;
|
||||
uint16_t ssid_len = NINA_MAX_SSID_LEN;
|
||||
uint16_t bssid_len = NINA_MAC_ADDR_LEN;
|
||||
|
||||
if (nina_send_command_read_vals(GET_CURR_RSSI_CMD,
|
||||
if (nina_send_command_read_vals(NINA_CMD_GET_RSSI,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_BYTE(0xFF)),
|
||||
1, ARG_8BITS, NINA_VALS({&rssi_len, &netinfo->rssi})) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nina_send_command_read_vals(GET_CURR_ENCT_CMD,
|
||||
if (nina_send_command_read_vals(NINA_CMD_GET_ENCRYPT,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_BYTE(0xFF)),
|
||||
1, ARG_8BITS, NINA_VALS({&sec_len, &netinfo->security})) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nina_send_command_read_vals(GET_CURR_SSID_CMD,
|
||||
if (nina_send_command_read_vals(NINA_CMD_GET_SSID,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_BYTE(0xFF)),
|
||||
1, ARG_8BITS, NINA_VALS({&ssid_len, &netinfo->ssid})) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nina_send_command_read_vals(GET_CURR_BSSID_CMD,
|
||||
// Null terminate SSID.
|
||||
netinfo->ssid[MIN((NINA_MAX_SSID_LEN - 1), ssid_len)] = 0;
|
||||
|
||||
if (nina_send_command_read_vals(NINA_CMD_GET_BSSID,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_BYTE(0xFF)),
|
||||
1, ARG_8BITS, NINA_VALS({&bssid_len, &netinfo->bssid})) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// The MAC address is read in reverse from the firmware.
|
||||
nina_fix_mac_addr(netinfo->bssid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nina_scan(nina_scan_callback_t scan_callback, void *arg, uint32_t timeout)
|
||||
{
|
||||
int nina_scan(nina_scan_callback_t scan_callback, void *arg, uint32_t timeout) {
|
||||
uint16_t sizes[NINA_MAX_NETWORK_LIST];
|
||||
char ssids[NINA_MAX_NETWORK_LIST][NINA_MAX_SSID_LEN];
|
||||
nina_vals_t vals[NINA_MAX_NETWORK_LIST];
|
||||
@ -549,13 +557,13 @@ int nina_scan(nina_scan_callback_t scan_callback, void *arg, uint32_t timeout)
|
||||
vals[i].data = ssids[i];
|
||||
}
|
||||
|
||||
if (nina_send_command_read_ack(START_SCAN_NETWORKS,
|
||||
if (nina_send_command_read_ack(NINA_CMD_AP_START_SCAN,
|
||||
0, ARG_8BITS, NULL) != SPI_ACK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (mp_uint_t start = mp_hal_ticks_ms(); ;) {
|
||||
if (nina_send_command_read_vals(SCAN_NETWORKS,
|
||||
if (nina_send_command_read_vals(NINA_CMD_AP_SCAN_RESULT,
|
||||
0, ARG_8BITS, NULL,
|
||||
NINA_MAX_NETWORK_LIST, ARG_8BITS, vals) != 0) {
|
||||
return -1;
|
||||
@ -589,44 +597,45 @@ int nina_scan(nina_scan_callback_t scan_callback, void *arg, uint32_t timeout)
|
||||
strncpy(scan_result.ssid, ssids[i], NINA_MAX_SSID_LEN);
|
||||
|
||||
// Read AP RSSI
|
||||
if (nina_send_command_read_vals(GET_IDX_RSSI_CMD,
|
||||
if (nina_send_command_read_vals(NINA_CMD_AP_GET_RSSI,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_BYTE(i)),
|
||||
1, ARG_8BITS, NINA_VALS({&rssi_len, &scan_result.rssi})) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Read AP encryption type
|
||||
if (nina_send_command_read_vals(GET_IDX_ENCT_CMD,
|
||||
if (nina_send_command_read_vals(NINA_CMD_AP_GET_ENCRYPT,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_BYTE(i)),
|
||||
1, ARG_8BITS, NINA_VALS({&sec_len, &scan_result.security})) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Read AP channel
|
||||
if (nina_send_command_read_vals(GET_IDX_CHANNEL_CMD,
|
||||
if (nina_send_command_read_vals(NINA_CMD_AP_GET_CHANNEL,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_BYTE(i)),
|
||||
1, ARG_8BITS, NINA_VALS({&chan_len, &scan_result.channel})) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Read AP bssid
|
||||
if (nina_send_command_read_vals(GET_IDX_BSSID_CMD,
|
||||
if (nina_send_command_read_vals(NINA_CMD_AP_GET_BSSID,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_BYTE(i)),
|
||||
1, ARG_8BITS, NINA_VALS({&bssid_len, scan_result.bssid})) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// The MAC address is read in reverse from the firmware.
|
||||
nina_fix_mac_addr(scan_result.bssid);
|
||||
scan_callback(&scan_result, arg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nina_get_rssi()
|
||||
{
|
||||
int nina_get_rssi(void) {
|
||||
uint16_t size = 4;
|
||||
uint16_t rssi = 0;
|
||||
if (nina_send_command_read_vals(GET_CURR_RSSI_CMD,
|
||||
int32_t rssi = 0;
|
||||
if (nina_send_command_read_vals(NINA_CMD_GET_RSSI,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_BYTE(0xFF)),
|
||||
1, ARG_8BITS, NINA_VALS({&size, &rssi})) != 0) {
|
||||
return -1;
|
||||
@ -635,10 +644,9 @@ int nina_get_rssi()
|
||||
return rssi;
|
||||
}
|
||||
|
||||
int nina_fw_version(uint8_t *fw_ver)
|
||||
{
|
||||
int nina_fw_version(uint8_t *fw_ver) {
|
||||
uint16_t size = NINA_FW_VER_LEN;
|
||||
if (nina_send_command_read_vals(GET_FW_VERSION_CMD,
|
||||
if (nina_send_command_read_vals(NINA_CMD_GET_FW_VERSION,
|
||||
0, ARG_8BITS, NULL,
|
||||
1, ARG_8BITS, NINA_VALS({&size, fw_ver})) != 0) {
|
||||
return -1;
|
||||
@ -646,25 +654,23 @@ int nina_fw_version(uint8_t *fw_ver)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nina_set_hostname(const char *hostname)
|
||||
{
|
||||
if (nina_send_command_read_ack(SET_HOSTNAME_CMD,
|
||||
int nina_set_hostname(const char *hostname) {
|
||||
if (nina_send_command_read_ack(NINA_CMD_SET_HOSTNAME,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_STR(hostname))) != SPI_ACK) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nina_gethostbyname(const char *name, uint8_t *out_ip)
|
||||
{
|
||||
int nina_gethostbyname(const char *name, uint8_t *out_ip) {
|
||||
uint16_t size = 4;
|
||||
|
||||
if (nina_send_command_read_ack(REQ_HOST_BY_NAME_CMD,
|
||||
if (nina_send_command_read_ack(NINA_CMD_HOST_BY_NAME,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_STR(name))) != SPI_ACK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nina_send_command_read_vals(GET_HOST_BY_NAME_CMD,
|
||||
if (nina_send_command_read_vals(NINA_CMD_GET_HOST_BY_NAME,
|
||||
0, ARG_8BITS, NULL,
|
||||
1, ARG_8BITS, NINA_VALS({&size, out_ip})) != 0) {
|
||||
return -1;
|
||||
@ -672,12 +678,11 @@ int nina_gethostbyname(const char *name, uint8_t *out_ip)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nina_socket_socket(uint8_t type)
|
||||
{
|
||||
int nina_socket_socket(uint8_t type) {
|
||||
uint16_t size = 1;
|
||||
uint8_t sock = 0;
|
||||
|
||||
if (nina_send_command_read_vals(GET_SOCKET_CMD,
|
||||
if (nina_send_command_read_vals(NINA_CMD_SOCKET_OPEN,
|
||||
0, ARG_8BITS, NULL,
|
||||
1, ARG_8BITS, NINA_VALS({&size, &sock})) != 0) {
|
||||
return -1;
|
||||
@ -685,10 +690,9 @@ int nina_socket_socket(uint8_t type)
|
||||
return sock;
|
||||
}
|
||||
|
||||
int nina_socket_close(int fd)
|
||||
{
|
||||
int nina_socket_close(int fd) {
|
||||
if (fd > 0 && fd < 255) {
|
||||
if (nina_send_command_read_ack(STOP_CLIENT_TCP_CMD,
|
||||
if (nina_send_command_read_ack(NINA_CMD_SOCKET_CLOSE,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_BYTE(fd))) != SPI_ACK) {
|
||||
return -1;
|
||||
}
|
||||
@ -704,9 +708,8 @@ int nina_socket_close(int fd)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nina_socket_bind(int fd, uint8_t *ip, uint16_t port, int type)
|
||||
{
|
||||
if (nina_send_command_read_ack(START_SERVER_TCP_CMD,
|
||||
int nina_socket_bind(int fd, uint8_t *ip, uint16_t port, int type) {
|
||||
if (nina_send_command_read_ack(NINA_CMD_SOCKET_BIND,
|
||||
3, ARG_8BITS,
|
||||
NINA_ARGS(
|
||||
ARG_SHORT(__REVSH(port)),
|
||||
@ -723,13 +726,11 @@ int nina_socket_bind(int fd, uint8_t *ip, uint16_t port, int type)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nina_socket_listen(int fd, uint32_t backlog)
|
||||
{
|
||||
int nina_socket_listen(int fd, uint32_t backlog) {
|
||||
return 0; // No listen ?
|
||||
}
|
||||
|
||||
int nina_socket_accept(int fd, uint8_t *ip, uint16_t *port, int *fd_out, uint32_t timeout)
|
||||
{
|
||||
int nina_socket_accept(int fd, uint8_t *ip, uint16_t *port, int *fd_out, uint32_t timeout) {
|
||||
uint16_t size = 2;
|
||||
uint16_t sock = NO_SOCKET_AVAIL;
|
||||
|
||||
@ -738,7 +739,7 @@ int nina_socket_accept(int fd, uint8_t *ip, uint16_t *port, int *fd_out, uint32_
|
||||
}
|
||||
|
||||
for (mp_uint_t start = mp_hal_ticks_ms(); sock == 0 || sock == NO_SOCKET_AVAIL; mp_hal_delay_ms(10)) {
|
||||
if (nina_send_command_read_vals(AVAIL_DATA_TCP_CMD,
|
||||
if (nina_send_command_read_vals(NINA_CMD_SOCKET_ACCEPT,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_BYTE(fd)),
|
||||
1, ARG_8BITS, NINA_VALS({&size, &sock})) != 0) {
|
||||
return -1;
|
||||
@ -751,7 +752,7 @@ int nina_socket_accept(int fd, uint8_t *ip, uint16_t *port, int *fd_out, uint32_
|
||||
|
||||
uint16_t port_len = 2;
|
||||
uint16_t ip_len = NINA_IPV4_ADDR_LEN;
|
||||
if (nina_send_command_read_vals(GET_REMOTE_DATA_CMD,
|
||||
if (nina_send_command_read_vals(NINA_CMD_SOCKET_REMOTE_ADDR,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_BYTE(sock)),
|
||||
2, ARG_8BITS, NINA_VALS({&ip_len, ip}, {&port_len, port})) != 0) {
|
||||
return -1;
|
||||
@ -761,9 +762,8 @@ int nina_socket_accept(int fd, uint8_t *ip, uint16_t *port, int *fd_out, uint32_
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nina_socket_connect(int fd, uint8_t *ip, uint16_t port, uint32_t timeout)
|
||||
{
|
||||
if (nina_send_command_read_ack(START_CLIENT_TCP_CMD,
|
||||
int nina_socket_connect(int fd, uint8_t *ip, uint16_t port, uint32_t timeout) {
|
||||
if (nina_send_command_read_ack(NINA_CMD_SOCKET_CONNECT,
|
||||
4, ARG_8BITS,
|
||||
NINA_ARGS(
|
||||
ARG_WORD((*(uint32_t *)ip)),
|
||||
@ -791,8 +791,7 @@ int nina_socket_connect(int fd, uint8_t *ip, uint16_t port, uint32_t timeout)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nina_socket_send(int fd, const uint8_t *buf, uint32_t len, uint32_t timeout)
|
||||
{
|
||||
int nina_socket_send(int fd, const uint8_t *buf, uint32_t len, uint32_t timeout) {
|
||||
uint16_t size = 2;
|
||||
uint16_t bytes = 0;
|
||||
|
||||
@ -800,14 +799,14 @@ int nina_socket_send(int fd, const uint8_t *buf, uint32_t len, uint32_t timeout)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nina_send_command_read_vals(SEND_DATA_TCP_CMD,
|
||||
if (nina_send_command_read_vals(NINA_CMD_TCP_SEND,
|
||||
2, ARG_16BITS, NINA_ARGS(ARG_BYTE(fd), {len, buf}),
|
||||
1, ARG_8BITS, NINA_VALS({&size, &bytes})) != 0 || bytes <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (mp_uint_t start = mp_hal_ticks_ms(); ;) {
|
||||
int resp = nina_send_command_read_ack(DATA_SENT_TCP_CMD,
|
||||
int resp = nina_send_command_read_ack(NINA_CMD_TCP_ACK,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_BYTE(fd)));
|
||||
|
||||
if (resp == -1) {
|
||||
@ -827,8 +826,7 @@ int nina_socket_send(int fd, const uint8_t *buf, uint32_t len, uint32_t timeout)
|
||||
return bytes;
|
||||
}
|
||||
|
||||
int nina_socket_recv(int fd, uint8_t *buf, uint32_t len, uint32_t timeout)
|
||||
{
|
||||
int nina_socket_recv(int fd, uint8_t *buf, uint32_t len, uint32_t timeout) {
|
||||
uint16_t bytes = 0;
|
||||
|
||||
if (nina_socket_status(fd) != SOCKET_STATE_ESTABLISHED) {
|
||||
@ -837,7 +835,7 @@ int nina_socket_recv(int fd, uint8_t *buf, uint32_t len, uint32_t timeout)
|
||||
|
||||
for (mp_uint_t start = mp_hal_ticks_ms(); bytes == 0; mp_hal_delay_ms(1)) {
|
||||
bytes = len;
|
||||
if (nina_send_command_read_vals(GET_DATABUF_TCP_CMD,
|
||||
if (nina_send_command_read_vals(NINA_CMD_TCP_RECV,
|
||||
2, ARG_16BITS, NINA_ARGS(ARG_BYTE(fd), ARG_SHORT(bytes)),
|
||||
1, ARG_16BITS, NINA_VALS({&bytes, buf})) != 0) {
|
||||
return -1;
|
||||
@ -851,10 +849,9 @@ int nina_socket_recv(int fd, uint8_t *buf, uint32_t len, uint32_t timeout)
|
||||
}
|
||||
|
||||
// Check from the upper layer if the socket is bound, if not then auto-bind it first.
|
||||
int nina_socket_sendto(int fd, const uint8_t *buf, uint32_t len, uint8_t *ip, uint16_t port, uint32_t timeout)
|
||||
{
|
||||
int nina_socket_sendto(int fd, const uint8_t *buf, uint32_t len, uint8_t *ip, uint16_t port, uint32_t timeout) {
|
||||
// TODO do we need to split the packet somewhere?
|
||||
if (nina_send_command_read_ack(START_CLIENT_TCP_CMD,
|
||||
if (nina_send_command_read_ack(NINA_CMD_SOCKET_CONNECT,
|
||||
4, ARG_8BITS,
|
||||
NINA_ARGS(
|
||||
ARG_WORD((*(uint32_t *)ip)),
|
||||
@ -865,12 +862,12 @@ int nina_socket_sendto(int fd, const uint8_t *buf, uint32_t len, uint8_t *ip, ui
|
||||
}
|
||||
|
||||
// Buffer length and socket number are passed as 16bits.
|
||||
if (nina_send_command_read_ack(INSERT_DATABUF_CMD,
|
||||
if (nina_send_command_read_ack(NINA_CMD_UDP_SEND,
|
||||
2, ARG_16BITS, NINA_ARGS(ARG_BYTE(fd), {len, buf})) != SPI_ACK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nina_send_command_read_ack(SEND_DATA_UDP_CMD,
|
||||
if (nina_send_command_read_ack(NINA_CMD_UDP_ACK,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_BYTE(fd))) != SPI_ACK) {
|
||||
return -1;
|
||||
}
|
||||
@ -879,15 +876,14 @@ int nina_socket_sendto(int fd, const uint8_t *buf, uint32_t len, uint8_t *ip, ui
|
||||
}
|
||||
|
||||
// Check from the upper layer if the socket is bound, if not then auto-bind it first.
|
||||
int nina_socket_recvfrom(int fd, uint8_t *buf, uint32_t len, uint8_t *ip, uint16_t *port, uint32_t timeout)
|
||||
{
|
||||
int nina_socket_recvfrom(int fd, uint8_t *buf, uint32_t len, uint8_t *ip, uint16_t *port, uint32_t timeout) {
|
||||
uint16_t bytes = 0;
|
||||
uint16_t port_len = 2;
|
||||
uint16_t ip_len = NINA_IPV4_ADDR_LEN;
|
||||
|
||||
for (mp_uint_t start = mp_hal_ticks_ms(); bytes == 0; mp_hal_delay_ms(1)) {
|
||||
bytes = len;
|
||||
if (nina_send_command_read_vals(GET_DATABUF_TCP_CMD,
|
||||
if (nina_send_command_read_vals(NINA_CMD_UDP_RECV,
|
||||
2, ARG_16BITS, NINA_ARGS(ARG_BYTE(fd), ARG_SHORT(bytes)),
|
||||
1, ARG_16BITS, NINA_VALS({&bytes, buf})) != 0) {
|
||||
return -1;
|
||||
@ -897,7 +893,7 @@ int nina_socket_recvfrom(int fd, uint8_t *buf, uint32_t len, uint8_t *ip, uint16
|
||||
return NINA_ERROR_TIMEOUT;
|
||||
}
|
||||
}
|
||||
if (nina_send_command_read_vals(GET_REMOTE_DATA_CMD,
|
||||
if (nina_send_command_read_vals(NINA_CMD_SOCKET_REMOTE_ADDR,
|
||||
1, ARG_8BITS, NINA_ARGS(ARG_BYTE(fd)),
|
||||
2, ARG_8BITS, NINA_VALS({&ip_len, ip}, {&port_len, port})) != 0) {
|
||||
return -1;
|
||||
@ -906,8 +902,8 @@ int nina_socket_recvfrom(int fd, uint8_t *buf, uint32_t len, uint8_t *ip, uint16
|
||||
return bytes;
|
||||
}
|
||||
|
||||
int nina_socket_setsockopt(int fd, uint32_t level, uint32_t opt, const void *optval, uint32_t optlen)
|
||||
{
|
||||
int nina_socket_setsockopt(int fd, uint32_t level, uint32_t opt, const void *optval, uint32_t optlen) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif // MICROPY_PY_NINAW10
|
||||
|
||||
@ -259,23 +259,15 @@ static mp_obj_t py_nina_netinfo(mp_obj_t self_in)
|
||||
static int nina_scan_callback(nina_scan_result_t *scan_result, void *arg)
|
||||
{
|
||||
mp_obj_t scan_list = (mp_obj_t)arg;
|
||||
|
||||
// Format MAC address
|
||||
VSTR_FIXED(bssid_vstr, 18);
|
||||
vstr_printf(&bssid_vstr, "%02X:%02X:%02X:%02X:%02X:%02X",
|
||||
scan_result->bssid[0], scan_result->bssid[1], scan_result->bssid[2],
|
||||
scan_result->bssid[3], scan_result->bssid[4], scan_result->bssid[5]);
|
||||
|
||||
mp_obj_t ap[5] = {
|
||||
mp_obj_t ap[6] = {
|
||||
mp_obj_new_bytes((uint8_t *)scan_result->ssid, strlen(scan_result->ssid)),
|
||||
mp_obj_new_bytes(scan_result->bssid, sizeof(scan_result->bssid)),
|
||||
mp_obj_new_int(scan_result->channel),
|
||||
mp_obj_new_int(scan_result->rssi),
|
||||
mp_obj_new_int(scan_result->security),
|
||||
mp_obj_new_str(bssid_vstr.buf, bssid_vstr.len),
|
||||
mp_obj_new_str(scan_result->ssid, strlen(scan_result->ssid)),
|
||||
MP_OBJ_NEW_SMALL_INT(1), // N
|
||||
};
|
||||
|
||||
mp_obj_list_append(scan_list, mp_obj_new_tuple(MP_ARRAY_SIZE(ap), ap));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user