Lines Matching +full:- +full:sc

4  * SPDX-License-Identifier: Apache-2.0
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()
78 if (pkt->control & PKT_CONTROL_SCB) { in osdp_phy_packet_get_data_offset()
79 sb_len = pkt->data[0]; in osdp_phy_packet_get_data_offset()
93 if (pkt->control & PKT_CONTROL_SCB) { in osdp_phy_packet_get_smb()
94 return pkt->data; in osdp_phy_packet_get_smb()
115 LOG_ERR("packet_init: out of space! CMD: %02x", pd->cmd_id); in osdp_phy_packet_init()
133 pkt->som = OSDP_PKT_SOM; in osdp_phy_packet_init()
134 pkt->pd_address = pd->address & 0x7F; /* Use only the lower 7 bits */ in osdp_phy_packet_init()
137 pkt->pd_address |= 0x80; 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()
143 pkt->control |= PKT_CONTROL_CRC; in osdp_phy_packet_init()
146 pkt->control |= PKT_CONTROL_SCB; in osdp_phy_packet_init()
147 pkt->data[0] = scb_len = 2; in osdp_phy_packet_init()
148 pkt->data[1] = SCS_15; in osdp_phy_packet_init()
150 pkt->control |= PKT_CONTROL_SCB; in osdp_phy_packet_init()
151 pkt->data[0] = scb_len = 3; in osdp_phy_packet_init()
152 pkt->data[1] = SCS_11; in osdp_phy_packet_init()
164 /* Do a sanity check only; we expect header to be pre-filled */ in osdp_phy_packet_finalize()
173 is_cp_mode(pd) ? pd->cmd_id : pd->reply_id); in osdp_phy_packet_finalize()
178 len -= 1; in osdp_phy_packet_finalize()
179 max_len -= 1; in osdp_phy_packet_finalize()
182 if (pkt->som != OSDP_PKT_SOM) { in osdp_phy_packet_finalize()
184 is_cp_mode(pd) ? pd->cmd_id : pd->reply_id); in osdp_phy_packet_finalize()
189 pkt->len_lsb = BYTE_0(len + 2); in osdp_phy_packet_finalize()
190 pkt->len_msb = BYTE_1(len + 2); 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()
197 if (pkt->data[1] == SCS_17 || pkt->data[1] == SCS_18) { in osdp_phy_packet_finalize()
206 data = pkt->data + pkt->data[0] + 1; in osdp_phy_packet_finalize()
207 data_len = len - (sizeof(struct osdp_packet_header) + in osdp_phy_packet_finalize()
208 pkt->data[0] + 1); in osdp_phy_packet_finalize()
209 len -= data_len; in osdp_phy_packet_finalize()
227 pkt->len_lsb = BYTE_0(len + 2 + 4); in osdp_phy_packet_finalize()
228 pkt->len_msb = BYTE_1(len + 2 + 4); in osdp_phy_packet_finalize()
232 data = is_cp_mode(pd) ? pd->sc.c_mac : pd->sc.r_mac; in osdp_phy_packet_finalize()
254 LOG_ERR("PKT_F: Out of buffer space! CMD(%02x)", pd->cmd_id); in osdp_phy_packet_finalize()
274 len -= 1; in osdp_phy_check_packet()
281 if (pkt->som != OSDP_PKT_SOM) { in osdp_phy_check_packet()
282 LOG_ERR("Invalid SOM 0x%02x", pkt->som); in osdp_phy_check_packet()
286 if (is_cp_mode(pd) && !(pkt->pd_address & 0x80)) { in osdp_phy_check_packet()
292 pkt_len = (pkt->len_msb << 8) | pkt->len_lsb; 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()
308 if (pkt->control & PKT_CONTROL_CRC) { in osdp_phy_check_packet()
309 pkt_len -= 2; /* consume CRC */ 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()
319 pkt_len -= 1; /* consume checksum */ 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()
331 pd_addr = pkt->pd_address & 0x7F; in osdp_phy_check_packet()
332 if (pd_addr != pd->address && pd_addr != 0x7F) { in osdp_phy_check_packet()
342 comp = pkt->control & PKT_CONTROL_SQN; in osdp_phy_check_packet()
348 * between commands so we can just set seq_number to -1 in osdp_phy_check_packet()
353 pd->seq_number = -1; in osdp_phy_check_packet()
356 if (comp == pd->seq_number) { in osdp_phy_check_packet()
361 LOG_ERR("seq-repeat/reply-resend not supported!"); 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()
373 if ((pkt_len == 6) && (pkt->data[0] == REPLY_BUSY)) { in osdp_phy_check_packet()
374 pd->seq_number -= 1; 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()
400 len -= 1; in osdp_phy_decode_packet()
404 len -= pkt->control & PKT_CONTROL_CRC ? 2 : 1; in osdp_phy_decode_packet()
405 mac_offset = len - 4; in osdp_phy_decode_packet()
406 data = pkt->data; in osdp_phy_decode_packet()
407 len -= sizeof(struct osdp_packet_header); in osdp_phy_decode_packet()
413 if (pkt->control & PKT_CONTROL_SCB) { 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()
420 if (pkt->data[1] < SCS_11 || pkt->data[1] > SCS_18) { 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()
432 if (pkt->data[1] == SCS_11 || pkt->data[1] == SCS_13) { in osdp_phy_decode_packet()
441 pkt->data[2] == 0) { in osdp_phy_decode_packet()
445 data = pkt->data + pkt->data[0]; in osdp_phy_decode_packet()
446 len -= pkt->data[0]; /* consume security block */ in osdp_phy_decode_packet()
458 if (is_cp_mode(pd) && pd->cmd_id == CMD_KEYSET && in osdp_phy_decode_packet()
459 pkt->data[0] == REPLY_ACK) { in osdp_phy_decode_packet()
464 LOG_ERR("Received plain-text message in SC"); 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()
472 pkt->control & PKT_CONTROL_SCB && pkt->data[1] >= SCS_15) { in osdp_phy_decode_packet()
476 mac = is_cmd ? pd->sc.c_mac : pd->sc.r_mac; in osdp_phy_decode_packet()
478 LOG_ERR("Invalid MAC; discarding SC"); 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()
484 len -= 4; /* consume MAC */ in osdp_phy_decode_packet()
487 if (pkt->data[1] == SCS_17 || pkt->data[1] == SCS_18) { in osdp_phy_decode_packet()
498 len = osdp_decrypt_data(pd, is_cmd, data + 1, len - 1); in osdp_phy_decode_packet()
500 LOG_ERR("Failed at decrypt; discarding SC"); 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()
513 "length; tolerating non-conformance!"); in osdp_phy_decode_packet()
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()