let dhcp & dns share the same buffer for building outbound packets in (since they don't call each other no chance of overwritting each others data)

git-svn-id: http://svn.code.sf.net/p/netboot65/code@83 93682198-c243-4bdb-bd91-e943c89aac3b
This commit is contained in:
jonnosan 2009-04-05 06:56:11 +00:00
parent 5ad3240531
commit e2a6916c57
3 changed files with 52 additions and 51 deletions

View File

@ -26,6 +26,7 @@ ETHOBJS= \
dhcp.o \ dhcp.o \
dns.o \ dns.o \
dottedquad.o \ dottedquad.o \
output_buffer.o\
tftp.o \ tftp.o \
function_dispatcher.o \ function_dispatcher.o \

View File

@ -37,6 +37,8 @@ MAX_DHCP_MESSAGES_SENT=12 ;timeout after sending 12 messages will be about 1
.importzp udp_data .importzp udp_data
.import output_buffer
.import udp_send_dest .import udp_send_dest
.import udp_send_src_port .import udp_send_src_port
.import udp_send_dest_port .import udp_send_dest_port
@ -48,7 +50,7 @@ MAX_DHCP_MESSAGES_SENT=12 ;timeout after sending 12 messages will be about 1
; dhcp packet offsets ; dhcp packet offsets
dhcp_inp = udp_inp + udp_data dhcp_inp = udp_inp + udp_data
dhcp_outp: .res 256
dhcp_op = 0 dhcp_op = 0
dhcp_htype = 1 dhcp_htype = 1
dhcp_hlen = 2 dhcp_hlen = 2
@ -200,57 +202,57 @@ dhcp_init:
dhcp_create_request_msg: dhcp_create_request_msg:
lda #BOOTREQUEST lda #BOOTREQUEST
sta dhcp_outp+dhcp_op sta output_buffer+dhcp_op
lda #1 ;htype 1 = "10 MB ethernet" lda #1 ;htype 1 = "10 MB ethernet"
sta dhcp_outp+dhcp_htype sta output_buffer+dhcp_htype
lda #6 ;ethernet MACs are 6 bytes lda #6 ;ethernet MACs are 6 bytes
sta dhcp_outp+dhcp_hlen sta output_buffer+dhcp_hlen
lda #0 ;hops = 0 lda #0 ;hops = 0
sta dhcp_outp+dhcp_hops sta output_buffer+dhcp_hops
ldx #3 ;set xid to be "1234" ldx #3 ;set xid to be "1234"
clc clc
: txa : txa
adc #01 adc #01
sta dhcp_outp+dhcp_xid,x sta output_buffer+dhcp_xid,x
dex dex
bpl :- bpl :-
lda #0 ;secs =00 lda #0 ;secs =00
sta dhcp_outp+dhcp_secs sta output_buffer+dhcp_secs
sta dhcp_outp+dhcp_secs+1 sta output_buffer+dhcp_secs+1
;initially turn off all flags ;initially turn off all flags
sta dhcp_outp+dhcp_flags sta output_buffer+dhcp_flags
sta dhcp_outp+dhcp_flags+1 sta output_buffer+dhcp_flags+1
ldx #$0F ;set ciaddr to 0.0.0.0 ldx #$0F ;set ciaddr to 0.0.0.0
;set yiaddr to 0.0.0.0 ;set yiaddr to 0.0.0.0
;set siaddr to 0.0.0.0 ;set siaddr to 0.0.0.0
;set giaddr to 0.0.0.0 ;set giaddr to 0.0.0.0
: sta dhcp_outp+dhcp_ciaddr,x : sta output_buffer+dhcp_ciaddr,x
dex dex
bpl :- bpl :-
ldx #5 ;set chaddr to mac ldx #5 ;set chaddr to mac
: lda cfg_mac,x : lda cfg_mac,x
sta dhcp_outp+dhcp_chaddr,x sta output_buffer+dhcp_chaddr,x
dex dex
bpl :- bpl :-
ldx #192 ;set sname & file both to null ldx #192 ;set sname & file both to null
lda #0 lda #0
: sta dhcp_outp+dhcp_sname-1,x : sta output_buffer+dhcp_sname-1,x
dex dex
bne :- bne :-
lda #$63 ;copy the magic cookie lda #$63 ;copy the magic cookie
sta dhcp_outp+dhcp_cookie+0 sta output_buffer+dhcp_cookie+0
lda #$82 lda #$82
sta dhcp_outp+dhcp_cookie+1 sta output_buffer+dhcp_cookie+1
lda #$53 lda #$53
sta dhcp_outp+dhcp_cookie+2 sta output_buffer+dhcp_cookie+2
lda #$63 lda #$63
sta dhcp_outp+dhcp_cookie+3 sta output_buffer+dhcp_cookie+3
ldax #dhcp_client_port ; set source port ldax #dhcp_client_port ; set source port
stax udp_send_src_port stax udp_send_src_port
@ -267,16 +269,16 @@ send_dhcpdiscover:
jsr dhcp_create_request_msg jsr dhcp_create_request_msg
lda #$80 ;broadcast flag =1, all other bits 0 lda #$80 ;broadcast flag =1, all other bits 0
sta dhcp_outp+dhcp_flags sta output_buffer+dhcp_flags
lda #53 ;option 53 - DHCP message type lda #53 ;option 53 - DHCP message type
sta dhcp_outp+dhcp_options+0 sta output_buffer+dhcp_options+0
lda #1 ;option length is 1 lda #1 ;option length is 1
sta dhcp_outp+dhcp_options+1 sta output_buffer+dhcp_options+1
lda #DHCPDISCOVER lda #DHCPDISCOVER
sta dhcp_outp+dhcp_options+2 sta output_buffer+dhcp_options+2
lda #$FF ;option FF = end of options lda #$FF ;option FF = end of options
sta dhcp_outp+dhcp_options+3 sta output_buffer+dhcp_options+3
ldx #3 ; set destination address ldx #3 ; set destination address
lda #$FF ; des = 255.255.255.255 (broadcast) lda #$FF ; des = 255.255.255.255 (broadcast)
@ -286,7 +288,7 @@ send_dhcpdiscover:
ldax #dhcp_options+4 ldax #dhcp_options+4
stax udp_send_len stax udp_send_len
ldax #dhcp_outp ldax #output_buffer
jsr udp_send jsr udp_send
bcc :+ bcc :+
rts rts
@ -417,42 +419,42 @@ dhcp_in:
send_dhcprequest: send_dhcprequest:
jsr dhcp_create_request_msg jsr dhcp_create_request_msg
lda #53 ;option 53 - DHCP message type lda #53 ;option 53 - DHCP message type
sta dhcp_outp+dhcp_options+0 sta output_buffer+dhcp_options+0
lda #1 ;option length is 1 lda #1 ;option length is 1
sta dhcp_outp+dhcp_options+1 sta output_buffer+dhcp_options+1
lda #DHCPREQUEST lda #DHCPREQUEST
sta dhcp_outp+dhcp_options+2 sta output_buffer+dhcp_options+2
lda #50 ;option 50 - requested IP address lda #50 ;option 50 - requested IP address
sta dhcp_outp+dhcp_options+3 sta output_buffer+dhcp_options+3
ldx #4 ;option length is 4 ldx #4 ;option length is 4
stx dhcp_outp+dhcp_options+4 stx output_buffer+dhcp_options+4
dex dex
: lda cfg_ip,x : lda cfg_ip,x
sta dhcp_outp+dhcp_options+5,x sta output_buffer+dhcp_options+5,x
dex dex
bpl :- bpl :-
lda #54 ;option 54 - DHCP server lda #54 ;option 54 - DHCP server
sta dhcp_outp+dhcp_options+9 sta output_buffer+dhcp_options+9
ldx #4 ;option length is 4 ldx #4 ;option length is 4
stx dhcp_outp+dhcp_options+10 stx output_buffer+dhcp_options+10
dex dex
: lda dhcp_server,x : lda dhcp_server,x
sta dhcp_outp+dhcp_options+11,x sta output_buffer+dhcp_options+11,x
sta udp_send_dest,x sta udp_send_dest,x
dex dex
bpl :- bpl :-
lda #$FF ;option FF = end of options lda #$FF ;option FF = end of options
sta dhcp_outp+dhcp_options+17 sta output_buffer+dhcp_options+17
ldax #dhcp_options+18 ldax #dhcp_options+18
stax udp_send_len stax udp_send_len
ldax #dhcp_outp ldax #output_buffer
jsr udp_send jsr udp_send
bcs :+ ;if we didn't send the message we probably need to wait for an ARP reply to come back. bcs :+ ;if we didn't send the message we probably need to wait for an ARP reply to come back.
lda #dhcp_bound ;technically, we should wait till we get a DHCPACK message. but we'll assume success lda #dhcp_bound ;technically, we should wait till we get a DHCPACK message. but we'll assume success

View File

@ -15,7 +15,6 @@
.import parse_dotted_quad .import parse_dotted_quad
.import dotted_quad_value .import dotted_quad_value
.import ip65_process .import ip65_process
.import udp_add_listener .import udp_add_listener
@ -25,7 +24,7 @@
.import udp_send .import udp_send
.import udp_inp .import udp_inp
.import output_buffer
.importzp udp_data .importzp udp_data
.import udp_send_dest .import udp_send_dest
@ -43,7 +42,6 @@
; dns packet offsets ; dns packet offsets
dns_inp = udp_inp + udp_data dns_inp = udp_inp + udp_data
dns_outp: .res 220
dns_id = 0 dns_id = 0
dns_flags=2 dns_flags=2
dns_qdcount=4 dns_qdcount=4
@ -265,21 +263,21 @@ send_dns_query:
inx inx
adc #0 adc #0
stax dns_msg_id stax dns_msg_id
stax dns_outp+dns_id stax output_buffer+dns_id
ldax #$0001 ;QR =0 (query), opcode=0 (query), AA=0, TC=0,RD=1,RA=0,Z=0,RCODE=0 ldax #$0001 ;QR =0 (query), opcode=0 (query), AA=0, TC=0,RD=1,RA=0,Z=0,RCODE=0
stax dns_outp+dns_flags stax output_buffer+dns_flags
ldax #$0100 ;we ask 1 question ldax #$0100 ;we ask 1 question
stax dns_outp+dns_qdcount stax output_buffer+dns_qdcount
ldax #$0000 ldax #$0000
stax dns_outp+dns_ancount ;we send no answers stax output_buffer+dns_ancount ;we send no answers
stax dns_outp+dns_nscount ;we send no name servers stax output_buffer+dns_nscount ;we send no name servers
stax dns_outp+dns_arcount ;we send no authorative records stax output_buffer+dns_arcount ;we send no authorative records
ldx #0 ldx #0
: :
lda dns_packed_hostname,x lda dns_packed_hostname,x
sta dns_outp+dns_qname,x sta output_buffer+dns_qname,x
inx inx
bpl @hostname_still_ok bpl @hostname_still_ok
lda #NB65_ERROR_INPUT_TOO_LARGE lda #NB65_ERROR_INPUT_TOO_LARGE
@ -290,11 +288,11 @@ send_dns_query:
bne :- ;keep looping until we have a zero byte. bne :- ;keep looping until we have a zero byte.
lda #0 lda #0
sta dns_outp+dns_qname,x ;high byte of QTYPE=1 (A) sta output_buffer+dns_qname,x ;high byte of QTYPE=1 (A)
sta dns_outp+dns_qname+2,x ;high byte of QLASS=1 (IN) sta output_buffer+dns_qname+2,x ;high byte of QLASS=1 (IN)
lda #1 lda #1
sta dns_outp+dns_qname+1,x ;low byte of QTYPE=1 (A) sta output_buffer+dns_qname+1,x ;low byte of QTYPE=1 (A)
sta dns_outp+dns_qname+3,x ;low byte of QLASS=1 (IN) sta output_buffer+dns_qname+3,x ;low byte of QLASS=1 (IN)
txa txa
clc clc
@ -314,7 +312,7 @@ send_dns_query:
ldax #dns_server_port ; set destination port ldax #dns_server_port ; set destination port
stax udp_send_dest_port stax udp_send_dest_port
ldax #dns_outp ldax #output_buffer
jsr udp_send jsr udp_send
bcs @error_on_send bcs @error_on_send
lda #dns_query_sent lda #dns_query_sent