Hoernchen has uploaded this change for review.
fw source: force reformat once and for all
This commit applies the rules to all files that matter
(obv excluding asf4 code) since it is impossible to modify code
because the code never used the code style enforced by the
linter/clang-format and
1) changing code
2) reformatting code
3) extracting the reformatting changes for the modified lines as a
separate commit
4) commiting standalone reformatting changes
4) commiting the actual code change on top
is a workflow that takes forever and is completely ridiculous because
the whole point of formatter rules is to apply them.
This needs a second commit with .git-blame-ignore-revs to not pollute blame.
Change-Id: Iacc086bb566551225e7a21b639a1ad2ec257484f
---
M ccid_common/ccid_device.c
M ccid_common/ccid_device.h
M ccid_common/ccid_proto.c
M ccid_common/ccid_proto.h
M ccid_common/ccid_slot_fsm.c
M ccid_common/cuart.c
M ccid_common/cuart.h
M ccid_common/iso7816_3.c
M ccid_common/iso7816_fsm.c
M ccid_common/iso7816_fsm.h
M sysmoOCTSIM/command.c
M sysmoOCTSIM/command.h
M sysmoOCTSIM/cuart_driver_asf4_usart_async.c
M sysmoOCTSIM/dfu_descriptors.h
M sysmoOCTSIM/driver_init.c
M sysmoOCTSIM/i2c_bitbang.c
M sysmoOCTSIM/i2c_bitbang.h
M sysmoOCTSIM/libosmo_emb.c
M sysmoOCTSIM/linuxlist_atomic.h
M sysmoOCTSIM/main.c
M sysmoOCTSIM/ncn8025.c
M sysmoOCTSIM/ncn8025.h
M sysmoOCTSIM/octsim_i2c.c
M sysmoOCTSIM/replace.h
M sysmoOCTSIM/talloc.c
M sysmoOCTSIM/talloc.h
M sysmoOCTSIM/usb_descriptors.c
M sysmoOCTSIM/usb_dfu.h
M sysmoOCTSIM/usb_start.c
M sysmoOCTSIM/usb_start.h
30 files changed, 1,749 insertions(+), 1,385 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-ccid-firmware refs/changes/30/42330/1
diff --git a/ccid_common/ccid_device.c b/ccid_common/ccid_device.c
index 8a53860..1d426aa 100644
--- a/ccid_common/ccid_device.c
+++ b/ccid_common/ccid_device.c
@@ -37,7 +37,8 @@
uint16_t wValue;
uint16_t wIndex;
uint16_t wLength;
-} __attribute__ ((packed));;
+} __attribute__((packed));
+;
/* decode on-the-wire T0 parameters into their parsed form */
static int decode_ccid_pars_t0(struct ccid_pars_decoded *out, const struct ccid_proto_data_t0 *in)
@@ -153,17 +154,19 @@
return CCID_ICC_STATUS_PRES_INACT;
}
-#define SET_HDR(x, msg_type, slot, seq) do { \
- (x)->hdr.bMessageType = msg_type; \
- (x)->hdr.dwLength = 0; \
- (x)->hdr.bSlot = slot; \
- (x)->hdr.bSeq = seq; \
+#define SET_HDR(x, msg_type, slot, seq) \
+ do { \
+ (x)->hdr.bMessageType = msg_type; \
+ (x)->hdr.dwLength = 0; \
+ (x)->hdr.bSlot = slot; \
+ (x)->hdr.bSeq = seq; \
} while (0)
-#define SET_HDR_IN(x, msg_type, slot, seq, status, error) do { \
- SET_HDR(&(x)->hdr, msg_type, slot, seq); \
- (x)->hdr.bStatus = status; \
- (x)->hdr.bError = error; \
+#define SET_HDR_IN(x, msg_type, slot, seq, status, error) \
+ do { \
+ SET_HDR(&(x)->hdr, msg_type, slot, seq); \
+ (x)->hdr.bStatus = status; \
+ (x)->hdr.bError = error; \
} while (0)
#if 0
@@ -188,14 +191,14 @@
/* Send given CCID message */
static int ccid_send(struct ccid_instance *ci, struct msgb *msg)
{
- struct ccid_header *ch = (struct ccid_header *) msgb_ccid_in(msg);
+ struct ccid_header *ch = (struct ccid_header *)msgb_ccid_in(msg);
struct ccid_slot *cs = get_ccid_slot(ci, ch->bSlot);
if (cs) {
LOGPCS(cs, LOGL_DEBUG, "Tx CCID(IN) %s %s\n",
- get_value_string(ccid_msg_type_vals, ch->bMessageType), msgb_hexdump(msg));
+ get_value_string(ccid_msg_type_vals, ch->bMessageType), msgb_hexdump(msg));
} else {
LOGPCI(ci, LOGL_DEBUG, "Tx CCID(IN) %s %s\n",
- get_value_string(ccid_msg_type_vals, ch->bMessageType), msgb_hexdump(msg));
+ get_value_string(ccid_msg_type_vals, ch->bMessageType), msgb_hexdump(msg));
}
return ci->ops->send_in(ci, msg);
}
@@ -203,7 +206,7 @@
/* Send given CCID message for given slot; patch bSlot into message */
int ccid_slot_send(struct ccid_slot *cs, struct msgb *msg)
{
- struct ccid_header *ch = (struct ccid_header *) msgb_ccid_in(msg);
+ struct ccid_header *ch = (struct ccid_header *)msgb_ccid_in(msg);
/* patch bSlotNr into message */
ch->bSlot = cs->slot_nr;
@@ -224,7 +227,7 @@
{
struct msgb *msg = ccid_msgb_alloc();
struct ccid_rdr_to_pc_data_block *db =
- (struct ccid_rdr_to_pc_data_block *) msgb_put(msg, sizeof(*db) + data_len);
+ (struct ccid_rdr_to_pc_data_block *)msgb_put(msg, sizeof(*db) + data_len);
uint8_t sts = (cmd_sts & CCID_CMD_STATUS_MASK) | icc_status;
SET_HDR_IN(db, RDR_to_PC_DataBlock, slot_nr, seq, sts, err);
@@ -246,7 +249,7 @@
{
struct msgb *msg = ccid_msgb_alloc();
struct ccid_rdr_to_pc_slot_status *ss =
- (struct ccid_rdr_to_pc_slot_status *) msgb_put(msg, sizeof(*ss));
+ (struct ccid_rdr_to_pc_slot_status *)msgb_put(msg, sizeof(*ss));
uint8_t sts = (cmd_sts & CCID_CMD_STATUS_MASK) | icc_status;
SET_HDR_IN(ss, RDR_to_PC_SlotStatus, slot_nr, seq, sts, err);
@@ -277,7 +280,7 @@
return msg;
}
struct msgb *ccid_gen_parameters_t0(struct ccid_slot *cs, uint8_t seq, uint8_t cmd_sts,
- enum ccid_error_code err)
+ enum ccid_error_code err)
{
return ccid_gen_parameters_t0_nr(cs->slot_nr, get_icc_status(cs), seq, cmd_sts, err, &cs->pars);
}
@@ -300,19 +303,18 @@
return msg;
}
struct msgb *ccid_gen_parameters_t1(struct ccid_slot *cs, uint8_t seq, uint8_t cmd_sts,
- enum ccid_error_code err)
+ enum ccid_error_code err)
{
return ccid_gen_parameters_t1_nr(cs->slot_nr, get_icc_status(cs), seq, cmd_sts, err, &cs->pars);
}
-
/* Section 6.2.4 */
static struct msgb *ccid_gen_escape_nr(uint8_t slot_nr, uint8_t icc_status, uint8_t seq, uint8_t cmd_sts,
- enum ccid_error_code err, const uint8_t *data, uint32_t data_len)
+ enum ccid_error_code err, const uint8_t *data, uint32_t data_len)
{
struct msgb *msg = ccid_msgb_alloc();
struct ccid_rdr_to_pc_escape *esc =
- (struct ccid_rdr_to_pc_escape *) msgb_put(msg, sizeof(*esc) + data_len);
+ (struct ccid_rdr_to_pc_escape *)msgb_put(msg, sizeof(*esc) + data_len);
uint8_t sts = (cmd_sts & CCID_CMD_STATUS_MASK) | icc_status;
SET_HDR_IN(esc, RDR_to_PC_Escape, slot_nr, seq, sts, err);
@@ -329,12 +331,12 @@
/* Section 6.2.5 */
static struct msgb *ccid_gen_clock_and_rate_nr(uint8_t slot_nr, uint8_t icc_status, uint8_t seq,
- uint8_t cmd_sts, enum ccid_error_code err,
- uint32_t clock_khz, uint32_t rate_bps)
+ uint8_t cmd_sts, enum ccid_error_code err,
+ uint32_t clock_khz, uint32_t rate_bps)
{
struct msgb *msg = ccid_msgb_alloc();
struct ccid_rdr_to_pc_data_rate_and_clock *drc =
- (struct ccid_rdr_to_pc_data_rate_and_clock *) msgb_put(msg, sizeof(*drc));
+ (struct ccid_rdr_to_pc_data_rate_and_clock *)msgb_put(msg, sizeof(*drc));
uint8_t sts = (cmd_sts & CCID_CMD_STATUS_MASK) | icc_status;
SET_HDR_IN(drc, RDR_to_PC_DataRateAndClockFrequency, slot_nr, seq, sts, err);
@@ -369,7 +371,7 @@
case PC_to_RDR_Secure:
/* Return RDR_to_PC_DataBlock */
resp = ccid_gen_data_block_nr(slot_nr, icc_status, seq, CCID_CMD_STATUS_FAILED,
- err_code, NULL, 0);
+ err_code, NULL, 0);
break;
case PC_to_RDR_IccPowerOff:
@@ -380,7 +382,7 @@
case PC_to_RDR_Abort:
/* Return RDR_to_PC_SlotStatus */
resp = ccid_gen_slot_status_nr(slot_nr, icc_status, seq, CCID_CMD_STATUS_FAILED,
- err_code);
+ err_code);
break;
case PC_to_RDR_GetParameters:
@@ -400,13 +402,13 @@
case PC_to_RDR_SetDataRateAndClockFrequency:
/* Return RDR_to_PC_SlotStatus */
resp = ccid_gen_slot_status_nr(slot_nr, icc_status, seq, CCID_CMD_STATUS_FAILED,
- err_code);
+ err_code);
break;
default:
/* generate general error */
resp = ccid_gen_slot_status_nr(slot_nr, icc_status, seq, CCID_CMD_STATUS_FAILED,
- CCID_ERR_CMD_NOT_SUPPORTED);
+ CCID_ERR_CMD_NOT_SUPPORTED);
break;
}
return resp;
@@ -420,7 +422,7 @@
static int ccid_handle_get_slot_status(struct ccid_slot *cs, struct msgb *msg)
{
const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
- const struct ccid_header *ch = (const struct ccid_header *) u;
+ const struct ccid_header *ch = (const struct ccid_header *)u;
uint8_t seq = u->get_slot_status.hdr.bSeq;
struct msgb *resp;
@@ -429,12 +431,11 @@
return ccid_slot_send_unbusy(cs, resp);
}
-
/* Section 6.1.1 */
static int ccid_handle_icc_power_on(struct ccid_slot *cs, struct msgb *msg)
{
const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
- const struct ccid_header *ch = (const struct ccid_header *) u;
+ const struct ccid_header *ch = (const struct ccid_header *)u;
/* handle this asynchronously */
cs->ci->slot_ops->icc_power_on_async(cs, msg, &u->icc_power_on);
@@ -445,7 +446,7 @@
static int ccid_handle_icc_power_off(struct ccid_slot *cs, struct msgb *msg)
{
const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
- const struct ccid_header *ch = (const struct ccid_header *) u;
+ const struct ccid_header *ch = (const struct ccid_header *)u;
uint8_t seq = u->icc_power_off.hdr.bSeq;
struct msgb *resp;
@@ -458,7 +459,7 @@
static int ccid_handle_xfr_block(struct ccid_slot *cs, struct msgb *msg)
{
const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
- const struct ccid_header *ch = (const struct ccid_header *) u;
+ const struct ccid_header *ch = (const struct ccid_header *)u;
struct msgb *resp;
int rc;
@@ -487,7 +488,7 @@
static int ccid_handle_get_parameters(struct ccid_slot *cs, struct msgb *msg)
{
const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
- const struct ccid_header *ch = (const struct ccid_header *) u;
+ const struct ccid_header *ch = (const struct ccid_header *)u;
uint8_t seq = u->get_parameters.hdr.bSeq;
struct msgb *resp;
@@ -500,7 +501,7 @@
static int ccid_handle_reset_parameters(struct ccid_slot *cs, struct msgb *msg)
{
const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
- const struct ccid_header *ch = (const struct ccid_header *) u;
+ const struct ccid_header *ch = (const struct ccid_header *)u;
uint8_t seq = u->reset_parameters.hdr.bSeq;
struct msgb *resp;
int rc;
@@ -531,7 +532,7 @@
{
const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
const struct ccid_pc_to_rdr_set_parameters *spar = &u->set_parameters;
- const struct ccid_header *ch = (const struct ccid_header *) u;
+ const struct ccid_header *ch = (const struct ccid_header *)u;
uint8_t seq = u->set_parameters.hdr.bSeq;
struct ccid_pars_decoded pars_dec;
struct msgb *resp;
@@ -541,11 +542,11 @@
case CCID_PROTOCOL_NUM_T0:
rc = decode_ccid_pars_t0(&pars_dec, &spar->abProtocolData.t0);
break;
-// case CCID_PROTOCOL_NUM_T1:
-// rc = decode_ccid_pars_t1(&pars_dec, &spar->abProtocolData.t1);
-// break;
+ // case CCID_PROTOCOL_NUM_T1:
+ // rc = decode_ccid_pars_t1(&pars_dec, &spar->abProtocolData.t1);
+ // break;
default:
- LOGP(DCCID, LOGL_ERROR, "SetParameters: Invalid Protocol 0x%02x\n",spar->bProtocolNum);
+ LOGP(DCCID, LOGL_ERROR, "SetParameters: Invalid Protocol 0x%02x\n", spar->bProtocolNum);
resp = ccid_gen_parameters_t0(cs, seq, CCID_CMD_STATUS_FAILED, 0);
goto out;
}
@@ -578,7 +579,7 @@
static int ccid_handle_escape(struct ccid_slot *cs, struct msgb *msg)
{
const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
- const struct ccid_header *ch = (const struct ccid_header *) u;
+ const struct ccid_header *ch = (const struct ccid_header *)u;
uint8_t seq = u->escape.hdr.bSeq;
struct msgb *resp;
@@ -590,7 +591,7 @@
static int ccid_handle_icc_clock(struct ccid_slot *cs, struct msgb *msg)
{
const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
- const struct ccid_header *ch = (const struct ccid_header *) u;
+ const struct ccid_header *ch = (const struct ccid_header *)u;
uint8_t seq = u->icc_clock.hdr.bSeq;
struct msgb *resp;
@@ -603,7 +604,7 @@
static int ccid_handle_t0apdu(struct ccid_slot *cs, struct msgb *msg)
{
const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
- const struct ccid_header *ch = (const struct ccid_header *) u;
+ const struct ccid_header *ch = (const struct ccid_header *)u;
uint8_t seq = u->t0apdu.hdr.bSeq;
struct msgb *resp;
@@ -617,7 +618,7 @@
static int ccid_handle_secure(struct ccid_slot *cs, struct msgb *msg)
{
const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
- const struct ccid_header *ch = (const struct ccid_header *) u;
+ const struct ccid_header *ch = (const struct ccid_header *)u;
uint8_t seq = u->secure.hdr.bSeq;
struct msgb *resp;
@@ -630,7 +631,7 @@
static int ccid_handle_mechanical(struct ccid_slot *cs, struct msgb *msg)
{
const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
- const struct ccid_header *ch = (const struct ccid_header *) u;
+ const struct ccid_header *ch = (const struct ccid_header *)u;
uint8_t seq = u->mechanical.hdr.bSeq;
struct msgb *resp;
@@ -642,18 +643,18 @@
static int ccid_handle_abort(struct ccid_slot *cs, struct msgb *msg)
{
const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
- const struct ccid_header *ch = (const struct ccid_header *) u;
+ const struct ccid_header *ch = (const struct ccid_header *)u;
uint8_t seq = u->abort.hdr.bSeq;
struct msgb *resp;
/* Check if the currently in-progress message is Abortable */
- switch (0/* FIXME */) {
+ switch (0 /* FIXME */) {
case PC_to_RDR_IccPowerOn:
case PC_to_RDR_XfrBlock:
case PC_to_RDR_Escape:
case PC_to_RDR_Secure:
case PC_to_RDR_Mechanical:
- //case PC_to_RDR_Abort: /* seriously? WTF! */
+ //case PC_to_RDR_Abort: /* seriously? WTF! */
break;
default:
LOGP(DCCID, LOGL_ERROR, "Abort for non-Abortable Message Type\n");
@@ -671,7 +672,7 @@
static int ccid_handle_set_rate_and_clock(struct ccid_slot *cs, struct msgb *msg)
{
const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
- const struct ccid_header *ch = (const struct ccid_header *) u;
+ const struct ccid_header *ch = (const struct ccid_header *)u;
uint8_t seq = u->set_rate_and_clock.hdr.bSeq;
uint32_t freq_hz = osmo_load32le(&u->set_rate_and_clock.dwClockFrequency);
uint32_t rate_bps = osmo_load32le(&u->set_rate_and_clock.dwDataRate);
@@ -696,7 +697,7 @@
int ccid_handle_out(struct ccid_instance *ci, struct msgb *msg)
{
const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
- const struct ccid_header *ch = (const struct ccid_header *) u;
+ const struct ccid_header *ch = (const struct ccid_header *)u;
unsigned int len = msgb_length(msg);
struct ccid_slot *cs;
struct msgb *resp;
@@ -722,7 +723,7 @@
LOGPCS(cs, LOGL_ERROR, "Slot Busy, but another cmd received\n");
/* FIXME: ABORT logic as per section 5.3.1 of CCID Spec v1.1 */
resp = gen_err_resp(ch->bMessageType, ch->bSlot, get_icc_status(cs), ch->bSeq,
- CCID_ERR_CMD_SLOT_BUSY);
+ CCID_ERR_CMD_SLOT_BUSY);
msgb_free(msg);
return ccid_send(ci, resp);
}
@@ -731,13 +732,13 @@
LOGPCS(cs, LOGL_ERROR, "No icc present, but another cmd received\n");
/* FIXME: ABORT logic as per section 5.3.1 of CCID Spec v1.1 */
resp = gen_err_resp(ch->bMessageType, ch->bSlot, get_icc_status(cs), ch->bSeq,
- CCID_ERR_ICC_MUTE);
+ CCID_ERR_ICC_MUTE);
msgb_free(msg);
return ccid_send(ci, resp);
}
LOGPCS(cs, LOGL_DEBUG, "Rx CCID(OUT) %s %s\n",
- get_value_string(ccid_msg_type_vals, ch->bMessageType), msgb_hexdump(msg));
+ get_value_string(ccid_msg_type_vals, ch->bMessageType), msgb_hexdump(msg));
/* we're now processing a command for the slot; mark slot as busy */
cs->cmd_busy = true;
@@ -781,7 +782,7 @@
break;
case PC_to_RDR_SetParameters:
// smallest union member
- if (len < (sizeof(u->set_parameters.abProtocolData.t0)+10))
+ if (len < (sizeof(u->set_parameters.abProtocolData.t0) + 10))
goto short_msg;
rc = ccid_handle_set_parameters(cs, msg);
break;
@@ -884,7 +885,7 @@
if (len != sizeof(uint32_t) * ci->class_desc->bNumClockSupported)
return CCID_CTRL_RET_INVALID;
- *data_in = (const uint8_t *) ci->clock_freqs;
+ *data_in = (const uint8_t *)ci->clock_freqs;
return CCID_CTRL_RET_OK;
}
@@ -897,7 +898,7 @@
if (len != sizeof(uint32_t) * ci->class_desc->bNumClockSupported)
return CCID_CTRL_RET_INVALID;
- *data_in = (const uint8_t *) ci->data_rates;
+ *data_in = (const uint8_t *)ci->data_rates;
return CCID_CTRL_RET_OK;
}
@@ -910,12 +911,12 @@
*/
int ccid_handle_ctrl(struct ccid_instance *ci, const uint8_t *ctrl_req, const uint8_t **data_in)
{
- const struct _usb_ctrl_req *req = (const struct _usb_ctrl_req *) ctrl_req;
+ const struct _usb_ctrl_req *req = (const struct _usb_ctrl_req *)ctrl_req;
int rc;
LOGPCI(ci, LOGL_DEBUG, "CTRL bmReqT=0x%02X bRequest=%s, wValue=0x%04X, wIndex=0x%04X, wLength=%d\n",
- req->bRequestType, get_value_string(ccid_class_spec_req_vals, req->bRequest),
- req->wValue, req->wIndex, req->wLength);
+ req->bRequestType, get_value_string(ccid_class_spec_req_vals, req->bRequest),
+ req->wValue, req->wIndex, req->wLength);
switch (req->bRequest) {
case CLASS_SPEC_CCID_ABORT:
@@ -956,5 +957,4 @@
slot_ops->init(cs);
}
-
}
diff --git a/ccid_common/ccid_device.h b/ccid_common/ccid_device.h
index 97d6212..a279af4 100644
--- a/ccid_common/ccid_device.h
+++ b/ccid_common/ccid_device.h
@@ -24,11 +24,11 @@
#include "ccid_proto.h"
#include "logging.h"
-#define NR_SLOTS 8
+#define NR_SLOTS 8
-#define LOGPCI(ci, lvl, fmt, args ...) LOGP(DCCID, lvl, "%s: " fmt, (ci)->name, ## args)
-#define LOGPCS(cs, lvl, fmt, args ...) \
- LOGP(DCCID, lvl, "%s(%u): " fmt, (cs)->ci->name, (cs)->slot_nr, ## args)
+#define LOGPCI(ci, lvl, fmt, args...) LOGP(DCCID, lvl, "%s: " fmt, (ci)->name, ##args)
+#define LOGPCS(cs, lvl, fmt, args...) \
+ LOGP(DCCID, lvl, "%s(%u): " fmt, (cs)->ci->name, (cs)->slot_nr, ##args)
struct msgb;
@@ -77,7 +77,7 @@
/* default parameters; applied on ResetParameters */
const struct ccid_pars_decoded *default_pars;
volatile uint32_t event;
- volatile void* event_data;
+ volatile void *event_data;
};
/* CCID operations provided by USB transport layer */
@@ -100,12 +100,12 @@
void (*icc_power_on_async)(struct ccid_slot *cs, struct msgb *msg,
const struct ccid_pc_to_rdr_icc_power_on *ipo);
int (*xfr_block_async)(struct ccid_slot *cs, struct msgb *msg,
- const struct ccid_pc_to_rdr_xfr_block *xfb);
+ const struct ccid_pc_to_rdr_xfr_block *xfb);
void (*set_power)(struct ccid_slot *cs, bool enable);
void (*set_clock)(struct ccid_slot *cs, enum ccid_clock_command cmd);
int (*set_params)(struct ccid_slot *cs, uint8_t seq, enum ccid_protocol_num proto,
const struct ccid_pars_decoded *pars_dec);
- int (*set_rate_and_clock)(struct ccid_slot *cs, uint32_t* freq_hz, uint32_t* rate_bps);
+ int (*set_rate_and_clock)(struct ccid_slot *cs, uint32_t *freq_hz, uint32_t *rate_bps);
void (*icc_set_insertion_status)(struct ccid_slot *cs, bool present);
int (*handle_fsm_events)(struct ccid_slot *cs, bool enable);
};
@@ -144,15 +144,15 @@
const char *name, void *priv);
int ccid_handle_out(struct ccid_instance *ci, struct msgb *msg);
struct msgb *ccid_gen_parameters_t0(struct ccid_slot *cs, uint8_t seq, uint8_t cmd_sts,
- enum ccid_error_code err);
+ enum ccid_error_code err);
struct msgb *ccid_gen_parameters_t1(struct ccid_slot *cs, uint8_t seq, uint8_t cmd_sts,
- enum ccid_error_code err);
+ enum ccid_error_code err);
/* Invalid request received: Please return STALL */
-#define CCID_CTRL_RET_INVALID -1
+#define CCID_CTRL_RET_INVALID -1
/* Unknown request received: Not something CCID is supposed to handle */
-#define CCID_CTRL_RET_UNKNOWN 0
+#define CCID_CTRL_RET_UNKNOWN 0
/* Request OK. In case of a CTRL-IN: continue by sending wLength bytes to host */
-#define CCID_CTRL_RET_OK 1
+#define CCID_CTRL_RET_OK 1
int ccid_handle_ctrl(struct ccid_instance *ci, const uint8_t *ctrl_req, const uint8_t **data_in);
diff --git a/ccid_common/ccid_proto.c b/ccid_common/ccid_proto.c
index 5265e36..146f737 100644
--- a/ccid_common/ccid_proto.c
+++ b/ccid_common/ccid_proto.c
@@ -67,21 +67,21 @@
};
const struct value_string ccid_error_code_vals[] = {
- { CCID_ERR_CMD_ABORTED, "CMD_ABORTED" },
- { CCID_ERR_ICC_MUTE, "ICC_MUTE" },
- { CCID_ERR_XFR_PARITY_ERROR, "XFR_PARITY_ERROR" },
- { CCID_ERR_XFR_OVERRUN, "XFR_OVERRUN" },
- { CCID_ERR_HW_ERROR, "HW_ERROR" },
- { CCID_ERR_BAD_ATR_TS, "BAD_ATR_TS" },
- { CCID_ERR_BAD_ATR_TCK, "BAD_ATR_TCK" },
- { CCID_ERR_ICC_PROTOCOL_NOT_SUPPORTED, "ICC_PROTOCOL_NOT_SUPPORTED" },
- { CCID_ERR_ICC_CLASS_NOT_SUPPORTED, "ICC_CLASS_NOT_SUPPORTED" },
- { CCID_ERR_PROCEDURE_BYTE_CONFLICT, "PROCEDURE_BYTE_CONFLICT" },
- { CCID_ERR_DEACTIVATED_PROTOCOL, "DEACTIVATED_PROTOCOL" },
- { CCID_ERR_BUSY_WITH_AUTO_SEQUENCE, "BUSY_WITH_AUTO_SEQUENCE" },
- { CCID_ERR_PIN_TIMEOUT, "PIN_TIMEOUT" },
- { CCID_ERR_PIN_CANCELLED, "PIN_CANCELLED" },
- { CCID_ERR_CMD_SLOT_BUSY, "CMD_SLOT_BUSY" },
- { CCID_ERR_CMD_NOT_SUPPORTED, "CMD_NOT_SUPPORTED" },
+ { CCID_ERR_CMD_ABORTED, "CMD_ABORTED" },
+ { CCID_ERR_ICC_MUTE, "ICC_MUTE" },
+ { CCID_ERR_XFR_PARITY_ERROR, "XFR_PARITY_ERROR" },
+ { CCID_ERR_XFR_OVERRUN, "XFR_OVERRUN" },
+ { CCID_ERR_HW_ERROR, "HW_ERROR" },
+ { CCID_ERR_BAD_ATR_TS, "BAD_ATR_TS" },
+ { CCID_ERR_BAD_ATR_TCK, "BAD_ATR_TCK" },
+ { CCID_ERR_ICC_PROTOCOL_NOT_SUPPORTED, "ICC_PROTOCOL_NOT_SUPPORTED" },
+ { CCID_ERR_ICC_CLASS_NOT_SUPPORTED, "ICC_CLASS_NOT_SUPPORTED" },
+ { CCID_ERR_PROCEDURE_BYTE_CONFLICT, "PROCEDURE_BYTE_CONFLICT" },
+ { CCID_ERR_DEACTIVATED_PROTOCOL, "DEACTIVATED_PROTOCOL" },
+ { CCID_ERR_BUSY_WITH_AUTO_SEQUENCE, "BUSY_WITH_AUTO_SEQUENCE" },
+ { CCID_ERR_PIN_TIMEOUT, "PIN_TIMEOUT" },
+ { CCID_ERR_PIN_CANCELLED, "PIN_CANCELLED" },
+ { CCID_ERR_CMD_SLOT_BUSY, "CMD_SLOT_BUSY" },
+ { CCID_ERR_CMD_NOT_SUPPORTED, "CMD_NOT_SUPPORTED" },
{ 0, NULL }
};
diff --git a/ccid_common/ccid_proto.h b/ccid_common/ccid_proto.h
index 19f1333..31737a6 100644
--- a/ccid_common/ccid_proto.h
+++ b/ccid_common/ccid_proto.h
@@ -26,73 +26,73 @@
/* Identifies the length of type of subordinate descriptors of a CCID device
* Table 5.1-1 Smart Card Device Class descriptors */
struct usb_ccid_class_descriptor {
- uint8_t bLength;
- uint8_t bDescriptorType;
+ uint8_t bLength;
+ uint8_t bDescriptorType;
uint16_t bcdCCID;
- uint8_t bMaxSlotIndex;
- uint8_t bVoltageSupport;
+ uint8_t bMaxSlotIndex;
+ uint8_t bVoltageSupport;
uint32_t dwProtocols;
uint32_t dwDefaultClock;
uint32_t dwMaximumClock;
- uint8_t bNumClockSupported;
+ uint8_t bNumClockSupported;
uint32_t dwDataRate;
uint32_t dwMaxDataRate;
- uint8_t bNumDataRatesSupported;
+ uint8_t bNumDataRatesSupported;
uint32_t dwMaxIFSD;
uint32_t dwSynchProtocols;
uint32_t dwMechanical;
uint32_t dwFeatures;
uint32_t dwMaxCCIDMessageLength;
- uint8_t bClassGetResponse;
- uint8_t bClassEnvelope;
+ uint8_t bClassGetResponse;
+ uint8_t bClassEnvelope;
uint16_t wLcdLayout;
- uint8_t bPINSupport;
- uint8_t bMaxCCIDBusySlots;
+ uint8_t bPINSupport;
+ uint8_t bMaxCCIDBusySlots;
} __attribute__((packed));
/* handling of bulk out from host */
enum ccid_msg_type {
/* Section 6.3 / Table 6.3-1: Interrupt IN */
- RDR_to_PC_NotifySlotChange = 0x50,
- RDR_to_PC_HardwareError = 0x51,
+ RDR_to_PC_NotifySlotChange = 0x50,
+ RDR_to_PC_HardwareError = 0x51,
/* Section 6.1 / Table 6.1-1: Bulk OUT */
- PC_to_RDR_IccPowerOn = 0x62,
- PC_to_RDR_IccPowerOff = 0x63,
- PC_to_RDR_GetSlotStatus = 0x65,
- PC_to_RDR_XfrBlock = 0x6f,
- PC_to_RDR_GetParameters = 0x6c,
- PC_to_RDR_ResetParameters = 0x6d,
- PC_to_RDR_SetParameters = 0x61,
- PC_to_RDR_Escape = 0x6b,
- PC_to_RDR_IccClock = 0x6e,
- PC_to_RDR_T0APDU = 0x6a,
- PC_to_RDR_Secure = 0x69,
- PC_to_RDR_Mechanical = 0x71,
- PC_to_RDR_Abort = 0x72,
- PC_to_RDR_SetDataRateAndClockFrequency = 0x73,
+ PC_to_RDR_IccPowerOn = 0x62,
+ PC_to_RDR_IccPowerOff = 0x63,
+ PC_to_RDR_GetSlotStatus = 0x65,
+ PC_to_RDR_XfrBlock = 0x6f,
+ PC_to_RDR_GetParameters = 0x6c,
+ PC_to_RDR_ResetParameters = 0x6d,
+ PC_to_RDR_SetParameters = 0x61,
+ PC_to_RDR_Escape = 0x6b,
+ PC_to_RDR_IccClock = 0x6e,
+ PC_to_RDR_T0APDU = 0x6a,
+ PC_to_RDR_Secure = 0x69,
+ PC_to_RDR_Mechanical = 0x71,
+ PC_to_RDR_Abort = 0x72,
+ PC_to_RDR_SetDataRateAndClockFrequency = 0x73,
/* Section 6.2 / Table 6.2-1: Bulk IN */
- RDR_to_PC_DataBlock = 0x80,
- RDR_to_PC_SlotStatus = 0x81,
- RDR_to_PC_Parameters = 0x82,
- RDR_to_PC_Escape = 0x83,
- RDR_to_PC_DataRateAndClockFrequency = 0x84,
+ RDR_to_PC_DataBlock = 0x80,
+ RDR_to_PC_SlotStatus = 0x81,
+ RDR_to_PC_Parameters = 0x82,
+ RDR_to_PC_Escape = 0x83,
+ RDR_to_PC_DataRateAndClockFrequency = 0x84,
};
/* CCID message header on BULK-OUT endpoint */
struct ccid_header {
- uint8_t bMessageType;
- uint32_t dwLength;
- uint8_t bSlot;
- uint8_t bSeq;
-} __attribute__ ((packed));
+ uint8_t bMessageType;
+ uint32_t dwLength;
+ uint8_t bSlot;
+ uint8_t bSeq;
+} __attribute__((packed));
/* CCID Class-Specific Control Request (Section 5.3 / Table 5.3-1) */
enum ccid_class_spec_req {
- CLASS_SPEC_CCID_ABORT = 0x01,
- CLASS_SPEC_CCID_GET_CLOCK_FREQ = 0x02,
- CLASS_SPEC_CCID_GET_DATA_RATES = 0x03
+ CLASS_SPEC_CCID_ABORT = 0x01,
+ CLASS_SPEC_CCID_GET_CLOCK_FREQ = 0x02,
+ CLASS_SPEC_CCID_GET_DATA_RATES = 0x03
};
/***********************************************************************
@@ -101,10 +101,10 @@
/* Section 6.1.1 */
enum ccid_power_select {
- CCID_PWRSEL_AUTO = 0x00,
- CCID_PWRSEL_5V0 = 0x01,
- CCID_PWRSEL_3V0 = 0x02,
- CCID_PWRSEL_1V8 = 0x03,
+ CCID_PWRSEL_AUTO = 0x00,
+ CCID_PWRSEL_5V0 = 0x01,
+ CCID_PWRSEL_3V0 = 0x02,
+ CCID_PWRSEL_1V8 = 0x03,
};
/* Section 6.1.1 */
@@ -112,21 +112,21 @@
struct ccid_header hdr;
uint8_t bPowerSelect;
uint8_t abRFU[2];
-} __attribute__ ((packed));
+} __attribute__((packed));
/* Response: RDR_to_PC_DataBlock */
/* Section 6.1.2 */
struct ccid_pc_to_rdr_icc_power_off {
struct ccid_header hdr;
uint8_t abRFU[3];
-} __attribute__ ((packed));
+} __attribute__((packed));
/* Response: RDR_to_PC_SlotStatus */
/* Section 6.1.3 */
struct ccid_pc_to_rdr_get_slot_status {
struct ccid_header hdr;
uint8_t abRFU[3];
-} __attribute__ ((packed));
+} __attribute__((packed));
/* Response: RDR_to_PC_SlotStatus */
/* Section 6.1.4 */
@@ -135,40 +135,40 @@
uint8_t bBWI;
uint16_t wLevelParameter;
uint8_t abData[0];
-} __attribute__ ((packed));
+} __attribute__((packed));
/* Response: RDR_to_PC_DataBlock */
/* Section 6.1.5 */
struct ccid_pc_to_rdr_get_parameters {
struct ccid_header hdr;
uint8_t abRFU[3];
-} __attribute__ ((packed));
+} __attribute__((packed));
/* Response: RDR_to_PC_Parameters */
/* Section 6.1.6 */
struct ccid_pc_to_rdr_reset_parameters {
struct ccid_header hdr;
uint8_t abRFU[3];
-} __attribute__ ((packed));
+} __attribute__((packed));
/* Response: RDR_to_PC_Parameters */
/* Section 6.1.7 */
enum ccid_protocol_num {
- CCID_PROTOCOL_NUM_T0 = 0x00,
- CCID_PROTOCOL_NUM_T1 = 0x01,
- CCID_PROTOCOL_NUM_2WIRE = 0x80,
- CCID_PROTOCOL_NUM_3WIRE = 0x81,
- CCID_PROTOCOL_NUM_I2C = 0x82,
+ CCID_PROTOCOL_NUM_T0 = 0x00,
+ CCID_PROTOCOL_NUM_T1 = 0x01,
+ CCID_PROTOCOL_NUM_2WIRE = 0x80,
+ CCID_PROTOCOL_NUM_3WIRE = 0x81,
+ CCID_PROTOCOL_NUM_I2C = 0x82,
};
enum ccid_clock_stop {
- CCID_CLOCK_STOP_NOTALLOWED = 0x00,
- CCID_CLOCK_STOP_LOW = 0x01,
- CCID_CLOCK_STOP_HIGH = 0x02,
- CCID_CLOCK_STOP_EITHER = 0x03,
+ CCID_CLOCK_STOP_NOTALLOWED = 0x00,
+ CCID_CLOCK_STOP_LOW = 0x01,
+ CCID_CLOCK_STOP_HIGH = 0x02,
+ CCID_CLOCK_STOP_EITHER = 0x03,
};
enum ccid_t1_csum_type {
- CCID_CSUM_TYPE_LRC = 0,
- CCID_CSUM_TYPE_CRC = 1,
+ CCID_CSUM_TYPE_LRC = 0,
+ CCID_CSUM_TYPE_CRC = 1,
};
struct ccid_proto_data_t0 {
uint8_t bmFindexDindex;
@@ -176,7 +176,7 @@
uint8_t bGuardTimeT0;
uint8_t bWaitingIntegerT0;
uint8_t bClockStop;
-} __attribute__ ((packed));
+} __attribute__((packed));
struct ccid_proto_data_t1 {
uint8_t bmFindexDindex;
uint8_t bmTCCKST1;
@@ -185,7 +185,7 @@
uint8_t bClockStop;
uint8_t bIFSC;
uint8_t bNadValue;
-} __attribute__ ((packed));
+} __attribute__((packed));
struct ccid_pc_to_rdr_set_parameters {
struct ccid_header hdr;
uint8_t bProtocolNum;
@@ -194,7 +194,7 @@
struct ccid_proto_data_t0 t0;
struct ccid_proto_data_t1 t1;
} abProtocolData;
-} __attribute__ ((packed));
+} __attribute__((packed));
/* Response: RDR_to_PC_Parameters */
/* Section 6.1.8 */
@@ -202,19 +202,19 @@
struct ccid_header hdr;
uint8_t abRFU[3];
uint8_t abData[0];
-} __attribute__ ((packed));
+} __attribute__((packed));
/* Response: RDR_to_PC_Escape */
/* Section 6.1.9 */
enum ccid_clock_command {
- CCID_CLOCK_CMD_RESTART = 0x00,
- CCID_CLOCK_CMD_STOP = 0x01,
+ CCID_CLOCK_CMD_RESTART = 0x00,
+ CCID_CLOCK_CMD_STOP = 0x01,
};
struct ccid_pc_to_rdr_icc_clock {
struct ccid_header hdr;
uint8_t bClockCommand;
uint8_t abRFU[2];
-} __attribute__ ((packed));
+} __attribute__((packed));
/* response: RDR_to_PC_SlotStatus */
/* Section 6.1.10 */
@@ -223,7 +223,7 @@
uint8_t bmChanges;
uint8_t bClassGetResponse;
uint8_t bClassEnvelope;
-} __attribute__ ((packed));
+} __attribute__((packed));
/* Response: RDR_to_PC_SlotStatus */
/* Section 6.1.11 */
@@ -232,11 +232,11 @@
uint8_t bBWI;
uint16_t wLevelParameter;
uint8_t abData[0];
-} __attribute__ ((packed));
+} __attribute__((packed));
struct ccid_pin_operation_data {
uint8_t bPINOperation;
uint8_t abPNDataStructure[0];
-} __attribute__ ((packed));
+} __attribute__((packed));
struct ccid_pin_verification_data {
uint8_t bTimeOut;
uint8_t bmFormatString;
@@ -249,7 +249,7 @@
uint8_t bMsgIndex;
uint8_t bTecPrologue;
uint8_t abPINApdu[0];
-} __attribute__ ((packed));
+} __attribute__((packed));
/* Response: RDR_to_PC_DataBlock */
/* Section 6.1.12 */
@@ -257,13 +257,13 @@
struct ccid_header hdr;
uint8_t bFunction; /* ccid_mech_function */
uint8_t abRFU[2];
-} __attribute__ ((packed));
+} __attribute__((packed));
enum ccid_mech_function {
- CCID_MECH_FN_ACCEPT_CARD = 0x01,
- CCID_MECH_FN_EJECT_CARD = 0x02,
- CCID_MECH_FN_CAPTURE_CARD = 0x03,
- CCID_MECH_FN_LOCK_CARD = 0x04,
- CCID_MECH_FN_UNLOCK_CARD = 0x05,
+ CCID_MECH_FN_ACCEPT_CARD = 0x01,
+ CCID_MECH_FN_EJECT_CARD = 0x02,
+ CCID_MECH_FN_CAPTURE_CARD = 0x03,
+ CCID_MECH_FN_LOCK_CARD = 0x04,
+ CCID_MECH_FN_UNLOCK_CARD = 0x05,
};
/* Response: RDR_to_PC_SlotStatus */
@@ -271,7 +271,7 @@
struct ccid_pc_to_rdr_abort {
struct ccid_header hdr;
uint8_t abRFU[3];
-} __attribute__ ((packed));
+} __attribute__((packed));
/* Response: RDR_to_PC_SlotStatus */
/* Section 6.1.14 */
@@ -280,24 +280,24 @@
uint8_t abRFU[3];
uint32_t dwClockFrequency;
uint32_t dwDataRate;
-} __attribute__ ((packed));
+} __attribute__((packed));
/* Response: RDR_to_PC_DataRateAndClockFrequency */
union ccid_pc_to_rdr {
- struct ccid_pc_to_rdr_icc_power_on icc_power_on;
- struct ccid_pc_to_rdr_icc_power_off icc_power_off;
- struct ccid_pc_to_rdr_get_slot_status get_slot_status;
- struct ccid_pc_to_rdr_xfr_block xfr_block;
- struct ccid_pc_to_rdr_get_parameters get_parameters;
- struct ccid_pc_to_rdr_reset_parameters reset_parameters;
- struct ccid_pc_to_rdr_set_parameters set_parameters;
- struct ccid_pc_to_rdr_escape escape;
- struct ccid_pc_to_rdr_icc_clock icc_clock;
- struct ccid_pc_to_rdr_t0apdu t0apdu;
- struct ccid_pc_to_rdr_secure secure;
- struct ccid_pc_to_rdr_mechanical mechanical;
- struct ccid_pc_to_rdr_abort abort;
- struct ccid_pc_to_rdr_set_rate_and_clock set_rate_and_clock;
+ struct ccid_pc_to_rdr_icc_power_on icc_power_on;
+ struct ccid_pc_to_rdr_icc_power_off icc_power_off;
+ struct ccid_pc_to_rdr_get_slot_status get_slot_status;
+ struct ccid_pc_to_rdr_xfr_block xfr_block;
+ struct ccid_pc_to_rdr_get_parameters get_parameters;
+ struct ccid_pc_to_rdr_reset_parameters reset_parameters;
+ struct ccid_pc_to_rdr_set_parameters set_parameters;
+ struct ccid_pc_to_rdr_escape escape;
+ struct ccid_pc_to_rdr_icc_clock icc_clock;
+ struct ccid_pc_to_rdr_t0apdu t0apdu;
+ struct ccid_pc_to_rdr_secure secure;
+ struct ccid_pc_to_rdr_mechanical mechanical;
+ struct ccid_pc_to_rdr_abort abort;
+ struct ccid_pc_to_rdr_set_rate_and_clock set_rate_and_clock;
};
/***********************************************************************
@@ -307,27 +307,27 @@
/* CCID message header on BULK-IN endpoint */
struct ccid_header_in {
struct ccid_header hdr;
- uint8_t bStatus;
- uint8_t bError;
-} __attribute__ ((packed));
+ uint8_t bStatus;
+ uint8_t bError;
+} __attribute__((packed));
/* Section 6.2.1 RDR_to_PC_DataBlock */
struct ccid_rdr_to_pc_data_block {
struct ccid_header_in hdr;
uint8_t bChainParameter;
uint8_t abData[0];
-} __attribute__ ((packed));
+} __attribute__((packed));
/* Section 6.2.2 RDR_to_PC_SlotStatus */
struct ccid_rdr_to_pc_slot_status {
struct ccid_header_in hdr;
uint8_t bClockStatus;
-} __attribute__ ((packed));
+} __attribute__((packed));
enum ccid_clock_status {
- CCID_CLOCK_STATUS_RUNNING = 0x00,
- CCID_CLOCK_STATUS_STOPPED_L = 0x01,
- CCID_CLOCK_STATUS_STOPPED_H = 0x02,
- CCID_CLOCK_STATUS_STOPPED_UNKN = 0x03,
+ CCID_CLOCK_STATUS_RUNNING = 0x00,
+ CCID_CLOCK_STATUS_STOPPED_L = 0x01,
+ CCID_CLOCK_STATUS_STOPPED_H = 0x02,
+ CCID_CLOCK_STATUS_STOPPED_UNKN = 0x03,
};
/* Section 6.2.3 RDR_to_PC_Parameters */
@@ -338,14 +338,14 @@
struct ccid_proto_data_t0 t0;
struct ccid_proto_data_t1 t1;
} abProtocolData;
-} __attribute__ ((packed));
+} __attribute__((packed));
/* Section 6.2.4 RDR_to_PC_Escape */
struct ccid_rdr_to_pc_escape {
struct ccid_header_in hdr;
uint8_t bRFU;
uint8_t abData[0];
-} __attribute__ ((packed));
+} __attribute__((packed));
/* Section 6.2.5 RDR_to_PC_DataRateAndClockFrequency */
struct ccid_rdr_to_pc_data_rate_and_clock {
@@ -353,43 +353,43 @@
uint8_t bRFU;
uint32_t dwClockFrequency;
uint32_t dwDataRate;
-} __attribute__ ((packed));
+} __attribute__((packed));
/* Section 6.2.6 */
-#define CCID_ICC_STATUS_MASK 0x03
-#define CCID_ICC_STATUS_PRES_ACT 0x00
-#define CCID_ICC_STATUS_PRES_INACT 0x01
-#define CCID_ICC_STATUS_NO_ICC 0x02
-#define CCID_CMD_STATUS_MASK 0xC0
-#define CCID_CMD_STATUS_OK 0x00
-#define CCID_CMD_STATUS_FAILED 0x40
-#define CCID_CMD_STATUS_TIME_EXT 0x80
+#define CCID_ICC_STATUS_MASK 0x03
+#define CCID_ICC_STATUS_PRES_ACT 0x00
+#define CCID_ICC_STATUS_PRES_INACT 0x01
+#define CCID_ICC_STATUS_NO_ICC 0x02
+#define CCID_CMD_STATUS_MASK 0xC0
+#define CCID_CMD_STATUS_OK 0x00
+#define CCID_CMD_STATUS_FAILED 0x40
+#define CCID_CMD_STATUS_TIME_EXT 0x80
/* Table 6.2-2: Slot Error value when bmCommandStatus == 1 */
enum ccid_error_code {
- CCID_ERR_CMD_ABORTED = 0xff,
- CCID_ERR_ICC_MUTE = 0xfe,
- CCID_ERR_XFR_PARITY_ERROR = 0xfd,
- CCID_ERR_XFR_OVERRUN = 0xfc,
- CCID_ERR_HW_ERROR = 0xfb,
- CCID_ERR_BAD_ATR_TS = 0xf8,
- CCID_ERR_BAD_ATR_TCK = 0xf7,
- CCID_ERR_ICC_PROTOCOL_NOT_SUPPORTED = 0xf6,
- CCID_ERR_ICC_CLASS_NOT_SUPPORTED = 0xf5,
- CCID_ERR_PROCEDURE_BYTE_CONFLICT = 0xf4,
- CCID_ERR_DEACTIVATED_PROTOCOL = 0xf3,
- CCID_ERR_BUSY_WITH_AUTO_SEQUENCE = 0xf2,
- CCID_ERR_PIN_TIMEOUT = 0xf0,
- CCID_ERR_PIN_CANCELLED = 0xef,
- CCID_ERR_CMD_SLOT_BUSY = 0xe0,
- CCID_ERR_CMD_NOT_SUPPORTED = 0x00
+ CCID_ERR_CMD_ABORTED = 0xff,
+ CCID_ERR_ICC_MUTE = 0xfe,
+ CCID_ERR_XFR_PARITY_ERROR = 0xfd,
+ CCID_ERR_XFR_OVERRUN = 0xfc,
+ CCID_ERR_HW_ERROR = 0xfb,
+ CCID_ERR_BAD_ATR_TS = 0xf8,
+ CCID_ERR_BAD_ATR_TCK = 0xf7,
+ CCID_ERR_ICC_PROTOCOL_NOT_SUPPORTED = 0xf6,
+ CCID_ERR_ICC_CLASS_NOT_SUPPORTED = 0xf5,
+ CCID_ERR_PROCEDURE_BYTE_CONFLICT = 0xf4,
+ CCID_ERR_DEACTIVATED_PROTOCOL = 0xf3,
+ CCID_ERR_BUSY_WITH_AUTO_SEQUENCE = 0xf2,
+ CCID_ERR_PIN_TIMEOUT = 0xf0,
+ CCID_ERR_PIN_CANCELLED = 0xef,
+ CCID_ERR_CMD_SLOT_BUSY = 0xe0,
+ CCID_ERR_CMD_NOT_SUPPORTED = 0x00
};
union ccid_rdr_to_pc {
- struct ccid_rdr_to_pc_data_block data_block;
- struct ccid_rdr_to_pc_slot_status slot_status;
- struct ccid_rdr_to_pc_parameters parameters;
- struct ccid_rdr_to_pc_escape escape;
- struct ccid_rdr_to_pc_data_rate_and_clock rate_and_clock;
+ struct ccid_rdr_to_pc_data_block data_block;
+ struct ccid_rdr_to_pc_slot_status slot_status;
+ struct ccid_rdr_to_pc_parameters parameters;
+ struct ccid_rdr_to_pc_escape escape;
+ struct ccid_rdr_to_pc_data_rate_and_clock rate_and_clock;
};
/***********************************************************************
@@ -399,8 +399,8 @@
/* Section 6.3.1 */
struct ccid_rdr_to_pc_notify_slot_change {
uint8_t bMessageType;
- uint8_t bmSlotCCState[0]; /* as long as bNumSlots/4 padded to next byte */
-} __attribute__ ((packed));
+ uint8_t bmSlotCCState[0]; /* as long as bNumSlots/4 padded to next byte */
+} __attribute__((packed));
/* Section 6.3.2 - Interrupt IN message (4 bytes, NOT bulk header format) */
struct ccid_rdr_to_pc_hardware_error {
@@ -408,17 +408,15 @@
uint8_t bSlot;
uint8_t bSeq;
uint8_t bHardwareErrorCode;
-} __attribute__ ((packed));
+} __attribute__((packed));
union ccid_rdr_to_pc_irq {
- struct ccid_rdr_to_pc_notify_slot_change slot_change;
- struct ccid_rdr_to_pc_hardware_error hw_error;
+ struct ccid_rdr_to_pc_notify_slot_change slot_change;
+ struct ccid_rdr_to_pc_hardware_error hw_error;
};
-
extern const struct value_string ccid_msg_type_vals[];
extern const struct value_string ccid_class_spec_req_vals[];
extern const struct value_string ccid_power_select_vals[];
extern const struct value_string ccid_clock_command_vals[];
extern const struct value_string ccid_error_code_vals[];
-
diff --git a/ccid_common/ccid_slot_fsm.c b/ccid_common/ccid_slot_fsm.c
index 05024c9..3f4053b 100644
--- a/ccid_common/ccid_slot_fsm.c
+++ b/ccid_common/ccid_slot_fsm.c
@@ -67,9 +67,10 @@
}
static const uint8_t sysmousim_sjs1_atr[] = {
- 0x3B, 0x9F, 0x96, 0x80, 0x1F, 0xC7, 0x80, 0x31,
- 0xA0, 0x73, 0xBE, 0x21, 0x13, 0x67, 0x43, 0x20,
- 0x07, 0x18, 0x00, 0x00, 0x01, 0xA5 };
+ 0x3B, 0x9F, 0x96, 0x80, 0x1F, 0xC7, 0x80, 0x31,
+ 0xA0, 0x73, 0xBE, 0x21, 0x13, 0x67, 0x43, 0x20,
+ 0x07, 0x18, 0x00, 0x00, 0x01, 0xA5
+};
static const struct ccid_pars_decoded iso_fsm_def_pars = {
.fi = 372,
@@ -88,7 +89,8 @@
/* do nothing; real hardware would update the slot related state here */
}
-static void iso_fsm_slot_icc_set_insertion_status(struct ccid_slot *cs, bool present) {
+static void iso_fsm_slot_icc_set_insertion_status(struct ccid_slot *cs, bool present)
+{
struct iso_fsm_slot *ss = ccid_slot2iso_fsm_slot(cs);
if (present == cs->icc_present)
@@ -106,7 +108,7 @@
}
static void iso_fsm_slot_icc_power_on_async(struct ccid_slot *cs, struct msgb *msg,
- const struct ccid_pc_to_rdr_icc_power_on *ipo)
+ const struct ccid_pc_to_rdr_icc_power_on *ipo)
{
struct iso_fsm_slot *ss = ccid_slot2iso_fsm_slot(cs);
enum ccid_power_select pwrsel = ipo->bPowerSelect;
@@ -137,22 +139,22 @@
osmo_fsm_inst_dispatch(ss->fi, ISO7816_E_POWER_UP_IND, NULL);
cs->icc_powered = true;
card_uart_ctrl(ss->cuart, CUART_CTL_CLOCK, true);
- #ifdef OCTSIMFWBUILD
+#ifdef OCTSIMFWBUILD
delay_us(10000);
- #else
+#else
usleep(10000);
- #endif
+#endif
osmo_fsm_inst_dispatch(ss->fi, ISO7816_E_RESET_REL_IND, NULL);
card_uart_ctrl(ss->cuart, CUART_CTL_RST, false);
} else { /* warm reset */
card_uart_ctrl(ss->cuart, CUART_CTL_RST, true);
osmo_fsm_inst_dispatch(ss->fi, ISO7816_E_RESET_ACT_IND, NULL);
- #ifdef OCTSIMFWBUILD
+#ifdef OCTSIMFWBUILD
delay_us(10000);
- #else
+#else
usleep(10000);
- #endif
+#endif
osmo_fsm_inst_dispatch(ss->fi, ISO7816_E_RESET_REL_IND, NULL);
card_uart_ctrl(ss->cuart, CUART_CTL_RST, false);
}
@@ -187,13 +189,13 @@
case ISO7816_E_PPS_DONE_IND:
cs->event_data = data;
#ifdef OCTSIMFWBUILD
- asm volatile("dmb st": : :"memory");
+ asm volatile("dmb st" : : : "memory");
#endif
cs->event = event;
break;
default:
LOGPCS(cs, LOGL_NOTICE, "%s(event=%d, cause=%d, data=%p) unhandled\n",
- __func__, event, cause, data);
+ __func__, event, cause, data);
break;
}
}
@@ -204,12 +206,12 @@
struct iso_fsm_slot *ss = ccid_slot2iso_fsm_slot(cs);
struct msgb *tpdu, *resp;
volatile uint32_t event = cs->event;
- volatile void * volatile data = cs->event_data;
+ volatile void *volatile data = cs->event_data;
if (!event)
return 0;
-// if(event && !data)
-// return 0;
+ // if(event && !data)
+ // return 0;
switch (event) {
case ISO7816_E_WTIME_EXP:
@@ -257,7 +259,7 @@
case ISO7816_E_TPDU_DONE_IND:
tpdu = data;
LOGPCS(cs, LOGL_DEBUG, "%s(event=%d, data=%s)\n", __func__, event,
- msgb_hexdump(tpdu));
+ msgb_hexdump(tpdu));
resp = ccid_gen_data_block(cs, ss->seq, CCID_CMD_STATUS_OK, 0, msgb_l4(tpdu), msgb_l4len(tpdu));
ccid_slot_send_unbusy(cs, resp);
cs->event = 0;
@@ -293,13 +295,13 @@
*/
#ifndef FAKE_CCID_SETPARAMETERS
card_uart_ctrl(ss->cuart, CUART_CTL_SET_CLOCK_FREQ, fmax);
- card_uart_ctrl(ss->cuart, CUART_CTL_SET_FD, F/D);
+ card_uart_ctrl(ss->cuart, CUART_CTL_SET_FD, F / D);
card_uart_ctrl(ss->cuart, CUART_CTL_WTIME, cs->proposed_pars.t0.waiting_integer * 960 * D_or_one);
cs->pars = cs->proposed_pars;
#else
//card_uart_ctrl(ss->cuart, CUART_CTL_SET_CLOCK_FREQ, fmax);
- card_uart_ctrl(ss->cuart, CUART_CTL_SET_FD, F/D);
+ card_uart_ctrl(ss->cuart, CUART_CTL_SET_FD, F / D);
//card_uart_ctrl(ss->cuart, CUART_CTL_WTIME, cs->proposed_pars.t0.waiting_integer);
cs->pars.fi = cs->proposed_pars.fi;
@@ -312,7 +314,7 @@
cs->event = 0;
break;
case ISO7816_E_PPS_UNSUPPORTED_IND:
- /* unsupported means no response, failed means request/response mismatch
+ /* unsupported means no response, failed means request/response mismatch
* yet both lead to a deactivation, and the host always gets a fi/di error
* 10 "FI - DI pair invalid or not supported" since that part of the
* ccid setparameters is handled by the pps exchange
@@ -336,7 +338,7 @@
break;
default:
LOGPCS(cs, LOGL_NOTICE, "%s(event=%d, data=%p) unhandled\n",
- __func__, event, data);
+ __func__, event, data);
break;
}
@@ -344,11 +346,10 @@
}
static int iso_fsm_slot_xfr_block_async(struct ccid_slot *cs, struct msgb *msg,
- const struct ccid_pc_to_rdr_xfr_block *xfb)
+ const struct ccid_pc_to_rdr_xfr_block *xfb)
{
struct iso_fsm_slot *ss = ccid_slot2iso_fsm_slot(cs);
-
ss->seq = xfb->hdr.bSeq;
/* must be '0' for TPDU level exchanges or for short APDU */
@@ -377,7 +378,6 @@
return 1;
}
-
static void iso_fsm_slot_set_power(struct ccid_slot *cs, bool enable)
{
struct iso_fsm_slot *ss = ccid_slot2iso_fsm_slot(cs);
@@ -408,19 +408,19 @@
}
static int iso_fsm_slot_set_params(struct ccid_slot *cs, uint8_t seq, enum ccid_protocol_num proto,
- const struct ccid_pars_decoded *pars_dec)
+ const struct ccid_pars_decoded *pars_dec)
{
struct iso_fsm_slot *ss = ccid_slot2iso_fsm_slot(cs);
uint8_t PPS1 = (pars_dec->fi << 4 | pars_dec->di);
/* see 6.1.7 for error offsets */
- if(proto != CCID_PROTOCOL_NUM_T0)
+ if (proto != CCID_PROTOCOL_NUM_T0)
return -7;
- if(pars_dec->t0.guard_time_etu != 0)
+ if (pars_dec->t0.guard_time_etu != 0)
return -12;
- if(pars_dec->clock_stop != CCID_CLOCK_STOP_NOTALLOWED)
+ if (pars_dec->clock_stop != CCID_CLOCK_STOP_NOTALLOWED)
return -14;
ss->seq = seq;
@@ -439,20 +439,20 @@
ccid_slot_send_unbusy(cs, ccid_gen_parameters_t0(cs, ss->seq, CCID_CMD_STATUS_OK, 0));
#else
/* pass PPS1 instead of msgb */
- osmo_fsm_inst_dispatch(ss->fi, ISO7816_E_XCEIVE_PPS_CMD, (void*)PPS1);
+ osmo_fsm_inst_dispatch(ss->fi, ISO7816_E_XCEIVE_PPS_CMD, (void *)PPS1);
#endif
/* continues in iso_fsm_clot_user_cb once response/error/timeout is received */
return 0;
}
-static int iso_fsm_slot_set_rate_and_clock(struct ccid_slot *cs, uint32_t* freq_hz, uint32_t* rate_bps)
+static int iso_fsm_slot_set_rate_and_clock(struct ccid_slot *cs, uint32_t *freq_hz, uint32_t *rate_bps)
{
/* we return the currently used values, since we support automatic features */
struct iso_fsm_slot *ss = ccid_slot2iso_fsm_slot(cs);
*rate_bps = card_uart_ctrl(ss->cuart, CUART_CTL_GET_BAUDRATE, false);
- *freq_hz = card_uart_ctrl(ss->cuart, CUART_CTL_GET_CLOCK_FREQ, false)/1000;
+ *freq_hz = card_uart_ctrl(ss->cuart, CUART_CTL_GET_CLOCK_FREQ, false) / 1000;
return 0;
}
@@ -463,8 +463,8 @@
void *ctx = g_tall_ctx; /* FIXME */
struct iso_fsm_slot *ss = ccid_slot2iso_fsm_slot(cs);
struct card_uart *cuart = talloc_zero(ctx, struct card_uart);
- char id_buf[3+3+1];
- char devname[2+1];
+ char id_buf[3 + 3 + 1];
+ char devname[2 + 1];
char *devnamep = 0;
char *drivername = "asf4";
int rc;
@@ -506,7 +506,6 @@
ss->cuart = cuart;
ss->cs = cs;
-
return 0;
}
diff --git a/ccid_common/cuart.c b/ccid_common/cuart.c
index d228c13..0013fce 100644
--- a/ccid_common/cuart.c
+++ b/ccid_common/cuart.c
@@ -38,7 +38,7 @@
static struct card_uart_driver *cuart_drv_by_name(const char *driver_name)
{
struct card_uart_driver *drv;
- llist_for_each_entry(drv, &g_cuart_drivers, list) {
+ llist_for_each_entry (drv, &g_cuart_drivers, list) {
if (!strcmp(drv->name, driver_name))
return drv;
}
@@ -59,7 +59,7 @@
/* software waiting-time timer has expired */
static void card_uart_wtime_cb(void *data)
{
- struct card_uart *cuart = (struct card_uart *) data;
+ struct card_uart *cuart = (struct card_uart *)data;
card_uart_notification(cuart, CUART_E_RX_TIMEOUT, NULL);
/* should we automatically disable the receiver? */
}
@@ -138,12 +138,12 @@
cuart->rx_enabled = arg ? true : false;
if (!cuart->rx_enabled)
osmo_timer_del(&cuart->wtime_tmr);
-// else
-// card_uart_wtime_restart(cuart);
+ // else
+ // card_uart_wtime_restart(cuart);
break;
case CUART_CTL_RX_TIMER_HINT:
cuart->current_wtime_byte = arg;
- if(arg)
+ if (arg)
card_uart_wtime_restart(cuart);
else
osmo_timer_del(&cuart->wtime_tmr);
@@ -210,12 +210,12 @@
if (cuart->rx_after_tx_compl)
card_uart_ctrl(cuart, CUART_CTL_RX, true);
break;
-// case CUART_E_RX_COMPLETE:
-// osmo_timer_del(&cuart->wtime_tmr);
-// break;
-// case CUART_E_RX_SINGLE:
-// card_uart_wtime_restart(cuart);
-// break;
+ // case CUART_E_RX_COMPLETE:
+ // osmo_timer_del(&cuart->wtime_tmr);
+ // break;
+ // case CUART_E_RX_SINGLE:
+ // card_uart_wtime_restart(cuart);
+ // break;
default:
break;
}
diff --git a/ccid_common/cuart.h b/ccid_common/cuart.h
index c8573c5..f647d57 100644
--- a/ccid_common/cuart.h
+++ b/ccid_common/cuart.h
@@ -42,16 +42,16 @@
extern const struct value_string card_uart_event_vals[];
enum card_uart_ctl {
- CUART_CTL_RX, /* enable/disable receiver */
+ CUART_CTL_RX, /* enable/disable receiver */
CUART_CTL_RX_TIMER_HINT, /* tell cuart approximate number of rx bytes */
- CUART_CTL_NO_RXTX, /* enable/disable receiver */
+ CUART_CTL_NO_RXTX, /* enable/disable receiver */
CUART_CTL_POWER_5V0,
CUART_CTL_POWER_3V0,
CUART_CTL_POWER_1V8,
- CUART_CTL_CLOCK, /* enable/disable ICC clock */
+ CUART_CTL_CLOCK, /* enable/disable ICC clock */
CUART_CTL_SET_CLOCK_FREQ, /* set ICC clock frequency (hz)*/
- CUART_CTL_RST, /* enable/disable ICC reset */
- CUART_CTL_WTIME, /* set the waiting time (in etu) */
+ CUART_CTL_RST, /* enable/disable ICC reset */
+ CUART_CTL_WTIME, /* set the waiting time (in etu) */
CUART_CTL_SET_FD,
CUART_CTL_GET_BAUDRATE,
CUART_CTL_GET_CLOCK_FREQ,
diff --git a/ccid_common/iso7816_3.c b/ccid_common/iso7816_3.c
index 9a3a7cb..d131fcf 100644
--- a/ccid_common/iso7816_3.c
+++ b/ccid_common/iso7816_3.c
@@ -32,8 +32,22 @@
};
const uint8_t iso7816_3_di_table[16] = {
- 0, 1, 2, 4, 8, 16, 32, 64,
- 12, 20, 0, 0, 0, 0, 0, 0,
+ 0,
+ 1,
+ 2,
+ 4,
+ 8,
+ 16,
+ 32,
+ 64,
+ 12,
+ 20,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
};
/* all values are based on the Elementary Time Unit (ETU), defined in ISO/IEC 7816-3 section 7.1
@@ -68,7 +82,8 @@
return false;
}
uint8_t i = 0;
- for (i = 0; i < ARRAY_SIZE(iso7816_3_fi_table) && iso7816_3_fi_table[i] != f; i++);
+ for (i = 0; i < ARRAY_SIZE(iso7816_3_fi_table) && iso7816_3_fi_table[i] != f; i++)
+ ;
return (i < ARRAY_SIZE(iso7816_3_fi_table) && iso7816_3_fi_table[i] == f);
}
@@ -78,7 +93,8 @@
return false;
}
uint8_t i = 0;
- for (i = 0; i < ARRAY_SIZE(iso7816_3_di_table) && iso7816_3_di_table[i] != d; i++);
+ for (i = 0; i < ARRAY_SIZE(iso7816_3_di_table) && iso7816_3_di_table[i] != d; i++)
+ ;
return (i < ARRAY_SIZE(iso7816_3_di_table) && iso7816_3_di_table[i] == d);
}
@@ -119,5 +135,5 @@
return -7;
}
- return wi * 960UL * (fi/f) * (di/d); // calculate timeout value in ETU
+ return wi * 960UL * (fi / f) * (di / d); // calculate timeout value in ETU
}
diff --git a/ccid_common/iso7816_fsm.c b/ccid_common/iso7816_fsm.c
index a035148..73a7f74 100644
--- a/ccid_common/iso7816_fsm.c
+++ b/ccid_common/iso7816_fsm.c
@@ -34,50 +34,52 @@
#include "iso7816_fsm.h"
/* unionize to ensure at least properly aligned msgb struct */
-#define DECLARE_STATIC_MSGB(name, size) \
- struct msgb* name; \
- union { \
- struct msgb name ## dummy; \
- unsigned char name ## _msgbuf[sizeof(struct msgb) + size]; \
+#define DECLARE_STATIC_MSGB(name, size) \
+ struct msgb *name; \
+ union { \
+ struct msgb name##dummy; \
+ unsigned char name##_msgbuf[sizeof(struct msgb) + size]; \
};
-#define INIT_STATIC_MSGB(name) { \
- name = (struct msgb*)name ## _msgbuf; \
- memset(name, 0x00, sizeof(name ## _msgbuf)); \
- name->data_len = sizeof(name ## _msgbuf) - sizeof(struct msgb); \
- name->len = 0; \
- name->data = &name->_data[0]; \
- name->head = &name->_data[0]; \
- name->tail = &name->_data[0]; \
-}
+#define INIT_STATIC_MSGB(name) \
+ { \
+ name = (struct msgb *)name##_msgbuf; \
+ memset(name, 0x00, sizeof(name##_msgbuf)); \
+ name->data_len = sizeof(name##_msgbuf) - sizeof(struct msgb); \
+ name->len = 0; \
+ name->data = &name->_data[0]; \
+ name->head = &name->_data[0]; \
+ name->tail = &name->_data[0]; \
+ }
-#define COPY_TO_STATIC_MSGB(src, dst) { \
- struct msgb *new_msg = dst; \
- struct msgb *msg = src; \
- \
- /* copy data */ \
- memcpy(new_msg->_data, msg->_data, new_msg->data_len); \
- \
- /* copy header */ \
- new_msg->len = msg->len; \
- new_msg->data += msg->data - msg->_data; \
- new_msg->head += msg->head - msg->_data; \
- new_msg->tail += msg->tail - msg->_data; \
- \
- if (msg->l1h) \
- new_msg->l1h = new_msg->_data + (msg->l1h - msg->_data); \
- if (msg->l2h) \
- new_msg->l2h = new_msg->_data + (msg->l2h - msg->_data); \
- if (msg->l3h) \
- new_msg->l3h = new_msg->_data + (msg->l3h - msg->_data); \
- if (msg->l4h) \
- new_msg->l4h = new_msg->_data + (msg->l4h - msg->_data); \
+#define COPY_TO_STATIC_MSGB(src, dst) \
+ { \
+ struct msgb *new_msg = dst; \
+ struct msgb *msg = src; \
+ \
+ /* copy data */ \
+ memcpy(new_msg->_data, msg->_data, new_msg->data_len); \
+ \
+ /* copy header */ \
+ new_msg->len = msg->len; \
+ new_msg->data += msg->data - msg->_data; \
+ new_msg->head += msg->head - msg->_data; \
+ new_msg->tail += msg->tail - msg->_data; \
+ \
+ if (msg->l1h) \
+ new_msg->l1h = new_msg->_data + (msg->l1h - msg->_data); \
+ if (msg->l2h) \
+ new_msg->l2h = new_msg->_data + (msg->l2h - msg->_data); \
+ if (msg->l3h) \
+ new_msg->l3h = new_msg->_data + (msg->l3h - msg->_data); \
+ if (msg->l4h) \
+ new_msg->l4h = new_msg->_data + (msg->l4h - msg->_data); \
}
/* Section 8.2: the Answer-to-Reset (... a string of at most 32 bytes) */
#define MAX_ATR_SIZE 32
-#define S(x) (1 << (x))
+#define S(x) (1 << (x))
/*! ISO 7816-3 states */
enum iso7816_3_state {
@@ -109,7 +111,7 @@
* @note defined in ISO/IEC 7816-3:2006(E) section 9
*/
enum pps_state {
- PPS_S_PPS_REQ_INIT, /*!< tx pps request */
+ PPS_S_PPS_REQ_INIT, /*!< tx pps request */
PPS_S_TX_PPS_REQ,
PPS_S_WAIT_PPSX, /*!< initial byte */
PPS_S_WAIT_PPS0, /*!< format byte */
@@ -164,35 +166,275 @@
#else
/* look-up table for bit-wise inversion to convert from "inverse convention" to normal */
static const uint8_t convention_convert_lut[256] = {
- 0xff, 0x7f, 0xbf, 0x3f, 0xdf, 0x5f, 0x9f, 0x1f, 0xef, 0x6f, 0xaf, 0x2f, 0xcf, 0x4f, 0x8f, 0x0f,
- 0xf7, 0x77, 0xb7, 0x37, 0xd7, 0x57, 0x97, 0x17, 0xe7, 0x67, 0xa7, 0x27, 0xc7, 0x47, 0x87, 0x07,
- 0xfb, 0x7b, 0xbb, 0x3b, 0xdb, 0x5b, 0x9b, 0x1b, 0xeb, 0x6b, 0xab, 0x2b, 0xcb, 0x4b, 0x8b, 0x0b,
- 0xf3, 0x73, 0xb3, 0x33, 0xd3, 0x53, 0x93, 0x13, 0xe3, 0x63, 0xa3, 0x23, 0xc3, 0x43, 0x83, 0x03,
- 0xfd, 0x7d, 0xbd, 0x3d, 0xdd, 0x5d, 0x9d, 0x1d, 0xed, 0x6d, 0xad, 0x2d, 0xcd, 0x4d, 0x8d, 0x0d,
- 0xf5, 0x75, 0xb5, 0x35, 0xd5, 0x55, 0x95, 0x15, 0xe5, 0x65, 0xa5, 0x25, 0xc5, 0x45, 0x85, 0x05,
- 0xf9, 0x79, 0xb9, 0x39, 0xd9, 0x59, 0x99, 0x19, 0xe9, 0x69, 0xa9, 0x29, 0xc9, 0x49, 0x89, 0x09,
- 0xf1, 0x71, 0xb1, 0x31, 0xd1, 0x51, 0x91, 0x11, 0xe1, 0x61, 0xa1, 0x21, 0xc1, 0x41, 0x81, 0x01,
- 0xfe, 0x7e, 0xbe, 0x3e, 0xde, 0x5e, 0x9e, 0x1e, 0xee, 0x6e, 0xae, 0x2e, 0xce, 0x4e, 0x8e, 0x0e,
- 0xf6, 0x76, 0xb6, 0x36, 0xd6, 0x56, 0x96, 0x16, 0xe6, 0x66, 0xa6, 0x26, 0xc6, 0x46, 0x86, 0x06,
- 0xfa, 0x7a, 0xba, 0x3a, 0xda, 0x5a, 0x9a, 0x1a, 0xea, 0x6a, 0xaa, 0x2a, 0xca, 0x4a, 0x8a, 0x0a,
- 0xf2, 0x72, 0xb2, 0x32, 0xd2, 0x52, 0x92, 0x12, 0xe2, 0x62, 0xa2, 0x22, 0xc2, 0x42, 0x82, 0x02,
- 0xfc, 0x7c, 0xbc, 0x3c, 0xdc, 0x5c, 0x9c, 0x1c, 0xec, 0x6c, 0xac, 0x2c, 0xcc, 0x4c, 0x8c, 0x0c,
- 0xf4, 0x74, 0xb4, 0x34, 0xd4, 0x54, 0x94, 0x14, 0xe4, 0x64, 0xa4, 0x24, 0xc4, 0x44, 0x84, 0x04,
- 0xf8, 0x78, 0xb8, 0x38, 0xd8, 0x58, 0x98, 0x18, 0xe8, 0x68, 0xa8, 0x28, 0xc8, 0x48, 0x88, 0x08,
- 0xf0, 0x70, 0xb0, 0x30, 0xd0, 0x50, 0x90, 0x10, 0xe0, 0x60, 0xa0, 0x20, 0xc0, 0x40, 0x80, 0x00,
+ 0xff,
+ 0x7f,
+ 0xbf,
+ 0x3f,
+ 0xdf,
+ 0x5f,
+ 0x9f,
+ 0x1f,
+ 0xef,
+ 0x6f,
+ 0xaf,
+ 0x2f,
+ 0xcf,
+ 0x4f,
+ 0x8f,
+ 0x0f,
+ 0xf7,
+ 0x77,
+ 0xb7,
+ 0x37,
+ 0xd7,
+ 0x57,
+ 0x97,
+ 0x17,
+ 0xe7,
+ 0x67,
+ 0xa7,
+ 0x27,
+ 0xc7,
+ 0x47,
+ 0x87,
+ 0x07,
+ 0xfb,
+ 0x7b,
+ 0xbb,
+ 0x3b,
+ 0xdb,
+ 0x5b,
+ 0x9b,
+ 0x1b,
+ 0xeb,
+ 0x6b,
+ 0xab,
+ 0x2b,
+ 0xcb,
+ 0x4b,
+ 0x8b,
+ 0x0b,
+ 0xf3,
+ 0x73,
+ 0xb3,
+ 0x33,
+ 0xd3,
+ 0x53,
+ 0x93,
+ 0x13,
+ 0xe3,
+ 0x63,
+ 0xa3,
+ 0x23,
+ 0xc3,
+ 0x43,
+ 0x83,
+ 0x03,
+ 0xfd,
+ 0x7d,
+ 0xbd,
+ 0x3d,
+ 0xdd,
+ 0x5d,
+ 0x9d,
+ 0x1d,
+ 0xed,
+ 0x6d,
+ 0xad,
+ 0x2d,
+ 0xcd,
+ 0x4d,
+ 0x8d,
+ 0x0d,
+ 0xf5,
+ 0x75,
+ 0xb5,
+ 0x35,
+ 0xd5,
+ 0x55,
+ 0x95,
+ 0x15,
+ 0xe5,
+ 0x65,
+ 0xa5,
+ 0x25,
+ 0xc5,
+ 0x45,
+ 0x85,
+ 0x05,
+ 0xf9,
+ 0x79,
+ 0xb9,
+ 0x39,
+ 0xd9,
+ 0x59,
+ 0x99,
+ 0x19,
+ 0xe9,
+ 0x69,
+ 0xa9,
+ 0x29,
+ 0xc9,
+ 0x49,
+ 0x89,
+ 0x09,
+ 0xf1,
+ 0x71,
+ 0xb1,
+ 0x31,
+ 0xd1,
+ 0x51,
+ 0x91,
+ 0x11,
+ 0xe1,
+ 0x61,
+ 0xa1,
+ 0x21,
+ 0xc1,
+ 0x41,
+ 0x81,
+ 0x01,
+ 0xfe,
+ 0x7e,
+ 0xbe,
+ 0x3e,
+ 0xde,
+ 0x5e,
+ 0x9e,
+ 0x1e,
+ 0xee,
+ 0x6e,
+ 0xae,
+ 0x2e,
+ 0xce,
+ 0x4e,
+ 0x8e,
+ 0x0e,
+ 0xf6,
+ 0x76,
+ 0xb6,
+ 0x36,
+ 0xd6,
+ 0x56,
+ 0x96,
+ 0x16,
+ 0xe6,
+ 0x66,
+ 0xa6,
+ 0x26,
+ 0xc6,
+ 0x46,
+ 0x86,
+ 0x06,
+ 0xfa,
+ 0x7a,
+ 0xba,
+ 0x3a,
+ 0xda,
+ 0x5a,
+ 0x9a,
+ 0x1a,
+ 0xea,
+ 0x6a,
+ 0xaa,
+ 0x2a,
+ 0xca,
+ 0x4a,
+ 0x8a,
+ 0x0a,
+ 0xf2,
+ 0x72,
+ 0xb2,
+ 0x32,
+ 0xd2,
+ 0x52,
+ 0x92,
+ 0x12,
+ 0xe2,
+ 0x62,
+ 0xa2,
+ 0x22,
+ 0xc2,
+ 0x42,
+ 0x82,
+ 0x02,
+ 0xfc,
+ 0x7c,
+ 0xbc,
+ 0x3c,
+ 0xdc,
+ 0x5c,
+ 0x9c,
+ 0x1c,
+ 0xec,
+ 0x6c,
+ 0xac,
+ 0x2c,
+ 0xcc,
+ 0x4c,
+ 0x8c,
+ 0x0c,
+ 0xf4,
+ 0x74,
+ 0xb4,
+ 0x34,
+ 0xd4,
+ 0x54,
+ 0x94,
+ 0x14,
+ 0xe4,
+ 0x64,
+ 0xa4,
+ 0x24,
+ 0xc4,
+ 0x44,
+ 0x84,
+ 0x04,
+ 0xf8,
+ 0x78,
+ 0xb8,
+ 0x38,
+ 0xd8,
+ 0x58,
+ 0x98,
+ 0x18,
+ 0xe8,
+ 0x68,
+ 0xa8,
+ 0x28,
+ 0xc8,
+ 0x48,
+ 0x88,
+ 0x08,
+ 0xf0,
+ 0x70,
+ 0xb0,
+ 0x30,
+ 0xd0,
+ 0x50,
+ 0x90,
+ 0x10,
+ 0xe0,
+ 0x60,
+ 0xa0,
+ 0x20,
+ 0xc0,
+ 0x40,
+ 0x80,
+ 0x00,
};
-#define invert_flip_uint8(XX) \
- do { \
- _Static_assert(__builtin_types_compatible_p(__typeof__(XX), uint8_t), \
- "invert_flip_uint8 argument must be uint8_t"); \
- XX = convention_convert_lut[XX]; \
+#define invert_flip_uint8(XX) \
+ do { \
+ _Static_assert(__builtin_types_compatible_p(__typeof__(XX), uint8_t), \
+ "invert_flip_uint8 argument must be uint8_t"); \
+ XX = convention_convert_lut[XX]; \
} while (0)
#endif
struct atr_fsm_priv {
- uint8_t hist_len; /*!< store the number of expected historical bytes */
- uint8_t y; /*!< last mask of the upcoming TA, TB, TC, TD interface bytes */
- uint8_t i; /*!< interface byte subgroup number */
+ uint8_t hist_len; /*!< store the number of expected historical bytes */
+ uint8_t y; /*!< last mask of the upcoming TA, TB, TC, TD interface bytes */
+ uint8_t i; /*!< interface byte subgroup number */
DECLARE_STATIC_MSGB(atr, 33) /*!< ATR data */
uint8_t computed_checksum;
uint16_t protocol_support;
@@ -218,26 +460,26 @@
***********************************************************************/
static const struct value_string iso7816_3_event_names[] = {
- { ISO7816_E_RX_SINGLE, "UART_RX_SINGLE" },
- { ISO7816_E_RX_COMPL, "UART_RX_COMPL" },
- { ISO7816_E_TX_COMPL, "UART_TX_COMPL" },
- { ISO7816_E_POWER_UP_IND, "POWER_UP_IND" },
- { ISO7816_E_RESET_REL_IND, "RESET_REL_IND" },
- { ISO7816_E_RX_ERR_IND, "RX_ERR_IND" },
- { ISO7816_E_TX_ERR_IND, "TX_ERR_IND" },
- { ISO7816_E_ATR_DONE_IND, "ATR_DONE_IND" },
- { ISO7816_E_ATR_ERR_IND, "ATR_ERR_IND" },
- { ISO7816_E_TPDU_DONE_IND, "TPDU_DONE_IND" },
- { ISO7816_E_XCEIVE_TPDU_CMD, "XCEIVE_TPDU_CMD" },
+ { ISO7816_E_RX_SINGLE, "UART_RX_SINGLE" },
+ { ISO7816_E_RX_COMPL, "UART_RX_COMPL" },
+ { ISO7816_E_TX_COMPL, "UART_TX_COMPL" },
+ { ISO7816_E_POWER_UP_IND, "POWER_UP_IND" },
+ { ISO7816_E_RESET_REL_IND, "RESET_REL_IND" },
+ { ISO7816_E_RX_ERR_IND, "RX_ERR_IND" },
+ { ISO7816_E_TX_ERR_IND, "TX_ERR_IND" },
+ { ISO7816_E_ATR_DONE_IND, "ATR_DONE_IND" },
+ { ISO7816_E_ATR_ERR_IND, "ATR_ERR_IND" },
+ { ISO7816_E_TPDU_DONE_IND, "TPDU_DONE_IND" },
+ { ISO7816_E_XCEIVE_TPDU_CMD, "XCEIVE_TPDU_CMD" },
/* allstate events */
- { ISO7816_E_WTIME_EXP, "WAIT_TIME_EXP" },
- { ISO7816_E_HW_ERR_IND, "HW_ERR_IND" },
- { ISO7816_E_SW_ERR_IND, "SW_ERR_IND" },
- { ISO7816_E_CARD_REMOVAL, "CARD_REMOVAL" },
- { ISO7816_E_POWER_DN_IND, "POWER_DN_IND" },
- { ISO7816_E_RESET_ACT_IND, "RESET_ACT_IND" },
- { ISO7816_E_ABORT_REQ, "ABORT_REQ" },
- { ISO7816_E_TPDU_CLEAR_REQ, "TPDU_CLEAR_REQ" },
+ { ISO7816_E_WTIME_EXP, "WAIT_TIME_EXP" },
+ { ISO7816_E_HW_ERR_IND, "HW_ERR_IND" },
+ { ISO7816_E_SW_ERR_IND, "SW_ERR_IND" },
+ { ISO7816_E_CARD_REMOVAL, "CARD_REMOVAL" },
+ { ISO7816_E_POWER_DN_IND, "POWER_DN_IND" },
+ { ISO7816_E_RESET_ACT_IND, "RESET_ACT_IND" },
+ { ISO7816_E_ABORT_REQ, "ABORT_REQ" },
+ { ISO7816_E_TPDU_CLEAR_REQ, "TPDU_CLEAR_REQ" },
{ 0, NULL }
};
@@ -248,7 +490,7 @@
struct osmo_fsm_inst *pps_fi;
struct osmo_fsm_inst *tpdu_fi;
/* other data */
- bool convention_convert;/*!< If convention conversion is needed */
+ bool convention_convert; /*!< If convention conversion is needed */
uint16_t guard_time_ms;
/* underlying UART */
struct card_uart *uart;
@@ -261,7 +503,7 @@
{
OSMO_ASSERT(fi);
OSMO_ASSERT(fi->fsm == &iso7816_3_fsm);
- return (struct iso7816_3_priv *) fi->priv;
+ return (struct iso7816_3_priv *)fi->priv;
}
/* convert from clock cycles of the CLK line to milli-seconds */
@@ -275,7 +517,7 @@
/* card UART notifies us: dispatch to (main ISO7816-3) FSM */
static void tpdu_uart_notification(struct card_uart *cuart, enum card_uart_event evt, void *data)
{
- struct osmo_fsm_inst *fi = (struct osmo_fsm_inst *) cuart->priv;
+ struct osmo_fsm_inst *fi = (struct osmo_fsm_inst *)cuart->priv;
OSMO_ASSERT(fi->fsm == &iso7816_3_fsm);
LOGPFSML(fi, LOGL_DEBUG, "UART Notification '%s'\n",
@@ -452,13 +694,13 @@
/* no break */
case ISO7816_E_CARD_REMOVAL:
/* FIXME: power off? */
- if(fi->state == ISO7816_S_WAIT_ATR || fi->state == ISO7816_S_IN_ATR)
+ if (fi->state == ISO7816_S_WAIT_ATR || fi->state == ISO7816_S_IN_ATR)
ip->user_cb(fi, ISO7816_E_ATR_ERR_IND, 0, atp->atr);
- if(fi->state == ISO7816_S_WAIT_PPS_RSP || fi->state == ISO7816_S_IN_PPS_RSP)
+ if (fi->state == ISO7816_S_WAIT_PPS_RSP || fi->state == ISO7816_S_IN_PPS_RSP)
ip->user_cb(fi, ISO7816_E_PPS_UNSUPPORTED_IND, 0, ppp->tx_cmd);
- if(fi->state == ISO7816_S_IN_TPDU)
+ if (fi->state == ISO7816_S_IN_TPDU)
ip->user_cb(fi, ISO7816_E_TPDU_FAILED_IND, 0, tpdup->tpdu);
osmo_fsm_inst_state_chg(fi, ISO7816_S_RESET, 0, 0);
@@ -471,15 +713,15 @@
/* FIXME */
break;
case ISO7816_E_WTIME_EXP:
- if(fi->state == ISO7816_S_WAIT_ATR || fi->state == ISO7816_S_IN_ATR) {
+ if (fi->state == ISO7816_S_WAIT_ATR || fi->state == ISO7816_S_IN_ATR) {
/* atr timeout instead of tck might be fine */
osmo_fsm_inst_dispatch(ip->atr_fi, event, data);
break;
}
- if(fi->state == ISO7816_S_WAIT_PPS_RSP || fi->state == ISO7816_S_IN_PPS_RSP)
+ if (fi->state == ISO7816_S_WAIT_PPS_RSP || fi->state == ISO7816_S_IN_PPS_RSP)
ip->user_cb(fi, ISO7816_E_PPS_UNSUPPORTED_IND, 0, ppp->tx_cmd);
- if(fi->state == ISO7816_S_WAIT_TPDU || fi->state == ISO7816_S_IN_TPDU)
+ if (fi->state == ISO7816_S_WAIT_TPDU || fi->state == ISO7816_S_IN_TPDU)
ip->user_cb(fi, ISO7816_E_TPDU_FAILED_IND, 0, tpdup->tpdu);
osmo_fsm_inst_state_chg(fi, ISO7816_S_RESET, 0, 0);
@@ -494,7 +736,6 @@
}
}
-
static void iso7816_3_s_wait_pps_rsp_action(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
struct iso7816_3_priv *ip = get_iso7816_3_priv(fi);
@@ -546,75 +787,48 @@
static const struct osmo_fsm_state iso7816_3_states[] = {
[ISO7816_S_RESET] = {
.name = "RESET",
- .in_event_mask = S(ISO7816_E_RESET_REL_IND) |
- S(ISO7816_E_POWER_UP_IND),
- .out_state_mask = S(ISO7816_S_WAIT_ATR) |
- S(ISO7816_S_RESET),
+ .in_event_mask = S(ISO7816_E_RESET_REL_IND) |
+ S(ISO7816_E_POWER_UP_IND),
+ .out_state_mask = S(ISO7816_S_WAIT_ATR) |
+ S(ISO7816_S_RESET),
.action = iso7816_3_reset_action,
.onenter = iso7816_3_reset_onenter,
},
[ISO7816_S_WAIT_ATR] = {
.name = "WAIT_ATR",
- .in_event_mask = S(ISO7816_E_RX_SINGLE),
- .out_state_mask = S(ISO7816_S_RESET) |
- S(ISO7816_S_IN_ATR),
+ .in_event_mask = S(ISO7816_E_RX_SINGLE),
+ .out_state_mask = S(ISO7816_S_RESET) | S(ISO7816_S_IN_ATR),
.action = iso7816_3_wait_atr_action,
},
[ISO7816_S_IN_ATR] = {
.name = "IN_ATR",
- .in_event_mask = S(ISO7816_E_RX_SINGLE) |
- S(ISO7816_E_RX_ERR_IND) |
- S(ISO7816_E_ATR_DONE_IND),
- .out_state_mask = S(ISO7816_S_RESET) |
- S(ISO7816_S_IN_ATR) |
- S(ISO7816_S_WAIT_TPDU),
+ .in_event_mask = S(ISO7816_E_RX_SINGLE) | S(ISO7816_E_RX_ERR_IND) | S(ISO7816_E_ATR_DONE_IND),
+ .out_state_mask = S(ISO7816_S_RESET) | S(ISO7816_S_IN_ATR) | S(ISO7816_S_WAIT_TPDU),
.action = iso7816_3_in_atr_action,
},
[ISO7816_S_WAIT_TPDU] = {
.name = "WAIT_TPDU",
- .in_event_mask = S(ISO7816_E_XCEIVE_TPDU_CMD) |
- S(ISO7816_E_XCEIVE_PPS_CMD),
- .out_state_mask = S(ISO7816_S_RESET) |
- S(ISO7816_S_WAIT_TPDU) |
- S(ISO7816_S_IN_TPDU) |
- S(ISO7816_S_WAIT_PPS_RSP),
+ .in_event_mask = S(ISO7816_E_XCEIVE_TPDU_CMD) | S(ISO7816_E_XCEIVE_PPS_CMD),
+ .out_state_mask = S(ISO7816_S_RESET) | S(ISO7816_S_WAIT_TPDU) | S(ISO7816_S_IN_TPDU) | S(ISO7816_S_WAIT_PPS_RSP),
.action = iso7816_3_wait_tpdu_action,
.onenter = iso7816_3_wait_tpdu_onenter,
},
[ISO7816_S_IN_TPDU] = {
.name = "IN_TPDU",
- .in_event_mask = S(ISO7816_E_RX_SINGLE) |
- S(ISO7816_E_RX_COMPL) |
- S(ISO7816_E_TX_COMPL) |
- S(ISO7816_E_RX_ERR_IND) |
- S(ISO7816_E_TX_ERR_IND) |
- S(ISO7816_E_TPDU_DONE_IND),
- .out_state_mask = S(ISO7816_S_RESET) |
- S(ISO7816_S_WAIT_TPDU) |
- S(ISO7816_S_IN_TPDU),
+ .in_event_mask = S(ISO7816_E_RX_SINGLE) | S(ISO7816_E_RX_COMPL) | S(ISO7816_E_TX_COMPL) | S(ISO7816_E_RX_ERR_IND) | S(ISO7816_E_TX_ERR_IND) | S(ISO7816_E_TPDU_DONE_IND),
+ .out_state_mask = S(ISO7816_S_RESET) | S(ISO7816_S_WAIT_TPDU) | S(ISO7816_S_IN_TPDU),
.action = iso7816_3_in_tpdu_action,
},
[ISO7816_S_WAIT_PPS_RSP] = {
.name = "WAIT_PPS_RESP",
- .in_event_mask = S(ISO7816_E_TX_COMPL) |
- S(ISO7816_E_TX_ERR_IND) |
- S(ISO7816_E_RX_SINGLE),
- .out_state_mask = S(ISO7816_S_RESET) |
- S(ISO7816_S_WAIT_TPDU) |
- S(ISO7816_S_WAIT_PPS_RSP) |
- S(ISO7816_S_IN_PPS_RSP),
+ .in_event_mask = S(ISO7816_E_TX_COMPL) | S(ISO7816_E_TX_ERR_IND) | S(ISO7816_E_RX_SINGLE),
+ .out_state_mask = S(ISO7816_S_RESET) | S(ISO7816_S_WAIT_TPDU) | S(ISO7816_S_WAIT_PPS_RSP) | S(ISO7816_S_IN_PPS_RSP),
.action = iso7816_3_s_wait_pps_rsp_action,
},
[ISO7816_S_IN_PPS_RSP] = {
.name = "IN_PPS_RESP",
- .in_event_mask = S(ISO7816_E_RX_SINGLE) |
- S(ISO7816_E_RX_COMPL) |
- S(ISO7816_E_RX_ERR_IND) |
- S(ISO7816_E_PPS_DONE_IND) |
- S(ISO7816_E_PPS_FAILED_IND),
- .out_state_mask = S(ISO7816_S_RESET) |
- S(ISO7816_S_WAIT_TPDU) |
- S(ISO7816_S_IN_PPS_RSP),
+ .in_event_mask = S(ISO7816_E_RX_SINGLE) | S(ISO7816_E_RX_COMPL) | S(ISO7816_E_RX_ERR_IND) | S(ISO7816_E_PPS_DONE_IND) | S(ISO7816_E_PPS_FAILED_IND),
+ .out_state_mask = S(ISO7816_S_RESET) | S(ISO7816_S_WAIT_TPDU) | S(ISO7816_S_IN_PPS_RSP),
.action = iso7816_3_s_ins_pps_rsp_action,
},
};
@@ -625,13 +839,13 @@
.log_subsys = DISO7816,
.event_names = iso7816_3_event_names,
.allstate_action = iso7816_3_allstate_action,
- .allstate_event_mask = S(ISO7816_E_CARD_REMOVAL) |
- S(ISO7816_E_POWER_DN_IND) |
- S(ISO7816_E_RESET_ACT_IND) |
- S(ISO7816_E_HW_ERR_IND) |
- S(ISO7816_E_ABORT_REQ) |
- S(ISO7816_E_WTIME_EXP) |
- S(ISO7816_E_ATR_ERR_IND),
+ .allstate_event_mask = S(ISO7816_E_CARD_REMOVAL) |
+ S(ISO7816_E_POWER_DN_IND) |
+ S(ISO7816_E_RESET_ACT_IND) |
+ S(ISO7816_E_HW_ERR_IND) |
+ S(ISO7816_E_ABORT_REQ) |
+ S(ISO7816_E_WTIME_EXP) |
+ S(ISO7816_E_ATR_ERR_IND),
};
/***********************************************************************
@@ -643,7 +857,7 @@
{
OSMO_ASSERT(fi);
OSMO_ASSERT(fi->fsm == &atr_fsm);
- return (struct atr_fsm_priv *) fi->priv;
+ return (struct atr_fsm_priv *)fi->priv;
}
/* obtain the [software] guard time in milli-seconds from the atr fsm_inst */
@@ -723,7 +937,7 @@
switch (event) {
case ISO7816_E_RX_SINGLE:
OSMO_ASSERT(msgb_length(atp->atr) == 0);
-restart:
+ restart:
byte = get_atr_rx_byte_evt(parent_fi, data);
LOGPFSML(fi, LOGL_DEBUG, "RX byte '%02x'\n", byte);
switch (byte) {
@@ -778,7 +992,7 @@
atp->hist_len = (byte & 0x0f);
} else {
/* remember supported protocol to know if TCK will be present */
- atp->protocol_support |= (1<<(byte & 0x0f));
+ atp->protocol_support |= (1 << (byte & 0x0f));
}
atp->y = (byte & 0xf0); /* remember incoming interface bytes */
atp->i++;
@@ -832,7 +1046,7 @@
uint8_t ui;
uint8_t *atr = msgb_data(atp->atr);
LOGPFSML(fi, LOGL_INFO, "Complete ATR: %s\n", msgb_hexdump(atp->atr));
- for (ui = 1; ui < msgb_length(atp->atr)-1; ui++) {
+ for (ui = 1; ui < msgb_length(atp->atr) - 1; ui++) {
atp->computed_checksum ^= atr[ui];
}
if (atp->computed_checksum != byte) {
@@ -852,16 +1066,16 @@
break;
case ISO7816_E_WTIME_EXP:
switch (fi->state) {
- case ATR_S_WAIT_HIST:
- case ATR_S_WAIT_TCK:
- /* Some cards have an ATR with long indication of historical bytes */
- /* FIXME: should we check the checksum? */
- osmo_fsm_inst_state_chg(fi, ATR_S_DONE, 0, 0);
- osmo_fsm_inst_dispatch(fi->proc.parent, ISO7816_E_ATR_DONE_IND, atp->atr);
- break;
- default:
- osmo_fsm_inst_dispatch(fi->proc.parent, ISO7816_E_ATR_ERR_IND, atp->atr);
- break;
+ case ATR_S_WAIT_HIST:
+ case ATR_S_WAIT_TCK:
+ /* Some cards have an ATR with long indication of historical bytes */
+ /* FIXME: should we check the checksum? */
+ osmo_fsm_inst_state_chg(fi, ATR_S_DONE, 0, 0);
+ osmo_fsm_inst_dispatch(fi->proc.parent, ISO7816_E_ATR_DONE_IND, atp->atr);
+ break;
+ default:
+ osmo_fsm_inst_dispatch(fi->proc.parent, ISO7816_E_ATR_ERR_IND, atp->atr);
+ break;
}
break;
default:
@@ -880,101 +1094,56 @@
static const struct osmo_fsm_state atr_states[] = {
[ATR_S_WAIT_TS] = {
.name = "WAIT_TS",
- .in_event_mask = S(ISO7816_E_RX_SINGLE) |
- S(ISO7816_E_WTIME_EXP),
- .out_state_mask = S(ATR_S_WAIT_TS) |
- S(ATR_S_WAIT_T0),
+ .in_event_mask = S(ISO7816_E_RX_SINGLE) |
+ S(ISO7816_E_WTIME_EXP),
+ .out_state_mask = S(ATR_S_WAIT_TS) |
+ S(ATR_S_WAIT_T0),
.action = atr_wait_ts_action,
.onenter = atr_wait_ts_onenter,
},
[ATR_S_WAIT_T0] = {
.name = "WAIT_T0",
- .in_event_mask = S(ISO7816_E_RX_SINGLE) |
- S(ISO7816_E_WTIME_EXP),
- .out_state_mask = S(ATR_S_WAIT_TS) |
- S(ATR_S_WAIT_TA) |
- S(ATR_S_WAIT_TB) |
- S(ATR_S_WAIT_TC) |
- S(ATR_S_WAIT_TD) |
- S(ATR_S_WAIT_HIST) |
- S(ATR_S_WAIT_TCK) |
- S(ATR_S_WAIT_T0),
+ .in_event_mask = S(ISO7816_E_RX_SINGLE) | S(ISO7816_E_WTIME_EXP),
+ .out_state_mask = S(ATR_S_WAIT_TS) | S(ATR_S_WAIT_TA) | S(ATR_S_WAIT_TB) | S(ATR_S_WAIT_TC) | S(ATR_S_WAIT_TD) | S(ATR_S_WAIT_HIST) | S(ATR_S_WAIT_TCK) | S(ATR_S_WAIT_T0),
.action = atr_wait_tX_action,
},
[ATR_S_WAIT_TA] = {
.name = "WAIT_TA",
- .in_event_mask = S(ISO7816_E_RX_SINGLE) |
- S(ISO7816_E_WTIME_EXP),
- .out_state_mask = S(ATR_S_WAIT_TS) |
- S(ATR_S_WAIT_TB) |
- S(ATR_S_WAIT_TC) |
- S(ATR_S_WAIT_TD) |
- S(ATR_S_WAIT_HIST) |
- S(ATR_S_WAIT_TCK) |
- S(ATR_S_WAIT_T0),
+ .in_event_mask = S(ISO7816_E_RX_SINGLE) | S(ISO7816_E_WTIME_EXP),
+ .out_state_mask = S(ATR_S_WAIT_TS) | S(ATR_S_WAIT_TB) | S(ATR_S_WAIT_TC) | S(ATR_S_WAIT_TD) | S(ATR_S_WAIT_HIST) | S(ATR_S_WAIT_TCK) | S(ATR_S_WAIT_T0),
.action = atr_wait_tX_action,
},
[ATR_S_WAIT_TB] = {
.name = "WAIT_TB",
- .in_event_mask = S(ISO7816_E_RX_SINGLE) |
- S(ISO7816_E_WTIME_EXP),
- .out_state_mask = S(ATR_S_WAIT_TS) |
- S(ATR_S_WAIT_TC) |
- S(ATR_S_WAIT_TD) |
- S(ATR_S_WAIT_HIST) |
- S(ATR_S_WAIT_TCK) |
- S(ATR_S_WAIT_T0),
+ .in_event_mask = S(ISO7816_E_RX_SINGLE) | S(ISO7816_E_WTIME_EXP),
+ .out_state_mask = S(ATR_S_WAIT_TS) | S(ATR_S_WAIT_TC) | S(ATR_S_WAIT_TD) | S(ATR_S_WAIT_HIST) | S(ATR_S_WAIT_TCK) | S(ATR_S_WAIT_T0),
.action = atr_wait_tX_action,
},
[ATR_S_WAIT_TC] = {
.name = "WAIT_TC",
- .in_event_mask = S(ISO7816_E_RX_SINGLE) |
- S(ISO7816_E_WTIME_EXP),
- .out_state_mask = S(ATR_S_WAIT_TS) |
- S(ATR_S_WAIT_TD) |
- S(ATR_S_WAIT_HIST) |
- S(ATR_S_WAIT_TCK) |
- S(ATR_S_WAIT_T0),
+ .in_event_mask = S(ISO7816_E_RX_SINGLE) | S(ISO7816_E_WTIME_EXP),
+ .out_state_mask = S(ATR_S_WAIT_TS) | S(ATR_S_WAIT_TD) | S(ATR_S_WAIT_HIST) | S(ATR_S_WAIT_TCK) | S(ATR_S_WAIT_T0),
.action = atr_wait_tX_action,
},
[ATR_S_WAIT_TD] = {
.name = "WAIT_TD",
- .in_event_mask = S(ISO7816_E_RX_SINGLE) |
- S(ISO7816_E_WTIME_EXP),
- .out_state_mask = S(ATR_S_WAIT_TS) |
- S(ATR_S_WAIT_TA) |
- S(ATR_S_WAIT_TB) |
- S(ATR_S_WAIT_TC) |
- S(ATR_S_WAIT_TD) |
- S(ATR_S_WAIT_HIST) |
- S(ATR_S_WAIT_TCK) |
- S(ATR_S_WAIT_T0),
+ .in_event_mask = S(ISO7816_E_RX_SINGLE) | S(ISO7816_E_WTIME_EXP),
+ .out_state_mask = S(ATR_S_WAIT_TS) | S(ATR_S_WAIT_TA) | S(ATR_S_WAIT_TB) | S(ATR_S_WAIT_TC) | S(ATR_S_WAIT_TD) | S(ATR_S_WAIT_HIST) | S(ATR_S_WAIT_TCK) | S(ATR_S_WAIT_T0),
.action = atr_wait_tX_action,
},
[ATR_S_WAIT_HIST] = {
.name = "WAIT_HIST",
- .in_event_mask = S(ISO7816_E_RX_SINGLE) |
- S(ISO7816_E_WTIME_EXP),
- .out_state_mask = S(ATR_S_WAIT_TS) |
- S(ATR_S_WAIT_TCK) |
- S(ATR_S_WAIT_T0) |
- S(ATR_S_DONE),
+ .in_event_mask = S(ISO7816_E_RX_SINGLE) | S(ISO7816_E_WTIME_EXP),
+ .out_state_mask = S(ATR_S_WAIT_TS) | S(ATR_S_WAIT_TCK) | S(ATR_S_WAIT_T0) | S(ATR_S_DONE),
.action = atr_wait_tX_action,
},
[ATR_S_WAIT_TCK] = {
.name = "WAIT_TCK",
- .in_event_mask = S(ISO7816_E_RX_SINGLE) |
- S(ISO7816_E_WTIME_EXP),
- .out_state_mask = S(ATR_S_WAIT_TS) |
- S(ATR_S_DONE),
+ .in_event_mask = S(ISO7816_E_RX_SINGLE) | S(ISO7816_E_WTIME_EXP),
+ .out_state_mask = S(ATR_S_WAIT_TS) | S(ATR_S_DONE),
.action = atr_wait_tX_action,
},
- [ATR_S_DONE] = {
- .name = "DONE",
- .in_event_mask = 0,
- .out_state_mask = S(ATR_S_WAIT_TS),
- .onenter = atr_done_onenter
- },
+ [ATR_S_DONE] = { .name = "DONE", .in_event_mask = 0, .out_state_mask = S(ATR_S_WAIT_TS), .onenter = atr_done_onenter },
};
static struct osmo_fsm atr_fsm = {
@@ -994,7 +1163,7 @@
{
OSMO_ASSERT(fi);
OSMO_ASSERT(fi->fsm == &pps_fsm);
- return (struct pps_fsm_priv *) fi->priv;
+ return (struct pps_fsm_priv *)fi->priv;
}
static void pps_s_pps_req_init_action(struct osmo_fsm_inst *fi, uint32_t event, void *data)
@@ -1002,7 +1171,7 @@
struct pps_fsm_priv *atp = get_pps_fsm_priv(fi);
struct osmo_fsm_inst *parent_fi = fi->proc.parent;
struct iso7816_3_priv *ip = get_iso7816_3_priv(parent_fi);
- struct msgb* pps_to_transmit = atp->tx_cmd;
+ struct msgb *pps_to_transmit = atp->tx_cmd;
/* data passed is PPS1, not msgb ptr! */
uint8_t PPS1 = (uint8_t)data;
@@ -1063,7 +1232,7 @@
break;
case PPS_S_WAIT_PPS0:
atp->pps0_recv = byte;
- if(atp->pps0_recv & (1 << 4)) {
+ if (atp->pps0_recv & (1 << 4)) {
osmo_fsm_inst_state_chg(fi, PPS_S_WAIT_PPS1, 0, 0);
break;
} else if (atp->pps0_recv & (1 << 5)) {
@@ -1105,7 +1274,7 @@
/* pps was successful if response equals request */
if (msgb_length(atp->rx_cmd) == msgb_length(atp->tx_cmd) &&
- !memcmp(pps_received, pps_sent, msgb_length(atp->rx_cmd))) {
+ !memcmp(pps_received, pps_sent, msgb_length(atp->rx_cmd))) {
osmo_fsm_inst_dispatch(fi->proc.parent, ISO7816_E_PPS_DONE_IND, atp->tx_cmd);
} else {
osmo_fsm_inst_dispatch(fi->proc.parent, ISO7816_E_PPS_FAILED_IND, atp->tx_cmd);
@@ -1121,7 +1290,6 @@
}
}
-
static void pps_s_done_onenter(struct osmo_fsm_inst *fi, uint32_t old_state)
{
struct osmo_fsm_inst *parent_fi = fi->proc.parent;
@@ -1130,80 +1298,60 @@
card_uart_ctrl(ip->uart, CUART_CTL_RX_TIMER_HINT, 0);
}
-
static const struct osmo_fsm_state pps_states[] = {
[PPS_S_PPS_REQ_INIT] = {
.name = "INIT",
- .in_event_mask = S(ISO7816_E_XCEIVE_PPS_CMD),
- .out_state_mask = S(PPS_S_PPS_REQ_INIT) |
- S(PPS_S_TX_PPS_REQ),
+ .in_event_mask = S(ISO7816_E_XCEIVE_PPS_CMD),
+ .out_state_mask = S(PPS_S_PPS_REQ_INIT) |
+ S(PPS_S_TX_PPS_REQ),
.action = pps_s_pps_req_init_action,
},
[PPS_S_TX_PPS_REQ] = {
.name = "TX_PPS_REQ",
- .in_event_mask = S(ISO7816_E_TX_COMPL),
- .out_state_mask = S(PPS_S_WAIT_PPSX),
+ .in_event_mask = S(ISO7816_E_TX_COMPL),
+ .out_state_mask = S(PPS_S_WAIT_PPSX),
.action = pps_s_tx_pps_req_action,
},
[PPS_S_WAIT_PPSX] = {
.name = "WAIT_PPSS",
- .in_event_mask = S(ISO7816_E_RX_SINGLE),
- .out_state_mask = S(PPS_S_WAIT_PPS0) |
- S(PPS_S_WAIT_PPSX) |
- S(PPS_S_PPS_REQ_INIT) |
- S(PPS_S_DONE),
+ .in_event_mask = S(ISO7816_E_RX_SINGLE),
+ .out_state_mask = S(PPS_S_WAIT_PPS0) | S(PPS_S_WAIT_PPSX) | S(PPS_S_PPS_REQ_INIT) | S(PPS_S_DONE),
.action = pps_wait_pX_action,
},
[PPS_S_WAIT_PPS0] = {
.name = "WAIT_PPS0",
- .in_event_mask = S(ISO7816_E_RX_SINGLE),
- .out_state_mask = S(PPS_S_WAIT_PPS1) |
- S(PPS_S_WAIT_PPS2) |
- S(PPS_S_WAIT_PPS3) |
- S(PPS_S_WAIT_PCK) |
- S(PPS_S_PPS_REQ_INIT) |
- S(PPS_S_DONE),
+ .in_event_mask = S(ISO7816_E_RX_SINGLE),
+ .out_state_mask = S(PPS_S_WAIT_PPS1) | S(PPS_S_WAIT_PPS2) | S(PPS_S_WAIT_PPS3) | S(PPS_S_WAIT_PCK) | S(PPS_S_PPS_REQ_INIT) | S(PPS_S_DONE),
.action = pps_wait_pX_action,
},
[PPS_S_WAIT_PPS1] = {
.name = "WAIT_PPS1",
- .in_event_mask = S(ISO7816_E_RX_SINGLE),
- .out_state_mask = S(PPS_S_WAIT_PPS2) |
- S(PPS_S_WAIT_PPS3) |
- S(PPS_S_WAIT_PCK) |
- S(PPS_S_PPS_REQ_INIT) |
- S(PPS_S_DONE),
+ .in_event_mask = S(ISO7816_E_RX_SINGLE),
+ .out_state_mask = S(PPS_S_WAIT_PPS2) | S(PPS_S_WAIT_PPS3) | S(PPS_S_WAIT_PCK) | S(PPS_S_PPS_REQ_INIT) | S(PPS_S_DONE),
.action = pps_wait_pX_action,
},
[PPS_S_WAIT_PPS2] = {
.name = "WAIT_PPS2",
- .in_event_mask = S(ISO7816_E_RX_SINGLE),
- .out_state_mask = S(PPS_S_WAIT_PPS3) |
- S(PPS_S_WAIT_PCK) |
- S(PPS_S_PPS_REQ_INIT) |
- S(PPS_S_DONE),
+ .in_event_mask = S(ISO7816_E_RX_SINGLE),
+ .out_state_mask = S(PPS_S_WAIT_PPS3) | S(PPS_S_WAIT_PCK) | S(PPS_S_PPS_REQ_INIT) | S(PPS_S_DONE),
.action = pps_wait_pX_action,
},
[PPS_S_WAIT_PPS3] = {
.name = "WAIT_PPS3",
- .in_event_mask = S(ISO7816_E_RX_SINGLE),
- .out_state_mask = S(PPS_S_WAIT_PCK) |
- S(PPS_S_PPS_REQ_INIT) |
- S(PPS_S_DONE),
+ .in_event_mask = S(ISO7816_E_RX_SINGLE),
+ .out_state_mask = S(PPS_S_WAIT_PCK) | S(PPS_S_PPS_REQ_INIT) | S(PPS_S_DONE),
.action = pps_wait_pX_action,
},
[PPS_S_WAIT_PCK] = {
.name = "WAIT_PCK",
- .in_event_mask = S(ISO7816_E_RX_SINGLE),
- .out_state_mask = S(PPS_S_DONE) |
- S(PPS_S_PPS_REQ_INIT) |
- S(PPS_S_DONE),
+ .in_event_mask = S(ISO7816_E_RX_SINGLE),
+ .out_state_mask = S(PPS_S_DONE) | S(PPS_S_PPS_REQ_INIT) | S(PPS_S_DONE),
.action = pps_wait_pX_action,
},
[PPS_S_DONE] = {
.name = "DONE",
- .in_event_mask = 0,
- .out_state_mask = S(PPS_S_PPS_REQ_INIT),
+ .in_event_mask = 0,
+ .out_state_mask = S(PPS_S_PPS_REQ_INIT),
.action = NULL,
.onenter = pps_s_done_onenter,
},
@@ -1230,8 +1378,9 @@
* - any response bytes are stored after the header at msg->l2h
*/
-static inline struct osim_apdu_cmd_hdr *msgb_tpdu_hdr(struct msgb *msg) {
- return (struct osim_apdu_cmd_hdr *) msgb_data(msg);
+static inline struct osim_apdu_cmd_hdr *msgb_tpdu_hdr(struct msgb *msg)
+{
+ return (struct osim_apdu_cmd_hdr *)msgb_data(msg);
}
/* type-safe method to obtain iso7816_3_priv from fi */
@@ -1239,7 +1388,7 @@
{
OSMO_ASSERT(fi);
OSMO_ASSERT(fi->fsm == &tpdu_fsm);
- return (struct tpdu_fsm_priv *) fi->priv;
+ return (struct tpdu_fsm_priv *)fi->priv;
}
static void tpdu_s_init_action(struct osmo_fsm_inst *fi, uint32_t event, void *data)
@@ -1271,16 +1420,15 @@
tpduh = msgb_tpdu_hdr(tfp->tpdu);
LOGPFSML(fi, LOGL_DEBUG, "Transmitting %s TPDU header %s via UART\n",
tfp->is_command ? "COMMAND" : "RESPONSE",
- osmo_hexdump_nospc((uint8_t *) tpduh, sizeof(*tpduh)));
+ osmo_hexdump_nospc((uint8_t *)tpduh, sizeof(*tpduh)));
osmo_fsm_inst_state_chg(fi, TPDU_S_TX_HDR, 0, 0);
- card_uart_tx(ip->uart, (uint8_t *) tpduh, sizeof(*tpduh), true);
+ card_uart_tx(ip->uart, (uint8_t *)tpduh, sizeof(*tpduh), true);
break;
default:
OSMO_ASSERT(0);
}
}
-
static void tpdu_s_tx_hdr_action(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
struct osmo_fsm_inst *parent_fi = fi->proc.parent;
@@ -1301,7 +1449,6 @@
}
}
-
#if 0
#include <hal_gpio.h>
#endif
@@ -1549,7 +1696,6 @@
}
}
-
static void tpdu_s_done_onenter(struct osmo_fsm_inst *fi, uint32_t old_state)
{
struct osmo_fsm_inst *parent_fi = fi->proc.parent;
@@ -1569,68 +1715,50 @@
},
[TPDU_S_TX_HDR] = {
.name = "TX_HDR",
- .in_event_mask = S(ISO7816_E_TX_COMPL) |
- S(ISO7816_E_RX_SINGLE),
- .out_state_mask = S(TPDU_S_INIT) |
- S(TPDU_S_PROCEDURE),
+ .in_event_mask = S(ISO7816_E_TX_COMPL) | S(ISO7816_E_RX_SINGLE),
+ .out_state_mask = S(TPDU_S_INIT) | S(TPDU_S_PROCEDURE),
.action = tpdu_s_tx_hdr_action,
},
[TPDU_S_PROCEDURE] = {
.name = "PROCEDURE",
.in_event_mask = S(ISO7816_E_RX_SINGLE),
- .out_state_mask = S(TPDU_S_INIT) |
- S(TPDU_S_PROCEDURE) |
- S(TPDU_S_RX_REMAINING) |
- S(TPDU_S_RX_SINGLE) |
- S(TPDU_S_TX_REMAINING) |
- S(TPDU_S_TX_SINGLE) |
- S(TPDU_S_SW2),
+ .out_state_mask = S(TPDU_S_INIT) | S(TPDU_S_PROCEDURE) | S(TPDU_S_RX_REMAINING) | S(TPDU_S_RX_SINGLE) | S(TPDU_S_TX_REMAINING) | S(TPDU_S_TX_SINGLE) | S(TPDU_S_SW2),
.action = tpdu_s_procedure_action,
},
[TPDU_S_TX_REMAINING] = {
.name = "TX_REMAINING",
- .in_event_mask = S(ISO7816_E_TX_COMPL) |
- S(ISO7816_E_RX_SINGLE),
- .out_state_mask = S(TPDU_S_INIT) |
- S(TPDU_S_SW1),
+ .in_event_mask = S(ISO7816_E_TX_COMPL) | S(ISO7816_E_RX_SINGLE),
+ .out_state_mask = S(TPDU_S_INIT) | S(TPDU_S_SW1),
.action = tpdu_s_tx_remaining_action,
},
[TPDU_S_TX_SINGLE] = {
.name = "TX_SINGLE",
- .in_event_mask = S(ISO7816_E_TX_COMPL) |
- S(ISO7816_E_RX_SINGLE),
- .out_state_mask = S(TPDU_S_INIT) |
- S(TPDU_S_PROCEDURE),
+ .in_event_mask = S(ISO7816_E_TX_COMPL) | S(ISO7816_E_RX_SINGLE),
+ .out_state_mask = S(TPDU_S_INIT) | S(TPDU_S_PROCEDURE),
.action = tpdu_s_tx_single_action,
},
[TPDU_S_RX_REMAINING] = {
.name = "RX_REMAINING",
.in_event_mask = S(ISO7816_E_RX_COMPL),
- .out_state_mask = S(TPDU_S_INIT) |
- S(TPDU_S_SW1),
+ .out_state_mask = S(TPDU_S_INIT) | S(TPDU_S_SW1),
.action = tpdu_s_rx_remaining_action,
},
[TPDU_S_RX_SINGLE] = {
.name = "RX_SINGLE",
.in_event_mask = S(ISO7816_E_RX_SINGLE),
- .out_state_mask = S(TPDU_S_INIT) |
- S(TPDU_S_PROCEDURE) |
- S(TPDU_S_SW1),
+ .out_state_mask = S(TPDU_S_INIT) | S(TPDU_S_PROCEDURE) | S(TPDU_S_SW1),
.action = tpdu_s_rx_single_action,
},
[TPDU_S_SW1] = {
.name = "SW1",
.in_event_mask = S(ISO7816_E_RX_SINGLE),
- .out_state_mask = S(TPDU_S_INIT) |
- S(TPDU_S_SW1) |
- S(TPDU_S_SW2),
+ .out_state_mask = S(TPDU_S_INIT) | S(TPDU_S_SW1) | S(TPDU_S_SW2),
.action = tpdu_s_sw1_action,
},
[TPDU_S_SW2] = {
.name = "SW2",
.in_event_mask = S(ISO7816_E_RX_SINGLE),
- .out_state_mask = S(TPDU_S_INIT) |
- S(TPDU_S_DONE),
+ .out_state_mask = S(TPDU_S_INIT) | S(TPDU_S_DONE),
.action = tpdu_s_sw2_action,
},
[TPDU_S_DONE] = {
@@ -1645,9 +1773,9 @@
.name = "TPDU",
.states = tpdu_states,
.num_states = ARRAY_SIZE(tpdu_states),
- .allstate_event_mask = S(ISO7816_E_RX_ERR_IND) |
- S(ISO7816_E_TX_ERR_IND) |
- S(ISO7816_E_TPDU_CLEAR_REQ),
+ .allstate_event_mask = S(ISO7816_E_RX_ERR_IND) |
+ S(ISO7816_E_TX_ERR_IND) |
+ S(ISO7816_E_TPDU_CLEAR_REQ),
.allstate_action = tpdu_allstate_action,
.log_subsys = DTPDU,
.event_names = iso7816_3_event_names,
@@ -1707,7 +1835,6 @@
INIT_STATIC_MSGB(ppsp->rx_cmd);
INIT_STATIC_MSGB(ppsp->tx_cmd);
-
/* This ensures the 'onenter' function of the initial state is called */
osmo_fsm_inst_state_chg(fi, ISO7816_S_RESET, 0, 0);
@@ -1733,7 +1860,6 @@
return ip->user_priv;
}
-
static __attribute__((constructor)) void on_dso_load_iso7816(void)
{
OSMO_ASSERT(osmo_fsm_register(&iso7816_3_fsm) == 0);
diff --git a/ccid_common/iso7816_fsm.h b/ccid_common/iso7816_fsm.h
index fb37396..c2e7640 100644
--- a/ccid_common/iso7816_fsm.h
+++ b/ccid_common/iso7816_fsm.h
@@ -22,22 +22,22 @@
struct card_uart;
enum iso7816_3_event {
- ISO7816_E_RX_SINGLE, /*!< single-byte data received on UART */
- ISO7816_E_RX_COMPL, /*!< data receive complete on UART */
- ISO7816_E_TX_COMPL, /*!< data transmit complete on UART */
- ISO7816_E_POWER_UP_IND, /*!< Card powered up */
- ISO7816_E_RESET_REL_IND, /*!< Reset released */
- ISO7816_E_RX_ERR_IND, /*!< Uncorrectable Rx [parity] error */
- ISO7816_E_TX_ERR_IND, /*!< Uncorrectable Rx [parity] error */
- ISO7816_E_XCEIVE_TPDU_CMD, /*!< Ask for start of TPDU transmission */
+ ISO7816_E_RX_SINGLE, /*!< single-byte data received on UART */
+ ISO7816_E_RX_COMPL, /*!< data receive complete on UART */
+ ISO7816_E_TX_COMPL, /*!< data transmit complete on UART */
+ ISO7816_E_POWER_UP_IND, /*!< Card powered up */
+ ISO7816_E_RESET_REL_IND, /*!< Reset released */
+ ISO7816_E_RX_ERR_IND, /*!< Uncorrectable Rx [parity] error */
+ ISO7816_E_TX_ERR_IND, /*!< Uncorrectable Rx [parity] error */
+ ISO7816_E_XCEIVE_TPDU_CMD, /*!< Ask for start of TPDU transmission */
/* allstate events */
- ISO7816_E_WTIME_EXP, /*!< WTIME expired */
- ISO7816_E_HW_ERR_IND, /*!< Hardware error (overcurrent, ...) */
- ISO7816_E_SW_ERR_IND, /*!< Software error */
- ISO7816_E_CARD_REMOVAL, /*!< card has been removed from slot */
- ISO7816_E_POWER_DN_IND, /*!< Card powered down */
- ISO7816_E_RESET_ACT_IND, /*!< Reset activated */
- ISO7816_E_ABORT_REQ, /*!< Abort request (e.g. from CCID) */
+ ISO7816_E_WTIME_EXP, /*!< WTIME expired */
+ ISO7816_E_HW_ERR_IND, /*!< Hardware error (overcurrent, ...) */
+ ISO7816_E_SW_ERR_IND, /*!< Software error */
+ ISO7816_E_CARD_REMOVAL, /*!< card has been removed from slot */
+ ISO7816_E_POWER_DN_IND, /*!< Card powered down */
+ ISO7816_E_RESET_ACT_IND, /*!< Reset activated */
+ ISO7816_E_ABORT_REQ, /*!< Abort request (e.g. from CCID) */
/* TODO: PPS request */
ISO7816_E_XCEIVE_PPS_CMD,
ISO7816_E_PPS_DONE_IND,
@@ -48,11 +48,11 @@
/* TODO: Rx buffer overrun */
/* internal events between FSMs in this file */
- ISO7816_E_ATR_DONE_IND, /*!< ATR Done indication from ATR child FSM */
- ISO7816_E_ATR_ERR_IND, /*!< ATR Error indication from ATR child FSM */
- ISO7816_E_TPDU_DONE_IND, /*!< TPDU Done indication from TPDU child FSM */
- ISO7816_E_TPDU_FAILED_IND, /*!< TPDU Failed indication from TPDU child FSM */
- ISO7816_E_TPDU_CLEAR_REQ, /*!< Return TPDU FSM to TPDU_S_INIT */
+ ISO7816_E_ATR_DONE_IND, /*!< ATR Done indication from ATR child FSM */
+ ISO7816_E_ATR_ERR_IND, /*!< ATR Error indication from ATR child FSM */
+ ISO7816_E_TPDU_DONE_IND, /*!< TPDU Done indication from TPDU child FSM */
+ ISO7816_E_TPDU_FAILED_IND, /*!< TPDU Failed indication from TPDU child FSM */
+ ISO7816_E_TPDU_CLEAR_REQ, /*!< Return TPDU FSM to TPDU_S_INIT */
};
typedef void (*iso7816_user_cb)(struct osmo_fsm_inst *fi, int event, int cause, void *data);
diff --git a/sysmoOCTSIM/command.c b/sysmoOCTSIM/command.c
index 1a904d5..30bc697 100644
--- a/sysmoOCTSIM/command.c
+++ b/sysmoOCTSIM/command.c
@@ -86,7 +86,7 @@
int c = getchar();
if (c < 0)
return;
- if (c == '\r' || c == '\n' || g_cmds.buf_idx >= sizeof(g_cmds.buf)-1) {
+ if (c == '\r' || c == '\n' || g_cmds.buf_idx >= sizeof(g_cmds.buf) - 1) {
/* skip empty commands */
if (g_cmds.buf_idx == 0)
return;
diff --git a/sysmoOCTSIM/command.h b/sysmoOCTSIM/command.h
index 5d022dc..ece9bec 100644
--- a/sysmoOCTSIM/command.h
+++ b/sysmoOCTSIM/command.h
@@ -6,13 +6,13 @@
void (*fn)(int argc, char **argv);
};
-#define DEFUN(funcname, cmdname, cmdstr, helpstr) \
- static void funcname(int argc, char **argv); \
- static struct command_fn cmdname = { \
- .command = cmdstr, \
- .help = helpstr, \
- .fn = funcname, \
- }; \
+#define DEFUN(funcname, cmdname, cmdstr, helpstr) \
+ static void funcname(int argc, char **argv); \
+ static struct command_fn cmdname = { \
+ .command = cmdstr, \
+ .help = helpstr, \
+ .fn = funcname, \
+ }; \
static void funcname(int argc, char **argv)
void command_init(const char *prompt);
diff --git a/sysmoOCTSIM/cuart_driver_asf4_usart_async.c b/sysmoOCTSIM/cuart_driver_asf4_usart_async.c
index 42c2110..b168ea9 100644
--- a/sysmoOCTSIM/cuart_driver_asf4_usart_async.c
+++ b/sysmoOCTSIM/cuart_driver_asf4_usart_async.c
@@ -15,9 +15,9 @@
#include "cuart.h"
#ifndef ENABLE_DBG_UART7
-static struct usart_async_descriptor* SIM_peripheral_descriptors[] = {&SIM0, &SIM1, &SIM2, &SIM3, &SIM4, &SIM5, &SIM6, &SIM7};
+static struct usart_async_descriptor *SIM_peripheral_descriptors[] = { &SIM0, &SIM1, &SIM2, &SIM3, &SIM4, &SIM5, &SIM6, &SIM7 };
#else
-static struct usart_async_descriptor* SIM_peripheral_descriptors[] = {&SIM0, &SIM1, &SIM2, &SIM3, &SIM4, &SIM5, &SIM6, NULL};
+static struct usart_async_descriptor *SIM_peripheral_descriptors[] = { &SIM0, &SIM1, &SIM2, &SIM3, &SIM4, &SIM5, &SIM6, NULL };
#endif
extern struct card_uart *cuart4slot_nr(uint8_t slot_nr);
@@ -35,7 +35,7 @@
if (cuart->rx_threshold == 1) {
/* bypass ringbuffer and report byte directly */
uint8_t rx[1];
- rc = io_read((struct io_descriptor * const)&io_descr->io, rx, sizeof(rx));
+ rc = io_read((struct io_descriptor *const)&io_descr->io, rx, sizeof(rx));
OSMO_ASSERT(rc == sizeof(rx));
card_uart_notification(cuart, CUART_E_RX_SINGLE, rx);
} else {
@@ -55,8 +55,8 @@
#include <hpl_usart_async.h>
#include <hpl_usart_sync.h>
-
-static void _SIM_error_cb(const struct usart_async_descriptor *const io_descr, uint8_t slot_nr) {
+static void _SIM_error_cb(const struct usart_async_descriptor *const io_descr, uint8_t slot_nr)
+{
struct card_uart *cuart = cuart4slot_nr(slot_nr);
OSMO_ASSERT(cuart);
card_uart_notification(cuart, CUART_E_HW_ERROR, 0);
@@ -98,8 +98,14 @@
_SIM_rx_cb(io_descr, 7);
}
static usart_cb_t SIM_rx_cb[8] = {
- SIM0_rx_cb, SIM1_rx_cb, SIM2_rx_cb, SIM3_rx_cb,
- SIM4_rx_cb, SIM5_rx_cb, SIM6_rx_cb, SIM7_rx_cb,
+ SIM0_rx_cb,
+ SIM1_rx_cb,
+ SIM2_rx_cb,
+ SIM3_rx_cb,
+ SIM4_rx_cb,
+ SIM5_rx_cb,
+ SIM6_rx_cb,
+ SIM7_rx_cb,
};
static void SIM0_tx_cb(const struct usart_async_descriptor *const io_descr)
{
@@ -134,8 +140,14 @@
_SIM_tx_cb(io_descr, 7);
}
static usart_cb_t SIM_tx_cb[8] = {
- SIM0_tx_cb, SIM1_tx_cb, SIM2_tx_cb, SIM3_tx_cb,
- SIM4_tx_cb, SIM5_tx_cb, SIM6_tx_cb, SIM7_tx_cb,
+ SIM0_tx_cb,
+ SIM1_tx_cb,
+ SIM2_tx_cb,
+ SIM3_tx_cb,
+ SIM4_tx_cb,
+ SIM5_tx_cb,
+ SIM6_tx_cb,
+ SIM7_tx_cb,
};
static void SIM0_error_cb(const struct usart_async_descriptor *const io_descr)
@@ -171,11 +183,16 @@
_SIM_error_cb(io_descr, 7);
}
static usart_cb_t SIM_error_cb[8] = {
- SIM0_error_cb, SIM1_error_cb, SIM2_error_cb, SIM3_error_cb,
- SIM4_error_cb, SIM5_error_cb, SIM6_error_cb, SIM7_error_cb,
+ SIM0_error_cb,
+ SIM1_error_cb,
+ SIM2_error_cb,
+ SIM3_error_cb,
+ SIM4_error_cb,
+ SIM5_error_cb,
+ SIM6_error_cb,
+ SIM7_error_cb,
};
-
#include <math.h>
#include "atmel_start.h"
#include "atmel_start_pins.h"
@@ -185,22 +202,22 @@
/** possible clock sources for the SERCOM peripheral
* warning: the definition must match the GCLK configuration
*/
-static const uint8_t sercom_glck_sources[] = {GCLK_PCHCTRL_GEN_GCLK2_Val, GCLK_PCHCTRL_GEN_GCLK4_Val, GCLK_PCHCTRL_GEN_GCLK6_Val};
+static const uint8_t sercom_glck_sources[] = { GCLK_PCHCTRL_GEN_GCLK2_Val, GCLK_PCHCTRL_GEN_GCLK4_Val, GCLK_PCHCTRL_GEN_GCLK6_Val };
- /** possible clock frequencies in MHz for the SERCOM peripheral
+/** possible clock frequencies in MHz for the SERCOM peripheral
* warning: the definition must match the GCLK configuration
*/
-static const double sercom_glck_freqs[] = {100E6 / CONF_GCLK_GEN_2_DIV, 100E6 / CONF_GCLK_GEN_4_DIV, 120E6 / CONF_GCLK_GEN_6_DIV};
+static const double sercom_glck_freqs[] = { 100E6 / CONF_GCLK_GEN_2_DIV, 100E6 / CONF_GCLK_GEN_4_DIV, 120E6 / CONF_GCLK_GEN_6_DIV };
/** the GCLK ID for the SERCOM SIM peripherals
* @note: used as index for PCHCTRL
*/
-static const uint8_t SIM_peripheral_GCLK_ID[] = {SERCOM0_GCLK_ID_CORE, SERCOM1_GCLK_ID_CORE, SERCOM2_GCLK_ID_CORE, SERCOM3_GCLK_ID_CORE, SERCOM4_GCLK_ID_CORE, SERCOM5_GCLK_ID_CORE, SERCOM6_GCLK_ID_CORE, SERCOM7_GCLK_ID_CORE};
+static const uint8_t SIM_peripheral_GCLK_ID[] = { SERCOM0_GCLK_ID_CORE, SERCOM1_GCLK_ID_CORE, SERCOM2_GCLK_ID_CORE, SERCOM3_GCLK_ID_CORE, SERCOM4_GCLK_ID_CORE, SERCOM5_GCLK_ID_CORE, SERCOM6_GCLK_ID_CORE, SERCOM7_GCLK_ID_CORE };
/** inverted signalling as per 7816-3 : inverted bit, inverted bit order
*/
-static void set_inverted_signalling(void* hw, bool on) {
-
+static void set_inverted_signalling(void *hw, bool on)
+{
hri_sercomusart_clear_CTRLA_ENABLE_bit(hw);
hri_sercomusart_write_CTRLA_DORD_bit(hw, !on); // inverted == msb first
@@ -219,7 +236,7 @@
static bool slot_set_baudrate(struct card_uart *cuart, uint32_t baudrate)
{
uint8_t slotnr = cuart->u.asf4.slot_nr;
- struct usart_async_descriptor* slot = SIM_peripheral_descriptors[slotnr];
+ struct usart_async_descriptor *slot = SIM_peripheral_descriptors[slotnr];
Sercom *sercom = cuart->u.asf4.usa_pd->device.hw;
ASSERT(slotnr < ARRAY_SIZE(SIM_peripheral_descriptors));
@@ -232,14 +249,14 @@
double errors[ARRAY_SIZE(sercom_glck_freqs)];
for (uint8_t i = 0; i < ARRAY_SIZE(sercom_glck_freqs); i++) {
double freq = sercom_glck_freqs[i]; // remember possible SERCOM frequency
- uint32_t min = freq/16. * (1. - 65535. / 65536.); // calculate the minimum baud rate for this frequency
- uint32_t max = freq/16. * (1. - 1. / 65536.); // calculate the maximum baud rate for this frequency
+ uint32_t min = freq / 16. * (1. - 65535. / 65536.); // calculate the minimum baud rate for this frequency
+ uint32_t max = freq / 16. * (1. - 1. / 65536.); // calculate the maximum baud rate for this frequency
if (baudrate < min || baudrate > max) { // baud rate it out of supported range
errors[i] = NAN;
} else {
- uint16_t baud = round(65536. * (1. - 16. * (baudrate/freq)));
+ uint16_t baud = round(65536. * (1. - 16. * (baudrate / freq)));
bauds[i] = baud;
- double actual = freq/16. * (1. - baud / 65536.);
+ double actual = freq / 16. * (1. - baud / 65536.);
errors[i] = fabs(1.0 - (actual / baudrate));
}
}
@@ -260,21 +277,22 @@
return false;
}
-
// update cached values
cuart->u.asf4.current_baudrate = baudrate;
- cuart->u.asf4.extrawait_after_rx = 1./baudrate * 1000 * 1000;
+ cuart->u.asf4.extrawait_after_rx = 1. / baudrate * 1000 * 1000;
printf("(%u) switching SERCOM clock to GCLK%u (freq = %lu kHz) and baud rate to %lu bps (baud = %u)\r\n", slotnr, (best + 1) * 2, (uint32_t)(round(sercom_glck_freqs[best] / 1000)), baudrate, bauds[best]);
/* only wait if the uart is enabled.... */
if (hri_sercomusart_get_CTRLA_reg(sercom, SERCOM_USART_CTRLA_ENABLE)) {
- while (!usart_async_is_tx_empty(slot)); // wait for transmission to complete (WARNING no timeout)
+ while (!usart_async_is_tx_empty(slot))
+ ; // wait for transmission to complete (WARNING no timeout)
usart_async_disable(slot); // disable SERCOM peripheral
}
hri_gclk_clear_PCHCTRL_reg(GCLK, SIM_peripheral_GCLK_ID[slotnr], (1 << GCLK_PCHCTRL_CHEN_Pos)); // disable clock for this peripheral
- while (hri_gclk_get_PCHCTRL_reg(GCLK, SIM_peripheral_GCLK_ID[slotnr], (1 << GCLK_PCHCTRL_CHEN_Pos))); // wait until clock is really disabled
+ while (hri_gclk_get_PCHCTRL_reg(GCLK, SIM_peripheral_GCLK_ID[slotnr], (1 << GCLK_PCHCTRL_CHEN_Pos)))
+ ; // wait until clock is really disabled
// it does not seem we need to completely disable the peripheral using hri_mclk_clear_APBDMASK_SERCOMn_bit
hri_gclk_write_PCHCTRL_reg(GCLK, SIM_peripheral_GCLK_ID[slotnr], sercom_glck_sources[best] | (1 << GCLK_PCHCTRL_CHEN_Pos)); // set peripheral core clock and re-enable it
usart_async_set_baud_rate(slot, bauds[best]); // set the new baud rate
@@ -304,7 +322,7 @@
static bool slot_set_isorate(struct card_uart *cuart, enum ncn8025_sim_clkdiv clkdiv, uint16_t f, uint8_t d)
{
uint8_t slotnr = cuart->u.asf4.slot_nr;
- struct usart_async_descriptor* slot = SIM_peripheral_descriptors[slotnr];
+ struct usart_async_descriptor *slot = SIM_peripheral_descriptors[slotnr];
// input checks
ASSERT(slotnr < ARRAY_SIZE(SIM_peripheral_descriptors));
@@ -384,7 +402,7 @@
// set USART baud rate to match the interface (f = 2.5 MHz) and card default settings (Fd = 372, Dd = 1)
slot_set_isorate(cuart, SIM_CLKDIV_8, ISO7816_3_DEFAULT_FD, ISO7816_3_DEFAULT_DD);
- return 0;
+ return 0;
}
static int asf4_usart_close(struct card_uart *cuart)
@@ -442,7 +460,7 @@
_usart_async_disable(&cuart->u.asf4.usa_pd->device);
break;
case CUART_CTL_RX:
- if (arg){
+ if (arg) {
/* no op */
} else {
delay_us(cuart->u.asf4.extrawait_after_rx);
@@ -466,13 +484,19 @@
/* reset everything */
slot_set_isorate(cuart, SIM_CLKDIV_8, ISO7816_3_DEFAULT_FD, ISO7816_3_DEFAULT_DD);
-
enum ncn8025_sim_voltage v = CUART_CTL_POWER_5V0;
switch (ctl) {
- case CUART_CTL_POWER_5V0: v = SIM_VOLT_5V0; break;
- case CUART_CTL_POWER_3V0: v = SIM_VOLT_3V0; break;
- case CUART_CTL_POWER_1V8: v = SIM_VOLT_1V8; break;
- default: break;
+ case CUART_CTL_POWER_5V0:
+ v = SIM_VOLT_5V0;
+ break;
+ case CUART_CTL_POWER_3V0:
+ v = SIM_VOLT_3V0;
+ break;
+ case CUART_CTL_POWER_1V8:
+ v = SIM_VOLT_1V8;
+ break;
+ default:
+ break;
}
ncn8025_get(cuart->u.asf4.slot_nr, &settings);
@@ -493,11 +517,11 @@
/* 2,5/5/10/20 supported by dividers */
enum ncn8025_sim_clkdiv clkdiv = SIM_CLKDIV_1;
- if(arg < 20000000)
+ if (arg < 20000000)
clkdiv = SIM_CLKDIV_2;
- if(arg < 10000000)
+ if (arg < 10000000)
clkdiv = SIM_CLKDIV_4;
- if(arg < 5000000)
+ if (arg < 5000000)
clkdiv = SIM_CLKDIV_8;
settings.clkdiv = clkdiv;
ncn8025_set(cuart->u.asf4.slot_nr, &settings);
@@ -505,7 +529,7 @@
case CUART_CTL_SET_FD:
ncn8025_get(cuart->u.asf4.slot_nr, &settings);
uint8_t divider = ncn8025_div_val[settings.clkdiv];
- uint32_t baudrate = (20e6/divider)/arg;
+ uint32_t baudrate = (20e6 / divider) / arg;
slot_set_baudrate(cuart, baudrate);
break;
case CUART_CTL_GET_BAUDRATE:
diff --git a/sysmoOCTSIM/dfu_descriptors.h b/sysmoOCTSIM/dfu_descriptors.h
index 7ef8cc9..bba7f91 100644
--- a/sysmoOCTSIM/dfu_descriptors.h
+++ b/sysmoOCTSIM/dfu_descriptors.h
@@ -12,38 +12,39 @@
#endif
/* USB DFU functional descriptor */
-#define DFU_FUNC_DESC { \
- .bLength = USB_DT_DFU_SIZE, \
- .bDescriptorType = USB_DT_DFU, \
- .bmAttributes = BMATT, \
- .wDetachTimeOut = 0, \
- .wTransferSize = FLASH_PAGE_SIZE, \
- .bcdDFUVersion = 0x0100, \
-}
+#define DFU_FUNC_DESC \
+ { \
+ .bLength = USB_DT_DFU_SIZE, \
+ .bDescriptorType = USB_DT_DFU, \
+ .bmAttributes = BMATT, \
+ .wDetachTimeOut = 0, \
+ .wTransferSize = FLASH_PAGE_SIZE, \
+ .bcdDFUVersion = 0x0100, \
+ }
/* Number of DFU interface during runtime mode */
-#define DFURT_NUM_IF 1
+#define DFURT_NUM_IF 1
/* to be used by the runtime as part of its USB descriptor structure
* declaration */
-#define DFURT_IF_DESCRIPTOR_STRUCT \
- struct usb_iface_desc dfu_rt; \
- struct usb_dfu_func_descriptor func_dfu;
+#define DFURT_IF_DESCRIPTOR_STRUCT \
+ struct usb_iface_desc dfu_rt; \
+ struct usb_dfu_func_descriptor func_dfu;
/* to be used by the runtime as part of its USB Dsecriptor structure
* definition */
-#define DFURT_IF_DESCRIPTOR(dfuIF, dfuSTR) \
- .dfu_rt = { \
- .bLength = sizeof(struct usb_iface_desc), \
- .bDescriptorType = USB_DT_INTERFACE, \
- .bInterfaceNumber = dfuIF, \
- .bAlternateSetting = 0, \
- .bNumEndpoints = 0, \
- .bInterfaceClass = 0xFE, \
- .bInterfaceSubClass = 0x01, \
- .bInterfaceProtocol = 0x01, \
- .iInterface = dfuSTR, \
- }, \
- .func_dfu = DFU_FUNC_DESC \
+#define DFURT_IF_DESCRIPTOR(dfuIF, dfuSTR) \
+ .dfu_rt = { \
+ .bLength = sizeof(struct usb_iface_desc), \
+ .bDescriptorType = USB_DT_INTERFACE, \
+ .bInterfaceNumber = dfuIF, \
+ .bAlternateSetting = 0, \
+ .bNumEndpoints = 0, \
+ .bInterfaceClass = 0xFE, \
+ .bInterfaceSubClass = 0x01, \
+ .bInterfaceProtocol = 0x01, \
+ .iInterface = dfuSTR, \
+ }, \
+ .func_dfu = DFU_FUNC_DESC
#endif
diff --git a/sysmoOCTSIM/driver_init.c b/sysmoOCTSIM/driver_init.c
index 1cfd8cf..ccc14e6 100644
--- a/sysmoOCTSIM/driver_init.c
+++ b/sysmoOCTSIM/driver_init.c
@@ -84,7 +84,6 @@
*/
void SIM0_CLOCK_init()
{
-
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM0_GCLK_ID_CORE, CONF_GCLK_SERCOM0_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM0_GCLK_ID_SLOW, CONF_GCLK_SERCOM0_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
@@ -98,7 +97,6 @@
*/
void SIM0_PORT_init()
{
-
gpio_set_pin_function(SIM0_IO, PINMUX_PA04D_SERCOM0_PAD0);
}
@@ -121,7 +119,6 @@
*/
void SIM1_CLOCK_init()
{
-
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM1_GCLK_ID_CORE, CONF_GCLK_SERCOM1_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM1_GCLK_ID_SLOW, CONF_GCLK_SERCOM1_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
@@ -135,7 +132,6 @@
*/
void SIM1_PORT_init()
{
-
gpio_set_pin_function(SIM1_IO, PINMUX_PA16C_SERCOM1_PAD0);
}
@@ -158,7 +154,6 @@
*/
void SIM2_CLOCK_init()
{
-
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM2_GCLK_ID_CORE, CONF_GCLK_SERCOM2_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM2_GCLK_ID_SLOW, CONF_GCLK_SERCOM2_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
@@ -172,7 +167,6 @@
*/
void SIM2_PORT_init()
{
-
gpio_set_pin_function(SIM2_IO, PINMUX_PA09D_SERCOM2_PAD0);
}
@@ -195,7 +189,6 @@
*/
void SIM3_CLOCK_init()
{
-
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM3_GCLK_ID_CORE, CONF_GCLK_SERCOM3_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM3_GCLK_ID_SLOW, CONF_GCLK_SERCOM3_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
@@ -209,7 +202,6 @@
*/
void SIM3_PORT_init()
{
-
gpio_set_pin_function(SIM3_IO, PINMUX_PB20C_SERCOM3_PAD0);
}
@@ -232,7 +224,6 @@
*/
void SIM4_CLOCK_init()
{
-
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM4_GCLK_ID_CORE, CONF_GCLK_SERCOM4_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM4_GCLK_ID_SLOW, CONF_GCLK_SERCOM4_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
@@ -246,7 +237,6 @@
*/
void SIM4_PORT_init()
{
-
gpio_set_pin_function(SIM4_IO, PINMUX_PB08D_SERCOM4_PAD0);
}
@@ -269,7 +259,6 @@
*/
void SIM5_CLOCK_init()
{
-
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM5_GCLK_ID_CORE, CONF_GCLK_SERCOM5_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM5_GCLK_ID_SLOW, CONF_GCLK_SERCOM5_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
@@ -283,7 +272,6 @@
*/
void SIM5_PORT_init()
{
-
gpio_set_pin_function(SIM5_IO, PINMUX_PB16C_SERCOM5_PAD0);
}
@@ -306,7 +294,6 @@
*/
void SIM6_CLOCK_init()
{
-
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM6_GCLK_ID_CORE, CONF_GCLK_SERCOM6_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM6_GCLK_ID_SLOW, CONF_GCLK_SERCOM6_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
@@ -320,7 +307,6 @@
*/
void SIM6_PORT_init()
{
-
gpio_set_pin_function(SIM6_IO, PINMUX_PC16C_SERCOM6_PAD0);
}
@@ -344,7 +330,6 @@
*/
void UART_debug_CLOCK_init()
{
-
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM7_GCLK_ID_CORE, CONF_GCLK_SERCOM7_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM7_GCLK_ID_SLOW, CONF_GCLK_SERCOM7_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
@@ -358,7 +343,6 @@
*/
void UART_debug_PORT_init()
{
-
gpio_set_pin_function(UART_TX, PINMUX_PB30C_SERCOM7_PAD0);
gpio_set_pin_function(UART_RX, PINMUX_PB31C_SERCOM7_PAD1);
@@ -383,7 +367,6 @@
*/
void SIM7_CLOCK_init()
{
-
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM7_GCLK_ID_CORE, CONF_GCLK_SERCOM7_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM7_GCLK_ID_SLOW, CONF_GCLK_SERCOM7_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
@@ -397,7 +380,6 @@
*/
void SIM7_PORT_init()
{
-
gpio_set_pin_function(SIM7_IO, PINMUX_PB21D_SERCOM7_PAD0);
}
@@ -415,96 +397,95 @@
#endif
void USB_DEVICE_INSTANCE_PORT_init(void)
{
-
gpio_set_pin_direction(USBUP_D_N,
- // <y> Pin direction
- // <id> pad_direction
- // <GPIO_DIRECTION_OFF"> Off
- // <GPIO_DIRECTION_IN"> In
- // <GPIO_DIRECTION_OUT"> Out
- GPIO_DIRECTION_OUT);
+ // <y> Pin direction
+ // <id> pad_direction
+ // <GPIO_DIRECTION_OFF"> Off
+ // <GPIO_DIRECTION_IN"> In
+ // <GPIO_DIRECTION_OUT"> Out
+ GPIO_DIRECTION_OUT);
gpio_set_pin_level(USBUP_D_N,
- // <y> Initial level
- // <id> pad_initial_level
- // <false"> Low
- // <true"> High
- false);
+ // <y> Initial level
+ // <id> pad_initial_level
+ // <false"> Low
+ // <true"> High
+ false);
gpio_set_pin_pull_mode(USBUP_D_N,
- // <y> Pull configuration
- // <id> pad_pull_config
- // <GPIO_PULL_OFF"> Off
- // <GPIO_PULL_UP"> Pull-up
- // <GPIO_PULL_DOWN"> Pull-down
- GPIO_PULL_OFF);
+ // <y> Pull configuration
+ // <id> pad_pull_config
+ // <GPIO_PULL_OFF"> Off
+ // <GPIO_PULL_UP"> Pull-up
+ // <GPIO_PULL_DOWN"> Pull-down
+ GPIO_PULL_OFF);
gpio_set_pin_function(USBUP_D_N,
- // <y> Pin function
- // <id> pad_function
- // <i> Auto : use driver pinmux if signal is imported by driver, else turn off function
- // <PINMUX_PA24H_USB_DM"> Auto
- // <GPIO_PIN_FUNCTION_OFF"> Off
- // <GPIO_PIN_FUNCTION_A"> A
- // <GPIO_PIN_FUNCTION_B"> B
- // <GPIO_PIN_FUNCTION_C"> C
- // <GPIO_PIN_FUNCTION_D"> D
- // <GPIO_PIN_FUNCTION_E"> E
- // <GPIO_PIN_FUNCTION_F"> F
- // <GPIO_PIN_FUNCTION_G"> G
- // <GPIO_PIN_FUNCTION_H"> H
- // <GPIO_PIN_FUNCTION_I"> I
- // <GPIO_PIN_FUNCTION_J"> J
- // <GPIO_PIN_FUNCTION_K"> K
- // <GPIO_PIN_FUNCTION_L"> L
- // <GPIO_PIN_FUNCTION_M"> M
- // <GPIO_PIN_FUNCTION_N"> N
- PINMUX_PA24H_USB_DM);
+ // <y> Pin function
+ // <id> pad_function
+ // <i> Auto : use driver pinmux if signal is imported by driver, else turn off function
+ // <PINMUX_PA24H_USB_DM"> Auto
+ // <GPIO_PIN_FUNCTION_OFF"> Off
+ // <GPIO_PIN_FUNCTION_A"> A
+ // <GPIO_PIN_FUNCTION_B"> B
+ // <GPIO_PIN_FUNCTION_C"> C
+ // <GPIO_PIN_FUNCTION_D"> D
+ // <GPIO_PIN_FUNCTION_E"> E
+ // <GPIO_PIN_FUNCTION_F"> F
+ // <GPIO_PIN_FUNCTION_G"> G
+ // <GPIO_PIN_FUNCTION_H"> H
+ // <GPIO_PIN_FUNCTION_I"> I
+ // <GPIO_PIN_FUNCTION_J"> J
+ // <GPIO_PIN_FUNCTION_K"> K
+ // <GPIO_PIN_FUNCTION_L"> L
+ // <GPIO_PIN_FUNCTION_M"> M
+ // <GPIO_PIN_FUNCTION_N"> N
+ PINMUX_PA24H_USB_DM);
gpio_set_pin_direction(USBUP_D_P,
- // <y> Pin direction
- // <id> pad_direction
- // <GPIO_DIRECTION_OFF"> Off
- // <GPIO_DIRECTION_IN"> In
- // <GPIO_DIRECTION_OUT"> Out
- GPIO_DIRECTION_OUT);
+ // <y> Pin direction
+ // <id> pad_direction
+ // <GPIO_DIRECTION_OFF"> Off
+ // <GPIO_DIRECTION_IN"> In
+ // <GPIO_DIRECTION_OUT"> Out
+ GPIO_DIRECTION_OUT);
gpio_set_pin_level(USBUP_D_P,
- // <y> Initial level
- // <id> pad_initial_level
- // <false"> Low
- // <true"> High
- false);
+ // <y> Initial level
+ // <id> pad_initial_level
+ // <false"> Low
+ // <true"> High
+ false);
gpio_set_pin_pull_mode(USBUP_D_P,
- // <y> Pull configuration
- // <id> pad_pull_config
- // <GPIO_PULL_OFF"> Off
- // <GPIO_PULL_UP"> Pull-up
- // <GPIO_PULL_DOWN"> Pull-down
- GPIO_PULL_OFF);
+ // <y> Pull configuration
+ // <id> pad_pull_config
+ // <GPIO_PULL_OFF"> Off
+ // <GPIO_PULL_UP"> Pull-up
+ // <GPIO_PULL_DOWN"> Pull-down
+ GPIO_PULL_OFF);
gpio_set_pin_function(USBUP_D_P,
- // <y> Pin function
- // <id> pad_function
- // <i> Auto : use driver pinmux if signal is imported by driver, else turn off function
- // <PINMUX_PA25H_USB_DP"> Auto
- // <GPIO_PIN_FUNCTION_OFF"> Off
- // <GPIO_PIN_FUNCTION_A"> A
- // <GPIO_PIN_FUNCTION_B"> B
- // <GPIO_PIN_FUNCTION_C"> C
- // <GPIO_PIN_FUNCTION_D"> D
- // <GPIO_PIN_FUNCTION_E"> E
- // <GPIO_PIN_FUNCTION_F"> F
- // <GPIO_PIN_FUNCTION_G"> G
- // <GPIO_PIN_FUNCTION_H"> H
- // <GPIO_PIN_FUNCTION_I"> I
- // <GPIO_PIN_FUNCTION_J"> J
- // <GPIO_PIN_FUNCTION_K"> K
- // <GPIO_PIN_FUNCTION_L"> L
- // <GPIO_PIN_FUNCTION_M"> M
- // <GPIO_PIN_FUNCTION_N"> N
- PINMUX_PA25H_USB_DP);
+ // <y> Pin function
+ // <id> pad_function
+ // <i> Auto : use driver pinmux if signal is imported by driver, else turn off function
+ // <PINMUX_PA25H_USB_DP"> Auto
+ // <GPIO_PIN_FUNCTION_OFF"> Off
+ // <GPIO_PIN_FUNCTION_A"> A
+ // <GPIO_PIN_FUNCTION_B"> B
+ // <GPIO_PIN_FUNCTION_C"> C
+ // <GPIO_PIN_FUNCTION_D"> D
+ // <GPIO_PIN_FUNCTION_E"> E
+ // <GPIO_PIN_FUNCTION_F"> F
+ // <GPIO_PIN_FUNCTION_G"> G
+ // <GPIO_PIN_FUNCTION_H"> H
+ // <GPIO_PIN_FUNCTION_I"> I
+ // <GPIO_PIN_FUNCTION_J"> J
+ // <GPIO_PIN_FUNCTION_K"> K
+ // <GPIO_PIN_FUNCTION_L"> L
+ // <GPIO_PIN_FUNCTION_M"> M
+ // <GPIO_PIN_FUNCTION_N"> N
+ PINMUX_PA25H_USB_DP);
}
/* The USB module requires a GCLK_USB of 48 MHz ~ 0.25% clock
@@ -515,7 +496,6 @@
void USB_DEVICE_INSTANCE_CLOCK_init(void)
{
-
hri_gclk_write_PCHCTRL_reg(GCLK, USB_GCLK_ID, CONF_GCLK_USB_SRC | GCLK_PCHCTRL_CHEN);
hri_mclk_set_AHBMASK_USB_bit(MCLK);
hri_mclk_set_APBBMASK_USB_bit(MCLK);
@@ -538,12 +518,12 @@
gpio_set_pin_direction(SIM4_INT, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(SIM4_INT,
- // <y> Pull configuration
- // <id> pad_pull_config
- // <GPIO_PULL_OFF"> Off
- // <GPIO_PULL_UP"> Pull-up
- // <GPIO_PULL_DOWN"> Pull-down
- GPIO_PULL_OFF);
+ // <y> Pull configuration
+ // <id> pad_pull_config
+ // <GPIO_PULL_OFF"> Off
+ // <GPIO_PULL_UP"> Pull-up
+ // <GPIO_PULL_DOWN"> Pull-down
+ GPIO_PULL_OFF);
gpio_set_pin_function(SIM4_INT, GPIO_PIN_FUNCTION_OFF);
@@ -553,108 +533,108 @@
gpio_set_pin_direction(SIM5_INT, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(SIM5_INT,
- // <y> Pull configuration
- // <id> pad_pull_config
- // <GPIO_PULL_OFF"> Off
- // <GPIO_PULL_UP"> Pull-up
- // <GPIO_PULL_DOWN"> Pull-down
- GPIO_PULL_OFF);
+ // <y> Pull configuration
+ // <id> pad_pull_config
+ // <GPIO_PULL_OFF"> Off
+ // <GPIO_PULL_UP"> Pull-up
+ // <GPIO_PULL_DOWN"> Pull-down
+ GPIO_PULL_OFF);
gpio_set_pin_function(SIM5_INT, GPIO_PIN_FUNCTION_OFF);
// GPIO on PA10
gpio_set_pin_direction(RMII_CLOCK,
- // <y> Pin direction
- // <id> pad_direction
- // <GPIO_DIRECTION_OFF"> Off
- // <GPIO_DIRECTION_IN"> In
- // <GPIO_DIRECTION_OUT"> Out
- GPIO_DIRECTION_OUT);
+ // <y> Pin direction
+ // <id> pad_direction
+ // <GPIO_DIRECTION_OFF"> Off
+ // <GPIO_DIRECTION_IN"> In
+ // <GPIO_DIRECTION_OUT"> Out
+ GPIO_DIRECTION_OUT);
gpio_set_pin_level(RMII_CLOCK,
- // <y> Initial level
- // <id> pad_initial_level
- // <false"> Low
- // <true"> High
- false);
+ // <y> Initial level
+ // <id> pad_initial_level
+ // <false"> Low
+ // <true"> High
+ false);
gpio_set_pin_pull_mode(RMII_CLOCK,
- // <y> Pull configuration
- // <id> pad_pull_config
- // <GPIO_PULL_OFF"> Off
- // <GPIO_PULL_UP"> Pull-up
- // <GPIO_PULL_DOWN"> Pull-down
- GPIO_PULL_OFF);
+ // <y> Pull configuration
+ // <id> pad_pull_config
+ // <GPIO_PULL_OFF"> Off
+ // <GPIO_PULL_UP"> Pull-up
+ // <GPIO_PULL_DOWN"> Pull-down
+ GPIO_PULL_OFF);
gpio_set_pin_function(RMII_CLOCK,
- // <y> Pin function
- // <id> pad_function
- // <i> Auto : use driver pinmux if signal is imported by driver, else turn off function
- // <GPIO_PIN_FUNCTION_OFF"> Auto
- // <GPIO_PIN_FUNCTION_OFF"> Off
- // <GPIO_PIN_FUNCTION_A"> A
- // <GPIO_PIN_FUNCTION_B"> B
- // <GPIO_PIN_FUNCTION_C"> C
- // <GPIO_PIN_FUNCTION_D"> D
- // <GPIO_PIN_FUNCTION_E"> E
- // <GPIO_PIN_FUNCTION_F"> F
- // <GPIO_PIN_FUNCTION_G"> G
- // <GPIO_PIN_FUNCTION_H"> H
- // <GPIO_PIN_FUNCTION_I"> I
- // <GPIO_PIN_FUNCTION_J"> J
- // <GPIO_PIN_FUNCTION_K"> K
- // <GPIO_PIN_FUNCTION_L"> L
- // <GPIO_PIN_FUNCTION_M"> M
- // <GPIO_PIN_FUNCTION_N"> N
- GPIO_PIN_FUNCTION_M);
+ // <y> Pin function
+ // <id> pad_function
+ // <i> Auto : use driver pinmux if signal is imported by driver, else turn off function
+ // <GPIO_PIN_FUNCTION_OFF"> Auto
+ // <GPIO_PIN_FUNCTION_OFF"> Off
+ // <GPIO_PIN_FUNCTION_A"> A
+ // <GPIO_PIN_FUNCTION_B"> B
+ // <GPIO_PIN_FUNCTION_C"> C
+ // <GPIO_PIN_FUNCTION_D"> D
+ // <GPIO_PIN_FUNCTION_E"> E
+ // <GPIO_PIN_FUNCTION_F"> F
+ // <GPIO_PIN_FUNCTION_G"> G
+ // <GPIO_PIN_FUNCTION_H"> H
+ // <GPIO_PIN_FUNCTION_I"> I
+ // <GPIO_PIN_FUNCTION_J"> J
+ // <GPIO_PIN_FUNCTION_K"> K
+ // <GPIO_PIN_FUNCTION_L"> L
+ // <GPIO_PIN_FUNCTION_M"> M
+ // <GPIO_PIN_FUNCTION_N"> N
+ GPIO_PIN_FUNCTION_M);
// GPIO on PA11
gpio_set_pin_direction(SIMCLK_20MHZ,
- // <y> Pin direction
- // <id> pad_direction
- // <GPIO_DIRECTION_OFF"> Off
- // <GPIO_DIRECTION_IN"> In
- // <GPIO_DIRECTION_OUT"> Out
- GPIO_DIRECTION_OUT);
+ // <y> Pin direction
+ // <id> pad_direction
+ // <GPIO_DIRECTION_OFF"> Off
+ // <GPIO_DIRECTION_IN"> In
+ // <GPIO_DIRECTION_OUT"> Out
+ GPIO_DIRECTION_OUT);
gpio_set_pin_level(SIMCLK_20MHZ,
- // <y> Initial level
- // <id> pad_initial_level
- // <false"> Low
- // <true"> High
- false);
+ // <y> Initial level
+ // <id> pad_initial_level
+ // <false"> Low
+ // <true"> High
+ false);
gpio_set_pin_pull_mode(SIMCLK_20MHZ,
- // <y> Pull configuration
- // <id> pad_pull_config
- // <GPIO_PULL_OFF"> Off
- // <GPIO_PULL_UP"> Pull-up
- // <GPIO_PULL_DOWN"> Pull-down
- GPIO_PULL_OFF);
+ // <y> Pull configuration
+ // <id> pad_pull_config
+ // <GPIO_PULL_OFF"> Off
+ // <GPIO_PULL_UP"> Pull-up
+ // <GPIO_PULL_DOWN"> Pull-down
+ GPIO_PULL_OFF);
gpio_set_pin_function(SIMCLK_20MHZ,
- // <y> Pin function
- // <id> pad_function
- // <i> Auto : use driver pinmux if signal is imported by driver, else turn off function
- // <GPIO_PIN_FUNCTION_OFF"> Auto
- // <GPIO_PIN_FUNCTION_OFF"> Off
- // <GPIO_PIN_FUNCTION_A"> A
- // <GPIO_PIN_FUNCTION_B"> B
- // <GPIO_PIN_FUNCTION_C"> C
- // <GPIO_PIN_FUNCTION_D"> D
- // <GPIO_PIN_FUNCTION_E"> E
- // <GPIO_PIN_FUNCTION_F"> F
- // <GPIO_PIN_FUNCTION_G"> G
- // <GPIO_PIN_FUNCTION_H"> H
- // <GPIO_PIN_FUNCTION_I"> I
- // <GPIO_PIN_FUNCTION_J"> J
- // <GPIO_PIN_FUNCTION_K"> K
- // <GPIO_PIN_FUNCTION_L"> L
- // <GPIO_PIN_FUNCTION_M"> M
- // <GPIO_PIN_FUNCTION_N"> N
- GPIO_PIN_FUNCTION_M);
+ // <y> Pin function
+ // <id> pad_function
+ // <i> Auto : use driver pinmux if signal is imported by driver, else turn off function
+ // <GPIO_PIN_FUNCTION_OFF"> Auto
+ // <GPIO_PIN_FUNCTION_OFF"> Off
+ // <GPIO_PIN_FUNCTION_A"> A
+ // <GPIO_PIN_FUNCTION_B"> B
+ // <GPIO_PIN_FUNCTION_C"> C
+ // <GPIO_PIN_FUNCTION_D"> D
+ // <GPIO_PIN_FUNCTION_E"> E
+ // <GPIO_PIN_FUNCTION_F"> F
+ // <GPIO_PIN_FUNCTION_G"> G
+ // <GPIO_PIN_FUNCTION_H"> H
+ // <GPIO_PIN_FUNCTION_I"> I
+ // <GPIO_PIN_FUNCTION_J"> J
+ // <GPIO_PIN_FUNCTION_K"> K
+ // <GPIO_PIN_FUNCTION_L"> L
+ // <GPIO_PIN_FUNCTION_M"> M
+ // <GPIO_PIN_FUNCTION_N"> N
+ GPIO_PIN_FUNCTION_M);
// GPIO on PA20
@@ -662,12 +642,12 @@
gpio_set_pin_direction(VB0, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(VB0,
- // <y> Pull configuration
- // <id> pad_pull_config
- // <GPIO_PULL_OFF"> Off
- // <GPIO_PULL_UP"> Pull-up
- // <GPIO_PULL_DOWN"> Pull-down
- GPIO_PULL_OFF);
+ // <y> Pull configuration
+ // <id> pad_pull_config
+ // <GPIO_PULL_OFF"> Off
+ // <GPIO_PULL_UP"> Pull-up
+ // <GPIO_PULL_DOWN"> Pull-down
+ GPIO_PULL_OFF);
gpio_set_pin_function(VB0, GPIO_PIN_FUNCTION_OFF);
@@ -677,12 +657,12 @@
gpio_set_pin_direction(VB1, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(VB1,
- // <y> Pull configuration
- // <id> pad_pull_config
- // <GPIO_PULL_OFF"> Off
- // <GPIO_PULL_UP"> Pull-up
- // <GPIO_PULL_DOWN"> Pull-down
- GPIO_PULL_OFF);
+ // <y> Pull configuration
+ // <id> pad_pull_config
+ // <GPIO_PULL_OFF"> Off
+ // <GPIO_PULL_UP"> Pull-up
+ // <GPIO_PULL_DOWN"> Pull-down
+ GPIO_PULL_OFF);
gpio_set_pin_function(VB1, GPIO_PIN_FUNCTION_OFF);
@@ -692,12 +672,12 @@
gpio_set_pin_direction(VB2, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(VB2,
- // <y> Pull configuration
- // <id> pad_pull_config
- // <GPIO_PULL_OFF"> Off
- // <GPIO_PULL_UP"> Pull-up
- // <GPIO_PULL_DOWN"> Pull-down
- GPIO_PULL_OFF);
+ // <y> Pull configuration
+ // <id> pad_pull_config
+ // <GPIO_PULL_OFF"> Off
+ // <GPIO_PULL_UP"> Pull-up
+ // <GPIO_PULL_DOWN"> Pull-down
+ GPIO_PULL_OFF);
gpio_set_pin_function(VB2, GPIO_PIN_FUNCTION_OFF);
@@ -707,23 +687,23 @@
gpio_set_pin_direction(VB3, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(VB3,
- // <y> Pull configuration
- // <id> pad_pull_config
- // <GPIO_PULL_OFF"> Off
- // <GPIO_PULL_UP"> Pull-up
- // <GPIO_PULL_DOWN"> Pull-down
- GPIO_PULL_OFF);
+ // <y> Pull configuration
+ // <id> pad_pull_config
+ // <GPIO_PULL_OFF"> Off
+ // <GPIO_PULL_UP"> Pull-up
+ // <GPIO_PULL_DOWN"> Pull-down
+ GPIO_PULL_OFF);
gpio_set_pin_function(VB3, GPIO_PIN_FUNCTION_OFF);
// GPIO on PB02
gpio_set_pin_level(SCL2,
- // <y> Initial level
- // <id> pad_initial_level
- // <false"> Low
- // <true"> High
- false);
+ // <y> Initial level
+ // <id> pad_initial_level
+ // <false"> Low
+ // <true"> High
+ false);
// Set pin direction to output
gpio_set_pin_direction(SCL2, GPIO_DIRECTION_OUT);
@@ -733,11 +713,11 @@
// GPIO on PB03
gpio_set_pin_level(SDA2,
- // <y> Initial level
- // <id> pad_initial_level
- // <false"> Low
- // <true"> High
- false);
+ // <y> Initial level
+ // <id> pad_initial_level
+ // <false"> Low
+ // <true"> High
+ false);
// Set pin direction to output
gpio_set_pin_direction(SDA2, GPIO_DIRECTION_OUT);
@@ -750,12 +730,12 @@
gpio_set_pin_direction(SIM6_INT, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(SIM6_INT,
- // <y> Pull configuration
- // <id> pad_pull_config
- // <GPIO_PULL_OFF"> Off
- // <GPIO_PULL_UP"> Pull-up
- // <GPIO_PULL_DOWN"> Pull-down
- GPIO_PULL_OFF);
+ // <y> Pull configuration
+ // <id> pad_pull_config
+ // <GPIO_PULL_OFF"> Off
+ // <GPIO_PULL_UP"> Pull-up
+ // <GPIO_PULL_DOWN"> Pull-down
+ GPIO_PULL_OFF);
gpio_set_pin_function(SIM6_INT, GPIO_PIN_FUNCTION_OFF);
@@ -765,23 +745,23 @@
gpio_set_pin_direction(SIM7_INT, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(SIM7_INT,
- // <y> Pull configuration
- // <id> pad_pull_config
- // <GPIO_PULL_OFF"> Off
- // <GPIO_PULL_UP"> Pull-up
- // <GPIO_PULL_DOWN"> Pull-down
- GPIO_PULL_OFF);
+ // <y> Pull configuration
+ // <id> pad_pull_config
+ // <GPIO_PULL_OFF"> Off
+ // <GPIO_PULL_UP"> Pull-up
+ // <GPIO_PULL_DOWN"> Pull-down
+ GPIO_PULL_OFF);
gpio_set_pin_function(SIM7_INT, GPIO_PIN_FUNCTION_OFF);
// GPIO on PB06
gpio_set_pin_level(SCL3,
- // <y> Initial level
- // <id> pad_initial_level
- // <false"> Low
- // <true"> High
- false);
+ // <y> Initial level
+ // <id> pad_initial_level
+ // <false"> Low
+ // <true"> High
+ false);
// Set pin direction to output
gpio_set_pin_direction(SCL3, GPIO_DIRECTION_OUT);
@@ -791,11 +771,11 @@
// GPIO on PB07
gpio_set_pin_level(SDA3,
- // <y> Initial level
- // <id> pad_initial_level
- // <false"> Low
- // <true"> High
- false);
+ // <y> Initial level
+ // <id> pad_initial_level
+ // <false"> Low
+ // <true"> High
+ false);
// Set pin direction to output
gpio_set_pin_direction(SDA3, GPIO_DIRECTION_OUT);
@@ -805,11 +785,11 @@
// GPIO on PB14
gpio_set_pin_level(SCL1,
- // <y> Initial level
- // <id> pad_initial_level
- // <false"> Low
- // <true"> High
- false);
+ // <y> Initial level
+ // <id> pad_initial_level
+ // <false"> Low
+ // <true"> High
+ false);
// Set pin direction to output
gpio_set_pin_direction(SCL1, GPIO_DIRECTION_OUT);
@@ -819,11 +799,11 @@
// GPIO on PB15
gpio_set_pin_level(SDA1,
- // <y> Initial level
- // <id> pad_initial_level
- // <false"> Low
- // <true"> High
- false);
+ // <y> Initial level
+ // <id> pad_initial_level
+ // <false"> Low
+ // <true"> High
+ false);
// Set pin direction to output
gpio_set_pin_direction(SDA1, GPIO_DIRECTION_OUT);
@@ -836,12 +816,12 @@
gpio_set_pin_direction(SIM0_INT, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(SIM0_INT,
- // <y> Pull configuration
- // <id> pad_pull_config
- // <GPIO_PULL_OFF"> Off
- // <GPIO_PULL_UP"> Pull-up
- // <GPIO_PULL_DOWN"> Pull-down
- GPIO_PULL_OFF);
+ // <y> Pull configuration
+ // <id> pad_pull_config
+ // <GPIO_PULL_OFF"> Off
+ // <GPIO_PULL_UP"> Pull-up
+ // <GPIO_PULL_DOWN"> Pull-down
+ GPIO_PULL_OFF);
gpio_set_pin_function(SIM0_INT, GPIO_PIN_FUNCTION_OFF);
@@ -851,12 +831,12 @@
gpio_set_pin_direction(SIM1_INT, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(SIM1_INT,
- // <y> Pull configuration
- // <id> pad_pull_config
- // <GPIO_PULL_OFF"> Off
- // <GPIO_PULL_UP"> Pull-up
- // <GPIO_PULL_DOWN"> Pull-down
- GPIO_PULL_OFF);
+ // <y> Pull configuration
+ // <id> pad_pull_config
+ // <GPIO_PULL_OFF"> Off
+ // <GPIO_PULL_UP"> Pull-up
+ // <GPIO_PULL_DOWN"> Pull-down
+ GPIO_PULL_OFF);
gpio_set_pin_function(SIM1_INT, GPIO_PIN_FUNCTION_OFF);
@@ -866,12 +846,12 @@
gpio_set_pin_direction(SIM2_INT, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(SIM2_INT,
- // <y> Pull configuration
- // <id> pad_pull_config
- // <GPIO_PULL_OFF"> Off
- // <GPIO_PULL_UP"> Pull-up
- // <GPIO_PULL_DOWN"> Pull-down
- GPIO_PULL_OFF);
+ // <y> Pull configuration
+ // <id> pad_pull_config
+ // <GPIO_PULL_OFF"> Off
+ // <GPIO_PULL_UP"> Pull-up
+ // <GPIO_PULL_DOWN"> Pull-down
+ GPIO_PULL_OFF);
gpio_set_pin_function(SIM2_INT, GPIO_PIN_FUNCTION_OFF);
@@ -881,12 +861,12 @@
gpio_set_pin_direction(SIM3_INT, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(SIM3_INT,
- // <y> Pull configuration
- // <id> pad_pull_config
- // <GPIO_PULL_OFF"> Off
- // <GPIO_PULL_UP"> Pull-up
- // <GPIO_PULL_DOWN"> Pull-down
- GPIO_PULL_OFF);
+ // <y> Pull configuration
+ // <id> pad_pull_config
+ // <GPIO_PULL_OFF"> Off
+ // <GPIO_PULL_UP"> Pull-up
+ // <GPIO_PULL_DOWN"> Pull-down
+ GPIO_PULL_OFF);
gpio_set_pin_function(SIM3_INT, GPIO_PIN_FUNCTION_OFF);
@@ -896,12 +876,12 @@
gpio_set_pin_direction(SWITCH, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(SWITCH,
- // <y> Pull configuration
- // <id> pad_pull_config
- // <GPIO_PULL_OFF"> Off
- // <GPIO_PULL_UP"> Pull-up
- // <GPIO_PULL_DOWN"> Pull-down
- GPIO_PULL_OFF);
+ // <y> Pull configuration
+ // <id> pad_pull_config
+ // <GPIO_PULL_OFF"> Off
+ // <GPIO_PULL_UP"> Pull-up
+ // <GPIO_PULL_DOWN"> Pull-down
+ GPIO_PULL_OFF);
gpio_set_pin_function(SWITCH, GPIO_PIN_FUNCTION_OFF);
@@ -911,23 +891,23 @@
gpio_set_pin_direction(MUX_STAT, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(MUX_STAT,
- // <y> Pull configuration
- // <id> pad_pull_config
- // <GPIO_PULL_OFF"> Off
- // <GPIO_PULL_UP"> Pull-up
- // <GPIO_PULL_DOWN"> Pull-down
- GPIO_PULL_OFF);
+ // <y> Pull configuration
+ // <id> pad_pull_config
+ // <GPIO_PULL_OFF"> Off
+ // <GPIO_PULL_UP"> Pull-up
+ // <GPIO_PULL_DOWN"> Pull-down
+ GPIO_PULL_OFF);
gpio_set_pin_function(MUX_STAT, GPIO_PIN_FUNCTION_OFF);
// GPIO on PC26
gpio_set_pin_level(USER_LED,
- // <y> Initial level
- // <id> pad_initial_level
- // <false"> Low
- // <true"> High
- false);
+ // <y> Initial level
+ // <id> pad_initial_level
+ // <false"> Low
+ // <true"> High
+ false);
// Set pin direction to output
gpio_set_pin_direction(USER_LED, GPIO_DIRECTION_OUT);
@@ -937,11 +917,11 @@
// GPIO on PC27
gpio_set_pin_level(SCL4,
- // <y> Initial level
- // <id> pad_initial_level
- // <false"> Low
- // <true"> High
- false);
+ // <y> Initial level
+ // <id> pad_initial_level
+ // <false"> Low
+ // <true"> High
+ false);
// Set pin direction to output
gpio_set_pin_direction(SCL4, GPIO_DIRECTION_OUT);
@@ -951,11 +931,11 @@
// GPIO on PC28
gpio_set_pin_level(SDA4,
- // <y> Initial level
- // <id> pad_initial_level
- // <false"> Low
- // <true"> High
- false);
+ // <y> Initial level
+ // <id> pad_initial_level
+ // <false"> Low
+ // <true"> High
+ false);
// Set pin direction to output
gpio_set_pin_direction(SDA4, GPIO_DIRECTION_OUT);
diff --git a/sysmoOCTSIM/i2c_bitbang.c b/sysmoOCTSIM/i2c_bitbang.c
index b1a9a62..7ec09b1 100644
--- a/sysmoOCTSIM/i2c_bitbang.c
+++ b/sysmoOCTSIM/i2c_bitbang.c
@@ -10,8 +10,8 @@
#include <err_codes.h>
#include "i2c_bitbang.h"
-#define setsda(adap, val) gpio_set_pin_level((adap)->pin_sda, val)
-#define setscl(adap, val) gpio_set_pin_level((adap)->pin_scl, val)
+#define setsda(adap, val) gpio_set_pin_level((adap)->pin_sda, val)
+#define setscl(adap, val) gpio_set_pin_level((adap)->pin_scl, val)
static int getsda(const struct i2c_adapter *adap)
{
@@ -34,13 +34,13 @@
static inline void sdalo(const struct i2c_adapter *adap)
{
setsda(adap, 0);
- delay_us((adap->udelay+1) / 2);
+ delay_us((adap->udelay + 1) / 2);
}
static inline void sdahi(const struct i2c_adapter *adap)
{
setsda(adap, 1);
- delay_us((adap->udelay+1) / 2);
+ delay_us((adap->udelay + 1) / 2);
}
static inline void scllo(const struct i2c_adapter *adap)
@@ -49,7 +49,6 @@
delay_us(adap->udelay / 2);
}
-
static int sclhi(const struct i2c_adapter *adap)
{
setscl(adap, 1);
@@ -64,9 +63,9 @@
static void i2c_start(const struct i2c_adapter *adap)
{
/* Assert: SCL + SDA are high */
- setsda(adap, 0); /* set SDA to low */
- delay_us(adap->udelay); /* delay */
- scllo(adap); /* Set SCL to low */
+ setsda(adap, 0); /* set SDA to low */
+ delay_us(adap->udelay); /* delay */
+ scllo(adap); /* Set SCL to low */
}
static void i2c_repstart(const struct i2c_adapter *adap)
@@ -82,10 +81,10 @@
static void i2c_stop(const struct i2c_adapter *adap)
{
/* Assert: SCL is low */
- sdalo(adap); /* set SDA low */
- sclhi(adap); /* set SCL to high */
- setsda(adap, 1); /* set SDA to high */
- delay_us(adap->udelay); /* delay */
+ sdalo(adap); /* set SDA low */
+ sclhi(adap); /* set SCL to high */
+ setsda(adap, 1); /* set SDA to high */
+ delay_us(adap->udelay); /* delay */
}
static int i2c_outb(const struct i2c_adapter *adap, uint8_t outdata)
diff --git a/sysmoOCTSIM/i2c_bitbang.h b/sysmoOCTSIM/i2c_bitbang.h
index 7157c2e..4634d4c 100644
--- a/sysmoOCTSIM/i2c_bitbang.h
+++ b/sysmoOCTSIM/i2c_bitbang.h
@@ -2,8 +2,8 @@
#include <stdint.h>
struct i2c_adapter {
- uint8_t pin_scl;
- uint8_t pin_sda;
+ uint8_t pin_scl;
+ uint8_t pin_sda;
uint32_t udelay;
};
diff --git a/sysmoOCTSIM/libosmo_emb.c b/sysmoOCTSIM/libosmo_emb.c
index 81b29e3..c3c7445 100644
--- a/sysmoOCTSIM/libosmo_emb.c
+++ b/sysmoOCTSIM/libosmo_emb.c
@@ -5,7 +5,6 @@
#include <osmocom/core/utils.h>
#include <osmocom/core/msgb.h>
-
extern void *g_tall_ctx;
void *g_msgb_ctx;
@@ -125,7 +124,7 @@
vfprintf(stderr, format, ap);
/* TODO: LOG_FILENAME_POS_LINE_END; we cannot modify the format string here :/ */
int fmt_len = strlen(format);
- if (fmt_len && format[fmt_len-1] == '\n')
+ if (fmt_len && format[fmt_len - 1] == '\n')
fputc('\r', stderr);
}
diff --git a/sysmoOCTSIM/linuxlist_atomic.h b/sysmoOCTSIM/linuxlist_atomic.h
index 8e0a5f0..532108a 100644
--- a/sysmoOCTSIM/linuxlist_atomic.h
+++ b/sysmoOCTSIM/linuxlist_atomic.h
@@ -14,11 +14,13 @@
/*! Initialize a llist_head to point back to itself.
* \param[in] ptr llist_head to be initialized.
*/
-#define INIT_LLIST_HEAD_AT(ptr) do { \
- CRITICAL_SECTION_ENTER(); \
- (ptr)->next = (ptr); (ptr)->prev = (ptr); \
- CRITICAL_SECTION_LEAVE(); \
-} while (0)
+#define INIT_LLIST_HEAD_AT(ptr) \
+ do { \
+ CRITICAL_SECTION_ENTER(); \
+ (ptr)->next = (ptr); \
+ (ptr)->prev = (ptr); \
+ CRITICAL_SECTION_LEAVE(); \
+ } while (0)
/*! Add a new entry into a linked list (at head).
* \param _new the entry to be added.
@@ -117,7 +119,7 @@
* The llist is reinitialised.
*/
static inline void llist_splice_init_at(struct llist_head *llist,
- struct llist_head *head)
+ struct llist_head *head)
{
CRITICAL_SECTION_ENTER()
if (!llist_empty(llist)) {
@@ -139,7 +141,7 @@
struct llist_head *entry;
unsigned int i = 0;
CRITICAL_SECTION_ENTER()
- llist_for_each(entry, head)
+ llist_for_each (entry, head)
i++;
CRITICAL_SECTION_LEAVE()
return i;
diff --git a/sysmoOCTSIM/main.c b/sysmoOCTSIM/main.c
index 92c5bbd..0bb5118 100644
--- a/sysmoOCTSIM/main.c
+++ b/sysmoOCTSIM/main.c
@@ -47,7 +47,6 @@
extern struct ccid_slot_ops iso_fsm_slot_ops;
static struct ccid_instance g_ci;
-
static void ccid_app_init(void);
static void board_init(void)
@@ -176,7 +175,6 @@
return -1;
}
return 1;
-
}
/* submit the next pending (if any) message for the IRQ EP */
@@ -258,7 +256,7 @@
llist_add_tail_at(&msg->list, &g_ccid_s.out_ep.list);
g_ccid_s.out_ep.in_progress = NULL;
- if(code != USB_XFER_DONE)
+ if (code != USB_XFER_DONE)
return;
/* submit another [free] msgb to receive the next transfer */
@@ -279,7 +277,7 @@
if (code == USB_XFER_UNHALT)
submit_next_in();
- if(code != USB_XFER_DONE)
+ if (code != USB_XFER_DONE)
return;
/* submit the next pending to-be-transmitted msgb (if any) */
@@ -300,7 +298,7 @@
if (code == USB_XFER_UNHALT)
submit_next_irq();
- if(code != USB_XFER_DONE)
+ if (code != USB_XFER_DONE)
return;
/* submit the next pending to-be-transmitted msgb (if any) */
@@ -310,14 +308,14 @@
#include "ccid_proto.h"
static struct msgb *ccid_gen_notify_slot_status(uint8_t old_bm, uint8_t new_bm)
{
- uint8_t statusbytes[2] = {0};
+ uint8_t statusbytes[2] = { 0 };
//struct msgb *msg = ccid_msgb_alloc();
- struct msgb *msg = msgb_alloc(300,"IRQ");
+ struct msgb *msg = msgb_alloc(300, "IRQ");
struct ccid_rdr_to_pc_notify_slot_change *nsc =
(struct ccid_rdr_to_pc_notify_slot_change *)msgb_put(msg, sizeof(*nsc) + sizeof(statusbytes));
nsc->bMessageType = RDR_to_PC_NotifySlotChange;
- for(int i = 0; i <8; i++) {
+ for (int i = 0; i < 8; i++) {
uint8_t byteidx = i >> 2;
uint8_t old_bit = (old_bm >> i) & 1;
uint8_t new_bit = (new_bm >> i) & 1;
@@ -346,7 +344,7 @@
struct msgb *msg;
unsigned int i;
- for (i = 0; i < 8; i++){
+ for (i = 0; i < 8; i++) {
bool level = ncn8025_interrupt_level(i);
new_mask |= level << i;
g_ci.slot_ops->icc_set_insertion_status(&g_ci.slot[i], level);
@@ -355,7 +353,7 @@
/* notify the user/host about any changes */
if (g_ccid_s.card_insert_mask != new_mask) {
printf("CARD_DET 0x%02x -> 0x%02x\r\n",
- g_ccid_s.card_insert_mask, new_mask);
+ g_ccid_s.card_insert_mask, new_mask);
msg = ccid_gen_notify_slot_status(g_ccid_s.card_insert_mask, new_mask);
msgb_enqueue_irqsafe(&g_ccid_s.irq_ep.list, msg);
@@ -381,7 +379,6 @@
* Command Line interface
***********************************************************************/
-
extern void testmode_init(void);
extern void libosmo_emb_init(void);
extern void libosmo_emb_mainloop(void);
@@ -391,7 +388,6 @@
void *g_tall_ctx;
-
/* Section 9.6 of SAMD5x/E5x Family Data Sheet */
static int get_chip_unique_serial(uint8_t *out, size_t len)
{
@@ -413,7 +409,7 @@
uint8_t buf[16];
int rc;
- if (len < 16*2 + 1)
+ if (len < 16 * 2 + 1)
return -EINVAL;
rc = get_chip_unique_serial(buf, sizeof(buf));
@@ -423,20 +419,20 @@
return 0;
}
-static int str_to_usb_desc(char* in, uint8_t in_sz, uint8_t* out, uint8_t out_sz){
- if (2+in_sz*2 < out_sz)
+static int str_to_usb_desc(char *in, uint8_t in_sz, uint8_t *out, uint8_t out_sz)
+{
+ if (2 + in_sz * 2 < out_sz)
return -1;
memset(out, 0, out_sz);
out[0] = out_sz;
out[1] = 0x3;
- for (int i= 2; i < out_sz; i+=2)
+ for (int i = 2; i < out_sz; i += 2)
out[i] = in[(i >> 1) - 1];
return 0;
}
-
-#define RSTCAUSE_STR_SIZE 64
+#define RSTCAUSE_STR_SIZE 64
static void get_rstcause_str(char *out)
{
uint8_t val = hri_rstc_read_RCAUSE_reg(RSTC);
@@ -461,8 +457,6 @@
//#######################
-
-
static uint32_t clock_freqs[] = {
2500000
};
@@ -472,8 +466,6 @@
};
extern struct usb_desc_collection usb_fs_descs;
-
-
static int feed_ccid(void)
{
struct usb_ep_q *ep_q = &g_ccid_s.out_ep;
@@ -508,8 +500,8 @@
#define NUM_OUT_BUF 16
-char sernr_buf[16*2+1];
-char product_buf[] = "sysmoOCTSIM "GIT_VERSION;
+char sernr_buf[16 * 2 + 1];
+char product_buf[] = "sysmoOCTSIM " GIT_VERSION;
//len, type, 2 byte per hex char * 2 for unicode
uint8_t sernr_buf_descr[1 + 1 + 16 * 2 * 2];
uint8_t product_buf_descr[1 + 1 + (sizeof(product_buf) - 1) * 2];
@@ -638,16 +630,16 @@
command_init("sysmoOCTSIM> ");
#endif
/* boost uart priority by setting all other irqs to uartprio+1 */
- for(int i = 0; i < PERIPH_COUNT_IRQn; i++)
+ for (int i = 0; i < PERIPH_COUNT_IRQn; i++)
NVIC_SetPriority(i, 2);
- for(int i = SERCOM0_0_IRQn; i <= SERCOM7_3_IRQn; i++)
+ for (int i = SERCOM0_0_IRQn; i <= SERCOM7_3_IRQn; i++)
NVIC_SetPriority(i, 1);
printf("\r\n\r\n"
- "=============================================================================\n\r"
- "sysmoOCTSIM firmware " GIT_VERSION "\n\r"
- "(C) 2018-2019 by sysmocom - s.f.m.c. GmbH and contributors\n\r"
- "=============================================================================\n\r");
+ "=============================================================================\n\r"
+ "sysmoOCTSIM firmware " GIT_VERSION "\n\r"
+ "(C) 2018-2019 by sysmocom - s.f.m.c. GmbH and contributors\n\r"
+ "=============================================================================\n\r");
printf("Chip ID: %s\r\n", sernr_buf);
printf("Reset cause: %s\r\n", rstcause_buf);
@@ -667,7 +659,7 @@
ccid_instance_init(&g_ci, &c_ops, &iso_fsm_slot_ops, &usb_fs_descs.ccid.class,
data_rates, clock_freqs, "", 0);
- for(int i =0; i < NUM_OUT_BUF; i++){
+ for (int i = 0; i < NUM_OUT_BUF; i++) {
struct msgb *msg = msgb_alloc(300, "ccid");
OSMO_ASSERT(msg);
/* return the message back to the queue of free message buffers */
@@ -688,7 +680,7 @@
gpio_set_pin_level(PIN_PB13, false);
#endif
-// command_print_prompt();
+ // command_print_prompt();
while (true) { // main loop
if (was_unconfigured_flag) {
reset_all_stuff_non_irq();
@@ -698,7 +690,7 @@
command_try_recv();
poll_card_detect();
submit_next_irq();
- for (int i = 0; i <= usb_fs_descs.ccid.class.bMaxSlotIndex; i++){
+ for (int i = 0; i <= usb_fs_descs.ccid.class.bMaxSlotIndex; i++) {
g_ci.slot_ops->handle_fsm_events(&g_ci.slot[i], true);
}
feed_ccid();
diff --git a/sysmoOCTSIM/ncn8025.c b/sysmoOCTSIM/ncn8025.c
index 04d0ebe..0e7cddf 100644
--- a/sysmoOCTSIM/ncn8025.c
+++ b/sysmoOCTSIM/ncn8025.c
@@ -15,7 +15,7 @@
#include "octsim_i2c.h"
#include "ncn8025.h"
-#define SX1503_ADDR 0x20
+#define SX1503_ADDR 0x20
/*! translate from ncn8025_settings into SX1503 register value */
static uint8_t ncn8025_encode(const struct ncn8025_settings *set)
@@ -70,7 +70,6 @@
return &i2c[idx];
}
-
static const uint8_t slot2data_reg(unsigned int slot)
{
if (slot & 1)
@@ -103,7 +102,6 @@
return (bool)(pin_values & (0x01U << GPIO_PIN(pin)));
}
-
/*! Set a given NCN8025 as described in 'set'.
* \param[in] slot Slot number (0..7)
* \param[in] set Settings that shall be written
diff --git a/sysmoOCTSIM/ncn8025.h b/sysmoOCTSIM/ncn8025.h
index 01ddc97..c2ba935 100644
--- a/sysmoOCTSIM/ncn8025.h
+++ b/sysmoOCTSIM/ncn8025.h
@@ -17,13 +17,13 @@
extern const unsigned int ncn8025_div_val[];
struct ncn8025_settings {
- bool rstin; /* Reset signal (true: asserted low) */
- bool cmdvcc; /* Command VCC pin. Activation sequence Enable (true: active low) */
- bool simpres; /* high: active */
- bool led; /* high: active */
- bool interrupt; /* high: active */
- enum ncn8025_sim_clkdiv clkdiv; /* raw 2bit value */
- enum ncn8025_sim_voltage vsel; /* raw 2bit value */
+ bool rstin; /* Reset signal (true: asserted low) */
+ bool cmdvcc; /* Command VCC pin. Activation sequence Enable (true: active low) */
+ bool simpres; /* high: active */
+ bool led; /* high: active */
+ bool interrupt; /* high: active */
+ enum ncn8025_sim_clkdiv clkdiv; /* raw 2bit value */
+ enum ncn8025_sim_voltage vsel; /* raw 2bit value */
};
int ncn8025_set(uint8_t slot, const struct ncn8025_settings *set);
diff --git a/sysmoOCTSIM/octsim_i2c.c b/sysmoOCTSIM/octsim_i2c.c
index 5b8a30a..7627602 100644
--- a/sysmoOCTSIM/octsim_i2c.c
+++ b/sysmoOCTSIM/octsim_i2c.c
@@ -3,7 +3,7 @@
/* FIXME: This somehow ends up with measured 125 kHz SCL speed ?!? We should probably
* switch away from using delay_us() and instead use some hardware timer? */
-#define I2C_DELAY_US 1
+#define I2C_DELAY_US 1
#ifndef SDA1
/* We should define those pins in Atmel START. Until they are, define them here */
diff --git a/sysmoOCTSIM/replace.h b/sysmoOCTSIM/replace.h
index 711f3a5..149788c 100644
--- a/sysmoOCTSIM/replace.h
+++ b/sysmoOCTSIM/replace.h
@@ -12,11 +12,11 @@
#endif
#ifndef MIN
-#define MIN(a,b) ((a)<(b)?(a):(b))
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
#ifndef MAX
-#define MAX(a,b) ((a)>(b)?(a):(b))
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
#define TALLOC_BUILD_VERSION_MAJOR 2
diff --git a/sysmoOCTSIM/talloc.c b/sysmoOCTSIM/talloc.c
index 918cf42..022ef5c 100644
--- a/sysmoOCTSIM/talloc.c
+++ b/sysmoOCTSIM/talloc.c
@@ -52,7 +52,7 @@
/* Special macros that are no-ops except when run under Valgrind on
* x86. They've moved a little bit from valgrind 1.0.4 to 1.9.4 */
#ifdef HAVE_VALGRIND_MEMCHECK_H
- /* memcheck.h includes valgrind.h */
+/* memcheck.h includes valgrind.h */
#include <valgrind/memcheck.h>
#elif defined(HAVE_VALGRIND_H)
#include <valgrind.h>
@@ -62,13 +62,12 @@
code that might not cope */
#define ALWAYS_REALLOC 0
-
#define MAX_TALLOC_SIZE 0x10000000
#define TALLOC_FLAG_FREE 0x01
#define TALLOC_FLAG_LOOP 0x02
-#define TALLOC_FLAG_POOL 0x04 /* This is a talloc pool */
-#define TALLOC_FLAG_POOLMEM 0x08 /* This is allocated in a pool */
+#define TALLOC_FLAG_POOL 0x04 /* This is a talloc pool */
+#define TALLOC_FLAG_POOLMEM 0x08 /* This is allocated in a pool */
/*
* Bits above this are random, used to make it harder to fake talloc
@@ -79,12 +78,11 @@
#define TALLOC_MAGIC_REFERENCE ((const char *)1)
#define TALLOC_MAGIC_BASE 0xe814ec70
-#define TALLOC_MAGIC_NON_RANDOM ( \
- ~TALLOC_FLAG_MASK & ( \
- TALLOC_MAGIC_BASE + \
- (TALLOC_BUILD_VERSION_MAJOR << 24) + \
- (TALLOC_BUILD_VERSION_MINOR << 16) + \
- (TALLOC_BUILD_VERSION_RELEASE << 8)))
+#define TALLOC_MAGIC_NON_RANDOM ( \
+ ~TALLOC_FLAG_MASK & (TALLOC_MAGIC_BASE + \
+ (TALLOC_BUILD_VERSION_MAJOR << 24) + \
+ (TALLOC_BUILD_VERSION_MINOR << 16) + \
+ (TALLOC_BUILD_VERSION_RELEASE << 8)))
static unsigned int talloc_magic = TALLOC_MAGIC_NON_RANDOM;
/* by default we abort when given a bad pointer (such as when talloc_free() is called
@@ -95,9 +93,9 @@
#ifndef discard_const_p
#if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T)
-# define discard_const_p(type, ptr) ((type *)((intptr_t)(ptr)))
+#define discard_const_p(type, ptr) ((type *)((intptr_t)(ptr)))
#else
-# define discard_const_p(type, ptr) ((type *)(ptr))
+#define discard_const_p(type, ptr) ((type *)(ptr))
#endif
#endif
@@ -106,7 +104,7 @@
/* the strange !! is to ensure that __builtin_expect() takes either 0 or 1
as its first argument */
#ifndef likely
-#define likely(x) __builtin_expect(!!(x), 1)
+#define likely(x) __builtin_expect(!!(x), 1)
#endif
#ifndef unlikely
#define unlikely(x) __builtin_expect(!!(x), 0)
@@ -146,98 +144,117 @@
* do not wipe the header, to allow the
* double-free logic to still work
*/
-#define TC_INVALIDATE_FULL_FILL_CHUNK(_tc) do { \
- if (unlikely(talloc_fill.enabled)) { \
- size_t _flen = (_tc)->size; \
- char *_fptr = (char *)TC_PTR_FROM_CHUNK(_tc); \
- memset(_fptr, talloc_fill.fill_value, _flen); \
- } \
-} while (0)
+#define TC_INVALIDATE_FULL_FILL_CHUNK(_tc) \
+ do { \
+ if (unlikely(talloc_fill.enabled)) { \
+ size_t _flen = (_tc)->size; \
+ char *_fptr = (char *)TC_PTR_FROM_CHUNK(_tc); \
+ memset(_fptr, talloc_fill.fill_value, _flen); \
+ } \
+ } while (0)
#if defined(DEVELOPER) && defined(VALGRIND_MAKE_MEM_NOACCESS)
/* Mark the whole chunk as not accessable */
-#define TC_INVALIDATE_FULL_VALGRIND_CHUNK(_tc) do { \
- size_t _flen = TC_HDR_SIZE + (_tc)->size; \
- char *_fptr = (char *)(_tc); \
- VALGRIND_MAKE_MEM_NOACCESS(_fptr, _flen); \
-} while(0)
+#define TC_INVALIDATE_FULL_VALGRIND_CHUNK(_tc) \
+ do { \
+ size_t _flen = TC_HDR_SIZE + (_tc)->size; \
+ char *_fptr = (char *)(_tc); \
+ VALGRIND_MAKE_MEM_NOACCESS(_fptr, _flen); \
+ } while (0)
#else
-#define TC_INVALIDATE_FULL_VALGRIND_CHUNK(_tc) do { } while (0)
+#define TC_INVALIDATE_FULL_VALGRIND_CHUNK(_tc) \
+ do { \
+ } while (0)
#endif
-#define TC_INVALIDATE_FULL_CHUNK(_tc) do { \
- TC_INVALIDATE_FULL_FILL_CHUNK(_tc); \
- TC_INVALIDATE_FULL_VALGRIND_CHUNK(_tc); \
-} while (0)
+#define TC_INVALIDATE_FULL_CHUNK(_tc) \
+ do { \
+ TC_INVALIDATE_FULL_FILL_CHUNK(_tc); \
+ TC_INVALIDATE_FULL_VALGRIND_CHUNK(_tc); \
+ } while (0)
-#define TC_INVALIDATE_SHRINK_FILL_CHUNK(_tc, _new_size) do { \
- if (unlikely(talloc_fill.enabled)) { \
- size_t _flen = (_tc)->size - (_new_size); \
- char *_fptr = (char *)TC_PTR_FROM_CHUNK(_tc); \
- _fptr += (_new_size); \
- memset(_fptr, talloc_fill.fill_value, _flen); \
- } \
-} while (0)
+#define TC_INVALIDATE_SHRINK_FILL_CHUNK(_tc, _new_size) \
+ do { \
+ if (unlikely(talloc_fill.enabled)) { \
+ size_t _flen = (_tc)->size - (_new_size); \
+ char *_fptr = (char *)TC_PTR_FROM_CHUNK(_tc); \
+ _fptr += (_new_size); \
+ memset(_fptr, talloc_fill.fill_value, _flen); \
+ } \
+ } while (0)
#if defined(DEVELOPER) && defined(VALGRIND_MAKE_MEM_NOACCESS)
/* Mark the unused bytes not accessable */
-#define TC_INVALIDATE_SHRINK_VALGRIND_CHUNK(_tc, _new_size) do { \
- size_t _flen = (_tc)->size - (_new_size); \
- char *_fptr = (char *)TC_PTR_FROM_CHUNK(_tc); \
- _fptr += (_new_size); \
- VALGRIND_MAKE_MEM_NOACCESS(_fptr, _flen); \
-} while (0)
+#define TC_INVALIDATE_SHRINK_VALGRIND_CHUNK(_tc, _new_size) \
+ do { \
+ size_t _flen = (_tc)->size - (_new_size); \
+ char *_fptr = (char *)TC_PTR_FROM_CHUNK(_tc); \
+ _fptr += (_new_size); \
+ VALGRIND_MAKE_MEM_NOACCESS(_fptr, _flen); \
+ } while (0)
#else
-#define TC_INVALIDATE_SHRINK_VALGRIND_CHUNK(_tc, _new_size) do { } while (0)
+#define TC_INVALIDATE_SHRINK_VALGRIND_CHUNK(_tc, _new_size) \
+ do { \
+ } while (0)
#endif
-#define TC_INVALIDATE_SHRINK_CHUNK(_tc, _new_size) do { \
- TC_INVALIDATE_SHRINK_FILL_CHUNK(_tc, _new_size); \
- TC_INVALIDATE_SHRINK_VALGRIND_CHUNK(_tc, _new_size); \
-} while (0)
+#define TC_INVALIDATE_SHRINK_CHUNK(_tc, _new_size) \
+ do { \
+ TC_INVALIDATE_SHRINK_FILL_CHUNK(_tc, _new_size); \
+ TC_INVALIDATE_SHRINK_VALGRIND_CHUNK(_tc, _new_size); \
+ } while (0)
-#define TC_UNDEFINE_SHRINK_FILL_CHUNK(_tc, _new_size) do { \
- if (unlikely(talloc_fill.enabled)) { \
- size_t _flen = (_tc)->size - (_new_size); \
- char *_fptr = (char *)TC_PTR_FROM_CHUNK(_tc); \
- _fptr += (_new_size); \
- memset(_fptr, talloc_fill.fill_value, _flen); \
- } \
-} while (0)
+#define TC_UNDEFINE_SHRINK_FILL_CHUNK(_tc, _new_size) \
+ do { \
+ if (unlikely(talloc_fill.enabled)) { \
+ size_t _flen = (_tc)->size - (_new_size); \
+ char *_fptr = (char *)TC_PTR_FROM_CHUNK(_tc); \
+ _fptr += (_new_size); \
+ memset(_fptr, talloc_fill.fill_value, _flen); \
+ } \
+ } while (0)
#if defined(DEVELOPER) && defined(VALGRIND_MAKE_MEM_UNDEFINED)
/* Mark the unused bytes as undefined */
-#define TC_UNDEFINE_SHRINK_VALGRIND_CHUNK(_tc, _new_size) do { \
- size_t _flen = (_tc)->size - (_new_size); \
- char *_fptr = (char *)TC_PTR_FROM_CHUNK(_tc); \
- _fptr += (_new_size); \
- VALGRIND_MAKE_MEM_UNDEFINED(_fptr, _flen); \
-} while (0)
+#define TC_UNDEFINE_SHRINK_VALGRIND_CHUNK(_tc, _new_size) \
+ do { \
+ size_t _flen = (_tc)->size - (_new_size); \
+ char *_fptr = (char *)TC_PTR_FROM_CHUNK(_tc); \
+ _fptr += (_new_size); \
+ VALGRIND_MAKE_MEM_UNDEFINED(_fptr, _flen); \
+ } while (0)
#else
-#define TC_UNDEFINE_SHRINK_VALGRIND_CHUNK(_tc, _new_size) do { } while (0)
+#define TC_UNDEFINE_SHRINK_VALGRIND_CHUNK(_tc, _new_size) \
+ do { \
+ } while (0)
#endif
-#define TC_UNDEFINE_SHRINK_CHUNK(_tc, _new_size) do { \
- TC_UNDEFINE_SHRINK_FILL_CHUNK(_tc, _new_size); \
- TC_UNDEFINE_SHRINK_VALGRIND_CHUNK(_tc, _new_size); \
-} while (0)
+#define TC_UNDEFINE_SHRINK_CHUNK(_tc, _new_size) \
+ do { \
+ TC_UNDEFINE_SHRINK_FILL_CHUNK(_tc, _new_size); \
+ TC_UNDEFINE_SHRINK_VALGRIND_CHUNK(_tc, _new_size); \
+ } while (0)
#if defined(DEVELOPER) && defined(VALGRIND_MAKE_MEM_UNDEFINED)
/* Mark the new bytes as undefined */
-#define TC_UNDEFINE_GROW_VALGRIND_CHUNK(_tc, _new_size) do { \
- size_t _old_used = TC_HDR_SIZE + (_tc)->size; \
- size_t _new_used = TC_HDR_SIZE + (_new_size); \
- size_t _flen = _new_used - _old_used; \
- char *_fptr = _old_used + (char *)(_tc); \
- VALGRIND_MAKE_MEM_UNDEFINED(_fptr, _flen); \
-} while (0)
+#define TC_UNDEFINE_GROW_VALGRIND_CHUNK(_tc, _new_size) \
+ do { \
+ size_t _old_used = TC_HDR_SIZE + (_tc)->size; \
+ size_t _new_used = TC_HDR_SIZE + (_new_size); \
+ size_t _flen = _new_used - _old_used; \
+ char *_fptr = _old_used + (char *)(_tc); \
+ VALGRIND_MAKE_MEM_UNDEFINED(_fptr, _flen); \
+ } while (0)
#else
-#define TC_UNDEFINE_GROW_VALGRIND_CHUNK(_tc, _new_size) do { } while (0)
+#define TC_UNDEFINE_GROW_VALGRIND_CHUNK(_tc, _new_size) \
+ do { \
+ } while (0)
#endif
-#define TC_UNDEFINE_GROW_CHUNK(_tc, _new_size) do { \
- TC_UNDEFINE_GROW_VALGRIND_CHUNK(_tc, _new_size); \
-} while (0)
+#define TC_UNDEFINE_GROW_CHUNK(_tc, _new_size) \
+ do { \
+ TC_UNDEFINE_GROW_VALGRIND_CHUNK(_tc, _new_size); \
+ } while (0)
struct talloc_reference_handle {
struct talloc_reference_handle *next, *prev;
@@ -254,16 +271,16 @@
static inline bool talloc_memlimit_check(struct talloc_memlimit *limit, size_t size);
static inline void talloc_memlimit_grow(struct talloc_memlimit *limit,
- size_t size);
+ size_t size);
static inline void talloc_memlimit_shrink(struct talloc_memlimit *limit,
- size_t size);
+ size_t size);
static inline void tc_memlimit_update_on_free(struct talloc_chunk *tc);
static inline void _tc_set_name_const(struct talloc_chunk *tc,
- const char *name);
+ const char *name);
static struct talloc_chunk *_vasprintf_tc(const void *t,
- const char *fmt,
- va_list ap);
+ const char *fmt,
+ va_list ap);
typedef int (*talloc_destructor_t)(void *);
@@ -322,9 +339,9 @@
};
/* 16 byte alignment seems to keep everyone happy */
-#define TC_ALIGN16(s) (((s)+15)&~15)
+#define TC_ALIGN16(s) (((s) + 15) & ~15)
#define TC_HDR_SIZE TC_ALIGN16(sizeof(struct talloc_chunk))
-#define TC_PTR_FROM_CHUNK(tc) ((void *)(TC_HDR_SIZE + (char*)tc))
+#define TC_PTR_FROM_CHUNK(tc) ((void *)(TC_HDR_SIZE + (char *)tc))
_PUBLIC_ int talloc_version_major(void)
{
@@ -342,7 +359,7 @@
}
static inline void _talloc_chunk_set_free(struct talloc_chunk *tc,
- const char *location)
+ const char *location)
{
/*
* Mark this memory as free, and also over-stamp the talloc
@@ -353,8 +370,7 @@
* attacker to prepare a valid header and so run a destructor.
*
*/
- tc->flags = TALLOC_MAGIC_NON_RANDOM | TALLOC_FLAG_FREE
- | (tc->flags & TALLOC_FLAG_MASK);
+ tc->flags = TALLOC_MAGIC_NON_RANDOM | TALLOC_FLAG_FREE | (tc->flags & TALLOC_FLAG_MASK);
/* we mark the freed memory with where we called the free
* from. This means on a double free error we can report where
@@ -380,7 +396,7 @@
*/
tc->flags = talloc_magic |
- ((tc->flags & TALLOC_FLAG_MASK) & ~TALLOC_FLAG_FREE);
+ ((tc->flags & TALLOC_FLAG_MASK) & ~TALLOC_FLAG_FREE);
}
static void (*talloc_log_fn)(const char *message);
@@ -401,7 +417,7 @@
* Use the kernel-provided random values used for
* ASLR. This won't change per-exec, which is ideal for us
*/
- p = (uint8_t *) getauxval(AT_RANDOM);
+ p = (uint8_t *)getauxval(AT_RANDOM);
if (p) {
/*
* We get 16 bytes from getauxval. By calling rand(),
@@ -461,7 +477,7 @@
done = true;
}
-static void talloc_log(const char *fmt, ...) PRINTF_ATTRIBUTE(1,2);
+static void talloc_log(const char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
static void talloc_log(const char *fmt, ...)
{
va_list ap;
@@ -523,8 +539,7 @@
const char *pp = (const char *)ptr;
struct talloc_chunk *tc = discard_const_p(struct talloc_chunk, pp - TC_HDR_SIZE);
if (unlikely((tc->flags & (TALLOC_FLAG_FREE | ~TALLOC_FLAG_MASK)) != talloc_magic)) {
- if ((tc->flags & (TALLOC_FLAG_FREE | ~TALLOC_FLAG_MASK))
- == (TALLOC_MAGIC_NON_RANDOM | TALLOC_FLAG_FREE)) {
+ if ((tc->flags & (TALLOC_FLAG_FREE | ~TALLOC_FLAG_MASK)) == (TALLOC_MAGIC_NON_RANDOM | TALLOC_FLAG_FREE)) {
talloc_log("talloc: access after free error - first free may be at %s\r\n", tc->name);
talloc_abort_access_after_free();
return NULL;
@@ -537,32 +552,35 @@
}
/* hook into the front of the list */
-#define _TLIST_ADD(list, p) \
-do { \
- if (!(list)) { \
- (list) = (p); \
- (p)->next = (p)->prev = NULL; \
- } else { \
- (list)->prev = (p); \
- (p)->next = (list); \
- (p)->prev = NULL; \
- (list) = (p); \
- }\
-} while (0)
+#define _TLIST_ADD(list, p) \
+ do { \
+ if (!(list)) { \
+ (list) = (p); \
+ (p)->next = (p)->prev = NULL; \
+ } else { \
+ (list)->prev = (p); \
+ (p)->next = (list); \
+ (p)->prev = NULL; \
+ (list) = (p); \
+ } \
+ } while (0)
/* remove an element from a list - element doesn't have to be in list. */
-#define _TLIST_REMOVE(list, p) \
-do { \
- if ((p) == (list)) { \
- (list) = (p)->next; \
- if (list) (list)->prev = NULL; \
- } else { \
- if ((p)->prev) (p)->prev->next = (p)->next; \
- if ((p)->next) (p)->next->prev = (p)->prev; \
- } \
- if ((p) && ((p) != (list))) (p)->next = (p)->prev = NULL; \
-} while (0)
-
+#define _TLIST_REMOVE(list, p) \
+ do { \
+ if ((p) == (list)) { \
+ (list) = (p)->next; \
+ if (list) \
+ (list)->prev = NULL; \
+ } else { \
+ if ((p)->prev) \
+ (p)->prev->next = (p)->next; \
+ if ((p)->next) \
+ (p)->next->prev = (p)->prev; \
+ } \
+ if ((p) && ((p) != (list))) \
+ (p)->next = (p)->prev = NULL; \
+ } while (0)
/*
return the parent chunk of a pointer
@@ -576,7 +594,8 @@
}
tc = talloc_chunk_from_ptr(ptr);
- while (tc->prev) tc=tc->prev;
+ while (tc->prev)
+ tc = tc->prev;
return tc->parent;
}
@@ -584,7 +603,7 @@
_PUBLIC_ void *talloc_parent(const void *ptr)
{
struct talloc_chunk *tc = talloc_parent_chunk(ptr);
- return tc? TC_PTR_FROM_CHUNK(tc) : NULL;
+ return tc ? TC_PTR_FROM_CHUNK(tc) : NULL;
}
/*
@@ -593,7 +612,7 @@
_PUBLIC_ const char *talloc_parent_name(const void *ptr)
{
struct talloc_chunk *tc = talloc_parent_chunk(ptr);
- return tc? tc->name : NULL;
+ return tc ? tc->name : NULL;
}
/*
@@ -669,7 +688,7 @@
*/
static inline struct talloc_chunk *tc_alloc_pool(struct talloc_chunk *parent,
- size_t size, size_t prefix_len)
+ size_t size, size_t prefix_len)
{
struct talloc_pool_hdr *pool_hdr = NULL;
size_t space_left;
@@ -682,8 +701,7 @@
if (parent->flags & TALLOC_FLAG_POOL) {
pool_hdr = talloc_pool_from_chunk(parent);
- }
- else if (parent->flags & TALLOC_FLAG_POOLMEM) {
+ } else if (parent->flags & TALLOC_FLAG_POOLMEM) {
pool_hdr = parent->pool;
}
@@ -722,9 +740,9 @@
Allocate a bit of memory as a child of an existing pointer
*/
static inline void *__talloc_with_prefix(const void *context,
- size_t size,
- size_t prefix_len,
- struct talloc_chunk **tc_ret)
+ size_t size,
+ size_t prefix_len,
+ struct talloc_chunk **tc_ret)
{
struct talloc_chunk *tc = NULL;
struct talloc_memlimit *limit = NULL;
@@ -732,7 +750,7 @@
struct talloc_chunk *parent = NULL;
// do not allocate while handling interrupts!
- OSMO_ASSERT( !(SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) )
+ OSMO_ASSERT(!(SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk))
if (unlikely(context == NULL)) {
context = null_context;
@@ -753,7 +771,7 @@
limit = parent->limit;
}
- tc = tc_alloc_pool(parent, TC_HDR_SIZE+size, prefix_len);
+ tc = tc_alloc_pool(parent, TC_HDR_SIZE + size, prefix_len);
}
if (tc == NULL) {
@@ -773,7 +791,7 @@
}
tc = (struct talloc_chunk *)(ptr + prefix_len);
tc->flags = talloc_magic;
- tc->pool = NULL;
+ tc->pool = NULL;
talloc_memlimit_grow(limit, total_len);
}
@@ -805,8 +823,8 @@
}
static inline void *__talloc(const void *context,
- size_t size,
- struct talloc_chunk **tc)
+ size_t size,
+ struct talloc_chunk **tc)
{
return __talloc_with_prefix(context, size, 0, tc);
}
@@ -872,7 +890,7 @@
if (num_subobjects == UINT_MAX) {
goto overflow;
}
- num_subobjects += 1; /* the object body itself */
+ num_subobjects += 1; /* the object body itself */
/*
* Alignment can increase the pool size by at most 15 bytes per object
@@ -952,7 +970,7 @@
true string constant
*/
static inline void _tc_set_name_const(struct talloc_chunk *tc,
- const char *name)
+ const char *name)
{
tc->name = name;
}
@@ -988,13 +1006,15 @@
{
struct talloc_chunk *tc;
struct talloc_reference_handle *handle;
- if (unlikely(ptr == NULL)) return NULL;
+ if (unlikely(ptr == NULL))
+ return NULL;
tc = talloc_chunk_from_ptr(ptr);
handle = (struct talloc_reference_handle *)_talloc_named_const(context,
- sizeof(struct talloc_reference_handle),
- TALLOC_MAGIC_REFERENCE);
- if (unlikely(handle == NULL)) return NULL;
+ sizeof(struct talloc_reference_handle),
+ TALLOC_MAGIC_REFERENCE);
+ if (unlikely(handle == NULL))
+ return NULL;
/* note that we hang the destructor off the handle, not the
main context as that allows the caller to still setup their
@@ -1009,7 +1029,7 @@
static void *_talloc_steal_internal(const void *new_ctx, const void *ptr);
static inline void _tc_free_poolmem(struct talloc_chunk *tc,
- const char *location)
+ const char *location)
{
struct talloc_pool_hdr *pool;
struct talloc_chunk *pool_tc;
@@ -1030,8 +1050,7 @@
pool->object_count--;
- if (unlikely(pool->object_count == 1
- && !(pool_tc->flags & TALLOC_FLAG_FREE))) {
+ if (unlikely(pool->object_count == 1 && !(pool_tc->flags & TALLOC_FLAG_FREE))) {
/*
* if there is just one object left in the pool
* and pool->flags does not have TALLOC_FLAG_FREE,
@@ -1085,8 +1104,8 @@
}
static inline void _tc_free_children_internal(struct talloc_chunk *tc,
- void *ptr,
- const char *location);
+ void *ptr,
+ const char *location);
static inline int _talloc_free_internal(void *ptr, const char *location);
@@ -1094,7 +1113,7 @@
internal free call that takes a struct talloc_chunk *.
*/
static inline int _tc_free_internal(struct talloc_chunk *tc,
- const char *location)
+ const char *location)
{
void *ptr_to_free;
void *ptr = TC_PTR_FROM_CHUNK(tc);
@@ -1160,8 +1179,10 @@
tc->parent->child->parent = tc->parent;
}
} else {
- if (tc->prev) tc->prev->next = tc->next;
- if (tc->next) tc->next->prev = tc->prev;
+ if (tc->prev)
+ tc->prev->next = tc->next;
+ if (tc->next)
+ tc->next->prev = tc->prev;
tc->prev = tc->next = NULL;
}
@@ -1235,8 +1256,8 @@
}
static inline size_t _talloc_total_limit_size(const void *ptr,
- struct talloc_memlimit *old_limit,
- struct talloc_memlimit *new_limit);
+ struct talloc_memlimit *old_limit,
+ struct talloc_memlimit *new_limit);
/*
move a lump of memory from one talloc context to another return the
@@ -1259,7 +1280,6 @@
tc = talloc_chunk_from_ptr(ptr);
if (tc->limit != NULL) {
-
ctx_size = _talloc_total_limit_size(ptr, NULL, NULL);
/* Decrement the memory limit from the source .. */
@@ -1279,8 +1299,10 @@
tc->parent->child->parent = tc->parent;
}
} else {
- if (tc->prev) tc->prev->next = tc->next;
- if (tc->next) tc->next->prev = tc->prev;
+ if (tc->prev)
+ tc->prev->next = tc->next;
+ if (tc->next)
+ tc->next->prev = tc->prev;
}
tc->parent = tc->next = tc->prev = NULL;
@@ -1299,13 +1321,16 @@
tc->parent->child->parent = tc->parent;
}
} else {
- if (tc->prev) tc->prev->next = tc->next;
- if (tc->next) tc->next->prev = tc->prev;
+ if (tc->prev)
+ tc->prev->next = tc->next;
+ if (tc->next)
+ tc->next->prev = tc->prev;
tc->prev = tc->next = NULL;
}
tc->parent = new_tc;
- if (new_tc->child) new_tc->child->parent = NULL;
+ if (new_tc->child)
+ new_tc->child->parent = NULL;
_TLIST_ADD(new_tc->child, tc);
if (tc->limit || new_tc->limit) {
@@ -1341,7 +1366,7 @@
talloc_log("WARNING: talloc_steal with references at %s\r\n",
location);
- for (h=tc->refs; h; h=h->next) {
+ for (h = tc->refs; h; h = h->next) {
talloc_log("\treference at %s\r\n",
h->location);
}
@@ -1379,7 +1404,7 @@
}
tc = talloc_chunk_from_ptr(ptr);
- for (h=tc->refs;h;h=h->next) {
+ for (h = tc->refs; h; h = h->next) {
if (talloc_parent(h) == old_parent) {
if (_talloc_steal_internal(new_parent, h) != h) {
return NULL;
@@ -1406,10 +1431,11 @@
context = null_context;
}
- for (h=tc->refs;h;h=h->next) {
+ for (h = tc->refs; h; h = h->next) {
struct talloc_chunk *p = talloc_parent_chunk(h);
if (p == NULL) {
- if (context == NULL) break;
+ if (context == NULL)
+ break;
} else if (TC_PTR_FROM_CHUNK(p) == context) {
break;
}
@@ -1477,16 +1503,16 @@
add a name to an existing pointer - va_list version
*/
static inline const char *tc_set_name_v(struct talloc_chunk *tc,
- const char *fmt,
- va_list ap) PRINTF_ATTRIBUTE(2,0);
+ const char *fmt,
+ va_list ap) PRINTF_ATTRIBUTE(2, 0);
static inline const char *tc_set_name_v(struct talloc_chunk *tc,
- const char *fmt,
- va_list ap)
+ const char *fmt,
+ va_list ap)
{
struct talloc_chunk *name_tc = _vasprintf_tc(TC_PTR_FROM_CHUNK(tc),
- fmt,
- ap);
+ fmt,
+ ap);
if (likely(name_tc)) {
tc->name = TC_PTR_FROM_CHUNK(name_tc);
_tc_set_name_const(name_tc, ".name");
@@ -1510,7 +1536,6 @@
return name;
}
-
/*
create a named talloc pointer. Any talloc pointer can be named, and
talloc_named() operates just like talloc() except that it allows you
@@ -1524,7 +1549,8 @@
struct talloc_chunk *tc;
ptr = __talloc(context, size, &tc);
- if (unlikely(ptr == NULL)) return NULL;
+ if (unlikely(ptr == NULL))
+ return NULL;
va_start(ap, fmt);
name = tc_set_name_v(tc, fmt, ap);
@@ -1565,7 +1591,8 @@
_PUBLIC_ void *talloc_check_name(const void *ptr, const char *name)
{
const char *pname;
- if (unlikely(ptr == NULL)) return NULL;
+ if (unlikely(ptr == NULL))
+ return NULL;
pname = __talloc_get_name(ptr);
if (likely(pname == name || strcmp(pname, name) == 0)) {
return discard_const_p(void, ptr);
@@ -1574,15 +1601,15 @@
}
static void talloc_abort_type_mismatch(const char *location,
- const char *name,
- const char *expected)
+ const char *name,
+ const char *expected)
{
const char *reason;
reason = talloc_asprintf(NULL,
"%s: Type mismatch: name[%s] expected[%s]",
location,
- name?name:"NULL",
+ name ? name : "NULL",
expected);
if (!reason) {
reason = "Type mismatch";
@@ -1620,7 +1647,8 @@
struct talloc_chunk *tc;
ptr = __talloc(NULL, 0, &tc);
- if (unlikely(ptr == NULL)) return NULL;
+ if (unlikely(ptr == NULL))
+ return NULL;
va_start(ap, fmt);
name = tc_set_name_v(tc, fmt, ap);
@@ -1635,8 +1663,8 @@
}
static inline void _tc_free_children_internal(struct talloc_chunk *tc,
- void *ptr,
- const char *location)
+ void *ptr,
+ const char *location)
{
while (tc->child) {
/* we need to work out who will own an abandoned child
@@ -1648,7 +1676,8 @@
const void *new_parent = null_context;
if (unlikely(tc->child->refs)) {
struct talloc_chunk *p = talloc_parent_chunk(tc->child->refs);
- if (p) new_parent = TC_PTR_FROM_CHUNK(p);
+ if (p)
+ new_parent = TC_PTR_FROM_CHUNK(p);
}
if (unlikely(_tc_free_internal(tc->child, location) == -1)) {
if (talloc_parent_chunk(child) != tc) {
@@ -1660,7 +1689,8 @@
}
if (new_parent == null_context) {
struct talloc_chunk *p = talloc_parent_chunk(ptr);
- if (p) new_parent = TC_PTR_FROM_CHUNK(p);
+ if (p)
+ new_parent = TC_PTR_FROM_CHUNK(p);
}
_talloc_steal_internal(new_parent, child);
}
@@ -1686,7 +1716,8 @@
/* we do not want to free the context name if it is a child .. */
if (likely(tc->child)) {
for (tc_name = tc->child; tc_name; tc_name = tc_name->next) {
- if (tc->name == TC_PTR_FROM_CHUNK(tc_name)) break;
+ if (tc->name == TC_PTR_FROM_CHUNK(tc_name))
+ break;
}
if (tc_name) {
_TLIST_REMOVE(tc->child, tc_name);
@@ -1748,7 +1779,7 @@
struct talloc_chunk *tc;
// do not deallocate while handling interrupts!
- OSMO_ASSERT( !(SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) )
+ OSMO_ASSERT(!(SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk))
if (unlikely(ptr == NULL)) {
return -1;
@@ -1769,7 +1800,7 @@
talloc_log("ERROR: talloc_free with references at %s\r\n",
location);
- for (h=tc->refs; h; h=h->next) {
+ for (h = tc->refs; h; h = h->next) {
talloc_log("\treference at %s\r\n",
h->location);
}
@@ -1779,8 +1810,6 @@
return _talloc_free_internal(ptr, location);
}
-
-
/*
A talloc version of realloc. The context argument is only used if
ptr is NULL
@@ -1892,13 +1921,13 @@
pool_hdr->object_count--;
if (new_ptr == NULL) {
- new_ptr = malloc(TC_HDR_SIZE+size);
+ new_ptr = malloc(TC_HDR_SIZE + size);
malloced = true;
new_size = size;
}
if (new_ptr) {
- memcpy(new_ptr, tc, MIN(tc->size,size) + TC_HDR_SIZE);
+ memcpy(new_ptr, tc, MIN(tc->size, size) + TC_HDR_SIZE);
TC_INVALIDATE_FULL_CHUNK(tc);
}
} else {
@@ -1955,7 +1984,7 @@
* (which is why we use memmove, not
* memcpy below) hence the MIN.
*/
- size_t undef_len = MIN((((char *)tc) - ((char *)new_ptr)),old_used);
+ size_t undef_len = MIN((((char *)tc) - ((char *)new_ptr)), old_used);
VALGRIND_MAKE_MEM_UNDEFINED(new_ptr, undef_len);
}
#endif
@@ -2008,18 +2037,17 @@
new_ptr = tc_alloc_pool(tc, size + TC_HDR_SIZE, 0);
if (new_ptr == NULL) {
- new_ptr = malloc(TC_HDR_SIZE+size);
+ new_ptr = malloc(TC_HDR_SIZE + size);
malloced = true;
new_size = size;
}
if (new_ptr) {
- memcpy(new_ptr, tc, MIN(tc->size,size) + TC_HDR_SIZE);
+ memcpy(new_ptr, tc, MIN(tc->size, size) + TC_HDR_SIZE);
_tc_free_poolmem(tc, __location__ "_talloc_realloc");
}
- }
- else {
+ } else {
/* We're doing realloc here, so record the difference. */
old_size = tc->size;
new_size = size;
@@ -2081,7 +2109,7 @@
*/
_PUBLIC_ void *_talloc_move(const void *new_ctx, const void *_pptr)
{
- const void **pptr = discard_const_p(const void *,_pptr);
+ const void **pptr = discard_const_p(const void *, _pptr);
void *ret = talloc_steal(new_ctx, discard_const_p(void, *pptr));
(*pptr) = NULL;
return ret;
@@ -2094,9 +2122,9 @@
};
static inline size_t _talloc_total_mem_internal(const void *ptr,
- enum talloc_mem_count_type type,
- struct talloc_memlimit *old_limit,
- struct talloc_memlimit *new_limit)
+ enum talloc_mem_count_type type,
+ struct talloc_memlimit *old_limit,
+ struct talloc_memlimit *new_limit)
{
size_t total = 0;
struct talloc_chunk *c, *tc;
@@ -2160,11 +2188,10 @@
* remember to add in the prefix
* length.
*/
- struct talloc_pool_hdr *pool_hdr
- = talloc_pool_from_chunk(tc);
+ struct talloc_pool_hdr *pool_hdr = talloc_pool_from_chunk(tc);
total = pool_hdr->poolsize +
- TC_HDR_SIZE +
- TP_HDR_SIZE;
+ TC_HDR_SIZE +
+ TP_HDR_SIZE;
} else {
total = tc->size + TC_HDR_SIZE;
}
@@ -2207,7 +2234,7 @@
struct talloc_reference_handle *h;
size_t ret = 0;
- for (h=tc->refs;h;h=h->next) {
+ for (h = tc->refs; h; h = h->next) {
ret++;
}
return ret;
@@ -2217,18 +2244,19 @@
report on memory usage by all children of a pointer, giving a full tree view
*/
_PUBLIC_ void talloc_report_depth_cb(const void *ptr, int depth, int max_depth,
- void (*callback)(const void *ptr,
- int depth, int max_depth,
- int is_ref,
- void *private_data),
- void *private_data)
+ void (*callback)(const void *ptr,
+ int depth, int max_depth,
+ int is_ref,
+ void *private_data),
+ void *private_data)
{
struct talloc_chunk *c, *tc;
if (ptr == NULL) {
ptr = null_context;
}
- if (ptr == NULL) return;
+ if (ptr == NULL)
+ return;
tc = talloc_chunk_from_ptr(ptr);
@@ -2243,7 +2271,7 @@
}
tc->flags |= TALLOC_FLAG_LOOP;
- for (c=tc->child;c;c=c->next) {
+ for (c = tc->child; c; c = c->next) {
if (c->name == TALLOC_MAGIC_REFERENCE) {
struct talloc_reference_handle *h = (struct talloc_reference_handle *)TC_PTR_FROM_CHUNK(c);
callback(h->ptr, depth + 1, max_depth, 1, private_data);
@@ -2261,30 +2289,30 @@
FILE *f = (FILE *)_f;
if (is_ref) {
- fprintf(f, "%*sreference to: %s\r\n", depth*4, "", name);
+ fprintf(f, "%*sreference to: %s\r\n", depth * 4, "", name);
return;
}
tc = talloc_chunk_from_ptr(ptr);
if (tc->limit && tc->limit->parent == tc) {
fprintf(f, "%*s%-30s is a memlimit context"
- " (max_size = %lu bytes, cur_size = %lu bytes)\r\n",
- depth*4, "",
+ " (max_size = %lu bytes, cur_size = %lu bytes)\r\n",
+ depth * 4, "",
name,
(unsigned long)tc->limit->max_size,
(unsigned long)tc->limit->cur_size);
}
if (depth == 0) {
- fprintf(f,"%stalloc report on '%s' (total %6lu bytes in %3lu blocks)\r",
- (max_depth < 0 ? "full " :""), name,
+ fprintf(f, "%stalloc report on '%s' (total %6lu bytes in %3lu blocks)\r",
+ (max_depth < 0 ? "full " : ""), name,
(unsigned long)talloc_total_size(ptr),
(unsigned long)talloc_total_blocks(ptr));
return;
}
fprintf(f, "%*s%-30s contains %6lu bytes in %3lu blocks (ref %d) %p\r\n",
- depth*4, "",
+ depth * 4, "",
name,
(unsigned long)talloc_total_size(ptr),
(unsigned long)talloc_total_blocks(ptr),
@@ -2369,13 +2397,17 @@
context */
struct talloc_chunk *tc, *tc2;
tc = talloc_chunk_from_ptr(null_context);
- for (tc2 = tc->child; tc2; tc2=tc2->next) {
- if (tc2->parent == tc) tc2->parent = NULL;
- if (tc2->prev == tc) tc2->prev = NULL;
+ for (tc2 = tc->child; tc2; tc2 = tc2->next) {
+ if (tc2->parent == tc)
+ tc2->parent = NULL;
+ if (tc2->prev == tc)
+ tc2->prev = NULL;
}
- for (tc2 = tc->next; tc2; tc2=tc2->next) {
- if (tc2->parent == tc) tc2->parent = NULL;
- if (tc2->prev == tc) tc2->prev = NULL;
+ for (tc2 = tc->next; tc2; tc2 = tc2->next) {
+ if (tc2->parent == tc)
+ tc2->parent = NULL;
+ if (tc2->prev == tc)
+ tc2->prev = NULL;
}
tc->child = NULL;
tc->next = NULL;
@@ -2438,7 +2470,8 @@
struct talloc_chunk *tc;
ret = (char *)__talloc(t, len + 1, &tc);
- if (unlikely(!ret)) return NULL;
+ if (unlikely(!ret))
+ return NULL;
memcpy(ret, p, len);
ret[len] = 0;
@@ -2452,7 +2485,8 @@
*/
_PUBLIC_ char *talloc_strdup(const void *t, const char *p)
{
- if (unlikely(!p)) return NULL;
+ if (unlikely(!p))
+ return NULL;
return __talloc_strlendup(t, p, strlen(p));
}
@@ -2461,7 +2495,8 @@
*/
_PUBLIC_ char *talloc_strndup(const void *t, const char *p, size_t n)
{
- if (unlikely(!p)) return NULL;
+ if (unlikely(!p))
+ return NULL;
return __talloc_strlendup(t, p, strnlen(p, n));
}
@@ -2471,11 +2506,12 @@
char *ret;
ret = talloc_realloc(NULL, s, char, slen + alen + 1);
- if (unlikely(!ret)) return NULL;
+ if (unlikely(!ret))
+ return NULL;
/* append the string and the trailing \0 */
memcpy(&ret[slen], a, alen);
- ret[slen+alen] = 0;
+ ret[slen + alen] = 0;
_tc_set_name_const(talloc_chunk_from_ptr(ret), ret);
return ret;
@@ -2571,7 +2607,7 @@
static struct talloc_chunk *_vasprintf_tc(const void *t,
const char *fmt,
- va_list ap) PRINTF_ATTRIBUTE(2,0);
+ va_list ap) PRINTF_ATTRIBUTE(2, 0);
static struct talloc_chunk *_vasprintf_tc(const void *t,
const char *fmt,
@@ -2596,14 +2632,15 @@
return NULL;
}
- ret = (char *)__talloc(t, len+1, &tc);
- if (unlikely(!ret)) return NULL;
+ ret = (char *)__talloc(t, len + 1, &tc);
+ if (unlikely(!ret))
+ return NULL;
if (len < sizeof(buf)) {
- memcpy(ret, buf, len+1);
+ memcpy(ret, buf, len + 1);
} else {
va_copy(ap2, ap);
- vsnprintf(ret, len+1, fmt, ap2);
+ vsnprintf(ret, len + 1, fmt, ap2);
va_end(ap2);
}
@@ -2620,7 +2657,6 @@
return TC_PTR_FROM_CHUNK(tc);
}
-
/*
Perform string formatting, and return a pointer to newly allocated
memory holding the result, inside a memory pool.
@@ -2638,7 +2674,7 @@
static inline char *__talloc_vaslenprintf_append(char *s, size_t slen,
const char *fmt, va_list ap)
- PRINTF_ATTRIBUTE(3,0);
+ PRINTF_ATTRIBUTE(3, 0);
static inline char *__talloc_vaslenprintf_append(char *s, size_t slen,
const char *fmt, va_list ap)
@@ -2662,7 +2698,8 @@
}
s = talloc_realloc(NULL, s, char, slen + alen + 1);
- if (!s) return NULL;
+ if (!s)
+ return NULL;
va_copy(ap2, ap);
vsnprintf(s + slen, alen + 1, fmt, ap2);
@@ -2743,7 +2780,7 @@
*/
_PUBLIC_ void *_talloc_array(const void *ctx, size_t el_size, unsigned count, const char *name)
{
- if (count >= MAX_TALLOC_SIZE/el_size) {
+ if (count >= MAX_TALLOC_SIZE / el_size) {
return NULL;
}
return _talloc_named_const(ctx, el_size * count, name);
@@ -2754,7 +2791,7 @@
*/
_PUBLIC_ void *_talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const char *name)
{
- if (count >= MAX_TALLOC_SIZE/el_size) {
+ if (count >= MAX_TALLOC_SIZE / el_size) {
return NULL;
}
return _talloc_zero(ctx, el_size * count, name);
@@ -2765,7 +2802,7 @@
*/
_PUBLIC_ void *_talloc_realloc_array(const void *ctx, void *ptr, size_t el_size, unsigned count, const char *name)
{
- if (count >= MAX_TALLOC_SIZE/el_size) {
+ if (count >= MAX_TALLOC_SIZE / el_size) {
return NULL;
}
return _talloc_realloc(ctx, ptr, el_size * count, name);
@@ -2781,7 +2818,6 @@
return _talloc_realloc(context, ptr, size, NULL);
}
-
static int talloc_autofree_destructor(void *ptr)
{
autofree_context = NULL;
@@ -2831,7 +2867,8 @@
if (tc->name && strcmp(tc->name, name) == 0) {
return TC_PTR_FROM_CHUNK(tc);
}
- while (tc && tc->prev) tc = tc->prev;
+ while (tc && tc->prev)
+ tc = tc->prev;
if (tc) {
tc = tc->parent;
}
@@ -2855,7 +2892,8 @@
fprintf(file, "talloc parents of '%s'\r\n", __talloc_get_name(context));
while (tc) {
fprintf(file, "\t'%s'\r\n", __talloc_get_name(TC_PTR_FROM_CHUNK(tc)));
- while (tc && tc->prev) tc = tc->prev;
+ while (tc && tc->prev)
+ tc = tc->prev;
if (tc) {
tc = tc->parent;
}
@@ -2879,8 +2917,10 @@
if (depth <= 0) {
return 0;
}
- if (TC_PTR_FROM_CHUNK(tc) == ptr) return 1;
- while (tc && tc->prev) tc = tc->prev;
+ if (TC_PTR_FROM_CHUNK(tc) == ptr)
+ return 1;
+ while (tc && tc->prev)
+ tc = tc->prev;
if (tc) {
tc = tc->parent;
depth--;
@@ -2901,8 +2941,8 @@
return the total size of memory used by this context and all children
*/
static inline size_t _talloc_total_limit_size(const void *ptr,
- struct talloc_memlimit *old_limit,
- struct talloc_memlimit *new_limit)
+ struct talloc_memlimit *old_limit,
+ struct talloc_memlimit *new_limit)
{
return _talloc_total_mem_internal(ptr, TOTAL_MEM_LIMIT,
old_limit, new_limit);
@@ -2950,7 +2990,7 @@
* we need to subtract the memory used from the counters
*/
- limit_shrink_size = tc->size+TC_HDR_SIZE;
+ limit_shrink_size = tc->size + TC_HDR_SIZE;
/*
* If we're deallocating a pool, take into
@@ -2974,7 +3014,7 @@
Increase memory limit accounting after a malloc/realloc.
*/
static void talloc_memlimit_grow(struct talloc_memlimit *limit,
- size_t size)
+ size_t size)
{
struct talloc_memlimit *l;
@@ -2992,7 +3032,7 @@
Decrease memory limit accounting after a free/realloc.
*/
static void talloc_memlimit_shrink(struct talloc_memlimit *limit,
- size_t size)
+ size_t size)
{
struct talloc_memlimit *l;
diff --git a/sysmoOCTSIM/talloc.h b/sysmoOCTSIM/talloc.h
index 7372df1..7e5c42b 100644
--- a/sysmoOCTSIM/talloc.h
+++ b/sysmoOCTSIM/talloc.h
@@ -79,9 +79,9 @@
this uses a little trick to allow __LINE__ to be stringified
*/
#ifndef __location__
-#define __TALLOC_STRING_LINE1__(s) #s
-#define __TALLOC_STRING_LINE2__(s) __TALLOC_STRING_LINE1__(s)
-#define __TALLOC_STRING_LINE3__ __TALLOC_STRING_LINE2__(__LINE__)
+#define __TALLOC_STRING_LINE1__(s) #s
+#define __TALLOC_STRING_LINE2__(s) __TALLOC_STRING_LINE1__(s)
+#define __TALLOC_STRING_LINE3__ __TALLOC_STRING_LINE2__(__LINE__)
#define __location__ __FILE__ ":" __TALLOC_STRING_LINE3__
#endif
@@ -95,7 +95,7 @@
* the parameter containing the format, and a2 the index of the first
* argument. Note that some gcc 2.x versions don't handle this
* properly **/
-#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
+#define PRINTF_ATTRIBUTE(a1, a2) __attribute__((format(__printf__, a1, a2)))
#else
#define PRINTF_ATTRIBUTE(a1, a2)
#endif
@@ -158,7 +158,7 @@
*
* @see talloc_named()
*/
-void *talloc_init(const char *fmt, ...) PRINTF_ATTRIBUTE(1,2);
+void *talloc_init(const char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
#ifdef DOXYGEN
/**
@@ -342,11 +342,11 @@
if we have a recent gcc */
#if (__GNUC__ >= 3)
#define _TALLOC_TYPEOF(ptr) __typeof__(ptr)
-#define talloc_set_destructor(ptr, function) \
- do { \
- int (*_talloc_destructor_fn)(_TALLOC_TYPEOF(ptr)) = (function); \
+#define talloc_set_destructor(ptr, function) \
+ do { \
+ int (*_talloc_destructor_fn)(_TALLOC_TYPEOF(ptr)) = (function); \
_talloc_set_destructor((ptr), (int (*)(void *))_talloc_destructor_fn); \
- } while(0)
+ } while (0)
/* this extremely strange macro is to avoid some braindamaged warning
stupidity in gcc 4.1.x */
#define talloc_steal(ctx, ptr) ({ _TALLOC_TYPEOF(ptr) __talloc_steal_ret = (_TALLOC_TYPEOF(ptr))_talloc_steal_loc((ctx),(ptr), __location__); __talloc_steal_ret; })
@@ -354,7 +354,7 @@
#define talloc_set_destructor(ptr, function) \
_talloc_set_destructor((ptr), (int (*)(void *))(function))
#define _TALLOC_TYPEOF(ptr) void *
-#define talloc_steal(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_steal_loc((ctx),(ptr), __location__)
+#define talloc_steal(ctx, ptr) (_TALLOC_TYPEOF(ptr)) _talloc_steal_loc((ctx), (ptr), __location__)
#endif /* __GNUC__ >= 3 */
void _talloc_set_destructor(const void *ptr, int (*_destructor)(void *));
void *_talloc_steal_loc(const void *new_ctx, const void *ptr, const char *location);
@@ -390,7 +390,7 @@
* releasing the name. All of the memory is released when the ptr is freed
* using talloc_free().
*/
-const char *talloc_set_name(const void *ptr, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
+const char *talloc_set_name(const void *ptr, const char *fmt, ...) PRINTF_ATTRIBUTE(2, 3);
#ifdef DOXYGEN
/**
@@ -415,7 +415,7 @@
*/
void *talloc_move(const void *new_ctx, void **pptr);
#else
-#define talloc_move(ctx, pptr) (_TALLOC_TYPEOF(*(pptr)))_talloc_move((ctx),(void *)(pptr))
+#define talloc_move(ctx, pptr) (_TALLOC_TYPEOF(*(pptr))) _talloc_move((ctx), (void *)(pptr))
void *_talloc_move(const void *new_ctx, const void *pptr);
#endif
@@ -461,7 +461,7 @@
* @see talloc_set_name()
*/
void *talloc_named(const void *context, size_t size,
- const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
+ const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
/**
* @brief Basic routine to allocate a chunk of memory.
@@ -533,7 +533,7 @@
*/
void *talloc_ptrtype(const void *ctx, #type);
#else
-#define talloc_ptrtype(ctx, ptr) (_TALLOC_TYPEOF(ptr))talloc_size(ctx, sizeof(*(ptr)))
+#define talloc_ptrtype(ctx, ptr) (_TALLOC_TYPEOF(ptr)) talloc_size(ctx, sizeof(*(ptr)))
#endif
#ifdef DOXYGEN
@@ -878,12 +878,12 @@
unsigned num_subobjects,
size_t total_subobjects_size);
#else
-#define talloc_pooled_object(_ctx, _type, \
- _num_subobjects, \
- _total_subobjects_size) \
+#define talloc_pooled_object(_ctx, _type, \
+ _num_subobjects, \
+ _total_subobjects_size) \
(_type *)_talloc_pooled_object((_ctx), sizeof(_type), #_type, \
- (_num_subobjects), \
- (_total_subobjects_size))
+ (_num_subobjects), \
+ (_total_subobjects_size))
void *_talloc_pooled_object(const void *ctx,
size_t type_size,
const char *type_name,
@@ -900,7 +900,13 @@
*
* @param[in] ctx The chunk to be freed.
*/
-#define TALLOC_FREE(ctx) do { if (ctx != NULL) { talloc_free(ctx); ctx=NULL; } } while(0)
+#define TALLOC_FREE(ctx) \
+ do { \
+ if (ctx != NULL) { \
+ talloc_free(ctx); \
+ ctx = NULL; \
+ } \
+ } while (0)
/* @} ******************************************************************/
@@ -986,7 +992,7 @@
*/
void *talloc_reference(const void *ctx, const void *ptr);
#else
-#define talloc_reference(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_reference_loc((ctx),(ptr), __location__)
+#define talloc_reference(ctx, ptr) (_TALLOC_TYPEOF(ptr)) _talloc_reference_loc((ctx), (ptr), __location__)
void *_talloc_reference_loc(const void *context, const void *ptr, const char *location);
#endif
@@ -1191,7 +1197,7 @@
*/
void *talloc_array_ptrtype(const void *ctx, const void *ptr, unsigned count);
#else
-#define talloc_array_ptrtype(ctx, ptr, count) (_TALLOC_TYPEOF(ptr))talloc_array_size(ctx, sizeof(*(ptr)), count)
+#define talloc_array_ptrtype(ctx, ptr, count) (_TALLOC_TYPEOF(ptr)) talloc_array_size(ctx, sizeof(*(ptr)), count)
#endif
#ifdef DOXYGEN
@@ -1207,7 +1213,7 @@
*/
size_t talloc_array_length(const void *ctx);
#else
-#define talloc_array_length(ctx) (talloc_get_size(ctx)/sizeof(*ctx))
+#define talloc_array_length(ctx) (talloc_get_size(ctx) / sizeof(*ctx))
#endif
#ifdef DOXYGEN
@@ -1523,7 +1529,7 @@
*
* @return The formatted string, NULL on error.
*/
-char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2,0);
+char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2, 0);
/**
* @brief Format a string given a va_list and append it to the given destination
@@ -1539,7 +1545,7 @@
*
* @see talloc_vasprintf()
*/
-char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2,0);
+char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2, 0);
/**
* @brief Format a string given a va_list and append it to the given destination
@@ -1555,7 +1561,7 @@
*
* @see talloc_vasprintf()
*/
-char *talloc_vasprintf_append_buffer(char *s, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2,0);
+char *talloc_vasprintf_append_buffer(char *s, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2, 0);
/**
* @brief Format a string.
@@ -1577,7 +1583,7 @@
*
* @return The formatted string, NULL on error.
*/
-char *talloc_asprintf(const void *t, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
+char *talloc_asprintf(const void *t, const char *fmt, ...) PRINTF_ATTRIBUTE(2, 3);
/**
* @brief Append a formatted string to another string.
@@ -1603,7 +1609,7 @@
*
* @return The formatted string, NULL on error.
*/
-char *talloc_asprintf_append(char *s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
+char *talloc_asprintf_append(char *s, const char *fmt, ...) PRINTF_ATTRIBUTE(2, 3);
/**
* @brief Append a formatted string to another string.
@@ -1640,7 +1646,7 @@
* @see talloc_asprintf()
* @see talloc_asprintf_append()
*/
-char *talloc_asprintf_append_buffer(char *s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
+char *talloc_asprintf_append_buffer(char *s, const char *fmt, ...) PRINTF_ATTRIBUTE(2, 3);
/* @} ******************************************************************/
@@ -1920,7 +1926,7 @@
#define talloc_array_p(ctx, type, count) talloc_array(ctx, type, count)
#define talloc_realloc_p(ctx, p, type, count) talloc_realloc(ctx, p, type, count)
#define talloc_destroy(ctx) talloc_free(ctx)
-#define talloc_append_string(c, s, a) (s?talloc_strdup_append(s,a):talloc_strdup(c, a))
+#define talloc_append_string(c, s, a) (s ? talloc_strdup_append(s, a) : talloc_strdup(c, a))
#endif
#ifndef TALLOC_MAX_DEPTH
diff --git a/sysmoOCTSIM/usb_descriptors.c b/sysmoOCTSIM/usb_descriptors.c
index d3084cc..fadd076 100644
--- a/sysmoOCTSIM/usb_descriptors.c
+++ b/sysmoOCTSIM/usb_descriptors.c
@@ -24,8 +24,6 @@
#include "cdcdf_acm_desc.h"
#include "usb_descriptors.h"
-
-
const struct usb_desc_collection usb_fs_descs = {
.dev = {
.bLength = sizeof(struct usb_dev_desc),
@@ -49,9 +47,7 @@
#ifdef WITH_DEBUG_CDC
sizeof(usb_fs_descs.cdc) +
#endif
- sizeof(usb_fs_descs.ccid) +
- sizeof(usb_fs_descs.dfu_rt) +
- sizeof(usb_fs_descs.func_dfu),
+ sizeof(usb_fs_descs.ccid) + sizeof(usb_fs_descs.dfu_rt) + sizeof(usb_fs_descs.func_dfu),
#ifdef WITH_DEBUG_CDC
.bNumInterfaces = 4,
#else
@@ -190,7 +186,8 @@
.bMaxCCIDBusySlots = 8,
},
.ep = {
- { /* Bulk-OUT descriptor */
+ {
+ /* Bulk-OUT descriptor */
.bLength = sizeof(struct usb_ep_desc),
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = 0x02,
@@ -198,7 +195,8 @@
.wMaxPacketSize = 64,
.bInterval = 0,
},
- { /* Bulk-IN descriptor */
+ {
+ /* Bulk-IN descriptor */
.bLength = sizeof(struct usb_ep_desc),
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = 0x83,
@@ -206,7 +204,8 @@
.wMaxPacketSize = 64,
.bInterval = 0,
},
- { /* Interrupt dscriptor */
+ {
+ /* Interrupt dscriptor */
.bLength = sizeof(struct usb_ep_desc),
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = 0x84,
@@ -225,18 +224,208 @@
#if 0
CDCD_ACM_STR_DESCES
#else
- 4, 3, 0x09, 0x04,
- 50, 3, 's',0, 'y',0, 's',0, 'm',0, 'o',0, 'c',0, 'o',0, 'm',0, ' ',0, '-',0, ' ',0, 's',0, '.',0, 'f',0, '.',0, 'm',0, '.',0, 'c',0, '.',0, ' ',0, 'G',0, 'm',0, 'b',0, 'H',0,
- 24, 3, 's',0, 'y',0, 's',0, 'm',0, 'o',0, 'O',0, 'C',0, 'T',0, 'S',0, 'I',0, 'M',0,
- 4, 3, 'A', 0,
- 22, 3, 'd',0, 'e',0, 'b',0, 'u',0, 'g',0, ' ',0, 'U',0, 'A',0, 'R',0, 'T',0,
- 22, 3, 'd',0, 'e',0, 'b',0, 'u',0, 'g',0, ' ',0, 'U',0, 'A',0, 'R',0, 'T',0,
- 10, 3, 'C',0, 'C',0, 'I',0, 'D',0,
- 12, 3, 'F',0, 'I',0, 'X',0, 'M',0, 'E',0,
- 52, 3, 's',0, 'y',0, 's',0, 'm',0, 'o',0, 'O',0, 'C',0, 'T',0, 'S',0, 'I',0, 'M',0, ' ',0, 'D',0, 'F',0, 'U',0, ' ',0, '(',0, 'R',0, 'u',0, 'n',0, 't',0, 'i',0, 'm',0, 'e',0 ,')',0,
+ 4,
+ 3,
+ 0x09,
+ 0x04,
+ 50,
+ 3,
+ 's',
+ 0,
+ 'y',
+ 0,
+ 's',
+ 0,
+ 'm',
+ 0,
+ 'o',
+ 0,
+ 'c',
+ 0,
+ 'o',
+ 0,
+ 'm',
+ 0,
+ ' ',
+ 0,
+ '-',
+ 0,
+ ' ',
+ 0,
+ 's',
+ 0,
+ '.',
+ 0,
+ 'f',
+ 0,
+ '.',
+ 0,
+ 'm',
+ 0,
+ '.',
+ 0,
+ 'c',
+ 0,
+ '.',
+ 0,
+ ' ',
+ 0,
+ 'G',
+ 0,
+ 'm',
+ 0,
+ 'b',
+ 0,
+ 'H',
+ 0,
+ 24,
+ 3,
+ 's',
+ 0,
+ 'y',
+ 0,
+ 's',
+ 0,
+ 'm',
+ 0,
+ 'o',
+ 0,
+ 'O',
+ 0,
+ 'C',
+ 0,
+ 'T',
+ 0,
+ 'S',
+ 0,
+ 'I',
+ 0,
+ 'M',
+ 0,
+ 4,
+ 3,
+ 'A',
+ 0,
+ 22,
+ 3,
+ 'd',
+ 0,
+ 'e',
+ 0,
+ 'b',
+ 0,
+ 'u',
+ 0,
+ 'g',
+ 0,
+ ' ',
+ 0,
+ 'U',
+ 0,
+ 'A',
+ 0,
+ 'R',
+ 0,
+ 'T',
+ 0,
+ 22,
+ 3,
+ 'd',
+ 0,
+ 'e',
+ 0,
+ 'b',
+ 0,
+ 'u',
+ 0,
+ 'g',
+ 0,
+ ' ',
+ 0,
+ 'U',
+ 0,
+ 'A',
+ 0,
+ 'R',
+ 0,
+ 'T',
+ 0,
+ 10,
+ 3,
+ 'C',
+ 0,
+ 'C',
+ 0,
+ 'I',
+ 0,
+ 'D',
+ 0,
+ 12,
+ 3,
+ 'F',
+ 0,
+ 'I',
+ 0,
+ 'X',
+ 0,
+ 'M',
+ 0,
+ 'E',
+ 0,
+ 52,
+ 3,
+ 's',
+ 0,
+ 'y',
+ 0,
+ 's',
+ 0,
+ 'm',
+ 0,
+ 'o',
+ 0,
+ 'O',
+ 0,
+ 'C',
+ 0,
+ 'T',
+ 0,
+ 'S',
+ 0,
+ 'I',
+ 0,
+ 'M',
+ 0,
+ ' ',
+ 0,
+ 'D',
+ 0,
+ 'F',
+ 0,
+ 'U',
+ 0,
+ ' ',
+ 0,
+ '(',
+ 0,
+ 'R',
+ 0,
+ 'u',
+ 0,
+ 'n',
+ 0,
+ 't',
+ 0,
+ 'i',
+ 0,
+ 'm',
+ 0,
+ 'e',
+ 0,
+ ')',
+ 0,
#endif
}
};
-const struct usbd_descriptors usb_descs[]
- = {{ (uint8_t *)&usb_fs_descs, (uint8_t *)&usb_fs_descs + sizeof(usb_fs_descs) }};
+const struct usbd_descriptors usb_descs[] = { { (uint8_t *)&usb_fs_descs, (uint8_t *)&usb_fs_descs + sizeof(usb_fs_descs) } };
diff --git a/sysmoOCTSIM/usb_dfu.h b/sysmoOCTSIM/usb_dfu.h
index 2e7e171..2719072 100644
--- a/sysmoOCTSIM/usb_dfu.h
+++ b/sysmoOCTSIM/usb_dfu.h
@@ -13,22 +13,22 @@
#include <stdint.h>
#define USB_DFU_CLASS 0xfe
-#define USB_DT_DFU 0x21
+#define USB_DT_DFU 0x21
struct usb_dfu_func_descriptor {
- uint8_t bLength;
- uint8_t bDescriptorType;
- uint8_t bmAttributes;
-#define USB_DFU_CAN_DOWNLOAD (1 << 0)
-#define USB_DFU_CAN_UPLOAD (1 << 1)
-#define USB_DFU_MANIFEST_TOL (1 << 2)
-#define USB_DFU_WILL_DETACH (1 << 3)
- uint16_t wDetachTimeOut;
- uint16_t wTransferSize;
- uint16_t bcdDFUVersion;
-} __attribute__ ((packed));
+ uint8_t bLength;
+ uint8_t bDescriptorType;
+ uint8_t bmAttributes;
+#define USB_DFU_CAN_DOWNLOAD (1 << 0)
+#define USB_DFU_CAN_UPLOAD (1 << 1)
+#define USB_DFU_MANIFEST_TOL (1 << 2)
+#define USB_DFU_WILL_DETACH (1 << 3)
+ uint16_t wDetachTimeOut;
+ uint16_t wTransferSize;
+ uint16_t bcdDFUVersion;
+} __attribute__((packed));
-#define USB_DT_DFU_SIZE 9
+#define USB_DT_DFU_SIZE 9
/* DFU class-specific requests (Section 3, DFU Rev 1.1) */
enum usb_dfu_req {
@@ -41,7 +41,6 @@
USB_DFU_ABORT,
};
-
struct dfu_status {
uint8_t bStatus;
uint8_t bwPollTimeout[3];
@@ -50,36 +49,36 @@
} __attribute__((packed));
enum usb_dfu_status {
- DFU_STATUS_OK =0x00,
- DFU_STATUS_errTARGET =0x01,
- DFU_STATUS_errFILE =0x02,
- DFU_STATUS_errWRITE =0x03,
- DFU_STATUS_errERASE =0x04,
- DFU_STATUS_errCHECK_ERASED =0x05,
- DFU_STATUS_errPROG =0x06,
- DFU_STATUS_errVERIFY =0x07,
- DFU_STATUS_errADDRESS =0x08,
- DFU_STATUS_errNOTDONE =0x09,
- DFU_STATUS_errFIRMWARE =0x0a,
- DFU_STATUS_errVENDOR =0x0b,
- DFU_STATUS_errUSBR =0x0c,
- DFU_STATUS_errPOR =0x0d,
- DFU_STATUS_errUNKNOWN =0x0e,
- DFU_STATUS_errSTALLEDPKT =0x0f,
+ DFU_STATUS_OK = 0x00,
+ DFU_STATUS_errTARGET = 0x01,
+ DFU_STATUS_errFILE = 0x02,
+ DFU_STATUS_errWRITE = 0x03,
+ DFU_STATUS_errERASE = 0x04,
+ DFU_STATUS_errCHECK_ERASED = 0x05,
+ DFU_STATUS_errPROG = 0x06,
+ DFU_STATUS_errVERIFY = 0x07,
+ DFU_STATUS_errADDRESS = 0x08,
+ DFU_STATUS_errNOTDONE = 0x09,
+ DFU_STATUS_errFIRMWARE = 0x0a,
+ DFU_STATUS_errVENDOR = 0x0b,
+ DFU_STATUS_errUSBR = 0x0c,
+ DFU_STATUS_errPOR = 0x0d,
+ DFU_STATUS_errUNKNOWN = 0x0e,
+ DFU_STATUS_errSTALLEDPKT = 0x0f,
};
enum dfu_state {
- DFU_STATE_appIDLE = 0,
- DFU_STATE_appDETACH = 1,
- DFU_STATE_dfuIDLE = 2,
- DFU_STATE_dfuDNLOAD_SYNC = 3,
- DFU_STATE_dfuDNBUSY = 4,
- DFU_STATE_dfuDNLOAD_IDLE = 5,
- DFU_STATE_dfuMANIFEST_SYNC = 6,
- DFU_STATE_dfuMANIFEST = 7,
- DFU_STATE_dfuMANIFEST_WAIT_RST = 8,
- DFU_STATE_dfuUPLOAD_IDLE = 9,
- DFU_STATE_dfuERROR = 10,
+ DFU_STATE_appIDLE = 0,
+ DFU_STATE_appDETACH = 1,
+ DFU_STATE_dfuIDLE = 2,
+ DFU_STATE_dfuDNLOAD_SYNC = 3,
+ DFU_STATE_dfuDNBUSY = 4,
+ DFU_STATE_dfuDNLOAD_IDLE = 5,
+ DFU_STATE_dfuMANIFEST_SYNC = 6,
+ DFU_STATE_dfuMANIFEST = 7,
+ DFU_STATE_dfuMANIFEST_WAIT_RST = 8,
+ DFU_STATE_dfuUPLOAD_IDLE = 9,
+ DFU_STATE_dfuERROR = 10,
};
#endif /* _USB_DFU_H */
diff --git a/sysmoOCTSIM/usb_start.c b/sysmoOCTSIM/usb_start.c
index 6946126..36a4296 100644
--- a/sysmoOCTSIM/usb_start.c
+++ b/sysmoOCTSIM/usb_start.c
@@ -120,8 +120,7 @@
}
}
-
-static struct usbdc_handler string_req_h = {NULL, (FUNC_PTR)string_req_cb};
+static struct usbdc_handler string_req_h = { NULL, (FUNC_PTR)string_req_cb };
/**
* \brief CDC ACM Init
@@ -139,7 +138,6 @@
dfudf_init();
printf("usb_descs_size=%u\r\n", usb_descs[0].eod - usb_descs[0].sod);
-
}
/**
@@ -147,7 +145,6 @@
*/
void usb_start(void)
{
-
#ifdef WITH_DEBUG_CDC
while (!cdcdf_acm_is_enabled()) {
// wait cdc acm to be installed
@@ -155,14 +152,14 @@
cdcdf_acm_register_callback(CDCDF_ACM_CB_STATE_C, (FUNC_PTR)usb_device_cb_state_c);
#endif
- while (!ccid_df_is_enabled());
+ while (!ccid_df_is_enabled())
+ ;
}
void usb_init(void)
{
cdc_device_acm_init();
ccid_df_init();
- usbdc_start((struct usbd_descriptors *) usb_descs);
+ usbdc_start((struct usbd_descriptors *)usb_descs);
usbdc_attach();
-
}
diff --git a/sysmoOCTSIM/usb_start.h b/sysmoOCTSIM/usb_start.h
index 12537bb..acadbaf 100644
--- a/sysmoOCTSIM/usb_start.h
+++ b/sysmoOCTSIM/usb_start.h
@@ -17,7 +17,6 @@
#include "ccid_df.h"
#include "dfudf.h"
-
void usb_start(void);
void cdc_device_acm_init(void);
To view, visit change 42330. To unsubscribe, or for help writing mail filters, visit settings.