Skip to content

Commit 00a6c79

Browse files
authored
Merge pull request #57 from facchinm/bearssl-nina-hack
Port BearSSL + crypto integration to NINA
2 parents 200f09d + 55c21a4 commit 00a6c79

File tree

357 files changed

+78183
-26
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

357 files changed

+78183
-26
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ PROJECT_NAME := nina-fw
22

33
EXTRA_COMPONENT_DIRS := $(PWD)/arduino
44

5+
CPPFLAGS += -DARDUINO
6+
57
ifeq ($(RELEASE),1)
68
CFLAGS += -DNDEBUG -DCONFIG_FREERTOS_ASSERT_DISABLE -Os -DLOG_LOCAL_LEVEL=0
79
CPPFLAGS += -DNDEBUG -Os

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ This firmware uses [Espressif's IDF](https://github.com/espressif/esp-idf)
1212
1. Load the `Tools -> SerialNINAPassthrough` example sketch on to the board
1313
1. Use `esptool` to flash the compiled firmware
1414

15+
## Notes
16+
If updating **Arduino UNO WiFi Rev. 2** NINA firmware via [SerialNINAPassthrough](https://github.com/arduino-libraries/WiFiNINA/blob/master/examples/Tools/SerialNINAPassthrough/SerialNINAPassthrough.ino) sketch then the `esptool` invocation needs to be changed slightly:
17+
```diff
18+
- --baud 115200 --before default_reset
19+
+ --baud 115200 --before no_reset
20+
```
21+
1522
## License
1623

1724
Copyright (c) 2018-2019 Arduino SA. All rights reserved.

arduino/component.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
COMPONENT_ADD_INCLUDEDIRS := cores/esp32 libraries/SPIS/src libraries/WiFi/src
1+
COMPONENT_ADD_INCLUDEDIRS := cores/esp32 libraries/SPIS/src libraries/WiFi/src libraries/Wire/src libraries/ArduinoECCX08/src libraries/ArduinoBearSSL/src
22

3-
COMPONENT_SRCDIRS := cores/esp32 libraries/SPIS/src libraries/WiFi/src
3+
COMPONENT_SRCDIRS := cores/esp32 libraries/SPIS/src libraries/WiFi/src libraries/Wire/src libraries/ArduinoECCX08/src libraries/ArduinoBearSSL/src libraries/ArduinoBearSSL/src/bearssl libraries/ArduinoBearSSL/src/utility

arduino/cores/esp32/Arduino.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626
#include <string.h>
2727
#include <math.h>
2828

29+
typedef bool boolean;
30+
typedef uint8_t byte;
31+
typedef uint16_t word;
32+
33+
#define min(a,b) ((a)<(b)?(a):(b))
34+
#define max(a,b) ((a)>(b)?(a):(b))
35+
#define abs(x) ((x)>0?(x):-(x))
36+
37+
2938
#ifdef __cplusplus
3039
extern "C"{
3140
#endif // __cplusplus
@@ -42,7 +51,9 @@ void loop(void);
4251
#endif
4352

4453
#ifdef __cplusplus
54+
#include "Stream.h"
4555
#include "WMath.h"
56+
#include "WString.h"
4657
#endif
4758
#include "delay.h"
4859

arduino/cores/esp32/Client.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
Client.h - Base class that provides Client
3+
Copyright (c) 2011 Adrian McEwen. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#ifndef client_h
21+
#define client_h
22+
#include "Print.h"
23+
#include "Stream.h"
24+
#include "IPAddress.h"
25+
26+
class Client : public Stream {
27+
28+
public:
29+
virtual int connect(IPAddress ip, uint16_t port) =0;
30+
virtual int connect(const char *host, uint16_t port) =0;
31+
virtual size_t write(uint8_t) =0;
32+
virtual size_t write(const uint8_t *buf, size_t size) =0;
33+
virtual int available() = 0;
34+
virtual int read() = 0;
35+
virtual int read(uint8_t *buf, size_t size) = 0;
36+
virtual int peek() = 0;
37+
virtual void flush() = 0;
38+
virtual void stop() = 0;
39+
virtual uint8_t connected() = 0;
40+
virtual operator bool() = 0;
41+
protected:
42+
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
43+
};
44+
45+
#endif

arduino/cores/esp32/IPAddress.cpp

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
IPAddress.cpp - Base class that provides IPAddress
3+
Copyright (c) 2011 Adrian McEwen. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#include <Arduino.h>
21+
#include <IPAddress.h>
22+
23+
IPAddress::IPAddress()
24+
{
25+
_address.dword = 0;
26+
}
27+
28+
IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet)
29+
{
30+
_address.bytes[0] = first_octet;
31+
_address.bytes[1] = second_octet;
32+
_address.bytes[2] = third_octet;
33+
_address.bytes[3] = fourth_octet;
34+
}
35+
36+
IPAddress::IPAddress(uint32_t address)
37+
{
38+
_address.dword = address;
39+
}
40+
41+
IPAddress::IPAddress(const uint8_t *address)
42+
{
43+
memcpy(_address.bytes, address, sizeof(_address.bytes));
44+
}
45+
46+
bool IPAddress::fromString(const char *address)
47+
{
48+
// TODO: add support for "a", "a.b", "a.b.c" formats
49+
50+
uint16_t acc = 0; // Accumulator
51+
uint8_t dots = 0;
52+
53+
while (*address)
54+
{
55+
char c = *address++;
56+
if (c >= '0' && c <= '9')
57+
{
58+
acc = acc * 10 + (c - '0');
59+
if (acc > 255) {
60+
// Value out of [0..255] range
61+
return false;
62+
}
63+
}
64+
else if (c == '.')
65+
{
66+
if (dots == 3) {
67+
// Too much dots (there must be 3 dots)
68+
return false;
69+
}
70+
_address.bytes[dots++] = acc;
71+
acc = 0;
72+
}
73+
else
74+
{
75+
// Invalid char
76+
return false;
77+
}
78+
}
79+
80+
if (dots != 3) {
81+
// Too few dots (there must be 3 dots)
82+
return false;
83+
}
84+
_address.bytes[3] = acc;
85+
return true;
86+
}
87+
88+
IPAddress& IPAddress::operator=(const uint8_t *address)
89+
{
90+
memcpy(_address.bytes, address, sizeof(_address.bytes));
91+
return *this;
92+
}
93+
94+
IPAddress& IPAddress::operator=(uint32_t address)
95+
{
96+
_address.dword = address;
97+
return *this;
98+
}
99+
100+
bool IPAddress::operator==(const uint8_t* addr) const
101+
{
102+
return memcmp(addr, _address.bytes, sizeof(_address.bytes)) == 0;
103+
}

arduino/cores/esp32/IPAddress.h

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
IPAddress.h - Base class that provides IPAddress
3+
Copyright (c) 2011 Adrian McEwen. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#ifndef IPAddress_h
21+
#define IPAddress_h
22+
23+
#include <stdint.h>
24+
#include "WString.h"
25+
26+
// A class to make it easier to handle and pass around IP addresses
27+
28+
class IPAddress {
29+
private:
30+
union {
31+
uint8_t bytes[4]; // IPv4 address
32+
uint32_t dword;
33+
} _address;
34+
35+
// Access the raw byte array containing the address. Because this returns a pointer
36+
// to the internal structure rather than a copy of the address this function should only
37+
// be used when you know that the usage of the returned uint8_t* will be transient and not
38+
// stored.
39+
uint8_t* raw_address() { return _address.bytes; };
40+
41+
public:
42+
// Constructors
43+
IPAddress();
44+
IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
45+
IPAddress(uint32_t address);
46+
IPAddress(const uint8_t *address);
47+
48+
bool fromString(const char *address);
49+
bool fromString(const String &address) { return fromString(address.c_str()); }
50+
51+
// Overloaded cast operator to allow IPAddress objects to be used where a pointer
52+
// to a four-byte uint8_t array is expected
53+
operator uint32_t() const { return _address.dword; };
54+
bool operator==(const IPAddress& addr) const { return _address.dword == addr._address.dword; };
55+
bool operator==(const uint8_t* addr) const;
56+
57+
// Overloaded index operator to allow getting and setting individual octets of the address
58+
uint8_t operator[](int index) const { return _address.bytes[index]; };
59+
uint8_t& operator[](int index) { return _address.bytes[index]; };
60+
61+
// Overloaded copy operators to allow initialisation of IPAddress objects from other types
62+
IPAddress& operator=(const uint8_t *address);
63+
IPAddress& operator=(uint32_t address);
64+
65+
friend class EthernetClass;
66+
friend class UDP;
67+
friend class Client;
68+
friend class Server;
69+
friend class DhcpClass;
70+
friend class DNSClient;
71+
};
72+
73+
#endif

0 commit comments

Comments
 (0)