From 5b26cabee3086077c255c322e43890402a821409 Mon Sep 17 00:00:00 2001 From: gardners Date: Fri, 15 Feb 2013 06:41:40 +1030 Subject: [PATCH] fixed bugs in UPPER7 SLIP encapsulation. Improved debugging of the same. --- conf_schema.h | 1 + overlay_interface.c | 13 ++++++++++- slip.c | 57 +++++++++++++++++++++++++++++++-------------- 3 files changed, 52 insertions(+), 19 deletions(-) diff --git a/conf_schema.h b/conf_schema.h index 8ffc44bb..fe274ad4 100644 --- a/conf_schema.h +++ b/conf_schema.h @@ -201,6 +201,7 @@ ATOM(char, broadcasts, 0, cf_opt_char_boolean,, "") ATOM(char, packettx, 0, cf_opt_char_boolean,, "") ATOM(char, packetrx, 0, cf_opt_char_boolean,, "") ATOM(char, packetradio, 0, cf_opt_char_boolean,, "") +ATOM(char, slip, 0, cf_opt_char_boolean,, "") ATOM(char, packetconstruction, 0, cf_opt_char_boolean,, "") ATOM(char, rhizome, 0, cf_opt_char_boolean,, "") ATOM(char, rhizome_tx, 0, cf_opt_char_boolean,, "") diff --git a/overlay_interface.c b/overlay_interface.c index 32aab87e..1370442a 100644 --- a/overlay_interface.c +++ b/overlay_interface.c @@ -729,7 +729,18 @@ overlay_broadcast_ensemble(overlay_interface *interface, bytes, len, buffer+out_len, sizeof(interface->txbuffer) - out_len); if (encoded < 0) return WHY("Buffer overflow"); - + + if (config.debug.slip) + { + // Test decoding of the packet we send + struct slip_decode_state state; + state.encapsulator=SLIP_FORMAT_UPPER7; + state.src_size=encoded; + state.src_offset=0; + state.src=buffer+out_len; + slip_decode(&state); + } + out_len+=encoded; interface->tx_bytes_pending=out_len; diff --git a/slip.c b/slip.c index 3bde5a42..a2c857f0 100644 --- a/slip.c +++ b/slip.c @@ -17,6 +17,7 @@ int slip_encode(int format, L/R RSSI: 48/0 L/R noise: 62/0 pkts: 0 txe=0 rxe=0 stx=0 srx=0 ecc=0/0 temp=21 dco=0 So we are using 0x80-0xff to hold data, and { and } to frame packets. */ + if (config.debug.slip) dump("pre-slipped packet",src,src_bytes); { if (src_bytes<1) return 0; if (src_bytes>0x3fff) @@ -41,7 +42,7 @@ int slip_encode(int format, dst[out_len++]=0x80|((crc>>(25-7-7-7))&0x7f); dst[out_len++]=0x80|((crc>>0)&0x7f); - for(i=0;istate,byte); + // Parse out inline RSSI reports - if (byte>=' '&&byte<=0x7f) { + if (byte=='{') { + state->state=UPPER7_STATE_L1; + state->packet_length=0; + return 0; + } else if (byte=='}') { + // End of packet marker -- report end of received packet to caller + // for CRC verification etc. + state->state=UPPER7_STATE_NOTINPACKET; return 1; + } else if (byte>=' '&&byte<=0x7f) { if (state->rssi_lenrssi_text[state->rssi_len++]=byte; return 0; @@ -132,17 +144,12 @@ int upper7_decode(struct slip_decode_state *state,unsigned char byte) state->rssi_len=0; } - // Non-data bytes + // Non-data bytes (none currently used, but we need to catch them before + // moving onto processing data bytes) if (byte<0x80) { switch (byte) { - case '{': - state->state=UPPER7_STATE_L1; - state->packet_length=0; + default: return 0; - case '}': - // End of packet marker -- report end of received packet to caller - // for CRC verification etc. - state->state=UPPER7_STATE_NOTINPACKET; return 1; } } @@ -177,32 +184,32 @@ int upper7_decode(struct slip_decode_state *state,unsigned char byte) return 0; case UPPER7_STATE_D1: state->dst[state->dst_offset+0]|=(byte>>6)&0x01; - state->dst[state->dst_offset+1]=(byte<<2)&0x7f; + state->dst[state->dst_offset+1]=(byte<<2); state->state++; return 0; case UPPER7_STATE_D2: state->dst[state->dst_offset+1]|=(byte>>5)&0x03; - state->dst[state->dst_offset+2]=(byte<<3)&0x7f; + state->dst[state->dst_offset+2]=(byte<<3); state->state++; return 0; case UPPER7_STATE_D3: state->dst[state->dst_offset+2]|=(byte>>4)&0x07; - state->dst[state->dst_offset+3]=(byte<<4)&0x7f; + state->dst[state->dst_offset+3]=(byte<<4); state->state++; return 0; case UPPER7_STATE_D4: state->dst[state->dst_offset+3]|=(byte>>3)&0x0f; - state->dst[state->dst_offset+4]=(byte<<5)&0x7f; + state->dst[state->dst_offset+4]=(byte<<5); state->state++; return 0; case UPPER7_STATE_D5: state->dst[state->dst_offset+4]|=(byte>>2)&0x1f; - state->dst[state->dst_offset+5]=(byte<<6)&0x7f; + state->dst[state->dst_offset+5]=(byte<<6); state->state++; return 0; case UPPER7_STATE_D6: state->dst[state->dst_offset+5]|=(byte>>1)&0x3f; - state->dst[state->dst_offset+6]=(byte<<7)&0x7f; + state->dst[state->dst_offset+6]=(byte<<7); state->state++; return 0; case UPPER7_STATE_D7: @@ -227,15 +234,29 @@ int slip_decode(struct slip_decode_state *state) return WHYF("SLIP encapsulation not implemented"); case SLIP_FORMAT_UPPER7: { + if (config.debug.slip) { + dump("RX bytes",&state->src[state->src_offset], + state->src_size-state->src_offset); + if (state->rssi_len<0) state->rssi_len=0; + if (state->rssi_len>=RSSI_TEXT_SIZE) state->rssi_len=RSSI_TEXT_SIZE-1; + state->rssi_text[state->rssi_len]=0; + DEBUGF("RX state=%d, rssi_len=%d, rssi_text='%s'", + state->state,state->rssi_len,state->rssi_text); + } while(state->src_offsetsrc_size) if (upper7_decode(state,state->src[state->src_offset++])==1) { + if (config.debug.slip) + dump("de-slipped packet",state->dst,state->packet_length); + // Check that CRC matches unsigned long crc=Crc32_ComputeBuf( 0, state->dst, state->packet_length); if (crc!=state->crc) { - if (config.debug.packetradio) + if (config.debug.slip) DEBUGF("Rejected packet of %d bytes due to CRC mis-match (%08x vs %08x)", state->packet_length,crc,state->crc); - } else { + } else { + if (config.debug.slip) + DEBUGF("Accepted packet of %d bytes (CRC ok)",state->packet_length); return state->packet_length; } }