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