Commit Graph

827 Commits

Author SHA1 Message Date
Dan Halbert ca25016b52
Merge pull request #7119 from jepler/picow-reuseaddr
Enable, use SOF_REUSEADDR
2022-10-26 15:25:50 -04:00
Jeff Epler f997d0053d
Enable, use SOF_REUSEADDR
This is the lwip no-os version of SO_REUSEADDR, which is set on all
listening sockets in the espressif port; do so here as well,
it makes running servers easier. The "address in use" error does
not occur.
2022-10-25 10:09:16 -05:00
Petr Sedlacek bd7f0e23d7 Adds support for the 42. Keebs Frood RP2040 board
https://github.com/piit79/Frood
2022-10-25 16:40:32 +02:00
Kattni Rembor 5ea8b75e17 Add STEMMA_I2C() object to Picos for Cowbells. 2022-10-24 16:27:32 -04:00
microDev b33a2b45dc
add coproc alarm 2022-10-20 18:38:20 +05:30
Dan Halbert 7015b7396e
Merge pull request #7089 from jepler/picow-gpio-number
pico w: Disentangle "TOTAL_GPIO_COUNT", it's complicated
2022-10-19 22:42:16 -04:00
Jeff Epler 576a1ac700
pico w: Disentangle "TOTAL_GPIO_COUNT", it's complicated
You might wonder how this fixes a problem with PulseIn, when the
changes aren't to any of those files! PulseIn is implemented in terms of
StateMachine, which had some assumptions about the relation between
the index of a pin object in mcu_pin_global_dict_table and its "pin
number". This was true, until some pins were removed from the
microcontroller module on Pico W.

Closes: #7078
2022-10-19 21:09:50 -05:00
Jeff Epler 8bef4282c0
pico w: implement static configuration methods in wifi.Radio 2022-10-19 20:54:53 -05:00
Dan Halbert 08e1cdb282
Merge pull request #7079 from jepler/picow-2xmss
Pico W grab bag
2022-10-19 15:03:00 -04:00
Jeff Epler 6e350a65cf
Merge pull request #7076 from bill88t/early-wifi
Implement async wifi connection on picow
2022-10-17 19:54:58 -05:00
Jeff Epler 3b7feccd9b
picow: Implement stop_station
Weirdly we have to stop the AP too (which we never started),
or cyw43_tcpip_link_status still reports that STA is connected.
As long as AP mode isn't implemented, this doesn't matter and
we can just do it.
2022-10-17 19:42:10 -05:00
Jeff Epler 57756863ef
picow: depending on memory pressure, may only be able to write 1 MSS
Foamyguy discovered that trying to send >2920 bytes at once consistently
failed. I further discovered that sometimes trying to send >1460 bytes
would fail too.  By "fail", I mean that it would take a very long time
(around 200 * 50ms) before erroneously reporting that all bytes were
written.

In my testing, this change causes larger writes to successfully
send either 2920 or 1460 bytes (possibly after doing some 50ms waits
for a previous packet to clear).

The documentation of socket.send always stated that it COULD send fewer
bytes than requested, but adafruit_httpserver assumed that the number
of requested bytes were always sent, so after this change alone,
adafruit_httpserver will still not work properly.

Closes: #7077 (albeit fixes are needed in adafruit_httpserver too)
2022-10-17 19:42:07 -05:00
Jeff Epler 861b22730e
picow: if initial write fails, write at most 1 TCP MSS of data 2022-10-17 19:28:02 -05:00
Jeff Epler 1975742d9f
picow: fix formatting numbers in lwip debug output 2022-10-17 19:28:02 -05:00
Jeff Epler 6128f4e5af
picow: add resolution of ".local" names 2022-10-17 19:28:01 -05:00
Bill Sideris 47c373e67e
Use `cyw43_tcpip_link_status` instead 2022-10-17 18:33:32 +03:00
Bill Sideris bce024f59e
Implement async wifi connection on picow 2022-10-17 18:17:14 +03:00
Jeff Epler 47541afc7c
picow: ask at a lower level if the interface is up
Closes: #7072

```
Adafruit CircuitPython 8.0.0-beta.2-9-g5192082e64-dirty on 2022-10-17; Raspberry Pi Pico W with rp2040
>>> import wifi
>>> print(wifi.radio.ipv4_address)
None
>>> import os
>>> wifi.radio.connect(os.getenv('WIFI_SSID'), os.getenv('WIFI_PASSWORD'))
>>> print(wifi.radio.ipv4_address)
10.0.2.94
```
2022-10-17 10:08:50 -05:00
Jeff Epler d4b1d4d430
Fix GPIO state when initializing CYW43 pin
Closes: #7063
2022-10-15 13:10:22 -05:00
Dan Halbert 062d63ee3a
Merge pull request #7050 from jepler/picow-wirelsess-off-in-deep-sleep
picow: Turn off wifi co-processor regulator when entering deep sleep
2022-10-14 08:17:16 -04:00
Jeff Epler 3b3fe44174
implement hashlib for picow 2022-10-13 20:42:50 -05:00
Jeff Epler 0c5fd55c16
picow: Turn off wifi co-processor regulator when entering deep sleep
This reduces power consumption during true deep sleep.

In my measurements with ppk2 and a program that _irrevocably_ entered
deep sleep (no time alarm or pin alarm), power usage as measured on a
ppk2 decreased from ~10mA to ~1mA.
2022-10-13 20:10:10 -05:00
Georg Bøe e768b9ebb3 Return correct errno 2022-10-13 21:00:51 +02:00
Jeff Epler 874ddd67bf
Pico W: ssl: factor out do_handshake 2022-10-12 11:38:30 -05:00
Jeff Epler 1641a7c002
Pico W: ssl: Correctly handle errors in send/recv
The prefixed versions raise Python exceptions, the un-prefixed return
negative error values. We don't want to raise an exception from here,
it leaves the SSL stack in an undefined state.
2022-10-12 11:38:30 -05:00
Jeff Epler 7c849fdadb
Pico W: ssl: Raise MemoryError for allocation errors 2022-10-12 11:38:29 -05:00
Jeff Epler b1f7940297
Pico W: Correctly treat empty cadata= as disabling host checking 2022-10-12 11:38:29 -05:00
Jeff Epler ca9523b814
Pico w: socket: Correctly return negative error code from recv_into 2022-10-12 11:38:29 -05:00
Jeff Epler 62cbd3bcd8
Pico w: socket: correctly track sockets generated by accept() 2022-10-12 11:38:26 -05:00
Dan Halbert e19abef57e forgot to add these! 2022-10-11 13:12:43 -04:00
Dan Halbert 851f8a188d Merge remote-tracking branch 'adafruit/main' into HEAD 2022-10-11 12:21:59 -04:00
Jeff Epler 0c8b261ec9
picow: Add support of self-signed certificates.
## Testing self-signed certificates and `load_verify_locations`

Obtain the badssl "self-signed" certificate in the correct form:

```sh
openssl s_client -servername self-signed.badssl.com -connect untrusted-root.badssl.com:443 < /dev/null | openssl x509 > self-signed.pem
```

Copy it and the script to CIRCUITPY:
```python
import os
import wifi
import socketpool
import ssl
import adafruit_requests

TEXT_URL = "https://self-signed.badssl.com/"
if not wifi.radio.ipv4_address:
    wifi.radio.connect(os.getenv('WIFI_SSID'), os.getenv('WIFI_PASSWORD'))

pool = socketpool.SocketPool(wifi.radio)
context = ssl.create_default_context()
requests = adafruit_requests.Session(pool, context)

print(f"Fetching from {TEXT_URL} without certificate (should fail)")
try:
    response = requests.get(TEXT_URL)
except Exception as e:
    print(f"Failed: {e}")
else:
    print(f"{response.status_code=}, should have failed with exception")

print("Loading server certificate")
with open("/self-signed.pem", "rb") as certfile:
    context.load_verify_locations(cadata=certfile.read())
requests = adafruit_requests.Session(pool, context)

print(f"Fetching from {TEXT_URL} with certificate (should succeed)")
try:
    response = requests.get(TEXT_URL)
except Exception as e:
    print(f"Unexpected exception: {e}")
else:
    print(f"{response.status_code=}, should be 200 OK")
```
2022-10-10 15:53:56 -05:00
Jeff Epler c98174eea5
Add support for SSL client certificate (load_cert_chain)
Tested with badssl.com:

 1. Get client certificates from https://badssl.com/download/
 2. Convert public portion with `openssl x509 -in badssl.com-client.pem -out CIRCUITPY/cert.pem`
 3. Convert private portion with `openssl rsa -in badssl.com-client.pem -out CIRCUITPY/privkey.pem` and the password `badssl.com`
 4. Put wifi settings in CIRCUITPY/.env
 5. Run the below Python script:

```py
import os
import wifi
import socketpool
import ssl
import adafruit_requests

TEXT_URL = "https://client.badssl.com/"
wifi.radio.connect(os.getenv('WIFI_SSID'), os.getenv('WIFI_PASSWORD'))

pool = socketpool.SocketPool(wifi.radio)
context = ssl.create_default_context()
requests = adafruit_requests.Session(pool, context)

print(f"Fetching from {TEXT_URL} without certificate (should fail)")
response = requests.get(TEXT_URL)
print(f"{response.status_code=}, should be 400 Bad Request")
input("hit enter to continue\r")

print("Loading client certificate")
context.load_cert_chain("/cert.pem", "privkey.pem")
requests = adafruit_requests.Session(pool, context)

print(f"Fetching from {TEXT_URL} with certificate (should succeed)")
response = requests.get(TEXT_URL)
print(f"{response.status_code=}, should be 200 OK")
```
2022-10-10 15:10:53 -05:00
Dan Halbert de95463deb
Merge pull request #7023 from dhalbert/wifi-scanning-fixes
update esp-idf; allow start/stop channels in wifi scanning
2022-10-10 13:54:54 -04:00
Dan Halbert 747dc7746d handle scan channel bounds but note they do nothing for RP2040 CYW43 2022-10-07 16:22:17 -04:00
Jeff Epler f882571366
pico w: pins improvements
Closes: #7017

 * Remove the 'GP23' alias for CYW1
 * Remove the 'CYW0' alias for CYW0
 * Switch VBUS_SENSE to CYW2, remove 'GP24' alias

Code that wants to use SMPS_MODE, VBUS_SENSE and LED while being
portable to the W and non-W variants should use those names, not alias
names.

 * Remove A3 / VOLTAGE_MONITOR

Right now this cannot be used. The ability to check the voltage monitor
should be added back in some fashion in the future.
2022-10-07 08:48:36 -05:00
Dan Halbert 041885da1b
Merge pull request #7011 from jepler/pico-w-resize-circuitpy-again
switch flash split to leave 512kB for CIRCUITPY
2022-10-07 08:32:18 -04:00
Neradoc 3a6382d1ea cyw43.CywPin should be the class, not a string 2022-10-07 02:11:05 +02:00
Jeff Epler 644d293641
Fix CIRCUITPY drive offset in flash correctly, accounting for NVM
.. and fix nvm to read/right the correct area.

.. putting a comment in link.ld to explain it all

Closes #7012
2022-10-06 12:39:46 -05:00
Jeff Epler 07cd2ff065
restore 4kB gap pending resolution of #7011 2022-10-06 11:20:48 -05:00
Jeff Epler 6e2c24083a
switch flash split to leave 512kB for CIRCUITPY 2022-10-06 10:12:22 -05:00
Jeff Epler 2dc283f578
close underlying socket object when closing ssl socket 2022-10-05 15:10:14 -05:00
Jeff Epler 4a9389d347
remove debug message 2022-10-05 14:57:04 -05:00
Jeff Epler 14f2309b6f
Enable more key exchange methods
This is intended (but not entirely verified) to match our esp32 builds.
It does fix accessing https://circuitpython.org, which failed before with
"MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE".

It still doesn't work on a personal website of mine with valid letsencrypt
certificate but I haven't verified whether it works on esp32s2 with CP.
That site only allows TLS 1.3, while this mbedtls only supports up to
1.2.
The version of mbedtls we adopted based on micropython's use has no
TLS 1.3 support, but the one in espressif esp-idf does.
2022-10-05 14:56:27 -05:00
Jeff Epler fabfdcf6fe
More ssl work 2022-10-05 14:56:26 -05:00
Jeff Epler 944d388158
copy esp_crt_bundle.c from esp-idf@d51f7d8821 2022-10-05 14:56:26 -05:00
Jeff Epler dcb650c513 pico w: add ssl module
Note: at this time, the ssl module on pico_w never verifies the server
certificate. This means it does not actually provide a higher security
level than regular socket / http protocols.
2022-10-05 13:12:43 -04:00
Jeff Epler 2bd50673b6
Finish adapting flash storage size
Before this, CIRCUITPY would start at 1MB anyway. This appeared to work
only because I hadn't checked the actual size of the CIRCUITPY drive,
and because until now the flash hadn't actually crossed that 1MB
boundary into CIRCUITPY storage.

WARNING: on pico_w, upgrading/downgrading CircuitPython across this commit
boundary will erase the CIRCUITPY filesystem. After this commit,
switching between pico and pico_w firmware will erase the CIRCUITPY
filesystem
2022-10-05 10:02:38 -05:00
Dan Halbert ad79f595a5
Merge pull request #6974 from MicroDev1/patch
Couple Minor Fixes
2022-10-01 13:12:01 -04:00
Dan Halbert 7bb90dbf45 remove redundant port/*/.gitignore; cleanup others 2022-10-01 11:52:36 -04:00