Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
27d36d8
Fix MacOS (case) filename clashes
manchoz Jul 6, 2021
357dba7
Add examples
manchoz Jul 6, 2021
c39cfee
Add helpers begin methods
manchoz Feb 1, 2021
05a1b80
Fix WebClient example
manchoz Feb 1, 2021
540e0ab
Add Static IP support
manchoz Jul 5, 2021
a5e512a
Manage Client status
manchoz Jul 5, 2021
d1501d0
Add support for Static Network configuration
manchoz Jul 5, 2021
b04124a
Update examples
manchoz Jul 5, 2021
817b47a
Add forgotten mac parameter
manchoz Jul 5, 2021
cf184fd
Add checks on socket validity before operations
manchoz Jul 6, 2021
9172c17
Manage sockets already connected
manchoz Jul 6, 2021
4aad72b
Add client socket management
manchoz Jul 6, 2021
5f802c1
WiFi: Cleanup libraries and error handling
facchinm Jul 7, 2021
4ded56c
WiFi: make library compliant with Arduino APIs
facchinm Jul 7, 2021
ec4109d
Initial: start moving WiFi generic classes into a standalone library
facchinm Jul 8, 2021
e0e8647
WiFi: port Client and Server to the new wrapper class
facchinm Jul 8, 2021
02b1239
TEMP: MbedClient: add horrible Client "constructor"
facchinm Jul 8, 2021
73cbc6b
WiFi: port UDP to new MbedUdp class
facchinm Jul 8, 2021
175d09f
Ethernet: port library to SocketWrapper
facchinm Jul 8, 2021
37edb74
MbedClient: fix copy constructor
facchinm Jul 8, 2021
974f4c2
Network: cleanup libraries and licenses
facchinm Jul 9, 2021
d4bb9d8
Network: apply clang-format on libraries
facchinm Jul 9, 2021
4340946
MbedUdp: make socket non blocking
facchinm Jul 9, 2021
123694b
SocketWrapper: fix download() API visibility
facchinm Jul 9, 2021
bc92047
MbedUDP: take into account write() errors
facchinm Jul 9, 2021
7fd7c9a
Remove protected leftovers
manchoz Jul 13, 2021
d9fa625
Add EthernetServer::available()
manchoz Jul 13, 2021
8c7962f
Add ::dnsServerIP
manchoz Jul 13, 2021
a175f35
Unlock mutexes before return
manchoz Jul 13, 2021
15ca271
Fix Typo
manchoz Jul 13, 2021
d3e8ee3
Manage copy and assignement
manchoz Jul 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Network: cleanup libraries and licenses
  • Loading branch information
facchinm authored and manchoz committed Jul 14, 2021
commit 974f4c29fd7e1c32cfb0e524fab5759dcc457a76
3 changes: 2 additions & 1 deletion libraries/Ethernet/src/Ethernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ int arduino::EthernetClass::begin(uint8_t *mac, unsigned long timeout, unsigned

unsigned long start = millis();
eth_if->set_blocking(false);
nsapi_error_t result = eth_if->connect();
eth_if->connect();

while ((millis() - start < timeout) && (linkStatus() != LinkON)) {
delay(10);
Expand Down Expand Up @@ -68,6 +68,7 @@ EthernetHardwareStatus arduino::EthernetClass::hardwareStatus() {

int arduino::EthernetClass::disconnect() {
eth_if->disconnect();
return 1;
}


Expand Down
2 changes: 1 addition & 1 deletion libraries/Ethernet/src/Ethernet.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright 2018 Paul Stoffregen
* Copyright 2020 Arduino SA
* Copyright 2020-2021 Arduino SA
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
Expand Down
1 change: 0 additions & 1 deletion libraries/Ethernet/src/EthernetClient.cpp

This file was deleted.

4 changes: 2 additions & 2 deletions libraries/Ethernet/src/EthernetClient.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
EthernetClient.h - Library for Arduino Wifi shield.
Copyright (c) 2011-2014 Arduino LLC. All right reserved.
EthernetClient.h
Copyright (c) 2021 Arduino SA. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down
1 change: 0 additions & 1 deletion libraries/Ethernet/src/EthernetServer.cpp

This file was deleted.

4 changes: 2 additions & 2 deletions libraries/Ethernet/src/EthernetServer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
EthernetServer.h - Library for Arduino Wifi shield.
Copyright (c) 2011-2014 Arduino LLC. All right reserved.
EthernetServer.h
Copyright (c) 2021 Arduino SA. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
Expand Down
1 change: 0 additions & 1 deletion libraries/Ethernet/src/EthernetUdp.cpp

This file was deleted.

4 changes: 2 additions & 2 deletions libraries/Ethernet/src/EthernetUdp.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
EthernetUdp.h - Library for Arduino Wifi shield.
Copyright (c) 2011-2014 Arduino LLC. All right reserved.
EthernetUdp.h
Copyright (c) 2021 Arduino SA. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down
1 change: 0 additions & 1 deletion libraries/SocketWrapper/src/MbedClient.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "MbedClient.h"


#ifndef SOCKET_TIMEOUT
#define SOCKET_TIMEOUT 1500
#endif
Expand Down
6 changes: 4 additions & 2 deletions libraries/SocketWrapper/src/MbedClient.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
MbedClient.h - Library for Arduino Wifi shield.
MbedClient.h - Client implementation using mbed Sockets
Copyright (c) 2021 Arduino LLC. All right reserved.

This library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -40,7 +40,9 @@ class MbedClient : public arduino::Client {
public:
MbedClient();

// Find something better to save the socket, this is nwither copy nor move constructor
// Copy constructor, to be used when a Client returned by server.available()
// needs to "survive" event if it goes out of scope
// Sample usage: Client* new_client = new Client(existing_client)
MbedClient(const MbedClient& orig) {
auto _sock = orig.sock;
auto _m = (MbedClient*)&orig;
Expand Down
4 changes: 2 additions & 2 deletions libraries/SocketWrapper/src/MbedSSLClient.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
WiFiSSLClient.cpp - Library for Arduino Wifi shield.
Copyright (c) 2011-2014 Arduino. All right reserved.
MbedSSLClient.cpp - SSLClient implementation using mbed Sockets
Copyright (c) 2021 Arduino SA. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down
4 changes: 2 additions & 2 deletions libraries/SocketWrapper/src/MbedServer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
WiFiServer.h - Library for Arduino Wifi shield.
Copyright (c) 2011-2014 Arduino LLC. All right reserved.
MbedServer.h - Server implementation using mbed Sockets
Copyright (c) 2021 Arduino SA. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
Expand Down
2 changes: 1 addition & 1 deletion libraries/SocketWrapper/src/MbedUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ int arduino::MbedUDP::read(unsigned char* buffer, size_t len) {
}
}

if (len > max_bytes) len = max_bytes;
if (len > (size_t)max_bytes) len = max_bytes;

// copy to target buffer
memcpy(buffer, _current_packet, len);
Expand Down
4 changes: 2 additions & 2 deletions libraries/SocketWrapper/src/MbedUdp.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
WiFiUdp.h - Library for Arduino Wifi shield.
Copyright (c) 2011-2014 Arduino LLC. All right reserved.
MbedUdp.h - UDP implementation using mbed Sockets
Copyright (c) 2021 Arduino SA. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down
64 changes: 31 additions & 33 deletions libraries/SocketWrapper/src/SocketHelpers.cpp
Original file line number Diff line number Diff line change
@@ -1,36 +1,11 @@
/*
WiFi.h - Library for Arduino Wifi shield.
Copyright (c) 2011-2014 Arduino LLC. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "SocketHelpers.h"
#include "utility/http_request.h"
#include "utility/https_request.h"

static FILE* target;

void body_callback(const char* data, uint32_t data_len)
{
fwrite(data, 1, data_len, target);
}

uint8_t* arduino::MbedSocketClass::macAddress(uint8_t* mac) {
const char *mac_str = getNetwork()->get_mac_address();
for( int b = 0; b < 6; b++ )
{
uint32_t tmp;
sscanf( &mac_str[b * 2 + (b)], "%02x", &tmp) ;
sscanf( &mac_str[b * 2 + (b)], "%02x", (unsigned int*)&tmp) ;
mac[5-b] = (uint8_t)tmp ;
}
//sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", &mac[5], &mac[4], &mac[3], &mac[2], &mac[1], &mac[0]);
Expand Down Expand Up @@ -116,29 +91,52 @@ SocketAddress arduino::MbedSocketClass::socketAddressFromIpAddress(arduino::IPAd
return SocketAddress(convertedIP, port);
}


// Download helper

#include "utility/http_request.h"
#include "utility/https_request.h"

void MbedSocketClass::setFeedWatchdogFunc(voidFuncPtr func)
{
_feed_watchdog_func = func;
}

void MbedSocketClass::feedWatchdog()
{
if (_feed_watchdog_func)
_feed_watchdog_func();
}

void MbedSocketClass::body_callback(const char* data, uint32_t data_len)
{
feedWatchdog();
fwrite(data, 1, data_len, download_target);
}

int MbedSocketClass::download(char* url, const char* target_file, bool const is_https)
{
target = fopen(target_file, "wb");
download_target = fopen(target_file, "wb");

HttpRequest * req_http = nullptr;
HttpsRequest * req_https = nullptr;
HttpResponse * rsp = nullptr;

if (is_https)
{
req_https = new HttpsRequest(getNetwork(), nullptr, HTTP_GET, url, &body_callback);
req_https = new HttpsRequest(getNetwork(), nullptr, HTTP_GET, url, mbed::callback(this, &MbedSocketClass::body_callback));
rsp = req_https->send(NULL, 0);
if (rsp == NULL) {
fclose(target);
fclose(download_target);
return req_https->get_error();
}
}
else
{
req_http = new HttpRequest(getNetwork(), HTTP_GET, url, &body_callback);
req_http = new HttpRequest(getNetwork(), HTTP_GET, url, mbed::callback(this, &MbedSocketClass::body_callback));
rsp = req_http->send(NULL, 0);
if (rsp == NULL) {
fclose(target);
fclose(download_target);
return req_http->get_error();
}
}
Expand All @@ -147,7 +145,7 @@ int MbedSocketClass::download(char* url, const char* target_file, bool const is_
delay(10);
}

int const size = ftell(target);
fclose(target);
int const size = ftell(download_target);
fclose(download_target);
return size;
}
31 changes: 28 additions & 3 deletions libraries/SocketWrapper/src/SocketHelpers.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
SocketHelpers.h - Utility wrappers for mbed Sockets and NetworkInterfaces
Copyright (c) 2021 Arduino SA. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef MBEDSOCKETCLASS_H
#define MBEDSOCKETCLASS_H

Expand All @@ -20,22 +36,22 @@ class MbedSocketClass {
/* Change Ip configuration settings disabling the dhcp client
*
* param local_ip: Static ip configuration
* param dns_server: IP configuration for DNS server 1
* param dns_server: IP configuration for DNS server 1
*/
void config(IPAddress local_ip, IPAddress dns_server);

/* Change Ip configuration settings disabling the dhcp client
*
* param local_ip: Static ip configuration
* param dns_server: IP configuration for DNS server 1
* param dns_server: IP configuration for DNS server 1
* param gateway : Static gateway configuration
*/
void config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway);

/* Change Ip configuration settings disabling the dhcp client
*
* param local_ip: Static ip configuration
* param dns_server: IP configuration for DNS server 1
* param dns_server: IP configuration for DNS server 1
* param gateway: Static gateway configuration
* param subnet: Static Subnet mask
*/
Expand Down Expand Up @@ -84,6 +100,9 @@ class MbedSocketClass {

uint8_t* macAddress(uint8_t* mac);

void setFeedWatchdogFunc(voidFuncPtr func);
void feedWatchdog();

friend class MbedUDP;
friend class MbedServer;
friend class MbedClient;
Expand All @@ -95,6 +114,12 @@ class MbedSocketClass {
SocketAddress _dnsServer1 = nullptr;
SocketAddress _dnsServer2 = nullptr;

voidFuncPtr _feed_watchdog_func = nullptr;

static FILE* download_target;

void body_callback(const char* data, uint32_t data_len);

static arduino::IPAddress ipAddressFromSocketAddress(SocketAddress socketAddress);
static SocketAddress socketAddressFromIpAddress(arduino::IPAddress ip, uint16_t port);
};
Expand Down
4 changes: 2 additions & 2 deletions libraries/SocketWrapper/src/utility/http_request_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class HttpRequestBase {

nsapi_size_or_error_t send_buffer(char* buffer, uint32_t buffer_size) {
nsapi_size_or_error_t total_send_count = 0;
while (total_send_count < buffer_size) {
while ((uint32_t)total_send_count < buffer_size) {

// get a slice of the buffer
char *buffer_slice = buffer + total_send_count;
Expand Down Expand Up @@ -299,7 +299,7 @@ class HttpRequestBase {

// Pass the chunk into the http_parser
uint32_t nparsed = parser.execute((const char*)recv_buffer, recv_ret);
if (nparsed != recv_ret) {
if (nparsed != (uint32_t)recv_ret) {
// printf("Parsing failed... parsed %d bytes, received %d bytes\n", nparsed, recv_ret);
_error = -2101;
free(recv_buffer);
Expand Down
45 changes: 7 additions & 38 deletions libraries/WiFi/src/WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ bool arduino::WiFiClass::isVisible(const char* ssid) {

int arduino::WiFiClass::begin(const char* ssid, const char *passphrase) {
if (wifi_if == nullptr) {
//Q: What is the callback for?
_initializerCallback();
if(wifi_if == nullptr) return WL_CONNECT_FAILED;
}
return 0;
}

scanNetworks();
// use scan result to populate security field
Expand All @@ -39,7 +37,8 @@ int arduino::WiFiClass::beginAP(const char* ssid, const char *passphrase, uint8_
#endif

if (_softAP == NULL) {
return (_currentNetworkStatus = WL_AP_FAILED);
_currentNetworkStatus = WL_AP_FAILED;
return _currentNetworkStatus;
}

ensureDefaultAPNetworkConfiguration();
Expand All @@ -55,7 +54,8 @@ int arduino::WiFiClass::beginAP(const char* ssid, const char *passphrase, uint8_
registrationResult = softAPInterface->register_event_handler(arduino::WiFiClass::handleAPEvents);

if (registrationResult != NSAPI_ERROR_OK) {
return (_currentNetworkStatus = WL_AP_FAILED);
_currentNetworkStatus = WL_AP_FAILED;
return _currentNetworkStatus;
}

_currentNetworkStatus = (result == NSAPI_ERROR_OK && setSSID(ssid)) ? WL_AP_LISTENING : WL_AP_FAILED;
Expand Down Expand Up @@ -133,25 +133,6 @@ int arduino::WiFiClass::setSSID(const char* ssid){
return 1;
}

static const char *sec2str(nsapi_security_t sec)
{
switch (sec) {
case NSAPI_SECURITY_NONE:
return "None";
case NSAPI_SECURITY_WEP:
return "WEP";
case NSAPI_SECURITY_WPA:
return "WPA";
case NSAPI_SECURITY_WPA2:
return "WPA2";
case NSAPI_SECURITY_WPA_WPA2:
return "WPA/WPA2";
case NSAPI_SECURITY_UNKNOWN:
default:
return "Unknown";
}
}

static uint8_t sec2enum(nsapi_security_t sec)
{
switch (sec) {
Expand Down Expand Up @@ -223,18 +204,6 @@ unsigned long arduino::WiFiClass::getTime() {
return 0;
}

void arduino::WiFiClass::setFeedWatchdogFunc(ArduinoPortentaH7WiFiFeedWatchdogFuncPtr func)
{
_feed_watchdog_func = func;
}

void arduino::WiFiClass::feedWatchdog()
{
if (_feed_watchdog_func)
_feed_watchdog_func();
}


#if defined(COMPONENT_4343W_FS)

#define WIFI_FIRMWARE_PATH "/wlan/4343WA1.BIN"
Expand Down Expand Up @@ -286,7 +255,7 @@ wiced_result_t whd_firmware_check_hook(const char *mounted_name, int mount_err)


#include "whd_version.h"
char* arduino::WiFiClass::firmwareVersion() {
const char* arduino::WiFiClass::firmwareVersion() {
if (firmware_available) {
return WHD_VERSION;
} else {
Expand Down
Loading