Skip to content

Commit 4aafff7

Browse files
Factorizing io functions
1 parent bb1cd7e commit 4aafff7

File tree

3 files changed

+21
-45
lines changed

3 files changed

+21
-45
lines changed

src/boilerplate/dispatcher.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void finalize_response(uint16_t sw) {
5252
}
5353

5454
static void send_response() {
55-
io_confirm_response();
55+
io_send_response();
5656
}
5757

5858
static void set_ui_dirty() {

src/boilerplate/io_ext.c

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,7 @@ void io_finalize_response(uint16_t sw) {
131131
}
132132
}
133133

134-
void io_reset_response() {
135-
G_output_len = 0;
136-
}
137-
138-
void io_set_response(const void *rdata, size_t rdata_len, uint16_t sw) {
139-
io_reset_response();
140-
if (rdata != NULL) {
141-
io_add_to_response(rdata, rdata_len);
142-
}
143-
io_finalize_response(sw);
144-
}
145-
146-
int io_confirm_response() {
134+
int io_send_response() {
147135
int ret;
148136

149137
ret = io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, G_output_len);
@@ -152,11 +140,8 @@ int io_confirm_response() {
152140
return ret;
153141
}
154142

155-
int io_send_response(void *rdata, size_t rdata_len, uint16_t sw) {
156-
io_set_response(rdata, rdata_len, sw);
157-
return io_confirm_response();
158-
}
159-
160143
int io_send_sw(uint16_t sw) {
161-
return io_send_response(NULL, 0, sw);
144+
G_output_len = 0;
145+
io_finalize_response(sw);
146+
return io_send_response();
162147
}

src/boilerplate/io_ext.h

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,48 +63,39 @@ void io_reset_timeouts();
6363
void io_show_processing_screen();
6464

6565
/**
66-
* TODO: docs
67-
*/
68-
void io_reset_response();
69-
70-
/**
71-
* TODO: docs
66+
* Append data to the APDU response buffer (G_io_apdu_buffer).
67+
*
68+
* @param[in] rdata
69+
* Pointer to the data to append.
70+
* @param[in] rdata_len
71+
* Length of data to append.
7272
*/
7373
void io_add_to_response(const void *rdata, size_t rdata_len);
7474

7575
/**
76-
* TODO: docs
76+
* Finalize the APDU response by appending the status word.
77+
* Must be called after all io_add_to_response() calls are done.
78+
*
79+
* @param[in] sw
80+
* Status word of APDU response.
7781
*/
7882
void io_finalize_response(uint16_t sw);
7983

80-
/* TODO: docs */
81-
void io_set_response(const void *rdata, size_t rdata_len, uint16_t sw);
82-
83-
/* TODO: docs */
84-
int io_confirm_response(void);
85-
8684
/**
87-
* Send APDU response (response data + status word) by filling G_io_apdu_buffer.
88-
*
89-
* @param[in] rdata
90-
* Pointer to the response.
91-
* @param[in] rdata_len
92-
* Length of response.
93-
* @param[in] sw
94-
* Status word of APDU response.
85+
* Send the previously prepared APDU response via io_exchange.
86+
* The response must have been built with io_add_to_response()/io_finalize_response()
87+
* before calling this function.
9588
*
9689
* @return zero or positive integer if success, -1 otherwise.
97-
*
9890
*/
99-
int io_send_response(void *rdata, size_t rdata_len, uint16_t sw);
91+
int io_send_response(void);
10092

10193
/**
102-
* Send APDU response (only status word) by filling G_io_apdu_buffer.
94+
* Send APDU response containing only a status word (no data).
10395
*
10496
* @param[in] sw
10597
* Status word of APDU response.
10698
*
10799
* @return zero or positive integer if success, -1 otherwise.
108-
*
109100
*/
110101
int io_send_sw(uint16_t sw);

0 commit comments

Comments
 (0)