summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlon Levy <alevy@redhat.com>2011-02-03 20:51:01 +0200
committerAlon Levy <alevy@redhat.com>2011-02-10 10:34:32 +0200
commitb05c744f4a9b121ae9849266bbc84f8c0dd79721 (patch)
tree829fceaac1e1ab5fc9f5acb909e511344141064f
parentd7cf75f68c92c7dcc1157fdb59f617eaf221fd1d (diff)
downloadspice-b05c744f4a9b121ae9849266bbc84f8c0dd79721.tar.gz
spice-b05c744f4a9b121ae9849266bbc84f8c0dd79721.tar.xz
spice-b05c744f4a9b121ae9849266bbc84f8c0dd79721.zip
server/smartcard: libcacard uses network byte order, so we must too
-rw-r--r--server/smartcard.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/server/smartcard.c b/server/smartcard.c
index 8af87d81..db6ad68f 100644
--- a/server/smartcard.c
+++ b/server/smartcard.c
@@ -1,3 +1,5 @@
+#include <arpa/inet.h>
+
#include "server/char_device.h"
#include "server/red_channel.h"
#include "server/smartcard.h"
@@ -67,6 +69,7 @@ void smartcard_char_device_wakeup(SpiceCharDeviceInstance *sin)
VSCMsgHeader *vheader = (VSCMsgHeader*)state->buf;
int n;
int remaining;
+ int actual_length;
while ((n = sif->read(sin, state->buf_pos, state->buf_size - state->buf_used)) > 0) {
state->buf_pos += n;
@@ -74,16 +77,17 @@ void smartcard_char_device_wakeup(SpiceCharDeviceInstance *sin)
if (state->buf_used < sizeof(VSCMsgHeader)) {
continue;
}
- if (vheader->length > state->buf_size) {
- state->buf_size = MAX(state->buf_size*2, vheader->length + sizeof(VSCMsgHeader));
+ actual_length = ntohl(vheader->length);
+ if (actual_length > state->buf_size) {
+ state->buf_size = MAX(state->buf_size*2, actual_length + sizeof(VSCMsgHeader));
state->buf = spice_realloc(state->buf, state->buf_size);
ASSERT(state->buf != NULL);
}
- if (state->buf_used - sizeof(VSCMsgHeader) < vheader->length) {
+ if (state->buf_used - sizeof(VSCMsgHeader) < actual_length) {
continue;
}
smartcard_char_device_on_message_from_device(state, vheader);
- remaining = state->buf_used - sizeof(VSCMsgHeader) > vheader->length;
+ remaining = state->buf_used - sizeof(VSCMsgHeader) > actual_length;
if (remaining > 0) {
memcpy(state->buf, state->buf_pos, remaining);
}
@@ -98,6 +102,10 @@ void smartcard_char_device_on_message_from_device(
{
VSCMsgHeader *sent_header;
+ vheader->type = ntohl(vheader->type);
+ vheader->length = ntohl(vheader->length);
+ vheader->reader_id = ntohl(vheader->reader_id);
+
switch (vheader->type) {
case VSC_Init:
return;
@@ -401,15 +409,20 @@ static void smartcard_channel_write_to_reader(
SpiceCharDeviceInstance *sin;
SpiceCharDeviceInterface *sif;
uint32_t n;
+ uint32_t actual_length = vheader->length;
ASSERT(vheader->reader_id >= 0 &&
vheader->reader_id <= g_smartcard_readers.num);
sin = g_smartcard_readers.sin[vheader->reader_id];
sif = SPICE_CONTAINEROF(sin->base.sif, SpiceCharDeviceInterface, base);
+ /* protocol requires messages to be in network endianess */
+ vheader->type = htonl(vheader->type);
+ vheader->length = htonl(vheader->length);
+ vheader->reader_id = htonl(vheader->reader_id);
n = sif->write(sin, (uint8_t*)vheader,
- vheader->length + sizeof(VSCMsgHeader));
+ actual_length + sizeof(VSCMsgHeader));
// TODO - add ring
- ASSERT(n == vheader->length + sizeof(VSCMsgHeader));
+ ASSERT(n == actual_length + sizeof(VSCMsgHeader));
}
static int smartcard_channel_handle_message(RedChannel *channel, SpiceDataHeader *header, uint8_t *msg)