Skip to content

Commit

Permalink
libosdp: Set PD address to 0x7F for broadcast packets
Browse files Browse the repository at this point in the history
According to the OSDP specification, section "5.9 Packet Format", the PD
has to respond to broadcast packets with address 0x7F instead of it's
own. This patch addresses this issue.

Fixes: #143
Signed-off-by: Siddharth Chandrasekaran <[email protected]>
  • Loading branch information
sidcha committed Dec 9, 2023
1 parent 068bf59 commit 02c41cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/osdp_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ union osdp_ephemeral_data {
#define PD_FLAG_PKT_HAS_MARK BIT(11) /* Packet has mark byte */
#define PD_FLAG_HAS_SCBK BIT(12) /* PD has a dedicated SCBK */
#define PD_FLAG_SC_DISABLED BIT(13) /* master_key=NULL && scbk=NULL */
#define PD_FLAG_PKT_BROADCAST BIT(14) /* this packet was addressed to 0x7F */

enum osdp_cp_phy_state_e {
OSDP_CP_PHY_STATE_IDLE,
Expand Down
13 changes: 13 additions & 0 deletions src/osdp_phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ int osdp_phy_packet_init(struct osdp_pd *pd, uint8_t *buf, int max_len)
pkt->pd_address = pd->address & 0x7F; /* Use only the lower 7 bits */
if (is_pd_mode(pd)) {
/* PD must reply with MSB of it's address set */
if (ISSET_FLAG(pd, PD_FLAG_PKT_BROADCAST)) {
pkt->pd_address = 0x7F; /* made 0xFF below */
CLEAR_FLAG(pd, PD_FLAG_PKT_BROADCAST);
}
pkt->pd_address |= 0x80;
id = pd->reply_id;
} else {
Expand Down Expand Up @@ -446,6 +450,15 @@ static int phy_check_packet(struct osdp_pd *pd, uint8_t *buf, int pkt_len)
pd->seq_number -= 1;
LOG_INF("received a sequence repeat packet!");
}
/**
* For packets addressed to the broadcast address, the reply
* must have address set to 0x7F and not the current PD's
* address. To handle this case, let's capture this state in PD
* flags.
*/
if (pd_addr == 0x7F) {
SET_FLAG(pd, PD_FLAG_PKT_BROADCAST);
}
} else {
if (comp == 0) {
/**
Expand Down

0 comments on commit 02c41cc

Please sign in to comment.