Lines Matching full:pd

28 static inline bool packet_has_mark(struct osdp_pd *pd)  in packet_has_mark()  argument
30 return ISSET_FLAG(pd, PD_FLAG_PKT_HAS_MARK); in packet_has_mark()
33 static inline void packet_set_mark(struct osdp_pd *pd, bool mark) in packet_set_mark() argument
36 SET_FLAG(pd, PD_FLAG_PKT_HAS_MARK); in packet_set_mark()
38 CLEAR_FLAG(pd, PD_FLAG_PKT_HAS_MARK); in packet_set_mark()
55 static int osdp_phy_get_seq_number(struct osdp_pd *pd, int do_inc) in osdp_phy_get_seq_number() argument
57 /* pd->seq_num is set to -1 to reset phy cmd state */ in osdp_phy_get_seq_number()
59 pd->seq_number += 1; in osdp_phy_get_seq_number()
60 if (pd->seq_number > 3) { in osdp_phy_get_seq_number()
61 pd->seq_number = 1; in osdp_phy_get_seq_number()
64 return pd->seq_number & PKT_CONTROL_SQN; in osdp_phy_get_seq_number()
67 int osdp_phy_packet_get_data_offset(struct osdp_pd *pd, const uint8_t *buf) in osdp_phy_packet_get_data_offset() argument
72 ARG_UNUSED(pd); in osdp_phy_packet_get_data_offset()
73 if (packet_has_mark(pd)) { in osdp_phy_packet_get_data_offset()
84 uint8_t *osdp_phy_packet_get_smb(struct osdp_pd *pd, const uint8_t *buf) in osdp_phy_packet_get_smb() argument
88 ARG_UNUSED(pd); in osdp_phy_packet_get_smb()
89 if (packet_has_mark(pd)) { in osdp_phy_packet_get_smb()
108 int osdp_phy_packet_init(struct osdp_pd *pd, uint8_t *buf, int max_len) in osdp_phy_packet_init() argument
115 LOG_ERR("packet_init: out of space! CMD: %02x", pd->cmd_id); in osdp_phy_packet_init()
120 * In PD mode just follow what we received from CP. In CP mode, as we in osdp_phy_packet_init()
123 if ((is_pd_mode(pd) && packet_has_mark(pd)) || in osdp_phy_packet_init()
124 (is_cp_mode(pd) && !ISSET_FLAG(pd, PD_FLAG_PKT_SKIP_MARK))) { in osdp_phy_packet_init()
128 packet_set_mark(pd, true); in osdp_phy_packet_init()
134 pkt->pd_address = pd->address & 0x7F; /* Use only the lower 7 bits */ in osdp_phy_packet_init()
135 if (is_pd_mode(pd)) { in osdp_phy_packet_init()
136 /* PD must reply with MSB of it's address set */ in osdp_phy_packet_init()
138 id = pd->reply_id; in osdp_phy_packet_init()
140 id = pd->cmd_id; in osdp_phy_packet_init()
142 pkt->control = osdp_phy_get_seq_number(pd, is_cp_mode(pd)); in osdp_phy_packet_init()
145 if (sc_is_active(pd)) { in osdp_phy_packet_init()
149 } else if (osdp_phy_in_sc_handshake(is_pd_mode(pd), id)) { in osdp_phy_packet_init()
158 int osdp_phy_packet_finalize(struct osdp_pd *pd, uint8_t *buf, in osdp_phy_packet_finalize() argument
170 if (packet_has_mark(pd)) { in osdp_phy_packet_finalize()
173 is_cp_mode(pd) ? pd->cmd_id : pd->reply_id); in osdp_phy_packet_finalize()
184 is_cp_mode(pd) ? pd->cmd_id : pd->reply_id); in osdp_phy_packet_finalize()
196 if (sc_is_active(pd) && (pkt->control & PKT_CONTROL_SCB) && pkt->data[1] >= SCS_15) { in osdp_phy_packet_finalize()
219 len += osdp_encrypt_data(pd, is_cp_mode(pd), data, data_len); in osdp_phy_packet_finalize()
231 osdp_compute_mac(pd, is_cp_mode(pd), buf, len); in osdp_phy_packet_finalize()
232 data = is_cp_mode(pd) ? pd->sc.c_mac : pd->sc.r_mac; in osdp_phy_packet_finalize()
247 if (packet_has_mark(pd)) { in osdp_phy_packet_finalize()
254 LOG_ERR("PKT_F: Out of buffer space! CMD(%02x)", pd->cmd_id); in osdp_phy_packet_finalize()
258 int osdp_phy_check_packet(struct osdp_pd *pd, uint8_t *buf, int len, in osdp_phy_check_packet() argument
271 packet_set_mark(pd, false); in osdp_phy_check_packet()
275 packet_set_mark(pd, true); in osdp_phy_check_packet()
286 if (is_cp_mode(pd) && !(pkt->pd_address & 0x80)) { in osdp_phy_check_packet()
300 pd->reply_id = REPLY_NAK; in osdp_phy_check_packet()
301 pd->ephemeral_data[0] = OSDP_PD_NAK_CMD_LEN; in osdp_phy_check_packet()
305 *one_pkt_len = pkt_len + (packet_has_mark(pd) ? 1 : 0); in osdp_phy_check_packet()
314 pd->reply_id = REPLY_NAK; in osdp_phy_check_packet()
315 pd->ephemeral_data[0] = OSDP_PD_NAK_MSG_CHK; in osdp_phy_check_packet()
324 pd->reply_id = REPLY_NAK; in osdp_phy_check_packet()
325 pd->ephemeral_data[0] = OSDP_PD_NAK_MSG_CHK; in osdp_phy_check_packet()
330 /* validate PD address */ in osdp_phy_check_packet()
332 if (pd_addr != pd->address && pd_addr != 0x7F) { in osdp_phy_check_packet()
334 if (is_cp_mode(pd)) { in osdp_phy_check_packet()
335 LOG_ERR("Invalid pd address %d", pd_addr); in osdp_phy_check_packet()
343 if (is_pd_mode(pd)) { in osdp_phy_check_packet()
347 * The current PD implementation does not hold any state in osdp_phy_check_packet()
353 pd->seq_number = -1; in osdp_phy_check_packet()
354 sc_deactivate(pd); in osdp_phy_check_packet()
356 if (comp == pd->seq_number) { in osdp_phy_check_packet()
358 * TODO: PD must resend the last response if CP send the in osdp_phy_check_packet()
362 pd->reply_id = REPLY_NAK; in osdp_phy_check_packet()
363 pd->ephemeral_data[0] = OSDP_PD_NAK_SEQ_NUM; in osdp_phy_check_packet()
369 * Check for receiving a busy reply from the PD which would in osdp_phy_check_packet()
374 pd->seq_number -= 1; in osdp_phy_check_packet()
379 cur = osdp_phy_get_seq_number(pd, is_pd_mode(pd)); in osdp_phy_check_packet()
380 if (cur != comp && !ISSET_FLAG(pd, PD_FLAG_SKIP_SEQ_CHECK)) { in osdp_phy_check_packet()
382 pd->reply_id = REPLY_NAK; in osdp_phy_check_packet()
383 pd->ephemeral_data[0] = OSDP_PD_NAK_SEQ_NUM; in osdp_phy_check_packet()
390 int osdp_phy_decode_packet(struct osdp_pd *pd, uint8_t *buf, int len, in osdp_phy_decode_packet() argument
397 if (packet_has_mark(pd)) { in osdp_phy_decode_packet()
414 if (is_pd_mode(pd) && !sc_is_capable(pd)) { in osdp_phy_decode_packet()
415 LOG_ERR("PD is not SC capable"); in osdp_phy_decode_packet()
416 pd->reply_id = REPLY_NAK; in osdp_phy_decode_packet()
417 pd->ephemeral_data[0] = OSDP_PD_NAK_SC_UNSUP; in osdp_phy_decode_packet()
422 pd->reply_id = REPLY_NAK; in osdp_phy_decode_packet()
423 pd->ephemeral_data[0] = OSDP_PD_NAK_SC_COND; in osdp_phy_decode_packet()
426 if (!sc_is_active(pd) && pkt->data[1] > SCS_14) { in osdp_phy_decode_packet()
428 pd->reply_id = REPLY_NAK; in osdp_phy_decode_packet()
429 pd->ephemeral_data[0] = OSDP_PD_NAK_SC_COND; in osdp_phy_decode_packet()
434 * CP signals PD to use SCBKD by setting SB data byte in osdp_phy_decode_packet()
436 * PD we extract it from the command itself. But this in osdp_phy_decode_packet()
437 * usage of SCBKD is allowed only when the PD is in in osdp_phy_decode_packet()
440 if (ISSET_FLAG(pd, PD_FLAG_INSTALL_MODE) && in osdp_phy_decode_packet()
442 SET_FLAG(pd, PD_FLAG_SC_USE_SCBKD); in osdp_phy_decode_packet()
449 * If the current packet is an ACK for a KEYSET, the PD might in osdp_phy_decode_packet()
458 if (is_cp_mode(pd) && pd->cmd_id == CMD_KEYSET && in osdp_phy_decode_packet()
460 osdp_keyset_complete(pd); in osdp_phy_decode_packet()
463 if (sc_is_active(pd)) { in osdp_phy_decode_packet()
465 pd->reply_id = REPLY_NAK; in osdp_phy_decode_packet()
466 pd->ephemeral_data[0] = OSDP_PD_NAK_SC_COND; in osdp_phy_decode_packet()
471 if (sc_is_active(pd) && in osdp_phy_decode_packet()
474 is_cmd = is_pd_mode(pd); in osdp_phy_decode_packet()
475 osdp_compute_mac(pd, is_cmd, buf, mac_offset); in osdp_phy_decode_packet()
476 mac = is_cmd ? pd->sc.c_mac : pd->sc.r_mac; in osdp_phy_decode_packet()
479 sc_deactivate(pd); in osdp_phy_decode_packet()
480 pd->reply_id = REPLY_NAK; in osdp_phy_decode_packet()
481 pd->ephemeral_data[0] = OSDP_PD_NAK_SC_COND; in osdp_phy_decode_packet()
498 len = osdp_decrypt_data(pd, is_cmd, data + 1, len - 1); in osdp_phy_decode_packet()
501 sc_deactivate(pd); in osdp_phy_decode_packet()
502 pd->reply_id = REPLY_NAK; in osdp_phy_decode_packet()
503 pd->ephemeral_data[0] = OSDP_PD_NAK_SC_COND; in osdp_phy_decode_packet()
508 * If cmd/reply has no data, PD "should" have in osdp_phy_decode_packet()
524 void osdp_phy_state_reset(struct osdp_pd *pd) in osdp_phy_state_reset() argument
527 pd->phy_state = 0; in osdp_phy_state_reset()
529 pd->seq_number = -1; in osdp_phy_state_reset()
530 pd->rx_buf_len = 0; in osdp_phy_state_reset()