d1cad5856ab652cdcd716a79747a7c24f84f6b28
[platform/core/multimedia/gst-rtsp-server-wfd.git] / src / wfdconfigmessage.c
1 /* GStreamer
2  * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <stdlib.h>
26 #include <string.h>
27 #include <stdio.h>
28 #ifdef HAVE_SYS_TYPES_H
29 #include <sys/types.h>
30 #endif
31
32 #include <glib.h>               /* for G_OS_WIN32 */
33 #include <gst/gstinfo.h>        /* For GST_STR_NULL */
34 #include <gst/gst.h>
35 #include "wfdconfigmessage.h"
36 #include <mm_debug.h>
37
38 /* FIXME, is currently allocated on the stack */
39 #define MAX_LINE_LEN    1024 * 16
40
41 #define FREE_STRING(field)              if(field != NULL) g_free (field); (field) = NULL
42 #define REPLACE_STRING(field, val)      FREE_STRING(field); (field) = g_strdup (val)
43 #define EDID_BLOCK_SIZE 128
44 #define LIBHDCP "/usr/lib/libhdcp library"
45 enum
46 {
47   WFD_SESSION,
48   WFD_MEDIA,
49 };
50
51 typedef struct
52 {
53   guint state;
54   WFDMessage *msg;
55 } WFDContext;
56
57 /**
58 * wfdconfig_message_new:
59 * @msg: pointer to new #WFDMessage
60 *
61 * Allocate a new WFDMessage and store the result in @msg.
62 *
63 * Returns: a #WFDResult.
64 */
65 WFDResult
66 wfdconfig_message_new (WFDMessage ** msg)
67 {
68   WFDMessage *newmsg;
69
70   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
71
72   newmsg = g_new0 (WFDMessage, 1);
73
74   *msg = newmsg;
75
76   return wfdconfig_message_init (newmsg);
77 }
78
79 /**
80 * wfdconfig_message_init:
81 * @msg: a #WFDMessage
82 *
83 * Initialize @msg so that its contents are as if it was freshly allocated
84 * with wfdconfig_message_new(). This function is mostly used to initialize a message
85 * allocated on the stack. wfdconfig_message_uninit() undoes this operation.
86 *
87 * When this function is invoked on newly allocated data (with malloc or on the
88 * stack), its contents should be set to 0 before calling this function.
89 *
90 * Returns: a #WFDResult.
91 */
92 WFDResult
93 wfdconfig_message_init (WFDMessage * msg)
94 {
95   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
96
97   return WFD_OK;
98 }
99
100 /**
101 * wfdconfig_message_uninit:
102 * @msg: a #WFDMessage
103 *
104 * Free all resources allocated in @msg. @msg should not be used anymore after
105 * this function. This function should be used when @msg was allocated on the
106 * stack and initialized with wfdconfig_message_init().
107 *
108 * Returns: a #WFDResult.
109 */
110 WFDResult
111 wfdconfig_message_uninit (WFDMessage * msg)
112 {
113   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
114
115   if(msg->audio_codecs) {
116     guint i=0;
117     if(msg->audio_codecs->list) {
118       for(; i<msg->audio_codecs->count; i++) {
119         FREE_STRING(msg->audio_codecs->list[i].audio_format);
120         msg->audio_codecs->list[i].modes=0;
121         msg->audio_codecs->list[i].latency=0;
122       }
123       FREE_STRING(msg->audio_codecs->list);
124     }
125     FREE_STRING(msg->audio_codecs);
126   }
127
128   if(msg->video_formats) {
129     FREE_STRING(msg->video_formats->list);
130     FREE_STRING(msg->video_formats);
131   }
132
133   if(msg->video_3d_formats) {
134     FREE_STRING(msg->video_3d_formats);
135   }
136
137   if(msg->content_protection) {
138     FREE_STRING(msg->content_protection);
139   }
140
141   if(msg->display_edid) {
142     if(msg->display_edid->edid_payload)
143       FREE_STRING(msg->display_edid->edid_payload);
144     FREE_STRING(msg->display_edid);
145   }
146
147   if(msg->coupled_sink) {
148     FREE_STRING(msg->coupled_sink);
149   }
150
151   if(msg->trigger_method) {
152     FREE_STRING(msg->trigger_method->wfd_trigger_method);
153     FREE_STRING(msg->trigger_method);
154   }
155
156   if(msg->presentation_url) {
157     FREE_STRING(msg->trigger_method);
158   }
159
160   if(msg->client_rtp_ports) {
161     FREE_STRING(msg->client_rtp_ports->profile);
162     FREE_STRING(msg->client_rtp_ports->mode);
163     FREE_STRING(msg->client_rtp_ports);
164   }
165
166   if(msg->route) {
167     FREE_STRING(msg->route);
168   }
169
170   if(msg->I2C) {
171     FREE_STRING(msg->I2C);
172   }
173
174   if(msg->av_format_change_timing) {
175     FREE_STRING(msg->av_format_change_timing);
176   }
177
178   if(msg->preferred_display_mode) {
179     FREE_STRING(msg->preferred_display_mode);
180   }
181
182   if(msg->uibc_capability) {
183     FREE_STRING(msg->uibc_capability);
184   }
185
186   if(msg->uibc_setting) {
187     FREE_STRING(msg->uibc_setting);
188   }
189
190   if(msg->standby_resume_capability) {
191     FREE_STRING(msg->standby_resume_capability);
192   }
193
194   if(msg->standby) {
195     FREE_STRING(msg->standby);
196   }
197
198   if(msg->connector_type) {
199     FREE_STRING(msg->connector_type);
200   }
201
202   if(msg->idr_request) {
203     FREE_STRING(msg->idr_request);
204   }
205
206   return WFD_OK;
207 }
208
209 /**
210 * wfdconfig_message_free:
211 * @msg: a #WFDMessage
212 *
213 * Free all resources allocated by @msg. @msg should not be used anymore after
214 * this function. This function should be used when @msg was dynamically
215 * allocated with wfdconfig_message_new().
216 *
217 * Returns: a #WFDResult.
218 */
219 WFDResult
220 wfdconfig_message_free (WFDMessage * msg)
221 {
222   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
223
224   wfdconfig_message_uninit (msg);
225   g_free (msg);
226
227   return WFD_OK;
228 }
229
230 /**
231 * wfdconfig_message_as_text:
232 * @msg: a #WFDMessage
233 *
234 * Convert the contents of @msg to a text string.
235 *
236 * Returns: A dynamically allocated string representing the WFD description.
237 */
238 gchar *
239 wfdconfig_message_as_text (const WFDMessage * msg)
240 {
241   /* change all vars so they match rfc? */
242   GString *lines;
243   g_return_val_if_fail (msg != NULL, NULL);
244
245   lines = g_string_new ("");
246
247   /* list of audio codecs */
248   if(msg->audio_codecs) {
249     guint i=0;
250     g_string_append_printf (lines,"wfd_audio_codecs");
251     if(msg->audio_codecs->list) {
252       g_string_append_printf (lines,":");
253       for(; i<msg->audio_codecs->count; i++) {
254         g_string_append_printf (lines," %s",msg->audio_codecs->list[i].audio_format);
255         g_string_append_printf (lines," %08x",msg->audio_codecs->list[i].modes);
256         g_string_append_printf (lines," %02x",msg->audio_codecs->list[i].latency);
257         if((i+1)<msg->audio_codecs->count)
258           g_string_append_printf (lines,",");
259       }
260     }
261     g_string_append_printf (lines,"\r\n");
262   }
263
264   /* list of video codecs */
265   if(msg->video_formats) {
266     g_string_append_printf (lines,"wfd_video_formats");
267     if(msg->video_formats->list) {
268       g_string_append_printf (lines,":");
269       g_string_append_printf (lines," %02x", msg->video_formats->list->native);
270       g_string_append_printf (lines," %02x", msg->video_formats->list->preferred_display_mode_supported);
271       g_string_append_printf (lines," %02x", msg->video_formats->list->H264_codec.profile);
272       g_string_append_printf (lines," %02x", msg->video_formats->list->H264_codec.level);
273       g_string_append_printf (lines," %08x", msg->video_formats->list->H264_codec.misc_params.CEA_Support);
274       g_string_append_printf (lines," %08x", msg->video_formats->list->H264_codec.misc_params.VESA_Support);
275       g_string_append_printf (lines," %08x", msg->video_formats->list->H264_codec.misc_params.HH_Support);
276       g_string_append_printf (lines," %02x", msg->video_formats->list->H264_codec.misc_params.latency);
277       g_string_append_printf (lines," %04x", msg->video_formats->list->H264_codec.misc_params.min_slice_size);
278       g_string_append_printf (lines," %04x", msg->video_formats->list->H264_codec.misc_params.slice_enc_params);
279       g_string_append_printf (lines," %02x", msg->video_formats->list->H264_codec.misc_params.frame_rate_control_support);
280
281       if(msg->video_formats->list->H264_codec.max_hres)
282         g_string_append_printf (lines," %04x", msg->video_formats->list->H264_codec.max_hres);
283       else
284         g_string_append_printf (lines," none");
285
286       if(msg->video_formats->list->H264_codec.max_vres)
287         g_string_append_printf (lines," %04x", msg->video_formats->list->H264_codec.max_vres);
288       else
289         g_string_append_printf (lines," none");
290     }
291     g_string_append_printf (lines,"\r\n");
292   }
293
294   /* list of video 3D codecs */
295   if(msg->video_3d_formats) {
296     g_string_append_printf (lines,"wfd_3d_video_formats");
297     g_string_append_printf (lines,":");
298     if(msg->video_3d_formats->list) {
299       g_string_append_printf (lines," %02x", msg->video_3d_formats->list->native);
300       g_string_append_printf (lines," %02x", msg->video_3d_formats->list->preferred_display_mode_supported);
301       g_string_append_printf (lines," %02x", msg->video_3d_formats->list->H264_codec.profile);
302       g_string_append_printf (lines," %02x", msg->video_3d_formats->list->H264_codec.level);
303       g_string_append_printf (lines," %16x", msg->video_3d_formats->list->H264_codec.misc_params.video_3d_capability);
304       g_string_append_printf (lines," %02x", msg->video_3d_formats->list->H264_codec.misc_params.latency);
305       g_string_append_printf (lines," %04x", msg->video_3d_formats->list->H264_codec.misc_params.min_slice_size);
306       g_string_append_printf (lines," %04x", msg->video_3d_formats->list->H264_codec.misc_params.slice_enc_params);
307       g_string_append_printf (lines," %02x", msg->video_3d_formats->list->H264_codec.misc_params.frame_rate_control_support);
308       if(msg->video_3d_formats->list->H264_codec.max_hres)
309         g_string_append_printf (lines," %04x", msg->video_formats->list->H264_codec.max_hres);
310       else
311         g_string_append_printf (lines," none");
312       if(msg->video_3d_formats->list->H264_codec.max_vres)
313         g_string_append_printf (lines," %04x", msg->video_formats->list->H264_codec.max_vres);
314       else
315         g_string_append_printf (lines," none");
316     } else {
317       g_string_append_printf (lines," none");
318     }
319     g_string_append_printf (lines,"\r\n");
320   }
321
322   if(msg->content_protection) {
323     g_string_append_printf (lines,"wfd_content_protection");
324     if(msg->content_protection->hdcp2_spec) {
325       g_string_append_printf (lines,":");
326       if( msg->content_protection->hdcp2_spec->hdcpversion) {
327         g_string_append_printf (lines," %s", msg->content_protection->hdcp2_spec->hdcpversion);
328         g_string_append_printf (lines," %s", msg->content_protection->hdcp2_spec->TCPPort);
329       } else {
330         g_string_append_printf (lines," none");
331       }
332     }
333     g_string_append_printf (lines,"\r\n");
334   }
335
336   if(msg->display_edid) {
337     g_string_append_printf (lines,"wfd_display_edid");
338     g_string_append_printf (lines,":");
339     if(msg->display_edid->edid_supported) {
340       g_string_append_printf (lines," %d", msg->display_edid->edid_supported);
341       if(msg->display_edid->edid_block_count)
342         g_string_append_printf (lines," %d", msg->display_edid->edid_block_count);
343       else
344         g_string_append_printf (lines," none");
345     } else {
346       g_string_append_printf (lines," none");
347     }
348     g_string_append_printf (lines,"\r\n");
349   }
350
351   if(msg->coupled_sink) {
352     g_string_append_printf (lines,"wfd_coupled_sink");
353     g_string_append_printf (lines,":");
354     if(msg->coupled_sink->coupled_sink_cap) {
355       g_string_append_printf (lines," %02x", msg->coupled_sink->coupled_sink_cap->status);
356       if(msg->coupled_sink->coupled_sink_cap->sink_address)
357         g_string_append_printf (lines," %s", msg->coupled_sink->coupled_sink_cap->sink_address);
358       else
359         g_string_append_printf (lines," none");
360     } else {
361       g_string_append_printf (lines," none");
362     }
363     g_string_append_printf (lines,"\r\n");
364   }
365
366   if(msg->trigger_method) {
367     g_string_append_printf (lines,"wfd_trigger_method");
368     g_string_append_printf (lines,":");
369     g_string_append_printf (lines," %s", msg->trigger_method->wfd_trigger_method);
370     g_string_append_printf (lines,"\r\n");
371   }
372
373   if(msg->presentation_url) {
374     g_string_append_printf (lines,"wfd_presentation_URL");
375     g_string_append_printf (lines,":");
376     if(msg->presentation_url->wfd_url0)
377       g_string_append_printf (lines," %s", msg->presentation_url->wfd_url0);
378     else
379       g_string_append_printf (lines," none");
380     if(msg->presentation_url->wfd_url1)
381       g_string_append_printf (lines," %s", msg->presentation_url->wfd_url1);
382     else
383       g_string_append_printf (lines," none");
384     g_string_append_printf (lines,"\r\n");
385   }
386   if(msg->client_rtp_ports) {
387     g_string_append_printf (lines,"wfd_client_rtp_ports");
388     if(msg->client_rtp_ports->profile) {
389       g_string_append_printf (lines,":");
390       g_string_append_printf (lines," %s", msg->client_rtp_ports->profile);
391       g_string_append_printf (lines," %d", msg->client_rtp_ports->rtp_port0);
392       g_string_append_printf (lines," %d", msg->client_rtp_ports->rtp_port1);
393       g_string_append_printf (lines," %s", msg->client_rtp_ports->mode);
394     }
395     g_string_append_printf (lines,"\r\n");
396   }
397
398   if(msg->route) {
399     g_string_append_printf (lines,"wfd_route");
400     g_string_append_printf (lines,":");
401     g_string_append_printf (lines," %s", msg->route->destination);
402     g_string_append_printf (lines,"\r\n");
403   }
404
405   if(msg->I2C) {
406     g_string_append_printf (lines,"wfd_I2C");
407     g_string_append_printf (lines,":");
408     if(msg->I2C->I2CPresent)
409       g_string_append_printf (lines," %x", msg->I2C->I2C_port);
410     else
411       g_string_append_printf (lines," none");
412     g_string_append_printf (lines,"\r\n");
413   }
414
415   if(msg->av_format_change_timing) {
416     g_string_append_printf (lines,"wfd_av_format_change_timing");
417     g_string_append_printf (lines,":");
418     g_string_append_printf (lines," %10llu", msg->av_format_change_timing->PTS);
419     g_string_append_printf (lines," %10llu", msg->av_format_change_timing->DTS);
420     g_string_append_printf (lines,"\r\n");
421   }
422
423   if(msg->preferred_display_mode) {
424     g_string_append_printf (lines,"wfd_preferred_display_mode");
425     g_string_append_printf (lines,":");
426     if(msg->preferred_display_mode->displaymodesupported) {
427       g_string_append_printf (lines," %06llu", msg->preferred_display_mode->p_clock);
428       g_string_append_printf (lines," %04x", msg->preferred_display_mode->H);
429       g_string_append_printf (lines," %04x", msg->preferred_display_mode->HB);
430       g_string_append_printf (lines," %04x", msg->preferred_display_mode->HSPOL_HSOFF);
431       g_string_append_printf (lines," %04x", msg->preferred_display_mode->HSW);
432       g_string_append_printf (lines," %04x", msg->preferred_display_mode->V);
433       g_string_append_printf (lines," %04x", msg->preferred_display_mode->VB);
434       g_string_append_printf (lines," %04x", msg->preferred_display_mode->VSPOL_VSOFF);
435       g_string_append_printf (lines," %04x", msg->preferred_display_mode->VSW);
436       g_string_append_printf (lines," %02x", msg->preferred_display_mode->VBS3D);
437       g_string_append_printf (lines," %02x", msg->preferred_display_mode->V2d_s3d_modes);
438       g_string_append_printf (lines," %02x", msg->preferred_display_mode->P_depth);
439     } else g_string_append_printf (lines," none");
440     g_string_append_printf (lines,"\r\n");
441   }
442
443   if(msg->uibc_capability) {
444     g_string_append_printf (lines,"wfd_uibc_capability");
445     g_string_append_printf (lines,":");
446     if(msg->uibc_capability->uibcsupported) {
447       g_string_append_printf (lines," input_category_list=");
448       if(msg->uibc_capability->input_category_list.input_cat) {
449         guint32 tempcap = 0;
450         if(msg->uibc_capability->input_category_list.input_cat & WFD_UIBC_INPUT_CAT_GENERIC) {
451           tempcap |= WFD_UIBC_INPUT_CAT_GENERIC;
452           g_string_append_printf (lines,"GENERIC");
453           if(msg->uibc_capability->input_category_list.input_cat != tempcap) g_string_append_printf (lines,", ");
454         }
455         if(msg->uibc_capability->input_category_list.input_cat & WFD_UIBC_INPUT_CAT_HIDC) {
456           tempcap |= WFD_UIBC_INPUT_CAT_HIDC;
457           g_string_append_printf (lines,"HIDC");
458           if(msg->uibc_capability->input_category_list.input_cat != tempcap) g_string_append_printf (lines,", ");
459         }
460       }
461       else g_string_append_printf (lines,"none");
462       g_string_append_printf (lines,";");
463       g_string_append_printf (lines," generic_cap_list=");
464       if(msg->uibc_capability->generic_cap_list.inp_type) {
465         guint32 tempcap = 0;
466         if(msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_KEYBOARD) {
467           tempcap |= WFD_UIBC_INPUT_TYPE_KEYBOARD;
468           g_string_append_printf (lines,"Keyboard");
469           if(msg->uibc_capability->generic_cap_list.inp_type != tempcap) g_string_append_printf (lines,", ");
470         }
471         if(msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_MOUSE) {
472           tempcap |= WFD_UIBC_INPUT_TYPE_MOUSE;
473           g_string_append_printf (lines,"Mouse");
474           if(msg->uibc_capability->generic_cap_list.inp_type != tempcap) g_string_append_printf (lines,", ");
475         }
476         if(msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_SINGLETOUCH) {
477           tempcap |= WFD_UIBC_INPUT_TYPE_SINGLETOUCH;
478           g_string_append_printf (lines,"SingleTouch");
479           if(msg->uibc_capability->generic_cap_list.inp_type != tempcap) g_string_append_printf (lines,", ");
480         }
481         if(msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_MULTITOUCH) {
482           tempcap |= WFD_UIBC_INPUT_TYPE_MULTITOUCH;
483           g_string_append_printf (lines,"MultiTouch");
484           if(msg->uibc_capability->generic_cap_list.inp_type != tempcap) g_string_append_printf (lines,", ");
485         }
486         if(msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_JOYSTICK) {
487           tempcap |= WFD_UIBC_INPUT_TYPE_JOYSTICK;
488           g_string_append_printf (lines,"Joystick");
489           if(msg->uibc_capability->generic_cap_list.inp_type != tempcap) g_string_append_printf (lines,", ");
490         }
491         if(msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_CAMERA) {
492           tempcap |= WFD_UIBC_INPUT_TYPE_CAMERA;
493           g_string_append_printf (lines,"Camera");
494           if(msg->uibc_capability->generic_cap_list.inp_type != tempcap) g_string_append_printf (lines,", ");
495         }
496         if(msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_GESTURE) {
497           tempcap |= WFD_UIBC_INPUT_TYPE_GESTURE;
498           g_string_append_printf (lines,"Gesture");
499           if(msg->uibc_capability->generic_cap_list.inp_type != tempcap) g_string_append_printf (lines,", ");
500         }
501         if(msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_REMOTECONTROL) {
502           tempcap |= WFD_UIBC_INPUT_TYPE_REMOTECONTROL;
503           g_string_append_printf (lines,"RemoteControl");
504           if(msg->uibc_capability->generic_cap_list.inp_type != tempcap) g_string_append_printf (lines,", ");
505         }
506       }
507       else g_string_append_printf (lines,"none");
508       g_string_append_printf (lines,";");
509       g_string_append_printf (lines," hidc_cap_list=");
510       if(msg->uibc_capability->hidc_cap_list.cap_count) {
511         detailed_cap *temp_cap = msg->uibc_capability->hidc_cap_list.next;
512         while(temp_cap)
513         {
514           if(temp_cap->p.inp_type == WFD_UIBC_INPUT_TYPE_KEYBOARD) g_string_append_printf (lines,"Keyboard");
515           else if(temp_cap->p.inp_type == WFD_UIBC_INPUT_TYPE_MOUSE) g_string_append_printf (lines,"Mouse");
516           else if(temp_cap->p.inp_type == WFD_UIBC_INPUT_TYPE_SINGLETOUCH) g_string_append_printf (lines,"SingleTouch");
517           else if(temp_cap->p.inp_type == WFD_UIBC_INPUT_TYPE_MULTITOUCH) g_string_append_printf (lines,"MultiTouch");
518           else if(temp_cap->p.inp_type == WFD_UIBC_INPUT_TYPE_JOYSTICK) g_string_append_printf (lines,"Joystick");
519           else if(temp_cap->p.inp_type == WFD_UIBC_INPUT_TYPE_CAMERA) g_string_append_printf (lines,"Camera");
520           else if(temp_cap->p.inp_type == WFD_UIBC_INPUT_TYPE_GESTURE) g_string_append_printf (lines,"Gesture");
521           else if(temp_cap->p.inp_type == WFD_UIBC_INPUT_TYPE_REMOTECONTROL) g_string_append_printf (lines,"RemoteControl");
522           g_string_append_printf (lines,"/");
523           if(temp_cap->p.inp_path == WFD_UIBC_INPUT_PATH_INFRARED) g_string_append_printf (lines,"Infrared");
524           else if(temp_cap->p.inp_path == WFD_UIBC_INPUT_PATH_USB) g_string_append_printf (lines,"USB");
525           else if(temp_cap->p.inp_path == WFD_UIBC_INPUT_PATH_BT) g_string_append_printf (lines,"BT");
526           else if(temp_cap->p.inp_path == WFD_UIBC_INPUT_PATH_ZIGBEE) g_string_append_printf (lines,"Zigbee");
527           else if(temp_cap->p.inp_path == WFD_UIBC_INPUT_PATH_WIFI) g_string_append_printf (lines,"Wi-Fi");
528           else if(temp_cap->p.inp_path == WFD_UIBC_INPUT_PATH_NOSP) g_string_append_printf (lines,"No-SP");
529           temp_cap = temp_cap->next;
530           if(temp_cap) g_string_append_printf (lines,", ");
531         }
532       } else g_string_append_printf (lines,"none");
533       g_string_append_printf (lines,";");
534       if(msg->uibc_capability->tcp_port) g_string_append_printf (lines," port=%x", msg->uibc_capability->tcp_port);
535       else  g_string_append_printf (lines,"port=none");
536     } else g_string_append_printf (lines," none");
537     g_string_append_printf (lines,"\r\n");
538   }
539
540   if(msg->uibc_setting) {
541     g_string_append_printf (lines,"wfd_uibc_setting");
542     g_string_append_printf (lines,":");
543     if(msg->uibc_setting->uibc_setting)
544       g_string_append_printf (lines," enable");
545     else
546       g_string_append_printf (lines," disable");
547     g_string_append_printf (lines,"\r\n");
548   }
549
550   if(msg->standby_resume_capability) {
551     g_string_append_printf (lines,"wfd_standby_resume_capability");
552     g_string_append_printf (lines,":");
553     if(msg->standby_resume_capability->standby_resume_cap)
554       g_string_append_printf (lines," supported");
555     else
556       g_string_append_printf (lines," none");
557     g_string_append_printf (lines,"\r\n");
558   }
559
560   if(msg->standby) {
561     g_string_append_printf (lines,"wfd_standby");
562     g_string_append_printf (lines,"\r\n");
563   }
564
565   if(msg->connector_type) {
566     g_string_append_printf (lines,"wfd_connector_type");
567     g_string_append_printf (lines,":");
568     if(msg->connector_type->connector_type)
569       g_string_append_printf (lines," %02x", msg->connector_type->connector_type);
570     else
571       g_string_append_printf (lines," none");
572     g_string_append_printf (lines,"\r\n");
573   }
574
575   if(msg->idr_request) {
576     g_string_append_printf (lines,"wfd_idr_request");
577     g_string_append_printf (lines,"\r\n");
578   }
579
580   //g_string_append_printf (lines,"\0");
581   /*if(g_str_has_suffix (lines,"\r\n\0"))
582   {
583   guint32 length = g_strlen(lines);
584   lines[length-2] = '\0';
585   }*/
586   return g_string_free (lines, FALSE);
587 }
588
589 gchar* wfdconfig_parameter_names_as_text (const WFDMessage *msg)
590 {
591   /* change all vars so they match rfc? */
592   GString *lines;
593   g_return_val_if_fail (msg != NULL, NULL);
594
595   lines = g_string_new ("");
596
597   /* list of audio codecs */
598   if(msg->audio_codecs) {
599     g_string_append_printf (lines,"wfd_audio_codecs");
600     g_string_append_printf (lines,"\r\n");
601   }
602   /* list of video codecs */
603   if(msg->video_formats) {
604     g_string_append_printf (lines,"wfd_video_formats");
605     g_string_append_printf (lines,"\r\n");
606   }
607   /* list of video 3D codecs */
608   if(msg->video_3d_formats) {
609     g_string_append_printf (lines,"wfd_3d_video_formats");
610     g_string_append_printf (lines,"\r\n");
611   }
612   if(msg->content_protection) {
613     g_string_append_printf (lines,"wfd_content_protection");
614     g_string_append_printf (lines,"\r\n");
615   }
616   if(msg->display_edid) {
617     g_string_append_printf (lines,"wfd_display_edid");
618     g_string_append_printf (lines,"\r\n");
619   }
620   if(msg->coupled_sink) {
621     g_string_append_printf (lines,"wfd_coupled_sink");
622     g_string_append_printf (lines,"\r\n");
623   }
624   if(msg->trigger_method) {
625     g_string_append_printf (lines,"wfd_trigger_method");
626     g_string_append_printf (lines,"\r\n");
627   }
628   if(msg->presentation_url) {
629     g_string_append_printf (lines,"wfd_presentation_URL");
630     g_string_append_printf (lines,"\r\n");
631   }
632   if(msg->client_rtp_ports) {
633     g_string_append_printf (lines,"wfd_client_rtp_ports");
634     g_string_append_printf (lines,"\r\n");
635   }
636   if(msg->route) {
637     g_string_append_printf (lines,"wfd_route");
638     g_string_append_printf (lines,"\r\n");
639   }
640   if(msg->I2C) {
641     g_string_append_printf (lines,"wfd_I2C");
642     g_string_append_printf (lines,"\r\n");
643   }
644   if(msg->av_format_change_timing) {
645     g_string_append_printf (lines,"wfd_av_format_change_timing");
646     g_string_append_printf (lines,"\r\n");
647   }
648   if(msg->preferred_display_mode) {
649     g_string_append_printf (lines,"wfd_preferred_display_mode");
650     g_string_append_printf (lines,"\r\n");
651   }
652   if(msg->uibc_capability) {
653     g_string_append_printf (lines,"wfd_uibc_capability");
654     g_string_append_printf (lines,"\r\n");
655   }
656   if(msg->uibc_setting) {
657     g_string_append_printf (lines,"wfd_uibc_setting");
658     g_string_append_printf (lines,"\r\n");
659   }
660   if(msg->standby_resume_capability) {
661     g_string_append_printf (lines,"wfd_standby_resume_capability");
662     g_string_append_printf (lines,"\r\n");
663   }
664   if(msg->standby) {
665     g_string_append_printf (lines,"wfd_standby");
666     g_string_append_printf (lines,"\r\n");
667   }
668   if(msg->connector_type) {
669     g_string_append_printf (lines,"wfd_connector_type");
670     g_string_append_printf (lines,"\r\n");
671   }
672   if(msg->idr_request) {
673     g_string_append_printf (lines,"wfd_idr_request");
674     g_string_append_printf (lines,"\r\n");
675   }
676   return g_string_free (lines, FALSE);
677 }
678
679 static int
680 hex_to_int (gchar c)
681 {
682 return c >= '0' && c <= '9' ? c - '0'
683 : c >= 'A' && c <= 'F' ? c - 'A' + 10
684 : c >= 'a' && c <= 'f' ? c - 'a' + 10 : 0;
685 }
686
687 static void
688 read_string (gchar * dest, guint size, gchar ** src)
689 {
690   guint idx;
691
692   idx = 0;
693   /* skip spaces */
694   while (g_ascii_isspace (**src))
695     (*src)++;
696
697   while (!g_ascii_isspace (**src) && **src != '\0') {
698     if (idx < size - 1)
699       dest[idx++] = **src;
700     (*src)++;
701   }
702
703   if (size > 0)
704     dest[idx] = '\0';
705 }
706
707 static void
708 read_string_del (gchar * dest, guint size, gchar del, gchar ** src)
709 {
710   guint idx;
711
712   idx = 0;
713   /* skip spaces */
714   while (g_ascii_isspace (**src))
715     (*src)++;
716
717   while (**src != del && **src != '\0') {
718     if (idx < size - 1)
719       dest[idx++] = **src;
720     (*src)++;
721   }
722   if (size > 0)
723     dest[idx] = '\0';
724 }
725
726 static void
727 read_string_space_ended (gchar * dest, guint size, gchar * src)
728 {
729   guint idx = 0;
730
731   while (!g_ascii_isspace (*src) && *src != '\0') {
732     if (idx < size - 1)
733       dest[idx++] = *src;
734     src++;
735   }
736
737   if (size > 0)
738     dest[idx] = '\0';
739 }
740
741 static void
742 read_string_char_ended (gchar * dest, guint size, gchar del, gchar * src)
743 {
744   guint idx = 0;
745
746   while (*src != del && *src != '\0') {
747     if (idx < size - 1)
748       dest[idx++] = *src;
749     src++;
750   }
751
752   if (size > 0)
753     dest[idx] = '\0';
754 }
755
756 static void
757 read_string_type_and_value (gchar * type, gchar * value, guint tsize, guint vsize, gchar del, gchar * src)
758 {
759   guint idx;
760
761   idx = 0;
762   while (*src != del && *src != '\0') {
763     if (idx < tsize - 1)
764       type[idx++] = *src;
765     src++;
766   }
767
768   if (tsize > 0)
769     type[idx] = '\0';
770
771   src++;
772   idx = 0;
773   while (*src != '\0') {
774     if (idx < vsize - 1)
775       value[idx++] = *src;
776     src++;
777   }
778   if (vsize > 0)
779     value[idx] = '\0';
780 }
781
782 static gboolean
783 wfdconfig_parse_line (WFDMessage * msg, gchar * buffer)
784 {
785   gchar type[8192];
786   gchar value[8192];
787   gchar temp[8192];
788   gchar *p = buffer;
789   gchar *v = value;
790
791   #define WFD_SKIP_SPACE(q) if (*q && g_ascii_isspace (*q)) q++
792   #define WFD_SKIP_COMMA(q) if (*q && g_ascii_ispunct (*q)) q++
793   #define WFD_READ_STRING(field) read_string_space_ended (temp, sizeof (temp), v); v+=strlen(temp); REPLACE_STRING (field, temp)
794   #define WFD_READ_CHAR_END_STRING(field, del) read_string_char_ended (temp, sizeof (temp), del, v); v+=strlen(temp); REPLACE_STRING (field, temp)
795   #define WFD_READ_UINT32(field) read_string_space_ended (temp, sizeof (temp), v); v+=strlen(temp); field = strtoul (temp, NULL, 16)
796   #define WFD_READ_UINT32_DIGIT(field) read_string_space_ended (temp, sizeof (temp), v); v+=strlen(temp); field = strtoul (temp, NULL, 10)
797
798   //g_print("wfdconfig_parse_line input: %s\n", buffer);
799   read_string_type_and_value (type, value, sizeof(type), sizeof(value), ':', p);
800   //g_print("wfdconfig_parse_line type:%s value:%s\n", type, value);
801   if(!g_strcmp0(type,"wfd_audio_codecs")) {
802     msg->audio_codecs = g_new0 (WFDAudioCodeclist, 1);
803     if(strlen(v)) {
804       guint i=0;
805       msg->audio_codecs->count= strlen(v)/16;
806       msg->audio_codecs->list = g_new0 (WFDAudioCodec, msg->audio_codecs->count);
807       for(;i<msg->audio_codecs->count;i++) {
808         WFD_SKIP_SPACE(v);
809         WFD_READ_STRING(msg->audio_codecs->list[i].audio_format);
810         WFD_SKIP_SPACE(v);
811         WFD_READ_UINT32(msg->audio_codecs->list[i].modes);
812         WFD_SKIP_SPACE(v);
813         WFD_READ_UINT32(msg->audio_codecs->list[i].latency);
814         WFD_SKIP_COMMA(v);
815       }
816     }
817   } else if(!g_strcmp0(type,"wfd_video_formats")) {
818     msg->video_formats = g_new0 (WFDVideoCodeclist, 1);
819     if(strlen(v)) {
820       msg->video_formats->count = 1;
821       msg->video_formats->list = g_new0 (WFDVideoCodec, 1);
822       WFD_SKIP_SPACE(v);
823       WFD_READ_UINT32(msg->video_formats->list->native);
824       WFD_SKIP_SPACE(v);
825       WFD_READ_UINT32(msg->video_formats->list->preferred_display_mode_supported);
826       WFD_SKIP_SPACE(v);
827       WFD_READ_UINT32(msg->video_formats->list->H264_codec.profile);
828       WFD_SKIP_SPACE(v);
829       WFD_READ_UINT32(msg->video_formats->list->H264_codec.level);
830       WFD_SKIP_SPACE(v);
831       WFD_READ_UINT32(msg->video_formats->list->H264_codec.misc_params.CEA_Support);
832       WFD_SKIP_SPACE(v);
833       WFD_READ_UINT32(msg->video_formats->list->H264_codec.misc_params.VESA_Support);
834       WFD_SKIP_SPACE(v);
835       WFD_READ_UINT32(msg->video_formats->list->H264_codec.misc_params.HH_Support);
836       WFD_SKIP_SPACE(v);
837       WFD_READ_UINT32(msg->video_formats->list->H264_codec.misc_params.latency);
838       WFD_SKIP_SPACE(v);
839       WFD_READ_UINT32(msg->video_formats->list->H264_codec.misc_params.min_slice_size);
840       WFD_SKIP_SPACE(v);
841       WFD_READ_UINT32(msg->video_formats->list->H264_codec.misc_params.slice_enc_params);
842       WFD_SKIP_SPACE(v);
843       WFD_READ_UINT32(msg->video_formats->list->H264_codec.misc_params.frame_rate_control_support);
844       WFD_SKIP_SPACE(v);
845       if(msg->video_formats->list->preferred_display_mode_supported == 1) {
846         WFD_READ_UINT32(msg->video_formats->list->H264_codec.max_hres);
847         WFD_SKIP_SPACE(v);
848         WFD_READ_UINT32(msg->video_formats->list->H264_codec.max_vres);
849         WFD_SKIP_SPACE(v);
850       }
851     }
852   }else if(!g_strcmp0(type,"wfd_3d_formats")) {
853     msg->video_3d_formats = g_new0 (WFD3DFormats, 1);
854     if(strlen(v)) {
855       msg->video_3d_formats->count = 1;
856       msg->video_3d_formats->list = g_new0 (WFD3dCapList, 1);
857       WFD_SKIP_SPACE(v);
858       WFD_READ_UINT32(msg->video_3d_formats->list->native);
859       WFD_SKIP_SPACE(v);
860       WFD_READ_UINT32(msg->video_3d_formats->list->preferred_display_mode_supported);
861       WFD_SKIP_SPACE(v);
862       WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.profile);
863       WFD_SKIP_SPACE(v);
864       WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.level);
865       WFD_SKIP_SPACE(v);
866       WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.misc_params.video_3d_capability);
867       WFD_SKIP_SPACE(v);
868       WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.misc_params.latency);
869       WFD_SKIP_SPACE(v);
870       WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.misc_params.min_slice_size);
871       WFD_SKIP_SPACE(v);
872       WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.misc_params.slice_enc_params);
873       WFD_SKIP_SPACE(v);
874       WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.misc_params.frame_rate_control_support);
875       WFD_SKIP_SPACE(v);
876       if(msg->video_formats->list->preferred_display_mode_supported == 1) {
877         WFD_READ_UINT32(msg->video_formats->list->H264_codec.max_hres);
878         WFD_SKIP_SPACE(v);
879         WFD_READ_UINT32(msg->video_formats->list->H264_codec.max_vres);
880         WFD_SKIP_SPACE(v);
881       }
882     }
883   } else if(!g_strcmp0(type,"wfd_content_protection")) {
884     msg->content_protection = g_new0 (WFDContentProtection, 1);
885     if(strlen(v)) {
886       WFD_SKIP_SPACE(v);
887       msg->content_protection->hdcp2_spec = g_new0 (WFDHdcp2Spec, 1);
888       if(strstr(v,"none")) {
889          msg->content_protection->hdcp2_spec->hdcpversion=g_strdup("none");
890       } else {
891         WFD_READ_STRING(msg->content_protection->hdcp2_spec->hdcpversion);
892         WFD_SKIP_SPACE(v);
893         WFD_READ_STRING(msg->content_protection->hdcp2_spec->TCPPort);
894       }
895     }
896   } else if(!g_strcmp0(type,"wfd_display_edid")) {
897     msg->display_edid = g_new0 (WFDDisplayEdid, 1);
898     if(strlen(v)) {
899       WFD_SKIP_SPACE(v);
900       if(strstr(v,"none")) {
901         msg->display_edid->edid_supported = 0;
902       } else {
903         msg->display_edid->edid_supported = 1;
904         WFD_READ_UINT32(msg->display_edid->edid_block_count);
905         WFD_SKIP_SPACE(v);
906         if(msg->display_edid->edid_block_count) {
907           guint32 payload_size = EDID_BLOCK_SIZE * msg->display_edid->edid_block_count;
908           msg->display_edid->edid_payload = g_malloc(payload_size);
909           memcpy(msg->display_edid->edid_payload, v, payload_size);
910             v += payload_size;
911         } else v += strlen(v);
912       }
913     }
914   } else if(!g_strcmp0(type,"wfd_coupled_sink")) {
915     msg->coupled_sink = g_new0 (WFDCoupledSink, 1);
916     if(strlen(v)) {
917     msg->coupled_sink->coupled_sink_cap = g_new0 (WFDCoupled_sink_cap, 1);
918     WFD_SKIP_SPACE(v);
919     WFD_READ_UINT32(msg->coupled_sink->coupled_sink_cap->status);
920     WFD_SKIP_SPACE(v);
921     WFD_READ_STRING(msg->coupled_sink->coupled_sink_cap->sink_address);
922     }
923   } else if(!g_strcmp0(type,"wfd_trigger_method")) {
924     msg->trigger_method = g_new0 (WFDTriggerMethod, 1);
925     if(strlen(v)) {
926       WFD_SKIP_SPACE(v);
927       WFD_READ_STRING(msg->trigger_method->wfd_trigger_method);
928     }
929   } else if(!g_strcmp0(type,"wfd_presentation_URL")) {
930     msg->presentation_url = g_new0 (WFDPresentationUrl, 1);
931     if(strlen(v)) {
932       WFD_SKIP_SPACE(v);
933       WFD_READ_STRING(msg->presentation_url->wfd_url0);
934       WFD_SKIP_SPACE(v);
935       WFD_READ_STRING(msg->presentation_url->wfd_url1);
936     }
937   } else if(!g_strcmp0(type,"wfd_client_rtp_ports")) {
938     msg->client_rtp_ports = g_new0 (WFDClientRtpPorts, 1);
939     if(strlen(v)) {
940       WFD_SKIP_SPACE(v);
941       WFD_READ_STRING(msg->client_rtp_ports->profile);
942       WFD_SKIP_SPACE(v);
943       WFD_READ_UINT32_DIGIT(msg->client_rtp_ports->rtp_port0);
944       WFD_SKIP_SPACE(v);
945       WFD_READ_UINT32_DIGIT(msg->client_rtp_ports->rtp_port1);
946       WFD_SKIP_SPACE(v);
947       WFD_READ_STRING(msg->client_rtp_ports->mode);
948     }
949   } else if(!g_strcmp0(type,"wfd_route")) {
950     msg->route = g_new0 (WFDRoute, 1);
951     if(strlen(v)) {
952       WFD_SKIP_SPACE(v);
953       WFD_READ_STRING(msg->route->destination);
954     }
955   } else if(!g_strcmp0(type,"wfd_I2C")) {
956     msg->I2C = g_new0 (WFDI2C, 1);
957     if(strlen(v)) {
958       msg->I2C->I2CPresent = TRUE;
959       WFD_SKIP_SPACE(v);
960       WFD_READ_UINT32_DIGIT(msg->I2C->I2C_port);
961       if(msg->I2C->I2C_port) msg->I2C->I2CPresent = TRUE;
962     }
963   } else if(!g_strcmp0(type,"wfd_av_format_change_timing")) {
964     msg->av_format_change_timing = g_new0 (WFDAVFormatChangeTiming, 1);
965     if(strlen(v)) {
966     WFD_SKIP_SPACE(v);
967     WFD_READ_UINT32(msg->av_format_change_timing->PTS);
968     WFD_SKIP_SPACE(v);
969     WFD_READ_UINT32(msg->av_format_change_timing->DTS);
970     }
971   } else if(!g_strcmp0(type,"wfd_preferred_display_mode")) {
972     msg->preferred_display_mode = g_new0 (WFDPreferredDisplayMode, 1);
973     if(strlen(v)) {
974       WFD_SKIP_SPACE(v);
975       if(!strstr(v,"none")) {
976         msg->preferred_display_mode->displaymodesupported = FALSE;
977       } else {
978         WFD_READ_UINT32(msg->preferred_display_mode->p_clock);
979         WFD_SKIP_SPACE(v);
980         WFD_READ_UINT32(msg->preferred_display_mode->H);
981         WFD_SKIP_SPACE(v);
982         WFD_READ_UINT32(msg->preferred_display_mode->HB);
983         WFD_SKIP_SPACE(v);
984         WFD_READ_UINT32(msg->preferred_display_mode->HSPOL_HSOFF);
985         WFD_SKIP_SPACE(v);
986         WFD_READ_UINT32(msg->preferred_display_mode->HSW);
987         WFD_SKIP_SPACE(v);
988         WFD_READ_UINT32(msg->preferred_display_mode->V);
989         WFD_SKIP_SPACE(v);
990         WFD_READ_UINT32(msg->preferred_display_mode->VB);
991         WFD_SKIP_SPACE(v);
992         WFD_READ_UINT32(msg->preferred_display_mode->VSPOL_VSOFF);
993         WFD_SKIP_SPACE(v);
994         WFD_READ_UINT32(msg->preferred_display_mode->VSW);
995         WFD_SKIP_SPACE(v);
996         WFD_READ_UINT32(msg->preferred_display_mode->VBS3D);
997         WFD_SKIP_SPACE(v);
998         WFD_READ_UINT32(msg->preferred_display_mode->V2d_s3d_modes);
999         WFD_SKIP_SPACE(v);
1000         WFD_READ_UINT32(msg->preferred_display_mode->P_depth);
1001         WFD_SKIP_SPACE(v);
1002         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.profile);
1003         WFD_SKIP_SPACE(v);
1004         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.level);
1005         WFD_SKIP_SPACE(v);
1006         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.misc_params.CEA_Support);
1007         WFD_SKIP_SPACE(v);
1008         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.misc_params.VESA_Support);
1009         WFD_SKIP_SPACE(v);
1010         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.misc_params.HH_Support);
1011         WFD_SKIP_SPACE(v);
1012         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.misc_params.latency);
1013         WFD_SKIP_SPACE(v);
1014         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.misc_params.min_slice_size);
1015         WFD_SKIP_SPACE(v);
1016         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.misc_params.slice_enc_params);
1017         WFD_SKIP_SPACE(v);
1018         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.misc_params.frame_rate_control_support);
1019         WFD_SKIP_SPACE(v);
1020         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.max_hres);
1021         WFD_SKIP_SPACE(v);
1022         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.max_vres);
1023         WFD_SKIP_SPACE(v);
1024       }
1025     }
1026   } else if(!g_strcmp0(type,"wfd_uibc_capability")) {
1027     msg->uibc_capability = g_new0 (WFDUibcCapability, 1);
1028     if(!strstr(v,"none")) {
1029       msg->uibc_capability->uibcsupported = FALSE;
1030     } else {
1031       gchar *tstring = NULL;
1032       msg->uibc_capability->uibcsupported = TRUE;
1033       WFD_READ_CHAR_END_STRING(tstring, '=');
1034       if(!g_strcmp0(tstring,"input_category_list")) {
1035         if(!strstr(v,"none")) {
1036
1037         } else {
1038           gchar temp[8192];
1039           guint rem_len, read_len=0;
1040           WFD_READ_CHAR_END_STRING(tstring, ';');
1041           rem_len = strlen(tstring);
1042           do {
1043             read_string_char_ended (temp, 8192, ',', tstring+read_len);
1044             read_len += (strlen(temp)+1);
1045             if(!g_strcmp0(temp,"GENERIC")) msg->uibc_capability->input_category_list.input_cat |= WFD_UIBC_INPUT_CAT_GENERIC;
1046             else if(!g_strcmp0(temp,"HIDC")) msg->uibc_capability->input_category_list.input_cat |= WFD_UIBC_INPUT_CAT_HIDC;
1047             else msg->uibc_capability->input_category_list.input_cat |= WFD_UIBC_INPUT_CAT_UNKNOWN;
1048           } while(read_len < rem_len);
1049         }
1050       }
1051       WFD_READ_CHAR_END_STRING(tstring, '=');
1052       if(!g_strcmp0(tstring,"generic_cap_list=")) {
1053         if(!strstr(v,"none")) {
1054         } else {
1055           gchar temp[8192];
1056           guint rem_len, read_len=0;
1057           WFD_READ_CHAR_END_STRING(tstring, ';');
1058           rem_len = strlen(tstring);
1059           do {
1060             read_string_char_ended (temp, 8192, ',', tstring+read_len);
1061             read_len += (strlen(temp)+1);
1062             if(!g_strcmp0(temp,"Keyboard")) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_KEYBOARD;
1063             else if(!g_strcmp0(temp,"Mouse")) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_MOUSE;
1064             else if(!g_strcmp0(temp,"SingleTouch")) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_SINGLETOUCH;
1065             else if(!g_strcmp0(temp,"MultiTouch")) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_MULTITOUCH;
1066             else if(!g_strcmp0(temp,"Joystick")) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_JOYSTICK;
1067             else if(!g_strcmp0(temp,"Camera")) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_CAMERA;
1068             else if(!g_strcmp0(temp,"Gesture")) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_GESTURE;
1069             else if(!g_strcmp0(temp,"RemoteControl")) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_REMOTECONTROL;
1070             else msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_UNKNOWN;
1071           } while(read_len < rem_len);
1072         }
1073       }
1074       WFD_READ_CHAR_END_STRING(tstring, '=');
1075       if(!g_strcmp0(tstring,"hidc_cap_list=")) {
1076         if(!strstr(v,"none")) {
1077         } else {
1078           gchar temp[8192];
1079           gchar inp_type[8192];
1080           gchar inp_path[8192];
1081           guint rem_len, read_len=0;
1082           detailed_cap *temp_cap;
1083           WFD_READ_CHAR_END_STRING(tstring, ';');
1084           rem_len = strlen(tstring);
1085           msg->uibc_capability->hidc_cap_list.next = g_new0 (detailed_cap, 1);
1086           temp_cap = msg->uibc_capability->hidc_cap_list.next;
1087           do {
1088             msg->uibc_capability->hidc_cap_list.cap_count++;
1089             read_string_char_ended (temp, 8192, ',', tstring+read_len);
1090             read_len += (strlen(temp)+1);
1091             read_string_type_and_value (inp_type, inp_path, sizeof(inp_type), sizeof(inp_path), '/', temp);
1092             if(!strstr(inp_type,"Keyboard")) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_KEYBOARD;
1093             else if(!strstr(inp_type,"Mouse")) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_MOUSE;
1094             else if(!strstr(inp_type,"SingleTouch")) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_SINGLETOUCH;
1095             else if(!strstr(inp_type,"MultiTouch")) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_MULTITOUCH;
1096             else if(!strstr(inp_type,"Joystick")) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_JOYSTICK;
1097             else if(!strstr(inp_type,"Camera")) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_CAMERA;
1098             else if(!strstr(inp_type,"Gesture")) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_GESTURE;
1099             else if(!strstr(inp_type,"RemoteControl")) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_REMOTECONTROL;
1100             else temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_UNKNOWN;
1101
1102             if(!strstr(inp_path,"Infrared")) temp_cap->p.inp_path = WFD_UIBC_INPUT_PATH_INFRARED;
1103             else if(!strstr(inp_path,"USB")) temp_cap->p.inp_path = WFD_UIBC_INPUT_PATH_USB;
1104             else if(!strstr(inp_path,"BT")) temp_cap->p.inp_path = WFD_UIBC_INPUT_PATH_BT;
1105             else if(!strstr(inp_path,"Zigbee")) temp_cap->p.inp_path = WFD_UIBC_INPUT_PATH_ZIGBEE;
1106             else if(!strstr(inp_path,"Wi-Fi")) temp_cap->p.inp_path = WFD_UIBC_INPUT_PATH_WIFI;
1107             else if(!strstr(inp_path,"No-SP")) temp_cap->p.inp_path = WFD_UIBC_INPUT_PATH_NOSP;
1108             else temp_cap->p.inp_path = WFD_UIBC_INPUT_PATH_UNKNOWN;
1109             if(read_len < rem_len) {
1110               temp_cap->next = g_new0 (detailed_cap, 1);
1111               temp_cap = temp_cap->next;
1112             }
1113           } while(read_len < rem_len);
1114         }
1115       }
1116       WFD_READ_CHAR_END_STRING(tstring, '=');
1117       if(!g_strcmp0(tstring,"hidc_cap_list=")) {
1118         if(!strstr(v,"none")) {
1119         } else {
1120           WFD_READ_UINT32(msg->uibc_capability->tcp_port);
1121         }
1122       }
1123     }
1124   } else if(!g_strcmp0(type,"wfd_uibc_setting")) {
1125     msg->uibc_setting = g_new0 (WFDUibcSetting, 1);
1126     if(strlen(v)) {
1127       WFD_SKIP_SPACE(v);
1128       if(!g_strcmp0(v, "enable"))
1129         msg->uibc_setting->uibc_setting = TRUE;
1130       else
1131         msg->uibc_setting->uibc_setting = FALSE;
1132     }
1133   } else if(!g_strcmp0(type,"wfd_standby_resume_capability")) {
1134     msg->standby_resume_capability = g_new0 (WFDStandbyResumeCapability, 1);
1135     if(strlen(v)) {
1136       WFD_SKIP_SPACE(v);
1137       if(!g_strcmp0(v, "supported"))
1138         msg->standby_resume_capability->standby_resume_cap = TRUE;
1139       else
1140         msg->standby_resume_capability->standby_resume_cap = FALSE;
1141     }
1142   } else if(!g_strcmp0(type,"wfd_standby")) {
1143     msg->standby = g_new0 (WFDStandby, 1);
1144     msg->standby->wfd_standby = TRUE;
1145   } else if(!g_strcmp0(type,"wfd_connector_type")) {
1146     msg->connector_type = g_new0 (WFDConnectorType, 1);
1147     if(strlen(v)) {
1148     msg->connector_type->supported = TRUE;
1149     WFD_SKIP_SPACE(v);
1150     WFD_READ_UINT32(msg->connector_type->connector_type);
1151     }
1152   } else if(!g_strcmp0(type,"wfd_idr_request")) {
1153     msg->idr_request = g_new0 (WFDIdrRequest, 1);
1154     msg->idr_request->idr_request = TRUE;
1155   }
1156
1157   return TRUE;
1158 }
1159
1160 /**
1161 * wfdconfig_message_parse_buffer:
1162 * @data: the start of the buffer
1163 * @size: the size of the buffer
1164 * @msg: the result #WFDMessage
1165 *
1166 * Parse the contents of @size bytes pointed to by @data and store the result in
1167 * @msg.
1168 *
1169 * Returns: #WFD_OK on success.
1170 */
1171 WFDResult
1172 wfdconfig_message_parse_buffer (const guint8 * data, guint size, WFDMessage * msg)
1173 {
1174   gchar *p;
1175   gchar buffer[MAX_LINE_LEN];
1176   guint idx = 0;
1177
1178   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1179   g_return_val_if_fail (data != NULL, WFD_EINVAL);
1180   g_return_val_if_fail (size != 0, WFD_EINVAL);
1181
1182   GST_LOG("wfdconfig_message_parse_buffer input: %s\n", data);
1183
1184   p = (gchar *) data;
1185   while (TRUE) {
1186
1187     if (*p == '\0')
1188     break;
1189
1190     idx = 0;
1191     while (*p != '\n' && *p != '\r' && *p != '\0') {
1192       if (idx < sizeof (buffer) - 1)
1193         buffer[idx++] = *p;
1194       p++;
1195     }
1196     buffer[idx] = '\0';
1197     wfdconfig_parse_line (msg, buffer);
1198
1199     if (*p == '\0')
1200       break;
1201     p+=2;
1202   }
1203
1204   return WFD_OK;
1205 }
1206
1207 /**
1208 * wfdconfig_message_dump:
1209 * @msg: a #WFDMessage
1210 *
1211 * Dump the parsed contents of @msg to stdout.
1212 *
1213 * Returns: a #WFDResult.
1214 */
1215 WFDResult
1216 wfdconfig_message_dump (const WFDMessage * msg)
1217 {
1218   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1219   debug_log("===========WFD Message dump=========");
1220
1221   if(msg->audio_codecs) {
1222     guint i=0;
1223     debug_log("Audio supported formats : \n");
1224     for(;i<msg->audio_codecs->count;i++) {
1225       debug_log("Codec: %s\n",msg->audio_codecs->list[i].audio_format);
1226       if(!strcmp(msg->audio_codecs->list[i].audio_format,"LPCM")) {
1227         if(msg->audio_codecs->list[i].modes & WFD_FREQ_44100)
1228           debug_log("   Freq: %d\n", 44100);
1229         if(msg->audio_codecs->list[i].modes & WFD_FREQ_48000)
1230           debug_log("   Freq: %d\n", 48000);
1231         debug_log("     Channels: %d\n", 2);
1232       }
1233       if(!strcmp(msg->audio_codecs->list[i].audio_format,"AAC")) {
1234         debug_log("     Freq: %d\n", 48000);
1235         if(msg->audio_codecs->list[i].modes & WFD_CHANNEL_2)
1236           debug_log("   Channels: %d\n", 2);
1237         if(msg->audio_codecs->list[i].modes & WFD_CHANNEL_4)
1238           debug_log("   Channels: %d\n", 4);
1239         if(msg->audio_codecs->list[i].modes & WFD_CHANNEL_6)
1240           debug_log("   Channels: %d\n", 6);
1241         if(msg->audio_codecs->list[i].modes & WFD_CHANNEL_8)
1242           debug_log("   Channels: %d\n", 8);
1243       }
1244       if(!strcmp(msg->audio_codecs->list[i].audio_format,"AC3")) {
1245         debug_log("     Freq: %d\n", 48000);
1246         if(msg->audio_codecs->list[i].modes & WFD_CHANNEL_2)
1247           debug_log("   Channels: %d\n", 2);
1248         if(msg->audio_codecs->list[i].modes & WFD_CHANNEL_4)
1249           debug_log("   Channels: %d\n", 4);
1250         if(msg->audio_codecs->list[i].modes & WFD_CHANNEL_6)
1251           debug_log("   Channels: %d\n", 6);
1252       }
1253       debug_log("       Bitwidth: %d\n", 16);
1254       debug_log("       Latency: %d\n", msg->audio_codecs->list[i].latency);
1255     }
1256   }
1257
1258
1259   if(msg->video_formats) {
1260     debug_log("Video supported formats : \n");
1261     if(msg->video_formats->list) {
1262       debug_log("Codec: H264\n");
1263       guint nativeindex = 0;
1264       if((msg->video_formats->list->native & 0x7) == WFD_VIDEO_CEA_RESOLUTION) {
1265         debug_log ("    Native type: CEA\n");
1266       } else if((msg->video_formats->list->native & 0x7) == WFD_VIDEO_VESA_RESOLUTION) {
1267         debug_log ("    Native type: VESA\n");
1268       } else if((msg->video_formats->list->native & 0x7) == WFD_VIDEO_HH_RESOLUTION) {
1269         debug_log ("    Native type: HH\n");
1270       }
1271       nativeindex = msg->video_formats->list->native >> 3;
1272       debug_log ("      Resolution: %d\n", (1 << nativeindex));
1273
1274       if(msg->video_formats->list->H264_codec.profile & WFD_H264_BASE_PROFILE) {
1275         debug_log ("    Profile: BASE\n");
1276       } else if(msg->video_formats->list->H264_codec.profile & WFD_H264_HIGH_PROFILE) {
1277         debug_log ("    Profile: HIGH\n");
1278       } if(msg->video_formats->list->H264_codec.level & WFD_H264_LEVEL_3_1) {
1279         debug_log ("    Level: 3.1\n");
1280       } else if(msg->video_formats->list->H264_codec.level & WFD_H264_LEVEL_3_2) {
1281         debug_log ("    Level: 3.2\n");
1282       } else if(msg->video_formats->list->H264_codec.level & WFD_H264_LEVEL_4) {
1283         debug_log ("    Level: 4\n");
1284       } else if(msg->video_formats->list->H264_codec.level & WFD_H264_LEVEL_4_1) {
1285         debug_log ("    Level: 4.1\n");
1286       } else if(msg->video_formats->list->H264_codec.level & WFD_H264_LEVEL_4_2) {
1287         debug_log ("    Level: 4.2\n");
1288       }
1289       debug_log ("      Latency: %d\n", msg->video_formats->list->H264_codec.misc_params.latency);
1290       debug_log ("      min_slice_size: %x\n", msg->video_formats->list->H264_codec.misc_params.min_slice_size);
1291       debug_log ("      slice_enc_params: %x\n", msg->video_formats->list->H264_codec.misc_params.slice_enc_params);
1292       debug_log ("      frame_rate_control_support: %x\n", msg->video_formats->list->H264_codec.misc_params.frame_rate_control_support);
1293       if(msg->video_formats->list->H264_codec.max_hres) {
1294         debug_log ("    Max Height: %04d\n", msg->video_formats->list->H264_codec.max_hres);
1295       }
1296       if(msg->video_formats->list->H264_codec.max_vres) {
1297         debug_log ("    Max Width: %04d\n", msg->video_formats->list->H264_codec.max_vres);
1298       }
1299     }
1300   }
1301
1302   if(msg->video_3d_formats) {
1303     debug_log ("wfd_3d_formats");
1304     debug_log ("\r\n");
1305   }
1306
1307   if(msg->content_protection) {
1308     debug_log ("wfd_content_protection");
1309     debug_log ("\r\n");
1310   }
1311
1312   if(msg->display_edid) {
1313     debug_log ("wfd_display_edid");
1314     debug_log ("\r\n");
1315   }
1316
1317   if(msg->coupled_sink) {
1318     debug_log ("wfd_coupled_sink");
1319     debug_log ("\r\n");
1320   }
1321
1322   if(msg->trigger_method) {
1323     debug_log ("        Trigger type: %s\n", msg->trigger_method->wfd_trigger_method);
1324   }
1325
1326   if(msg->presentation_url) {
1327     debug_log ("wfd_presentation_URL");
1328     debug_log ("\r\n");
1329   }
1330
1331   if(msg->client_rtp_ports) {
1332     debug_log(" Client RTP Ports : \n");
1333     if(msg->client_rtp_ports->profile) {
1334       debug_log ("%s\n", msg->client_rtp_ports->profile);
1335       debug_log ("      %d\n", msg->client_rtp_ports->rtp_port0);
1336       debug_log ("      %d\n", msg->client_rtp_ports->rtp_port1);
1337       debug_log ("      %s\n", msg->client_rtp_ports->mode);
1338     }
1339   }
1340
1341   if(msg->route) {
1342     debug_log ("wfd_route");
1343     debug_log ("\r\n");
1344   }
1345
1346   if(msg->I2C) {
1347     debug_log ("wfd_I2C");
1348     debug_log ("\r\n");
1349   }
1350
1351   if(msg->av_format_change_timing) {
1352     debug_log ("wfd_av_format_change_timing");
1353     debug_log ("\r\n");
1354   }
1355
1356   if(msg->preferred_display_mode) {
1357     debug_log ("wfd_preferred_display_mode");
1358     debug_log ("\r\n");
1359   }
1360
1361   if(msg->uibc_capability) {
1362     debug_log ("wfd_uibc_capability");
1363     debug_log ("\r\n");
1364   }
1365
1366   if(msg->uibc_setting) {
1367     debug_log ("wfd_uibc_setting");
1368     debug_log ("\r\n");
1369   }
1370
1371   if(msg->standby_resume_capability) {
1372     debug_log ("wfd_standby_resume_capability");
1373     debug_log ("\r\n");
1374   }
1375
1376   if(msg->standby) {
1377     debug_log ("wfd_standby");
1378     debug_log ("\r\n");
1379   }
1380
1381   if(msg->connector_type) {
1382     debug_log ("wfd_connector_type");
1383     debug_log ("\r\n");
1384   }
1385
1386   if(msg->idr_request) {
1387     debug_log ("wfd_idr_request");
1388     debug_log ("\r\n");
1389   }
1390   debug_log("===============================================\n");
1391   return WFD_OK;
1392 }
1393
1394 WFDResult wfdconfig_set_supported_audio_format(WFDMessage *msg, WFDAudioFormats aCodec, guint aFreq, guint aChanels,
1395                                                                                               guint aBitwidth, guint32 aLatency)
1396 {
1397   guint temp = aCodec;
1398   guint i = 0;
1399   guint pcm = 0, aac = 0, ac3 = 0;
1400
1401   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1402
1403   if(!msg->audio_codecs)
1404     msg->audio_codecs = g_new0 (WFDAudioCodeclist, 1);
1405
1406   if(aCodec != WFD_AUDIO_UNKNOWN) {
1407     while(temp) {
1408       msg->audio_codecs->count++;
1409       temp >>= 1;
1410     }
1411     msg->audio_codecs->list = g_new0 (WFDAudioCodec, msg->audio_codecs->count);
1412     for(; i<msg->audio_codecs->count; i++) {
1413       if((aCodec & WFD_AUDIO_LPCM) && (!pcm)) {
1414         msg->audio_codecs->list[i].audio_format = g_strdup("LPCM");
1415         msg->audio_codecs->list[i].modes = aFreq;
1416         msg->audio_codecs->list[i].latency = aLatency;
1417         pcm = 1;
1418       } else if((aCodec & WFD_AUDIO_AAC) && (!aac)) {
1419         msg->audio_codecs->list[i].audio_format = g_strdup("AAC");
1420         msg->audio_codecs->list[i].modes = aChanels;
1421         msg->audio_codecs->list[i].latency = aLatency;
1422         aac = 1;
1423       } else if((aCodec & WFD_AUDIO_AC3) && (!ac3)) {
1424         msg->audio_codecs->list[i].audio_format = g_strdup("AC3");
1425         msg->audio_codecs->list[i].modes = aChanels;
1426         msg->audio_codecs->list[i].latency = aLatency;
1427         ac3 = 1;
1428       }
1429     }
1430   }
1431   return WFD_OK;
1432 }
1433
1434 WFDResult wfdconfig_set_prefered_audio_format(WFDMessage *msg, WFDAudioFormats aCodec, WFDAudioFreq aFreq, WFDAudioChannels aChanels,
1435                                                                                           guint aBitwidth, guint32 aLatency)
1436 {
1437
1438   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1439
1440   if(!msg->audio_codecs)
1441     msg->audio_codecs = g_new0 (WFDAudioCodeclist, 1);
1442
1443   msg->audio_codecs->list = g_new0 (WFDAudioCodec, 1);
1444   msg->audio_codecs->count = 1;
1445   if(aCodec == WFD_AUDIO_LPCM) {
1446     msg->audio_codecs->list->audio_format = g_strdup("LPCM");
1447     msg->audio_codecs->list->modes = aFreq;
1448     msg->audio_codecs->list->latency = aLatency;
1449   } else if(aCodec == WFD_AUDIO_AAC) {
1450     msg->audio_codecs->list->audio_format = g_strdup("AAC");
1451     msg->audio_codecs->list->modes = aChanels;
1452     msg->audio_codecs->list->latency = aLatency;
1453   } else if(aCodec == WFD_AUDIO_AC3) {
1454     msg->audio_codecs->list->audio_format = g_strdup("AC3");
1455     msg->audio_codecs->list->modes = aChanels;
1456     msg->audio_codecs->list->latency = aLatency;
1457   }
1458   return WFD_OK;
1459 }
1460
1461 WFDResult wfdconfig_get_supported_audio_format(WFDMessage *msg, guint *aCodec, guint *aFreq, guint *aChanels,
1462                                                                                              guint *aBitwidth, guint32 *aLatency)
1463 {
1464   guint i = 0;
1465   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1466   g_return_val_if_fail (msg->audio_codecs != NULL, WFD_EINVAL);
1467
1468   for(; i<msg->audio_codecs->count; i++) {
1469     if(!g_strcmp0(msg->audio_codecs->list[i].audio_format,"LPCM")) {
1470       *aCodec |= WFD_AUDIO_LPCM;
1471       *aFreq |= msg->audio_codecs->list[i].modes;
1472       *aChanels |= WFD_CHANNEL_2;
1473       *aBitwidth = 16;
1474       *aLatency = msg->audio_codecs->list[i].latency;
1475     } else if(!g_strcmp0(msg->audio_codecs->list[i].audio_format,"AAC")) {
1476       *aCodec |= WFD_AUDIO_AAC;
1477       *aFreq |= WFD_FREQ_48000;
1478       *aChanels |= msg->audio_codecs->list[i].modes;
1479       *aBitwidth = 16;
1480       *aLatency = msg->audio_codecs->list[i].latency;
1481     } else if(!g_strcmp0(msg->audio_codecs->list[i].audio_format,"AC3")) {
1482       *aCodec |= WFD_AUDIO_AC3;
1483       *aFreq |= WFD_FREQ_48000;
1484       *aChanels |= msg->audio_codecs->list[i].modes;
1485       *aBitwidth = 16;
1486       *aLatency = msg->audio_codecs->list[i].latency;
1487     }
1488   }
1489   return WFD_OK;
1490 }
1491
1492 WFDResult wfdconfig_get_prefered_audio_format(WFDMessage *msg, WFDAudioFormats *aCodec, WFDAudioFreq *aFreq, WFDAudioChannels *aChanels,
1493                                                                                           guint *aBitwidth, guint32 *aLatency)
1494 {
1495   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1496
1497   if(!g_strcmp0(msg->audio_codecs->list->audio_format,"LPCM")) {
1498     *aCodec = WFD_AUDIO_LPCM;
1499     *aFreq = msg->audio_codecs->list->modes;
1500     *aChanels = WFD_CHANNEL_2;
1501     *aBitwidth = 16;
1502     *aLatency = msg->audio_codecs->list->latency;
1503   } else if(!g_strcmp0(msg->audio_codecs->list->audio_format,"AAC")) {
1504     *aCodec = WFD_AUDIO_AAC;
1505     *aFreq = WFD_FREQ_48000;
1506     *aChanels = msg->audio_codecs->list->modes;
1507     *aBitwidth = 16;
1508     *aLatency = msg->audio_codecs->list->latency;
1509   } else if(!g_strcmp0(msg->audio_codecs->list->audio_format,"AC3")) {
1510     *aCodec = WFD_AUDIO_AC3;
1511     *aFreq = WFD_FREQ_48000;
1512     *aChanels = msg->audio_codecs->list->modes;
1513     *aBitwidth = 16;
1514     *aLatency = msg->audio_codecs->list->latency;
1515   }
1516   return WFD_OK;
1517 }
1518
1519 WFDResult wfdconfig_set_supported_video_format(WFDMessage *msg, WFDVideoCodecs vCodec,
1520                       WFDVideoNativeResolution vNative, guint64 vNativeResolution,
1521                       guint64 vCEAResolution, guint64 vVESAResolution, guint64 vHHResolution,
1522                       guint vProfile, guint vLevel, guint32 vLatency, guint32 vMaxHeight,
1523                       guint32 vMaxWidth, guint32 min_slice_size, guint32 slice_enc_params, guint frame_rate_control)
1524 {
1525   guint nativeindex = 0;
1526   guint64 temp = vNativeResolution;
1527
1528   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1529
1530   if(!msg->video_formats)
1531   msg->video_formats = g_new0 (WFDVideoCodeclist, 1);
1532
1533   if(vCodec != WFD_VIDEO_UNKNOWN) {
1534     msg->video_formats->list = g_new0 (WFDVideoCodec, 1);
1535     while(temp) {
1536       nativeindex++;
1537       temp >>= 1;
1538     }
1539
1540     msg->video_formats->list->native = nativeindex-1;
1541     msg->video_formats->list->native <<= 3;
1542
1543     if(vNative == WFD_VIDEO_VESA_RESOLUTION)
1544       msg->video_formats->list->native |= 1;
1545     else if(vNative == WFD_VIDEO_HH_RESOLUTION)
1546       msg->video_formats->list->native |= 2;
1547
1548     msg->video_formats->list->preferred_display_mode_supported = 1;
1549     msg->video_formats->list->H264_codec.profile = vProfile;
1550     msg->video_formats->list->H264_codec.level = vLevel;
1551     msg->video_formats->list->H264_codec.max_hres = vMaxHeight;
1552     msg->video_formats->list->H264_codec.max_vres = vMaxWidth;
1553     msg->video_formats->list->H264_codec.misc_params.CEA_Support = vCEAResolution;
1554     msg->video_formats->list->H264_codec.misc_params.VESA_Support = vVESAResolution;
1555     msg->video_formats->list->H264_codec.misc_params.HH_Support = vHHResolution;
1556     msg->video_formats->list->H264_codec.misc_params.latency = vLatency;
1557     msg->video_formats->list->H264_codec.misc_params.min_slice_size = min_slice_size;
1558     msg->video_formats->list->H264_codec.misc_params.slice_enc_params = slice_enc_params;
1559     msg->video_formats->list->H264_codec.misc_params.frame_rate_control_support = frame_rate_control;
1560   }
1561   return WFD_OK;
1562 }
1563
1564 WFDResult wfdconfig_set_prefered_video_format(WFDMessage *msg, WFDVideoCodecs vCodec,
1565                   WFDVideoNativeResolution vNative, guint64 vNativeResolution,
1566                   WFDVideoCEAResolution vCEAResolution, WFDVideoVESAResolution vVESAResolution,
1567                   WFDVideoHHResolution vHHResolution,   WFDVideoH264Profile vProfile,
1568                   WFDVideoH264Level vLevel, guint32 vLatency, guint32 vMaxHeight,
1569                   guint32 vMaxWidth, guint32 min_slice_size, guint32 slice_enc_params, guint frame_rate_control)
1570 {
1571   guint nativeindex = 0;
1572   guint64 temp = vNativeResolution;
1573
1574   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1575
1576   if(!msg->video_formats)
1577     msg->video_formats = g_new0 (WFDVideoCodeclist, 1);
1578   msg->video_formats->list = g_new0 (WFDVideoCodec, 1);
1579
1580   while(temp) {
1581     nativeindex++;
1582     temp >>= 1;
1583   }
1584
1585   if(nativeindex) msg->video_formats->list->native = nativeindex-1;
1586   msg->video_formats->list->native <<= 3;
1587
1588   if(vNative == WFD_VIDEO_VESA_RESOLUTION)
1589     msg->video_formats->list->native |= 1;
1590   else if(vNative == WFD_VIDEO_HH_RESOLUTION)
1591     msg->video_formats->list->native |= 2;
1592
1593   msg->video_formats->list->preferred_display_mode_supported = 0;
1594   msg->video_formats->list->H264_codec.profile = vProfile;
1595   msg->video_formats->list->H264_codec.level = vLevel;
1596   msg->video_formats->list->H264_codec.max_hres = vMaxHeight;
1597   msg->video_formats->list->H264_codec.max_vres = vMaxWidth;
1598   msg->video_formats->list->H264_codec.misc_params.CEA_Support = vCEAResolution;
1599   msg->video_formats->list->H264_codec.misc_params.VESA_Support = vVESAResolution;
1600   msg->video_formats->list->H264_codec.misc_params.HH_Support = vHHResolution;
1601   msg->video_formats->list->H264_codec.misc_params.latency = vLatency;
1602   msg->video_formats->list->H264_codec.misc_params.min_slice_size = min_slice_size;
1603   msg->video_formats->list->H264_codec.misc_params.slice_enc_params = slice_enc_params;
1604   msg->video_formats->list->H264_codec.misc_params.frame_rate_control_support = frame_rate_control;
1605   return WFD_OK;
1606 }
1607
1608 WFDResult wfdconfig_get_supported_video_format(WFDMessage *msg, WFDVideoCodecs *vCodec,
1609                   WFDVideoNativeResolution *vNative, guint64 *vNativeResolution,
1610                   guint64 *vCEAResolution, guint64 *vVESAResolution, guint64 *vHHResolution,
1611                   guint *vProfile, guint *vLevel, guint32 *vLatency, guint32 *vMaxHeight,
1612                   guint32 *vMaxWidth, guint32 *min_slice_size, guint32 *slice_enc_params, guint *frame_rate_control)
1613 {
1614   guint nativeindex = 0;
1615
1616   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1617   *vCodec = WFD_VIDEO_H264;
1618   *vNative = msg->video_formats->list->native & 0x7;
1619   nativeindex = msg->video_formats->list->native >> 3;
1620   *vNativeResolution = 1 << nativeindex;
1621   *vProfile = msg->video_formats->list->H264_codec.profile;
1622   *vLevel = msg->video_formats->list->H264_codec.level;
1623   *vMaxHeight = msg->video_formats->list->H264_codec.max_hres;
1624   *vMaxWidth = msg->video_formats->list->H264_codec.max_vres;
1625   *vCEAResolution = msg->video_formats->list->H264_codec.misc_params.CEA_Support;
1626   *vVESAResolution = msg->video_formats->list->H264_codec.misc_params.VESA_Support;
1627   *vHHResolution = msg->video_formats->list->H264_codec.misc_params.HH_Support;
1628   *vLatency = msg->video_formats->list->H264_codec.misc_params.latency;
1629   *min_slice_size = msg->video_formats->list->H264_codec.misc_params.min_slice_size;
1630   *slice_enc_params = msg->video_formats->list->H264_codec.misc_params.slice_enc_params;
1631   *frame_rate_control = msg->video_formats->list->H264_codec.misc_params.frame_rate_control_support;
1632   return WFD_OK;
1633 }
1634
1635 WFDResult wfdconfig_get_prefered_video_format(WFDMessage *msg, WFDVideoCodecs *vCodec,
1636                  WFDVideoNativeResolution *vNative, guint64 *vNativeResolution,
1637                  WFDVideoCEAResolution *vCEAResolution, WFDVideoVESAResolution *vVESAResolution,
1638                  WFDVideoHHResolution *vHHResolution,   WFDVideoH264Profile *vProfile,
1639                  WFDVideoH264Level *vLevel, guint32 *vLatency, guint32 *vMaxHeight,
1640                  guint32 *vMaxWidth, guint32 *min_slice_size, guint32 *slice_enc_params, guint *frame_rate_control)
1641 {
1642   guint nativeindex = 0;
1643   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1644
1645   *vCodec = WFD_VIDEO_H264;
1646   *vNative = msg->video_formats->list->native & 0x7;
1647   nativeindex = msg->video_formats->list->native >> 3;
1648   *vNativeResolution = 1 << nativeindex;
1649   *vProfile = msg->video_formats->list->H264_codec.profile;
1650   *vLevel = msg->video_formats->list->H264_codec.level;
1651   *vMaxHeight = msg->video_formats->list->H264_codec.max_hres;
1652   *vMaxWidth = msg->video_formats->list->H264_codec.max_vres;
1653   *vCEAResolution = msg->video_formats->list->H264_codec.misc_params.CEA_Support;
1654   *vVESAResolution = msg->video_formats->list->H264_codec.misc_params.VESA_Support;
1655   *vHHResolution = msg->video_formats->list->H264_codec.misc_params.HH_Support;
1656   *vLatency = msg->video_formats->list->H264_codec.misc_params.latency;
1657   *min_slice_size = msg->video_formats->list->H264_codec.misc_params.min_slice_size;
1658   *slice_enc_params = msg->video_formats->list->H264_codec.misc_params.slice_enc_params;
1659   *frame_rate_control = msg->video_formats->list->H264_codec.misc_params.frame_rate_control_support;
1660   return WFD_OK;
1661 }
1662
1663 WFDResult wfdconfig_set_contentprotection_type(WFDMessage *msg, WFDHDCPProtection hdcpversion, guint32 TCPPort)
1664 {
1665   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1666
1667  /*check LIBHDCP*/
1668   FILE *fp = NULL;
1669   fp = fopen(LIBHDCP, "r");
1670   if (fp == NULL) {
1671         return WFD_OK;
1672   }
1673   fclose(fp);
1674
1675   if(!msg->content_protection) msg->content_protection = g_new0 (WFDContentProtection, 1);
1676   if(hdcpversion == WFD_HDCP_NONE) return WFD_OK;
1677   msg->content_protection->hdcp2_spec = g_new0 (WFDHdcp2Spec, 1);
1678   if(hdcpversion == WFD_HDCP_2_0) msg->content_protection->hdcp2_spec->hdcpversion = g_strdup("HDCP2.0");
1679   else if(hdcpversion == WFD_HDCP_2_1) msg->content_protection->hdcp2_spec->hdcpversion = g_strdup("HDCP2.1");
1680   char str[11]={0,};
1681   sprintf(str, "port=%d", TCPPort);
1682   msg->content_protection->hdcp2_spec->TCPPort = g_strdup(str);
1683   return WFD_OK;
1684 }
1685
1686 WFDResult wfdconfig_get_contentprotection_type(WFDMessage *msg, WFDHDCPProtection *hdcpversion, guint32 *TCPPort)
1687 {
1688   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1689   if(msg->content_protection && msg->content_protection->hdcp2_spec) {
1690   char *result = NULL;
1691   gint value= 0;
1692     if(!g_strcmp0(msg->content_protection->hdcp2_spec->hdcpversion,"none")) {
1693         *hdcpversion = WFD_HDCP_NONE;
1694         *TCPPort = 0;
1695         return WFD_OK;
1696     }
1697     if(!g_strcmp0(msg->content_protection->hdcp2_spec->hdcpversion,"HDCP2.0")) *hdcpversion = WFD_HDCP_2_0;
1698     else if(!g_strcmp0(msg->content_protection->hdcp2_spec->hdcpversion,"HDCP2.1")) *hdcpversion = WFD_HDCP_2_1;
1699     result = strtok(msg->content_protection->hdcp2_spec->TCPPort, "=");
1700     while (result !=NULL) {
1701         result = strtok(NULL, "=");
1702         *TCPPort = atoi (result);
1703         break;
1704     }
1705   } else *hdcpversion = WFD_HDCP_NONE;
1706   return WFD_OK;
1707 }
1708
1709 WFDResult wfdconfig_set_display_EDID(WFDMessage *msg, gboolean edid_supported, guint32 edid_blockcount, gchar *edid_playload)
1710 {
1711   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1712   if(!msg->display_edid) msg->display_edid = g_new0 (WFDDisplayEdid, 1);
1713   msg->display_edid->edid_supported = edid_supported;
1714   if(!edid_supported) return WFD_OK;
1715   msg->display_edid->edid_block_count = edid_blockcount;
1716   if(edid_blockcount) {
1717     msg->display_edid->edid_payload = g_malloc(128 * edid_blockcount);
1718     if(!msg->display_edid->edid_payload)
1719       memcpy(msg->display_edid->edid_payload, edid_playload, 128 * edid_blockcount);
1720   } else msg->display_edid->edid_payload = g_strdup("none");
1721   return WFD_OK;
1722 }
1723
1724 WFDResult wfdconfig_get_display_EDID(WFDMessage *msg, gboolean *edid_supported, guint32 *edid_blockcount, gchar **edid_playload)
1725 {
1726   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1727   if(msg->display_edid ) {
1728     if(msg->display_edid->edid_supported) {
1729       *edid_blockcount = msg->display_edid->edid_block_count;
1730       if(msg->display_edid->edid_block_count) {
1731         char * temp;
1732         temp = g_malloc(EDID_BLOCK_SIZE * msg->display_edid->edid_block_count);
1733         if(temp) {
1734            memset(temp, 0, EDID_BLOCK_SIZE * msg->display_edid->edid_block_count);
1735           memcpy(temp, msg->display_edid->edid_payload, EDID_BLOCK_SIZE * msg->display_edid->edid_block_count);
1736            *edid_playload = temp;
1737           *edid_supported = TRUE;
1738         }
1739       } else *edid_playload = g_strdup("none");
1740     }
1741   } else *edid_supported = FALSE;
1742   return WFD_OK;
1743 }
1744
1745 WFDResult wfdconfig_set_coupled_sink(WFDMessage *msg, WFDCoupledSinkStatus status, gchar *sink_address)
1746 {
1747   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1748   if(!msg->coupled_sink) msg->coupled_sink = g_new0 (WFDCoupledSink, 1);
1749   if(status == WFD_SINK_UNKNOWN) return WFD_OK;
1750   msg->coupled_sink->coupled_sink_cap = g_new0 (WFDCoupled_sink_cap, 1);
1751   msg->coupled_sink->coupled_sink_cap->status = status;
1752   msg->coupled_sink->coupled_sink_cap->sink_address = g_strdup(sink_address);
1753   return WFD_OK;
1754 }
1755
1756 WFDResult wfdconfig_get_coupled_sink(WFDMessage *msg, WFDCoupledSinkStatus *status, gchar **sink_address)
1757 {
1758   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1759   if(msg->coupled_sink && msg->coupled_sink->coupled_sink_cap) {
1760     *status = msg->coupled_sink->coupled_sink_cap->status;
1761     *sink_address = g_strdup(msg->coupled_sink->coupled_sink_cap->sink_address);
1762   } else *status = WFD_SINK_UNKNOWN;
1763   return WFD_OK;
1764 }
1765
1766 WFDResult wfdconfig_set_trigger_type(WFDMessage *msg, WFDTrigger trigger)
1767 {
1768   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1769
1770   if(!msg->trigger_method)
1771     msg->trigger_method = g_new0 (WFDTriggerMethod, 1);
1772   if(trigger == WFD_TRIGGER_SETUP)
1773     msg->trigger_method->wfd_trigger_method = g_strdup("SETUP");
1774   else if(trigger == WFD_TRIGGER_PAUSE)
1775     msg->trigger_method->wfd_trigger_method = g_strdup("PAUSE");
1776   else if(trigger == WFD_TRIGGER_TEARDOWN)
1777     msg->trigger_method->wfd_trigger_method = g_strdup("TEARDOWN");
1778   else if(trigger == WFD_TRIGGER_PLAY)
1779     msg->trigger_method->wfd_trigger_method = g_strdup("PLAY");
1780   else
1781     return WFD_EINVAL;
1782   return WFD_OK;
1783 }
1784
1785 WFDResult wfdconfig_get_trigger_type(WFDMessage *msg, WFDTrigger *trigger)
1786 {
1787   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1788   if(!g_strcmp0(msg->trigger_method->wfd_trigger_method, "SETUP"))
1789     *trigger = WFD_TRIGGER_SETUP;
1790   else if(!g_strcmp0(msg->trigger_method->wfd_trigger_method, "PAUSE"))
1791     *trigger = WFD_TRIGGER_PAUSE;
1792   else if(!g_strcmp0(msg->trigger_method->wfd_trigger_method, "TEARDOWN"))
1793     *trigger = WFD_TRIGGER_TEARDOWN;
1794   else if(!g_strcmp0(msg->trigger_method->wfd_trigger_method, "PLAY"))
1795     *trigger = WFD_TRIGGER_PLAY;
1796   else {
1797     *trigger = WFD_TRIGGER_UNKNOWN;
1798     return WFD_EINVAL;
1799   }
1800   return WFD_OK;
1801 }
1802
1803 WFDResult wfdconfig_set_presentation_url(WFDMessage *msg, gchar *wfd_url0, gchar *wfd_url1)
1804 {
1805   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1806   if(!msg->presentation_url) msg->presentation_url = g_new0 (WFDPresentationUrl, 1);
1807   if(wfd_url0) msg->presentation_url->wfd_url0 = g_strdup(wfd_url0);
1808   if(wfd_url1) msg->presentation_url->wfd_url1 = g_strdup(wfd_url1);
1809   return WFD_OK;
1810 }
1811
1812 WFDResult wfdconfig_get_presentation_url(WFDMessage *msg, gchar **wfd_url0, gchar **wfd_url1)
1813 {
1814   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1815   if(msg->presentation_url) {
1816     *wfd_url0 = g_strdup(msg->presentation_url->wfd_url0);
1817     *wfd_url1 = g_strdup(msg->presentation_url->wfd_url1);
1818   }
1819   return WFD_OK;
1820 }
1821
1822 WFDResult wfdconfig_set_prefered_RTP_ports(WFDMessage *msg, WFDRTSPTransMode trans, WFDRTSPProfile profile,
1823                  WFDRTSPLowerTrans lowertrans, guint32 rtp_port0, guint32 rtp_port1)
1824 {
1825   GString *lines;
1826   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1827
1828   if(!msg->client_rtp_ports)
1829     msg->client_rtp_ports = g_new0 (WFDClientRtpPorts, 1);
1830
1831   if(trans != WFD_RTSP_TRANS_UNKNOWN) {
1832     lines = g_string_new ("");
1833     if(trans == WFD_RTSP_TRANS_RTP)     g_string_append_printf (lines,"RTP");
1834     else if(trans == WFD_RTSP_TRANS_RDT) g_string_append_printf (lines,"RDT");
1835
1836     if(profile == WFD_RTSP_PROFILE_AVP) g_string_append_printf (lines,"/AVP");
1837     else if(profile == WFD_RTSP_PROFILE_SAVP) g_string_append_printf (lines,"/SAVP");
1838
1839     if(lowertrans == WFD_RTSP_LOWER_TRANS_UDP) g_string_append_printf (lines,"/UDP;unicast");
1840     else if(lowertrans == WFD_RTSP_LOWER_TRANS_UDP_MCAST) g_string_append_printf (lines,"/UDP;multicast");
1841     else if(lowertrans == WFD_RTSP_LOWER_TRANS_TCP) g_string_append_printf (lines,"/TCP;unicast");
1842     else if(lowertrans == WFD_RTSP_LOWER_TRANS_HTTP) g_string_append_printf (lines,"/HTTP");
1843
1844     msg->client_rtp_ports->profile = g_string_free (lines, FALSE);
1845     msg->client_rtp_ports->rtp_port0 = rtp_port0;
1846     msg->client_rtp_ports->rtp_port1 = rtp_port1;
1847     msg->client_rtp_ports->mode = g_strdup("mode=play");
1848   }
1849   return WFD_OK;
1850 }
1851
1852 WFDResult wfdconfig_get_prefered_RTP_ports(WFDMessage *msg, WFDRTSPTransMode *trans, WFDRTSPProfile *profile,
1853                 WFDRTSPLowerTrans *lowertrans, guint32 *rtp_port0, guint32 *rtp_port1)
1854 {
1855   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1856   g_return_val_if_fail (msg->client_rtp_ports != NULL, WFD_EINVAL);
1857
1858   if(g_strrstr(msg->client_rtp_ports->profile, "RTP")) *trans = WFD_RTSP_TRANS_RTP;
1859   if(g_strrstr(msg->client_rtp_ports->profile, "RDT")) *trans = WFD_RTSP_TRANS_RDT;
1860   if(g_strrstr(msg->client_rtp_ports->profile, "AVP")) *profile = WFD_RTSP_PROFILE_AVP;
1861   if(g_strrstr(msg->client_rtp_ports->profile, "SAVP")) *profile = WFD_RTSP_PROFILE_SAVP;
1862   if(g_strrstr(msg->client_rtp_ports->profile, "UDP;unicast")) *lowertrans = WFD_RTSP_LOWER_TRANS_UDP;
1863   if(g_strrstr(msg->client_rtp_ports->profile, "UDP;multicast")) *lowertrans = WFD_RTSP_LOWER_TRANS_UDP_MCAST;
1864   if(g_strrstr(msg->client_rtp_ports->profile, "TCP;unicast")) *lowertrans = WFD_RTSP_LOWER_TRANS_TCP;
1865   if(g_strrstr(msg->client_rtp_ports->profile, "HTTP")) *lowertrans = WFD_RTSP_LOWER_TRANS_HTTP;
1866
1867   *rtp_port0 = msg->client_rtp_ports->rtp_port0;
1868   *rtp_port1 = msg->client_rtp_ports->rtp_port1;
1869
1870   return WFD_OK;
1871 }
1872
1873 WFDResult wfdconfig_set_audio_sink_type(WFDMessage *msg, WFDSinkType sinktype)
1874 {
1875   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1876   if(!msg->route) msg->route = g_new0 (WFDRoute, 1);
1877   if(sinktype == WFD_PRIMARY_SINK) msg->route->destination = g_strdup("primary");
1878   else if(sinktype == WFD_SECONDARY_SINK) msg->route->destination = g_strdup("secondary");
1879   return WFD_OK;
1880 }
1881
1882 WFDResult wfdconfig_get_audio_sink_type(WFDMessage *msg, WFDSinkType *sinktype)
1883 {
1884   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1885   if(msg->route) {
1886     if(!g_strcmp0(msg->route->destination,"primary")) *sinktype = WFD_PRIMARY_SINK;
1887     else if(!g_strcmp0(msg->route->destination,"secondary")) *sinktype = WFD_SECONDARY_SINK;
1888   }
1889   return WFD_OK;
1890 }
1891
1892 WFDResult wfdconfig_set_I2C_port(WFDMessage *msg, gboolean i2csupport, guint32 i2cport)
1893 {
1894   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1895   if(!msg->I2C) msg->I2C = g_new0 (WFDI2C, 1);
1896   msg->I2C->I2CPresent = i2csupport;
1897   msg->I2C->I2C_port = i2cport;
1898   return WFD_OK;
1899 }
1900
1901 WFDResult wfdconfig_get_I2C_port(WFDMessage *msg, gboolean *i2csupport, guint32 *i2cport)
1902 {
1903   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1904   if(msg->I2C && msg->I2C->I2CPresent) {
1905     *i2csupport = msg->I2C->I2CPresent;
1906     *i2cport = msg->I2C->I2C_port;
1907   } else *i2csupport = FALSE;
1908   return WFD_OK;
1909 }
1910
1911 WFDResult wfdconfig_set_av_format_change_timing(WFDMessage *msg, guint64 PTS, guint64 DTS)
1912 {
1913   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1914   if(!msg->av_format_change_timing) msg->av_format_change_timing = g_new0 (WFDAVFormatChangeTiming, 1);
1915   msg->av_format_change_timing->PTS = PTS;
1916   msg->av_format_change_timing->DTS = DTS;
1917   return WFD_OK;
1918 }
1919
1920 WFDResult wfdconfig_get_av_format_change_timing(WFDMessage *msg, guint64 *PTS, guint64 *DTS)
1921 {
1922   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1923   if(msg->av_format_change_timing) {
1924     *PTS = msg->av_format_change_timing->PTS;
1925     *DTS = msg->av_format_change_timing->DTS;
1926   }
1927   return WFD_OK;
1928 }
1929
1930 WFDResult wfdconfig_set_uibc_capability(WFDMessage *msg, guint32 input_category, guint32 inp_type, WFDHIDCTypePathPair *inp_pair,
1931                                                                                                 guint32 inp_type_path_count, guint32 tcp_port)
1932 {
1933   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1934   if(!msg->uibc_capability) msg->uibc_capability = g_new0 (WFDUibcCapability, 1);
1935   msg->uibc_capability->uibcsupported = TRUE;
1936   msg->uibc_capability->input_category_list.input_cat = input_category;
1937   msg->uibc_capability->generic_cap_list.inp_type = inp_type;
1938   msg->uibc_capability->hidc_cap_list.cap_count = inp_type_path_count;
1939   if(msg->uibc_capability->hidc_cap_list.cap_count) {
1940     detailed_cap *temp_cap;
1941     guint i=0;
1942     msg->uibc_capability->hidc_cap_list.next = g_new0 (detailed_cap, 1);
1943     temp_cap = msg->uibc_capability->hidc_cap_list.next;
1944     for(;i<inp_type_path_count;) {
1945       temp_cap->p.inp_type = inp_pair[i].inp_type;
1946       temp_cap->p.inp_path = inp_pair[i].inp_path;
1947       i++;
1948       if(i<inp_type_path_count) {
1949         temp_cap->next = g_new0 (detailed_cap, 1);
1950         temp_cap = temp_cap->next;
1951       }
1952     }
1953   }
1954   msg->uibc_capability->tcp_port = tcp_port;
1955   return WFD_OK;
1956 }
1957
1958 WFDResult wfdconfig_get_uibc_capability(WFDMessage *msg, guint32 *input_category, guint32 *inp_type, WFDHIDCTypePathPair *inp_pair,
1959                                                                                                 guint32 *inp_type_path_count, guint32 *tcp_port)
1960 {
1961   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1962   if(msg->uibc_capability && msg->uibc_capability->uibcsupported) {
1963     *input_category = msg->uibc_capability->input_category_list.input_cat;
1964     *inp_type = msg->uibc_capability->generic_cap_list.inp_type;
1965     if(msg->uibc_capability->hidc_cap_list.cap_count) {
1966       detailed_cap *temp_cap;
1967       guint i = 0;
1968       inp_pair = g_new0 (WFDHIDCTypePathPair, msg->uibc_capability->hidc_cap_list.cap_count);
1969       temp_cap = msg->uibc_capability->hidc_cap_list.next;
1970       while(temp_cap) {
1971         inp_pair[i].inp_type = temp_cap->p.inp_type;
1972         inp_pair[i].inp_path = temp_cap->p.inp_path;
1973         temp_cap = temp_cap->next;
1974         i++;
1975       }
1976     }
1977     *tcp_port = msg->uibc_capability->tcp_port;
1978   }
1979   return WFD_OK;
1980 }
1981
1982 WFDResult wfdconfig_set_uibc_status(WFDMessage *msg, gboolean uibc_enable)
1983 {
1984   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1985   if(!msg->uibc_setting) msg->uibc_setting = g_new0 (WFDUibcSetting, 1);
1986   msg->uibc_setting->uibc_setting = uibc_enable;
1987   return WFD_OK;
1988 }
1989
1990 WFDResult wfdconfig_get_uibc_status(WFDMessage *msg, gboolean *uibc_enable)
1991 {
1992   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1993   if(msg->uibc_setting) *uibc_enable = msg->uibc_setting->uibc_setting;
1994   return WFD_OK;
1995 }
1996 #ifdef STANDBY_RESUME_CAPABILITY
1997 WFDResult wfdconfig_set_standby_resume_capability(WFDMessage *msg, gboolean supported)
1998 {
1999   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
2000   if(!msg->standby_resume_capability) msg->standby_resume_capability = g_new0 (WFDStandbyResumeCapability, 1);
2001   msg->standby_resume_capability->standby_resume_cap = supported;
2002   return WFD_OK;
2003 }
2004
2005 WFDResult wfdconfig_get_standby_resume_capability(WFDMessage *msg, gboolean *supported)
2006 {
2007   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
2008   if(msg->standby_resume_capability) *supported = msg->standby_resume_capability->standby_resume_cap;
2009   return WFD_OK;
2010 }
2011 #endif
2012 WFDResult wfdconfig_set_standby(WFDMessage *msg, gboolean standby_enable)
2013 {
2014   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
2015   if(!msg->standby) msg->standby = g_new0 (WFDStandby, 1);
2016   msg->standby->wfd_standby = standby_enable;
2017   return WFD_OK;
2018 }
2019
2020 WFDResult wfdconfig_get_standby(WFDMessage *msg, gboolean *standby_enable)
2021 {
2022   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
2023   if(msg->standby) *standby_enable = msg->standby->wfd_standby;
2024   return WFD_OK;
2025 }
2026
2027 WFDResult wfdconfig_set_connector_type(WFDMessage *msg, WFDConnector connector)
2028 {
2029   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
2030   if(!msg->connector_type) msg->connector_type = g_new0 (WFDConnectorType, 1);
2031   msg->connector_type->connector_type = connector;
2032   return WFD_OK;
2033 }
2034
2035 WFDResult wfdconfig_get_connector_type(WFDMessage *msg, WFDConnector *connector)
2036 {
2037   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
2038   if(msg->connector_type) *connector = msg->connector_type->connector_type;
2039   return WFD_OK;
2040 }
2041
2042 WFDResult wfdconfig_set_idr_request(WFDMessage *msg)
2043 {
2044   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
2045   if(!msg->idr_request) msg->idr_request = g_new0 (WFDIdrRequest, 1);
2046   msg->idr_request->idr_request = TRUE;
2047   return WFD_OK;
2048 }