Harald Welte has uploaded this change for review. ( 
https://gerrit.osmocom.org/14054


Change subject: ccid_device: Make it compile
......................................................................

ccid_device: Make it compile

Change-Id: I0350fec36eeef69eeccb873f547c9df8b364ae12
---
M ccid/ccid_device.c
1 file changed, 47 insertions(+), 22 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-ccid-firmware 
refs/changes/54/14054/1

diff --git a/ccid/ccid_device.c b/ccid/ccid_device.c
index c81f177..f10b700 100644
--- a/ccid/ccid_device.c
+++ b/ccid/ccid_device.c
@@ -2,6 +2,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <assert.h>
+#include <string.h>

 #include <osmocom/core/msgb.h>
 #include <osmocom/core/utils.h>
@@ -19,7 +20,7 @@
 };

 struct ccid_ops {
-       int (*send)(struct ccid_instance *ci, struct msgb *msg);
+       int (*send_in)(struct ccid_instance *ci, struct msgb *msg);
 };

 struct ccid_instance {
@@ -35,7 +36,7 @@
        if (slot_nr >= sizeof(ci->slot))
                return NULL;
        else
-               return &ci->slot[slot_nr]
+               return &ci->slot[slot_nr];
 }

 static uint8_t get_icc_status(const struct ccid_slot *cs)
@@ -67,7 +68,7 @@

 static struct msgb *ccid_msgb_alloc(void)
 {
-       struct msgb *msg = msgb_alloc("ccid");
+       struct msgb *msg = msgb_alloc(512, "ccid");
        OSMO_ASSERT(msg);
        return msg;
 }
@@ -79,10 +80,10 @@

 static int ccid_slot_send(struct ccid_slot *cs, struct msgb *msg)
 {
-       const struct ccid_header *ch = (const struct ccid_header *) 
msgb_ccid_in(msg);
+       struct ccid_header *ch = (struct ccid_header *) msgb_ccid_in(msg);

        /* patch bSlotNr into message */
-       ch->hdr.bSlot = cs->slot_nr;
+       ch->bSlot = cs->slot_nr;
        return ccid_send(cs->ci, msg);
 }

@@ -93,11 +94,12 @@
                                         uint32_t data_len)
 {
        struct msgb *msg = ccid_msgb_alloc();
-       struct ccid_rdr_to_pc_data_block *db = msgb_put(msg, sizeof(*db) + 
data_len);
+       struct ccid_rdr_to_pc_data_block *db =
+               (struct ccid_rdr_to_pc_data_block *) msgb_put(msg, sizeof(*db) 
+ data_len);
        uint8_t sts = (cmd_sts & CCID_CMD_STATUS_MASK) | get_icc_status(cs);

        SET_HDR_IN(db, RDR_to_PC_DataBlock, cs->slot_nr, seq, sts, err);
-       db->hdr.dwLength = cpu_to_le32(data_len);
+       osmo_store32le(data_len, &db->hdr.hdr.dwLength);
        memcpy(db->abData, data, data_len);
        return msg;
 }
@@ -107,7 +109,8 @@
                                         enum ccid_error_code err)
 {
        struct msgb *msg = ccid_msgb_alloc();
-       struct ccid_rdr_to_pc_slot_status *ss = msgb_put(msg, sizeof(*ss));
+       struct ccid_rdr_to_pc_slot_status *ss =
+               (struct ccid_rdr_to_pc_slot_status *) msgb_put(msg, 
sizeof(*ss));
        uint8_t sts = (cmd_sts & CCID_CMD_STATUS_MASK) | get_icc_status(cs);

        SET_HDR_IN(ss, RDR_to_PC_SlotStatus, cs->slot_nr, seq, sts, err);
@@ -123,11 +126,12 @@
                                    uint32_t data_len)
 {
        struct msgb *msg = ccid_msgb_alloc();
-       struct ccid_rdr_to_pc_escape *esc = msgb_put(msg, sizeof(*esc) + 
data_len);
+       struct ccid_rdr_to_pc_escape *esc =
+               (struct ccid_rdr_to_pc_escape *) msgb_put(msg, sizeof(*esc) + 
data_len);
        uint8_t sts = (cmd_sts & CCID_CMD_STATUS_MASK) | get_icc_status(cs);

        SET_HDR_IN(esc, RDR_to_PC_Escape, cs->slot_nr, seq, sts, err);
-       esc->hdr.dwLength = cpu_to_le32(data_len);
+       osmo_store32le(data_len, &esc->hdr.hdr.dwLength);
        memcpy(esc->abData, data, data_len);
        return msg;
 }
@@ -137,13 +141,14 @@
                                            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 = msgb_put(msg, 
sizeof(*drc));
+       struct ccid_rdr_to_pc_data_rate_and_clock *drc =
+               (struct ccid_rdr_to_pc_data_rate_and_clock *) msgb_put(msg, 
sizeof(*drc));
        uint8_t sts = (cmd_sts & CCID_CMD_STATUS_MASK) | get_icc_status(cs);

        SET_HDR_IN(drc, RDR_to_PC_DataRateAndClockFrequency, cs->slot_nr, seq, 
sts, err);
-       drc->dwLength = cpu_to_le32(8); /* Message-specific data length (wtf?) 
*/
-       drc->dwClockFrequency = cpu_to_le32(clock_khz); /* kHz */
-       drc->dwDataRate = cpu_to_le32(rate_bps); /* bps */
+       osmo_store32le(8, &drc->hdr.hdr.dwLength); /* Message-specific data 
length (wtf?) */
+       osmo_store32le(clock_khz, &drc->dwClockFrequency); /* kHz */
+       osmo_store32le(rate_bps, &drc->dwDataRate); /* bps */
        return msg;
 }

@@ -181,7 +186,7 @@

        /* TODO: send actual ATR; handle error cases */
        /* TODO: handle this asynchronously */
-       resp = ccid_gen_data_block(cs, u->icc_power_on.hdr.hSeq, 
CCID_CMD_STATUS_OK, 0, NULL, 0);
+       resp = ccid_gen_data_block(cs, u->icc_power_on.hdr.bSeq, 
CCID_CMD_STATUS_OK, 0, NULL, 0);

        return ccid_send(cs->ci, resp);
 }
@@ -190,6 +195,8 @@
 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);
+       struct msgb *resp;
+
        resp = ccid_gen_slot_status(cs, u->get_slot_status.hdr.bSeq, 
CCID_CMD_STATUS_OK, 0);
        return ccid_send(cs->ci, resp);
 }
@@ -198,7 +205,9 @@
 static int ccid_handle_xfr_block(struct ccid_slot *cs, struct msgb *msg)
 {
        const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
-       resp = ccid_gen_data_block(cs, u->icc_power_on.hdr.hSeq, 
CCID_CMD_STATUS_OK, 0, NULL, 0);
+       struct msgb *resp;
+
+       resp = ccid_gen_data_block(cs, u->icc_power_on.hdr.bSeq, 
CCID_CMD_STATUS_OK, 0, NULL, 0);
        return ccid_send(cs->ci, resp);
 }

@@ -206,30 +215,36 @@
 static int ccid_handle_get_parameters(struct ccid_slot *cs, struct msgb *msg)
 {
        const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
+       struct msgb *resp;
 }

 /* Section 6.1.6 */
 static int ccid_handle_reset_parameters(struct ccid_slot *cs, struct msgb *msg)
 {
        const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
+       struct msgb *resp;
 }

 /* Section 6.1.7 */
 static int ccid_handle_set_parameters(struct ccid_slot *cs, struct msgb *msg)
 {
        const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
+       struct msgb *resp;
 }

 /* Section 6.1.8 */
 static int ccid_handle_escape(struct ccid_slot *cs, struct msgb *msg)
 {
        const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
+       struct msgb *resp;
 }

 /* Section 6.1.9 */
 static int ccid_handle_icc_clock(struct ccid_slot *cs, struct msgb *msg)
 {
        const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
+       struct msgb *resp;
+
        resp = ccid_gen_slot_status(cs, u->get_slot_status.hdr.bSeq, 
CCID_CMD_STATUS_OK, 0);
        return ccid_send(cs->ci, resp);
 }
@@ -238,6 +253,8 @@
 static int ccid_handle_t0apdu(struct ccid_slot *cs, struct msgb *msg)
 {
        const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
+       struct msgb *resp;
+
        resp = ccid_gen_slot_status(cs, u->get_slot_status.hdr.bSeq, 
CCID_CMD_STATUS_OK, 0);
        return ccid_send(cs->ci, resp);
 }
@@ -252,6 +269,8 @@
 static int ccid_handle_mechanical(struct ccid_slot *cs, struct msgb *msg)
 {
        const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
+       struct msgb *resp;
+
        resp = ccid_gen_slot_status(cs, u->get_slot_status.hdr.bSeq, 
CCID_CMD_STATUS_OK, 0);
        return ccid_send(cs->ci, resp);
 }
@@ -260,6 +279,8 @@
 static int ccid_handle_abort(struct ccid_slot *cs, struct msgb *msg)
 {
        const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
+       struct msgb *resp;
+
        resp = ccid_gen_slot_status(cs, u->get_slot_status.hdr.bSeq, 
CCID_CMD_STATUS_OK, 0);
        return ccid_send(cs->ci, resp);
 }
@@ -267,7 +288,8 @@
 /* Section 6.1.14 */
 static int ccid_handle_set_rate_and_clock(struct ccid_slot *cs, struct msgb 
*msg)
 {
-       const union ccid_pc_to_rdr *u = msgb_ccid(msg);
+       const union ccid_pc_to_rdr *u = msgb_ccid_out(msg);
+       struct msgb *resp;
 }

 /* handle data arriving from the host on the OUT endpoint */
@@ -277,13 +299,14 @@
        const struct ccid_header *ch = (const struct ccid_header *) u;
        unsigned int len = msgb_length(msg);
        struct ccid_slot *cs;
+       int rc;

        if (len < sizeof(*ch)) {
                /* FIXME */
                return -1;
        }

-       cs = get_ccid_slot(ci, ch->hdr.bSlot);
+       cs = get_ccid_slot(ci, ch->bSlot);
        if (!cs) {
                /* FIXME */
                return -1;
@@ -338,7 +361,7 @@
        case PC_to_RDR_T0APDU:
                if (len != /*FIXME*/ sizeof(u->t0apdu))
                        goto short_msg;
-               rc = ccid_handle_t0_apdu(cs, msg);
+               rc = ccid_handle_t0apdu(cs, msg);
                break;
        case PC_to_RDR_Secure:
                if (len < sizeof(u->secure))
@@ -361,10 +384,12 @@
                rc = ccid_handle_set_rate_and_clock(cs, msg);
                break;
        default:
-               FIXME
+               /* FIXME */
                break;
        }
-       FIXME
+       return 0;
+
 short_msg:
-       FIXME
+       /* FIXME */
+       return -1;
 }

--
To view, visit https://gerrit.osmocom.org/14054
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-ccid-firmware
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0350fec36eeef69eeccb873f547c9df8b364ae12
Gerrit-Change-Number: 14054
Gerrit-PatchSet: 1
Gerrit-Owner: Harald Welte <[email protected]>

Reply via email to