1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2024-07-05 04:28:57 +00:00

Update WIP

This commit is contained in:
David Schmenk 2015-01-25 13:10:10 -08:00
parent 9455d23add
commit 90c1a459d7
2 changed files with 86 additions and 26 deletions

View File

@ -40,6 +40,17 @@ struc t_ip
byte[IP_SIZE] ip_dst
byte[] ip_options
end
const IP_PROTO_ICMP = 1
const IP_PROTO_UDP = 2
const IP_PROTO_TCP = 3
//
// ICMP message format
//
struc t_icmp
byte icmp_type
byte icmp_code
word icmp_checksum
end
//
// ARP packet
//
@ -211,7 +222,19 @@ end
//
// Write IP datagram
//
export def writeIP(dst, proto, packet)
export def writeIP(dstip, proto, packet, len)
byte[t_ip] iphdr
iphdr.ip_vers_hlen = 0
iphdr.ip_service = 0
iphdr:ip_length = len
iphdr:ip_id = 0
iphdr:ip_flags_fragofst = 0
iphdr.ip_ttl = 1
iphdr.ip_proto = proto
iphdr:ip_checksum = 0
memcpy(@iphdr.ip_src, @localip, IP_SIZE)
memcpy(@ip_dst, @dstip, IP_SIZE)
end
//
// Read IP datagram
@ -222,38 +245,46 @@ end
// Service incoming packets
//
def serviceIP
word pkt, len
word pkt, iphdr, ipopt, len
len = recvEther
if len
len = len - t_ehdr
when readEther(t_ehdr)=>ehdr_payload
is PAYLOAD_IP
readEther(len)
break
is PAYLOAD_ARP
pkt = readEther(len)
if pkt=>arp_op == ARP_REPLY
//
// Fill in ARP cache
//
memcpy(@remoteha, @pkt=>arp_senderha, 10) // copy ha and ip
putha(pkt+arp_senderha);putc('=');putip(pkt+arp_senderip);putln
elsif pkt=>arp_op == ARP_REQST
//
// Is this a request for me?
//
if pkt=>arp_targip:0 == localip:0 and pkt=>arp_targip:2 == localip:2
memcpy(@dstMAC, pkt=>arp_senderha, MAC_SIZE)
memcpy(@remoteha, @pkt=>arp_senderha, 10) // copy ha and ip
opARP = ARP_REPLY
writeEther(@ARP, t_earp)
putha(pkt+arp_senderha);putc('=');putip(pkt+arp_senderip);putln
fin
else
dumparp(pkt)
fin
when pkt=>arp_op
is ARP_REPLY
//
// Fill in ARP cache
//
memcpy(@remoteha, @pkt=>arp_senderha, 10) // copy ha and ip
putha(pkt+arp_senderha);putc('=');putip(pkt+arp_senderip);putln
break
is ARP_REQST
//
// Is this a request for me?
//
if pkt=>arp_targip:0 == localip:0 and pkt=>arp_targip:2 == localip:2
memcpy(@dstMAC, pkt=>arp_senderha, MAC_SIZE)
memcpy(@remoteha, @pkt=>arp_senderha, 10) // copy ha and ip
opARP = ARP_REPLY
writeEther(@ARP, t_earp)
putha(pkt+arp_senderha);putc('=');putip(pkt+arp_senderip);putln
fin
break
otherwise
dumparp(pkt)
wend
break
is PAYLOAD_IP
len = len - t_ip
iphdr = readEther(t_ip)
if iphdr=>ip_length > t_ip
len = len - (iphdr=>ip_length - t_ip)
ipopt = readEther(iphdr=>ip_length - t_ip)
fin
break
otherwise
pkt = readEther(len)
dumpehdr(pkt - t_ehdr)
@ -261,11 +292,15 @@ def serviceIP
wend
fin
end
//
// Start things off with an ARP request
// Fill in MAC
//
memcpy(@srcMAC, @MAC, MAC_SIZE)
memcpy(@localha, @MAC, MAC_SIZE)
//
// Start things off with an ARP request
//
memset(@dstMAC, MAC_SIZE, BROADCAST_MAC)
memset(@remoteha, MAC_SIZE, 0)
opARP = ARP_REQST

25
src/samplesrc/mon.pla Normal file
View File

@ -0,0 +1,25 @@
import stdlib
predef syscall, call, memset, getc, gets, putc, puts, putln
predef memset, memcpy, modaddr, modexec
predef heapmark, heapallocalign, heapalloc, heaprelease
predef isugt, isuge, isult, isule
byte MACHID
end
byte bye = $20, $00, $BF, $65
word paramsptr
byte[7] params = 4
//
// Set 'BYE' params
//
paramsptr = @params
//
// Set up CTRL-Y to point to 'BYE' routine
//
^$3F8 = $4C
*$3F9 = @bye
//
// Call into monitor
//
call(-151, 0, 0, 0, 0)
done