10000 Hook in pico_rand, use ioctl to set ipv6 allmulti · dyno-project/arduino-pico@b943c05 · GitHub
[go: up one dir, main page]

Skip to content

Commit b943c05

Browse files
Hook in pico_rand, use ioctl to set ipv6 allmulti
RP2040.hwrand() uses the new SDK API. Hook it into LWIP, too. Use exported cyw43_ioctl to set allmulti=true to avoid need for custom repo for ipv6 support
1 parent 3326f0f commit b943c05

File tree

6 files changed

+13
-20
lines changed

6 files changed

+13
-20
lines changed

cores/rp2040/RP2040Support.h

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <hardware/structs/rosc.h>
2828
#include <hardware/structs/systick.h>
2929
#include <pico/multicore.h>
30+
#include <pico/rand.h>
3031
#include <pico/util/queue.h>
3132
#include "CoreMutex.h"
3233
#include "ccount.pio.h"
@@ -336,26 +337,8 @@ class RP2040 {
336337
_MFIFO fifo;
337338

338339

339-
// TODO - Not so great HW random generator. 32-bits wide. Cryptographers somewhere are crying
340340
uint32_t hwrand32() {
341-
// Try and whiten the HW ROSC bit
342-
uint32_t r = 0;
343-
for (int k = 0; k < 32; k++) {
344-
unsigned long int b;
345-
do {
346-
b = rosc_hw->randombit & 1;
347-
if (b != (rosc_hw->randombit & 1)) {
348-
break;
349-
}
350-
} while (true);
351-
r <<= 1;
352-
r |= b;
353-
}
354-
// Stir using the cycle count LSBs. In any WiFi use case this will be a random # since the connection time is not cycle-accurate
355-
uint64_t rr = (((uint64_t)~r) << 32LL) | r;
356-
rr >>= rp2040.getCycleCount() & 32LL;
357-
358-
return (uint32_t)rr;
341+
return get_rand_32();
359342
}
360343

361344
private:

include/lwipopts.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ extern void interrupts();
1313
#define SYS_ARCH_PROTECT(lev) noInterrupts
1414
#define SYS_ARCH_UNPROTECT(lev) interrupts
1515

16+
extern unsigned long get_rand_32(void);
17+
#define LWIP_RAND() get_rand_32()
18+
1619
// Common settings used in most of the pico_w examples
1720
// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details)
1821

lib/libpico-ipv6.a

-248 Bytes
Binary file not shown.

lib/libpico.a

-180 Bytes
Binary file not shown.

libraries/lwIP_CYW43/src/utility/CYW43shim.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ bool CYW43::begin(const uint8_t* address, netif* netif) {
6565

6666
// Not currently possible to hook up igmp_mac_filter and mld_mac_filter
6767
// TODO: implement igmp_mac_filter and mld_mac_filter
68-
// cyw43_set_allmulti(_self, true);
68+
#if LWIP_IPV6
69+
// Implement cyw43_set_allmulti(_self, true) using exposed ioctl call
70+
uint8_t allmulti_true[] = { 'a', 'l', 'l', 'm', 'u', 'l', 't', 'i', 0, 1, 0, 0, 0 };
71+
cyw43_ioctl(&cyw43_state, CYW43_IOCTL_SET_VAR, sizeof allmulti_true, allmulti_true, CYW43_ITF_STA);
72+
#endif
6973

7074
if (cyw43_arch_wifi_connect_timeout_ms(_ssid, _password, authmode, _timeout)) {
7175
return false;

tools/libpico/lwipopts.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ extern void interrupts();
1313
#define SYS_ARCH_PROTECT(lev) noInterrupts
1414
#define SYS_ARCH_UNPROTECT(lev) interrupts
1515

16+
extern unsigned long get_rand_32(void);
17+
#define LWIP_RAND() get_rand_32()
18+
1619
// Common settings used in most of the pico_w examples
1720
// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details)
1821

0 commit comments

Comments
 (0)
0