a01cd5ca9099f145e92d54bf299e42bd2e2fa682
[archive/platform/core/multimedia/libmm-scmirroring-common.git] / wfdconfig / wfdconfigmessage.c
1 /*
2  * wfdconfig messages
3  *
4  * Copyright (c) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, ByungWook Jang <bw.jang@samsung.com>,
7  * Manoj Kumar K <manojkumar.k@samsung.com>, Abhishek Bajaj <abhi.bajaj@samsung.com>, Nikhilesh Mittal <nikhilesh.m@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <stdlib.h>
28 #include <string.h>
29 #include <stdio.h>
30 #ifdef HAVE_SYS_TYPES_H
31 #include <sys/types.h>
32 #endif
33
34 #include <glib.h>               /* for G_OS_WIN32 */
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 enum
45 {
46   WFD_SESSION,
47   WFD_MEDIA,
48 };
49
50 typedef struct
51 {
52   guint state;
53   WFDMessage *msg;
54 } WFDContext;
55
56 /**
57 * wfdconfig_message_new:
58 * @msg: pointer to new #WFDMessage
59 *
60 * Allocate a new WFDMessage and store the result in @msg.
61 *
62 * Returns: a #WFDResult.
63 */
64 WFDResult
65 wfdconfig_message_new (WFDMessage ** msg)
66 {
67   WFDMessage *newmsg;
68
69   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
70
71   newmsg = g_new0 (WFDMessage, 1);
72
73   *msg = newmsg;
74
75   return wfdconfig_message_init (newmsg);
76 }
77
78 /**
79 * wfdconfig_message_init:
80 * @msg: a #WFDMessage
81 *
82 * Initialize @msg so that its contents are as if it was freshly allocated
83 * with wfdconfig_message_new(). This function is mostly used to initialize a message
84 * allocated on the stack. wfdconfig_message_uninit() undoes this operation.
85 *
86 * When this function is invoked on newly allocated data (with malloc or on the
87 * stack), its contents should be set to 0 before calling this function.
88 *
89 * Returns: a #WFDResult.
90 */
91 WFDResult
92 wfdconfig_message_init (WFDMessage * msg)
93 {
94   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
95
96   return WFD_OK;
97 }
98
99 /**
100 * wfdconfig_message_uninit:
101 * @msg: a #WFDMessage
102 *
103 * Free all resources allocated in @msg. @msg should not be used anymore after
104 * this function. This function should be used when @msg was allocated on the
105 * stack and initialized with wfdconfig_message_init().
106 *
107 * Returns: a #WFDResult.
108 */
109 WFDResult
110 wfdconfig_message_uninit (WFDMessage * msg)
111 {
112   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
113
114   if(msg->audio_codecs) {
115     guint i=0;
116     if(msg->audio_codecs->list) {
117       for(; i<msg->audio_codecs->count; i++) {
118         FREE_STRING(msg->audio_codecs->list[i].audio_format);
119         msg->audio_codecs->list[i].modes=0;
120         msg->audio_codecs->list[i].latency=0;
121       }
122       FREE_STRING(msg->audio_codecs->list);
123     }
124     FREE_STRING(msg->audio_codecs);
125   }
126
127   if(msg->video_formats) {
128     FREE_STRING(msg->video_formats->list);
129     FREE_STRING(msg->video_formats);
130   }
131
132   if(msg->video_3d_formats) {
133     FREE_STRING(msg->video_3d_formats);
134   }
135
136   if(msg->content_protection) {
137     FREE_STRING(msg->content_protection);
138   }
139
140   if(msg->display_edid) {
141     if(msg->display_edid->edid_payload)
142       FREE_STRING(msg->display_edid->edid_payload);
143     FREE_STRING(msg->display_edid);
144   }
145
146   if(msg->coupled_sink) {
147     FREE_STRING(msg->coupled_sink);
148   }
149
150   if(msg->trigger_method) {
151     FREE_STRING(msg->trigger_method->wfd_trigger_method);
152     FREE_STRING(msg->trigger_method);
153   }
154
155   if(msg->presentation_url) {
156     FREE_STRING(msg->trigger_method);
157   }
158
159   if(msg->client_rtp_ports) {
160     FREE_STRING(msg->client_rtp_ports->profile);
161     FREE_STRING(msg->client_rtp_ports->mode);
162     FREE_STRING(msg->client_rtp_ports);
163   }
164
165   if(msg->route) {
166     FREE_STRING(msg->route);
167   }
168
169   if(msg->I2C) {
170     FREE_STRING(msg->I2C);
171   }
172
173   if(msg->av_format_change_timing) {
174     FREE_STRING(msg->av_format_change_timing);
175   }
176
177   if(msg->preferred_display_mode) {
178     FREE_STRING(msg->preferred_display_mode);
179   }
180
181   if(msg->uibc_capability) {
182     FREE_STRING(msg->uibc_capability);
183   }
184
185   if(msg->uibc_setting) {
186     FREE_STRING(msg->uibc_setting);
187   }
188
189   if(msg->standby_resume_capability) {
190     FREE_STRING(msg->standby_resume_capability);
191   }
192
193   if(msg->standby) {
194     FREE_STRING(msg->standby);
195   }
196
197   if(msg->connector_type) {
198     FREE_STRING(msg->connector_type);
199   }
200
201   if(msg->idr_request) {
202     FREE_STRING(msg->idr_request);
203   }
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     g_string_append_printf (lines,":");
324     if(msg->content_protection->hdcp2_spec) {
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," %10"G_GUINT64_FORMAT, msg->av_format_change_timing->PTS);
421     g_string_append_printf (lines," %10"G_GUINT64_FORMAT, 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," %06"G_GUINT64_FORMAT, 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=%u", 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     g_string_append_printf (lines,"\r\n");
571   }
572
573   if(msg->idr_request) {
574     g_string_append_printf (lines,"wfd_idr_request");
575     g_string_append_printf (lines,"\r\n");
576   }
577
578   //g_string_append_printf (lines,"\0");
579   /*if(g_str_has_suffix (lines,"\r\n\0"))
580   {
581   guint32 length = g_strlen(lines);
582   lines[length-2] = '\0';
583   }*/
584   return g_string_free (lines, FALSE);
585 }
586
587 gchar* wfdconfig_parameter_names_as_text (const WFDMessage *msg)
588 {
589   /* change all vars so they match rfc? */
590   GString *lines;
591   g_return_val_if_fail (msg != NULL, NULL);
592
593   lines = g_string_new ("");
594
595   /* list of audio codecs */
596   if(msg->audio_codecs) {
597     g_string_append_printf (lines,"wfd_audio_codecs");
598     g_string_append_printf (lines,"\r\n");
599   }
600   /* list of video codecs */
601   if(msg->video_formats) {
602     g_string_append_printf (lines,"wfd_video_formats");
603     g_string_append_printf (lines,"\r\n");
604   }
605   /* list of video 3D codecs */
606   if(msg->video_3d_formats) {
607     g_string_append_printf (lines,"wfd_3d_video_formats");
608     g_string_append_printf (lines,"\r\n");
609   }
610   if(msg->content_protection) {
611     g_string_append_printf (lines,"wfd_content_protection");
612     g_string_append_printf (lines,"\r\n");
613   }
614   if(msg->display_edid) {
615     g_string_append_printf (lines,"wfd_display_edid");
616     g_string_append_printf (lines,"\r\n");
617   }
618   if(msg->coupled_sink) {
619     g_string_append_printf (lines,"wfd_coupled_sink");
620     g_string_append_printf (lines,"\r\n");
621   }
622   if(msg->trigger_method) {
623     g_string_append_printf (lines,"wfd_trigger_method");
624     g_string_append_printf (lines,"\r\n");
625   }
626   if(msg->presentation_url) {
627     g_string_append_printf (lines,"wfd_presentation_URL");
628     g_string_append_printf (lines,"\r\n");
629   }
630   if(msg->client_rtp_ports) {
631     g_string_append_printf (lines,"wfd_client_rtp_ports");
632     g_string_append_printf (lines,"\r\n");
633   }
634   if(msg->route) {
635     g_string_append_printf (lines,"wfd_route");
636     g_string_append_printf (lines,"\r\n");
637   }
638   if(msg->I2C) {
639     g_string_append_printf (lines,"wfd_I2C");
640     g_string_append_printf (lines,"\r\n");
641   }
642   if(msg->av_format_change_timing) {
643     g_string_append_printf (lines,"wfd_av_format_change_timing");
644     g_string_append_printf (lines,"\r\n");
645   }
646   if(msg->preferred_display_mode) {
647     g_string_append_printf (lines,"wfd_preferred_display_mode");
648     g_string_append_printf (lines,"\r\n");
649   }
650   if(msg->uibc_capability) {
651     g_string_append_printf (lines,"wfd_uibc_capability");
652     g_string_append_printf (lines,"\r\n");
653   }
654   if(msg->uibc_setting) {
655     g_string_append_printf (lines,"wfd_uibc_setting");
656     g_string_append_printf (lines,"\r\n");
657   }
658   if(msg->standby_resume_capability) {
659     g_string_append_printf (lines,"wfd_standby_resume_capability");
660     g_string_append_printf (lines,"\r\n");
661   }
662   if(msg->standby) {
663     g_string_append_printf (lines,"wfd_standby");
664     g_string_append_printf (lines,"\r\n");
665   }
666   if(msg->connector_type) {
667     g_string_append_printf (lines,"wfd_connector_type");
668     g_string_append_printf (lines,"\r\n");
669   }
670   if(msg->idr_request) {
671     g_string_append_printf (lines,"wfd_idr_request");
672     g_string_append_printf (lines,"\r\n");
673   }
674   return g_string_free (lines, FALSE);
675 }
676
677 static void
678 read_string_space_ended (gchar * dest, guint size, gchar * src)
679 {
680   guint idx = 0;
681
682   while (!g_ascii_isspace (*src) && *src != '\0') {
683     if (idx < size - 1)
684       dest[idx++] = *src;
685     src++;
686   }
687
688   if (size > 0)
689     dest[idx] = '\0';
690 }
691
692 static void
693 read_string_char_ended (gchar * dest, guint size, gchar del, gchar * src)
694 {
695   guint idx = 0;
696
697   while (*src != del && *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_type_and_value (gchar * type, gchar * value, guint tsize, guint vsize, gchar del, gchar * src)
709 {
710   guint idx;
711
712   idx = 0;
713   while (*src != del && *src != '\0') {
714     if (idx < tsize - 1)
715       type[idx++] = *src;
716     src++;
717   }
718
719   if (tsize > 0)
720     type[idx] = '\0';
721
722   src++;
723   idx = 0;
724   while (*src != '\0') {
725     if (idx < vsize - 1)
726       value[idx++] = *src;
727     src++;
728   }
729   if (vsize > 0)
730     value[idx] = '\0';
731 }
732
733 static gboolean
734 wfdconfig_parse_line (WFDMessage * msg, gchar * buffer)
735 {
736   gchar type[8192] = {0};
737   gchar value[8192] = {0};
738   gchar temp[8192] = {0};
739   gchar *p = buffer;
740   gchar *v = value;
741   gchar *result = NULL;
742
743   #define WFD_SKIP_SPACE(q) if (*q && g_ascii_isspace (*q)) q++
744   #define WFD_SKIP_EQUAL(q) if (*q && *q == '=') q++
745   #define WFD_SKIP_COMMA(q) if (*q && g_ascii_ispunct (*q)) q++
746   #define WFD_READ_STRING(field) read_string_space_ended (temp, sizeof (temp), v); v+=strlen(temp); REPLACE_STRING (field, temp)
747   #define WFD_READ_CHAR_END_STRING(field, del) read_string_char_ended (temp, sizeof (temp), del, v); v+=strlen(temp); REPLACE_STRING (field, temp)
748   #define WFD_READ_UINT32(field) read_string_space_ended (temp, sizeof (temp), v); v+=strlen(temp); field = strtoul (temp, NULL, 16)
749   #define WFD_READ_UINT32_DIGIT(field) read_string_space_ended (temp, sizeof (temp), v); v+=strlen(temp); field = strtoul (temp, NULL, 10)
750
751   //g_print("wfdconfig_parse_line input: %s\n", buffer);
752   read_string_type_and_value (type, value, sizeof(type), sizeof(value), ':', p);
753   //g_print("wfdconfig_parse_line type:%s value:%s\n", type, value);
754   if(!g_strcmp0(type,"wfd_audio_codecs")) {
755     msg->audio_codecs = g_new0 (WFDAudioCodeclist, 1);
756     if(strlen(v)) {
757       guint i=0;
758       msg->audio_codecs->count= strlen(v)/16;
759       msg->audio_codecs->list = g_new0 (WFDAudioCodec, msg->audio_codecs->count);
760       for(;i<msg->audio_codecs->count;i++) {
761         WFD_SKIP_SPACE(v);
762         WFD_READ_STRING(msg->audio_codecs->list[i].audio_format);
763         WFD_SKIP_SPACE(v);
764         WFD_READ_UINT32(msg->audio_codecs->list[i].modes);
765         WFD_SKIP_SPACE(v);
766         WFD_READ_UINT32(msg->audio_codecs->list[i].latency);
767         WFD_SKIP_COMMA(v);
768       }
769     }
770   } else if(!g_strcmp0(type,"wfd_video_formats")) {
771     msg->video_formats = g_new0 (WFDVideoCodeclist, 1);
772     if(strlen(v)) {
773       msg->video_formats->count = 1;
774       msg->video_formats->list = g_new0 (WFDVideoCodec, 1);
775       WFD_SKIP_SPACE(v);
776       WFD_READ_UINT32(msg->video_formats->list->native);
777       WFD_SKIP_SPACE(v);
778       WFD_READ_UINT32(msg->video_formats->list->preferred_display_mode_supported);
779       WFD_SKIP_SPACE(v);
780       WFD_READ_UINT32(msg->video_formats->list->H264_codec.profile);
781       WFD_SKIP_SPACE(v);
782       WFD_READ_UINT32(msg->video_formats->list->H264_codec.level);
783       WFD_SKIP_SPACE(v);
784       WFD_READ_UINT32(msg->video_formats->list->H264_codec.misc_params.CEA_Support);
785       WFD_SKIP_SPACE(v);
786       WFD_READ_UINT32(msg->video_formats->list->H264_codec.misc_params.VESA_Support);
787       WFD_SKIP_SPACE(v);
788       WFD_READ_UINT32(msg->video_formats->list->H264_codec.misc_params.HH_Support);
789       WFD_SKIP_SPACE(v);
790       WFD_READ_UINT32(msg->video_formats->list->H264_codec.misc_params.latency);
791       WFD_SKIP_SPACE(v);
792       WFD_READ_UINT32(msg->video_formats->list->H264_codec.misc_params.min_slice_size);
793       WFD_SKIP_SPACE(v);
794       WFD_READ_UINT32(msg->video_formats->list->H264_codec.misc_params.slice_enc_params);
795       WFD_SKIP_SPACE(v);
796       WFD_READ_UINT32(msg->video_formats->list->H264_codec.misc_params.frame_rate_control_support);
797       WFD_SKIP_SPACE(v);
798       if(msg->video_formats->list->preferred_display_mode_supported == 1) {
799         WFD_READ_UINT32(msg->video_formats->list->H264_codec.max_hres);
800         WFD_SKIP_SPACE(v);
801         WFD_READ_UINT32(msg->video_formats->list->H264_codec.max_vres);
802         WFD_SKIP_SPACE(v);
803       }
804     }
805   }else if(!g_strcmp0(type,"wfd_3d_video_formats")) {
806     msg->video_3d_formats = g_new0 (WFD3DFormats, 1);
807     if(strlen(v)) {
808       msg->video_3d_formats->count = 1;
809       msg->video_3d_formats->list = g_new0 (WFD3dCapList, 1);
810       WFD_SKIP_SPACE(v);
811       WFD_READ_UINT32(msg->video_3d_formats->list->native);
812       WFD_SKIP_SPACE(v);
813       WFD_READ_UINT32(msg->video_3d_formats->list->preferred_display_mode_supported);
814       WFD_SKIP_SPACE(v);
815       WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.profile);
816       WFD_SKIP_SPACE(v);
817       WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.level);
818       WFD_SKIP_SPACE(v);
819       WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.misc_params.video_3d_capability);
820       WFD_SKIP_SPACE(v);
821       WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.misc_params.latency);
822       WFD_SKIP_SPACE(v);
823       WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.misc_params.min_slice_size);
824       WFD_SKIP_SPACE(v);
825       WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.misc_params.slice_enc_params);
826       WFD_SKIP_SPACE(v);
827       WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.misc_params.frame_rate_control_support);
828       WFD_SKIP_SPACE(v);
829       if(msg->video_3d_formats->list->preferred_display_mode_supported == 1) {
830         WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.max_hres);
831         WFD_SKIP_SPACE(v);
832         WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.max_vres);
833         WFD_SKIP_SPACE(v);
834       }
835     }
836   } else if(!g_strcmp0(type,"wfd_content_protection")) {
837     msg->content_protection = g_new0 (WFDContentProtection, 1);
838     if(strlen(v)) {
839       WFD_SKIP_SPACE(v);
840       msg->content_protection->hdcp2_spec = g_new0 (WFDHdcp2Spec, 1);
841       if(strstr(v,"none")) {
842          msg->content_protection->hdcp2_spec->hdcpversion=g_strdup("none");
843       } else {
844         WFD_READ_STRING(msg->content_protection->hdcp2_spec->hdcpversion);
845         WFD_SKIP_SPACE(v);
846         WFD_READ_STRING(msg->content_protection->hdcp2_spec->TCPPort);
847       }
848     }
849   } else if(!g_strcmp0(type,"wfd_display_edid")) {
850     msg->display_edid = g_new0 (WFDDisplayEdid, 1);
851     if(strlen(v)) {
852       WFD_SKIP_SPACE(v);
853       if(strstr(v,"none")) {
854         msg->display_edid->edid_supported = 0;
855       } else {
856         msg->display_edid->edid_supported = 1;
857         WFD_READ_UINT32(msg->display_edid->edid_block_count);
858         WFD_SKIP_SPACE(v);
859         if(msg->display_edid->edid_block_count) {
860           gchar *edid_string = v;
861           int i=0, j=0, size =0;
862           guint32 payload_size = EDID_BLOCK_SIZE * msg->display_edid->edid_block_count;
863           msg->display_edid->edid_payload = g_malloc(payload_size);
864           size = EDID_BLOCK_SIZE*msg->display_edid->edid_block_count*2;
865           for (;i<size; j++) {
866             int k=0,kk=0;
867             if(edid_string[i]>0x29 && edid_string[i]<0x40) k=edid_string[i]-48;
868             else if(edid_string[i]>0x60 && edid_string[i]<0x67) k=edid_string[i]-87;
869             else if(edid_string[i]>0x40 && edid_string[i]<0x47) k=edid_string[i]-55;
870
871             if(edid_string[i+1]>0x29 && edid_string[i+1]<0x40) kk=edid_string[i+1]-48;
872             else if(edid_string[i+1]>0x60 && edid_string[i+1]<0x67) kk=edid_string[i+1]-87;
873             else if(edid_string[i+1]>0x40 && edid_string[i+1]<0x47) kk=edid_string[i+1]-55;
874
875             msg->display_edid->edid_payload[j] = (k<<4)|kk;
876             i+=2;
877           }
878           //memcpy(msg->display_edid->edid_payload, v, payload_size);
879                 v += (payload_size*2);
880         } else v += strlen(v);
881       }
882     }
883   } else if(!g_strcmp0(type,"wfd_coupled_sink")) {
884     msg->coupled_sink = g_new0 (WFDCoupledSink, 1);
885     if(strlen(v)) {
886     msg->coupled_sink->coupled_sink_cap = g_new0 (WFDCoupled_sink_cap, 1);
887     WFD_SKIP_SPACE(v);
888     WFD_READ_UINT32(msg->coupled_sink->coupled_sink_cap->status);
889     WFD_SKIP_SPACE(v);
890     WFD_READ_STRING(msg->coupled_sink->coupled_sink_cap->sink_address);
891     }
892   } else if(!g_strcmp0(type,"wfd_trigger_method")) {
893     msg->trigger_method = g_new0 (WFDTriggerMethod, 1);
894     if(strlen(v)) {
895       WFD_SKIP_SPACE(v);
896       WFD_READ_STRING(msg->trigger_method->wfd_trigger_method);
897     }
898   } else if(!g_strcmp0(type,"wfd_presentation_URL")) {
899     msg->presentation_url = g_new0 (WFDPresentationUrl, 1);
900     if(strlen(v)) {
901       WFD_SKIP_SPACE(v);
902       WFD_READ_STRING(msg->presentation_url->wfd_url0);
903       WFD_SKIP_SPACE(v);
904       WFD_READ_STRING(msg->presentation_url->wfd_url1);
905     }
906   } else if(!g_strcmp0(type,"wfd_client_rtp_ports")) {
907     msg->client_rtp_ports = g_new0 (WFDClientRtpPorts, 1);
908     if(strlen(v)) {
909       WFD_SKIP_SPACE(v);
910       WFD_READ_STRING(msg->client_rtp_ports->profile);
911       WFD_SKIP_SPACE(v);
912       WFD_READ_UINT32_DIGIT(msg->client_rtp_ports->rtp_port0);
913       WFD_SKIP_SPACE(v);
914       WFD_READ_UINT32_DIGIT(msg->client_rtp_ports->rtp_port1);
915       WFD_SKIP_SPACE(v);
916       WFD_READ_STRING(msg->client_rtp_ports->mode);
917     }
918   } else if(!g_strcmp0(type,"wfd_route")) {
919     msg->route = g_new0 (WFDRoute, 1);
920     if(strlen(v)) {
921       WFD_SKIP_SPACE(v);
922       WFD_READ_STRING(msg->route->destination);
923     }
924   } else if(!g_strcmp0(type,"wfd_I2C")) {
925     msg->I2C = g_new0 (WFDI2C, 1);
926     if(strlen(v)) {
927       msg->I2C->I2CPresent = TRUE;
928       WFD_SKIP_SPACE(v);
929       WFD_READ_UINT32_DIGIT(msg->I2C->I2C_port);
930       if(msg->I2C->I2C_port) msg->I2C->I2CPresent = TRUE;
931     }
932   } else if(!g_strcmp0(type,"wfd_av_format_change_timing")) {
933     msg->av_format_change_timing = g_new0 (WFDAVFormatChangeTiming, 1);
934     if(strlen(v)) {
935     WFD_SKIP_SPACE(v);
936     WFD_READ_UINT32(msg->av_format_change_timing->PTS);
937     WFD_SKIP_SPACE(v);
938     WFD_READ_UINT32(msg->av_format_change_timing->DTS);
939     }
940   } else if(!g_strcmp0(type,"wfd_preferred_display_mode")) {
941     msg->preferred_display_mode = g_new0 (WFDPreferredDisplayMode, 1);
942     if(strlen(v)) {
943       WFD_SKIP_SPACE(v);
944       if(!strstr(v,"none")) {
945         msg->preferred_display_mode->displaymodesupported = FALSE;
946       } else {
947         WFD_READ_UINT32(msg->preferred_display_mode->p_clock);
948         WFD_SKIP_SPACE(v);
949         WFD_READ_UINT32(msg->preferred_display_mode->H);
950         WFD_SKIP_SPACE(v);
951         WFD_READ_UINT32(msg->preferred_display_mode->HB);
952         WFD_SKIP_SPACE(v);
953         WFD_READ_UINT32(msg->preferred_display_mode->HSPOL_HSOFF);
954         WFD_SKIP_SPACE(v);
955         WFD_READ_UINT32(msg->preferred_display_mode->HSW);
956         WFD_SKIP_SPACE(v);
957         WFD_READ_UINT32(msg->preferred_display_mode->V);
958         WFD_SKIP_SPACE(v);
959         WFD_READ_UINT32(msg->preferred_display_mode->VB);
960         WFD_SKIP_SPACE(v);
961         WFD_READ_UINT32(msg->preferred_display_mode->VSPOL_VSOFF);
962         WFD_SKIP_SPACE(v);
963         WFD_READ_UINT32(msg->preferred_display_mode->VSW);
964         WFD_SKIP_SPACE(v);
965         WFD_READ_UINT32(msg->preferred_display_mode->VBS3D);
966         WFD_SKIP_SPACE(v);
967         WFD_READ_UINT32(msg->preferred_display_mode->V2d_s3d_modes);
968         WFD_SKIP_SPACE(v);
969         WFD_READ_UINT32(msg->preferred_display_mode->P_depth);
970         WFD_SKIP_SPACE(v);
971         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.profile);
972         WFD_SKIP_SPACE(v);
973         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.level);
974         WFD_SKIP_SPACE(v);
975         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.misc_params.CEA_Support);
976         WFD_SKIP_SPACE(v);
977         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.misc_params.VESA_Support);
978         WFD_SKIP_SPACE(v);
979         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.misc_params.HH_Support);
980         WFD_SKIP_SPACE(v);
981         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.misc_params.latency);
982         WFD_SKIP_SPACE(v);
983         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.misc_params.min_slice_size);
984         WFD_SKIP_SPACE(v);
985         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.misc_params.slice_enc_params);
986         WFD_SKIP_SPACE(v);
987         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.misc_params.frame_rate_control_support);
988         WFD_SKIP_SPACE(v);
989         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.max_hres);
990         WFD_SKIP_SPACE(v);
991         WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.max_vres);
992         WFD_SKIP_SPACE(v);
993       }
994     }
995   } else if(!g_strcmp0(type,"wfd_uibc_capability")) {
996     msg->uibc_capability = g_new0 (WFDUibcCapability, 1);
997     if(strstr(v,"input_category_list")) {
998       gchar *tstring = NULL;
999       msg->uibc_capability->uibcsupported = TRUE;
1000       WFD_SKIP_SPACE(v);
1001       WFD_READ_CHAR_END_STRING(tstring, '=');
1002       if(!g_strcmp0(tstring,"input_category_list")) {
1003         gchar temp2[8192]={0};
1004         guint rem_len=0, read_len=0;
1005         WFD_READ_CHAR_END_STRING(tstring, ';');
1006         rem_len = strlen(tstring);
1007         do {
1008           WFD_SKIP_SPACE(v);
1009           read_string_char_ended (temp2, 8192, ',', tstring+read_len);
1010           read_len += (strlen(temp2)+1);
1011           if(strstr(temp2,"GENERIC")) msg->uibc_capability->input_category_list.input_cat |= WFD_UIBC_INPUT_CAT_GENERIC;
1012           else if(strstr(temp2,"HIDC")) msg->uibc_capability->input_category_list.input_cat |= WFD_UIBC_INPUT_CAT_HIDC;
1013           else msg->uibc_capability->input_category_list.input_cat |= WFD_UIBC_INPUT_CAT_UNKNOWN;
1014         } while(read_len < rem_len);
1015
1016         result = strstr(v,"generic_cap_list");
1017         if(result != NULL){
1018           memset(temp2, 0, 8192);
1019           rem_len=0;
1020           read_len=0;
1021           v = result;
1022           WFD_READ_CHAR_END_STRING(tstring, '=');
1023           if(!g_strcmp0(tstring,"generic_cap_list")) {
1024             WFD_SKIP_SPACE(v);
1025             WFD_READ_CHAR_END_STRING(tstring, ';');
1026             rem_len = strlen(tstring);
1027             do {
1028               read_string_char_ended (temp2, 8192, ',', tstring+read_len);
1029               read_len += (strlen(temp2)+1);
1030               if(strstr(temp2,"Keyboard")) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_KEYBOARD;
1031               else if(strstr(temp2,"Mouse")) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_MOUSE;
1032               else if(strstr(temp2,"SingleTouch")) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_SINGLETOUCH;
1033               else if(strstr(temp2,"MultiTouch")) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_MULTITOUCH;
1034               else if(strstr(temp2,"Joystick")) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_JOYSTICK;
1035               else if(strstr(temp2,"Camera")) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_CAMERA;
1036               else if(strstr(temp2,"Gesture")) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_GESTURE;
1037               else if(strstr(temp2,"RemoteControl")) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_REMOTECONTROL;
1038               else msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_UNKNOWN;
1039             } while(read_len < rem_len);
1040           }
1041         }
1042         result = strstr (v, "hidc_cap_list");
1043         if(result != NULL){
1044           v = result;
1045           WFD_SKIP_SPACE(v);
1046           WFD_READ_CHAR_END_STRING(tstring, '=');
1047           if(!g_strcmp0(tstring,"hidc_cap_list")) {
1048             gchar inp_type[8192];
1049             gchar inp_path[8192];
1050             memset(temp2, 0, 8192);
1051             rem_len=0;
1052             read_len=0;
1053             detailed_cap *temp_cap;
1054             WFD_READ_CHAR_END_STRING(tstring, ';');
1055             rem_len = strlen(tstring);
1056             msg->uibc_capability->hidc_cap_list.next = g_new0 (detailed_cap, 1);
1057             temp_cap = msg->uibc_capability->hidc_cap_list.next;
1058             do {
1059               msg->uibc_capability->hidc_cap_list.cap_count++;
1060               read_string_char_ended (temp2, 8192, ',', tstring+read_len);
1061               read_len += (strlen(temp2)+1);
1062               read_string_type_and_value (inp_type, inp_path, sizeof(inp_type), sizeof(inp_path), '/',temp2);
1063               if(strstr(inp_type,"Keyboard")) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_KEYBOARD;
1064               else if(strstr(inp_type,"Mouse")) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_MOUSE;
1065               else if(strstr(inp_type,"SingleTouch")) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_SINGLETOUCH;
1066               else if(strstr(inp_type,"MultiTouch")) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_MULTITOUCH;
1067               else if(strstr(inp_type,"Joystick")) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_JOYSTICK;
1068               else if(strstr(inp_type,"Camera")) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_CAMERA;
1069               else if(strstr(inp_type,"Gesture")) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_GESTURE;
1070               else if(strstr(inp_type,"RemoteControl")) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_REMOTECONTROL;
1071               else temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_UNKNOWN;
1072
1073               if(strstr(inp_path,"Infrared")) temp_cap->p.inp_path = WFD_UIBC_INPUT_PATH_INFRARED;
1074               else if(strstr(inp_path,"USB")) temp_cap->p.inp_path = WFD_UIBC_INPUT_PATH_USB;
1075               else if(strstr(inp_path,"BT")) temp_cap->p.inp_path = WFD_UIBC_INPUT_PATH_BT;
1076               else if(strstr(inp_path,"Zigbee")) temp_cap->p.inp_path = WFD_UIBC_INPUT_PATH_ZIGBEE;
1077               else if(strstr(inp_path,"Wi-Fi")) temp_cap->p.inp_path = WFD_UIBC_INPUT_PATH_WIFI;
1078               else if(strstr(inp_path,"No-SP")) temp_cap->p.inp_path = WFD_UIBC_INPUT_PATH_NOSP;
1079               else temp_cap->p.inp_path = WFD_UIBC_INPUT_PATH_UNKNOWN;
1080               if(read_len < rem_len) {
1081                 temp_cap->next = g_new0 (detailed_cap, 1);
1082                 temp_cap = temp_cap->next;
1083               }
1084             } while(read_len < rem_len);
1085           }
1086         }
1087         result = strstr(v,"port");
1088         if(result != NULL) {
1089           v = result;
1090           WFD_READ_CHAR_END_STRING(tstring, '=');
1091           if(!g_strcmp0(tstring,"port")) {
1092             WFD_SKIP_EQUAL(v);
1093             WFD_READ_CHAR_END_STRING(tstring, ';');
1094             if(!strstr(tstring,"none")) {
1095               msg->uibc_capability->tcp_port = strtoul (tstring, NULL, 10);
1096             }
1097           }
1098         }
1099       }
1100     } else if (strstr(v,"none")) {
1101       msg->uibc_capability->uibcsupported = FALSE;
1102     }
1103   } else if(!g_strcmp0(type,"wfd_uibc_setting")) {
1104     msg->uibc_setting = g_new0 (WFDUibcSetting, 1);
1105     if(strlen(v)) {
1106       WFD_SKIP_SPACE(v);
1107       if(!g_strcmp0(v, "enable"))
1108         msg->uibc_setting->uibc_setting = TRUE;
1109       else
1110         msg->uibc_setting->uibc_setting = FALSE;
1111     }
1112   } else if(!g_strcmp0(type,"wfd_standby_resume_capability")) {
1113     msg->standby_resume_capability = g_new0 (WFDStandbyResumeCapability, 1);
1114     if(strlen(v)) {
1115       WFD_SKIP_SPACE(v);
1116       if(!g_strcmp0(v, "supported"))
1117         msg->standby_resume_capability->standby_resume_cap = TRUE;
1118       else
1119         msg->standby_resume_capability->standby_resume_cap = FALSE;
1120     }
1121   } else if(!g_strcmp0(type,"wfd_standby")) {
1122     msg->standby = g_new0 (WFDStandby, 1);
1123     msg->standby->wfd_standby = TRUE;
1124   } else if(!g_strcmp0(type,"wfd_connector_type")) {
1125     msg->connector_type = g_new0 (WFDConnectorType, 1);
1126     if(strlen(v)) {
1127     msg->connector_type->supported = TRUE;
1128     WFD_SKIP_SPACE(v);
1129     WFD_READ_UINT32(msg->connector_type->connector_type);
1130     }
1131   } else if(!g_strcmp0(type,"wfd_idr_request")) {
1132     msg->idr_request = g_new0 (WFDIdrRequest, 1);
1133     msg->idr_request->idr_request = TRUE;
1134   }
1135
1136   return TRUE;
1137 }
1138
1139 /**
1140 * wfdconfig_message_parse_buffer:
1141 * @data: the start of the buffer
1142 * @size: the size of the buffer
1143 * @msg: the result #WFDMessage
1144 *
1145 * Parse the contents of @size bytes pointed to by @data and store the result in
1146 * @msg.
1147 *
1148 * Returns: #WFD_OK on success.
1149 */
1150 WFDResult
1151 wfdconfig_message_parse_buffer (const guint8 * data, guint size, WFDMessage * msg)
1152 {
1153   const gchar *p;
1154   gchar buffer[MAX_LINE_LEN] = {0};
1155   guint idx = 0;
1156
1157   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1158   g_return_val_if_fail (data != NULL, WFD_EINVAL);
1159   g_return_val_if_fail (size != 0, WFD_EINVAL);
1160
1161   p = (const gchar *) data;
1162   while (TRUE) {
1163
1164     if (*p == '\0')
1165     break;
1166
1167     idx = 0;
1168     while (*p != '\n' && *p != '\r' && *p != '\0') {
1169       if (idx < sizeof (buffer) - 1)
1170         buffer[idx++] = *p;
1171       p++;
1172     }
1173     buffer[idx] = '\0';
1174     wfdconfig_parse_line (msg, buffer);
1175
1176     if (*p == '\0')
1177       break;
1178     p+=2;
1179   }
1180
1181   return WFD_OK;
1182 }
1183
1184 /**
1185 * wfdconfig_message_dump:
1186 * @msg: a #WFDMessage
1187 *
1188 * Dump the parsed contents of @msg to stdout.
1189 *
1190 * Returns: a #WFDResult.
1191 */
1192 WFDResult
1193 wfdconfig_message_dump (const WFDMessage * msg)
1194 {
1195   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1196   debug_log("===========WFD Message dump=========");
1197
1198   if(msg->audio_codecs) {
1199     guint i=0;
1200     debug_log("Audio supported formats : \n");
1201     for(;i<msg->audio_codecs->count;i++) {
1202       debug_log("Codec: %s\n",msg->audio_codecs->list[i].audio_format);
1203       if(!strcmp(msg->audio_codecs->list[i].audio_format,"LPCM")) {
1204         if(msg->audio_codecs->list[i].modes & WFD_FREQ_44100)
1205           debug_log("   Freq: %d\n", 44100);
1206         if(msg->audio_codecs->list[i].modes & WFD_FREQ_48000)
1207           debug_log("   Freq: %d\n", 48000);
1208         debug_log("     Channels: %d\n", 2);
1209       }
1210       if(!strcmp(msg->audio_codecs->list[i].audio_format,"AAC")) {
1211         debug_log("     Freq: %d\n", 48000);
1212         if(msg->audio_codecs->list[i].modes & WFD_CHANNEL_2)
1213           debug_log("   Channels: %d\n", 2);
1214         if(msg->audio_codecs->list[i].modes & WFD_CHANNEL_4)
1215           debug_log("   Channels: %d\n", 4);
1216         if(msg->audio_codecs->list[i].modes & WFD_CHANNEL_6)
1217           debug_log("   Channels: %d\n", 6);
1218         if(msg->audio_codecs->list[i].modes & WFD_CHANNEL_8)
1219           debug_log("   Channels: %d\n", 8);
1220       }
1221       if(!strcmp(msg->audio_codecs->list[i].audio_format,"AC3")) {
1222         debug_log("     Freq: %d\n", 48000);
1223         if(msg->audio_codecs->list[i].modes & WFD_CHANNEL_2)
1224           debug_log("   Channels: %d\n", 2);
1225         if(msg->audio_codecs->list[i].modes & WFD_CHANNEL_4)
1226           debug_log("   Channels: %d\n", 4);
1227         if(msg->audio_codecs->list[i].modes & WFD_CHANNEL_6)
1228           debug_log("   Channels: %d\n", 6);
1229       }
1230       debug_log("       Bitwidth: %d\n", 16);
1231       debug_log("       Latency: %d\n", msg->audio_codecs->list[i].latency);
1232     }
1233   }
1234
1235
1236   if(msg->video_formats) {
1237     debug_log("Video supported formats : \n");
1238     if(msg->video_formats->list) {
1239       debug_log("Codec: H264\n");
1240       guint nativeindex = 0;
1241       if((msg->video_formats->list->native & 0x7) == WFD_VIDEO_CEA_RESOLUTION) {
1242         debug_log ("    Native type: CEA\n");
1243       } else if((msg->video_formats->list->native & 0x7) == WFD_VIDEO_VESA_RESOLUTION) {
1244         debug_log ("    Native type: VESA\n");
1245       } else if((msg->video_formats->list->native & 0x7) == WFD_VIDEO_HH_RESOLUTION) {
1246         debug_log ("    Native type: HH\n");
1247       }
1248       nativeindex = msg->video_formats->list->native >> 3;
1249       debug_log ("      Resolution: %d\n", (1 << nativeindex));
1250
1251       if(msg->video_formats->list->H264_codec.profile & WFD_H264_BASE_PROFILE) {
1252         debug_log ("    Profile: BASE\n");
1253       } else if(msg->video_formats->list->H264_codec.profile & WFD_H264_HIGH_PROFILE) {
1254         debug_log ("    Profile: HIGH\n");
1255       } if(msg->video_formats->list->H264_codec.level & WFD_H264_LEVEL_3_1) {
1256         debug_log ("    Level: 3.1\n");
1257       } else if(msg->video_formats->list->H264_codec.level & WFD_H264_LEVEL_3_2) {
1258         debug_log ("    Level: 3.2\n");
1259       } else if(msg->video_formats->list->H264_codec.level & WFD_H264_LEVEL_4) {
1260         debug_log ("    Level: 4\n");
1261       } else if(msg->video_formats->list->H264_codec.level & WFD_H264_LEVEL_4_1) {
1262         debug_log ("    Level: 4.1\n");
1263       } else if(msg->video_formats->list->H264_codec.level & WFD_H264_LEVEL_4_2) {
1264         debug_log ("    Level: 4.2\n");
1265       }
1266       debug_log ("      Latency: %d\n", msg->video_formats->list->H264_codec.misc_params.latency);
1267       debug_log ("      min_slice_size: %x\n", msg->video_formats->list->H264_codec.misc_params.min_slice_size);
1268       debug_log ("      slice_enc_params: %x\n", msg->video_formats->list->H264_codec.misc_params.slice_enc_params);
1269       debug_log ("      frame_rate_control_support: %x\n", msg->video_formats->list->H264_codec.misc_params.frame_rate_control_support);
1270       if(msg->video_formats->list->H264_codec.max_hres) {
1271         debug_log ("    Max Height: %04d\n", msg->video_formats->list->H264_codec.max_hres);
1272       }
1273       if(msg->video_formats->list->H264_codec.max_vres) {
1274         debug_log ("    Max Width: %04d\n", msg->video_formats->list->H264_codec.max_vres);
1275       }
1276     }
1277   }
1278
1279   if(msg->video_3d_formats) {
1280     debug_log ("wfd_3d_formats");
1281     debug_log ("\r\n");
1282   }
1283
1284   if(msg->content_protection) {
1285     debug_log ("wfd_content_protection");
1286     debug_log ("\r\n");
1287   }
1288
1289   if(msg->display_edid) {
1290     debug_log ("wfd_display_edid");
1291     debug_log ("\r\n");
1292   }
1293
1294   if(msg->coupled_sink) {
1295     debug_log ("wfd_coupled_sink");
1296     debug_log ("\r\n");
1297   }
1298
1299   if(msg->trigger_method) {
1300     debug_log ("        Trigger type: %s\n", msg->trigger_method->wfd_trigger_method);
1301   }
1302
1303   if(msg->presentation_url) {
1304     debug_log ("wfd_presentation_URL");
1305     debug_log ("\r\n");
1306   }
1307
1308   if(msg->client_rtp_ports) {
1309     debug_log(" Client RTP Ports : \n");
1310     if(msg->client_rtp_ports->profile) {
1311       debug_log ("%s\n", msg->client_rtp_ports->profile);
1312       debug_log ("      %d\n", msg->client_rtp_ports->rtp_port0);
1313       debug_log ("      %d\n", msg->client_rtp_ports->rtp_port1);
1314       debug_log ("      %s\n", msg->client_rtp_ports->mode);
1315     }
1316     debug_log("\r\n");
1317   }
1318
1319   if(msg->route) {
1320     debug_log ("wfd_route");
1321     debug_log ("\r\n");
1322   }
1323
1324   if(msg->I2C) {
1325     debug_log ("wfd_I2C");
1326     debug_log ("\r\n");
1327   }
1328
1329   if(msg->av_format_change_timing) {
1330     debug_log ("wfd_av_format_change_timing");
1331     debug_log ("\r\n");
1332   }
1333
1334   if(msg->preferred_display_mode) {
1335     debug_log ("wfd_preferred_display_mode");
1336     debug_log ("\r\n");
1337   }
1338
1339   if(msg->uibc_capability) {
1340     debug_log ("wfd_uibc_capability \r\n");
1341     debug_log ("input category list:");
1342     if(msg->uibc_capability->input_category_list.input_cat & WFD_UIBC_INPUT_CAT_GENERIC)
1343       debug_log ("GENERIC");
1344     if(msg->uibc_capability->input_category_list.input_cat & WFD_UIBC_INPUT_CAT_HIDC)
1345       debug_log ("HIDC");
1346     if(!msg->uibc_capability->input_category_list.input_cat)
1347       debug_log ("none");
1348     if(msg->uibc_capability->input_category_list.input_cat & WFD_UIBC_INPUT_CAT_GENERIC) {
1349       debug_log ("generic cap list: ");
1350       if(msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_KEYBOARD)
1351         debug_log("keyboard ");
1352       if(msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_MOUSE)
1353         debug_log("mouse ");
1354       if(msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_SINGLETOUCH)
1355         debug_log("single-touch ");
1356       if(msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_MULTITOUCH)
1357         debug_log("multi-touch ");
1358       if(msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_JOYSTICK)
1359         debug_log("joystick ");
1360       if(msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_CAMERA)
1361         debug_log("camera ");
1362       if(msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_GESTURE)
1363         debug_log("gesture ");
1364       if(msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_REMOTECONTROL)
1365         debug_log("remote control ");
1366       if(!msg->uibc_capability->generic_cap_list.inp_type)
1367         debug_log("none ");
1368     }
1369     if(msg->uibc_capability->input_category_list.input_cat & WFD_UIBC_INPUT_CAT_HIDC) {
1370       debug_log ("hidc cap list:");
1371       if(msg->uibc_capability->hidc_cap_list.cap_count) {
1372         detailed_cap *temp_cap = msg->uibc_capability->hidc_cap_list.next;
1373         while (temp_cap) {
1374           if(temp_cap->p.inp_type & WFD_UIBC_INPUT_TYPE_KEYBOARD) {
1375             debug_log("keyboard ");
1376           } else if(temp_cap->p.inp_type & WFD_UIBC_INPUT_TYPE_MOUSE) {
1377             debug_log("mouse ");
1378           } else if(temp_cap->p.inp_type & WFD_UIBC_INPUT_TYPE_SINGLETOUCH) {
1379             debug_log("single-touch ");
1380           } else if(temp_cap->p.inp_type & WFD_UIBC_INPUT_TYPE_MULTITOUCH) {
1381             debug_log("multi-touch ");
1382           } else if(temp_cap->p.inp_type & WFD_UIBC_INPUT_TYPE_JOYSTICK) {
1383             debug_log("joystick ");
1384           } else if(temp_cap->p.inp_type & WFD_UIBC_INPUT_TYPE_CAMERA) {
1385             debug_log("camera ");
1386           } else if(temp_cap->p.inp_type & WFD_UIBC_INPUT_TYPE_GESTURE) {
1387             debug_log("gesture ");
1388           } else if(temp_cap->p.inp_type & WFD_UIBC_INPUT_TYPE_REMOTECONTROL) {
1389             debug_log("remote control ");
1390           } else if(!temp_cap->p.inp_type) {
1391             debug_log("none ");
1392           }
1393           if(temp_cap->p.inp_path & WFD_UIBC_INPUT_PATH_INFRARED) {
1394             debug_log("infrared");
1395           } else if(temp_cap->p.inp_path & WFD_UIBC_INPUT_PATH_USB) {
1396             debug_log("usb");
1397           } else if(temp_cap->p.inp_path & WFD_UIBC_INPUT_PATH_BT) {
1398             debug_log("bluetooth");
1399           } else if(temp_cap->p.inp_path & WFD_UIBC_INPUT_PATH_WIFI) {
1400             debug_log("Wi-Fi");
1401           } else if(temp_cap->p.inp_path & WFD_UIBC_INPUT_PATH_ZIGBEE) {
1402             debug_log("Zigbee");
1403           } else if(temp_cap->p.inp_path & WFD_UIBC_INPUT_PATH_NOSP) {
1404             debug_log("No-SP");
1405           } else if(!temp_cap->p.inp_path) {
1406             debug_log("none");
1407           }
1408           temp_cap = temp_cap->next;
1409         }
1410       }
1411     }
1412     if(msg->uibc_capability->tcp_port)
1413       debug_log("tcp port:%u", msg->uibc_capability->tcp_port);
1414     if(!msg->uibc_capability->tcp_port)
1415       debug_log ("tcp port: none");
1416     debug_log ("\r\n");
1417   }
1418
1419   if(msg->uibc_setting) {
1420     debug_log ("wfd_uibc_setting: ");
1421     if(msg->uibc_setting->uibc_setting) {
1422       debug_log("true");
1423     } else debug_log("false");
1424     debug_log ("\r\n");
1425   }
1426
1427   if(msg->standby_resume_capability) {
1428     debug_log ("wfd_standby_resume_capability");
1429     debug_log ("\r\n");
1430   }
1431
1432   if(msg->standby) {
1433     debug_log ("wfd_standby");
1434     debug_log ("\r\n");
1435   }
1436
1437   if(msg->connector_type) {
1438     debug_log ("wfd_connector_type");
1439     debug_log ("\r\n");
1440   }
1441
1442   if(msg->idr_request) {
1443     debug_log ("wfd_idr_request");
1444     debug_log ("\r\n");
1445   }
1446
1447   debug_log("===============================================\n");
1448   return WFD_OK;
1449 }
1450
1451 WFDResult wfdconfig_set_supported_audio_format(WFDMessage *msg, WFDAudioFormats aCodec, guint aFreq, guint aChanels,
1452                                                                                               guint aBitwidth, guint32 aLatency)
1453 {
1454   guint temp = aCodec;
1455   guint i = 0;
1456   guint pcm = 0, aac = 0, ac3 = 0;
1457
1458   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1459
1460   if(!msg->audio_codecs)
1461     msg->audio_codecs = g_new0 (WFDAudioCodeclist, 1);
1462
1463   if(aCodec != WFD_AUDIO_UNKNOWN) {
1464     while(temp) {
1465       msg->audio_codecs->count++;
1466       temp >>= 1;
1467     }
1468     msg->audio_codecs->list = g_new0 (WFDAudioCodec, msg->audio_codecs->count);
1469     for(; i<msg->audio_codecs->count; i++) {
1470       if((aCodec & WFD_AUDIO_LPCM) && (!pcm)) {
1471         msg->audio_codecs->list[i].audio_format = g_strdup("LPCM");
1472         msg->audio_codecs->list[i].modes = aFreq;
1473         msg->audio_codecs->list[i].latency = aLatency;
1474         pcm = 1;
1475       } else if((aCodec & WFD_AUDIO_AAC) && (!aac)) {
1476         msg->audio_codecs->list[i].audio_format = g_strdup("AAC");
1477         msg->audio_codecs->list[i].modes = aChanels;
1478         msg->audio_codecs->list[i].latency = aLatency;
1479         aac = 1;
1480       } else if((aCodec & WFD_AUDIO_AC3) && (!ac3)) {
1481         msg->audio_codecs->list[i].audio_format = g_strdup("AC3");
1482         msg->audio_codecs->list[i].modes = aChanels;
1483         msg->audio_codecs->list[i].latency = aLatency;
1484         ac3 = 1;
1485       }
1486     }
1487   }
1488   return WFD_OK;
1489 }
1490
1491 WFDResult wfdconfig_set_prefered_audio_format(WFDMessage *msg, WFDAudioFormats aCodec, WFDAudioFreq aFreq, WFDAudioChannels aChanels,
1492                                                                                           guint aBitwidth, guint32 aLatency)
1493 {
1494
1495   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1496
1497   if(!msg->audio_codecs)
1498     msg->audio_codecs = g_new0 (WFDAudioCodeclist, 1);
1499
1500   msg->audio_codecs->list = g_new0 (WFDAudioCodec, 1);
1501   msg->audio_codecs->count = 1;
1502   if(aCodec == WFD_AUDIO_LPCM) {
1503     msg->audio_codecs->list->audio_format = g_strdup("LPCM");
1504     msg->audio_codecs->list->modes = aFreq;
1505     msg->audio_codecs->list->latency = aLatency;
1506   } else if(aCodec == WFD_AUDIO_AAC) {
1507     msg->audio_codecs->list->audio_format = g_strdup("AAC");
1508     msg->audio_codecs->list->modes = aChanels;
1509     msg->audio_codecs->list->latency = aLatency;
1510   } else if(aCodec == WFD_AUDIO_AC3) {
1511     msg->audio_codecs->list->audio_format = g_strdup("AC3");
1512     msg->audio_codecs->list->modes = aChanels;
1513     msg->audio_codecs->list->latency = aLatency;
1514   }
1515   return WFD_OK;
1516 }
1517
1518 WFDResult wfdconfig_get_supported_audio_format(WFDMessage *msg, guint *aCodec, guint *aFreq, guint *aChanels,
1519                                                                                              guint *aBitwidth, guint32 *aLatency)
1520 {
1521   guint i = 0;
1522   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1523   g_return_val_if_fail (msg->audio_codecs != NULL, WFD_EINVAL);
1524
1525   for(; i<msg->audio_codecs->count; i++) {
1526     if(!g_strcmp0(msg->audio_codecs->list[i].audio_format,"LPCM")) {
1527       *aCodec |= WFD_AUDIO_LPCM;
1528       *aFreq |= msg->audio_codecs->list[i].modes;
1529       *aChanels |= WFD_CHANNEL_2;
1530       *aBitwidth = 16;
1531       *aLatency = msg->audio_codecs->list[i].latency;
1532     } else if(!g_strcmp0(msg->audio_codecs->list[i].audio_format,"AAC")) {
1533       *aCodec |= WFD_AUDIO_AAC;
1534       *aFreq |= WFD_FREQ_48000;
1535       *aChanels |= msg->audio_codecs->list[i].modes;
1536       *aBitwidth = 16;
1537       *aLatency = msg->audio_codecs->list[i].latency;
1538     } else if(!g_strcmp0(msg->audio_codecs->list[i].audio_format,"AC3")) {
1539       *aCodec |= WFD_AUDIO_AC3;
1540       *aFreq |= WFD_FREQ_48000;
1541       *aChanels |= msg->audio_codecs->list[i].modes;
1542       *aBitwidth = 16;
1543       *aLatency = msg->audio_codecs->list[i].latency;
1544     }
1545   }
1546   return WFD_OK;
1547 }
1548
1549 WFDResult wfdconfig_get_prefered_audio_format(WFDMessage *msg, WFDAudioFormats *aCodec, WFDAudioFreq *aFreq, WFDAudioChannels *aChanels,
1550                                                                                           guint *aBitwidth, guint32 *aLatency)
1551 {
1552   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1553
1554   if(!g_strcmp0(msg->audio_codecs->list->audio_format,"LPCM")) {
1555     *aCodec = WFD_AUDIO_LPCM;
1556     *aFreq = msg->audio_codecs->list->modes;
1557     *aChanels = WFD_CHANNEL_2;
1558     *aBitwidth = 16;
1559     *aLatency = msg->audio_codecs->list->latency;
1560   } else if(!g_strcmp0(msg->audio_codecs->list->audio_format,"AAC")) {
1561     *aCodec = WFD_AUDIO_AAC;
1562     *aFreq = WFD_FREQ_48000;
1563     *aChanels = msg->audio_codecs->list->modes;
1564     *aBitwidth = 16;
1565     *aLatency = msg->audio_codecs->list->latency;
1566   } else if(!g_strcmp0(msg->audio_codecs->list->audio_format,"AC3")) {
1567     *aCodec = WFD_AUDIO_AC3;
1568     *aFreq = WFD_FREQ_48000;
1569     *aChanels = msg->audio_codecs->list->modes;
1570     *aBitwidth = 16;
1571     *aLatency = msg->audio_codecs->list->latency;
1572   }
1573   return WFD_OK;
1574 }
1575
1576 WFDResult wfdconfig_set_supported_video_format(WFDMessage *msg, WFDVideoCodecs vCodec,
1577                       WFDVideoNativeResolution vNative, guint64 vNativeResolution,
1578                       guint64 vCEAResolution, guint64 vVESAResolution, guint64 vHHResolution,
1579                       guint vProfile, guint vLevel, guint32 vLatency, guint32 vMaxHeight,
1580                       guint32 vMaxWidth, guint32 min_slice_size, guint32 slice_enc_params, guint frame_rate_control)
1581 {
1582   guint nativeindex = 0;
1583   guint64 temp = vNativeResolution;
1584
1585   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1586
1587   if(!msg->video_formats)
1588   msg->video_formats = g_new0 (WFDVideoCodeclist, 1);
1589
1590   if(vCodec != WFD_VIDEO_UNKNOWN) {
1591     msg->video_formats->list = g_new0 (WFDVideoCodec, 1);
1592     while(temp) {
1593       nativeindex++;
1594       temp >>= 1;
1595     }
1596
1597     msg->video_formats->list->native = nativeindex-1;
1598     msg->video_formats->list->native <<= 3;
1599
1600     if(vNative == WFD_VIDEO_VESA_RESOLUTION)
1601       msg->video_formats->list->native |= 1;
1602     else if(vNative == WFD_VIDEO_HH_RESOLUTION)
1603       msg->video_formats->list->native |= 2;
1604
1605     msg->video_formats->list->preferred_display_mode_supported = 1;
1606     msg->video_formats->list->H264_codec.profile = vProfile;
1607     msg->video_formats->list->H264_codec.level = vLevel;
1608     msg->video_formats->list->H264_codec.max_hres = vMaxHeight;
1609     msg->video_formats->list->H264_codec.max_vres = vMaxWidth;
1610     msg->video_formats->list->H264_codec.misc_params.CEA_Support = vCEAResolution;
1611     msg->video_formats->list->H264_codec.misc_params.VESA_Support = vVESAResolution;
1612     msg->video_formats->list->H264_codec.misc_params.HH_Support = vHHResolution;
1613     msg->video_formats->list->H264_codec.misc_params.latency = vLatency;
1614     msg->video_formats->list->H264_codec.misc_params.min_slice_size = min_slice_size;
1615     msg->video_formats->list->H264_codec.misc_params.slice_enc_params = slice_enc_params;
1616     msg->video_formats->list->H264_codec.misc_params.frame_rate_control_support = frame_rate_control;
1617   }
1618   return WFD_OK;
1619 }
1620
1621 WFDResult wfdconfig_set_prefered_video_format(WFDMessage *msg, WFDVideoCodecs vCodec,
1622                   WFDVideoNativeResolution vNative, guint64 vNativeResolution,
1623                   WFDVideoCEAResolution vCEAResolution, WFDVideoVESAResolution vVESAResolution,
1624                   WFDVideoHHResolution vHHResolution,   WFDVideoH264Profile vProfile,
1625                   WFDVideoH264Level vLevel, guint32 vLatency, guint32 vMaxHeight,
1626                   guint32 vMaxWidth, guint32 min_slice_size, guint32 slice_enc_params, guint frame_rate_control)
1627 {
1628   guint nativeindex = 0;
1629   guint64 temp = vNativeResolution;
1630
1631   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1632
1633   if(!msg->video_formats)
1634     msg->video_formats = g_new0 (WFDVideoCodeclist, 1);
1635   msg->video_formats->list = g_new0 (WFDVideoCodec, 1);
1636
1637   while(temp) {
1638     nativeindex++;
1639     temp >>= 1;
1640   }
1641
1642   if(nativeindex) msg->video_formats->list->native = nativeindex-1;
1643   msg->video_formats->list->native <<= 3;
1644
1645   if(vNative == WFD_VIDEO_VESA_RESOLUTION)
1646     msg->video_formats->list->native |= 1;
1647   else if(vNative == WFD_VIDEO_HH_RESOLUTION)
1648     msg->video_formats->list->native |= 2;
1649
1650   msg->video_formats->list->preferred_display_mode_supported = 0;
1651   msg->video_formats->list->H264_codec.profile = vProfile;
1652   msg->video_formats->list->H264_codec.level = vLevel;
1653   msg->video_formats->list->H264_codec.max_hres = vMaxHeight;
1654   msg->video_formats->list->H264_codec.max_vres = vMaxWidth;
1655   msg->video_formats->list->H264_codec.misc_params.CEA_Support = vCEAResolution;
1656   msg->video_formats->list->H264_codec.misc_params.VESA_Support = vVESAResolution;
1657   msg->video_formats->list->H264_codec.misc_params.HH_Support = vHHResolution;
1658   msg->video_formats->list->H264_codec.misc_params.latency = vLatency;
1659   msg->video_formats->list->H264_codec.misc_params.min_slice_size = min_slice_size;
1660   msg->video_formats->list->H264_codec.misc_params.slice_enc_params = slice_enc_params;
1661   msg->video_formats->list->H264_codec.misc_params.frame_rate_control_support = frame_rate_control;
1662   return WFD_OK;
1663 }
1664
1665 WFDResult wfdconfig_get_supported_video_format(WFDMessage *msg, WFDVideoCodecs *vCodec,
1666                   WFDVideoNativeResolution *vNative, guint64 *vNativeResolution,
1667                   guint64 *vCEAResolution, guint64 *vVESAResolution, guint64 *vHHResolution,
1668                   guint *vProfile, guint *vLevel, guint32 *vLatency, guint32 *vMaxHeight,
1669                   guint32 *vMaxWidth, guint32 *min_slice_size, guint32 *slice_enc_params, guint *frame_rate_control)
1670 {
1671   guint nativeindex = 0;
1672
1673   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1674   g_return_val_if_fail (msg->video_formats != NULL, WFD_EINVAL);
1675   g_return_val_if_fail (msg->video_formats->list != NULL, WFD_EINVAL);
1676
1677   *vCodec = WFD_VIDEO_H264;
1678   *vNative = msg->video_formats->list->native & 0x7;
1679   nativeindex = msg->video_formats->list->native >> 3;
1680   *vNativeResolution = (guint64)1 << nativeindex;
1681   *vProfile = msg->video_formats->list->H264_codec.profile;
1682   *vLevel = msg->video_formats->list->H264_codec.level;
1683   *vMaxHeight = msg->video_formats->list->H264_codec.max_hres;
1684   *vMaxWidth = msg->video_formats->list->H264_codec.max_vres;
1685   *vCEAResolution = msg->video_formats->list->H264_codec.misc_params.CEA_Support;
1686   *vVESAResolution = msg->video_formats->list->H264_codec.misc_params.VESA_Support;
1687   *vHHResolution = msg->video_formats->list->H264_codec.misc_params.HH_Support;
1688   *vLatency = msg->video_formats->list->H264_codec.misc_params.latency;
1689   *min_slice_size = msg->video_formats->list->H264_codec.misc_params.min_slice_size;
1690   *slice_enc_params = msg->video_formats->list->H264_codec.misc_params.slice_enc_params;
1691   *frame_rate_control = msg->video_formats->list->H264_codec.misc_params.frame_rate_control_support;
1692   return WFD_OK;
1693 }
1694
1695 WFDResult wfdconfig_get_prefered_video_format(WFDMessage *msg, WFDVideoCodecs *vCodec,
1696                  WFDVideoNativeResolution *vNative, guint64 *vNativeResolution,
1697                  WFDVideoCEAResolution *vCEAResolution, WFDVideoVESAResolution *vVESAResolution,
1698                  WFDVideoHHResolution *vHHResolution,   WFDVideoH264Profile *vProfile,
1699                  WFDVideoH264Level *vLevel, guint32 *vLatency, guint32 *vMaxHeight,
1700                  guint32 *vMaxWidth, guint32 *min_slice_size, guint32 *slice_enc_params, guint *frame_rate_control)
1701 {
1702   guint nativeindex = 0;
1703   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1704   g_return_val_if_fail (msg->video_formats != NULL, WFD_EINVAL);
1705   g_return_val_if_fail (msg->video_formats->list != NULL, WFD_EINVAL);
1706
1707   *vCodec = WFD_VIDEO_H264;
1708   *vNative = msg->video_formats->list->native & 0x7;
1709   nativeindex = msg->video_formats->list->native >> 3;
1710   *vNativeResolution = (guint64)1 << nativeindex;
1711   *vProfile = msg->video_formats->list->H264_codec.profile;
1712   *vLevel = msg->video_formats->list->H264_codec.level;
1713   *vMaxHeight = msg->video_formats->list->H264_codec.max_hres;
1714   *vMaxWidth = msg->video_formats->list->H264_codec.max_vres;
1715   *vCEAResolution = msg->video_formats->list->H264_codec.misc_params.CEA_Support;
1716   *vVESAResolution = msg->video_formats->list->H264_codec.misc_params.VESA_Support;
1717   *vHHResolution = msg->video_formats->list->H264_codec.misc_params.HH_Support;
1718   *vLatency = msg->video_formats->list->H264_codec.misc_params.latency;
1719   *min_slice_size = msg->video_formats->list->H264_codec.misc_params.min_slice_size;
1720   *slice_enc_params = msg->video_formats->list->H264_codec.misc_params.slice_enc_params;
1721   *frame_rate_control = msg->video_formats->list->H264_codec.misc_params.frame_rate_control_support;
1722   return WFD_OK;
1723 }
1724
1725 WFDResult wfdconfig_set_contentprotection_type(WFDMessage *msg, WFDHDCPProtection hdcpversion, guint32 TCPPort)
1726 {
1727   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1728
1729   if(!msg->content_protection) msg->content_protection = g_new0 (WFDContentProtection, 1);
1730   if(hdcpversion == WFD_HDCP_NONE) return WFD_OK;
1731   msg->content_protection->hdcp2_spec = g_new0 (WFDHdcp2Spec, 1);
1732   if(hdcpversion == WFD_HDCP_2_0) msg->content_protection->hdcp2_spec->hdcpversion = g_strdup("HDCP2.0");
1733   else if(hdcpversion == WFD_HDCP_2_1) msg->content_protection->hdcp2_spec->hdcpversion = g_strdup("HDCP2.1");
1734   char str[11]={0,};
1735   snprintf(str, 11, "port=%d", TCPPort);
1736   msg->content_protection->hdcp2_spec->TCPPort = g_strdup(str);
1737   return WFD_OK;
1738 }
1739
1740 WFDResult wfdconfig_get_contentprotection_type(WFDMessage *msg, WFDHDCPProtection *hdcpversion, guint32 *TCPPort)
1741 {
1742   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1743   if(msg->content_protection && msg->content_protection->hdcp2_spec) {
1744     char *result = NULL;
1745     char *ptr = NULL;
1746     if(!g_strcmp0(msg->content_protection->hdcp2_spec->hdcpversion,"none")) {
1747           debug_warning("HDCP none");
1748           *hdcpversion = WFD_HDCP_NONE;
1749           *TCPPort = 0;
1750           return WFD_OK;
1751     }
1752     if(!g_strcmp0(msg->content_protection->hdcp2_spec->hdcpversion,"HDCP2.0")) *hdcpversion = WFD_HDCP_2_0;
1753     else if(!g_strcmp0(msg->content_protection->hdcp2_spec->hdcpversion,"HDCP2.1")) *hdcpversion = WFD_HDCP_2_1;
1754     else {
1755           debug_warning("Unknown protection type");
1756           *hdcpversion = WFD_HDCP_NONE;
1757           *TCPPort = 0;
1758           return WFD_OK;
1759     }
1760
1761     result = strtok_r(msg->content_protection->hdcp2_spec->TCPPort, "=", &ptr);
1762     while (result !=NULL) {
1763           result = strtok_r(NULL, "=", &ptr);
1764           *TCPPort = atoi (result);
1765           break;
1766     }
1767   } else *hdcpversion = WFD_HDCP_NONE;
1768   return WFD_OK;
1769 }
1770
1771 WFDResult wfdconfig_set_display_EDID(WFDMessage *msg, gboolean edid_supported, guint32 edid_blockcount, gchar *edid_playload)
1772 {
1773   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1774   if(!msg->display_edid) msg->display_edid = g_new0 (WFDDisplayEdid, 1);
1775   msg->display_edid->edid_supported = edid_supported;
1776   if(!edid_supported) return WFD_OK;
1777   msg->display_edid->edid_block_count = edid_blockcount;
1778   if(edid_blockcount) {
1779     msg->display_edid->edid_payload = g_malloc(128 * edid_blockcount);
1780     if(!msg->display_edid->edid_payload)
1781       memcpy(msg->display_edid->edid_payload, edid_playload, 128 * edid_blockcount);
1782   } else msg->display_edid->edid_payload = g_strdup("none");
1783   return WFD_OK;
1784 }
1785
1786 WFDResult wfdconfig_get_display_EDID(WFDMessage *msg, gboolean *edid_supported, guint32 *edid_blockcount, gchar **edid_playload)
1787 {
1788   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1789   if(msg->display_edid ) {
1790     if(msg->display_edid->edid_supported) {
1791       *edid_blockcount = msg->display_edid->edid_block_count;
1792       if(msg->display_edid->edid_block_count) {
1793         char * temp;
1794         temp = g_malloc(EDID_BLOCK_SIZE * msg->display_edid->edid_block_count);
1795         if(temp) {
1796            memset(temp, 0, EDID_BLOCK_SIZE * msg->display_edid->edid_block_count);
1797           memcpy(temp, msg->display_edid->edid_payload, EDID_BLOCK_SIZE * msg->display_edid->edid_block_count);
1798            *edid_playload = temp;
1799           *edid_supported = TRUE;
1800         }
1801       } else *edid_playload = g_strdup("none");
1802     }
1803   } else *edid_supported = FALSE;
1804   return WFD_OK;
1805 }
1806
1807 WFDResult wfdconfig_set_coupled_sink(WFDMessage *msg, WFDCoupledSinkStatus status, gchar *sink_address)
1808 {
1809   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1810   if(!msg->coupled_sink) msg->coupled_sink = g_new0 (WFDCoupledSink, 1);
1811   if(status == WFD_SINK_UNKNOWN) return WFD_OK;
1812   msg->coupled_sink->coupled_sink_cap = g_new0 (WFDCoupled_sink_cap, 1);
1813   msg->coupled_sink->coupled_sink_cap->status = status;
1814   msg->coupled_sink->coupled_sink_cap->sink_address = g_strdup(sink_address);
1815   return WFD_OK;
1816 }
1817
1818 WFDResult wfdconfig_get_coupled_sink(WFDMessage *msg, WFDCoupledSinkStatus *status, gchar **sink_address)
1819 {
1820   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1821   if(msg->coupled_sink && msg->coupled_sink->coupled_sink_cap) {
1822     *status = msg->coupled_sink->coupled_sink_cap->status;
1823     *sink_address = g_strdup(msg->coupled_sink->coupled_sink_cap->sink_address);
1824   } else *status = WFD_SINK_UNKNOWN;
1825   return WFD_OK;
1826 }
1827
1828 WFDResult wfdconfig_set_trigger_type(WFDMessage *msg, WFDTrigger trigger)
1829 {
1830   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1831
1832   if(!msg->trigger_method)
1833     msg->trigger_method = g_new0 (WFDTriggerMethod, 1);
1834   if(trigger == WFD_TRIGGER_SETUP)
1835     msg->trigger_method->wfd_trigger_method = g_strdup("SETUP");
1836   else if(trigger == WFD_TRIGGER_PAUSE)
1837     msg->trigger_method->wfd_trigger_method = g_strdup("PAUSE");
1838   else if(trigger == WFD_TRIGGER_TEARDOWN)
1839     msg->trigger_method->wfd_trigger_method = g_strdup("TEARDOWN");
1840   else if(trigger == WFD_TRIGGER_PLAY)
1841     msg->trigger_method->wfd_trigger_method = g_strdup("PLAY");
1842   else
1843     return WFD_EINVAL;
1844   return WFD_OK;
1845 }
1846
1847 WFDResult wfdconfig_get_trigger_type(WFDMessage *msg, WFDTrigger *trigger)
1848 {
1849   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1850   if(!g_strcmp0(msg->trigger_method->wfd_trigger_method, "SETUP"))
1851     *trigger = WFD_TRIGGER_SETUP;
1852   else if(!g_strcmp0(msg->trigger_method->wfd_trigger_method, "PAUSE"))
1853     *trigger = WFD_TRIGGER_PAUSE;
1854   else if(!g_strcmp0(msg->trigger_method->wfd_trigger_method, "TEARDOWN"))
1855     *trigger = WFD_TRIGGER_TEARDOWN;
1856   else if(!g_strcmp0(msg->trigger_method->wfd_trigger_method, "PLAY"))
1857     *trigger = WFD_TRIGGER_PLAY;
1858   else {
1859     *trigger = WFD_TRIGGER_UNKNOWN;
1860     return WFD_EINVAL;
1861   }
1862   return WFD_OK;
1863 }
1864
1865 WFDResult wfdconfig_set_presentation_url(WFDMessage *msg, gchar *wfd_url0, gchar *wfd_url1)
1866 {
1867   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1868   if(!msg->presentation_url) msg->presentation_url = g_new0 (WFDPresentationUrl, 1);
1869   if(wfd_url0) msg->presentation_url->wfd_url0 = g_strdup(wfd_url0);
1870   if(wfd_url1) msg->presentation_url->wfd_url1 = g_strdup(wfd_url1);
1871   return WFD_OK;
1872 }
1873
1874 WFDResult wfdconfig_get_presentation_url(WFDMessage *msg, gchar **wfd_url0, gchar **wfd_url1)
1875 {
1876   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1877   if(msg->presentation_url) {
1878     *wfd_url0 = g_strdup(msg->presentation_url->wfd_url0);
1879     *wfd_url1 = g_strdup(msg->presentation_url->wfd_url1);
1880   }
1881   return WFD_OK;
1882 }
1883
1884 WFDResult wfdconfig_set_prefered_RTP_ports(WFDMessage *msg, WFDRTSPTransMode trans, WFDRTSPProfile profile,
1885                  WFDRTSPLowerTrans lowertrans, guint32 rtp_port0, guint32 rtp_port1)
1886 {
1887   GString *lines;
1888   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1889
1890   if(!msg->client_rtp_ports)
1891     msg->client_rtp_ports = g_new0 (WFDClientRtpPorts, 1);
1892
1893   if(trans != WFD_RTSP_TRANS_UNKNOWN) {
1894     lines = g_string_new ("");
1895     if(trans == WFD_RTSP_TRANS_RTP)     g_string_append_printf (lines,"RTP");
1896     else if(trans == WFD_RTSP_TRANS_RDT) g_string_append_printf (lines,"RDT");
1897
1898     if(profile == WFD_RTSP_PROFILE_AVP) g_string_append_printf (lines,"/AVP");
1899     else if(profile == WFD_RTSP_PROFILE_SAVP) g_string_append_printf (lines,"/SAVP");
1900
1901     if(lowertrans == WFD_RTSP_LOWER_TRANS_UDP) g_string_append_printf (lines,"/UDP;unicast");
1902     else if(lowertrans == WFD_RTSP_LOWER_TRANS_UDP_MCAST) g_string_append_printf (lines,"/UDP;multicast");
1903     else if(lowertrans == WFD_RTSP_LOWER_TRANS_TCP) g_string_append_printf (lines,"/TCP;unicast");
1904     else if(lowertrans == WFD_RTSP_LOWER_TRANS_HTTP) g_string_append_printf (lines,"/HTTP");
1905
1906     msg->client_rtp_ports->profile = g_string_free (lines, FALSE);
1907     msg->client_rtp_ports->rtp_port0 = rtp_port0;
1908     msg->client_rtp_ports->rtp_port1 = rtp_port1;
1909     msg->client_rtp_ports->mode = g_strdup("mode=play");
1910   }
1911   return WFD_OK;
1912 }
1913
1914 WFDResult wfdconfig_get_prefered_RTP_ports(WFDMessage *msg, WFDRTSPTransMode *trans, WFDRTSPProfile *profile,
1915                 WFDRTSPLowerTrans *lowertrans, guint32 *rtp_port0, guint32 *rtp_port1)
1916 {
1917   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1918   g_return_val_if_fail (msg->client_rtp_ports != NULL, WFD_EINVAL);
1919
1920   if(g_strrstr(msg->client_rtp_ports->profile, "RTP")) *trans = WFD_RTSP_TRANS_RTP;
1921   if(g_strrstr(msg->client_rtp_ports->profile, "RDT")) *trans = WFD_RTSP_TRANS_RDT;
1922   if(g_strrstr(msg->client_rtp_ports->profile, "AVP")) *profile = WFD_RTSP_PROFILE_AVP;
1923   if(g_strrstr(msg->client_rtp_ports->profile, "SAVP")) *profile = WFD_RTSP_PROFILE_SAVP;
1924   if(g_strrstr(msg->client_rtp_ports->profile, "UDP;unicast")) *lowertrans = WFD_RTSP_LOWER_TRANS_UDP;
1925   if(g_strrstr(msg->client_rtp_ports->profile, "UDP;multicast")) *lowertrans = WFD_RTSP_LOWER_TRANS_UDP_MCAST;
1926   if(g_strrstr(msg->client_rtp_ports->profile, "TCP;unicast")) *lowertrans = WFD_RTSP_LOWER_TRANS_TCP;
1927   if(g_strrstr(msg->client_rtp_ports->profile, "HTTP")) *lowertrans = WFD_RTSP_LOWER_TRANS_HTTP;
1928
1929   *rtp_port0 = msg->client_rtp_ports->rtp_port0;
1930   *rtp_port1 = msg->client_rtp_ports->rtp_port1;
1931
1932   return WFD_OK;
1933 }
1934
1935 WFDResult wfdconfig_set_audio_sink_type(WFDMessage *msg, WFDSinkType sinktype)
1936 {
1937   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1938   if(!msg->route) msg->route = g_new0 (WFDRoute, 1);
1939   if(sinktype == WFD_PRIMARY_SINK) msg->route->destination = g_strdup("primary");
1940   else if(sinktype == WFD_SECONDARY_SINK) msg->route->destination = g_strdup("secondary");
1941   return WFD_OK;
1942 }
1943
1944 WFDResult wfdconfig_get_audio_sink_type(WFDMessage *msg, WFDSinkType *sinktype)
1945 {
1946   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1947   if(msg->route) {
1948     if(!g_strcmp0(msg->route->destination,"primary")) *sinktype = WFD_PRIMARY_SINK;
1949     else if(!g_strcmp0(msg->route->destination,"secondary")) *sinktype = WFD_SECONDARY_SINK;
1950   }
1951   return WFD_OK;
1952 }
1953
1954 WFDResult wfdconfig_set_I2C_port(WFDMessage *msg, gboolean i2csupport, guint32 i2cport)
1955 {
1956   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1957   if(!msg->I2C) msg->I2C = g_new0 (WFDI2C, 1);
1958   msg->I2C->I2CPresent = i2csupport;
1959   msg->I2C->I2C_port = i2cport;
1960   return WFD_OK;
1961 }
1962
1963 WFDResult wfdconfig_get_I2C_port(WFDMessage *msg, gboolean *i2csupport, guint32 *i2cport)
1964 {
1965   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1966   if(msg->I2C && msg->I2C->I2CPresent) {
1967     *i2csupport = msg->I2C->I2CPresent;
1968     *i2cport = msg->I2C->I2C_port;
1969   } else *i2csupport = FALSE;
1970   return WFD_OK;
1971 }
1972
1973 WFDResult wfdconfig_set_av_format_change_timing(WFDMessage *msg, guint64 PTS, guint64 DTS)
1974 {
1975   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1976   if(!msg->av_format_change_timing) msg->av_format_change_timing = g_new0 (WFDAVFormatChangeTiming, 1);
1977   msg->av_format_change_timing->PTS = PTS;
1978   msg->av_format_change_timing->DTS = DTS;
1979   return WFD_OK;
1980 }
1981
1982 WFDResult wfdconfig_get_av_format_change_timing(WFDMessage *msg, guint64 *PTS, guint64 *DTS)
1983 {
1984   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1985   if(msg->av_format_change_timing) {
1986     *PTS = msg->av_format_change_timing->PTS;
1987     *DTS = msg->av_format_change_timing->DTS;
1988   }
1989   return WFD_OK;
1990 }
1991
1992 WFDResult wfdconfig_set_uibc_capability(WFDMessage *msg, guint32 input_category, guint32 inp_type, WFDHIDCTypePathPair *inp_pair,
1993                                                                                                 guint32 inp_type_path_count, guint32 tcp_port)
1994 {
1995   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
1996   if(!msg->uibc_capability) msg->uibc_capability = g_new0 (WFDUibcCapability, 1);
1997   msg->uibc_capability->uibcsupported = TRUE;
1998   msg->uibc_capability->input_category_list.input_cat = input_category;
1999   msg->uibc_capability->generic_cap_list.inp_type = inp_type;
2000   msg->uibc_capability->hidc_cap_list.cap_count = inp_type_path_count;
2001   if(msg->uibc_capability->hidc_cap_list.cap_count) {
2002     detailed_cap *temp_cap;
2003     guint i=0;
2004     msg->uibc_capability->hidc_cap_list.next = g_new0 (detailed_cap, 1);
2005     temp_cap = msg->uibc_capability->hidc_cap_list.next;
2006     for(;i<inp_type_path_count;) {
2007       temp_cap->p.inp_type = inp_pair[i].inp_type;
2008       temp_cap->p.inp_path = inp_pair[i].inp_path;
2009       i++;
2010       if(i<inp_type_path_count) {
2011         temp_cap->next = g_new0 (detailed_cap, 1);
2012         temp_cap = temp_cap->next;
2013       }
2014     }
2015   }
2016   msg->uibc_capability->tcp_port = tcp_port;
2017   return WFD_OK;
2018 }
2019
2020 WFDResult wfdconfig_get_uibc_capability(WFDMessage *msg, guint32 *input_category, guint32 *inp_type, WFDHIDCTypePathPair **inp_pair,
2021                                                                                                 guint32 *inp_type_path_count, guint32 *tcp_port)
2022 {
2023   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
2024   if(msg->uibc_capability && msg->uibc_capability->uibcsupported) {
2025     *input_category = msg->uibc_capability->input_category_list.input_cat;
2026     *inp_type = msg->uibc_capability->generic_cap_list.inp_type;
2027     *inp_type_path_count = msg->uibc_capability->hidc_cap_list.cap_count;
2028     if(msg->uibc_capability->hidc_cap_list.cap_count) {
2029       detailed_cap *temp_cap;
2030       guint i = 0;
2031       *inp_pair = g_new0 (WFDHIDCTypePathPair, msg->uibc_capability->hidc_cap_list.cap_count);
2032       temp_cap = msg->uibc_capability->hidc_cap_list.next;
2033       while(temp_cap) {
2034         (*(inp_pair))[i].inp_type = temp_cap->p.inp_type;
2035         (*(inp_pair))[i].inp_path = temp_cap->p.inp_path;
2036         temp_cap = temp_cap->next;
2037         i++;
2038       }
2039     }
2040     *tcp_port = msg->uibc_capability->tcp_port;
2041   }
2042   return WFD_OK;
2043 }
2044
2045 WFDResult wfdconfig_set_uibc_status(WFDMessage *msg, gboolean uibc_enable)
2046 {
2047   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
2048   if(!msg->uibc_setting) msg->uibc_setting = g_new0 (WFDUibcSetting, 1);
2049   msg->uibc_setting->uibc_setting = uibc_enable;
2050   return WFD_OK;
2051 }
2052
2053 WFDResult wfdconfig_get_uibc_status(WFDMessage *msg, gboolean *uibc_enable)
2054 {
2055   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
2056   if(msg->uibc_setting) *uibc_enable = msg->uibc_setting->uibc_setting;
2057   return WFD_OK;
2058 }
2059 #ifdef STANDBY_RESUME_CAPABILITY
2060 WFDResult wfdconfig_set_standby_resume_capability(WFDMessage *msg, gboolean supported)
2061 {
2062   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
2063   if(!msg->standby_resume_capability) msg->standby_resume_capability = g_new0 (WFDStandbyResumeCapability, 1);
2064   msg->standby_resume_capability->standby_resume_cap = supported;
2065   return WFD_OK;
2066 }
2067
2068 WFDResult wfdconfig_get_standby_resume_capability(WFDMessage *msg, gboolean *supported)
2069 {
2070   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
2071   if(msg->standby_resume_capability) *supported = msg->standby_resume_capability->standby_resume_cap;
2072   return WFD_OK;
2073 }
2074 #endif
2075 WFDResult wfdconfig_set_standby(WFDMessage *msg, gboolean standby_enable)
2076 {
2077   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
2078   if(!msg->standby) msg->standby = g_new0 (WFDStandby, 1);
2079   msg->standby->wfd_standby = standby_enable;
2080   return WFD_OK;
2081 }
2082
2083 WFDResult wfdconfig_get_standby(WFDMessage *msg, gboolean *standby_enable)
2084 {
2085   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
2086   if(msg->standby) *standby_enable = msg->standby->wfd_standby;
2087   return WFD_OK;
2088 }
2089
2090 WFDResult wfdconfig_set_connector_type(WFDMessage *msg, WFDConnector connector)
2091 {
2092   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
2093   if(!msg->connector_type) msg->connector_type = g_new0 (WFDConnectorType, 1);
2094   msg->connector_type->connector_type = connector;
2095   return WFD_OK;
2096 }
2097
2098 WFDResult wfdconfig_get_connector_type(WFDMessage *msg, WFDConnector *connector)
2099 {
2100   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
2101   if(msg->connector_type) *connector = msg->connector_type->connector_type;
2102   return WFD_OK;
2103 }
2104
2105 WFDResult wfdconfig_set_idr_request(WFDMessage *msg)
2106 {
2107   g_return_val_if_fail (msg != NULL, WFD_EINVAL);
2108   if(!msg->idr_request) msg->idr_request = g_new0 (WFDIdrRequest, 1);
2109   msg->idr_request->idr_request = TRUE;
2110   return WFD_OK;
2111 }