Lines Matching +full:- +full:sc
4 * SPDX-License-Identifier: Apache-2.0
47 OSDP_PD_ERR_NO_DATA = -1,
48 OSDP_PD_ERR_GENERIC = -2,
49 OSDP_PD_ERR_REPLY = -3,
50 OSDP_PD_ERR_IGNORE = -4,
65 1, /* The PD supports the 16-bit CRC-16 mode */
71 1, /* (Bit-0) AES128 support */
72 1, /* (Bit-0) default AES128 key */
74 0, /* SC not supported */
75 0, /* SC not supported */
114 { -1, 0, 0 } /* Sentinel */
121 if (k_mem_slab_alloc(&pd->event.slab, (void **)&event, K_MSEC(100))) { in pd_event_alloc()
122 LOG_ERR("Memory allocation time-out"); in pd_event_alloc()
130 k_mem_slab_free(&pd->event.slab, (void *)event); in pd_event_free()
135 sys_slist_append(&pd->event.queue, &event->node); in pd_event_enqueue()
142 node = sys_slist_peek_head(&pd->event.queue); in pd_event_dequeue()
144 return -1; in pd_event_dequeue()
146 sys_slist_remove(&pd->event.queue, NULL, node); in pd_event_dequeue()
155 switch (event->type) { in pd_translate_event()
157 if (event->cardread.format == OSDP_CARD_FMT_RAW_UNSPECIFIED || in pd_translate_event()
158 event->cardread.format == OSDP_CARD_FMT_RAW_WIEGAND) { in pd_translate_event()
160 } else if (event->cardread.format == OSDP_CARD_FMT_ASCII) { in pd_translate_event()
171 LOG_ERR("Unknown event type %d", event->type); in pd_translate_event()
178 memcpy(pd->ephemeral_data, event, sizeof(struct osdp_event)); in pd_translate_event()
186 ret = pd->command_callback(pd->command_callback_arg, cmd); in do_command_callback()
188 pd->reply_id = REPLY_NAK; in do_command_callback()
189 pd->ephemeral_data[0] = OSDP_PD_NAK_RECORD; in do_command_callback()
200 switch (pd->cmd_id) { in pd_cmd_cap_ok()
202 cap = &pd->cap[OSDP_PD_CAP_CONTACT_STATUS_MONITORING]; in pd_cmd_cap_ok()
203 if (cap->num_items == 0 || cap->compliance_level == 0) { in pd_cmd_cap_ok()
208 cap = &pd->cap[OSDP_PD_CAP_OUTPUT_CONTROL]; in pd_cmd_cap_ok()
209 if (cap->num_items == 0 || cap->compliance_level == 0) { in pd_cmd_cap_ok()
214 cap = &pd->cap[OSDP_PD_CAP_OUTPUT_CONTROL]; in pd_cmd_cap_ok()
215 if (!cmd || cap->compliance_level == 0 || in pd_cmd_cap_ok()
216 cmd->output.output_no + 1 > cap->num_items) { in pd_cmd_cap_ok()
221 cap = &pd->cap[OSDP_PD_CAP_READER_LED_CONTROL]; in pd_cmd_cap_ok()
222 if (!cmd || cap->compliance_level == 0 || in pd_cmd_cap_ok()
223 cmd->led.led_number + 1 > cap->num_items) { in pd_cmd_cap_ok()
228 cap = &pd->cap[OSDP_PD_CAP_READER_AUDIBLE_OUTPUT]; in pd_cmd_cap_ok()
229 if (cap->num_items == 0 || cap->compliance_level == 0) { in pd_cmd_cap_ok()
234 cap = &pd->cap[OSDP_PD_CAP_READER_TEXT_OUTPUT]; in pd_cmd_cap_ok()
235 if (cap->num_items == 0 || cap->compliance_level == 0) { in pd_cmd_cap_ok()
242 cap = &pd->cap[OSDP_PD_CAP_COMMUNICATION_SECURITY]; in pd_cmd_cap_ok()
243 if (cap->compliance_level == 0) { in pd_cmd_cap_ok()
244 pd->reply_id = REPLY_NAK; in pd_cmd_cap_ok()
245 pd->ephemeral_data[0] = OSDP_PD_NAK_SC_UNSUP; in pd_cmd_cap_ok()
251 pd->reply_id = REPLY_NAK; in pd_cmd_cap_ok()
252 pd->ephemeral_data[0] = OSDP_PD_NAK_CMD_UNKNOWN; in pd_cmd_cap_ok()
254 "Reply with NAK_CMD_UNKNOWN", pd->cmd_id); in pd_cmd_cap_ok()
265 pd->reply_id = 0; in pd_decode_command()
266 pd->cmd_id = cmd.id = buf[pos++]; in pd_decode_command()
267 len--; in pd_decode_command()
269 switch (pd->cmd_id) { in pd_decode_command()
277 pd->reply_id = ret; in pd_decode_command()
280 pd->reply_id = REPLY_ACK; in pd_decode_command()
288 pd->reply_id = REPLY_LSTATR; in pd_decode_command()
299 pd->reply_id = REPLY_ISTATR; in pd_decode_command()
310 pd->reply_id = REPLY_OSTATR; in pd_decode_command()
317 pd->reply_id = REPLY_RSTATR; in pd_decode_command()
325 pd->reply_id = REPLY_PDID; in pd_decode_command()
333 pd->reply_id = REPLY_PDCAP; in pd_decode_command()
337 if (len != CMD_OUT_DATA_LEN || !pd->command_callback) { in pd_decode_command()
352 pd->reply_id = REPLY_ACK; in pd_decode_command()
356 if (len != CMD_LED_DATA_LEN || !pd->command_callback) { in pd_decode_command()
383 pd->reply_id = REPLY_ACK; in pd_decode_command()
387 if (len != CMD_BUZ_DATA_LEN || !pd->command_callback) { in pd_decode_command()
403 pd->reply_id = REPLY_ACK; in pd_decode_command()
407 if (len < CMD_TEXT_DATA_LEN || !pd->command_callback) { in pd_decode_command()
418 ((len - CMD_TEXT_DATA_LEN) < cmd.text.length) || in pd_decode_command()
430 pd->reply_id = REPLY_ACK; in pd_decode_command()
434 if (len != CMD_COMSET_DATA_LEN || !pd->command_callback) { in pd_decode_command()
450 cmd.comset.address = pd->address; in pd_decode_command()
451 cmd.comset.baud_rate = pd->baud_rate; in pd_decode_command()
458 memcpy(pd->ephemeral_data, &cmd, sizeof(struct osdp_cmd)); in pd_decode_command()
459 pd->reply_id = REPLY_COM; in pd_decode_command()
482 pd->reply_id = REPLY_NAK; in pd_decode_command()
483 pd->ephemeral_data[0] = OSDP_PD_NAK_SC_COND; in pd_decode_command()
484 LOG_ERR("Keyset with SC inactive"); in pd_decode_command()
491 if (!pd->command_callback) { in pd_decode_command()
492 LOG_ERR("Keyset without a command callback! The SC new " in pd_decode_command()
497 memcpy(pd->sc.scbk, cmd.keyset.data, 16); in pd_decode_command()
501 pd->reply_id = REPLY_ACK; in pd_decode_command()
514 memcpy(pd->sc.cp_random, buf + pos, 8); in pd_decode_command()
515 pd->reply_id = REPLY_CCRYPT; in pd_decode_command()
527 pd->reply_id = REPLY_NAK; in pd_decode_command()
528 pd->ephemeral_data[0] = OSDP_PD_NAK_SC_COND; in pd_decode_command()
532 memcpy(pd->sc.cp_cryptogram, buf + pos, CMD_SCRYPT_DATA_LEN); in pd_decode_command()
533 pd->reply_id = REPLY_RMAC_I; in pd_decode_command()
538 LOG_ERR("Unknown CMD(%02x)", pd->cmd_id); in pd_decode_command()
539 pd->reply_id = REPLY_NAK; in pd_decode_command()
540 pd->ephemeral_data[0] = OSDP_PD_NAK_CMD_UNKNOWN; in pd_decode_command()
546 pd->cmd_id, len, ret); in pd_decode_command()
547 pd->reply_id = REPLY_NAK; in pd_decode_command()
548 pd->ephemeral_data[0] = OSDP_PD_NAK_CMD_LEN; in pd_decode_command()
552 if (pd->cmd_id != CMD_POLL) { in pd_decode_command()
553 LOG_DBG("CMD: %02x REPLY: %02x", pd->cmd_id, pd->reply_id); in pd_decode_command()
571 * -ve: error
584 max_len -= data_off; in pd_build_reply()
586 switch (pd->reply_id) { in pd_build_reply()
591 buf[len++] = pd->reply_id; in pd_build_reply()
598 buf[len++] = pd->reply_id; in pd_build_reply()
600 buf[len++] = BYTE_0(pd->id.vendor_code); in pd_build_reply()
601 buf[len++] = BYTE_1(pd->id.vendor_code); in pd_build_reply()
602 buf[len++] = BYTE_2(pd->id.vendor_code); in pd_build_reply()
604 buf[len++] = pd->id.model; in pd_build_reply()
605 buf[len++] = pd->id.version; in pd_build_reply()
607 buf[len++] = BYTE_0(pd->id.serial_number); in pd_build_reply()
608 buf[len++] = BYTE_1(pd->id.serial_number); in pd_build_reply()
609 buf[len++] = BYTE_2(pd->id.serial_number); in pd_build_reply()
610 buf[len++] = BYTE_3(pd->id.serial_number); in pd_build_reply()
612 buf[len++] = BYTE_3(pd->id.firmware_version); in pd_build_reply()
613 buf[len++] = BYTE_2(pd->id.firmware_version); in pd_build_reply()
614 buf[len++] = BYTE_1(pd->id.firmware_version); in pd_build_reply()
621 buf[len++] = pd->reply_id; in pd_build_reply()
623 if (pd->cap[i].function_code != i) { in pd_build_reply()
631 buf[len++] = pd->cap[i].compliance_level; in pd_build_reply()
632 buf[len++] = pd->cap[i].num_items; in pd_build_reply()
633 max_len -= REPLY_PDCAP_ENTITY_LEN; in pd_build_reply()
641 buf[len++] = pd->reply_id; in pd_build_reply()
650 buf[len++] = pd->reply_id; in pd_build_reply()
655 event = (struct osdp_event *)pd->ephemeral_data; in pd_build_reply()
656 if (!check_buf_len(REPLY_KEYPAD_LEN + event->keypress.length, max_len)) { in pd_build_reply()
659 buf[len++] = pd->reply_id; in pd_build_reply()
660 buf[len++] = (uint8_t)event->keypress.reader_no; in pd_build_reply()
661 buf[len++] = (uint8_t)event->keypress.length; in pd_build_reply()
662 memcpy(buf + len, event->keypress.data, event->keypress.length); in pd_build_reply()
663 len += event->keypress.length; in pd_build_reply()
669 event = (struct osdp_event *)pd->ephemeral_data; in pd_build_reply()
670 len_bytes = (event->cardread.length + 7) / 8; in pd_build_reply()
674 buf[len++] = pd->reply_id; in pd_build_reply()
675 buf[len++] = (uint8_t)event->cardread.reader_no; in pd_build_reply()
676 buf[len++] = (uint8_t)event->cardread.format; in pd_build_reply()
677 buf[len++] = BYTE_0(event->cardread.length); in pd_build_reply()
678 buf[len++] = BYTE_1(event->cardread.length); in pd_build_reply()
679 memcpy(buf + len, event->cardread.data, len_bytes); in pd_build_reply()
685 event = (struct osdp_event *)pd->ephemeral_data; in pd_build_reply()
686 if (!check_buf_len(REPLY_FMT_LEN + event->cardread.length, max_len)) { in pd_build_reply()
689 buf[len++] = pd->reply_id; in pd_build_reply()
690 buf[len++] = (uint8_t)event->cardread.reader_no; in pd_build_reply()
691 buf[len++] = (uint8_t)event->cardread.direction; in pd_build_reply()
692 buf[len++] = (uint8_t)event->cardread.length; in pd_build_reply()
693 memcpy(buf + len, event->cardread.data, event->cardread.length); in pd_build_reply()
694 len += event->cardread.length; in pd_build_reply()
706 * pd->addr/pd->baud_rate. in pd_build_reply()
708 * TODO: Persist pd->address and pd->baud_rate via in pd_build_reply()
711 cmd = (struct osdp_cmd *)pd->ephemeral_data; in pd_build_reply()
712 buf[len++] = pd->reply_id; in pd_build_reply()
713 buf[len++] = cmd->comset.address; in pd_build_reply()
714 buf[len++] = BYTE_0(cmd->comset.baud_rate); in pd_build_reply()
715 buf[len++] = BYTE_1(cmd->comset.baud_rate); in pd_build_reply()
716 buf[len++] = BYTE_2(cmd->comset.baud_rate); in pd_build_reply()
717 buf[len++] = BYTE_3(cmd->comset.baud_rate); in pd_build_reply()
719 pd->address = (int)cmd->comset.address; in pd_build_reply()
720 pd->baud_rate = (int)cmd->comset.baud_rate; in pd_build_reply()
721 LOG_INF("COMSET Succeeded! New PD-Addr: %d; Baud: %d", in pd_build_reply()
722 pd->address, pd->baud_rate); in pd_build_reply()
729 buf[len++] = pd->reply_id; in pd_build_reply()
730 buf[len++] = pd->ephemeral_data[0]; in pd_build_reply()
741 osdp_fill_random(pd->sc.pd_random, 8); in pd_build_reply()
744 buf[len++] = pd->reply_id; in pd_build_reply()
745 memcpy(buf + len, pd->sc.pd_client_uid, 8); in pd_build_reply()
746 memcpy(buf + len + 8, pd->sc.pd_random, 8); in pd_build_reply()
747 memcpy(buf + len + 16, pd->sc.pd_cryptogram, 16); in pd_build_reply()
762 buf[len++] = pd->reply_id; in pd_build_reply()
763 memcpy(buf + len, pd->sc.r_mac, 16); in pd_build_reply()
770 pd->sc_tstamp = osdp_millis_now(); in pd_build_reply()
772 LOG_WRN("SC Active with SCBK-D"); in pd_build_reply()
774 LOG_INF("SC Active"); in pd_build_reply()
795 pd->reply_id); in pd_build_reply()
812 len = osdp_phy_packet_init(pd, pd->rx_buf, sizeof(pd->rx_buf)); in pd_send_reply()
818 ret = pd_build_reply(pd, pd->rx_buf, sizeof(pd->rx_buf)); in pd_send_reply()
825 len = osdp_phy_packet_finalize(pd, pd->rx_buf, len, sizeof(pd->rx_buf)); in pd_send_reply()
831 if (pd->channel.flush) { in pd_send_reply()
832 pd->channel.flush(pd->channel.data); in pd_send_reply()
835 ret = pd->channel.send(pd->channel.data, pd->rx_buf, len); in pd_send_reply()
842 if (pd->cmd_id != CMD_POLL) { in pd_send_reply()
843 osdp_dump("PD sent", pd->rx_buf, len); in pd_send_reply()
855 err = osdp_phy_check_packet(pd, pd->rx_buf, pd->rx_buf_len, one_pkt_len); in pd_decode_packet()
870 return err; /* propagate other errors as-is */ in pd_decode_packet()
873 len = osdp_phy_decode_packet(pd, pd->rx_buf, *one_pkt_len, &buf); in pd_decode_packet()
889 buf = pd->rx_buf + pd->rx_buf_len; in pd_receive_and_process_command()
890 remaining = sizeof(pd->rx_buf) - pd->rx_buf_len; in pd_receive_and_process_command()
892 len = pd->channel.recv(pd->channel.data, buf, remaining); in pd_receive_and_process_command()
898 * We received some data on the bus; update pd->tstamp. A rouge CP can in pd_receive_and_process_command()
903 pd->tstamp = osdp_millis_now(); in pd_receive_and_process_command()
904 pd->rx_buf_len += len; in pd_receive_and_process_command()
912 if (pd->rx_buf_len > 8 && in pd_receive_and_process_command()
913 pd->rx_buf[6] != CMD_POLL && pd->rx_buf[8] != CMD_POLL) { in pd_receive_and_process_command()
914 osdp_dump("PD received", pd->rx_buf, pd->rx_buf_len); in pd_receive_and_process_command()
925 remaining = pd->rx_buf_len - len; in pd_receive_and_process_command()
927 memmove(pd->rx_buf, pd->rx_buf + len, remaining); in pd_receive_and_process_command()
934 pd->rx_buf_len = remaining; in pd_receive_and_process_command()
942 if (pd->channel.flush) { in pd_error_reset()
943 pd->channel.flush(pd->channel.data); in pd_error_reset()
945 pd->rx_buf_len = 0; in pd_error_reset()
959 osdp_millis_since(pd->sc_tstamp) > OSDP_PD_SC_TIMEOUT_MS) { in osdp_update()
960 LOG_INF("PD SC session timeout!"); in osdp_update()
972 if (pd->rx_buf_len == 0 || in osdp_update()
973 osdp_millis_since(pd->tstamp) < OSDP_RESP_TOUT_MS) { in osdp_update()
976 LOG_DBG("rx_buf: %d", pd->rx_buf_len); in osdp_update()
977 osdp_dump("Buf", pd->rx_buf, pd->rx_buf_len); in osdp_update()
981 LOG_ERR("CMD receive error/timeout - err:%d", ret); in osdp_update()
988 pd->sc_tstamp = osdp_millis_now(); in osdp_update()
1011 while (cap && ((fc = cap->function_code) > 0)) { in osdp_pd_set_attributes()
1015 pd->cap[fc].function_code = cap->function_code; in osdp_pd_set_attributes()
1016 pd->cap[fc].compliance_level = cap->compliance_level; in osdp_pd_set_attributes()
1017 pd->cap[fc].num_items = cap->num_items; in osdp_pd_set_attributes()
1021 memcpy(&pd->id, id, sizeof(struct osdp_pd_id)); in osdp_pd_set_attributes()
1031 return -1; in osdp_setup()
1041 memcpy(pd->sc.scbk, key, 16); in osdp_setup()
1048 /* --- Exported Methods --- */
1054 pd->command_callback_arg = arg; in osdp_pd_set_command_callback()
1055 pd->command_callback = cb; in osdp_pd_set_command_callback()
1065 return -1; in osdp_pd_notify_event()