add MkIdentifyReply skeleton
This commit is contained in:
parent
003b9fa9ba
commit
d14d58e629
|
@ -1,3 +1,5 @@
|
||||||
|
# python 3 compatible
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
import struct
|
import struct
|
||||||
import array
|
import array
|
||||||
|
|
|
@ -76,6 +76,28 @@ TEST_REPLY_FMT = "!32s"
|
||||||
MAX_ATTEMPTS = 10
|
MAX_ATTEMPTS = 10
|
||||||
MAX_TIMEOUT = 0.5
|
MAX_TIMEOUT = 0.5
|
||||||
|
|
||||||
|
#---- NOTES ----
|
||||||
|
# Header Format: !2cH6s2x
|
||||||
|
# ! : Big Endian, std format
|
||||||
|
# 2c: 2 bytes
|
||||||
|
# H : unsigned short 0-65535 (2 bytes)
|
||||||
|
# 6s: 6 byte array
|
||||||
|
# 2x: 2 pad (null) bytes
|
||||||
|
#
|
||||||
|
# NF_MAGIC: 1 byte
|
||||||
|
# COMMAND: 1 byte
|
||||||
|
# SEQUENCE: 2 bytes
|
||||||
|
# ETH_ADDR (MAC): 6 bytes
|
||||||
|
# PAD: 2 bytes
|
||||||
|
# Total: 12 bytes
|
||||||
|
#
|
||||||
|
# Example: b'Z\x00V\x81\xff\xff\xff\xff\xff\xff\x00\x00'
|
||||||
|
# NF_MAGIC: b'Z' (HEX: 5A, DEC: 90)
|
||||||
|
# COMMAND: b'\x00' (NF_IDENTIFY)
|
||||||
|
# SEQUENCE: b'V\x81' (22145)
|
||||||
|
# ETH_ADDR (MAC): b'\xff\xff\xff\xff\xff\xff' (FF:FF:FF:FF:FF:FF)
|
||||||
|
# PAD: b'\x00\x00'
|
||||||
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
def MkHeader(header, seq, eth_addr):
|
def MkHeader(header, seq, eth_addr):
|
||||||
|
@ -94,8 +116,51 @@ def MkIdentify(seq):
|
||||||
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
def MkAssignment(seq, eth_addr, ip_type, ip_addr, netmask, gateway):
|
def MkIdentifyReply(seq, vDev):
|
||||||
|
# header: 12 bytes
|
||||||
|
# IdentifyReplyData: 64 bytes
|
||||||
|
# header
|
||||||
|
# NF_MAGIC
|
||||||
|
# NF_IDENTIFY_REPLY
|
||||||
|
# seq
|
||||||
|
# IdentifyReplyData
|
||||||
|
# uptime_days [0-65535]
|
||||||
|
# uptime_hrs [0-23]
|
||||||
|
# uptime_min [0-59]
|
||||||
|
# uptime_secs [0-59]
|
||||||
|
# mode []
|
||||||
|
# alert []
|
||||||
|
# ip_type [static|dynamic]
|
||||||
|
# ip_addr [255.255.255.255]
|
||||||
|
# ip_netmask [255.255.255.255]
|
||||||
|
# ip_gw [255.255.255.255]
|
||||||
|
# app_ver [255.255.255.255]
|
||||||
|
# boot_ver [255.255.255.255]
|
||||||
|
# hw_ver [255.255.255.255]
|
||||||
|
# name [32 chars]
|
||||||
|
# todo: setup vDev class, VirtualDevice, which will provide the answers
|
||||||
|
# for the reply data
|
||||||
|
return MkHeader(NF_IDENTIFY_REPLY, seq, vDev.addr) + \
|
||||||
|
struct.pack(
|
||||||
|
IDENTIFY_REPLY_FMT,
|
||||||
|
chr(vDev.updays),
|
||||||
|
chr(vDev.uphrs),
|
||||||
|
chr(vDev.upmins),
|
||||||
|
chr(vDev.upsecs),
|
||||||
|
chr(vDev.mode),
|
||||||
|
chr(vDev.alert),
|
||||||
|
chr(vDev.iptype),
|
||||||
|
socket.inet_aton(vDev.ipaddr),
|
||||||
|
socket.inet_aton(vDev.ipnetmask),
|
||||||
|
socket.inet_aton(vDev.ipgw),
|
||||||
|
vDev.version_binary,
|
||||||
|
vDev.bootver_binary,
|
||||||
|
vDev.hwver_binary,
|
||||||
|
vDev.name_binary
|
||||||
|
)
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
def MkAssignment(seq, eth_addr, ip_type, ip_addr, netmask, gateway):
|
||||||
return MkHeader(NF_ASSIGNMENT, seq, eth_addr) + \
|
return MkHeader(NF_ASSIGNMENT, seq, eth_addr) + \
|
||||||
struct.pack(
|
struct.pack(
|
||||||
ASSIGNMENT_FMT,
|
ASSIGNMENT_FMT,
|
||||||
|
@ -103,7 +168,7 @@ def MkAssignment(seq, eth_addr, ip_type, ip_addr, netmask, gateway):
|
||||||
socket.inet_aton(ip_addr),
|
socket.inet_aton(ip_addr),
|
||||||
socket.inet_aton(netmask),
|
socket.inet_aton(netmask),
|
||||||
socket.inet_aton(gateway)
|
socket.inet_aton(gateway)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue