ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
wifi_hal_ip.c File Reference

The NetX Duo DHCP provider the ra8_wifi facade calls for an address. More...

#include <stdint.h>
#include "nx_api.h"
#include "nx_ether_driver_c6.h"
#include "nxd_dhcp_client.h"
#include "ra8_c6link.h"
#include "ra8_err.h"
#include "ra8_wifi.h"
#include "tx_api.h"
#include "wifi_hal_join.h"
Include dependency graph for wifi_hal_ip.c:

Go to the source code of this file.

Enumerations

enum  wifi_hal_net_size_t : uint32_t {
  k_wifi_hal_pkt_payload = 1568U ,
  k_wifi_hal_pool_bytes = 40960U ,
  k_wifi_hal_ip_stack = 2048U ,
  k_wifi_hal_arp_bytes = 1040U ,
  k_wifi_hal_ip_prio = 3U
}
 Static sizing for the NetX Duo objects this application owns. More...

Functions

static UINT priv_net_create_ip (void)
static UINT priv_net_dhcp (ra8_wifi_lease_t *out)
ra8_err_t wifi_hal_ip_bind (void *ip_ctx, const ra8_wifi_mac_t *mac, ra8_wifi_lease_t *out)
 The application's IP provider: a NetX Duo DHCP client to a lease.

Variables

static NX_PACKET_POOL s_pool
 NetX packet pool control block.
static uint8_t s_pool_mem [k_wifi_hal_pool_bytes]
 Packet-pool backing store.
static NX_IP s_ip
 NetX IP instance driven over the C6 link.
static uint8_t s_ip_stack [k_wifi_hal_ip_stack]
 NetX IP helper-thread stack.
static uint8_t s_arp_cache [k_wifi_hal_arp_bytes]
 ARP cache backing store.
static NX_DHCP s_dhcp
 NetX DHCP client control block.
static CHAR s_pool_name [] = "wifi_hal_pool"
 Mutable pool name (NetX takes CHAR*).
static CHAR s_ip_name [] = "wifi_hal_ip"
 Mutable IP-instance name.
static CHAR s_dhcp_name [] = "wifi_hal_dhcp"
 Mutable DHCP-client name.

Detailed Description

The NetX Duo DHCP provider the ra8_wifi facade calls for an address.

Tag
[Ring 6 / APP] {World: S}

Implements wifi_hal_ip_bind, the ra8_wifi_ip_bind_fn. Once ra8_wifi reports the station associated, the facade calls this to turn the L2 link into an IP address: it binds nx_ether_driver_c6 to the open C6 link, creates the NetX Duo packet pool and IP instance, enables ARP / UDP / ICMP, and runs the vendored DHCP client to a bound lease. The whole IP stack runs on the RA8; the C6 is a pure L2 bridge.

This is the one piece the facade cannot own without dragging NetX Duo into every consumer, so it lives with the application by design. The heavy NetX objects are file-scope statics because this image has no heap (NASA Rule 3).

Since
0.1.0

Definition in file wifi_hal_ip.c.

Enumeration Type Documentation

◆ wifi_hal_net_size_t

enum wifi_hal_net_size_t : uint32_t

Static sizing for the NetX Duo objects this application owns.

Sized for full Ethernet frames plus the DHCP working set, with a comfortable packet count so a DHCP retransmit never starves ARP.

Invariant
k_wifi_hal_pkt_payload is at least a full Ethernet frame plus the driver's two-octet alignment slide.
k_wifi_hal_pool_bytes holds several k_wifi_hal_pkt_payload packets.
Example:
static uint8_t pool[k_wifi_hal_pool_bytes];
@ k_wifi_hal_pool_bytes
Packet-pool backing store, in octets.
Definition wifi_hal_ip.c:55
See also
wifi_hal_ip_bind
Since
0.1.0
Enumerator
k_wifi_hal_pkt_payload 

Per-packet payload, in octets.

k_wifi_hal_pool_bytes 

Packet-pool backing store, in octets.

k_wifi_hal_ip_stack 

NetX IP helper-thread stack, in octets.

k_wifi_hal_arp_bytes 

ARP cache backing store, in octets.

k_wifi_hal_ip_prio 

NetX IP helper-thread priority.

Definition at line 53 of file wifi_hal_ip.c.

Function Documentation

◆ priv_net_create_ip()

UINT priv_net_create_ip ( void )
static

◆ priv_net_dhcp()

◆ wifi_hal_ip_bind()

ra8_err_t wifi_hal_ip_bind ( void * ip_ctx,
const ra8_wifi_mac_t * mac,
ra8_wifi_lease_t * out )
nodiscard

The application's IP provider: a NetX Duo DHCP client to a lease.

The ra8_wifi_ip_bind_fn ra8_wifi_wait_ip calls. It binds the wireless NetX link driver to the open C6 link, creates the packet pool and IP instance, runs the vendored DHCP client to a bound lease, and copies the lease out. From here NetX Duo owns the wire.

Parameters
[in]ip_ctxThe open ra8_c6link_t* this application passed as ra8_wifi_cfg::ip_ctx; must be non-null.
[in]macThe station MAC the IP stack must adopt; must be non-null.
[out]outLease to fill; must be non-null.
Returns
ra8_err_t Error code.
Return values
k_ra8_okA lease was obtained and copied into out.
k_ra8_err_null_ptrAn argument was null.
k_ra8_err_not_initializedThe NetX objects could not be created.
k_ra8_err_timeoutDHCP did not bind within k_wifi_hal_dhcp_wait_ms.
Precondition
The station is associated (ra8_wifi_connect has succeeded).
ip_ctx is the same open link the facade drives.
Postcondition
On success out->bound is implied by a non-zero out->ip.
On failure out is cleared.
Note
Runs once, on the worker thread, inside ra8_wifi_wait_ip.
Warning
Blocks up to k_wifi_hal_dhcp_wait_ms waiting for the lease.
Example:
cfg.ip_bind = wifi_hal_ip_bind;
cfg.ip_ctx = &s_link;
static ra8_c6link_t s_link
Definition c6_cam_app.c:44
ra8_err_t wifi_hal_ip_bind(void *ip_ctx, const ra8_wifi_mac_t *mac, ra8_wifi_lease_t *out)
The application's IP provider: a NetX Duo DHCP client to a lease.
See also
ra8_wifi_wait_ip
Since
0.1.0

Definition at line 147 of file wifi_hal_ip.c.

References ra8_wifi_lease::bound, ra8_wifi_lease::ip, k_ra8_err_not_initialized, k_ra8_err_null_ptr, k_ra8_err_timeout, k_ra8_ok, nx_ether_driver_c6_bind(), nx_ether_driver_c6_set_mac(), ra8_wifi_mac::octet, priv_net_create_ip(), and priv_net_dhcp().

Referenced by wifi_hal_make_cfg().

Variable Documentation

◆ s_arp_cache

uint8_t s_arp_cache[k_wifi_hal_arp_bytes]
static

ARP cache backing store.

Since
0.1.0

Definition at line 70 of file wifi_hal_ip.c.

◆ s_dhcp

NX_DHCP s_dhcp
static

NetX DHCP client control block.

Since
0.1.0

Definition at line 72 of file wifi_hal_ip.c.

◆ s_dhcp_name

CHAR s_dhcp_name[] = "wifi_hal_dhcp"
static

Mutable DHCP-client name.

Since
0.1.0

Definition at line 78 of file wifi_hal_ip.c.

◆ s_ip

NX_IP s_ip
static

NetX IP instance driven over the C6 link.

Since
0.1.0

Definition at line 66 of file wifi_hal_ip.c.

◆ s_ip_name

CHAR s_ip_name[] = "wifi_hal_ip"
static

Mutable IP-instance name.

Since
0.1.0

Definition at line 76 of file wifi_hal_ip.c.

◆ s_ip_stack

uint8_t s_ip_stack[k_wifi_hal_ip_stack]
static

NetX IP helper-thread stack.

Since
0.1.0

Definition at line 68 of file wifi_hal_ip.c.

◆ s_pool

NX_PACKET_POOL s_pool
static

NetX packet pool control block.

Since
0.1.0

Definition at line 62 of file wifi_hal_ip.c.

◆ s_pool_mem

uint8_t s_pool_mem[k_wifi_hal_pool_bytes]
static

Packet-pool backing store.

Since
0.1.0

Definition at line 64 of file wifi_hal_ip.c.

◆ s_pool_name

CHAR s_pool_name[] = "wifi_hal_pool"
static

Mutable pool name (NetX takes CHAR*).

Since
0.1.0

Definition at line 74 of file wifi_hal_ip.c.