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