diff --git a/Core/Inc/ax25.h b/Core/Inc/ax25.h index 3cd4087..32d7827 100644 --- a/Core/Inc/ax25.h +++ b/Core/Inc/ax25.h @@ -29,6 +29,28 @@ along with VP-Digi. If not, see . //for AX.25 329 bytes is the theoretical max size assuming 2-byte Control, 1-byte PID, 256-byte info field and 8 digi address fields #define AX25_FRAME_MAX_SIZE (329) //single frame max length +/** + * @brief Extract SSID from SSID byte in AX.25 frame + * @param byte Byte containing SSID + * @return Decoded SSID (0-15) + */ +#define EXTRACT_SSID(byte) (((byte) >> 1) & 0xF) + +/** + * @brief H-bit (has been repeated) mask + */ +#define H_BIT_MASK 0x80 + +/** + * @brief Reserved bits in AX.25 SSID + */ +#define SSID_RESERVED_MASK 0x60 + +/** + * @brief C-bit (end of path) mask + */ +#define C_BIT_MASK 0x1 + enum Ax25RxStage { RX_STAGE_IDLE = 0, diff --git a/Core/Src/beacon.c b/Core/Src/beacon.c index c36d2fc..f41521b 100644 --- a/Core/Src/beacon.c +++ b/Core/Src/beacon.c @@ -49,7 +49,7 @@ void BeaconSend(uint8_t number) for(uint8_t i = 0; i < sizeof(GeneralConfig.call); i++) //add source address buf[idx++] = GeneralConfig.call[i]; - buf[idx++] = ((GeneralConfig.callSsid << 1) + 0b01100000); //add source ssid + buf[idx++] = ((GeneralConfig.callSsid << 1) | SSID_RESERVED_MASK); //add source ssid if(BeaconConfig[number].path[0] > 0) //this BeaconConfig has some path set { @@ -60,7 +60,7 @@ void BeaconSend(uint8_t number) buf[idx] = BeaconConfig[number].path[i]; //copy path if((i == 6) || (i == 13)) //it was and ssid { - buf[idx] = ((buf[idx] << 1) + 0b01100000); //add appropriate bits for ssid + buf[idx] = ((buf[idx] << 1) | SSID_RESERVED_MASK); //add appropriate bits for ssid } idx++; } @@ -68,7 +68,7 @@ void BeaconSend(uint8_t number) break; //end here } } - buf[idx - 1] |= 1; //add c-bit on the last element + buf[idx - 1] |= C_BIT_MASK; //add c-bit on the last element buf[idx++] = 0x03; //control buf[idx++] = 0xF0; //pid for(uint8_t i = 0; i < strlen((char*)BeaconConfig[number].data); i++) diff --git a/Core/Src/common.c b/Core/Src/common.c index c4e141e..1cda0a5 100644 --- a/Core/Src/common.c +++ b/Core/Src/common.c @@ -101,7 +101,7 @@ static void sendTNC2ToUart(Uart *uart, uint8_t *from, uint16_t len) } } - uint8_t ssid = ((from[13] >> 1) & 0b00001111); //store ssid + uint8_t ssid = EXTRACT_SSID(from[13]); //store ssid if(ssid > 0) //SSID >0 { UartSendByte(uart, '-'); //add - @@ -117,7 +117,7 @@ static void sendTNC2ToUart(Uart *uart, uint8_t *from, uint16_t len) UartSendByte(uart, from[i] >> 1); } } - ssid = ((from[6] >> 1) & 0b00001111); //store ssid + ssid = EXTRACT_SSID(from[6]); //store ssid if(ssid > 0) //SSID >0 { @@ -141,20 +141,20 @@ static void sendTNC2ToUart(Uart *uart, uint8_t *from, uint16_t len) } } - ssid = ((from[nextPathEl + 6] >> 1) & 0b00001111); //store ssid + ssid = EXTRACT_SSID(from[nextPathEl + 6]); //store ssid if(ssid > 0) //SSID >0 { UartSendByte(uart, '-'); //add - UartSendNumber(uart, ssid); } - if((from[nextPathEl + 6] & 0x80)) //h-bit in ssid + if((from[nextPathEl + 6] & H_BIT_MASK)) //h-bit in ssid UartSendByte(uart, '*'); //add * nextPathEl += 7; //next path element if(nextPathEl > 56) //too many path elements break; } - while((from[nextPathEl - 1] & 1) == 0); //loop until the c-bit is found + while((from[nextPathEl - 1] & C_BIT_MASK) == 0); //loop until the c-bit is found } diff --git a/Core/Src/digipeater.c b/Core/Src/digipeater.c index 9b64c63..4b9efc1 100644 --- a/Core/Src/digipeater.c +++ b/Core/Src/digipeater.c @@ -210,7 +210,7 @@ static void makeFrame(uint8_t *frame, uint16_t elStart, uint16_t len, uint32_t h if(!filterFrameCheck(&frame[7], alias)) //push source callsign through the filter return; } - uint8_t ssid = (frame[elStart + 6] >> 1) - 48; //store SSID (N) + uint8_t ssid = EXTRACT_SSID(frame[elStart + 6]); //store SSID (N) if(alias < 8) @@ -241,8 +241,8 @@ static void makeFrame(uint8_t *frame, uint16_t elStart, uint16_t len, uint32_t h for(uint8_t i = 0; i < sizeof(GeneralConfig.call); i++) //replace with own call buffer[elStart + i] = GeneralConfig.call[i]; - buffer[elStart + 6] &= 1; //clear everything but path end bit - buffer[elStart + 6] |= ((GeneralConfig.callSsid << 1) + 0b11100000); //insert ssid and h-bit + buffer[elStart + 6] &= C_BIT_MASK; //clear everything but path end bit + buffer[elStart + 6] |= ((GeneralConfig.callSsid << 1) | H_BIT_MASK | SSID_RESERVED_MASK); //insert ssid and h-bit } } else //standard n-N alias @@ -263,7 +263,7 @@ static void makeFrame(uint8_t *frame, uint16_t elStart, uint16_t len, uint32_t h for(uint8_t i = 0; i < sizeof(GeneralConfig.call); i++) //insert own call buffer[(*index)++] = GeneralConfig.call[i]; - buffer[(*index)++] = ((GeneralConfig.callSsid << 1) + 0b11100000); //insert ssid and h-bit + buffer[(*index)++] = ((GeneralConfig.callSsid << 1) | H_BIT_MASK | SSID_RESERVED_MASK); //insert ssid and h-bit shift = 7; //additional shift when own call is inserted } @@ -274,9 +274,9 @@ static void makeFrame(uint8_t *frame, uint16_t elStart, uint16_t len, uint32_t h } buffer[elStart + shift + 6] -= 2; //decrement SSID in alias (2 because ssid is shifted left by 1) - if((buffer[elStart + shift + 6] & 0b11110) == 0) //if SSID is 0 + if(EXTRACT_SSID(buffer[elStart + shift + 6]) == 0) //if SSID is 0 { - buffer[elStart + shift + 6] += 0x80; //add h-bit + buffer[elStart + shift + 6] |= H_BIT_MASK; //add h-bit } } @@ -314,7 +314,7 @@ void DigiDigipeat(uint8_t *frame, uint16_t len) return; uint16_t t = 13; //start from first byte that can contain path end bit - while((frame[t] & 1) == 0) //look for path end + while((frame[t] & C_BIT_MASK) == 0) //look for path end { if((t + 7) >= len) return; @@ -347,7 +347,7 @@ void DigiDigipeat(uint8_t *frame, uint16_t len) } - while((frame[t] & 0x80) == 0) //look for h-bit + while((frame[t] & H_BIT_MASK) == 0) //look for h-bit { if(t == 13) { @@ -357,7 +357,7 @@ void DigiDigipeat(uint8_t *frame, uint16_t len) } t++; //now t is the index for the first byte in path element we want to process - uint8_t ssid = ((frame[t + 6] >> 1) - 0b00110000); //current path element SSID + uint8_t ssid = EXTRACT_SSID(frame[t + 6]); //current path element SSID uint8_t err = 0; @@ -416,7 +416,7 @@ void DigiDigipeat(uint8_t *frame, uint16_t len) if(err == 0) //alias matching, check further { - uint8_t n = ((frame[t + j] >> 1) - 48); //get n from alias (e.g. WIDEn-N) - N is in ssid variable + uint8_t n = ((frame[t + j] >> 1) - '0'); //get n from alias (e.g. WIDEn-N) - N is in ssid variable //every path must meet several requirements //say we have a WIDEn-N path. Then: diff --git a/lwfec b/lwfec index c4b8bbf..97d1753 160000 --- a/lwfec +++ b/lwfec @@ -1 +1 @@ -Subproject commit c4b8bbf1ff6fa1b3f6fa1a584eab6fb42732a91b +Subproject commit 97d1753fda01372fe45b3c3b8ca6d28f1eddab98