Implement patty_ax25_addr_copy()

Implement patty_ax25_addr_copy() as a means to copy a patty_ax25_addr
object from one location in memory to another, ensuring that the SSID
field only contains at minimum the station identifier (0-15) and the
reserved bits 0x60
This commit is contained in:
XANTRONIX Development 2020-07-14 17:02:17 -04:00 committed by XANTRONIX Industrial
parent cbae61db27
commit 79d1393e74
2 changed files with 18 additions and 0 deletions

View file

@ -84,4 +84,8 @@ int patty_ax25_ntop(const patty_ax25_addr *addr,
void patty_ax25_addr_hash(uint32_t *hash,
const patty_ax25_addr *addr);
size_t patty_ax25_addr_copy(void *buf,
patty_ax25_addr *addr,
uint8_t ssid_flags);
#endif /* _PATTY_AX25_H */

View file

@ -106,3 +106,17 @@ void patty_ax25_addr_hash(uint32_t *hash, const patty_ax25_addr *addr) {
hash_byte(hash, PATTY_AX25_ADDR_SSID_NUMBER(addr->ssid));
}
size_t patty_ax25_addr_copy(void *buf,
patty_ax25_addr *addr,
uint8_t ssid_flags) {
size_t encoded = 0;
memcpy(buf, addr->callsign, sizeof(addr->callsign));
encoded += sizeof(addr->callsign);
((uint8_t *)buf)[encoded++] = ssid_flags | 0x60 | (addr->ssid & 0x1e);
return encoded;
}