static int spicevmc_red_channel_client_handle_message(RedChannelClient *rcc, uint16_t type, uint32_t size, uint8_t *msg) { SpiceVmcState *state; SpiceCharDeviceInstance *sin; SpiceCharDeviceInterface *sif; state = spicevmc_red_channel_client_get_state(rcc); sin = state->chardev_sin; sif = SPICE_CONTAINEROF(sin->base.sif, SpiceCharDeviceInterface, base); switch (type) { case SPICE_MSGC_SPICEVMC_DATA: spice_assert(state->recv_from_client_buf->buf == msg); state->recv_from_client_buf->buf_used = size; spice_char_device_write_buffer_add(state->chardev_st, state->recv_from_client_buf); state->recv_from_client_buf = NULL; break; case SPICE_MSGC_PORT_EVENT: if (size != sizeof(uint8_t)) { spice_warning("bad port event message size"); return FALSE; } if (sif->base.minor_version >= 2 && sif->event != NULL) sif->event(sin, *msg); break; default: return red_channel_client_handle_message(rcc, size, type, msg); } return TRUE; }
static void smartcard_channel_write_to_reader(SpiceCharDeviceWriteBuffer *write_buf) { SpiceCharDeviceInstance *sin; SmartCardDeviceState *st; VSCMsgHeader *vheader; uint32_t actual_length; vheader = (VSCMsgHeader *)write_buf->buf; actual_length = vheader->length; spice_assert(vheader->reader_id <= g_smartcard_readers.num); sin = g_smartcard_readers.sin[vheader->reader_id]; st = (SmartCardDeviceState *)spice_char_device_state_opaque_get(sin->st); spice_assert(!st->scc || st == st->scc->smartcard_state); /* 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); write_buf->buf_used = actual_length + sizeof(VSCMsgHeader); /* pushing the buffer to the write queue; It will be released * when it will be fully consumed by the device */ spice_char_device_write_buffer_add(sin->st, write_buf); if (st->scc && write_buf == st->scc->write_buf) { st->scc->write_buf = NULL; } }