BOOL rdp_client_connect_auto_detect(rdpRdp* rdp, wStream *s) { BYTE* mark; UINT16 length; UINT16 channelId; /* If the MCS message channel has been joined... */ if (rdp->mcs->messageChannelId != 0) { /* Process any MCS message channel PDUs. */ Stream_GetPointer(s, mark); if (rdp_read_header(rdp, s, &length, &channelId)) { if (channelId == rdp->mcs->messageChannelId) { if (rdp_recv_message_channel_pdu(rdp, s) == 0) return TRUE; } } Stream_SetPointer(s, mark); } return FALSE; }
BOOL tsmf_codec_check_media_type(const char* decoder_name, wStream* s) { BYTE* m; BOOL ret; TS_AM_MEDIA_TYPE mediatype; Stream_GetPointer(s, m); ret = tsmf_codec_parse_media_type(&mediatype, s); Stream_SetPointer(s, m); if (ret) { ITSMFDecoder* decoder = tsmf_load_decoder(decoder_name, &mediatype); if (!decoder) { WLog_WARN(TAG, "Format not supported by decoder %s", decoder_name); ret = FALSE; } else { decoder->Free(decoder); } } return ret; }
int rdp_client_connect_demand_active(rdpRdp* rdp, wStream* s) { BYTE* mark; UINT16 width; UINT16 height; width = rdp->settings->DesktopWidth; height = rdp->settings->DesktopHeight; Stream_GetPointer(s, mark); if (!rdp_recv_demand_active(rdp, s)) { UINT16 channelId; Stream_SetPointer(s, mark); rdp_recv_get_active_header(rdp, s, &channelId); /* Was Stream_Seek(s, RDP_PACKET_HEADER_MAX_LENGTH); * but the headers aren't always that length, * so that could result in a bad offset. */ return rdp_recv_out_of_sequence_pdu(rdp, s); } if (freerdp_shall_disconnect(rdp->instance)) return 0; if (!rdp_send_confirm_active(rdp)) return -1; if (!input_register_client_callbacks(rdp->input)) { WLog_ERR(TAG, "error registering client callbacks"); return -1; } /** * The server may request a different desktop size during Deactivation-Reactivation sequence. * In this case, the UI should be informed and do actual window resizing at this point. */ if (width != rdp->settings->DesktopWidth || height != rdp->settings->DesktopHeight) { BOOL status = TRUE; IFCALLRET(rdp->update->DesktopResize, status, rdp->update->context); if (!status) { WLog_ERR(TAG, "client desktop resize callback failed"); return -1; } } rdp_client_transition_to_state(rdp, CONNECTION_STATE_FINALIZATION); return rdp_client_connect_finalize(rdp); }
BOOL tsmf_codec_check_media_type(wStream *s) { BYTE *m; BOOL ret; TS_AM_MEDIA_TYPE mediatype; Stream_GetPointer(s, m); ret = tsmf_codec_parse_media_type(&mediatype, s); Stream_SetPointer(s, m); return ret; }
BOOL rdp_client_connect_demand_active(rdpRdp* rdp, wStream* s) { BYTE* mark; UINT16 width; UINT16 height; width = rdp->settings->DesktopWidth; height = rdp->settings->DesktopHeight; Stream_GetPointer(s, mark); if (!rdp_recv_demand_active(rdp, s)) { UINT16 channelId; Stream_SetPointer(s, mark); rdp_recv_get_active_header(rdp, s, &channelId); /* Was Stream_Seek(s, RDP_PACKET_HEADER_MAX_LENGTH); * but the headers aren't always that length, * so that could result in a bad offset. */ if (rdp_recv_out_of_sequence_pdu(rdp, s) != TRUE) return FALSE; return TRUE; } if (rdp->disconnect) return TRUE; if (!rdp_send_confirm_active(rdp)) return FALSE; input_register_client_callbacks(rdp->input); /** * The server may request a different desktop size during Deactivation-Reactivation sequence. * In this case, the UI should be informed and do actual window resizing at this point. */ if (width != rdp->settings->DesktopWidth || height != rdp->settings->DesktopHeight) { IFCALL(rdp->update->DesktopResize, rdp->update->context); } rdp->state = CONNECTION_STATE_FINALIZATION; update_reset_state(rdp->update); return rdp_client_connect_finalize(rdp); }
BOOL tf_peer_dump_rfx(freerdp_peer* client) { wStream* s; UINT32 prev_seconds; UINT32 prev_useconds; rdpUpdate* update; rdpPcap* pcap_rfx; pcap_record record; s = Stream_New(NULL, 512); if (!s) return FALSE; update = client->update; if (!(pcap_rfx = pcap_open(test_pcap_file, FALSE))) return FALSE; prev_seconds = prev_useconds = 0; while (pcap_has_next_record(pcap_rfx)) { if (!pcap_get_next_record_header(pcap_rfx, &record)) break; if (!Stream_EnsureCapacity(s, record.length)) break; record.data = Stream_Buffer(s); pcap_get_next_record_content(pcap_rfx, &record); Stream_SetPointer(s, Stream_Buffer(s) + Stream_Capacity(s)); if (test_dump_rfx_realtime && test_sleep_tsdiff(&prev_seconds, &prev_useconds, record.header.ts_sec, record.header.ts_usec) == FALSE) break; update->SurfaceCommand(update->context, s); if (client->CheckFileDescriptor(client) != TRUE) break; } Stream_Free(s, TRUE); pcap_close(pcap_rfx); return TRUE; }
BOOL rdp_client_connect_auto_detect(rdpRdp* rdp, wStream* s) { BYTE* mark; UINT16 length; UINT16 channelId; /* If the MCS message channel has been joined... */ if (rdp->mcs->messageChannelId != 0) { /* Process any MCS message channel PDUs. */ Stream_GetPointer(s, mark); if (rdp_read_header(rdp, s, &length, &channelId)) { if (channelId == rdp->mcs->messageChannelId) { UINT16 securityFlags = 0; if (!rdp_read_security_header(s, &securityFlags, &length)) return FALSE; if (securityFlags & SEC_ENCRYPT) { if (!rdp_decrypt(rdp, s, length, securityFlags)) { WLog_ERR(TAG, "rdp_decrypt failed"); return FALSE; } } if (rdp_recv_message_channel_pdu(rdp, s, securityFlags) == 0) return TRUE; } } Stream_SetPointer(s, mark); } return FALSE; }
void guac_rdpsnd_formats_handler(guac_rdpsndPlugin* rdpsnd, wStream* input_stream, guac_rdpsnd_pdu_header* header) { int server_format_count; int server_version; int i; wStream* output_stream; int output_body_size; unsigned char* output_stream_end; /* Get associated client data */ guac_client* client = rdpsnd->client; guac_rdp_client* rdp_client = (guac_rdp_client*) client->data; /* Get audio stream from client data */ guac_audio_stream* audio = rdp_client->audio; /* Format header */ Stream_Seek(input_stream, 14); Stream_Read_UINT16(input_stream, server_format_count); Stream_Seek_UINT8(input_stream); Stream_Read_UINT16(input_stream, server_version); Stream_Seek_UINT8(input_stream); /* Initialize Client Audio Formats and Version PDU */ output_stream = Stream_New(NULL, 24); Stream_Write_UINT8(output_stream, SNDC_FORMATS); Stream_Write_UINT8(output_stream, 0); /* Fill in body size later */ Stream_Seek_UINT16(output_stream); /* offset = 0x02 */ /* Flags, volume, and pitch */ Stream_Write_UINT32(output_stream, TSSNDCAPS_ALIVE); Stream_Write_UINT32(output_stream, 0); Stream_Write_UINT32(output_stream, 0); /* Datagram port (UDP) */ Stream_Write_UINT16(output_stream, 0); /* Fill in format count later */ Stream_Seek_UINT16(output_stream); /* offset = 0x12 */ /* Version and padding */ Stream_Write_UINT8(output_stream, 0); Stream_Write_UINT16(output_stream, 6); Stream_Write_UINT8(output_stream, 0); /* Check each server format, respond if supported and audio is enabled */ if (audio != NULL) { for (i=0; i < server_format_count; i++) { unsigned char* format_start; int format_tag; int channels; int rate; int bps; int body_size; /* Remember position in stream */ Stream_GetPointer(input_stream, format_start); /* Read format */ Stream_Read_UINT16(input_stream, format_tag); Stream_Read_UINT16(input_stream, channels); Stream_Read_UINT32(input_stream, rate); Stream_Seek_UINT32(input_stream); Stream_Seek_UINT16(input_stream); Stream_Read_UINT16(input_stream, bps); /* Skip past extra data */ Stream_Read_UINT16(input_stream, body_size); Stream_Seek(input_stream, body_size); /* If PCM, accept */ if (format_tag == WAVE_FORMAT_PCM) { /* If can fit another format, accept it */ if (rdpsnd->format_count < GUAC_RDP_MAX_FORMATS) { /* Add channel */ int current = rdpsnd->format_count++; rdpsnd->formats[current].rate = rate; rdpsnd->formats[current].channels = channels; rdpsnd->formats[current].bps = bps; /* Log format */ guac_client_log(client, GUAC_LOG_INFO, "Accepted format: %i-bit PCM with %i channels at " "%i Hz", bps, channels, rate); /* Ensure audio stream is configured to use accepted * format */ guac_audio_stream_reset(audio, NULL, rate, channels, bps); /* Queue format for sending as accepted */ Stream_EnsureRemainingCapacity(output_stream, 18 + body_size); Stream_Write(output_stream, format_start, 18 + body_size); /* * BEWARE that using Stream_EnsureRemainingCapacity means * that any pointers returned via Stream_GetPointer on * output_stream are invalid. */ } /* Otherwise, log that we dropped one */ else guac_client_log(client, GUAC_LOG_INFO, "Dropped valid format: %i-bit PCM with %i " "channels at %i Hz", bps, channels, rate); } } } /* Otherwise, ignore all supported formats as we do not intend to actually * receive audio */ else guac_client_log(client, GUAC_LOG_DEBUG, "Audio explicitly disabled. Ignoring supported formats."); /* Calculate size of PDU */ output_body_size = Stream_GetPosition(output_stream) - 4; Stream_GetPointer(output_stream, output_stream_end); /* Set body size */ Stream_SetPosition(output_stream, 0x02); Stream_Write_UINT16(output_stream, output_body_size); /* Set format count */ Stream_SetPosition(output_stream, 0x12); Stream_Write_UINT16(output_stream, rdpsnd->format_count); /* Reposition cursor at end (necessary for message send) */ Stream_SetPointer(output_stream, output_stream_end); /* Send accepted formats */ pthread_mutex_lock(&(rdp_client->rdp_lock)); svc_plugin_send((rdpSvcPlugin*)rdpsnd, output_stream); /* If version greater than 6, must send Quality Mode PDU */ if (server_version >= 6) { /* Always send High Quality for now */ output_stream = Stream_New(NULL, 8); Stream_Write_UINT8(output_stream, SNDC_QUALITYMODE); Stream_Write_UINT8(output_stream, 0); Stream_Write_UINT16(output_stream, 4); Stream_Write_UINT16(output_stream, HIGH_QUALITY); Stream_Write_UINT16(output_stream, 0); svc_plugin_send((rdpSvcPlugin*)rdpsnd, output_stream); } pthread_mutex_unlock(&(rdp_client->rdp_lock)); }