MCPcopy Create free account
hub / github.com/ArduPilot/ArduRemoteID / handle_secure_command

Method handle_secure_command

RemoteIDModule/mavlink_secure_command.cpp:13–144  ·  view source on GitHub ↗

handle a SECURE_COMMAND */

Source from the content-addressed store, hash-verified

11 handle a SECURE_COMMAND
12 */
13void MAVLinkSerial::handle_secure_command(const mavlink_secure_command_t &pkt)
14{
15 mavlink_secure_command_reply_t reply {};
16 reply.result = MAV_RESULT_UNSUPPORTED;
17 reply.sequence = pkt.sequence;
18 reply.operation = pkt.operation;
19
20 if (uint16_t(pkt.data_length) + uint16_t(pkt.sig_length) > sizeof(pkt.data)) {
21 reply.result = MAV_RESULT_DENIED;
22 goto send_reply;
23 }
24 if (!check_signature(pkt.sig_length, pkt.data_length, pkt.sequence, pkt.operation, pkt.data)) {
25 reply.result = MAV_RESULT_DENIED;
26 goto send_reply;
27 }
28
29 switch (pkt.operation) {
30
31 case SECURE_COMMAND_GET_SESSION_KEY:
32 case SECURE_COMMAND_GET_REMOTEID_SESSION_KEY: {
33 make_session_key(session_key);
34 reply.data_length = sizeof(session_key);
35 memcpy(reply.data, session_key, reply.data_length);
36 reply.result = MAV_RESULT_ACCEPTED;
37 break;
38 }
39
40 case SECURE_COMMAND_GET_PUBLIC_KEYS: {
41 if (pkt.data_length != 2) {
42 reply.result = MAV_RESULT_UNSUPPORTED;
43 goto send_reply;
44 }
45 const uint8_t key_idx = pkt.data[0];
46 uint8_t num_keys = pkt.data[1];
47 const uint8_t max_fetch = (sizeof(reply.data)-1) / PUBLIC_KEY_LEN;
48 if (key_idx >= MAX_PUBLIC_KEYS ||
49 num_keys > max_fetch ||
50 key_idx+num_keys > MAX_PUBLIC_KEYS ||
51 g.no_public_keys()) {
52 reply.result = MAV_RESULT_FAILED;
53 goto send_reply;
54 }
55
56 for (uint8_t i=0;i<num_keys;i++) {
57 g.get_public_key(i+key_idx, &reply.data[1+i*PUBLIC_KEY_LEN]);
58 }
59
60 reply.data_length = 1+num_keys*PUBLIC_KEY_LEN;
61 reply.data[0] = key_idx;
62 reply.result = MAV_RESULT_ACCEPTED;
63 break;
64 }
65
66 case SECURE_COMMAND_SET_PUBLIC_KEYS: {
67 if (pkt.data_length < PUBLIC_KEY_LEN+1) {
68 reply.result = MAV_RESULT_FAILED;
69 goto send_reply;
70 }

Callers

nothing calls this directly

Calls 5

no_public_keysMethod · 0.80
get_public_keyMethod · 0.80
set_public_keyMethod · 0.80
remove_public_keyMethod · 0.80
set_by_name_stringMethod · 0.80

Tested by

no test coverage detected