Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
address_book.c
Go to the documentation of this file.
1/*****************************************************************************
2 * (c) 2026 Ledger SAS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
43
44/* Includes ------------------------------------------------------------------*/
45#include <string.h>
46#include "os_apdu.h"
47#include "os_helpers.h"
48#include "os_print.h"
49#include "os_utils.h"
50#include "address_book.h"
51#include "apdu_chunks.h"
52#include "status_words.h"
53#include "identity.h"
54#ifdef HAVE_ADDRESS_BOOK_LEDGER_ACCOUNT
55#include "ledger_account.h"
56#endif
57
58#if defined(HAVE_ADDRESS_BOOK)
59
60/* Private defines------------------------------------------------------------*/
61#define P1_REGISTER_IDENTITY 0x01
62#define P1_EDIT_CONTACT_NAME 0x02
63#define P1_EDIT_IDENTIFIER 0x03
64#define P1_EDIT_SCOPE 0x04
65#define P1_PROVIDE_CONTACT 0x20
66
67#ifdef HAVE_ADDRESS_BOOK_LEDGER_ACCOUNT
68#define P1_REGISTER_LEDGER_ACCOUNT 0x11
69#define P1_EDIT_LEDGER_ACCOUNT 0x12
70#define P1_PROVIDE_LEDGER_ACCOUNT_CONTACT 0x21
71#endif
72
73/* Exported functions --------------------------------------------------------*/
74bolos_err_t addr_book_handle_apdu(uint8_t *buffer, size_t buffer_len, uint8_t p1, uint8_t p2)
75{
76 bolos_err_t err = SWO_CONDITIONS_NOT_SATISFIED;
77 uint8_t *payload = NULL;
78 size_t payload_len = 0;
79
80 // All sub-commands share the same chunked transport: reassemble the full
81 // payload first, then dispatch on P1. Intermediate chunks return success
82 // (an intermediate SW is sent) and wait for the next chunk.
84 APDU_CHUNKS_OWNER_ADDRESS_BOOK, buffer, buffer_len, p2, &payload, &payload_len)) {
86 return SWO_INCORRECT_DATA;
88 return SWO_SUCCESS;
90 break;
91 }
92
93 switch (p1) {
95 err = register_identity(payload, payload_len);
96 break;
97
99 err = edit_contact_name(payload, payload_len);
100 break;
101
103 err = edit_identifier(payload, payload_len);
104 break;
105
106 case P1_EDIT_SCOPE:
107 err = edit_scope(payload, payload_len);
108 break;
109
111 err = provide_contact(payload, payload_len);
112 break;
113
114#ifdef HAVE_ADDRESS_BOOK_LEDGER_ACCOUNT
116 err = register_ledger_account(payload, payload_len);
117 break;
118
120 err = edit_ledger_account(payload, payload_len);
121 break;
122
124 err = provide_ledger_account_contact(payload, payload_len);
125 break;
126#endif // HAVE_ADDRESS_BOOK_LEDGER_ACCOUNT
127
128 default:
129 break;
130 }
131
132 return err;
133}
134#endif // HAVE_ADDRESS_BOOK
#define P1_PROVIDE_CONTACT
#define P1_EDIT_SCOPE
#define P1_PROVIDE_LEDGER_ACCOUNT_CONTACT
#define P1_REGISTER_IDENTITY
#define P1_EDIT_IDENTIFIER
#define P1_EDIT_LEDGER_ACCOUNT
bolos_err_t addr_book_handle_apdu(uint8_t *buffer, size_t buffer_len, uint8_t p1, uint8_t p2)
#define P1_EDIT_CONTACT_NAME
#define P1_REGISTER_LEDGER_ACCOUNT
Chunked APDU payload reassembly shared by the SDK app features.
@ APDU_CHUNKS_OWNER_ADDRESS_BOOK
Definition apdu_chunks.h:42
@ APDU_CHUNKS_ERROR
Protocol error; the payload in progress is dropped.
Definition apdu_chunks.h:37
@ APDU_CHUNKS_PENDING
More chunks needed.
Definition apdu_chunks.h:35
@ APDU_CHUNKS_COMPLETE
Full payload assembled; out_buf/out_len are valid.
Definition apdu_chunks.h:36
apdu_chunks_status_t apdu_chunks_reassemble(apdu_chunks_owner_t owner, const uint8_t *data, size_t len, uint8_t p2, uint8_t **out_buf, size_t *out_len)
Reassemble a multi-chunk APDU payload.
Register / Edit Contact Name / Edit Scope / Edit Identifier.
bolos_err_t provide_contact(uint8_t *buffer_in, size_t buffer_in_length)
Deliver a verified contact to the coin application.
bolos_err_t register_identity(uint8_t *buffer_in, size_t buffer_in_length)
Register a new identity.
bolos_err_t edit_scope(uint8_t *buffer_in, size_t buffer_in_length)
Edit the SCOPE of an existing Identity contact.
bolos_err_t edit_identifier(uint8_t *buffer_in, size_t buffer_in_length)
Edit the IDENTIFIER of an existing Identity contact.
bolos_err_t edit_contact_name(uint8_t *buffer_in, size_t buffer_in_length)
Edit the CONTACT_NAME of an existing Identity contact.
bolos_err_t provide_ledger_account_contact(uint8_t *buffer_in, size_t buffer_in_length)
Deliver a verified Ledger Account contact to the coin application.
bolos_err_t register_ledger_account(uint8_t *buffer_in, size_t buffer_in_length)
Register a new Ledger Account.
bolos_err_t edit_ledger_account(uint8_t *buffer_in, size_t buffer_in_length)
Edit the name of an existing Ledger Account.