Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
; A green run here does NOT mean the C64 test suites passed. conftest.py
; prints that on every invocation; do not remove it.
;
; FIVE modules here are not build-independent: test_uci_data_acc.py,
; SIX modules here are not build-independent: test_uci_data_acc.py,
; test_uci_timeout_recovery.py, test_uci_reply_valid_wait.py,
; test_uci_abort_recovery.py and test_uci_resp_read_wait.py execute
; test_uci_abort_recovery.py, test_uci_resp_read_wait.py and
; test_uci_dhcp_probe.py execute
; the shipped 6502 bytes out of
; build/c64-https.prg, so they need a BACKEND=uci build in build/. That is
; deliberate — they are still pure-logic (no VICE, no hardware, well under
Expand Down Expand Up @@ -74,6 +75,7 @@ testpaths =
tools/test_trust_store_format.py
tools/test_uci_abort_recovery.py
tools/test_uci_data_acc.py
tools/test_uci_dhcp_probe.py
tools/test_uci_reply_valid_wait.py
tools/test_uci_resp_read_wait.py
tools/test_uci_timeout_recovery.py
Expand Down
4 changes: 3 additions & 1 deletion src/net/uci-m3/net.s
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,9 @@ m3_release:

; =============================================================================
; net_dhcp_acquire — the firmware's lease via GET_IPADDR, interfaces 0..3,
; first non-zero address wins (same contract as src/net/uci/net.s).
; first non-zero address wins. Same loop as src/net/uci/net.s, but NOT the
; same reply rule: this one takes any reply of >= 4 bytes, where that one
; requires the full 12-byte record.
; Out: C=0 net_local_ip set; C=1 $83 no lease, or $82/$89.
; Clobbers: A, X, Y
; =============================================================================
Expand Down
70 changes: 53 additions & 17 deletions src/net/uci/net.s
Original file line number Diff line number Diff line change
Expand Up @@ -501,16 +501,28 @@ net_poll:
; -> push_wait -> check_err -> read 12 bytes -> drain resp
; -> drain status -> ack
;
; Interface fallback: the U64E has a single interface (index 0), but the
; C64 Ultimate has Ethernet AND WiFi — a box on WiFi returns 0.0.0.0 for
; index 0. We probe indices 0..NET_DHCP_MAX_IFACE-1 and take the first
; one with a non-zero lease. A CMD_FAILED on an out-of-range index is
; cleaned up (drain + ack) and treated like "no lease on this interface".
; Interface fallback: on both the U64E (fw 3a1ff9ff) and the C64 Ultimate,
; Ethernet registers as index 0 whether or not a cable is in, and WiFi as
; index 1 (rmii_interface.cc / wifi.cc init order), so a box on WiFi returns
; 0.0.0.0 for index 0. We probe indices 0..NET_DHCP_MAX_IFACE-1 and take the first
; one with a non-zero lease.
;
; An out-of-range index is NOT a command failure: network_target.cc answers
; it with an EMPTY reply and "82,PARAMETER(S) OUT OF RANGE" on the status
; channel, and the $DF1C ERROR bit stays clear (its only setter is a PUSH
; while not idle). So the reply is checked by length: only a full 12-byte
; record is a lease. Anything shorter (uci_resp_count != 12, an empty
; reply included) reads as "no lease here" without touching net_local_ip,
; so a buffer left over from an earlier call can never be reported as this
; call's lease. net_local_ip is also zeroed on entry. net_init already
; does that on the menu path; it is kept for a caller that skips net_init
; (none in tree today), per net_abi.inc's "zero until net_dhcp_acquire
; succeeds".
;
; The 12-byte response layout is IP(4) + Netmask(4) + Gateway(4). We copy
; the first 4 bytes into net_local_ip. If all probed interfaces yield a
; zero IP we return C=1 with net_last_error = UCI_ERR_NO_IP (or
; UCI_ERR_CMD_FAILED if the last probe failed at the command layer).
; the first 4 bytes into net_local_ip. If all probed interfaces yield no
; lease we return C=1 with net_last_error = UCI_ERR_NO_IP (or
; UCI_ERR_CMD_FAILED if the last push was rejected).
;
; Clobbers: A, X, Y
; Output: C=0 on success (net_local_ip populated), C=1 on failure
Expand All @@ -521,6 +533,11 @@ NET_DHCP_MAX_IFACE = 4 ; probe interface indices 0..3
net_dhcp_acquire:
lda #$00
sta @iface_idx ; SMC-style local, no-ZP file convention
ldx #3 ; no lease until a probe returns one: a
@clear_ip: ; failed call reads 0.0.0.0, never the last
sta net_local_ip,x ; call's address
dex
bpl @clear_ip

@next_iface:
jsr uci_wait_idle
Expand All @@ -532,8 +549,8 @@ net_dhcp_acquire:
lda #UCI_CMD_GET_IPADDR
jsr uci_put_byte

; Interface index — 0 first (only iface on U64E; Ethernet on the
; C64 Ultimate), then 1.. (C64U WiFi) until one has a lease.
; Interface index — 0 first (Ethernet), then 1.. (WiFi is 1)
; until one has a lease.
lda @iface_idx
jsr uci_put_byte

Expand All @@ -544,9 +561,10 @@ net_dhcp_acquire:
jsr uci_check_err
bcc @no_err

; Command failed for this interface (e.g. index out of range on
; single-interface firmware). Clean up response/status state so
; the next probe starts from idle, then advance.
; The push was rejected (the interface was not idle). Clean up
; response/status state so the next probe starts from idle, then
; advance. An out-of-range index does NOT land here — see the
; header.
lda #UCI_ERR_CMD_FAILED
sta net_last_error
jsr uci_drain_resp
Expand All @@ -563,7 +581,8 @@ net_dhcp_acquire:
@iface_idx: .byte 0

@no_err:
; Read the 12-byte response into uci_ipaddr_resp.
; Read the 12-byte response into uci_ipaddr_resp. An empty reply
; returns at once with uci_resp_count = 0 (the read does not wait).
lda #<uci_ipaddr_resp
sta uci_resp_dst
lda #>uci_ipaddr_resp
Expand All @@ -581,6 +600,11 @@ net_dhcp_acquire:
bcs @dhcp_wait_to
jsr uci_ack

; Anything but the full record is "no lease on this interface".
lda uci_resp_count
cmp #12
bne @no_ip

; Copy the first 4 bytes (IP) into net_local_ip.
ldx #3
@copy_ip:
Expand All @@ -597,15 +621,17 @@ net_dhcp_acquire:
ora net_local_ip+3
bne @have_ip

@no_ip:
lda #UCI_ERR_NO_IP
sta net_last_error

@advance:
inc @iface_idx
lda @iface_idx
cmp #NET_DHCP_MAX_IFACE
bcc @next_iface
sec ; every interface probed, none had a lease
bcs @probed_all ; C=1: every interface probed, none leased
jmp @next_iface ; long branch: out of BCC range
@probed_all:
rts

@have_ip:
Expand Down Expand Up @@ -767,7 +793,8 @@ net_tcp_connect:
; Response: 2 bytes = written_lo/hi (LE). If written != requested we set
; UCI_ERR_SHORT_WRITE but still return C=0 so the caller can continue
; (mirrors ip65 behaviour that treats short writes as best-effort). A
; written count of $FFFF (lwip_send's -1) is a failed send: C=1, $87.
; written count of $FFFF (lwip_send's -1), or a reply that is not exactly
; the 2-byte count, is a failed send: C=1, $87.
; =============================================================================
net_tcp_send:
sta uci_send_ptr_lo
Expand Down Expand Up @@ -913,8 +940,17 @@ net_tcp_send:
; and GREW uci_send_rem by one per round trip, so the loop ran
; ~65k SOCKET_WRITEs (~45 min) before rem wrapped to zero and it
; returned C=0. A chunk is at most 800 B, so bit 15 is never a count.
;
; A reply that is not exactly 2 bytes carries no count at all, and
; uci_write_resp would still hold the PREVIOUS chunk's: the #230(a)
; mis-parse ("21,UNKNOWN COMMAND", empty reply) is that shape. Same
; verdict as uci-m3's send: $87, C=1.
lda uci_resp_count
cmp #2
bne @sb_no_count
lda uci_write_resp+1
bpl @sb_counted
@sb_no_count:
lda #UCI_ERR_SHORT_WRITE
sta net_last_error
sec
Expand Down
Loading