summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Levy <alevy@redhat.com>2011-02-23 16:50:44 +0200
committerAlon Levy <alevy@redhat.com>2011-02-23 16:50:44 +0200
commit27728857b41643bd1f3003db2827126a3e9234f3 (patch)
treef76d3a670354ec0351df6d7d3875207f2ed3c808
parentc0aa647f37f029f52a15f81587701eab44e7c438 (diff)
checkpatch.pl - identical to v20 proposal on qemu-devel
-rw-r--r--cac.c36
-rw-r--r--card_7816.c50
-rw-r--r--event.c8
-rw-r--r--mutex.h6
-rw-r--r--passthru.c110
-rw-r--r--vcard.c18
-rw-r--r--vcard.h6
-rw-r--r--vcard_emul.h2
-rw-r--r--vcard_emul_nss.c95
-rw-r--r--vcard_emul_type.c6
-rw-r--r--vcard_emul_type.h15
-rw-r--r--vcardt.h4
-rw-r--r--vreader.c16
-rw-r--r--vreadert.h2
-rw-r--r--vscard_common.h14
-rw-r--r--vscclient.c403
16 files changed, 398 insertions, 393 deletions
diff --git a/cac.c b/cac.c
index e51caec..0a605ca 100644
--- a/cac.c
+++ b/cac.c
@@ -58,7 +58,7 @@ cac_common_process_apdu(VCard *card, VCardAPDU *apdu, VCardResponse **response)
}
/* CAC 1.0 only supports ef = 0 */
ef = apdu->a_body[0] | (apdu->a_body[1] << 8);
- if (ef != 0 ) {
+ if (ef != 0) {
*response = vcard_make_response(
VCARD7816_STATUS_ERROR_FILE_NOT_FOUND);
return VCARD_DONE;
@@ -123,15 +123,15 @@ cac_applet_pki_process_apdu(VCard *card, VCardAPDU *apdu,
return VCARD_DONE;
case CAC_GET_CERTIFICATE:
if ((apdu->a_p2 != 0) || (apdu->a_p1 != 0)) {
- *response = vcard_make_response(
- VCARD7816_STATUS_ERROR_P1_P2_INCORRECT);
- break;
+ *response = vcard_make_response(
+ VCARD7816_STATUS_ERROR_P1_P2_INCORRECT);
+ break;
}
ASSERT(pki_applet->cert != NULL);
size = apdu->a_Le;
if (pki_applet->cert_buffer == NULL) {
- pki_applet->cert_buffer=pki_applet->cert;
- pki_applet->cert_buffer_len=pki_applet->cert_len;
+ pki_applet->cert_buffer = pki_applet->cert;
+ pki_applet->cert_buffer_len = pki_applet->cert_len;
}
size = MIN(size, pki_applet->cert_buffer_len);
next = MIN(255, pki_applet->cert_buffer_len - size);
@@ -144,7 +144,7 @@ cac_applet_pki_process_apdu(VCard *card, VCardAPDU *apdu,
pki_applet->cert_buffer += size;
pki_applet->cert_buffer_len -= size;
if ((*response == NULL) || (next == 0)) {
- pki_applet->cert_buffer=NULL;
+ pki_applet->cert_buffer = NULL;
}
if (*response == NULL) {
*response = vcard_make_response(
@@ -153,9 +153,9 @@ cac_applet_pki_process_apdu(VCard *card, VCardAPDU *apdu,
return VCARD_DONE;
case CAC_SIGN_DECRYPT:
if (apdu->a_p2 != 0) {
- *response = vcard_make_response(
- VCARD7816_STATUS_ERROR_P1_P2_INCORRECT);
- break;
+ *response = vcard_make_response(
+ VCARD7816_STATUS_ERROR_P1_P2_INCORRECT);
+ break;
}
size = apdu->a_Lc;
@@ -289,7 +289,7 @@ cac_new_pki_applet_private(const unsigned char *cert,
if (applet_private == NULL) {
goto fail;
}
- pki_applet_data= &(applet_private->u.pki_data);
+ pki_applet_data = &(applet_private->u.pki_data);
pki_applet_data->cert_buffer = NULL;
pki_applet_data->cert_buffer_len = 0;
pki_applet_data->sign_buffer = NULL;
@@ -328,7 +328,7 @@ cac_new_pki_applet(int i, const unsigned char *cert,
VCardAppletPrivate *applet_private = NULL;
VCardApplet *applet = NULL;
unsigned char pki_aid[] = { 0xa0, 0x00, 0x00, 0x00, 0x79, 0x01, 0x00 };
- int pki_aid_len = sizeof (pki_aid);
+ int pki_aid_len = sizeof(pki_aid);
pki_aid[pki_aid_len-1] = i;
@@ -355,10 +355,10 @@ failure:
}
-static unsigned char cac_default_container_aid[] =
- { 0xa0, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00 };
-static unsigned char cac_id_aid[] =
- { 0xa0, 0x00, 0x00, 0x00, 0x79, 0x03, 0x00 };
+static unsigned char cac_default_container_aid[] = {
+ 0xa0, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00 };
+static unsigned char cac_id_aid[] = {
+ 0xa0, 0x00, 0x00, 0x00, 0x79, 0x03, 0x00 };
/*
* Initialize the cac card. This is the only public function in this file. All
* the rest are connected through function pointers.
@@ -375,10 +375,10 @@ cac_card_init(VReader *reader, VCard *card,
VCardApplet *applet;
/* CAC Cards are VM Cards */
- vcard_set_type(card,VCARD_VM);
+ vcard_set_type(card, VCARD_VM);
/* create one PKI applet for each cert */
- for (i=0; i < cert_count; i++) {
+ for (i = 0; i < cert_count; i++) {
applet = cac_new_pki_applet(i, cert[i], cert_len[i], key[i]);
if (applet == NULL) {
goto failure;
diff --git a/card_7816.c b/card_7816.c
index e2d8466..6b84645 100644
--- a/card_7816.c
+++ b/card_7816.c
@@ -71,7 +71,7 @@ vcard_init_buffer_response(VCard *card, unsigned char *buf, int len)
VCardResponse *response;
VCardBufferResponse *buffer_response;
- buffer_response =vcard_get_buffer_response(card);
+ buffer_response = vcard_get_buffer_response(card);
if (buffer_response) {
vcard_set_buffer_response(card, NULL);
vcard_buffer_response_delete(buffer_response);
@@ -85,7 +85,7 @@ vcard_init_buffer_response(VCard *card, unsigned char *buf, int len)
if (response == NULL) {
return NULL;
}
- vcard_set_buffer_response(card,buffer_response);
+ vcard_set_buffer_response(card, buffer_response);
return response;
}
@@ -99,13 +99,13 @@ vcard_response_new(VCard *card, unsigned char *buf,
VCardResponse *new_response;
if (len > Le) {
- return vcard_init_buffer_response(card, buf, len);
+ return vcard_init_buffer_response(card, buf, len);
}
- new_response = vcard_response_new_data(buf,len);
+ new_response = vcard_response_new_data(buf, len);
if (new_response == NULL) {
return NULL;
}
- vcard_response_set_status(new_response,status);
+ vcard_response_set_status(new_response, status);
return new_response;
}
@@ -119,13 +119,13 @@ vcard_response_new_bytes(VCard *card, unsigned char *buf, int len, int Le,
VCardResponse *new_response;
if (len > Le) {
- return vcard_init_buffer_response(card, buf, len);
+ return vcard_init_buffer_response(card, buf, len);
}
- new_response = vcard_response_new_data(buf,len);
+ new_response = vcard_response_new_data(buf, len);
if (new_response == NULL) {
return NULL;
}
- vcard_response_set_status_bytes(new_response,sw1,sw2);
+ vcard_response_set_status_bytes(new_response, sw1, sw2);
return new_response;
}
@@ -145,7 +145,7 @@ vcard_response_new_status(vcard_7816_status_t status)
new_response->b_len = 0;
new_response->b_total_len = 2;
new_response->b_type = VCARD_MALLOC_STRUCT;
- vcard_response_set_status(new_response,status);
+ vcard_response_set_status(new_response, status);
return new_response;
}
@@ -194,13 +194,13 @@ vcard_response_delete(VCardResponse *response)
free(response->b_data);
}
break;
- case VCARD_MALLOC_STRUCT:
+ case VCARD_MALLOC_STRUCT:
/* only the structure was malloc'ed */
free(response);
break;
- case VCARD_STATIC:
+ case VCARD_STATIC:
break;
- }
+ }
}
/*
@@ -243,7 +243,7 @@ vcard_apdu_set_class(VCardAPDU *apdu) {
case 0xf0:
default:
apdu->a_gen_type =
- (apdu->a_cla == 0xff)? VCARD_7816_PTS : VCARD_7816_PROPIETARY;
+ (apdu->a_cla == 0xff) ? VCARD_7816_PTS : VCARD_7816_PROPIETARY;
break;
}
return VCARD7816_STATUS_SUCCESS;
@@ -314,7 +314,7 @@ vcard_apdu_set_length(VCardAPDU *apdu)
return VCARD7816_STATUS_ERROR_WRONG_LENGTH;
}
/* not extended */
- apdu->a_Lc= apdu->a_header->ah_Le;
+ apdu->a_Lc = apdu->a_header->ah_Le;
apdu->a_body = &apdu->a_header->ah_body[0];
if (L == apdu->a_Lc + 1) {
/* 3S only body parameters */
@@ -651,10 +651,10 @@ vcard7816_vm_process_apdu(VCard *card, VCardAPDU *apdu,
unsigned char *aid;
int aid_len;
aid = vcard_applet_get_aid(current_applet, &aid_len);
- *response = vcard_response_new(card, aid, aid_len, apdu->a_Le,
+ *response = vcard_response_new(card, aid, aid_len, apdu->a_Le,
VCARD7816_STATUS_SUCCESS);
} else {
- *response = vcard_make_response(
+ *response = vcard_make_response(
VCARD7816_STATUS_ERROR_FILE_NOT_FOUND);
}
break;
@@ -702,12 +702,12 @@ vcard7816_vm_process_apdu(VCard *card, VCardAPDU *apdu,
card, buffer_response->current, bytes_to_copy,
apdu->a_Le,
next_byte_count ?
- VCARD7816_SW1_RESPONSE_BYTES: VCARD7816_SW1_SUCCESS,
+ VCARD7816_SW1_RESPONSE_BYTES : VCARD7816_SW1_SUCCESS,
next_byte_count);
buffer_response->current += bytes_to_copy;
buffer_response->len -= bytes_to_copy;
if (*response == NULL || (next_byte_count == 0)) {
- vcard_set_buffer_response(card,NULL);
+ vcard_set_buffer_response(card, NULL);
vcard_buffer_response_delete(buffer_response);
}
if (*response == NULL) {
@@ -753,11 +753,11 @@ vcard_process_apdu(VCard *card, VCardAPDU *apdu, VCardResponse **response)
}
buffer_response = vcard_get_buffer_response(card);
if (buffer_response && apdu->a_ins != VCARD7816_INS_GET_RESPONSE) {
- /* clear out buffer_response, return an error */
- vcard_set_buffer_response(card,NULL);
+ /* clear out buffer_response, return an error */
+ vcard_set_buffer_response(card, NULL);
vcard_buffer_response_delete(buffer_response);
- *response = vcard_make_response(VCARD7816_STATUS_EXC_ERROR);
- return VCARD_DONE;
+ *response = vcard_make_response(VCARD7816_STATUS_EXC_ERROR);
+ return VCARD_DONE;
}
status = vcard_process_applet_apdu(card, apdu, response);
@@ -766,13 +766,13 @@ vcard_process_apdu(VCard *card, VCardAPDU *apdu, VCardResponse **response)
}
switch (vcard_get_type(card)) {
case VCARD_FILE_SYSTEM:
- return vcard7816_file_system_process_apdu(card,apdu,response);
+ return vcard7816_file_system_process_apdu(card, apdu, response);
case VCARD_VM:
- return vcard7816_vm_process_apdu(card,apdu,response);
+ return vcard7816_vm_process_apdu(card, apdu, response);
case VCARD_DIRECT:
/* if we are type direct, then the applet should handle everything */
assert("VCARD_DIRECT: applet failure");
- break;
+ break;
}
*response =
vcard_make_response(VCARD7816_STATUS_ERROR_COMMAND_NOT_SUPPORTED);
diff --git a/event.c b/event.c
index 25d99ae..20276a0 100644
--- a/event.c
+++ b/event.c
@@ -47,8 +47,8 @@ vevent_delete(VEvent *vevent)
* VEvent queue management
*/
-static VEvent *vevent_queue_head = NULL;
-static VEvent *vevent_queue_tail = NULL;
+static VEvent *vevent_queue_head;
+static VEvent *vevent_queue_tail;
static mutex_t vevent_queue_lock;
static condition_t vevent_queue_condition;
@@ -88,7 +88,7 @@ vevent_dequeue_vevent(void)
return vevent;
}
-VEvent * vevent_wait_next_vevent(void)
+VEvent *vevent_wait_next_vevent(void)
{
VEvent *vevent;
@@ -100,7 +100,7 @@ VEvent * vevent_wait_next_vevent(void)
return vevent;
}
-VEvent * vevent_get_next_vevent(void)
+VEvent *vevent_get_next_vevent(void)
{
VEvent *vevent;
diff --git a/mutex.h b/mutex.h
index ffbdb31..cb46aa7 100644
--- a/mutex.h
+++ b/mutex.h
@@ -32,8 +32,8 @@ typedef CRITICAL_SECTION mutex_t;
#define MUTEX_UNLOCK(mutex) LeaveCriticalSection(&mutex)
typedef CONDITION_VARIABLE condition_t;
#define CONDITION_INIT(cond) InitializeConditionVariable(&cond)
-#define CONDITION_WAIT(cond,mutex) \
- SleepConditionVariableCS(&cond,&mutex,INFINTE)
+#define CONDITION_WAIT(cond, mutex) \
+ SleepConditionVariableCS(&cond, &mutex, INFINTE)
#define CONDITION_NOTIFY(cond) WakeConditionVariable(&cond)
typedef uint32_t thread_t;
typedef HANDLE thread_status_t;
@@ -48,7 +48,7 @@ typedef pthread_mutex_t mutex_t;
#define MUTEX_UNLOCK(mutex) pthread_mutex_unlock(&mutex)
typedef pthread_cond_t condition_t;
#define CONDITION_INIT(cond) pthread_cond_init(&cond, NULL)
-#define CONDITION_WAIT(cond,mutex) pthread_cond_wait(&cond,&mutex)
+#define CONDITION_WAIT(cond, mutex) pthread_cond_wait(&cond, &mutex)
#define CONDITION_NOTIFY(cond) pthread_cond_signal(&cond)
typedef pthread_t thread_t;
typedef int thread_status_t;
diff --git a/passthru.c b/passthru.c
index 09471c7..828516d 100644
--- a/passthru.c
+++ b/passthru.c
@@ -26,7 +26,7 @@ struct VCardAppletPrivateStruct {
int atr_len;
};
-static SCARDCONTEXT global_context = 0;
+static SCARDCONTEXT global_context;
#define MAX_RESPONSE_LENGTH 261 /*65537 */
/*
@@ -43,23 +43,23 @@ passthru_process_apdu(VCard *card, VCardAPDU *apdu, VCardResponse **response)
applet_private = vcard_get_current_applet_private(card, 0);
if (applet_private == NULL) {
- *response = vcard_make_response(VCARD7816_STATUS_EXC_ERROR);
- return VCARD_DONE;
+ *response = vcard_make_response(VCARD7816_STATUS_EXC_ERROR);
+ return VCARD_DONE;
}
rv = SCardTransmit(applet_private->hCard, applet_private->send_io,
apdu->a_data, apdu->a_len, &receive_io, buf, &len);
if (rv != SCARD_S_SUCCESS) {
- *response = vcard_make_response(VCARD7816_STATUS_EXC_ERROR);
- return VCARD_DONE;
+ *response = vcard_make_response(VCARD7816_STATUS_EXC_ERROR);
+ return VCARD_DONE;
}
- *response = vcard_response_new_data(buf,len);
+ *response = vcard_response_new_data(buf, len);
if (*response == NULL) {
- *response =
+ *response =
vcard_make_response(VCARD7816_STATUS_EXC_ERROR_MEMORY_FAILURE);
} else {
- (*response)->b_total_len = (*response)->b_len;
+ (*response)->b_total_len = (*response)->b_len;
}
return VCARD_DONE;
}
@@ -87,7 +87,7 @@ static void passthru_card_get_atr(VCard *card, unsigned char *atr, int *atr_len)
return;
}
*atr_len = MIN(applet_private->atr_len, *atr_len);
- memcpy(atr,applet_private->atr,*atr_len);
+ memcpy(atr, applet_private->atr, *atr_len);
return;
}
@@ -124,9 +124,9 @@ string_match(const char *s1, const char *s2)
const char *start;
for (start = strchr(s2, *s1); start; start = strchr(start+1, *s1)) {
- if (strncmp(start, s1, len) == 0) {
- return 1;
- }
+ if (strncmp(start, s1, len) == 0) {
+ return 1;
+ }
}
return 0;
}
@@ -152,29 +152,29 @@ passthru_get_reader_name(VReader *reader)
status = passthru_pcsc_lite_init();
if (status != VCARD_DONE) {
- return NULL;
+ return NULL;
}
/* find the existing reader names */
rv = SCardListReaders(global_context, NULL, NULL, &reader_string_length);
if (rv != SCARD_S_SUCCESS) {
- return NULL;
+ return NULL;
}
reader_list = (char *)malloc(reader_string_length);
rv = SCardListReaders(global_context, NULL, reader_list,
&reader_string_length);
if (rv != SCARD_S_SUCCESS) {
- goto cleanup;
+ goto cleanup;
}
/* match that name */
- for (reader_entry= reader_list;*reader_entry;
+ for (reader_entry = reader_list; *reader_entry;
reader_entry += strlen(reader_entry)+1) {
- if (string_match(reader_entry, reader_name)) {
- reader_match = strdup(reader_entry);
- break;
- }
+ if (string_match(reader_entry, reader_name)) {
+ reader_match = strdup(reader_entry);
+ break;
+ }
}
cleanup:
if (reader_list) {
@@ -194,7 +194,7 @@ passthru_delete_applet_private(VCardAppletPrivate *applet_private)
return;
}
if (applet_private->hCard) {
- SCardDisconnect(applet_private->hCard,SCARD_LEAVE_CARD);
+ SCardDisconnect(applet_private->hCard, SCARD_LEAVE_CARD);
}
if (applet_private->reader_name != NULL) {
free(applet_private->reader_name);
@@ -221,8 +221,8 @@ passthru_new_applet_private(VReader *reader)
goto fail;
}
- rv = SCardConnect( global_context, applet_private->reader_name,
- SCARD_SHARE_DIRECT, SCARD_PROTOCOL_T0|SCARD_PROTOCOL_T1,
+ rv = SCardConnect(global_context, applet_private->reader_name,
+ SCARD_SHARE_DIRECT, SCARD_PROTOCOL_T0|SCARD_PROTOCOL_T1,
&applet_private->hCard,
&applet_private->hProtocol);
if (rv != SCARD_S_SUCCESS) {
@@ -254,7 +254,7 @@ passthru_new_applet(VReader *reader)
VCardAppletPrivate *applet_private = NULL;
VCardApplet *applet = NULL;
unsigned char passthru_aid[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- int passthru_aid_len = sizeof (passthru_aid);
+ int passthru_aid_len = sizeof(passthru_aid);
applet_private = passthru_new_applet_private(reader);
if (applet_private == NULL) {
@@ -286,17 +286,17 @@ failure:
*/
VCardStatus
passthru_card_init(VReader *vreader, VCard *card,
- const char *flags,
- unsigned char * const *cert,
- int cert_len[],
- VCardKey *key[] /* adopt the keys*/,
- int cert_count)
+ const char *flags,
+ unsigned char * const *cert,
+ int cert_len[],
+ VCardKey *key[] /* adopt the keys*/,
+ int cert_count)
{
int i;
VCardApplet *applet;
/* Don't do soft emulation of the 7816, pass everything to the card */
- vcard_set_type(card,VCARD_DIRECT);
+ vcard_set_type(card, VCARD_DIRECT);
applet = passthru_new_applet(vreader);
if (applet == NULL) {
@@ -306,8 +306,8 @@ passthru_card_init(VReader *vreader, VCard *card,
vcard_add_applet(card, applet);
/* we are adopting the keys, so free them now (since we don't use them) */
- for (i=0; i < cert_count; i++) {
- vcard_emul_delete_key(key[i]);
+ for (i = 0; i < cert_count; i++) {
+ vcard_emul_delete_key(key[i]);
}
return VCARD_DONE;
@@ -331,9 +331,9 @@ passthru_get_reader_state(SCARD_READERSTATE_A *reader_states,
{
int i;
- for (i=0; i < reader_count; i++) {
+ for (i = 0; i < reader_count; i++) {
if (name == NULL && reader_states[i].szReader == NULL) {
- // looking for a blank slot to return
+ /* looking for a blank slot to return */
return &reader_states[i];
}
if (name == NULL || reader_states[i].szReader == NULL) {
@@ -370,7 +370,7 @@ passthru_emul_event_thread(void *args)
int max_reader_count = 0; /* size of the reader_state array (including
inactive readers) */
LONG rv;
- int timeout=1000;
+ int timeout = 1000;
int i;
do {
@@ -381,7 +381,7 @@ passthru_emul_event_thread(void *args)
int new_reader_count = 0;
/* other temps */
- char * reader_entry;
+ char *reader_entry;
VReader *reader;
/*
@@ -389,7 +389,7 @@ passthru_emul_event_thread(void *args)
*/
rv = SCardListReaders(global_context, NULL, NULL, &new_reader_list_len);
if (rv != SCARD_S_SUCCESS) {
- goto next;
+ goto next;
}
/*
* If the names have changed, we need to update our list and states.
@@ -408,7 +408,7 @@ passthru_emul_event_thread(void *args)
goto next;
}
/* clear out our event state */
- for (i=0; i < reader_count; i++) {
+ for (i = 0; i < reader_count; i++) {
reader_states[i].dwEventState = 0;
}
/* count the readers and mark the ones that are still with us */
@@ -425,7 +425,7 @@ passthru_emul_event_thread(void *args)
}
}
/* eject any removed readers */
- for (i=0; i < reader_count; i++) {
+ for (i = 0; i < reader_count; i++) {
if (reader_states[i].dwEventState == SCARD_STATE_PRESENT) {
reader_states[i].dwEventState = 0;
continue;
@@ -439,17 +439,17 @@ passthru_emul_event_thread(void *args)
if (new_reader_count < reader_count) {
/* fold all the valid entries at the end of our reader_states
* array up into those locations vacated by ejected readers. */
- for (i=reader_count-1; i < (new_reader_count -1); i--) {
- if (reader_states[i].szReader) {
- SCARD_READERSTATE_A *blank_reader;
- blank_reader =
- passthru_get_blank_reader(reader_states,
- new_reader_count);
- assert(blank_reader);
- *blank_reader = reader_states[i];
- reader_states[i].szReader = NULL;
- }
- }
+ for (i = reader_count - 1; i < (new_reader_count - 1); i--) {
+ if (reader_states[i].szReader) {
+ SCARD_READERSTATE_A *blank_reader;
+ blank_reader =
+ passthru_get_blank_reader(reader_states,
+ new_reader_count);
+ assert(blank_reader);
+ *blank_reader = reader_states[i];
+ reader_states[i].szReader = NULL;
+ }
+ }
}
/* handle the growing list */
if (new_reader_count > max_reader_count) {
@@ -470,7 +470,7 @@ passthru_emul_event_thread(void *args)
* */
}
/* mark our new entries as empty */
- for (i=reader_count; i > new_reader_count; i++) {
+ for (i = reader_count; i > new_reader_count; i++) {
reader_states[i].szReader = NULL;
}
}
@@ -515,7 +515,7 @@ next:
continue; /* check for new readers */
}
if (rv != SCARD_S_SUCCESS) {
- static int restarts = 0;
+ static int restarts;
VCardStatus status;
/* try resetting the pcsc_lite subsystem */
@@ -533,7 +533,7 @@ next:
continue;
}
/* deal with card insertion/removal */
- for (i=0; i < reader_count ; i++) {
+ for (i = 0; i < reader_count ; i++) {
if ((reader_states[i].dwEventState & SCARD_STATE_CHANGED) == 0) {
continue;
}
@@ -572,8 +572,8 @@ next:
vreader_free(reader);
}
- } while (1);
- return NULL;
+ } while (1);
+ return NULL;
}
/*
diff --git a/vcard.c b/vcard.c
index 9672001..fff766f 100644
--- a/vcard.c
+++ b/vcard.c
@@ -73,14 +73,14 @@ vcard_reset(VCard *card, VCardPower power)
VCardApplet *applet = NULL;
if (card->type == VCARD_DIRECT) {
- /* select the last applet */
+ /* select the last applet */
VCardApplet *current_applet = NULL;
for (current_applet = card->applet_list; current_applet;
current_applet = current_applet->next) {
- applet = current_applet;
- }
+ applet = current_applet;
+ }
}
- for (i=0; i < MAX_CHANNEL; i++) {
+ for (i = 0; i < MAX_CHANNEL; i++) {
card->current_applet[i] = applet;
}
if (card->vcard_buffer_response) {
@@ -164,7 +164,7 @@ vcard_new(VCardEmul *private, VCardEmulFree private_free)
new_card = (VCard *)malloc(sizeof(VCard));
new_card->applet_list = NULL;
- for (i=0; i < MAX_CHANNEL; i++) {
+ for (i = 0; i < MAX_CHANNEL; i++) {
new_card->current_applet[i] = NULL;
}
new_card->vcard_buffer_response = NULL;
@@ -218,8 +218,8 @@ void
vcard_get_atr(VCard *vcard, unsigned char *atr, int *atr_len)
{
if (vcard->vcard_get_atr) {
- (*vcard->vcard_get_atr)(vcard, atr, atr_len);
- return;
+ (*vcard->vcard_get_atr)(vcard, atr, atr_len);
+ return;
}
vcard_emul_get_atr(vcard, atr, atr_len);
}
@@ -227,7 +227,7 @@ vcard_get_atr(VCard *vcard, unsigned char *atr, int *atr_len)
void
vcard_set_atr_func(VCard *card, VCardGetAtr vcard_get_atr)
{
- card-> vcard_get_atr = vcard_get_atr;
+ card->vcard_get_atr = vcard_get_atr;
}
@@ -240,7 +240,7 @@ vcard_add_applet(VCard *card, VCardApplet *applet)
if (card->type == VCARD_DIRECT) {
int i;
- for (i=0; i < MAX_CHANNEL; i++) {
+ for (i = 0; i < MAX_CHANNEL; i++) {
card->current_applet[i] = applet;
}
}
diff --git a/vcard.h b/vcard.h
index 8dbd761..12552c3 100644
--- a/vcard.h
+++ b/vcard.h
@@ -54,7 +54,7 @@ VCardApplet *vcard_find_applet(VCard *card, unsigned char *aid, int aid_len);
/* set the following applet to be current on the given channel */
void vcard_select_applet(VCard *card, int channel, VCardApplet *applet);
/* get the card type specific private data on the given channel */
-VCardAppletPrivate * vcard_get_current_applet_private(VCard *card, int channel);
+VCardAppletPrivate *vcard_get_current_applet_private(VCard *card, int channel);
/* fetch the applet's id */
unsigned char *vcard_applet_get_aid(VCardApplet *applet, int *aid_len);
@@ -65,9 +65,9 @@ VCardStatus vcard_process_applet_apdu(VCard *card, VCardAPDU *apdu,
* VCard utilities
*/
/* constructor */
-VCard * vcard_new(VCardEmul *_private, VCardEmulFree private_free);
+VCard *vcard_new(VCardEmul *_private, VCardEmulFree private_free);
/* get a reference */
-VCard * vcard_reference(VCard *);
+VCard *vcard_reference(VCard *);
/* destructor (reference counted) */
void vcard_free(VCard *);
/* get the atr from the card */
diff --git a/vcard_emul.h b/vcard_emul.h
index 05fb57e..766f08d 100644
--- a/vcard_emul.h
+++ b/vcard_emul.h
@@ -18,7 +18,7 @@
* types
*/
typedef enum {
- VCARD_EMUL_OK =0,
+ VCARD_EMUL_OK = 0,
VCARD_EMUL_FAIL,
/* return values by vcard_emul_init */
VCARD_EMUL_INIT_ALREADY_INITED,
diff --git a/vcard_emul_nss.c b/vcard_emul_nss.c
index 6887cf6..e4f0b73 100644
--- a/vcard_emul_nss.c
+++ b/vcard_emul_nss.c
@@ -68,7 +68,7 @@ struct VCardEmulOptionsStruct {
PRBool use_hw;
};
-static int nss_emul_init = 0;
+static int nss_emul_init;
/* if we have more that just the slot, define
* VCardEmulStruct here */
@@ -142,7 +142,7 @@ vcard_emul_card_get_slot(VCard *card)
static VCardKey *
vcard_emul_make_key(PK11SlotInfo *slot, CERTCertificate *cert)
{
- VCardKey * key;
+ VCardKey *key;
key = (VCardKey *)malloc(sizeof(VCardKey));
if (key == NULL) {
@@ -153,7 +153,7 @@ vcard_emul_make_key(PK11SlotInfo *slot, CERTCertificate *cert)
/* NOTE: if we aren't logged into the token, this could return NULL */
/* NOTE: the cert is a temp cert, not necessarily the cert in the token,
* use the DER version of this function */
- key->key = PK11_FindKeyByDERCert(slot,cert, NULL);
+ key->key = PK11_FindKeyByDERCert(slot, cert, NULL);
return key;
}
@@ -187,7 +187,7 @@ vcard_emul_get_nss_key(VCardKey *key)
return key->key;
}
/* NOTE: if we aren't logged into the token, this could return NULL */
- key->key = PK11_FindPrivateKeyFromCert(key->slot,key->cert, NULL);
+ key->key = PK11_FindPrivateKeyFromCert(key->slot, key->cert, NULL);
return key->key;
}
@@ -279,7 +279,7 @@ vcard_emul_login(VCard *card, unsigned char *pin, int pin_len)
if (pin_string == NULL) {
return VCARD7816_STATUS_EXC_ERROR_MEMORY_FAILURE;
}
- memcpy(pin_string,pin,pin_len);
+ memcpy(pin_string, pin, pin_len);
pin_string[pin_len] = 0;
/* handle CAC expanded pins correctly */
@@ -325,8 +325,8 @@ vcard_emul_find_vreader_from_slot(PK11SlotInfo *slot)
if (reader_list == NULL) {
return NULL;
}
- for (current_entry= vreader_list_get_first(reader_list); current_entry;
- current_entry=vreader_list_get_next(current_entry)) {
+ for (current_entry = vreader_list_get_first(reader_list); current_entry;
+ current_entry = vreader_list_get_next(current_entry)) {
VReader *reader = vreader_list_get_reader(current_entry);
VReaderEmul *reader_emul = vreader_get_private(reader);
if (reader_emul->slot == slot) {
@@ -506,7 +506,7 @@ vcard_emul_mirror_card(VReader *vreader)
}
/* count the certs */
- cert_count=0;
+ cert_count = 0;
for (thisObj = firstObj; thisObj;
thisObj = PK11_GetNextGenericObject(thisObj)) {
cert_count++;
@@ -518,7 +518,7 @@ vcard_emul_mirror_card(VReader *vreader)
}
/* allocate the arrays */
- ret = vcard_emul_alloc_arrays(&certs,&cert_len, &keys, cert_count);
+ ret = vcard_emul_alloc_arrays(&certs, &cert_len, &keys, cert_count);
if (ret == PR_FALSE) {
return NULL;
}
@@ -615,7 +615,7 @@ vcard_emul_event_thread(void *arg)
vreader_emul->present = 0;
PK11_FreeSlot(slot);
vreader_free(vreader);
- } while(1);
+ } while (1);
}
/* if the card is inserted when we start up, make sure our state is correct */
@@ -639,7 +639,7 @@ vcard_emul_init_series(VReader *vreader, VCard *vcard)
static void
vcard_emul_new_event_thread(SECMODModule *module)
{
- PR_CreateThread(PR_SYSTEM_THREAD, vcard_emul_event_thread,
+ PR_CreateThread(PR_SYSTEM_THREAD, vcard_emul_event_thread,
module, PR_PRIORITY_HIGH, PR_GLOBAL_THREAD,
PR_UNJOINABLE_THREAD, 0);
}
@@ -730,7 +730,7 @@ module_has_removable_hw_slots(SECMODModule *mod)
return ret;
}
SECMOD_GetReadLock(moduleLock);
- for (i=0; i < mod->slotCount; i++) {
+ for (i = 0; i < mod->slotCount; i++) {
PK11SlotInfo *slot = mod->slots[i];
if (PK11_IsRemovable(slot) && PK11_IsHW(slot)) {
ret = PR_TRUE;
@@ -747,13 +747,13 @@ module_has_removable_hw_slots(SECMODModule *mod)
* recognized later. So Instead return FAIL only if no_hw==1 and no
* vcards can be created (indicates error with certificates provided
* or db), or if any other higher level error (NSS error, missing coolkey). */
-static int vcard_emul_init_called = 0;
+static int vcard_emul_init_called;
VCardEmulError
vcard_emul_init(const VCardEmulOptions *options)
{
SECStatus rv;
- PRBool ret, has_readers=PR_FALSE, need_coolkey_module;
+ PRBool ret, has_readers = PR_FALSE, need_coolkey_module;
VReader *vreader;
VReaderEmul *vreader_emul;
SECMODListLock *module_lock;
@@ -811,7 +811,7 @@ vcard_emul_init(const VCardEmulOptions *options)
continue;
}
cert_count = 0;
- for (j=0; j < options->vreader[i].cert_count; j++) {
+ for (j = 0; j < options->vreader[i].cert_count; j++) {
/* we should have a better way of identifying certs than by
* nickname here */
CERTCertificate *cert = PK11_FindCertFromNickname(
@@ -852,7 +852,7 @@ vcard_emul_init(const VCardEmulOptions *options)
need_coolkey_module = !has_readers;
SECMOD_GetReadLock(module_lock);
for (mlp = module_list; mlp; mlp = mlp->next) {
- SECMODModule * module = mlp->module;
+ SECMODModule *module = mlp->module;
if (module_has_removable_hw_slots(module)) {
need_coolkey_module = PR_FALSE;
break;
@@ -863,7 +863,7 @@ vcard_emul_init(const VCardEmulOptions *options)
if (need_coolkey_module) {
SECMODModule *module;
module = SECMOD_LoadUserModule(
- (char*)"library=libcoolkeypk11.so name=Coolkey",
+ (char *)"library=libcoolkeypk11.so name=Coolkey",
NULL, PR_FALSE);
if (module == NULL) {
return VCARD_EMUL_FAIL;
@@ -881,14 +881,14 @@ vcard_emul_init(const VCardEmulOptions *options)
SECMOD_GetReadLock(module_lock);
for (mlp = module_list; mlp; mlp = mlp->next) {
- SECMODModule * module = mlp->module;
+ SECMODModule *module = mlp->module;
PRBool has_emul_slots = PR_FALSE;
if (module == NULL) {
continue;
}
- for (i=0; i < module->slotCount; i++) {
+ for (i = 0; i < module->slotCount; i++) {
PK11SlotInfo *slot = module->slots[i];
/* only map removable HW slots */
@@ -932,8 +932,8 @@ vcard_emul_replay_insertion_events(void)
VReaderListEntry *next_entry = NULL;
VReaderList *list = vreader_get_reader_list();
- for (current_entry= vreader_list_get_first(list); current_entry;
- current_entry=next_entry) {
+ for (current_entry = vreader_list_get_first(list); current_entry;
+ current_entry = next_entry) {
VReader *vreader = vreader_list_get_reader(current_entry);
next_entry = vreader_list_get_next(current_entry);
vreader_queue_card_event(vreader);
@@ -959,7 +959,7 @@ count_tokens(const char *str, char token, char token_end)
{
int count = 0;
- for (;*str;str++) {
+ for (; *str; str++) {
if (*str == token) {
count++;
}
@@ -974,7 +974,7 @@ static const char *
find_token(const char *str, char token, char token_end)
{
/* just do the blind simple thing */
- for (;*str;str++) {
+ for (; *str; str++) {
if ((*str == token) || (*str == token_end)) {
break;
}
@@ -985,7 +985,7 @@ find_token(const char *str, char token, char token_end)
static const char *
strip(const char *str)
{
- for(;*str; str++) {
+ for (; *str; str++) {
if ((*str != ' ') && (*str != '\n') &&
(*str != '\t') && (*str != '\r')) {
break;
@@ -997,7 +997,7 @@ strip(const char *str)
static const char *
find_blank(const char *str)
{
- for(;*str; str++) {
+ for (; *str; str++) {
if ((*str == ' ') || (*str == '\n') ||
(*str == '\t') || (*str == '\r')) {
break;
@@ -1028,11 +1028,11 @@ vcard_emul_options(const char *args)
do {
args = strip(args); /* strip off the leading spaces */
if (*args == ',') {
- continue;
+ continue;
}
/* soft=(slot_name,virt_name,emul_type,emul_flags,cert_1, (no eol)
* cert_2,cert_3...) */
- if (strncmp(args,"soft=",5) == 0) {
+ if (strncmp(args, "soft=", 5) == 0) {
const char *name;
const char *vname;
const char *type_params;
@@ -1040,12 +1040,12 @@ vcard_emul_options(const char *args)
int name_length, vname_length, type_params_length, count, i;
VirtualReaderOptions *vreaderOpt = NULL;
- args = strip(args+5);
+ args = strip(args + 5);
if (*args != '(') {
continue;
}
name = args;
- args = find_token(args+1,',',')');
+ args = find_token(args + 1, ',', ')');
if (*args == 0) {
break;
}
@@ -1056,7 +1056,7 @@ vcard_emul_options(const char *args)
args = strip(args+1);
name_length = args - name - 2;
vname = args;
- args = find_token(args+1,',',')');
+ args = find_token(args + 1, ',', ')');
if (*args == 0) {
break;
}
@@ -1066,12 +1066,12 @@ vcard_emul_options(const char *args)
}
vname_length = args - name - 2;
args = strip(args+1);
- type_len = find_token(args,',',')') - args;
+ type_len = find_token(args, ',', ')') - args;
assert(sizeof(type_str) > type_len);
strncpy(type_str, args, type_len);
type_str[type_len] = 0;
type = vcard_emul_type_from_string(type_str);
- args = find_token(args,',',')');
+ args = find_token(args, ',', ')');
if (*args == 0) {
break;
}
@@ -1080,8 +1080,8 @@ vcard_emul_options(const char *args)
continue;
}
args = strip(args++);
- type_params=args;
- args = find_token(args+1,',',')');
+ type_params = args;
+ args = find_token(args + 1, ',', ')');
if (*args == 0) {
break;
}
@@ -1098,7 +1098,7 @@ vcard_emul_options(const char *args)
if (opts->vreader_count >= reader_count) {
reader_count += READER_STEP;
vreaderOpt = realloc(opts->vreader,
- reader_count*sizeof(*vreaderOpt));
+ reader_count * sizeof(*vreaderOpt));
if (vreaderOpt == NULL) {
return opts; /* we're done */
}
@@ -1108,11 +1108,12 @@ vcard_emul_options(const char *args)
vreaderOpt->name = copy_string(name, name_length);
vreaderOpt->vname = copy_string(vname, vname_length);
vreaderOpt->card_type = type;
- vreaderOpt->type_params = copy_string(type_params, type_params_length);
- count = count_tokens(args,',',')');
+ vreaderOpt->type_params =
+ copy_string(type_params, type_params_length);
+ count = count_tokens(args, ',', ')');
vreaderOpt->cert_count = count;
vreaderOpt->cert_name = (char **)malloc(count*sizeof(char *));
- for (i=0; i < count; i++) {
+ for (i = 0; i < count; i++) {
const char *cert = args + 1;
args = find_token(args + 1, ',', ')');
vreaderOpt->cert_name[i] = copy_string(cert, args - cert);
@@ -1122,7 +1123,7 @@ vcard_emul_options(const char *args)
}
opts->vreader_count++;
/* use_hw= */
- } else if (strncmp(args,"use_hw=",7) == 0) {
+ } else if (strncmp(args, "use_hw=", 7) == 0) {
args = strip(args+7);
if (*args == '0' || *args == 'N' || *args == 'n' || *args == 'F') {
opts->use_hw = PR_FALSE;
@@ -1131,19 +1132,19 @@ vcard_emul_options(const char *args)
}
args = find_blank(args);
/* hw_type= */
- } else if (strncmp(args,"hw_type=",8) == 0) {
+ } else if (strncmp(args, "hw_type=", 8) == 0) {
args = strip(args+8);
opts->hw_card_type = vcard_emul_type_from_string(args);
args = find_blank(args);
/* hw_params= */
- } else if (strncmp(args,"hw_params=",10) == 0) {
+ } else if (strncmp(args, "hw_params=", 10) == 0) {
const char *params;
args = strip(args+10);
- params= args;
+ params = args;
args = find_blank(args);
opts->hw_type_params = copy_string(params, args-params);
/* db="/data/base/path" */
- } else if (strncmp(args,"db=",3) == 0) {
+ } else if (strncmp(args, "db=", 3) == 0) {
const char *db;
args = strip(args+3);
if (*args != '"') {
@@ -1152,11 +1153,13 @@ vcard_emul_options(const char *args)
args++;
db = args;
args = find_token(args, '"', '\n');
- opts->nss_db = copy_string(db,args-db);
+ opts->nss_db = copy_string(db, args-db);
if (*args != 0) {
args++;
}
- } else args = find_blank(args);
+ } else {
+ args = find_blank(args);
+ }
} while (*args != 0);
return opts;
@@ -1184,7 +1187,7 @@ vcard_emul_usage(void)
"These parameters come as a single string separated by blanks or newlines."
"\n"
"Unless use_hw is set to no, all tokens that look like removable hardware\n"
-"tokens will be presented to the guest using the emulator specified by \n"
+"tokens will be presented to the guest using the emulator specified by\n"
"hw_type, and parameters of hw_param.\n"
"\n"
"If more one or more soft= parameters are specified, these readers will be\n"
diff --git a/vcard_emul_type.c b/vcard_emul_type.c
index adbc54b..d0af45b 100644
--- a/vcard_emul_type.c
+++ b/vcard_emul_type.c
@@ -12,7 +12,7 @@
#include "passthru.h"
VCardStatus vcard_init(VReader *vreader, VCard *vcard,
- VCardEmulType type, const char * params,
+ VCardEmulType type, const char *params,
unsigned char *const *cert, int cert_len[],
VCardKey *key[], int cert_count)
{
@@ -48,11 +48,11 @@ VCardEmulType vcard_emul_type_select(VReader *vreader)
VCardEmulType vcard_emul_type_from_string(const char *type_string)
{
- if (strcasecmp(type_string,"CAC") == 0) {
+ if (strcasecmp(type_string, "CAC") == 0) {
return VCARD_EMUL_CAC;
}
#ifdef USE_PASSTHRU
- if (strcasecmp(type_string,"PASSTHRU") == 0) {
+ if (strcasecmp(type_string, "PASSTHRU") == 0) {
return VCARD_EMUL_PASSTHRU;
}
#endif
diff --git a/vcard_emul_type.h b/vcard_emul_type.h
index 34fb3c1..241c1d0 100644
--- a/vcard_emul_type.h
+++ b/vcard_emul_type.h
@@ -1,7 +1,8 @@
/*
- * This header file abstracts the different card types. The goal is new card types can easily
- * be added by simply changing this file and vcard_emul_type.c. It is currently not a requirement
- * to dynamically add new card types.
+ * This header file abstracts the different card types. The goal is new card
+ * types can easily be added by simply changing this file and
+ * vcard_emul_type.c. It is currently not a requirement to dynamically add new
+ * card types.
*/
#ifndef VCARD_EMUL_TYPE_H
@@ -13,15 +14,15 @@
* types
*/
typedef enum {
- VCARD_EMUL_NONE =0,
+ VCARD_EMUL_NONE = 0,
VCARD_EMUL_CAC,
VCARD_EMUL_PASSTHRU
} VCardEmulType;
/* functions used by the rest of the emulator */
-VCardStatus vcard_init(VReader *vreader, VCard *vcard, VCardEmulType type, const char *params,
- unsigned char * const *cert, int cert_len[], VCardKey *key[],
- int cert_count);
+VCardStatus vcard_init(VReader *vreader, VCard *vcard, VCardEmulType type,
+ const char *params, unsigned char * const *cert,
+ int cert_len[], VCardKey *key[], int cert_count);
VCardEmulType vcard_emul_type_select(VReader *vreader);
VCardEmulType vcard_emul_type_from_string(const char *type_string);
diff --git a/vcardt.h b/vcardt.h
index e371451..8bca16e 100644
--- a/vcardt.h
+++ b/vcardt.h
@@ -12,8 +12,8 @@
#define ASSERT assert
#endif
#ifndef MIN
-#define MIN(x,y) ((x)>(y)?(y):(x))
-#define MAX(x,y) ((x)>(y)?(x):(y))
+#define MIN(x, y) ((x) > (y) ? (y) : (x))
+#define MAX(x, y) ((x) > (y) ? (x) : (y))
#endif
typedef struct VCardStruct VCard;
diff --git a/vreader.c b/vreader.c
index 5e46019..f4a0c60 100644
--- a/vreader.c
+++ b/vreader.c
@@ -182,7 +182,7 @@ vreader_reset(VReader *reader, VCardPower power, unsigned char *atr, int *len)
VReaderStatus
vreader_power_on(VReader *reader, unsigned char *atr, int *len)
{
- return vreader_reset(reader, VCARD_POWER_ON, atr, len );
+ return vreader_reset(reader, VCARD_POWER_ON, atr, len);
}
VReaderStatus
@@ -284,8 +284,8 @@ vreader_list_delete(VReaderList *list)
{
VReaderListEntry *current_entry;
VReaderListEntry *next_entry = NULL;
- for (current_entry= vreader_list_get_first(list); current_entry;
- current_entry=next_entry) {
+ for (current_entry = vreader_list_get_first(list); current_entry;
+ current_entry = next_entry) {
next_entry = vreader_list_get_next(current_entry);
vreader_list_entry_delete(current_entry);
}
@@ -349,7 +349,7 @@ vreader_dequeue(VReaderList *list, VReaderListEntry *entry)
entry->next = entry->prev = NULL;
}
-static VReaderList *vreader_list = NULL;
+static VReaderList *vreader_list;
static mutex_t vreader_list_mutex;
static void
@@ -381,8 +381,8 @@ vreader_copy_list(VReaderList *list)
if (new_list == NULL) {
return NULL;
}
- for (current_entry= vreader_list_get_first(list); current_entry;
- current_entry=vreader_list_get_next(current_entry)) {
+ for (current_entry = vreader_list_get_first(list); current_entry;
+ current_entry = vreader_list_get_next(current_entry)) {
VReader *reader = vreader_list_get_reader(current_entry);
VReaderListEntry *new_entry = vreader_list_entry_new(reader);
@@ -471,8 +471,8 @@ vreader_remove_reader(VReader *reader)
VReaderListEntry *current_entry;
vreader_list_lock();
- for (current_entry= vreader_list_get_first(vreader_list); current_entry;
- current_entry=vreader_list_get_next(current_entry)) {
+ for (current_entry = vreader_list_get_first(vreader_list); current_entry;
+ current_entry = vreader_list_get_next(current_entry)) {
if (current_entry->reader == reader) {
break;
}
diff --git a/vreadert.h b/vreadert.h
index 4c01259..51670a3 100644
--- a/vreadert.h
+++ b/vreadert.h
@@ -6,7 +6,7 @@
#define VREADERT_H 1
typedef enum {
- VREADER_OK=0,
+ VREADER_OK = 0,
VREADER_NO_CARD,
VREADER_OUT_OF_MEMORY
} VReaderStatus;
diff --git a/vscard_common.h b/vscard_common.h
index 5cb6eb5..59bcb68 100644
--- a/vscard_common.h
+++ b/vscard_common.h
@@ -15,7 +15,7 @@
*
* Copyright (c) 2011 Red Hat.
*
- * This code is licensed under the LGPL.
+ * This code is licensed under the GNU LGPL, version 2 or later.
*/
#ifndef VSCARD_COMMON_H
@@ -28,9 +28,9 @@
#define VERSION_MINOR_BITS 10
#define MAKE_VERSION(major, middle, minor) \
- ( (major << (VERSION_MINOR_BITS + VERSION_MIDDLE_BITS)) \
+ ((major << (VERSION_MINOR_BITS + VERSION_MIDDLE_BITS)) \
| (middle << VERSION_MINOR_BITS) \
- | (minor) )
+ | (minor))
/** IMPORTANT NOTE on VERSION
*
@@ -45,7 +45,7 @@
* something that cannot be accomodated with the existing protocol.
*/
-#define VSCARD_VERSION MAKE_VERSION(0,0,2)
+#define VSCARD_VERSION MAKE_VERSION(0, 0, 2)
typedef enum VSCMsgType {
VSC_Init = 1,
@@ -60,8 +60,8 @@ typedef enum VSCMsgType {
} VSCMsgType;
typedef enum VSCErrorCode {
- VSC_SUCCESS=0,
- VSC_GENERAL_ERROR=1,
+ VSC_SUCCESS = 0,
+ VSC_GENERAL_ERROR = 1,
VSC_CANNOT_ADD_MORE_READERS,
VSC_CARD_ALREAY_INSERTED,
} VSCErrorCode;
@@ -69,7 +69,7 @@ typedef enum VSCErrorCode {
#define VSCARD_UNDEFINED_READER_ID 0xffffffff
#define VSCARD_MINIMAL_READER_ID 0
-#define VSCARD_MAGIC (*(uint32_t*)"VSCD")
+#define VSCARD_MAGIC (*(uint32_t *)"VSCD")
/* Header
* Each message starts with the header.
diff --git a/vscclient.c b/vscclient.c
index f29fd6b..f8edf14 100644
--- a/vscclient.c
+++ b/vscclient.c
@@ -30,29 +30,29 @@
#include "mutex.h"
-int verbose = 0;
+int verbose;
int sock;
static void
-print_byte_array (
+print_byte_array(
uint8_t *arrBytes,
unsigned int nSize
) {
int i;
- for (i=0; i < nSize; i++) {
- printf ("%02X ", arrBytes[i]);
+ for (i = 0; i < nSize; i++) {
+ printf("%02X ", arrBytes[i]);
}
- printf ("\n");
+ printf("\n");
}
static void
-print_usage (void) {
- printf ("vscclient [-c <certname> .. -e <emul_args> -d <level>%s] "
- "<host> <port> \n",
+print_usage(void) {
+ printf("vscclient [-c <certname> .. -e <emul_args> -d <level>%s] "
+ "<host> <port>\n",
#ifdef USE_PASSTHRU
" -p");
- printf (" -p use passthrough mode\n");
+ printf(" -p use passthrough mode\n");
#else
"");
#endif
@@ -62,7 +62,7 @@ print_usage (void) {
static mutex_t write_lock;
static int
-send_msg (
+send_msg(
VSCMsgType type,
uint32_t reader_id,
const void *msg,
@@ -81,36 +81,36 @@ send_msg (
mhHeader.type = htonl(type);
mhHeader.reader_id = 0;
mhHeader.length = htonl(length);
- rv = write (
+ rv = write(
sock,
&mhHeader,
- sizeof (mhHeader)
+ sizeof(mhHeader)
);
if (rv < 0) {
/* Error */
- printf ("write header error\n");
- close (sock);
+ printf("write header error\n");
+ close(sock);
MUTEX_UNLOCK(write_lock);
- return (16);
+ return 16;
}
- rv = write (
+ rv = write(
sock,
msg,
length
);
if (rv < 0) {
/* Error */
- printf ("write error\n");
- close (sock);
+ printf("write error\n");
+ close(sock);
MUTEX_UNLOCK(write_lock);
- return (16);
+ return 16;
}
MUTEX_UNLOCK(write_lock);
- return (0);
+ return 0;
}
-static VReader *pending_reader = NULL;
+static VReader *pending_reader;
static mutex_t pending_reader_lock;
static condition_t pending_reader_condition;
@@ -118,7 +118,7 @@ static condition_t pending_reader_condition;
static void *
event_thread(void *arg)
{
- unsigned char atr[ MAX_ATR_LEN];
+ unsigned char atr[MAX_ATR_LEN];
int atr_len = MAX_ATR_LEN;
VEvent *event = NULL;
unsigned int reader_id;
@@ -148,7 +148,7 @@ event_thread(void *arg)
/* this reader hasn't been told it's status from qemu yet, wait for
* that status */
while (pending_reader != NULL) {
- CONDITION_WAIT(pending_reader_condition,pending_reader_lock);
+ CONDITION_WAIT(pending_reader_condition, pending_reader_lock);
}
MUTEX_UNLOCK(pending_reader_lock);
/* now recheck the id */
@@ -168,15 +168,15 @@ event_thread(void *arg)
* */
MUTEX_LOCK(pending_reader_lock);
while (pending_reader != NULL) {
- CONDITION_WAIT(pending_reader_condition,pending_reader_lock);
+ CONDITION_WAIT(pending_reader_condition, pending_reader_lock);
}
pending_reader = vreader_reference(event->reader);
MUTEX_UNLOCK(pending_reader_lock);
reader_name = vreader_get_name(event->reader);
if (verbose > 10) {
- printf (" READER INSERT: %s\n", reader_name);
+ printf(" READER INSERT: %s\n", reader_name);
}
- send_msg (
+ send_msg(
VSC_ReaderAdd,
reader_id, /* currerntly VSCARD_UNDEFINED_READER_ID */
NULL, 0
@@ -188,7 +188,7 @@ event_thread(void *arg)
case VEVENT_READER_REMOVE:
/* future, tell qemu that an old CCID reader has been removed */
if (verbose > 10) {
- printf (" READER REMOVE: %d \n", reader_id);
+ printf(" READER REMOVE: %d\n", reader_id);
}
send_msg(
VSC_ReaderRemove,
@@ -204,10 +204,10 @@ event_thread(void *arg)
vreader_power_on(event->reader, atr, &atr_len);
/* ATR call functions as a Card Insert event */
if (verbose > 10) {
- printf (" CARD INSERT %d: ", reader_id);
- print_byte_array (atr, atr_len);
+ printf(" CARD INSERT %d: ", reader_id);
+ print_byte_array(atr, atr_len);
}
- send_msg (
+ send_msg(
VSC_ATR,
reader_id,
atr,
@@ -215,11 +215,11 @@ event_thread(void *arg)
);
break;
case VEVENT_CARD_REMOVE:
- // Card removed
+ /* Card removed */
if (verbose > 10) {
- printf (" CARD REMOVE %d: \n", reader_id);
+ printf(" CARD REMOVE %d:\n", reader_id);
}
- send_msg (
+ send_msg(
VSC_CardRemove,
reader_id,
NULL,
@@ -253,14 +253,14 @@ do_command(void)
char inbuf[255];
char *string;
VCardEmulError error;
- static unsigned int default_reader_id = 0;
+ static unsigned int default_reader_id;
unsigned int reader_id;
VReader *reader = NULL;
reader_id = default_reader_id;
string = fgets(inbuf, sizeof(inbuf), stdin);
if (string != NULL) {
- if (strncmp(string,"exit",4) == 0) {
+ if (strncmp(string, "exit", 4) == 0) {
/* remove all the readers */
VReaderList *list = vreader_get_reader_list();
VReaderListEntry *reader_entry;
@@ -269,21 +269,21 @@ do_command(void)
reader_entry = vreader_list_get_next(reader_entry)) {
VReader *reader = vreader_list_get_reader(reader_entry);
vreader_id_t reader_id;
- reader_id=vreader_get_id(reader);
+ reader_id = vreader_get_id(reader);
if (reader_id == -1) {
continue;
}
/* be nice and signal card removal first (qemu probably should
* do this itself) */
if (vreader_card_is_present(reader) == VREADER_OK) {
- send_msg (
+ send_msg(
VSC_CardRemove,
reader_id,
NULL,
0
);
}
- send_msg (
+ send_msg(
VSC_ReaderRemove,
reader_id,
NULL,
@@ -291,7 +291,7 @@ do_command(void)
);
}
exit(0);
- } else if (strncmp(string,"insert",6) == 0) {
+ } else if (strncmp(string, "insert", 6) == 0) {
if (string[6] == ' ') {
reader_id = get_id_from_string(&string[7], reader_id);
}
@@ -304,7 +304,7 @@ do_command(void)
} else {
printf("no reader by id %d found\n", reader_id);
}
- } else if (strncmp(string,"remove",6) == 0) {
+ } else if (strncmp(string, "remove", 6) == 0) {
if (string[6] == ' ') {
reader_id = get_id_from_string(&string[7], reader_id);
}
@@ -317,7 +317,7 @@ do_command(void)
} else {
printf("no reader by id %d found\n", reader_id);
}
- } else if (strncmp(string,"select",6) == 0) {
+ } else if (strncmp(string, "select", 6) == 0) {
if (string[6] == ' ') {
reader_id = get_id_from_string(&string[7],
VSCARD_UNDEFINED_READER_ID);
@@ -332,12 +332,12 @@ do_command(void)
} else {
printf("Reader with id %d not found\n", reader_id);
}
- } else if (strncmp(string,"debug",5) == 0) {
+ } else if (strncmp(string, "debug", 5) == 0) {
if (string[5] == ' ') {
- verbose = get_id_from_string(&string[6],0);
+ verbose = get_id_from_string(&string[6], 0);
}
- printf ("debug level = %d\n", verbose);
- } else if (strncmp(string,"list",4) == 0) {
+ printf("debug level = %d\n", verbose);
+ } else if (strncmp(string, "list", 4) == 0) {
VReaderList *list = vreader_get_reader_list();
VReaderListEntry *reader_entry;
printf("Active Readers:\n");
@@ -345,13 +345,13 @@ do_command(void)
reader_entry = vreader_list_get_next(reader_entry)) {
VReader *reader = vreader_list_get_reader(reader_entry);
vreader_id_t reader_id;
- reader_id=vreader_get_id(reader);
+ reader_id = vreader_get_id(reader);
if (reader_id == -1) {
continue;
}
- printf("%3d %s %s\n",reader_id,
+ printf("%3d %s %s\n", reader_id,
vreader_card_is_present(reader) == VREADER_OK ?
- "CARD_PRESENT": " ",
+ "CARD_PRESENT" : " ",
vreader_get_name(reader));
}
printf("Inactive Readers:\n");
@@ -359,18 +359,18 @@ do_command(void)
reader_entry = vreader_list_get_next(reader_entry)) {
VReader *reader = vreader_list_get_reader(reader_entry);
vreader_id_t reader_id;
- reader_id=vreader_get_id(reader);
+ reader_id = vreader_get_id(reader);
if (reader_id != -1) {
continue;
}
printf("INA %s %s\n",
vreader_card_is_present(reader) == VREADER_OK ?
- "CARD_PRESENT": " ",
+ "CARD_PRESENT" : " ",
vreader_get_name(reader));
}
} else if (*string != 0) {
- printf("valid commands: \n");
+ printf("valid commands:\n");
printf("insert [reader_id]\n");
printf("remove [reader_id]\n");
printf("select reader_id\n");
@@ -387,26 +387,26 @@ do_command(void)
#define APDUBufSize 270
-// just for ease of parsing command line arguments.
+/* just for ease of parsing command line arguments. */
#define MAX_CERTS 100
static int
-connect_to_qemu (
+connect_to_qemu(
const char *host,
const char *port
) {
struct addrinfo hints;
- struct addrinfo* server;
+ struct addrinfo *server;
int ret;
- sock = socket (
+ sock = socket(
AF_INET,
SOCK_STREAM,
0
);
if (sock < 0) {
- // Error
- printf ("Error opening socket!\n");
+ /* Error */
+ printf("Error opening socket!\n");
}
memset(&hints, 0, sizeof(struct addrinfo));
@@ -418,22 +418,22 @@ connect_to_qemu (
ret = getaddrinfo(host, port, &hints, &server);
if (ret != 0) {
- printf ("getaddrinfo failed\n");
- return (5);
+ printf("getaddrinfo failed\n");
+ return 5;
}
- if (connect (
+ if (connect(
sock,
server->ai_addr,
server->ai_addrlen
) < 0
) {
- // Error
- printf ("Could not connect\n");
- return (5);
+ /* Error */
+ printf("Could not connect\n");
+ return 5;
}
if (verbose) {
- printf ("Connected (sizeof Header=%zd)!\n", sizeof (VSCMsgHeader));
+ printf("Connected (sizeof Header=%zd)!\n", sizeof(VSCMsgHeader));
}
return sock;
}
@@ -441,7 +441,8 @@ connect_to_qemu (
static int on_host_init(VSCMsgHeader *mhHeader, VSCMsgInit *incoming)
{
uint32_t *capabilities = (incoming->capabilities);
- int num_capabilities = 1 + ((mhHeader->length - sizeof(VSCMsgInit)) / sizeof(uint32_t));
+ int num_capabilities =
+ 1 + ((mhHeader->length - sizeof(VSCMsgInit)) / sizeof(uint32_t));
int i;
int rv;
pthread_t thread_id;
@@ -481,12 +482,12 @@ static int on_host_init(VSCMsgHeader *mhHeader, VSCMsgInit *incoming)
}
int
-main (
+main(
int argc,
char *argv[]
) {
- char* qemu_host;
- char* qemu_port;
+ char *qemu_host;
+ char *qemu_port;
VSCMsgHeader mhHeader;
VSCMsgError *error_msg;
@@ -500,40 +501,40 @@ main (
VCardEmulOptions *command_line_options = NULL;
int passthru = 0;
- char* cert_names[MAX_CERTS];
- char* emul_args = NULL;
+ char *cert_names[MAX_CERTS];
+ char *emul_args = NULL;
int cert_count = 0;
int c;
while ((c = getopt(argc, argv, "c:e:pd:")) != -1) {
switch (c) {
- case 'c':
- if (cert_count >= MAX_CERTS) {
- printf("too many certificates (max = %d)\n", MAX_CERTS);
- exit (5);
- }
- cert_names[cert_count++] = optarg;
- break;
- case 'e':
- emul_args = optarg;
- break;
- case 'p':
+ case 'c':
+ if (cert_count >= MAX_CERTS) {
+ printf("too many certificates (max = %d)\n", MAX_CERTS);
+ exit(5);
+ }
+ cert_names[cert_count++] = optarg;
+ break;
+ case 'e':
+ emul_args = optarg;
+ break;
+ case 'p':
#ifdef USE_PASSTHRU
- passthru = 1;
+ passthru = 1;
#else
- print_usage();
- exit(4);
+ print_usage();
+ exit(4);
#endif
- break;
- case 'd':
- verbose = get_id_from_string(optarg,1);
- break;
+ break;
+ case 'd':
+ verbose = get_id_from_string(optarg, 1);
+ break;
}
}
if (argc - optind != 2) {
print_usage();
- exit (4);
+ exit(4);
}
if (!passthru && cert_count > 0) {
@@ -543,22 +544,22 @@ main (
* software emulation. add that emulation now. this is NSS Emulator
* specific */
if (emul_args == NULL) {
- emul_args = (char*)"db=\"/etc/pki/nssdb\"";
+ emul_args = (char *)"db=\"/etc/pki/nssdb\"";
}
#define SOFT_STRING ",soft=(,Virtual Reader,CAC,,"
/* 2 == close paren & null */
len = strlen(emul_args) + strlen(SOFT_STRING) + 2;
- for (i=0; i < cert_count; i++) {
- len +=strlen(cert_names[i])+1; /* 1 == comma */
+ for (i = 0; i < cert_count; i++) {
+ len += strlen(cert_names[i])+1; /* 1 == comma */
}
new_args = malloc(len);
- strcpy(new_args,emul_args);
- strcat(new_args,SOFT_STRING);
- for (i=0; i < cert_count; i++) {
- strcat(new_args,cert_names[i]);
- strcat(new_args,",");
+ strcpy(new_args, emul_args);
+ strcat(new_args, SOFT_STRING);
+ for (i = 0; i < cert_count; i++) {
+ strcat(new_args, cert_names[i]);
+ strcat(new_args, ",");
}
- strcat(new_args,")");
+ strcat(new_args, ")");
emul_args = new_args;
}
if (emul_args) {
@@ -571,7 +572,7 @@ main (
}
qemu_host = strdup(argv[argc - 2]);
- qemu_port = strdup(argv[argc -1]);
+ qemu_port = strdup(argv[argc - 1]);
sock = connect_to_qemu(qemu_host, qemu_port);
MUTEX_INIT(write_lock);
@@ -590,9 +591,9 @@ main (
/* Send init message, Host responds (and then we send reader attachments) */
VSCMsgInit init = {
- .version=htonl(VSCARD_VERSION),
- .magic=VSCARD_MAGIC,
- .capabilities={0}
+ .version = htonl(VSCARD_VERSION),
+ .magic = VSCARD_MAGIC,
+ .capabilities = {0}
};
send_msg(VSC_Init, mhHeader.reader_id, &init, sizeof(init));
@@ -600,144 +601,144 @@ main (
fd_set fds;
FD_ZERO(&fds);
- FD_SET(1,&fds);
- FD_SET(sock,&fds);
+ FD_SET(1, &fds);
+ FD_SET(sock, &fds);
/* waiting on input from the socket */
rv = select(sock+1, &fds, NULL, NULL, NULL);
if (rv < 0) {
/* handle error */
perror("select");
- return (7);
+ return 7;
}
- if (FD_ISSET(1,&fds)) {
+ if (FD_ISSET(1, &fds)) {
do_command();
}
- if (!FD_ISSET(sock,&fds)) {
+ if (!FD_ISSET(sock, &fds)) {
continue;
}
- rv = read (
+ rv = read(
sock,
&mhHeader,
- sizeof (mhHeader)
+ sizeof(mhHeader)
);
if (rv < sizeof(mhHeader)) {
/* Error */
if (rv < 0) {
perror("header read error\n");
} else {
- printf ("header short read %d\n", rv);
+ printf("header short read %d\n", rv);
}
- return (8);
+ return 8;
}
mhHeader.type = ntohl(mhHeader.type);
mhHeader.reader_id = ntohl(mhHeader.reader_id);
mhHeader.length = ntohl(mhHeader.length);
if (verbose) {
- printf ("Header: type=%d, reader_id=%d length=%d (0x%x)\n",
+ printf("Header: type=%d, reader_id=%d length=%d (0x%x)\n",
mhHeader.type, mhHeader.reader_id, mhHeader.length,
mhHeader.length);
}
switch (mhHeader.type) {
- case VSC_APDU:
- case VSC_Flush:
- case VSC_Error:
- case VSC_Init:
- rv = read (
- sock,
- pbSendBuffer,
- mhHeader.length
- );
- break;
- default:
- printf ("Unexpected message of type 0x%X\n", mhHeader.type);
- return 0;
+ case VSC_APDU:
+ case VSC_Flush:
+ case VSC_Error:
+ case VSC_Init:
+ rv = read(
+ sock,
+ pbSendBuffer,
+ mhHeader.length
+ );
+ break;
+ default:
+ printf("Unexpected message of type 0x%X\n", mhHeader.type);
+ return 0;
}
switch (mhHeader.type) {
- case VSC_APDU:
- if (rv < 0) {
- /* Error */
- printf ("read error\n");
- close (sock);
- return (8);
- }
+ case VSC_APDU:
+ if (rv < 0) {
+ /* Error */
+ printf("read error\n");
+ close(sock);
+ return 8;
+ }
+ if (verbose) {
+ printf(" recv APDU: ");
+ print_byte_array(pbSendBuffer, mhHeader.length);
+ }
+ /* Transmit recieved APDU */
+ dwSendLength = mhHeader.length;
+ dwRecvLength = sizeof(pbRecvBuffer);
+ reader = vreader_get_reader_by_id(mhHeader.reader_id);
+ reader_status = vreader_xfr_bytes(reader,
+ pbSendBuffer, dwSendLength,
+ pbRecvBuffer, &dwRecvLength);
+ if (reader_status == VREADER_OK) {
+ mhHeader.length = dwRecvLength;
if (verbose) {
- printf (" recv APDU: ");
- print_byte_array (pbSendBuffer, mhHeader.length);
- }
- /* Transmit recieved APDU */
- dwSendLength = mhHeader.length;
- dwRecvLength = sizeof(pbRecvBuffer);
- reader = vreader_get_reader_by_id(mhHeader.reader_id);
- reader_status = vreader_xfr_bytes(reader,
- pbSendBuffer, dwSendLength,
- pbRecvBuffer, &dwRecvLength);
- if (reader_status == VREADER_OK) {
- mhHeader.length = dwRecvLength;
- if (verbose) {
- printf (" send response: ");
- print_byte_array (pbRecvBuffer, mhHeader.length);
- }
- send_msg (
- VSC_APDU,
- mhHeader.reader_id,
- pbRecvBuffer,
- dwRecvLength
- );
- } else {
- rv = reader_status; /* warning: not meaningful */
- send_msg (
- VSC_Error,
- mhHeader.reader_id,
- &rv,
- sizeof (uint32_t)
- );
- }
- vreader_free(reader);
- reader = NULL; /* we've freed it, don't use it by accident
- again */
- break;
- case VSC_Flush:
- /* TODO: actually flush */
- send_msg(VSC_FlushComplete, mhHeader.reader_id, NULL, 0);
- break;
- case VSC_Error:
- error_msg = (VSCMsgError *) pbSendBuffer;
- if (error_msg->code == VSC_SUCCESS) {
- MUTEX_LOCK(pending_reader_lock);
- if (pending_reader) {
- vreader_set_id(pending_reader, mhHeader.reader_id);
- vreader_free(pending_reader);
- pending_reader = NULL;
- CONDITION_NOTIFY(pending_reader_condition);
- }
- MUTEX_UNLOCK(pending_reader_lock);
- break;
+ printf(" send response: ");
+ print_byte_array(pbRecvBuffer, mhHeader.length);
}
- printf("error: qemu refused to add reader\n");
- if (error_msg->code == VSC_CANNOT_ADD_MORE_READERS) {
- /* clear pending reader, qemu can't handle any more */
- MUTEX_LOCK(pending_reader_lock);
- if (pending_reader) {
- pending_reader = NULL;
- /* make sure the event loop doesn't hang */
- CONDITION_NOTIFY(pending_reader_condition);
- }
- MUTEX_UNLOCK(pending_reader_lock);
+ send_msg(
+ VSC_APDU,
+ mhHeader.reader_id,
+ pbRecvBuffer,
+ dwRecvLength
+ );
+ } else {
+ rv = reader_status; /* warning: not meaningful */
+ send_msg(
+ VSC_Error,
+ mhHeader.reader_id,
+ &rv,
+ sizeof(uint32_t)
+ );
+ }
+ vreader_free(reader);
+ reader = NULL; /* we've freed it, don't use it by accident
+ again */
+ break;
+ case VSC_Flush:
+ /* TODO: actually flush */
+ send_msg(VSC_FlushComplete, mhHeader.reader_id, NULL, 0);
+ break;
+ case VSC_Error:
+ error_msg = (VSCMsgError *) pbSendBuffer;
+ if (error_msg->code == VSC_SUCCESS) {
+ MUTEX_LOCK(pending_reader_lock);
+ if (pending_reader) {
+ vreader_set_id(pending_reader, mhHeader.reader_id);
+ vreader_free(pending_reader);
+ pending_reader = NULL;
+ CONDITION_NOTIFY(pending_reader_condition);
}
+ MUTEX_UNLOCK(pending_reader_lock);
break;
- case VSC_Init:
- if (on_host_init(&mhHeader, (VSCMsgInit*)pbSendBuffer) < 0) {
- return -1;
+ }
+ printf("error: qemu refused to add reader\n");
+ if (error_msg->code == VSC_CANNOT_ADD_MORE_READERS) {
+ /* clear pending reader, qemu can't handle any more */
+ MUTEX_LOCK(pending_reader_lock);
+ if (pending_reader) {
+ pending_reader = NULL;
+ /* make sure the event loop doesn't hang */
+ CONDITION_NOTIFY(pending_reader_condition);
}
- break;
- default:
- printf ("Default\n");
- return 0;
+ MUTEX_UNLOCK(pending_reader_lock);
+ }
+ break;
+ case VSC_Init:
+ if (on_host_init(&mhHeader, (VSCMsgInit *)pbSendBuffer) < 0) {
+ return -1;
+ }
+ break;
+ default:
+ printf("Default\n");
+ return 0;
}
} while (rv >= 0);
- return (0);
+ return 0;
}