From 2dcd81fd2345fd3839a35f75f8fffcf79e359a5e Mon Sep 17 00:00:00 2001 From: dodge-this Date: Wed, 13 Oct 2010 16:19:50 +0000 Subject: [PATCH] myriad of arm/adi additions. working on moving past arm7 into adiv5 git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@755 12e2690d-a6be-4b82-a7b7-67c4a43b65c8 --- client/ARM7_chip_data.py | 158 +++++ client/GoodFETADIv5.py | 425 +++++++++++++ client/GoodFETARM9.py | 72 +++ client/M29W640GB.py | 26 + client/em260_data.py | 1157 ++++++++++++++++++++++++++++++++++++ client/em260_disass.py | 175 ++++++ firmware/apps/jtag/adiv5.c | 108 ++++ firmware/include/adiv5.h | 156 +++++ 8 files changed, 2277 insertions(+) create mode 100644 client/ARM7_chip_data.py create mode 100644 client/GoodFETADIv5.py create mode 100644 client/GoodFETARM9.py create mode 100644 client/M29W640GB.py create mode 100644 client/em260_data.py create mode 100644 client/em260_disass.py create mode 100644 firmware/apps/jtag/adiv5.c create mode 100644 firmware/include/adiv5.h diff --git a/client/ARM7_chip_data.py b/client/ARM7_chip_data.py new file mode 100644 index 0000000..56117e1 --- /dev/null +++ b/client/ARM7_chip_data.py @@ -0,0 +1,158 @@ + +READ = 0 +WRITE = 1 + +platforms = { + "at91sam7": {0x000000: (0x100000, "Flash before remap, SRAM after remap"), + 0x100000: (0x100000, "Internal Flash"), + 0x200000: (0x100000, "Internal SRAM"), + }, + "at91r40008":{0x000000: (0x100000, "Flash before remap, SRAM after remap"), + 0x100000: (0x100000, "Internal Flash"), + 0x200000: (0x100000, "Internal SRAM"), + 0x300000: (0x100000, "Internal SRAM - pre-remap"), + 0x400000: (0xfc000000-0x400000, "External Bus Interface Addressing"), + }, + } + +# gratuitously leveraged from atmel's Flash_uploader demo app +EB40_EBI_desc = ( + ( WRITE, 0xFFE00000, 0x01002529 ), #* Write EBI_CSR0 + ( WRITE, 0xFFE00004, 0x02002121 ), #* Write EBI_CSR1 + ( WRITE, 0xFFE00020, 0x00000001 ), #* Remap Command + ( WRITE, 0xFFE00024, 0x00000006 ) #* Memory Control Register +) + +EB40A_EBI_desc = ( + ( WRITE, 0xFFE00000, 0x01002539 ), #* Write EBI_CSR0 0x01002539 + ( WRITE, 0xFFE00020, 0x00000001 ), #* Remap Command + ( WRITE, 0xFFE00024, 0x00000006 ) #* Memory Control Register +) + +EB42_EBI_desc = ( + ( WRITE, 0xFFE00000, 0x01002529 ), #* Write EBI_CSR0 + ( WRITE, 0xFFE00004, 0x02002121 ), #* Write EBI_CSR1 + ( WRITE, 0xFFE00020, 0x00000001 ), #* Remap Command + ( WRITE, 0xFFE00024, 0x00000006 ) #* Memory Control Register +) + +EB55_EBI_desc = ( + ( WRITE, 0xFFE00000, 0x01002529 ), #* Write EBI_CSR0 + ( WRITE, 0xFFE00004, 0x02002121 ), #* Write EBI_CSR1 + ( WRITE, 0xFFE00020, 0x00000001 ), #* Remap Command + ( WRITE, 0xFFE00024, 0x00000006 ) #* Memory Control Register +) + +EB63_EBI_desc = ( + ( WRITE, 0xFFE00000, 0x01002529 ), #* Write EBI_CSR0 + ( WRITE, 0xFFE00004, 0x02002121 ), #* Write EBI_CSR1 + ( WRITE, 0xFFE00020, 0x00000001 ), #* Remap Command + ( WRITE, 0xFFE00024, 0x00000006 ) #* Memory Control Register +) + +EB42_PLL_desc = ( + #* Disable external watchdog assertion + ( WRITE, 0xFFFF8008, 0x00000000 ), #* ST_WMR + + #* Set up the Clock frequency to run at 32,768 MHz with PLLB + ( WRITE, 0xFFFF4020, 0xC503E708 ), #* PMC_CGMR + + #* Reading the PMC Status register to detect when the PLLB is stabilized + ( POLL, 0xFFFF4030, 0x00000001 ), #* PMC_SR + + #* Commuting from Slow Clock to PLLB + ( WRITE, 0xFFFF4020, 0xC503E798 ) #* PMC_CGMR +) + +EB55_PLL_desc = ( + #* Enable the main oscillator (16Mhz) / MOSCEN = 1, OSCOUNT = 47 (1.4ms/30µs) + ( WRITE, 0xFFFF4020, 0x002F0002 ), #* APMC_CGMR + + #* Wait for Main oscillator stabilization. Wait for APMC_MOSCS Bit in APMC_SR equals 1 + ( POLL, 0xFFFF4030, 0x00000001 ), #* APMC_SR + + #* Commuting from Slow Clock to Main Oscillator (32K to 16Mhz) + ( WRITE, 0xFFFF4020, 0x002F4002 ), #* APMC_CGMR + + #* Setup the PLL / MUL = 1, PLLCOUNT = 3, CSS = 1 + ( WRITE, 0xFFFF4020, 0x032F4102 ), #* APMC_CGMR + + #* Wait for the PLL is stabilized. Wait for APMC_PLL_LOCK Bit in APMC_SR equals 1 + ( POLL, 0xFFFF4030, 0x00000002 ), #* APMC_SR + + #* Commuting from 16Mhz to PLL @ 32MHz / CSS = 2, MUL = 1 + ( WRITE, 0xFFFF4020, 0x032F8102 ) #* APMC_CGMR +) + + +{ + { + EB40, + { NULL, 0 }, + { EB40_EBI_desc, sizeof(EB40_EBI_desc)/sizeof(Instr) }, + FLASH_LV, + {(u_int *)FLASH_LV_PRG, 0x7D0, 0x20 }, //* Flash algo + {(u_int *)0x0101C000, 0x7D0, 0x20 }, //* Flash identify + {(u_int *)0x01020000, 0x800, 0x0 }, //* boot 2KB + {(u_int *)0x01030000, 0xCD00, 0x2000 }, //* angel 51KB + {(u_int *)0x01028000, 0x1800, 0x00010000 }, //* appli 6KB + { NULL, 0, 0 } //* Mirror + }, + { + EB40A, + { NULL, 0 }, + { EB40A_EBI_desc, sizeof(EB40A_EBI_desc)/sizeof(Instr) }, + FLASH_BV, + {(u_int *)FLASH_BV_PRG, 0x7D0, 0x20 }, //* Flash algo + {(u_int *)0x0101E000, 0x400, 0x20 }, //* Flash identify + {(u_int *)0x01040000, 0x2800, 0x01000000 }, //* boot 10KB + {(u_int *)0x01050000, 0xCD00, 0x01006000 }, //* angel 51KB + {(u_int *)0x01048000, 0x1800, 0x01100000 }, //* appli 4KB + {(u_int *)0x01000000, 0x200000 , 0x01000000 } //* Mirror + }, + { + EB42, + { EB42_PLL_desc, sizeof(EB42_PLL_desc)/sizeof(Instr) }, + { EB42_EBI_desc, sizeof(EB42_EBI_desc)/sizeof(Instr) }, + FLASH_BV, + {(u_int *)FLASH_BV_PRG, 0x7D0, 0x20 }, //* Flash algo + {(u_int *)0x0101E000, 0x400, 0x20 }, //* Flash identify + {(u_int *)0x01060000, 0x3400, 0x01000000 }, //* boot 13KB + {(u_int *)0x01070000, 0xCD00, 0x01006000 }, //* angel 51KB + {(u_int *)0x01068000, 0x1800, 0x01100000 }, //* appli 4KB 0x1170000 0x1100000 + { NULL, 0, 0 } //* Mirror + }, + { + EB55, + { EB55_PLL_desc, sizeof(EB55_PLL_desc)/sizeof(Instr) }, + { EB55_EBI_desc, sizeof(EB55_EBI_desc)/sizeof(Instr) }, + FLASH_BV, + {(u_int *)FLASH_BV_PRG, 0x7D0, 0x20 }, //* Flash algo + {(u_int *)0x0101E000, 0x400, 0x20 }, //* Flash identify + {(u_int *)0x01080000, 0x4C00, 0x01000000 }, //* boot 19KB + {(u_int *)0x01090000, 0xCD00, 0x01006000 }, //* angel 51KB + {(u_int *)0x01088000, 0x1800, 0x01100000 }, //* appli 4KB + { NULL, 0, 0 } //* Mirror + }, + { + EB63, + { NULL, 0 }, + { EB63_EBI_desc, sizeof(EB63_EBI_desc)/sizeof(Instr) }, + FLASH_BV, + {(u_int *)FLASH_BV_PRG, 0x7D0, 0x20 }, //* Flash algo + {(u_int *)0x0101E000, 0x400, 0x20 }, //* Flash identify + {(u_int *)0x010A0000, 0x2800, 0x01000000 }, //* boot 10KB + {(u_int *)0x010B0000, 0xCD00, 0x01004000 }, //* angel 51KB + {(u_int *)0x010A8000, 0x1800, 0x01100000 }, //* appli 4KB + { NULL, 0, 0 } //* Mirror + } + +}; + +IV_RESET = 0 +IV_ABORT = 4 +IV_DABORT = 8 +IV_PREFETCH = 12 +IV_UNDEF = 16 +IV_FIQ = 20 + diff --git a/client/GoodFETADIv5.py b/client/GoodFETADIv5.py new file mode 100644 index 0000000..c2006b5 --- /dev/null +++ b/client/GoodFETADIv5.py @@ -0,0 +1,425 @@ +#!/usr/bin/env python +# GoodFET ARM Debugging Interface v5 (ADIv5) Client Library. +# the ideal interface to pwning ARM Cortex +# +# Contributions and bug reports welcome. +# +# + +import sys, binascii, struct, time +import atlasutils.smartprint as asp +from GoodFET import GoodFET +from intelhex import IntelHex + + +#Global Commands +READ = 0x00 +WRITE = 0x01 +PEEK = 0x02 +POKE = 0x03 +SETUP = 0x10 +START = 0x20 +STOP = 0x21 +CALL = 0x30 +EXEC = 0x31 +NOK = 0x7E +OK = 0x7F + +# ARM7TDMI JTAG commands +IR_SHIFT = 0x80 +DR_SHIFT = 0x81 +RESETTAP = 0x82 +RESETTARGET = 0x83 +GET_REGISTER = 0x87 +SET_REGISTER = 0x88 +DEBUG_INSTR = 0x89 +# Really ARM specific stuff +WAIT_DBG = 0x91 +CHAIN0 = 0x93 +SCANCHAIN1 = 0x94 +EICE_READ = 0x95 +EICE_WRITE = 0x96 + +#4-bit ARM JTAG INSTRUCTIONS - STANDARD +IR_ABORT = 0x8 +IR_RESERVED1 = 0x9 +IR_DPACC = 0xA +IR_APACC = 0xB +IR_RESERVED2 = 0xC +IR_RESERVED3 = 0xD +IR_IDCODE = 0xE +IR_BYPASS = 0xF +#4-bit ARM JTAG INSTRUCTIONS - IMPLEMENTATION-DEFINED +IR_EXTEST = 0x0 +IR_SAMPLE = 0x1 +IR_PRELOAD = 0x2 +IR_RESERVED = 0x3 +IR_INTEST = 0x4 +IR_CLAMP = 0x5 +IR_HIGHZ = 0x6 +IR_CLAMPZ = 0x7 + +DP_CTRLSTAT_OFF = 0x4 +DP_SELECT_OFF = 0x8 +DP_RDBUFF_OFF = 0xC + +PM_usr = 0b10000 +PM_fiq = 0b10001 +PM_irq = 0b10010 +PM_svc = 0b10011 +PM_abt = 0b10111 +PM_und = 0b11011 +PM_sys = 0b11111 +proc_modes = { + 0: ("UNKNOWN, MESSED UP PROCESSOR MODE","fsck", "This should Never happen. MCU is in funky state!"), + PM_usr: ("User Processor Mode", "usr", "Normal program execution mode"), + PM_fiq: ("FIQ Processor Mode", "fiq", "Supports a high-speed data transfer or channel process"), + PM_irq: ("IRQ Processor Mode", "irq", "Used for general-purpose interrupt handling"), + PM_svc: ("Supervisor Processor Mode", "svc", "A protected mode for the operating system"), + PM_abt: ("Abort Processor Mode", "abt", "Implements virtual memory and/or memory protection"), + PM_und: ("Undefined Processor Mode", "und", "Supports software emulation of hardware coprocessor"), + PM_sys: ("System Processor Mode", "sys", "Runs privileged operating system tasks (ARMv4 and above)"), +} + +PSR_bits = [ + None, None, None, None, None, "Thumb", "nFIQ_int", "nIRQ_int", + "nImprDataAbort_int", "BIGendian", None, None, None, None, None, None, + "GE_0", "GE_1", "GE_2", "GE_3", None, None, None, None, + "Jazelle", None, None, "Q (DSP-overflow)", "oVerflow", "Carry", "Zero", "Neg", + ] + +ARM_INSTR_NOP = 0xe1a00000L +ARM_INSTR_BX_R0 = 0xe12fff10L +ARM_INSTR_STR_Rx_r14 = 0xe58f0000L # from atmel docs +ARM_READ_REG = ARM_INSTR_STR_Rx_r14 +ARM_INSTR_LDR_Rx_r14 = 0xe59f0000L # from atmel docs +ARM_WRITE_REG = ARM_INSTR_LDR_Rx_r14 +ARM_INSTR_LDR_R1_r0_4 = 0xe4901004L +ARM_READ_MEM = ARM_INSTR_LDR_R1_r0_4 +ARM_INSTR_STR_R1_r0_4 = 0xe4801004L +ARM_WRITE_MEM = ARM_INSTR_STR_R1_r0_4 +ARM_INSTR_MRS_R0_CPSR = 0xe10f0000L +ARM_INSTR_MSR_cpsr_cxsf_R0 =0xe12ff000L +ARM_INSTR_STMIA_R14_r0_rx = 0xE88e0000L # add up to 65k to indicate which registers... +ARM_INSTR_LDMIA_R14_r0_rx = 0xE89e0000L # add up to 65k to indicate which registers... +ARM_STORE_MULTIPLE = ARM_INSTR_STMIA_R14_r0_rx +ARM_INSTR_SKANKREGS = 0xE88F7fffL +ARM_INSTR_CLOBBEREGS = 0xE89F7fffL + +ARM_INSTR_B_IMM = 0xea000000L +ARM_INSTR_B_PC = 0xea000000L +ARM_INSTR_BX_PC = 0xe1200010L # need to set r0 to the desired address +THUMB_INSTR_LDR_R0_r0 = 0x68006800L +THUMB_WRITE_REG = THUMB_INSTR_LDR_R0_r0 +THUMB_INSTR_STR_R0_r0 = 0x60006000L +THUMB_READ_REG = THUMB_INSTR_STR_R0_r0 +THUMB_INSTR_MOV_R0_PC = 0x46b846b8L +THUMB_INSTR_MOV_PC_R0 = 0x46474647L +THUMB_INSTR_BX_PC = 0x47784778L +THUMB_INSTR_NOP = 0x1c001c00L +THUMB_INSTR_B_IMM = 0xe000e000L +ARM_REG_PC = 15 + + +LDM_BITMASKS = [(1<>sys.stderr,(strng) +def PSRdecode(psrval): + output = [ "(%s mode)"%proc_modes[psrval&0x1f][1] ] + for x in xrange(5,32): + if psrval & (1<> 28) + partno = (ident >> 12) & 0xffff + mfgid = (ident >> 1) & 0x7ff + return "Chip IDCODE: 0x%x\n\tver: %x\n\tpartno: %x\n\tmfgid: %x\n" % (ident, ver, partno, mfgid); + + def ADIget_register(self, reg): + """Get an ARM's Register""" + self.writecmd(0x14,GET_REGISTER,1,[reg&0xf]) + retval = struct.unpack(">8)&0xff, (val>>16)&0xff, val>>24, reg,0,0,0]) + retval = struct.unpack(">4) & 0xf + apsel = raw>>24 + return "SWDP_CTRLSEL = %d\nAPBANKSEL = %d\nAPSEL = %d\n" + + def ADIgetWCR(self): # SWDP only + raise Exception("IMPLEMENT ME: ADIgetWCR") + + def ADIgetRESEND(self): # SWDP only + raise Exception("IMPLEMENT ME: ADIgetRESEND") + +class GoodFETADIjtag(GoodFETADIv5): + """A GoodFET variant for use with ARM7TDMI microprocessor.""" + def ADIshift_IR(self, IR, noretidle=0): + if (self.ir_status != IR): + self.writecmd(0x14,IR_SHIFT,2, [IR, LSB|noretidle]) + self.ir_status = IR + return self.data + def ADIshift_DR(self, bignum, bits, flags=0): + data = [bits&0xff, flags&0xff,0,0] + data.extend(chop(data, bits/4)) + self.writecmd(0x14,DR_SHIFT, len(data), data) + return self.data + def ADIident(self): + """Get an ARM's ID.""" + self.ADIshift_IR(IR_IDCODE,0) + self.ADIshift_DR(0,32,LSB) + retval = struct.unpack(">1) # addr[3:2] goes in bits [2:1]. this *must* be a multiple of 4. + return self.ADIshift_DR(data, 35, LSB) + def ADIsetAPACC(self, addr, val): + """ + 0 < val < 0xffffffff + addr == 4*n (ie. multiple of four, returns the word at that register) + """ + self.ADIshift_IR(IR_APACC) + data = (val<<3) | (addr>>1) # addr[3:2] goes in bits [2:1]. this *must* be a multiple of 4. + self.ADIshift_DR(data, 35, LSB) + def ADIgetDPACC(self, addr, flags): # candidate for firmware. not sure the intelligence wants to be there, but performance may want it. + self.ADIshift_IR(IR_DPACC) + data = 1 | (addr>>1) # addr[3:2] goes in bits [2:1]. this *must* be a multiple of 4. + return self.ADIshift_DR(data, 35, LSB) + def ADIsetDPACC(self, addr, val): + """ + 0 < val < 0xffffffff + addr == 4*n (ie. multiple of four, returns the word at that register) + """ + self.ADIshift_IR(IR_DPACC) + data = (val<<3) | (addr>>1) # addr[3:2] goes in bits [2:1]. this *must* be a multiple of 4. + self.ADIshift_DR(data, 35, LSB) + + def ADIsetABORT(self): + """ ONLY use if the debugger has received WAIT responses over an extended period""" + self.ADIshift_IR(self, IR_ABORT) + self.ADIshift_DR(self, 1, 35) + + def ADIsetSELECT(self, apnum, apbank, flags="ignored for jtag"): + if (apnum != self.ap_selected or apbank != self.ap_bank): + select = (apnum<<24) | (apbank<<4) + self.ADIsetDPACC(0x8, select) + self.ap_selected = apnum + self.ap_bank = apbank + def ADIgetSELECT(self, noncached=False): + if (noncached): + return self.ADIgetDPACC(0x8) + return self.ap_selected + + + +class ADI_AccessPort: # define common AP calls + def __init__(self, DP, apnum): + self.dp = DP # link to parent. all calls should use this to access the underlying debug port. + self.apnum = apnum # which AP am i to this DP? + + def getRegister(self, bank, off): + self.dp.ADIsetSELECT(self.apnum, bank) + return self.dp.ADIgetAPACC(off) + + def getRegisterByAddr(self, addr): + bank = addr/16 + self.dp.ADIsetSELECT(self.apnum, bank) + return self.dp.ADIgetAPACC(addr&0xf) + + def getIdentRegister(self): + ident = self.getRegisterByAddr(0xfc) + return ident + + def getIdentRegisterrepr(self): + raw = self.getIdentRegister() + ap_rev = raw>>28 + jep_cont = (raw>>24) & 0xf + jep_ident = (raw>>17) & 0x7f + ap_class = (raw>>16) & 1 + ap_ident = raw & 0xff + return "AP Revision: 0x%x\nJEP-106 Continuation Code: 0x%x\nJEP-106 Identity Code: 0x%x\nAP Class: 0x%x\nAP Identification: %x (%s)\n"%(ap_rev,jep_cont,jep_ident,ap_class,ap_ident,AP_IDENT_TYPES[ap_ident&0xf]) + #def + +class ADI_MEM_AP(ADI_AccessPort): + def __init__(self, DP, apnum): + ADI_AccessPort.__init__(self, DP, apnum) + self.cfg = self.getCFG() # necessary to cache endianness information + # FIXME: how do i determine if this adi supports multibyte access or just word? or packed transfers? + self.setMemAccessSize(4) + + def setMemAccessSize(self, bytecount): + csw = self.getCSW() + csw &= 0xfffffff8 + csw |= (bytecount>>1) + self.setCSW(csw) + + def getCSW(self): + pass + def setCSW(self, csw): + pass + + def getTAR(self): + pass + def setTAR(self, csw): + pass + + def getDRW(self): + pass + def setDRW(self, csw): + pass + + def getBD0(self): + pass + def setBD0(self, csw): + pass + + def getCFG(self): + pass + def setCFG(self, csw): + pass + + def getBASE(self): + pass + def setBASE(self, csw): + pass + + def getIDR(self): + pass + def setIDR(self, csw): + pass diff --git a/client/GoodFETARM9.py b/client/GoodFETARM9.py new file mode 100644 index 0000000..a92fe57 --- /dev/null +++ b/client/GoodFETARM9.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python +# GoodFET ARM9 Client Library +# +# Contributions and bug reports welcome. +# +# todo: +# * full cycle debugging.. halt to resume +# * ensure correct PC handling +# * flash manipulation (probably need to get the specific chip for this one) +# * set security (chip-specific) + +import sys, binascii, struct, time +import atlasutils.smartprint as asp +from GoodFET import GoodFET +import GoodFETARM7 +from intelhex import IntelHex + + +#Global Commands +READ = 0x00 +WRITE = 0x01 +PEEK = 0x02 +POKE = 0x03 +SETUP = 0x10 +START = 0x20 +STOP = 0x21 +CALL = 0x30 +EXEC = 0x31 +NOK = 0x7E +OK = 0x7F + +# ARM JTAG commands +IR_SHIFT = 0x80 +DR_SHIFT = 0x81 +RESETTAP = 0x82 +RESETTARGET = 0x83 +GET_REGISTER = 0x87 +SET_REGISTER = 0x88 +DEBUG_INSTR = 0x89 +# Really ARM specific stuff +WAIT_DBG = 0x91 +CHAIN0 = 0x93 +SCANCHAIN1 = 0x94 +EICE_READ = 0x95 +EICE_WRITE = 0x96 + + +class GoodFETARM9(GoodFETARM7.GoodFETARM7): + def ARM9readMem(self, adr, wordcount): + """ Only works in ARM mode currently + WARNING: Addresses must be word-aligned! + """ + regs = self.ARMget_registers() + self.ARMset_registers([0xdeadbeef for x in xrange(14)], 0xe) + output = [] + count = wordcount + while (wordcount > 0): + count = (wordcount, 0xe)[wordcount>0xd] + bitmask = LDM_BITMASKS[count] + self.ARMset_register(14,adr) + self.ARMdebuginstr(ARM_INSTR_LDMIA_R14_r0_rx | bitmask ,0) + self.ARM_nop(1) + #FIXME: do we need the extra nop here? + self.ARMrestart() + self.ARMwaitDBG() + output.extend([self.ARMget_register(x) for x in xrange(count)]) + wordcount -= count + adr += count*4 + #print hex(adr) + # FIXME: handle the rest of the wordcount here. + self.ARMset_registers(regs,0xe) + return output diff --git a/client/M29W640GB.py b/client/M29W640GB.py new file mode 100644 index 0000000..3eb5960 --- /dev/null +++ b/client/M29W640GB.py @@ -0,0 +1,26 @@ +""" +http://www.tonews.com/thread/1644423/comp/sys/arm/getting_chip_selects_working_after_remap_on_the_at91r40008.html + +This sets the base to 0x00000000 (illegal). +If you would like to have it at 0x00400000, change the register to +0x0040203E. + +The base address contains the real top bits of the base address, no offset +from the range base. + +I'd start addressing from e.g. 0x01000000, so all sizes will fit in. There +are plenty of free addresses with the AT91: you can fill only 64 Mbytes of +the 4 Gbytes of address space. +""" + +class M29W640G: + def __init__(self, addrE, pinE, addrG, pinG, addrW, pinW, chipnum, chip_base_addr=0x1000000): + self.addrE = addrE + self.pinE = pinE + self.addrG = addrG + self.pinG = pinG + self.addrW = addrW + self.pinW pinW + self.chipnum = chipnum + self.base_addr = chip_base_addr + diff --git a/client/em260_data.py b/client/em260_data.py new file mode 100644 index 0000000..3f4c738 --- /dev/null +++ b/client/em260_data.py @@ -0,0 +1,1157 @@ +############################# +# Transaction Values +# 0 = Request +# 1 = Response +############################# +TRANSACTION = 0 +############################# + +############################# +# SPI Byte Values +############################# +spi_version_mask = 0xC0 +spi_pro_stat = (0x0A, 0x0B, 0xC0, 0xC1) + +spi_bytes = ( + 0x00, + 0x01, + 0x02, + 0x03, + 0x04, + 0x0A, + 0x0B, + 0xC0, + 0xC1, + 0xA7, + 0xFD, + 0xFE, + 0xFF +) + +spi_values = ( + 'EM260_RESET', + 'OVERSIZED_EZSP_FRAME', + 'ABORTED_TRANSACTION', + 'MISSING_FRAME_TERMINATOR', + 'RESERVED_ERROR', + 'SPI_PROTOCOL_VERSION', + 'SPI_STATUS', + 'RESP_STAT_SLEEP', + 'RESP_STAT_READY', + 'FRAME_TERMINATOR', + 'BOOTLOADER_FRAME', + 'EZSP_FRAME', + 'CONT_BYTE' +) + +spi_table = {} +spi_table_rev = {} +for byte in xrange(len(spi_bytes)): + spi_table[spi_bytes[byte]] = spi_values[byte] + spi_table_rev[spi_values[byte]] = spi_bytes[byte] + +############################# + +############################# +# Command Control Frame +############################# +cmd_mask = 0x80 +resp_over_mask = 0x01 +resp_trun_mask = 0x02 + +cmd_control = ( + 'CMDI', # Master State: Idle + 'CMDD', # Master State: Deep Sleep + 'CMDP', # Master State: Power Down + 'Reserved', + 'Reserved', + 'Reserved', + 'Reserved', +) + +#resp_overflow = 'Out of Memory' +resp_overflow = 'NOMEM' +#resp_truncated = 'Truncated Response' +resp_truncated = 'TRUNC_RESP' +############################# + +############################# +# Named Values +############################# + +# Ember + +# Boolean +boolean = ( + 'FALSE', # 0x00 + 'TRUE' # 0x01 +) + +# Frame IDs +frame_error = 'NOT IMPLEMENTED' +frame_ids = ( + 'version', # 0x00 + 'NOT IMPLEMENTED', # 0x01 + 'addEndpoint', # 0x02 + 'NOT IMPLEMENTED', # 0x03 + 'NOT IMPLEMENTED', # 0x04 + 'nop', # 0x05 + 'callback', # 0x06 + 'noCallbacks', # 0x07 + 'reset', # 0x08 + 'setToken', # 0x09 + 'getToken', # 0x0A + 'getMfgToken', # 0x0B + 'NOT IMPLEMENTED', # 0x0C + 'getMillisecondTime', # 0x0D + 'setTimer', # 0x0E + 'timerHandler', # 0x0F + 'serialWrite', # 0x10 + 'serialRead', # 0x11 + 'debugWrite', # 0x12 + 'debugHandler', # 0x13 + 'requestLinkKey', # 0x14 + 'setManufacturerCode', # 0x15 + 'setPowerDescriptor', # 0x16 + 'networkInit', # 0x17 + 'networkState', # 0x18 + 'stackStatusHandler', # 0x19 + 'startScan', # 0x1A + 'networkFoundHandler', # 0x1B + 'scanCompleteHandler', # 0x1C + 'stopScan', # 0x1D + 'formNetwork', # 0x1E + 'joinNetwork', # 0x1F + 'leaveNetwork', # 0x20 + 'findAndRejoinNetwork', # 0x21 + 'permitJoining', # 0x22 + 'childJoinHandler', # 0x23 + 'trustCenterJoinHandler', # 0x24 + 'NOT IMPLEMENTED', # 0x25 + 'getEui64', # 0x26 + 'getNodeId', # 0x27 + 'getNetworkParameters', # 0x28 + 'getParentChildParameters', # 0x29 + 'clearBindingTable', # 0x2A + 'setBinding', # 0x2B + 'getBinding', # 0x2C + 'deleteBinding', # 0x2D + 'bindingIsActive', # 0x2E + 'getBindingRemoteNodeId', # 0x2F + 'setBindingRemoteNodeId', # 0x30 + 'remoteSetBindingHandler', # 0x31 + 'remoteDeleteBindingHandler', # 0x32 + 'maximumPayloadLength', # 0x33 + 'sendUnicast', # 0x34 + 'NOT IMPLEMENTED', # 0x35 + 'sendBroadcast', # 0x36 + 'NOT IMPLEMENTED', # 0x37 + 'sendMulticast', # 0x38 + 'sendReply', # 0x39 + 'NOT IMPLEMENTED', # 0x3A + 'NOT IMPLEMENTED', # 0x3B + 'NOT IMPLEMENTED', # 0x3C + 'NOT IMPLEMENTED', # 0x3D + 'NOT IMPLEMENTED', # 0x3E + 'messageSentHandler', # 0x3F + 'cancelMessage', # 0x40 + 'sendManyToOneRouteRequest',# 0x41 + 'pollForData', # 0x42 + 'pollCompleteHandler', # 0x43 + 'pollHandler', # 0x44 + 'incomingMessageHandler', # 0x45 + 'setRam', # 0x46 + 'getRam', # 0x47 + 'energyScanResultHandler', # 0x48 + 'getRandomNumber', # 0x49 + 'getChildData', # 0x4A + 'NOT IMPLEMENTED', # 0x4B + 'NOT IMPLEMENTED', # 0x4C + 'NOT IMPLEMENTED', # 0x4D + 'getTimer', # 0x4E + 'scanAndFormNetwork', # 0x4F + 'scanAndJoinNetwork', # 0x50 + 'scanErrorHandler', # 0x51 + 'getConfigurationValue', # 0x52 + 'setConfigurationValue', # 0x53 + 'NOT IMPLEMENTED', # 0x54 + 'setPolicy', # 0x55 + 'getPolicy', # 0x56 + 'NOT IMPLEMENTED', # 0x57 + 'invalidCommand', # 0x58 + 'incomingRouteRecordHandler', # 0x59 + 'setSourceRoute', # 0x5A + 'addressTableEntryIsActive',# 0x5B + 'setAddressTableRemoteEui64', # 0x5C + 'setAddressTableRemoteNodeId', # 0x5D + 'getAddressTableRemoteEui64', # 0x5E + 'getAddressTableRemoteNodeId', # 0x5F + 'lookupNodeIdByEui64', # 0x60 + 'lookupEui64ByNodeId', # 0x61 + 'incomingSenderEui64Handler', # 0x62 + 'getMulticastTableEntry', # 0x63 + 'setMulticastTableEntry', # 0x64 + 'readAndClearCounters', # 0x65 + 'addOrUpdateKeyTableEntry', # 0x66 + 'NOT IMPLEMENTED', # 0x67 + 'setInitialSecurityState', # 0x68 + 'getCurrentSecurityState', # 0x69 + 'getKey', # 0x6A + 'NOT IMPLEMENTED', # 0x6B + 'NOT IMPLEMENTED', # 0x6C + 'NOT IMPLEMENTED', # 0x6D + 'switchNetworkKeyHandler', # 0x6E + 'NOT IMPLEMENTED', # 0x6F + 'NOT IMPLEMENTED', # 0x70 + 'getKeyTableEntry', # 0x71 + 'setKeyTableEntry', # 0x72 + 'broadcastNextNetworkKey', # 0x73 + 'broadcastNetworkKeySwitch',# 0x74 + 'findKeyTableEntry', # 0x75 + 'eraseKeyTableEntry', # 0x76 + 'becomeTrustCenter', # 0x77 + 'NOT IMPLEMENTED', # 0x78 + 'getNeighbor', # 0x79 + 'neighborCount', # 0x7A + 'getRouteTableEntry', # 0x7B + 'idConflictHandler', # 0x7C + 'incomingManyToOneRouteRequestHandler', # 0x7D + 'setExtendedTimeout', # 0x7E + 'getExtendedTimeout', # 0x7F + 'incomingRouteErrorHandler',# 0x80 + 'echo', # 0x81 + 'replaceAddressTableEntry', # 0x82 + 'mfglibStart', # 0x83 + 'mfglibEnd', # 0x84 + 'mfglibStartTone', # 0x85 + 'mfglibStopTone', # 0x86 + 'mfglibStartStream', # 0x87 + 'mfglibStopStream', # 0x88 + 'mfglibSendPacket', # 0x89 + 'mfglibSetChannel', # 0x8A + 'mfglibGetChannel', # 0x8B + 'mfglibSetPower', # 0x8C + 'mfglibGetPower', # 0x8D + 'mfglibRxHandler', # 0x8E + 'launchStandaloneBootloader', # 0x8F + 'sendBootloadMessage', # 0x90 + 'getStandaloneBootloaderVersionPlatMicroPhy', # 0x91 + 'incomingBootloadMessageHandler', # 0x92 + 'bootloadTransmitCompleteHandler', # 0x93 + 'aesEncrypt', # 0x94 + 'overrideCurrentChannel', # 0x95 + 'sendRawMessage', # 0x96 + 'macPassthroughMessageHandler', # 0x97 + 'rawTransmitCompleteHandler', # 0x98 + 'setRadioPower', # 0x99 + 'setRadioChannel', # 0x9A + 'zigbeeKeyEstablishmentHandler', # 0x9B + 'energyScanRequest', # 0x9C + 'delayTest', # 0x9D + 'generateCbkeKeysHandler', # 0x9E + 'calculateSmacs', # 0x9F + 'calculateSmacsHandler', # 0xA0 + 'clearTemporaryDataMaybeStoreLinkKey', # 0xA1 + 'NOT IMPLEMENTED', # 0xA2 + 'NOT IMPLEMENTED', # 0xA3 + 'generateCbkeKeys', # 0xA4 + 'NOT IMPLEMENTED', # 0xA5 + 'dsaSign', # 0xA6 + 'dsaSignHandler', # 0xA7 + 'scanForJoinableNetwork', # 0xA8 + 'unusedPanIdFoundHandler', # 0xA9 + 'getValue', # 0xAA + 'setValue', # 0xAB + 'NOT IMPLEMENTED', # 0xAC + 'NOT IMPLEMENTED', # 0xAD + 'NOT IMPLEMENTED', # 0xAE + 'NOT IMPLEMENTED' # 0xAF +) + +frame_table = {} +frame_table_rev = {} +for fid in xrange(len(frame_ids)): + frame_table[fid] = frame_ids[fid] + frame_table[frame_ids[fid]] = fid + +# EzspConfigId +EZSP_CONFIG_PACKET_BUFFER_COUNT = 0x01 +EZSP_CONFIG_NEIGHBOR_TABLE_SIZE = 0x02 +EZSP_CONFIG_APS_UNICAST_MESSAGE_COUNT = 0x03 +EZSP_CONFIG_BINDING_TABLE_SIZE = 0x04 +EZSP_CONFIG_ADDRESS_TABLE_SIZE = 0x05 +EZSP_CONFIG_MULTICAST_TABLE_SIZE = 0x06 +EZSP_CONFIG_ROUTE_TABLE_SIZE = 0x07 +EZSP_CONFIG_DISCOVERY_TABLE_SIZE = 0x08 +EZSP_CONFIG_BROADCAST_ALARM_DATA_SIZE = 0x09 +EZSP_CONFIG_UNICAST_ALARM_DATA_SIZE = 0x0A +EZSP_CONFIG_STACK_PROFILE = 0x0C +EZSP_CONFIG_SECURITY_LEVEL = 0x0D +EZSP_CONFIG_MAX_HOPS = 0x10 +EZSP_CONFIG_MAX_END_DEVICE_CHILDREN = 0x11 +EZSP_CONFIG_INDIRECT_TRANSMISSION_TIMEOUT = 0x12 +EZSP_CONFIG_END_DEVICE_POLL_TIMEOUT = 0x13 +EZSP_CONFIG_MOBILE_NODE_POLL_TIMEOUT = 0x14 +EZSP_CONFIG_RESERVED_MOBILE_CHILD_ENTRIES = 0x15 +EZSP_CONFIG_HOST_RAM = 0x16 +EZSP_CONFIG_TX_POWER_MODE = 0x17 +EZSP_CONFIG_DISABLE_RELAY = 0x18 +EZSP_CONFIG_TRUST_CENTER_ADDRESS_CACHE_SIZE = 0x19 +EZSP_CONFIG_SOURCE_ROUTE_TABLE_SIZE = 0x1A +EZSP_CONFIG_END_DEVICE_POLL_TIMEOUT_SHIFT = 0x1B +EZSP_CONFIG_FRAGMENT_WINDOW_SIZE = 0x1C +EZSP_CONFIG_FRAGMENT_DELAY_MS = 0x1D +EZSP_CONFIG_KEY_TABLE_SIZE = 0x1E +EZSP_CONFIG_APS_ACK_TIMEOUT = 0x1F +EZSP_CONFIG_ACTIVE_SCAN_DURATION = 0x20 +EZSP_CONFIG_END_DEVICE_BIND_TIMEOUT = 0x21 +EZSP_CONFIG_PAN_ID_CONFLICT_REPORT_THRESHOLD = 0x22 +EZSP_CONFIG_REQUEST_KEY_TIMEOUT = 0x24 +EZSP_CONFIG_ENABLE_DUAL_CHANNEL_SCAN = 0x25 + +ezsp_config_id = { + 'EZSP_CONFIG_PACKET_BUFFER_COUNT' : 0x01,\ + 'EZSP_CONFIG_NEIGHBOR_TABLE_SIZE' : 0x02,\ + 'EZSP_CONFIG_APS_UNICAST_MESSAGE_COUNT' : 0x03,\ + 'EZSP_CONFIG_BINDING_TABLE_SIZE' : 0x04,\ + 'EZSP_CONFIG_ADDRESS_TABLE_SIZE' : 0x05,\ + 'EZSP_CONFIG_MULTICAST_TABLE_SIZE' : 0x06,\ + 'EZSP_CONFIG_ROUTE_TABLE_SIZE' : 0x07,\ + 'EZSP_CONFIG_DISCOVERY_TABLE_SIZE' : 0x08,\ + 'EZSP_CONFIG_BROADCAST_ALARM_DATA_SIZE' : 0x09,\ + 'EZSP_CONFIG_UNICAST_ALARM_DATA_SIZE' : 0x0A,\ + 'EZSP_CONFIG_STACK_PROFILE' : 0x0C,\ + 'EZSP_CONFIG_SECURITY_LEVEL' : 0x0D,\ + 'EZSP_CONFIG_MAX_HOPS' : 0x10,\ + 'EZSP_CONFIG_MAX_END_DEVICE_CHILDREN' : 0x11,\ + 'EZSP_CONFIG_INDIRECT_TRANSMISSION_TIMEOUT' : 0x12,\ + 'EZSP_CONFIG_END_DEVICE_POLL_TIMEOUT' : 0x13,\ + 'EZSP_CONFIG_MOBILE_NODE_POLL_TIMEOUT' : 0x14,\ + 'EZSP_CONFIG_RESERVED_MOBILE_CHILD_ENTRIES' : 0x15,\ + 'EZSP_CONFIG_HOST_RAM' : 0x16,\ + 'EZSP_CONFIG_TX_POWER_MODE' : 0x17,\ + 'EZSP_CONFIG_DISABLE_RELAY' : 0x18,\ + 'EZSP_CONFIG_TRUST_CENTER_ADDRESS_CACHE_SIZE' : 0x19,\ + 'EZSP_CONFIG_SOURCE_ROUTE_TABLE_SIZE' : 0x1A,\ + 'EZSP_CONFIG_END_DEVICE_POLL_TIMEOUT_SHIFT' : 0x1B,\ + 'EZSP_CONFIG_FRAGMENT_WINDOW_SIZE' : 0x1C,\ + 'EZSP_CONFIG_FRAGMENT_DELAY_MS' : 0x1D,\ + 'EZSP_CONFIG_KEY_TABLE_SIZE' : 0x1E,\ + 'EZSP_CONFIG_APS_ACK_TIMEOUT' : 0x1F,\ + 'EZSP_CONFIG_ACTIVE_SCAN_DURATION' : 0x20,\ + 'EZSP_CONFIG_END_DEVICE_BIND_TIMEOUT' : 0x21,\ + 'EZSP_CONFIG_PAN_ID_CONFLICT_REPORT_THRESHOLD' : 0x22,\ + 'EZSP_CONFIG_REQUEST_KEY_TIMEOUT' : 0x24,\ + 'EZSP_CONFIG_ENABLE_DUAL_CHANNEL_SCAN' : 0x25,\ + } +ezsp_config_id_rev = {} +for cid,num in ezsp_config_id.items(): + ezsp_config_id_rev[num] = cid + +# EzspValueId +EZSP_VALUE_TOKEN_STACK_NODE_DATA = 0x00 +EZSP_VALUE_MAC_PASSTHROUGH_FLAGS = 0x01 +EZSP_VALUE_EMBERNET_PASSTHROUGH_SOURCE_ADDRESS = 0x02 +ezsp_value_id = {\ + 'EZSP_VALUE_TOKEN_STACK_NODE_DATA' : 0x00,\ + 'EZSP_VALUE_MAC_PASSTHROUGH_FLAGS' : 0x01,\ + 'EZSP_VALUE_EMBERNET_PASSTHROUGH_SOURCE_ADDRESS' : 0x02,\ +} +ezsp_value_id_rev = {} +for vid,num in ezsp_value_id.items(): + ezsp_value_id_rev[num] = vid + +# EmberConfigTxPowerMode +EMBER_TX_POWER_MODE_DEFAULT = 0x00 +EMBER_TX_POWER_MODE_BOOST = 0x01 +EMBER_TX_POWER_MODE_ALTERNATE = 0x02 +EMBER_TX_POWER_MODE_BOOST_AND_ALTERNATE = 0x03 + +ember_config_tx_power_mode = {\ + 'EMBER_TX_POWER_MODE_DEFAULT' : 0x00,\ + 'EMBER_TX_POWER_MODE_BOOST' : 0x01,\ + 'EMBER_TX_POWER_MODE_ALTERNATE' : 0x02,\ + 'EMBER_TX_POWER_MODE_BOOST_AND_ALTERNATE' : 0x03,\ +} +ember_config_tx_power_mode_rev = {} +for mode,num in ember_config_tx_power_mode.items(): + ember_config_tx_power_mode_rev[num] = mode + + +# EzspPolicyId +EZSP_TRUST_CENTER_POLICY = 0x00 +EZSP_BINDING_MODIFICATION_POLICY = 0x01 +EZSP_UNICAST_REPLIES_POLICY = 0x02 +EZSP_POLL_HANDLER_POLICY = 0x03 +EZSP_MESSAGE_CONTENTS_IN_CALLBACK_POLICY = 0x04 +EZSP_TC_KEY_REQUEST_POLICY = 0x05 +EZSP_APP_KEY_REQUEST_POLICY = 0x06 +ezsp_policy_id = {\ + 'EZSP_TRUST_CENTER_POLICY' : 0x00,\ + 'EZSP_BINDING_MODIFICATION_POLICY' : 0x01,\ + 'EZSP_UNICAST_REPLIES_POLICY' : 0x02,\ + 'EZSP_POLL_HANDLER_POLICY' : 0x03,\ + 'EZSP_MESSAGE_CONTENTS_IN_CALLBACK_POLICY' : 0x04,\ + 'EZSP_TC_KEY_REQUEST_POLICY' : 0x05,\ + 'EZSP_APP_KEY_REQUEST_POLICY' : 0x06,\ +} +ezsp_policy_id_rev = {} +for pid,num in ezsp_policy_id.items(): + ezsp_policy_id_rev[num] = pid + + +# EzspDecisionid +EZSP_ALLOW_JOINS = 0x00 +EZSP_ALLOW_JOINS_REJOINS_HAVE_LINK_KEY = 0x04 +EZSP_ALLOW_PRECONFIGURED_KEY_JOINS = 0x01 +EZSP_ALLOW_REJOINS_ONLY = 0x02 +EZSP_DISALLOW_ALL_JOINS_AND_REJOINS = 0x03 +EZSP_DISALLOW_BINDING_MODIFICATION = 0x10 +EZSP_ALLOW_BINDING_MODIFICATION = 0x11 +EZSP_HOST_WILL_NOT_SUPPLY_REPLY = 0x20 +EZSP_HOST_WILL_SUPPLY_REPLY = 0x21 +EZSP_POLL_HANDLER_IGNORE = 0x30 +EZSP_POLL_HANDLER_CALLBACK = 0x31 +EZSP_MESSAGE_TAG_ONLY_IN_CALLBACK = 0x40 +EZSP_MESSAGE_TAG_AND_CONTENTS_IN_CALLBACK = 0x41 +EZSP_DENY_TC_KEY_REQUESTS = 0x50 +EZSP_ALLOW_TC_KEY_REQUESTS = 0x51 +EZSP_DENY_APP_KEY_REQUESTS = 0x60 +EZSP_ALLOW_APP_KEY_REQUESTS = 0x61 +ezsp_decision_id = { + 'EZSP_ALLOW_JOINS' : 0x00,\ + 'EZSP_ALLOW_JOINS_REJOINS_HAVE_LINK_KEY' : 0x04,\ + 'EZSP_ALLOW_PRECONFIGURED_KEY_JOINS' : 0x01,\ + 'EZSP_ALLOW_REJOINS_ONLY' : 0x02,\ + 'EZSP_DISALLOW_ALL_JOINS_AND_REJOINS' : 0x03,\ + 'EZSP_DISALLOW_BINDING_MODIFICATION' : 0x10,\ + 'EZSP_ALLOW_BINDING_MODIFICATION' : 0x11,\ + 'EZSP_HOST_WILL_NOT_SUPPLY_REPLY' : 0x20,\ + 'EZSP_HOST_WILL_SUPPLY_REPLY' : 0x21,\ + 'EZSP_POLL_HANDLER_IGNORE' : 0x30,\ + 'EZSP_POLL_HANDLER_CALLBACK' : 0x31,\ + 'EZSP_MESSAGE_TAG_ONLY_IN_CALLBACK' : 0x40,\ + 'EZSP_MESSAGE_TAG_AND_CONTENTS_IN_CALLBACK' : 0x41,\ + 'EZSP_DENY_TC_KEY_REQUESTS' : 0x50,\ + 'EZSP_ALLOW_TC_KEY_REQUESTS' : 0x51,\ + 'EZSP_DENY_APP_KEY_REQUESTS' : 0x60,\ + 'EZSP_ALLOW_APP_KEY_REQUESTS' : 0x61,\ +} +ezsp_decision_id_rev = {} +for did,num in ezsp_decision_id.items(): + ezsp_decision_id_rev[num] = did + + +# EzspMfgTokenId +EZSP_MFG_CUSTOM_VERSION = 0x00 +EZSP_MFG_STRING = 0x01 +EZSP_MFG_BOARD_NAME = 0x02 +EZSP_MFG_MANUF_ID = 0x03 +EZSP_MFG_PHY_CONFIG = 0x04 +EZSP_MFG_BOOTLOAD_AES_KEY = 0x05 +EZSP_MFG_ASH_CONFIG = 0x06 +EZSP_MFG_EZSP_STORAGE = 0x07 +EZSP_STACK_CAL_DATA = 0x08 +EZSP_MFG_CBKE_DATA = 0x09 +EZSP_MFG_INSTALLATION_CODE = 0x0A +ezsp_mfg_token_id = { + 'EZSP_MFG_CUSTOM_VERSION' : 0x00,\ + 'EZSP_MFG_STRING' : 0x01,\ + 'EZSP_MFG_BOARD_NAME' : 0x02,\ + 'EZSP_MFG_MANUF_ID' : 0x03,\ + 'EZSP_MFG_PHY_CONFIG' : 0x04,\ + 'EZSP_MFG_BOOTLOAD_AES_KEY' : 0x05,\ + 'EZSP_MFG_ASH_CONFIG' : 0x06,\ + 'EZSP_MFG_EZSP_STORAGE' : 0x07,\ + 'EZSP_STACK_CAL_DATA' : 0x08,\ + 'EZSP_MFG_CBKE_DATA' : 0x09,\ + 'EZSP_MFG_INSTALLATION_CODE' : 0x0A,\ +} +ezsp_mfg_token_id_rev = {} +for tid,num in ezsp_mfg_token_id.items(): + ezsp_mfg_token_id_rev[num] = tid + + +# EzspStatus +EZSP_SUCCESS = 0x00 +EZSP_SPI_ERR_FATAL = 0x10 +EZSP_SPI_ERR_EM260_RESET = 0x11 +EZSP_SPI_ERR_OVERSIZED_EZSP_FRAME = 0x12 +EZSP_SPI_ERR_ABORTED_TRANSACTION = 0x13 +EZSP_SPI_ERR_MISSING_FRAME_TERMINATOR = 0x14 +EZSP_SPI_ERR_WAIT_SECTION_TIMEOUT = 0x15 +EZSP_SPI_ERR_NO_FRAME_TERMINATOR = 0x16 +EZSP_SPI_ERR_EZSP_COMMAND_OVERSIZED = 0x17 +EZSP_SPI_ERR_EZSP_RESPONSE_OVERSIZED = 0x18 +EZSP_SPI_WAITING_FOR_RESPONSE = 0x19 +EZSP_SPI_ERR_HANDSHAKE_TIMEOUT = 0x1A +EZSP_SPI_ERR_STARTUP_TIMEOUT = 0x1B +EZSP_SPI_ERR_STARTUP_FAIL = 0x1C +EZSP_SPI_ERR_UNSUPPORTED_SPI_COMMAND = 0x1D +EZSP_ASH_IN_PROGRESS = 0x20 +EZSP_ASH_HOST_FATAL_ERROR = 0x21 +EZSP_ASH_NCP_FATAL_ERROR = 0x22 +EZSP_ASH_DATA_FRAME_TOO_LONG = 0x23 +EZSP_ASH_DATA_FRAME_TOO_SHORT = 0x24 +EZSP_ASH_NO_TX_SPACE = 0x25 +EZSP_ASH_NO_RX_SPACE = 0x26 +EZSP_ASH_NO_RX_DATA = 0x27 +EZSP_ASH_NOT_CONNECTED = 0x28 +EZSP_ERROR_VERSION_NOT_SET = 0x30 +EZSP_ERROR_INVALID_FRAME_ID = 0x31 +EZSP_ERROR_WRONG_DIRECTION = 0x32 +EZSP_ERROR_TRUNCATED = 0x33 +EZSP_ERROR_OVERFLOW = 0x34 +EZSP_ERROR_OUT_OF_MEMORY = 0x35 +EZSP_ERROR_INVALID_VALUE = 0x36 +EZSP_ERROR_INVALID_ID = 0x37 +EZSP_ERROR_INVALID_CALL = 0x38 +EZSP_ERROR_NO_RESPONSE = 0x39 +EZSP_ERROR_COMMAND_TOO_LONG = 0x40 +EZSP_ERROR_QUEUE_FULL = 0x41 +EZSP_ASH_ERROR_VERSION = 0x50 +EZSP_ASH_ERROR_TIMEOUTS = 0x51 +EZSP_ASH_ERROR_RESET_FAIL = 0x52 +EZSP_ASH_ERROR_NCP_RESET = 0x53 +EZSP_ASH_ERROR_SERIAL_INIT = 0x54 +EZSP_ASH_ERROR_NCP_TYPE = 0x55 +EZSP_ASH_ERROR_RESET_METHOD = 0x56 +EZSP_ASH_ERROR_XON_XOFF = 0x57 +EZSP_ASH_STARTED = 0x70 +EZSP_ASH_CONNECTED = 0x71 +EZSP_ASH_DISCONNECTED = 0x72 +EZSP_ASH_ACK_TIMEOUT = 0x73 +EZSP_ASH_CANCELLED = 0x74 +EZSP_ASH_OUT_OF_SEQUENCE = 0x75 +EZSP_ASH_BAD_CRC = 0x76 +EZSP_ASH_COMM_ERROR = 0x77 +EZSP_ASH_BAD_ACKNUM = 0x78 +EZSP_ASH_TOO_SHORT = 0x79 +EZSP_ASH_TOO_LONG = 0x7A +EZSP_ASH_BAD_CONTROL = 0x7B +EZSP_ASH_BAD_LENGTH = 0x7C +EZSP_ASH_NO_ERROR = 0xFF +ezsp_status = {\ + 'EZSP_SUCCESS' : 0x00,\ + 'EZSP_SPI_ERR_FATAL' : 0x10,\ + 'EZSP_SPI_ERR_EM260_RESET' : 0x11,\ + 'EZSP_SPI_ERR_OVERSIZED_EZSP_FRAME' : 0x12,\ + 'EZSP_SPI_ERR_ABORTED_TRANSACTION' : 0x13,\ + 'EZSP_SPI_ERR_MISSING_FRAME_TERMINATOR' : 0x14,\ + 'EZSP_SPI_ERR_WAIT_SECTION_TIMEOUT' : 0x15,\ + 'EZSP_SPI_ERR_NO_FRAME_TERMINATOR' : 0x16,\ + 'EZSP_SPI_ERR_EZSP_COMMAND_OVERSIZED' : 0x17,\ + 'EZSP_SPI_ERR_EZSP_RESPONSE_OVERSIZED' : 0x18,\ + 'EZSP_SPI_WAITING_FOR_RESPONSE' : 0x19,\ + 'EZSP_SPI_ERR_HANDSHAKE_TIMEOUT' : 0x1A,\ + 'EZSP_SPI_ERR_STARTUP_TIMEOUT' : 0x1B,\ + 'EZSP_SPI_ERR_STARTUP_FAIL' : 0x1C,\ + 'EZSP_SPI_ERR_UNSUPPORTED_SPI_COMMAND' : 0x1D,\ + 'EZSP_ASH_IN_PROGRESS' : 0x20,\ + 'EZSP_ASH_HOST_FATAL_ERROR' : 0x21,\ + 'EZSP_ASH_NCP_FATAL_ERROR' : 0x22,\ + 'EZSP_ASH_DATA_FRAME_TOO_LONG' : 0x23,\ + 'EZSP_ASH_DATA_FRAME_TOO_SHORT' : 0x24,\ + 'EZSP_ASH_NO_TX_SPACE' : 0x25,\ + 'EZSP_ASH_NO_RX_SPACE' : 0x26,\ + 'EZSP_ASH_NO_RX_DATA' : 0x27,\ + 'EZSP_ASH_NOT_CONNECTED' : 0x28,\ + 'EZSP_ERROR_VERSION_NOT_SET' : 0x30,\ + 'EZSP_ERROR_INVALID_FRAME_ID' : 0x31,\ + 'EZSP_ERROR_WRONG_DIRECTION' : 0x32,\ + 'EZSP_ERROR_TRUNCATED' : 0x33,\ + 'EZSP_ERROR_OVERFLOW' : 0x34,\ + 'EZSP_ERROR_OUT_OF_MEMORY' : 0x35,\ + 'EZSP_ERROR_INVALID_VALUE' : 0x36,\ + 'EZSP_ERROR_INVALID_ID' : 0x37,\ + 'EZSP_ERROR_INVALID_CALL' : 0x38,\ + 'EZSP_ERROR_NO_RESPONSE' : 0x39,\ + 'EZSP_ERROR_COMMAND_TOO_LONG' : 0x40,\ + 'EZSP_ERROR_QUEUE_FULL' : 0x41,\ + 'EZSP_ASH_ERROR_VERSION' : 0x50,\ + 'EZSP_ASH_ERROR_TIMEOUTS' : 0x51,\ + 'EZSP_ASH_ERROR_RESET_FAIL' : 0x52,\ + 'EZSP_ASH_ERROR_NCP_RESET' : 0x53,\ + 'EZSP_ASH_ERROR_SERIAL_INIT' : 0x54,\ + 'EZSP_ASH_ERROR_NCP_TYPE' : 0x55,\ + 'EZSP_ASH_ERROR_RESET_METHOD' : 0x56,\ + 'EZSP_ASH_ERROR_XON_XOFF' : 0x57,\ + 'EZSP_ASH_STARTED' : 0x70,\ + 'EZSP_ASH_CONNECTED' : 0x71,\ + 'EZSP_ASH_DISCONNECTED' : 0x72,\ + 'EZSP_ASH_ACK_TIMEOUT' : 0x73,\ + 'EZSP_ASH_CANCELLED' : 0x74,\ + 'EZSP_ASH_OUT_OF_SEQUENCE' : 0x75,\ + 'EZSP_ASH_BAD_CRC' : 0x76,\ + 'EZSP_ASH_COMM_ERROR' : 0x77,\ + 'EZSP_ASH_BAD_ACKNUM' : 0x78,\ + 'EZSP_ASH_TOO_SHORT' : 0x79,\ + 'EZSP_ASH_TOO_LONG' : 0x7A,\ + 'EZSP_ASH_BAD_CONTROL' : 0x7B,\ + 'EZSP_ASH_BAD_LENGTH' : 0x7C,\ + 'EZSP_ASH_NO_ERROR' : 0xFF,\ +} +ezsp_status_rev = {} +for tid,num in ezsp_status.items(): + ezsp_status_rev[num] = tid + + +# EmberStatus +EMBER_SUCCESS = 0x00 +EMBER_ERR_FATAL = 0x01 +EMBER_EEPROM_MFG_STACK_VERSION_MISMATCH = 0x04 +EMBER_INCOMPATIBLE_STATIC_MEMORY_DEFINITIONS = 0x05 +EMBER_EEPROM_MFG_VERSION_MISMATCH = 0x06 +EMBER_EEPROM_STACK_VERSION_MISMATCH = 0x07 +EMBER_NO_BUFFERS = 0x18 +EMBER_SERIAL_INVALID_BAUD_RATE = 0x20 +EMBER_SERIAL_INVALID_PORT = 0x21 +EMBER_SERIAL_TX_OVERFLOW = 0x22 +EMBER_SERIAL_RX_OVERFLOW = 0x23 +EMBER_SERIAL_RX_FRAME_ERROR = 0x24 +EMBER_SERIAL_RX_PARITY_ERROR = 0x25 +EMBER_SERIAL_RX_EMPTY = 0x26 +EMBER_SERIAL_RX_OVERRUN_ERROR = 0x27 +EMBER_MAC_TRANSMIT_QUEUE_FULL = 0x39 +EMBER_MAC_UNKNOWN_HEADER_TYPE = 0x3A +EMBER_MAC_SCANNING = 0x3D +EMBER_MAC_NO_DATA = 0x31 +EMBER_MAC_JOINED_NETWORK = 0x32 +EMBER_MAC_BAD_SCAN_DURATION = 0x33 +EMBER_MAC_INCORRECT_SCAN_TYPE = 0x34 +EMBER_MAC_INVALID_CHANNEL_MASK = 0x35 +EMBER_MAC_COMMAND_TRANSMIT_FAILURE = 0x36 +EMBER_MAC_NO_ACK_RECEIVED = 0x40 +EMBER_MAC_INDIRECT_TIMEOUT = 0x42 +EMBER_SIM_EEPROM_ERASE_PAGE_GREEN = 0x43 +EMBER_SIM_EEPROM_ERASE_PAGE_RED = 0x44 +EMBER_SIM_EEPROM_FULL = 0x45 +EMBER_ERR_FLASH_WRITE_INHIBITED = 0x46 +EMBER_ERR_FLASH_VERIFY_FAILED = 0x47 +EMBER_SIM_EEPROM_INIT_1_FAILED = 0x48 +EMBER_SIM_EEPROM_INIT_2_FAILED = 0x49 +EMBER_SIM_EEPROM_INIT_3_FAILED = 0x4A +EMBER_ERR_TOKEN_UNKNOWN = 0x4B +EMBER_ERR_TOKEN_EXISTS = 0x4C +EMBER_ERR_TOKEN_INVALID_SIZE = 0x4D +EMBER_ERR_TOKEN_READ_ONLY = 0x4E +EMBER_ERR_BOOTLOADER_TRAP_TABLE_BAD = 0x58 +EMBER_ERR_BOOTLOADER_TRAP_UNKNOWN = 0x59 +EMBER_ERR_BOOTLOADER_NO_IMAGE = 0x5A +EMBER_DELIVERY_FAILED = 0x66 +EMBER_BINDING_INDEX_OUT_OF_RANGE = 0x69 +EMBER_ADDRESS_TABLE_INDEX_OUT_OF_RANGE = 0x6A +EMBER_INVALID_BINDING_INDEX = 0x6C +EMBER_INVALID_CALL = 0x70 +EMBER_COST_NOT_KNOWN = 0x71 +EMBER_MAX_MESSAGE_LIMIT_REACHED = 0x72 +EMBER_MESSAGE_TOO_LONG = 0x74 +EMBER_BINDING_IS_ACTIVE = 0x75 +EMBER_ADDRESS_TABLE_ENTRY_IS_ACTIVE = 0x76 +EMBER_ADC_CONVERSION_DONE = 0x80 +EMBER_ADC_CONVERSION_BUSY = 0x81 +EMBER_ADC_CONVERSION_DEFERRED = 0x82 +EMBER_ADC_NO_CONVERSION_PENDING = 0x84 +EMBER_SLEEP_INTERRUPTED = 0x85 +EMBER_PHY_TX_UNDERFLOW = 0x88 +EMBER_PHY_TX_INCOMPLETE = 0x89 +EMBER_PHY_INVALID_CHANNEL = 0x8A +EMBER_PHY_INVALID_POWER = 0x8B +EMBER_PHY_TX_BUSY = 0x8C +EMBER_PHY_UNKNOWN_RADIO_TYPE = 0x8D +EMBER_PHY_OSCILLATOR_CHECK_FAILED = 0x8E +EMBER_PHY_PARTIAL_PACKET = 0x8F +EMBER_NETWORK_UP = 0x90 +EMBER_NETWORK_DOWN = 0x91 +EMBER_JOIN_FAILED = 0x94 +EMBER_MOVE_FAILED = 0x96 +EMBER_CANNOT_JOIN_AS_ROUTER = 0x98 +EMBER_NODE_ID_CHANGED = 0x99 +EMBER_PAN_ID_CHANGED = 0x9A +EMBER_NO_BEACONS = 0xAB +EMBER_RECEIVED_KEY_IN_THE_CLEAR = 0xAC +EMBER_NO_NETWORK_KEY_RECEIVED = 0xAD +EMBER_NO_LINK_KEY_RECEIVED = 0xAE +EMBER_PRECONFIGURED_KEY_REQUIRED = 0xAF +EMBER_NOT_JOINED = 0x93 +EMBER_INVALID_SECURITY_LEVEL = 0x95 +EMBER_NETWORK_BUSY = 0xA1 +EMBER_INVALID_ENDPOINT = 0xA3 +EMBER_BINDING_HAS_CHANGED = 0xA4 +EMBER_INSUFFICIENT_RANDOM_DATA = 0xA5 +EMBER_APS_ENCRYPTION_ERROR = 0xA6 +EMBER_TRUST_CENTER_MASTER_KEY_NOT_SET = 0xA7 +EMBER_SECURITY_STATE_NOT_SET = 0xA8 +EMBER_KEY_TABLE_INVALID_ADDRESS = 0xB3 +EMBER_SECURITY_CONFIGURATION_INVALID = 0xB7 +EMBER_TOO_SOON_FOR_SWITCH_KEY = 0xB8 +EMBER_KEY_NOT_AUTHORIZED = 0xBB +EMBER_SOURCE_ROUTE_FAILURE = 0xA9 +EMBER_MANY_TO_ONE_ROUTE_FAILURE = 0xAA +EMBER_STACK_AND_HARDWARE_MISMATCH = 0xB0 +EMBER_APPLICATION_ERROR_0 = 0xF0 +EMBER_APPLICATION_ERROR_1 = 0xF1 +EMBER_APPLICATION_ERROR_2 = 0xF2 +EMBER_APPLICATION_ERROR_3 = 0xF3 +EMBER_APPLICATION_ERROR_4 = 0xF4 +EMBER_APPLICATION_ERROR_5 = 0xF5 +EMBER_APPLICATION_ERROR_6 = 0xF6 +EMBER_APPLICATION_ERROR_7 = 0xF7 +EMBER_APPLICATION_ERROR_8 = 0xF8 +EMBER_APPLICATION_ERROR_9 = 0xF9 +EMBER_APPLICATION_ERROR_10 = 0xFA +EMBER_APPLICATION_ERROR_11 = 0xFB +EMBER_APPLICATION_ERROR_12 = 0xFC +EMBER_APPLICATION_ERROR_13 = 0xFD +EMBER_APPLICATION_ERROR_14 = 0xFE +EMBER_APPLICATION_ERROR_15 = 0xFF +ember_status = {\ + 'EMBER_SUCCESS' : 0x00,\ + 'EMBER_ERR_FATAL' : 0x01,\ + 'EMBER_EEPROM_MFG_STACK_VERSION_MISMATCH' : 0x04,\ + 'EMBER_INCOMPATIBLE_STATIC_MEMORY_DEFINITIONS' : 0x05,\ + 'EMBER_EEPROM_MFG_VERSION_MISMATCH' : 0x06,\ + 'EMBER_EEPROM_STACK_VERSION_MISMATCH' : 0x07,\ + 'EMBER_NO_BUFFERS' : 0x18,\ + 'EMBER_SERIAL_INVALID_BAUD_RATE' : 0x20,\ + 'EMBER_SERIAL_INVALID_PORT' : 0x21,\ + 'EMBER_SERIAL_TX_OVERFLOW' : 0x22,\ + 'EMBER_SERIAL_RX_OVERFLOW' : 0x23,\ + 'EMBER_SERIAL_RX_FRAME_ERROR' : 0x24,\ + 'EMBER_SERIAL_RX_PARITY_ERROR' : 0x25,\ + 'EMBER_SERIAL_RX_EMPTY' : 0x26,\ + 'EMBER_SERIAL_RX_OVERRUN_ERROR' : 0x27,\ + 'EMBER_MAC_TRANSMIT_QUEUE_FULL' : 0x39,\ + 'EMBER_MAC_UNKNOWN_HEADER_TYPE' : 0x3A,\ + 'EMBER_MAC_SCANNING' : 0x3D,\ + 'EMBER_MAC_NO_DATA' : 0x31,\ + 'EMBER_MAC_JOINED_NETWORK' : 0x32,\ + 'EMBER_MAC_BAD_SCAN_DURATION' : 0x33,\ + 'EMBER_MAC_INCORRECT_SCAN_TYPE' : 0x34,\ + 'EMBER_MAC_INVALID_CHANNEL_MASK' : 0x35,\ + 'EMBER_MAC_COMMAND_TRANSMIT_FAILURE' : 0x36,\ + 'EMBER_MAC_NO_ACK_RECEIVED' : 0x40,\ + 'EMBER_MAC_INDIRECT_TIMEOUT' : 0x42,\ + 'EMBER_SIM_EEPROM_ERASE_PAGE_GREEN' : 0x43,\ + 'EMBER_SIM_EEPROM_ERASE_PAGE_RED' : 0x44,\ + 'EMBER_SIM_EEPROM_FULL' : 0x45,\ + 'EMBER_ERR_FLASH_WRITE_INHIBITED' : 0x46,\ + 'EMBER_ERR_FLASH_VERIFY_FAILED' : 0x47,\ + EMBER_SIM_EEPROM_INIT_1_FAILED : 0x48,\ + EMBER_SIM_EEPROM_INIT_2_FAILED : 0x49,\ + EMBER_SIM_EEPROM_INIT_3_FAILED : 0x4A,\ + 'EMBER_ERR_TOKEN_UNKNOWN' : 0x4B,\ + 'EMBER_ERR_TOKEN_EXISTS' : 0x4C,\ + 'EMBER_ERR_TOKEN_INVALID_SIZE' : 0x4D,\ + 'EMBER_ERR_TOKEN_READ_ONLY' : 0x4E,\ + 'EMBER_ERR_BOOTLOADER_TRAP_TABLE_BAD' : 0x58,\ + 'EMBER_ERR_BOOTLOADER_TRAP_UNKNOWN' : 0x59,\ + 'EMBER_ERR_BOOTLOADER_NO_IMAGE' : 0x5A,\ + 'EMBER_DELIVERY_FAILED' : 0x66,\ + 'EMBER_BINDING_INDEX_OUT_OF_RANGE' : 0x69,\ + 'EMBER_ADDRESS_TABLE_INDEX_OUT_OF_RANGE' : 0x6A,\ + 'EMBER_INVALID_BINDING_INDEX' : 0x6C,\ + 'EMBER_INVALID_CALL' : 0x70,\ + 'EMBER_COST_NOT_KNOWN' : 0x71,\ + 'EMBER_MAX_MESSAGE_LIMIT_REACHED' : 0x72,\ + 'EMBER_MESSAGE_TOO_LONG' : 0x74,\ + 'EMBER_BINDING_IS_ACTIVE' : 0x75,\ + 'EMBER_ADDRESS_TABLE_ENTRY_IS_ACTIVE' : 0x76,\ + 'EMBER_ADC_CONVERSION_DONE' : 0x80,\ + 'EMBER_ADC_CONVERSION_BUSY' : 0x81,\ + 'EMBER_ADC_CONVERSION_DEFERRED' : 0x82,\ + 'EMBER_ADC_NO_CONVERSION_PENDING' : 0x84,\ + 'EMBER_SLEEP_INTERRUPTED' : 0x85,\ + 'EMBER_PHY_TX_UNDERFLOW' : 0x88,\ + 'EMBER_PHY_TX_INCOMPLETE' : 0x89,\ + 'EMBER_PHY_INVALID_CHANNEL' : 0x8A,\ + 'EMBER_PHY_INVALID_POWER' : 0x8B,\ + 'EMBER_PHY_TX_BUSY' : 0x8C,\ + 'EMBER_PHY_UNKNOWN_RADIO_TYPE' : 0x8D,\ + 'EMBER_PHY_OSCILLATOR_CHECK_FAILED' : 0x8E,\ + 'EMBER_PHY_PARTIAL_PACKET' : 0x8F,\ + 'EMBER_NETWORK_UP' : 0x90,\ + 'EMBER_NETWORK_DOWN' : 0x91,\ + 'EMBER_JOIN_FAILED' : 0x94,\ + 'EMBER_MOVE_FAILED' : 0x96,\ + 'EMBER_CANNOT_JOIN_AS_ROUTER' : 0x98,\ + 'EMBER_NODE_ID_CHANGED' : 0x99,\ + 'EMBER_PAN_ID_CHANGED' : 0x9A,\ + 'EMBER_NO_BEACONS' : 0xAB,\ + 'EMBER_RECEIVED_KEY_IN_THE_CLEAR' : 0xAC,\ + 'EMBER_NO_NETWORK_KEY_RECEIVED' : 0xAD,\ + 'EMBER_NO_LINK_KEY_RECEIVED' : 0xAE,\ + 'EMBER_PRECONFIGURED_KEY_REQUIRED' : 0xAF,\ + 'EMBER_NOT_JOINED' : 0x93,\ + 'EMBER_INVALID_SECURITY_LEVEL' : 0x95,\ + 'EMBER_NETWORK_BUSY' : 0xA1,\ + 'EMBER_INVALID_ENDPOINT' : 0xA3,\ + 'EMBER_BINDING_HAS_CHANGED' : 0xA4,\ + 'EMBER_INSUFFICIENT_RANDOM_DATA' : 0xA5,\ + 'EMBER_APS_ENCRYPTION_ERROR' : 0xA6,\ + 'EMBER_TRUST_CENTER_MASTER_KEY_NOT_SET' : 0xA7,\ + 'EMBER_SECURITY_STATE_NOT_SET' : 0xA8,\ + 'EMBER_KEY_TABLE_INVALID_ADDRESS' : 0xB3,\ + 'EMBER_SECURITY_CONFIGURATION_INVALID' : 0xB7,\ + 'EMBER_TOO_SOON_FOR_SWITCH_KEY' : 0xB8,\ + 'EMBER_KEY_NOT_AUTHORIZED' : 0xBB,\ + 'EMBER_SOURCE_ROUTE_FAILURE' : 0xA9,\ + 'EMBER_MANY_TO_ONE_ROUTE_FAILURE' : 0xAA,\ + 'EMBER_STACK_AND_HARDWARE_MISMATCH' : 0xB0,\ + 'EMBER_APPLICATION_ERROR_0' : 0xF0,\ + 'EMBER_APPLICATION_ERROR_1' : 0xF1,\ + 'EMBER_APPLICATION_ERROR_2' : 0xF2,\ + 'EMBER_APPLICATION_ERROR_3' : 0xF3,\ + 'EMBER_APPLICATION_ERROR_4' : 0xF4,\ + 'EMBER_APPLICATION_ERROR_5' : 0xF5,\ + 'EMBER_APPLICATION_ERROR_6' : 0xF6,\ + 'EMBER_APPLICATION_ERROR_7' : 0xF7,\ + 'EMBER_APPLICATION_ERROR_8' : 0xF8,\ + 'EMBER_APPLICATION_ERROR_9' : 0xF9,\ + 'EMBER_APPLICATION_ERROR_10' : 0xFA,\ + 'EMBER_APPLICATION_ERROR_11' : 0xFB,\ + 'EMBER_APPLICATION_ERROR_12' : 0xFC,\ + 'EMBER_APPLICATION_ERROR_13' : 0xFD,\ + 'EMBER_APPLICATION_ERROR_14' : 0xFE,\ + 'EMBER_APPLICATION_ERROR_15' : 0xFF,\ +} +ember_status_rev = {} +for tid,num in ember_status.items(): + ember_status_rev[num] = tid + + +# EmberEventUnits +EMBER_EVENT_INACTIVE = 0x00 +EMBER_EVENT_MS_TIME = 0x01 +EMBER_EVENT_QS_TIME = 0x02 +EMBER_EVENT_MINUTE_TIME = 0x03 +ember_event_units = {\ + 'EMBER_EVENT_INACTIVE' : 0x00,\ + 'EMBER_EVENT_MS_TIME' : 0x01,\ + 'EMBER_EVENT_QS_TIME' : 0x02,\ + 'EMBER_EVENT_MINUTE_TIME' : 0x03,\ +} +ember_event_units_rev = {} +for tid,num in ember_event_units.items(): + ember_event_units_rev[num] = tid + + +# EmberNodeType +EMBER_UNKNOWN_DEVICE = 0x00 +EMBER_COORDINATOR = 0x01 +EMBER_ROUTER = 0x02 +EMBER_END_DEVICE = 0x03 +EMBER_SLEEPY_END_DEVICE = 0x04 +EMBER_MOBILE_END_DEVICE = 0x05 +ember_node_type = {\ + 'EMBER_UNKNOWN_DEVICE' : 0x00,\ + 'EMBER_COORDINATOR' : 0x01,\ + 'EMBER_ROUTER' : 0x02,\ + 'EMBER_END_DEVICE' : 0x03,\ + 'EMBER_SLEEPY_END_DEVICE' : 0x04,\ + 'EMBER_MOBILE_END_DEVICE' : 0x05 ,\ +} +ember_node_type_rev = {} +for tid,num in ember_node_type.items(): + ember_node_type_rev[num] = tid + + +# EmberNetworkStatus +EMBER_NO_NETWORK = 0x00 +EMBER_JOINING_NETWORK = 0x01 +EMBER_JOINED_NETWORK = 0x02 +EMBER_JOINED_NETWORK_NO_PARENT = 0x03 +EMBER_LEAVING_NETWORK = 0x04 +ember_network_status = {\ + 'EMBER_NO_NETWORK' : 0x00,\ + 'EMBER_JOINING_NETWORK' : 0x01,\ + 'EMBER_JOINED_NETWORK' : 0x02,\ + 'EMBER_JOINED_NETWORK_NO_PARENT' : 0x03,\ + 'EMBER_LEAVING_NETWORK' : 0x04 ,\ +} +ember_network_status_rev = {} +for tid,num in ember_network_status.items(): + ember_network_status_rev[num] = tid + + +# EmberIncomingMessageType +EMBER_INCOMING_UNICAST = 0x00 +EMBER_INCOMING_UNICAST_REPLY = 0x01 +EMBER_INCOMING_MULTICAST = 0x02 +EMBER_INCOMING_MULTICAST_LOOPBACK = 0x03 +EMBER_INCOMING_BROADCAST = 0x04 +EMBER_INCOMING_BROADCAST_LOOPBACK = 0x05 +EMBER_INCOMING_MANY_TO_ONE_ROUTE_REQUEST = 0x06 +ember_incoming_message_type = {\ + 'EMBER_INCOMING_UNICAST' : 0x00,\ + 'EMBER_INCOMING_UNICAST_REPLY' : 0x01,\ + 'EMBER_INCOMING_MULTICAST' : 0x02,\ + 'EMBER_INCOMING_MULTICAST_LOOPBACK' : 0x03,\ + 'EMBER_INCOMING_BROADCAST' : 0x04,\ + 'EMBER_INCOMING_BROADCAST_LOOPBACK' : 0x05,\ + 'EMBER_INCOMING_MANY_TO_ONE_ROUTE_REQUEST' : 0x06,\ +} +ember_incoming_message_type_rev = {} +for tid,num in ember_incoming_message_type.items(): + ember_incoming_message_type_rev[num] = tid + + +# EmberOutgoingMessageType +EMBER_OUTGOING_DIRECT = 0x00 +EMBER_OUTGOING_VIA_ADDRESS_TABLE = 0x01 +EMBER_OUTGOING_VIA_BINDING = 0x02 +EMBER_OUTGOING_MULTICAST = 0x03 +EMBER_OUTGOING_BROADCAST = 0x04 +ember_outgoing_message_type = {\ + 'EMBER_OUTGOING_DIRECT' : 0x00,\ + 'EMBER_OUTGOING_VIA_ADDRESS_TABLE' : 0x01,\ + 'EMBER_OUTGOING_VIA_BINDING' : 0x02,\ + 'EMBER_OUTGOING_MULTICAST' : 0x03,\ + 'EMBER_OUTGOING_BROADCAST' : 0x04,\ +} +ember_outgoing_message_type_rev = {} +for tid,num in ember_outgoing_message_type.items(): + ember_outgoing_message_type_rev[num] = tid + + +# EmberMacPassthroughType +EMBER_MAC_PASSTHROUGH_NONE = 0x00 +EMBER_MAC_PASSTHROUGH_SE_INTERPAN = 0x01 +EMBER_MAC_PASSTHROUGH_EMBERNET = 0x02 +EMBER_MAC_PASSTHROUGH_EMBERNET_SOURCE = 0x04 +ember_mac_passthrough_type = {\ + 'EMBER_MAC_PASSTHROUGH_NONE' : 0x00,\ + 'EMBER_MAC_PASSTHROUGH_SE_INTERPAN' : 0x01,\ + 'EMBER_MAC_PASSTHROUGH_EMBERNET' : 0x02,\ + 'EMBER_MAC_PASSTHROUGH_EMBERNET_SOURCE' : 0x04,\ +} +ember_mac_passthrough_type_rev = {} +for tid,num in ember_mac_passthrough_type.items(): + ember_mac_passthrough_type_rev[num] = tid + + +# EmberBindingType +EMBER_UNUSED_BINDING = 0x00 +EMBER_UNICAST_BINDING = 0x01 +EMBER_MANY_TO_ONE_BINDING = 0x02 +EMBER_MULTICAST_BINDING = 0x03 +ember_binding_type = {\ + 'EMBER_UNUSED_BINDING' : 0x00,\ + 'EMBER_UNICAST_BINDING' : 0x01,\ + 'EMBER_MANY_TO_ONE_BINDING' : 0x02,\ + 'EMBER_MULTICAST_BINDING' : 0x03,\ +} +ember_binding_type_rev = {} +for tid,num in ember_binding_type.items(): + ember_binding_type_rev[num] = tid + + +# EmberApsOption +EMBER_APS_OPTION_NONE = 0x0000 +EMBER_APS_OPTION_ENCRYPTION = 0x0020 +EMBER_APS_OPTION_RETRY = 0x0040 +EMBER_APS_OPTION_ENABLE_ROUTE_DISCOVERY = 0x0100 +EMBER_APS_OPTION_FORCE_ROUTE_DISCOVERY = 0x0200 +EMBER_APS_OPTION_SOURCE_EUI64 = 0x0400 +EMBER_APS_OPTION_DESTINATION_EUI64 = 0x0800 +EMBER_APS_OPTION_ENABLE_ADDRESS_DISCOVERY = 0x1000 +EMBER_APS_OPTION_POLL_RESPONSE = 0x2000 +EMBER_APS_OPTION_FRAGMENT = 0x8000 +ember_aps_options = {\ + 'EMBER_APS_OPTION_NONE' : 0x0000,\ + 'EMBER_APS_OPTION_ENCRYPTION' : 0x0020,\ + 'EMBER_APS_OPTION_RETRY' : 0x0040,\ + 'EMBER_APS_OPTION_ENABLE_ROUTE_DISCOVERY' : 0x0100,\ + 'EMBER_APS_OPTION_FORCE_ROUTE_DISCOVERY' : 0x0200,\ + 'EMBER_APS_OPTION_SOURCE_EUI64' : 0x0400,\ + 'EMBER_APS_OPTION_DESTINATION_EUI64' : 0x0800,\ + 'EMBER_APS_OPTION_ENABLE_ADDRESS_DISCOVERY' : 0x1000,\ + 'EMBER_APS_OPTION_POLL_RESPONSE' : 0x2000,\ + 'EMBER_APS_OPTION_FRAGMENT' : 0x8000,\ +} +ember_aps_options_rev = {} +for tid,num in ember_aps_options.items(): + ember_aps_options_rev[num] = tid + + +# EzspNetworkScanType +EZSP_ENERGY_SCAN = 0x00 +EZSP_ACTIVE_SCAN = 0x01 +EZSP_UNUSED_PAN_ID_SCAN = 0x02 +EZSP_NEXT_JOINABLE_NETWORK_SCAN = 0x03 +ezsp_network_scan_type = {\ + 'EZSP_ENERGY_SCAN' : 0x00,\ + 'EZSP_ACTIVE_SCAN' : 0x01,\ + 'EZSP_UNUSED_PAN_ID_SCAN' : 0x02,\ + 'EZSP_NEXT_JOINABLE_NETWORK_SCAN' : 0x03,\ +} +ezsp_network_scan_type_rev = {} +for tid,num in ezsp_network_scan_type.items(): + ezsp_network_scan_type_rev[num] = tid + + +# EmberJoinDecision +EMBER_USE_PRECONFIGURED_KEY = 0x00 +EMBER_SEND_KEY_IN_THE_CLEAR = 0x01 +EMBER_DENY_JOIN = 0x02 +EMBER_NO_ACTION = 0x03 +ember_join_decision = {\ + 'EMBER_USE_PRECONFIGURED_KEY' : 0x00,\ + 'EMBER_SEND_KEY_IN_THE_CLEAR' : 0x01,\ + 'EMBER_DENY_JOIN' : 0x02,\ + 'EMBER_NO_ACTION' : 0x03,\ +} +ember_join_decision_rev = {} +for tid,num in ember_join_decision.items(): + ember_join_decision_rev[num] = tid + + +# EmberInitialSecurityBitmask +EMBER_STANDARD_SECURITY_MODE = 0x0000 +EMBER_HIGH_SECURITY_MODE = 0x0001 +EMBER_DISTRIBUTED_TRUST_CENTER_MODE = 0x0002 +EMBER_GLOBAL_LINK_KEY = 0x0004 +EMBER_PRECONFIGURED_NETWORK_KEY_MODE = 0x0008 +EMBER_TRUST_CENTER_USES_HASHED_LINK_KEY = 0x0084 +EMBER_HAVE_PRECONFIGURED_KEY = 0x0100 +EMBER_HAVE_NETWORK_KEY = 0x0200 +EMBER_GET_LINK_KEY_WHEN_JOINING = 0x0400 +EMBER_REQUIRE_ENCRYPTED_KEY = 0x0800 +ember_initial_security_bitmask = {\ + 'EMBER_STANDARD_SECURITY_MODE' : 0x0000,\ + 'EMBER_HIGH_SECURITY_MODE' : 0x0001,\ + 'EMBER_DISTRIBUTED_TRUST_CENTER_MODE' : 0x0002,\ + 'EMBER_GLOBAL_LINK_KEY' : 0x0004,\ + 'EMBER_PRECONFIGURED_NETWORK_KEY_MODE' : 0x0008,\ + 'EMBER_TRUST_CENTER_USES_HASHED_LINK_KEY' : 0x0084,\ + 'EMBER_HAVE_PRECONFIGURED_KEY' : 0x0100,\ + 'EMBER_HAVE_NETWORK_KEY' : 0x0200,\ + 'EMBER_GET_LINK_KEY_WHEN_JOINING' : 0x0400,\ + 'EMBER_REQUIRE_ENCRYPTED_KEY' : 0x0800,\ +} +ember_initial_security_bitmask_rev = {} +for tid,num in ember_initial_security_bitmask.items(): + ember_initial_security_bitmask_rev[num] = tid + + +# EmberCurrentSecurityBitmask +EMBER_STANDARD_SECURITY_MODE = 0x0000 +EMBER_HIGH_SECURITY_MODE = 0x0001 +EMBER_DISTRIBUTED_TRUST_CENTER_MODE = 0x0002 +EMBER_GLOBAL_LINK_KEY = 0x0004 +EMBER_HAVE_TRUST_CENTER_LINK_KEY = 0x0010 +EMBER_TRUST_CENTER_USES_HASHED_LINK_KEY = 0x0084 +ember_current_security_bitmask = {\ + 'EMBER_STANDARD_SECURITY_MODE' : 0x0000,\ + 'EMBER_HIGH_SECURITY_MODE' : 0x0001,\ + 'EMBER_DISTRIBUTED_TRUST_CENTER_MODE' : 0x0002,\ + 'EMBER_GLOBAL_LINK_KEY' : 0x0004,\ + 'EMBER_HAVE_TRUST_CENTER_LINK_KEY' : 0x0010,\ + 'EMBER_TRUST_CENTER_USES_HASHED_LINK_KEY' : 0x0084,\ +} +ember_current_security_bitmask_rev = {} +for tid,num in ember_current_security_bitmask.items(): + ember_current_security_bitmask_rev[num] = tid + + +# EmberKeyType +EMBER_TRUST_CENTER_LINK_KEY = 0x01 +EMBER_TRUST_CENTER_MASTER_KEY = 0x02 +EMBER_CURRENT_NETWORK_KEY = 0x03 +EMBER_NEXT_NETWORK_KEY = 0x04 +EMBER_APPLICATION_LINK_KEY = 0x05 +EMBER_APPLICATION_MASTER_KEY = 0x06 +ember_key_type = {\ + 'EMBER_TRUST_CENTER_LINK_KEY' : 0x01,\ + 'EMBER_TRUST_CENTER_MASTER_KEY' : 0x02,\ + 'EMBER_CURRENT_NETWORK_KEY' : 0x03,\ + 'EMBER_NEXT_NETWORK_KEY' : 0x04,\ + 'EMBER_APPLICATION_LINK_KEY' : 0x05,\ + 'EMBER_APPLICATION_MASTER_KEY' : 0x06,\ +} +ember_key_type_rev = {} +for tid,num in ember_key_type.items(): + ember_key_type_rev[num] = tid + + +# EmberKeyStructBitmask +EMBER_KEY_HAS_SEQUENCE_NUMBER = 0x0001 +EMBER_KEY_HAS_OUTGOING_FRAME_COUNTER = 0x0002 +EMBER_KEY_HAS_INCOMING_FRAME_COUNTER = 0x0004 +EMBER_KEY_HAS_PARTNER_EUI64 = 0x0008 +ember_key_structure_bitmask = {\ + 'EMBER_KEY_HAS_SEQUENCE_NUMBER' : 0x0001,\ + 'EMBER_KEY_HAS_OUTGOING_FRAME_COUNTER' : 0x0002,\ + 'EMBER_KEY_HAS_INCOMING_FRAME_COUNTER' : 0x0004,\ + 'EMBER_KEY_HAS_PARTNER_EUI64' : 0x0008,\ +} +ember_key_structure_bitmask_rev = {} +for tid,num in ember_key_structure_bitmask.items(): + ember_key_structure_bitmask_rev[num] = tid + + +# EmberDeviceUpdate +EMBER_STANDARD_SECURITY_SECURED_REJOIN = 0x0 +EMBER_STANDARD_SECURITY_UNSECURED_JOIN = 0x1 +EMBER_DEVICE_LEFT = 0x2 +EMBER_STANDARD_SECURITY_UNSECURED_REJOIN = 0x3 +EMBER_HIGH_SECURITY_SECURED_REJOIN = 0x4 +EMBER_HIGH_SECURITY_UNSECURED_JOIN = 0x5 +EMBER_HIGH_SECURITY_UNSECURED_REJOIN = 0x7 +ember_device_update = {\ + 'EMBER_STANDARD_SECURITY_SECURED_REJOIN' : 0x0,\ + 'EMBER_STANDARD_SECURITY_UNSECURED_JOIN' : 0x1,\ + 'EMBER_DEVICE_LEFT' : 0x2,\ + 'EMBER_STANDARD_SECURITY_UNSECURED_REJOIN' : 0x3,\ + 'EMBER_HIGH_SECURITY_SECURED_REJOIN' : 0x4,\ + 'EMBER_HIGH_SECURITY_UNSECURED_JOIN' : 0x5,\ + 'EMBER_HIGH_SECURITY_UNSECURED_REJOIN' : 0x7,\ +} +ember_device_update_rev = {} +for tid,num in ember_device_update.items(): + ember_device_update_rev[num] = tid + + +# EmberKeyStatus +EMBER_APP_LINK_KEY_ESTABLISHED = 0x01 +EMBER_APP_MASTER_KEY_ESTABLISHED = 0x02 +EMBER_TRUST_CENTER_LINK_KEY_ESTABLISHED = 0x03 +EMBER_KEY_ESTABLISHMENT_TIMEOUT = 0x04 +EMBER_KEY_TABLE_FULL = 0x05 +EMBER_TC_RESPONDED_TO_KEY_REQUEST = 0x06 +EMBER_TC_APP_KEY_SENT_TO_REQUESTER = 0x07 +EMBER_TC_RESPONSE_TO_KEY_REQUEST_FAILED = 0x08 +EMBER_TC_REQUEST_KEY_TYPE_NOT_SUPPORTED = 0x09 +EMBER_TC_NO_LINK_KEY_FOR_REQUESTER = 0x0A +EMBER_TC_REQUESTER_EUI64_UNKNOWN = 0x0B +EMBER_TC_RECEIVED_FIRST_APP_KEY_REQUEST = 0x0C +EMBER_TC_TIMEOUT_WAITING_FOR_SECOND_APP_KEY_REQUEST = 0x0D +EMBER_TC_NON_MATCHING_APP_KEY_REQUEST_RECEIVED = 0x0E +EMBER_TC_FAILED_TO_SEND_APP_KEYS = 0x0F +EMBER_TC_FAILED_TO_STORE_APP_KEY_REQUEST = 0x10 +EMBER_TC_REJECTED_APP_KEY_REQUEST = 0x11 +ember_key_status = {\ + 'EMBER_APP_LINK_KEY_ESTABLISHED' : 0x01,\ + 'EMBER_APP_MASTER_KEY_ESTABLISHED' : 0x02,\ + 'EMBER_TRUST_CENTER_LINK_KEY_ESTABLISHED' : 0x03,\ + 'EMBER_KEY_ESTABLISHMENT_TIMEOUT' : 0x04,\ + 'EMBER_KEY_TABLE_FULL' : 0x05,\ + 'EMBER_TC_RESPONDED_TO_KEY_REQUEST' : 0x06,\ + 'EMBER_TC_APP_KEY_SENT_TO_REQUESTER' : 0x07,\ + 'EMBER_TC_RESPONSE_TO_KEY_REQUEST_FAILED' : 0x08,\ + 'EMBER_TC_REQUEST_KEY_TYPE_NOT_SUPPORTED' : 0x09,\ + 'EMBER_TC_NO_LINK_KEY_FOR_REQUESTER' : 0x0A,\ + 'EMBER_TC_REQUESTER_EUI64_UNKNOWN' : 0x0B,\ + 'EMBER_TC_RECEIVED_FIRST_APP_KEY_REQUEST' : 0x0C,\ + 'EMBER_TC_TIMEOUT_WAITING_FOR_SECOND_APP_KEY_REQUEST' : 0x0D,\ + 'EMBER_TC_NON_MATCHING_APP_KEY_REQUEST_RECEIVED' : 0x0E,\ + 'EMBER_TC_FAILED_TO_SEND_APP_KEYS' : 0x0F,\ + 'EMBER_TC_FAILED_TO_STORE_APP_KEY_REQUEST' : 0x10,\ + 'EMBER_TC_REJECTED_APP_KEY_REQUEST' : 0x11,\ +} +ember_key_status_rev = {} +for tid,num in ember_key_status.items(): + ember_key_status_rev[num] = tid + +############################# + diff --git a/client/em260_disass.py b/client/em260_disass.py new file mode 100644 index 0000000..944aac2 --- /dev/null +++ b/client/em260_disass.py @@ -0,0 +1,175 @@ +import sys +import em260_data as em + +########################################## +# Name: em260_spi_disass.py +# Author: Don C. Weber +# Usage: em260_spi_disass.py +# +# Notes: This tool will parse SPI data from a Beagle +# dump file taken while monitoring the EM250/EM260. +# You can pass it either MOSI, MISO, +# or Bidirectional data. This will output to +# STDOUT. +########################################## + +#debug = 0 # 0 == off, 1 == on +debug = 1 # 0 == off, 1 == on + +def process_data(ascii_data): + byte = 0 + + while byte != len(ascii_data): + outLine = [] + spi_byte = int(ascii_data[byte:byte+2],16) # process this byte + byte += 2 # next byte + + # ORDER IS IMPORTANT HERE SO LIMIT TABLE ASSOCIATED + # WITH SPI BYTE VALUES + + # Continuation Test + # Do this first to save on processing + if spi_byte == 0xFF: + #if debug: print ": ".join(outLine) + continue + + # SPI Error Test + # Do this second to save on processing + if spi_byte <= 0x04: + # Grab byte error + #outLine.append("Error Byte") + outLine.append(ascii_data[byte:byte+2]) + byte += 2 # next byte + # Termination Test + if int(ascii_data[byte:byte+2],16) != 0xA7: + outLine.append("Frame Termination Error") + outLine.append(ascii_data[byte:byte+2]) + print ": ".join(outLine) + byte += 2 # next byte + continue + + # SPI Version Response Test + # Do this third to keep it from the truncated SPI table + # FIXME: A mask should work here!!! + #if ((spi_byte & em.spi_version_mask) == 0x80): + if ((spi_byte >= 0x81) and (spi_byte <= 0xBF)): + outLine.append("SPI Version") + outLine.append(hex(spi_byte)) + # Termination Test + if int(ascii_data[byte:byte+2],16) != 0xA7: + outLine.append("Frame Termination Error") + outLine.append(ascii_data[byte:byte+2]) + print ": ".join(outLine) + byte += 2 # next byte + continue + + # SPI Byte Value + try: # Test for value else error + outLine.append(em.spi_values[em.spi_bytes.index(spi_byte)]) + except: + outLine.append("Unknown SPI Byte Value") + outLine.append(repr(hex(spi_byte))) + print ": ".join(outLine) + continue + + # SPI Protocol Version and Status Test + if spi_byte in em.spi_pro_stat: + # Termination Test + if int(ascii_data[byte:byte+2],16) != 0xA7: + outLine.append("Frame Termination Error") + outLine.append(ascii_data[byte:byte+2]) + print ": ".join(outLine) + byte += 2 # next byte + continue + + # EZSP Frame Test + # Process the Frame + if spi_byte == 0xFE: + # Get Frame Length + data_length = int(ascii_data[byte:byte+2],16) + data_length *= 2 # For ASCII the length must be doubled + if debug: + outLine.append("Len") + outLine.append(str(data_length)) + byte += 2 # next byte + + # Use Length to get Frame Data + data_frame = ascii_data[byte:byte+data_length] + if debug: + outLine.append("Data") + outLine.append(str(data_length)) + byte += data_length # skip frames + + # Test for Frame Terminator before processing + if int(ascii_data[byte:byte+2],16) != 0xA7: + outLine.append("Frame Termination Error") + outLine.append(ascii_data[byte:byte+2]) + # Carrying on to next input + print ": ".join(outLine) + byte += 2 # next byte + continue + + # Process Frame Data + dfdata = 0 + + # Handle Frame Counter + outLine.insert(0, data_frame[dfdata:dfdata+2]) + + # Handle Data + dfdata += 2 # next byte + cmd_data = int(data_frame[dfdata:dfdata+2],16) + + # Response Test + if (cmd_data & em.cmd_mask): + outLine.append("RESP") + # Overflow Test + if (cmd_data & em.resp_over_mask): + outLine.append(em.resp_overflow) + # Truncated Data Test + if (cmd_data & em.resp_trun_mask): + outLine.append(em.resp_truncated) + # Command Test + else: + # Try in case reserved bits set take em.cmd_control out of range + try: + outLine.append(em.cmd_control[cmd_data]) + except: + outLine.append("Unknown Control Command") + # Carrying on to next input + byte += 2 # next byte + continue + + # Frame Identification (A.K.A.: VERB) + dfdata += 2 # next byte + frame_id_data = int(data_frame[dfdata:dfdata+2],16) + try: + outLine.append(em.frame_ids[frame_id_data]) + except: + outLine.append("Unknown Frame Id") + + # Frame Data + # Not Implemented but we can tack it onto the end + # for manual checking + dfdata += 2 # next byte + if dfdata < len(data_frame): + outLine.append("Frame Data") + outLine.append(data_frame[dfdata:]) + + # Carrying on to next input + print outLine + print ": ".join(outLine) + byte += 2 # next byte + continue + +################# +# Main +################# + +# Get Input - Remove whitespaces just in case +#ascii_data = sys.argv[1].replace(' ','') +if __name__ == "__main__": + INF = open(sys.argv[1],'r') + + for line in INF.readlines(): + indata = line.replace(' ','').strip() + process_data(indata) diff --git a/firmware/apps/jtag/adiv5.c b/firmware/apps/jtag/adiv5.c new file mode 100644 index 0000000..2977e81 --- /dev/null +++ b/firmware/apps/jtag/adiv5.c @@ -0,0 +1,108 @@ +// ARM Debug Interface version 5 (cortex and above) +// from the ARM Debug Interface v5 Architecture Specification (IHI 0031A) document: +// "Logically, the ARM Debug Interface (ADI) consists of: +// * A number of registrs that are private to the ADI. These are referred to as the Debug Access Port (DAP) Registers +// * A means to access the DAP registers +// * A means to access the debug registers of the debug components to which the ADI is connected +// ... +// Because the DAP logically consists of two parts, the Debug Port and Access Ports, it must support two types of access: +// * Access to the Debug Port (DP) registers. This is provided by Debug Port accesses (DPACC). +// * Access to Access Port (AP) registers. This is provided by Access Port accesses (APACC). +// An ADI can include multiple Access Ports." + + + + +//////// lower levels - "Debug Ports"//////// +//// Serial Wire Debug protocol +// the sw-dp is based on the coresight serial wire interface and can be implemented as either a synchronous or async interface (yay! *NOT*) +// +// swd protocol comms consists of a three-phase protocol: +// * host-to-target packet req +// * target-to-host ack +// * data-transfer if necessary, either direction depending on the packet req. +// + + +//// JTAG debug protocol +// as with arm7tdmi will soon be, we're going to live at Select DR state as home state. this allows each transaction to finish to a known state. it's more for mental peace more than anything, since the old way works... but the mental understanding that the tap may either be in exit2 or runtest/idle is a hack at best. +// +// + + +//////// mid-levels - resource interface, or "Access Ports" //////// - elected for pythonyness +// "An AP is responsible for accessing debug component registers such as processor debug logic, ETM and trace port registers. These accesses are made in response to APACC accesses in a manner defined by the AP." +// two such APs: +// * MEM-AP +// * JTAG-AP + + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////// +//! Handles ARM7TDMI JTAG commands. Forwards others to JTAG. +void adiv5handle(unsigned char app, unsigned char verb, unsigned long len){ + unsigned int val; + + switch(verb){ + case START: + //Enter JTAG mode. + adiv5_start(); + txdata(app,verb,0); + break; + case JTAG_IR_SHIFT: + cmddataword[0] = jtagarm_shift_ir(cmddata[0], cmddata[1]); + txdata(app,verb,1); + break; + case JTAG_DR_SHIFT: + jtag_goto_shift_dr(); + if (cmddata[0]>32){ + val = cmddatalong[1]; + cmddatalong[0] = jtagtransn(cmddatalong[1],cmddata[0]-32,cmddata[1]|NOEND); + cmddatalong[1] = jtagtransn(cmddatalong[2],32,cmddata[1]); + txdata(app,verb,5); + } else { + cmddatalong[0] = jtagtransn(cmddatalong[1],cmddata[0],cmddata[1]); + txdata(app,verb,5); + } + tapstate = (cmddata[1]&NORETIDLE)>0?Update_DR:RunTest_Idle; + break; + case JTAGADI_DEBUG_INSTR: + cmddatalong[0] = adiv5_instr_primitive(cmddatalong[0],cmddata[4]); + txdata(app,verb,4); + break; + case JTAGADI_GET_REGISTER: + val = cmddata[0]; + cmddatalong[0] = adiv5_get_register(val); + txdata(app,verb,4); + break; + case JTAGADI_SET_REGISTER: + adiv5_set_register(cmddatalong[1], cmddatalong[0]); + txdata(app,verb,4); + break; + case JTAG_RESETTARGET: + debugstr("RESET TARGET"); + CLRTST; + delay(cmddataword[0]); + SETTST; + txdata(app,verb,4); + break; + + + //case JTAGARM7_STEP_INSTR: +/* case JTAGARM7_READ_CODE_MEMORY: + case JTAGARM7_WRITE_FLASH_PAGE: + case JTAGARM7_READ_FLASH_PAGE: + case JTAGARM7_MASS_ERASE_FLASH: + case JTAGARM7_PROGRAM_FLASH: + case JTAGARM7_LOCKCHIP: + case JTAGARM7_CHIP_ERASE: + */ + default: + jtaghandle(app,verb,len); + } +} + + diff --git a/firmware/include/adiv5.h b/firmware/include/adiv5.h new file mode 100644 index 0000000..1a26a3d --- /dev/null +++ b/firmware/include/adiv5.h @@ -0,0 +1,156 @@ +/*! \file jtagarm7tdmi.h + \brief JTAG handler functions for the ARM family of processors +*/ + +#include "jtag.h" + + +#define JTAGSTATE_ARM 0 // bit 4 on dbg status reg is low +#define JTAGSTATE_THUMB 1 + +unsigned long last_instr = -1; +unsigned char last_sysstate = 0; +unsigned char last_ir = -1; +unsigned char last_scanchain = -1; +unsigned char tapstate = 15; +unsigned char current_dbgstate = -1; +//unsigned char last_halt_debug_state = -1; +//unsigned long last_halt_pc = -1; + + +// JTAGARM7 Commands + +//! Start JTAG +void adiv5_start(void); + +//! Set a 32-bit ARM register +void jtagarm7tdmi_set_register(unsigned long reg, unsigned long val); +//! Get a 32-bit ARM register +unsigned long jtagarm7tdmi_get_register(unsigned long reg); + +// ARM-specific pins +// DBGRQ - GoodFET Pin 8 +#define DBGRQ TST + +/* ARM data +The instruction register is 4 bits in length. +There is no parity bit. +The fixed value 0001 is loaded into the instruction register during the CAPTURE-IR +controller state. +The least significant bit of the instruction register is scanned in and scanned out first. +*/ + +//4-bit ARM JTAG INSTRUCTIONS - STANDARD +#define ADI_IR_ABORT 0x8 +#define ADI_IR_RESERVED1 0x9 +#define ADI_IR_DPACC 0xA +#define ADI_IR_APACC 0xB +#define ADI_IR_RESERVED2 0xC +#define ADI_IR_RESERVED3 0xD +#define ADI_IR_IDCODE 0xE +#define ADI_IR_BYPASS 0xF + + +//4-bit ARM JTAG INSTRUCTIONS - IMPLEMENTATION-DEFINED +#define ADI_IR_EXTEST 0x0 +#define ADI_IR_SAMPLE 0x1 +#define ADI_IR_PRELOAD 0x2 +#define ADI_IR_RESERVED 0x3 +#define ADI_IR_INTEST 0x4 +#define ADI_IR_CLAMP 0x5 +#define ADI_IR_HIGHZ 0x6 +#define ADI_IR_CLAMPZ 0x7 + +// read 3 bit - Debug Control +#define EICE_DBGCTRL 0 +#define EICE_DBGCTRL_BITLEN 3 +// read 5 bit - Debug Status +#define EICE_DBGSTATUS 1 +#define EICE_DBGSTATUS_BITLEN 5 +// read 6 bit - Debug Comms Control Register +#define EICE_DBGCCR 4 +#define EICE_DBGCCR_BITLEN 6 +// r/w 32 bit - Debug Comms Data Register +#define EICE_DBGCDR 5 +// r/w 32 bit - Watchpoint 0 Address +#define EICE_WP0ADDR 8 +// r/w 32 bit - Watchpoint 0 Addres Mask +#define EICE_WP0ADDRMASK 9 +// r/w 32 bit - Watchpoint 0 Data +#define EICE_WP0DATA 10 +// r/w 32 bit - Watchpoint 0 Data Masl +#define EICE_WP0DATAMASK 11 +// r/w 9 bit - Watchpoint 0 Control Value +#define EICE_WP0CTRL 12 +// r/w 8 bit - Watchpoint 0 Control Mask +#define EICE_WP0CTRLMASK 13 +// r/w 32 bit - Watchpoint 0 Address +#define EICE_WP1ADDR 16 +// r/w 32 bit - Watchpoint 0 Addres Mask +#define EICE_WP1ADDRMASK 17 +// r/w 32 bit - Watchpoint 0 Data +#define EICE_WP1DATA 18 +// r/w 32 bit - Watchpoint 0 Data Masl +#define EICE_WP1DATAMASK 19 +// r/w 9 bit - Watchpoint 0 Control Value +#define EICE_WP1CTRL 20 +// r/w 8 bit - Watchpoint 0 Control Mask +#define EICE_WP1CTRLMASK 21 + + +//JTAGARM commands +#define JTAGARM7_GET_REGISTER 0x87 +#define JTAGARM7_SET_REGISTER 0x88 +#define JTAGARM7_DEBUG_INSTR 0x89 +// Really ARM specific stuff +#define JTAGARM7_SET_IR 0x90 +#define JTAGARM7_WAIT_DBG 0x91 +#define JTAGARM7_SHIFT_DR 0x92 +#define JTAGARM7_CHAIN0 0x93 +#define JTAGARM7_SCANCHAIN1 0x94 +#define JTAGARM7_EICE_READ 0x95 +#define JTAGARM7_EICE_WRITE 0x96 + + +// for deeper understanding, read the instruction cycle timing section of: +// http://www.atmel.com/dyn/resources/prod_documents/DDI0029G_7TDMI_R3_trm.pdf +#define EXECNOPARM 0xe1a00000L +#define ARM_INSTR_NOP 0xe1a00000L +#define ARM_INSTR_BX_R0 0xe12fff10L +#define ARM_INSTR_STR_Rx_r14 0xe58f0000L // from atmel docs +#define ARM_READ_REG ARM_INSTR_STR_Rx_r14 +#define ARM_INSTR_LDR_Rx_r14 0xe5900000L // NOT from atmel docs (e59e0000L is from atmel docs) +#define ARM_WRITE_REG ARM_INSTR_LDR_Rx_r14 +#define ARM_INSTR_LDR_R1_r0_4 0xe4901004L +#define ARM_READ_MEM ARM_INSTR_LDR_R1_r0_4 +#define ARM_INSTR_STR_R1_r0_4 0xe4801004L +#define ARM_WRITE_MEM ARM_INSTR_STR_R1_r0_4 +#define ARM_INSTR_MRS_R0_CPSR 0xe10f0000L +#define ARM_INSTR_MSR_cpsr_cxsf_R0 0xe12ff000L +#define ARM_INSTR_STMIA_R14_r0_rx 0xE88E0000L // add up to 65k to indicate which registers... +#define ARM_STORE_MULTIPLE ARM_INSTR_STMIA_R14_r0_rx +#define ARM_INSTR_SKANKREGS 0xE88F7fffL +#define ARM_INSTR_CLOBBEREGS 0xE89F7fffL + +#define ARM_INSTR_B_IMM 0xea000000L +#define ARM_INSTR_BX_PC 0xe12fff10L // need to set r0 to the desired address +#define THUMB_INSTR_LDR_R0_r0 0x68006800L +#define THUMB_WRITE_REG THUMB_INSTR_LDR_R0_r0 +#define THUMB_INSTR_STR_R0_r0 0x60006000L +#define THUMB_READ_REG THUMB_INSTR_STR_R0_r0 +#define THUMB_INSTR_MOV_R0_PC 0x46b846b8L +#define THUMB_INSTR_MOV_PC_R0 0x46474647L +#define THUMB_INSTR_MOV_HiLo 0x46404640L +#define THUMB_INSTR_MOV_LoHi 0x46804680L +#define THUMB_INSTR_BX_PC 0x47784778L +#define THUMB_INSTR_NOP 0x1c001c00L +#define THUMB_SWAP_HiLo 0 +#define THUMB_SWAP_LoHi 1 +#define ARM_REG_PC 15 + +#define JTAG_ARM_DBG_DBGACK 1 +#define JTAG_ARM_DBG_DBGRQ 2 +#define JTAG_ARM_DBG_IFEN 4 +#define JTAG_ARM_DBG_cgenL 8 +#define JTAG_ARM_DBG_TBIT 16 + -- 2.20.1