Fix to use string for wfd rtsp message.
[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, ":");
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, ",");
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, ":");
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, ":");
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, ":");
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, ":");
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, ":");
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, ":");
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, ":");
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, ":");
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, ":");
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, ":");
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, ":");
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, ":");
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, ":");
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, "=");
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, ", ");
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, ", ");
512                                         }
513                                 }
514                         } else {
515                                 g_string_append_printf(lines, STRING_WFD_NONE);
516                         }
517                         g_string_append_printf(lines, ";");
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, "=");
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) g_string_append_printf(lines, ", ");
527                                 }
528                                 if (msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_MOUSE) {
529                                         tempcap |= WFD_UIBC_INPUT_TYPE_MOUSE;
530                                         g_string_append_printf(lines, STRING_WFD_MOUSE);
531                                         if (msg->uibc_capability->generic_cap_list.inp_type != tempcap) g_string_append_printf(lines, ", ");
532                                 }
533                                 if (msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_SINGLETOUCH) {
534                                         tempcap |= WFD_UIBC_INPUT_TYPE_SINGLETOUCH;
535                                         g_string_append_printf(lines, STRING_WFD_SINGLE_TOUCH);
536                                         if (msg->uibc_capability->generic_cap_list.inp_type != tempcap) g_string_append_printf(lines, ", ");
537                                 }
538                                 if (msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_MULTITOUCH) {
539                                         tempcap |= WFD_UIBC_INPUT_TYPE_MULTITOUCH;
540                                         g_string_append_printf(lines, STRING_WFD_MULTI_TOUCH);
541                                         if (msg->uibc_capability->generic_cap_list.inp_type != tempcap) g_string_append_printf(lines, ", ");
542                                 }
543                                 if (msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_JOYSTICK) {
544                                         tempcap |= WFD_UIBC_INPUT_TYPE_JOYSTICK;
545                                         g_string_append_printf(lines, STRING_WFD_JOYSTICK);
546                                         if (msg->uibc_capability->generic_cap_list.inp_type != tempcap) g_string_append_printf(lines, ", ");
547                                 }
548                                 if (msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_CAMERA) {
549                                         tempcap |= WFD_UIBC_INPUT_TYPE_CAMERA;
550                                         g_string_append_printf(lines, STRING_WFD_CAMERA);
551                                         if (msg->uibc_capability->generic_cap_list.inp_type != tempcap) g_string_append_printf(lines, ", ");
552                                 }
553                                 if (msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_GESTURE) {
554                                         tempcap |= WFD_UIBC_INPUT_TYPE_GESTURE;
555                                         g_string_append_printf(lines, STRING_WFD_GESTURE);
556                                         if (msg->uibc_capability->generic_cap_list.inp_type != tempcap) g_string_append_printf(lines, ", ");
557                                 }
558                                 if (msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_REMOTECONTROL) {
559                                         tempcap |= WFD_UIBC_INPUT_TYPE_REMOTECONTROL;
560                                         g_string_append_printf(lines, STRING_WFD_REMOTE_CONTROL);
561                                         if (msg->uibc_capability->generic_cap_list.inp_type != tempcap) g_string_append_printf(lines, ", ");
562                                 }
563                         } else {
564                                 g_string_append_printf(lines, STRING_WFD_NONE);
565                         }
566                         g_string_append_printf(lines, ";");
567                         g_string_append_printf(lines, STRING_WFD_SPACE);
568                         g_string_append_printf(lines, STRING_WFD_HIDC_CAP_LIST);
569                         g_string_append_printf(lines, "=");
570                         if (msg->uibc_capability->hidc_cap_list.cap_count) {
571                                 detailed_cap *temp_cap = msg->uibc_capability->hidc_cap_list.next;
572                                 while (temp_cap) {
573                                         if (temp_cap->p.inp_type == WFD_UIBC_INPUT_TYPE_KEYBOARD) g_string_append_printf(lines, STRING_WFD_KEYBOARD);
574                                         else if (temp_cap->p.inp_type == WFD_UIBC_INPUT_TYPE_MOUSE) g_string_append_printf(lines, STRING_WFD_MOUSE);
575                                         else if (temp_cap->p.inp_type == WFD_UIBC_INPUT_TYPE_SINGLETOUCH) g_string_append_printf(lines, STRING_WFD_SINGLE_TOUCH);
576                                         else if (temp_cap->p.inp_type == WFD_UIBC_INPUT_TYPE_MULTITOUCH) g_string_append_printf(lines, STRING_WFD_MULTI_TOUCH);
577                                         else if (temp_cap->p.inp_type == WFD_UIBC_INPUT_TYPE_JOYSTICK) g_string_append_printf(lines, STRING_WFD_JOYSTICK);
578                                         else if (temp_cap->p.inp_type == WFD_UIBC_INPUT_TYPE_CAMERA) g_string_append_printf(lines, STRING_WFD_CAMERA);
579                                         else if (temp_cap->p.inp_type == WFD_UIBC_INPUT_TYPE_GESTURE) g_string_append_printf(lines, STRING_WFD_GESTURE);
580                                         else if (temp_cap->p.inp_type == WFD_UIBC_INPUT_TYPE_REMOTECONTROL) g_string_append_printf(lines, STRING_WFD_REMOTE_CONTROL);
581                                         g_string_append_printf(lines, "/");
582                                         if (temp_cap->p.inp_path == WFD_UIBC_INPUT_PATH_INFRARED) g_string_append_printf(lines, STRING_WFD_INFRARED);
583                                         else if (temp_cap->p.inp_path == WFD_UIBC_INPUT_PATH_USB) g_string_append_printf(lines, STRING_WFD_USB);
584                                         else if (temp_cap->p.inp_path == WFD_UIBC_INPUT_PATH_BT) g_string_append_printf(lines, STRING_WFD_BT);
585                                         else if (temp_cap->p.inp_path == WFD_UIBC_INPUT_PATH_ZIGBEE) g_string_append_printf(lines, STRING_WFD_ZIGBEE);
586                                         else if (temp_cap->p.inp_path == WFD_UIBC_INPUT_PATH_WIFI) g_string_append_printf(lines, STRING_WFD_WIFI);
587                                         else if (temp_cap->p.inp_path == WFD_UIBC_INPUT_PATH_NOSP) g_string_append_printf(lines, STRING_WFD_NO_SP);
588                                         temp_cap = temp_cap->next;
589                                         if (temp_cap) g_string_append_printf(lines, ", ");
590                                 }
591                         } else {
592                                 g_string_append_printf(lines, STRING_WFD_NONE);
593                         }
594                         g_string_append_printf(lines, ";");
595                         if (msg->uibc_capability->tcp_port) {
596                                 g_string_append_printf(lines, STRING_WFD_PORT);
597                                 g_string_append_printf(lines, "=%u", msg->uibc_capability->tcp_port);
598                         } else {
599                                 g_string_append_printf(lines, STRING_WFD_PORT);
600                                 g_string_append_printf(lines, "=");
601                                 g_string_append_printf(lines, STRING_WFD_NONE);
602                         }
603                 } else {
604                         g_string_append_printf(lines, STRING_WFD_SPACE);
605                         g_string_append_printf(lines, STRING_WFD_NONE);
606                 }
607                 g_string_append_printf(lines, STRING_WFD_CRLF);
608         }
609
610         if (msg->uibc_setting) {
611                 g_string_append_printf(lines, STRING_WFD_UIBC_SETTING);
612                 g_string_append_printf(lines, ":");
613                 g_string_append_printf(lines, STRING_WFD_SPACE);
614                 if (msg->uibc_setting->uibc_setting)
615                         g_string_append_printf(lines, STRING_WFD_ENABLE);
616                 else
617                         g_string_append_printf(lines, STRING_WFD_DISABLE);
618                 g_string_append_printf(lines, STRING_WFD_CRLF);
619         }
620
621         if (msg->standby_resume_capability) {
622                 g_string_append_printf(lines, STRING_WFD_STANDBY_RESUME_CAPABILITY);
623                 g_string_append_printf(lines, ":");
624                 g_string_append_printf(lines, STRING_WFD_SPACE);
625                 if (msg->standby_resume_capability->standby_resume_cap)
626                         g_string_append_printf(lines, STRING_WFD_SUPPORTED);
627                 else
628                         g_string_append_printf(lines, STRING_WFD_NONE);
629                 g_string_append_printf(lines, STRING_WFD_CRLF);
630         }
631
632         if (msg->standby) {
633                 g_string_append_printf(lines, STRING_WFD_STANDBY);
634                 g_string_append_printf(lines, STRING_WFD_CRLF);
635         }
636
637         if (msg->connector_type) {
638                 g_string_append_printf(lines, STRING_WFD_CONNECTOR_TYPE);
639                 g_string_append_printf(lines, ":");
640                 g_string_append_printf(lines, STRING_WFD_CRLF);
641         }
642
643         if (msg->idr_request) {
644                 g_string_append_printf(lines, STRING_WFD_IDR_REQUEST);
645                 g_string_append_printf(lines, STRING_WFD_CRLF);
646         }
647
648         /*g_string_append_printf (lines, "\0"); */
649         /*if(g_str_has_suffix (lines, "\r\n\0"))
650         {
651         guint32 length = g_strlen(lines);
652         lines[length-2] = '\0';
653         }*/
654         return g_string_free(lines, FALSE);
655 }
656
657 gchar *wfdconfig_parameter_names_as_text(const WFDMessage *msg)
658 {
659         /* change all vars so they match rfc? */
660         GString *lines;
661         g_return_val_if_fail(msg != NULL, NULL);
662
663         lines = g_string_new("");
664
665         /* list of audio codecs */
666         if (msg->audio_codecs) {
667                 g_string_append_printf(lines, STRING_WFD_AUDIO_CODECS);
668                 g_string_append_printf(lines, STRING_WFD_CRLF);
669         }
670         /* list of video codecs */
671         if (msg->video_formats) {
672                 g_string_append_printf(lines, STRING_WFD_VIDEO_FORMATS);
673                 g_string_append_printf(lines, STRING_WFD_CRLF);
674         }
675         /* list of video 3D codecs */
676         if (msg->video_3d_formats) {
677                 g_string_append_printf(lines, STRING_WFD_3D_VIDEO_FORMATS);
678                 g_string_append_printf(lines, STRING_WFD_CRLF);
679         }
680         if (msg->content_protection) {
681                 g_string_append_printf(lines, STRING_WFD_CONTENT_PROTECTION);
682                 g_string_append_printf(lines, STRING_WFD_CRLF);
683         }
684         if (msg->display_edid) {
685                 g_string_append_printf(lines, STRING_WFD_DISPLAY_EDID);
686                 g_string_append_printf(lines, STRING_WFD_CRLF);
687         }
688         if (msg->coupled_sink) {
689                 g_string_append_printf(lines, STRING_WFD_COUPLED_SINK);
690                 g_string_append_printf(lines, STRING_WFD_CRLF);
691         }
692         if (msg->trigger_method) {
693                 g_string_append_printf(lines, STRING_WFD_TRIGGER_METHOD);
694                 g_string_append_printf(lines, STRING_WFD_CRLF);
695         }
696         if (msg->presentation_url) {
697                 g_string_append_printf(lines, STRING_WFD_PRESENTATION_URL);
698                 g_string_append_printf(lines, STRING_WFD_CRLF);
699         }
700         if (msg->client_rtp_ports) {
701                 g_string_append_printf(lines, STRING_WFD_CLIENT_RTP_PORTS);
702                 g_string_append_printf(lines, STRING_WFD_CRLF);
703         }
704         if (msg->route) {
705                 g_string_append_printf(lines, STRING_WFD_ROUTE);
706                 g_string_append_printf(lines, STRING_WFD_CRLF);
707         }
708         if (msg->I2C) {
709                 g_string_append_printf(lines, STRING_WFD_I2C);
710                 g_string_append_printf(lines, STRING_WFD_CRLF);
711         }
712         if (msg->av_format_change_timing) {
713                 g_string_append_printf(lines, STRING_WFD_AV_FORMAT_CHANGE_TIMING);
714                 g_string_append_printf(lines, STRING_WFD_CRLF);
715         }
716         if (msg->preferred_display_mode) {
717                 g_string_append_printf(lines, STRING_WFD_PREFERRED_DISPLAY_MODE);
718                 g_string_append_printf(lines, STRING_WFD_CRLF);
719         }
720         if (msg->uibc_capability) {
721                 g_string_append_printf(lines, STRING_WFD_UIBC_CAPABILITY);
722                 g_string_append_printf(lines, STRING_WFD_CRLF);
723         }
724         if (msg->uibc_setting) {
725                 g_string_append_printf(lines, STRING_WFD_UIBC_SETTING);
726                 g_string_append_printf(lines, STRING_WFD_CRLF);
727         }
728         if (msg->standby_resume_capability) {
729                 g_string_append_printf(lines, STRING_WFD_STANDBY_RESUME_CAPABILITY);
730                 g_string_append_printf(lines, STRING_WFD_CRLF);
731         }
732         if (msg->standby) {
733                 g_string_append_printf(lines, STRING_WFD_STANDBY);
734                 g_string_append_printf(lines, STRING_WFD_CRLF);
735         }
736         if (msg->connector_type) {
737                 g_string_append_printf(lines, STRING_WFD_CONNECTOR_TYPE);
738                 g_string_append_printf(lines, STRING_WFD_CRLF);
739         }
740         if (msg->idr_request) {
741                 g_string_append_printf(lines, STRING_WFD_IDR_REQUEST);
742                 g_string_append_printf(lines, STRING_WFD_CRLF);
743         }
744         return g_string_free(lines, FALSE);
745 }
746
747 static void
748 read_string_space_ended(gchar *dest, guint size, gchar *src)
749 {
750         guint idx = 0;
751
752         while (!g_ascii_isspace(*src) && *src != '\0') {
753                 if (idx < size - 1)
754                         dest[idx++] = *src;
755                 src++;
756         }
757
758         if (size > 0)
759                 dest[idx] = '\0';
760 }
761
762 static void
763 read_string_char_ended(gchar *dest, guint size, gchar del, gchar *src)
764 {
765         guint idx = 0;
766
767         while (*src != del && *src != '\0') {
768                 if (idx < size - 1)
769                         dest[idx++] = *src;
770                 src++;
771         }
772
773         if (size > 0)
774                 dest[idx] = '\0';
775 }
776
777 static void
778 read_string_type_and_value(gchar *type, gchar *value, guint tsize, guint vsize, gchar del, gchar *src)
779 {
780         guint idx;
781
782         idx = 0;
783         while (*src != del && *src != '\0') {
784                 if (idx < tsize - 1)
785                         type[idx++] = *src;
786                 src++;
787         }
788
789         if (tsize > 0)
790                 type[idx] = '\0';
791
792         src++;
793         idx = 0;
794         while (*src != '\0') {
795                 if (idx < vsize - 1)
796                         value[idx++] = *src;
797                 src++;
798         }
799         if (vsize > 0)
800                 value[idx] = '\0';
801 }
802
803 static gboolean
804 wfdconfig_parse_line(WFDMessage *msg, gchar *buffer)
805 {
806         gchar type[8192] = {0};
807         gchar value[8192] = {0};
808         gchar temp[8192] = {0};
809         gchar *p = buffer;
810         gchar *v = value;
811         gchar *result = NULL;
812
813 #define WFD_SKIP_SPACE(q) if (*q && g_ascii_isspace(*q)) q++;
814 #define WFD_SKIP_EQUAL(q) if (*q && *q == '=') q++;
815 #define WFD_SKIP_COMMA(q) if (*q && g_ascii_ispunct(*q)) q++;
816 #define WFD_READ_STRING(field) read_string_space_ended(temp, sizeof(temp), v); v += strlen(temp); REPLACE_STRING(field, temp);
817 #define WFD_READ_CHAR_END_STRING(field, del) read_string_char_ended(temp, sizeof(temp), del, v); v += strlen(temp); REPLACE_STRING(field, temp);
818 #define WFD_READ_UINT32(field) read_string_space_ended(temp, sizeof(temp), v); v += strlen(temp); field = strtoul(temp, NULL, 16);
819 #define WFD_READ_UINT32_DIGIT(field) read_string_space_ended(temp, sizeof(temp), v); v += strlen(temp); field = strtoul(temp, NULL, 10);
820
821         /*g_print("wfdconfig_parse_line input: %s\n", buffer); */
822         read_string_type_and_value(type, value, sizeof(type), sizeof(value), ':', p);
823         /*g_print("wfdconfig_parse_line type:%s value:%s\n", type, value); */
824         if (!g_strcmp0(type, STRING_WFD_AUDIO_CODECS)) {
825                 msg->audio_codecs = g_new0(WFDAudioCodeclist, 1);
826                 if (strlen(v)) {
827                         guint i = 0;
828                         msg->audio_codecs->count = strlen(v) / 16;
829                         msg->audio_codecs->list = g_new0(WFDAudioCodec, msg->audio_codecs->count);
830                         for (; i < msg->audio_codecs->count; i++) {
831                                 WFD_SKIP_SPACE(v);
832                                 WFD_READ_STRING(msg->audio_codecs->list[i].audio_format);
833                                 WFD_SKIP_SPACE(v);
834                                 WFD_READ_UINT32(msg->audio_codecs->list[i].modes);
835                                 WFD_SKIP_SPACE(v);
836                                 WFD_READ_UINT32(msg->audio_codecs->list[i].latency);
837                                 WFD_SKIP_COMMA(v);
838                         }
839                 }
840         } else if (!g_strcmp0(type, STRING_WFD_VIDEO_FORMATS)) {
841                 msg->video_formats = g_new0(WFDVideoCodeclist, 1);
842                 if (strlen(v)) {
843                         msg->video_formats->count = 1;
844                         msg->video_formats->list = g_new0(WFDVideoCodec, 1);
845                         WFD_SKIP_SPACE(v);
846                         WFD_READ_UINT32(msg->video_formats->list->native);
847                         WFD_SKIP_SPACE(v);
848                         WFD_READ_UINT32(msg->video_formats->list->preferred_display_mode_supported);
849                         WFD_SKIP_SPACE(v);
850                         WFD_READ_UINT32(msg->video_formats->list->H264_codec.profile);
851                         WFD_SKIP_SPACE(v);
852                         WFD_READ_UINT32(msg->video_formats->list->H264_codec.level);
853                         WFD_SKIP_SPACE(v);
854                         WFD_READ_UINT32(msg->video_formats->list->H264_codec.misc_params.CEA_Support);
855                         WFD_SKIP_SPACE(v);
856                         WFD_READ_UINT32(msg->video_formats->list->H264_codec.misc_params.VESA_Support);
857                         WFD_SKIP_SPACE(v);
858                         WFD_READ_UINT32(msg->video_formats->list->H264_codec.misc_params.HH_Support);
859                         WFD_SKIP_SPACE(v);
860                         WFD_READ_UINT32(msg->video_formats->list->H264_codec.misc_params.latency);
861                         WFD_SKIP_SPACE(v);
862                         WFD_READ_UINT32(msg->video_formats->list->H264_codec.misc_params.min_slice_size);
863                         WFD_SKIP_SPACE(v);
864                         WFD_READ_UINT32(msg->video_formats->list->H264_codec.misc_params.slice_enc_params);
865                         WFD_SKIP_SPACE(v);
866                         WFD_READ_UINT32(msg->video_formats->list->H264_codec.misc_params.frame_rate_control_support);
867                         WFD_SKIP_SPACE(v);
868                         if (msg->video_formats->list->preferred_display_mode_supported == 1) {
869                                 WFD_READ_UINT32(msg->video_formats->list->H264_codec.max_hres);
870                                 WFD_SKIP_SPACE(v);
871                                 WFD_READ_UINT32(msg->video_formats->list->H264_codec.max_vres);
872                                 WFD_SKIP_SPACE(v);
873                         }
874                 }
875         } else if (!g_strcmp0(type, STRING_WFD_3D_VIDEO_FORMATS)) {
876                 msg->video_3d_formats = g_new0(WFD3DFormats, 1);
877                 if (strlen(v)) {
878                         msg->video_3d_formats->count = 1;
879                         msg->video_3d_formats->list = g_new0(WFD3dCapList, 1);
880                         WFD_SKIP_SPACE(v);
881                         WFD_READ_UINT32(msg->video_3d_formats->list->native);
882                         WFD_SKIP_SPACE(v);
883                         WFD_READ_UINT32(msg->video_3d_formats->list->preferred_display_mode_supported);
884                         WFD_SKIP_SPACE(v);
885                         WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.profile);
886                         WFD_SKIP_SPACE(v);
887                         WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.level);
888                         WFD_SKIP_SPACE(v);
889                         WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.misc_params.video_3d_capability);
890                         WFD_SKIP_SPACE(v);
891                         WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.misc_params.latency);
892                         WFD_SKIP_SPACE(v);
893                         WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.misc_params.min_slice_size);
894                         WFD_SKIP_SPACE(v);
895                         WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.misc_params.slice_enc_params);
896                         WFD_SKIP_SPACE(v);
897                         WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.misc_params.frame_rate_control_support);
898                         WFD_SKIP_SPACE(v);
899                         if (msg->video_3d_formats->list->preferred_display_mode_supported == 1) {
900                                 WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.max_hres);
901                                 WFD_SKIP_SPACE(v);
902                                 WFD_READ_UINT32(msg->video_3d_formats->list->H264_codec.max_vres);
903                                 WFD_SKIP_SPACE(v);
904                         }
905                 }
906         } else if (!g_strcmp0(type, STRING_WFD_CONTENT_PROTECTION)) {
907                 msg->content_protection = g_new0(WFDContentProtection, 1);
908                 if (strlen(v)) {
909                         WFD_SKIP_SPACE(v);
910                         msg->content_protection->hdcp2_spec = g_new0(WFDHdcp2Spec, 1);
911                         if (strstr(v, STRING_WFD_NONE)) {
912                                 msg->content_protection->hdcp2_spec->hdcpversion = g_strdup(STRING_WFD_NONE);
913                         } else {
914                                 WFD_READ_STRING(msg->content_protection->hdcp2_spec->hdcpversion);
915                                 WFD_SKIP_SPACE(v);
916                                 WFD_READ_STRING(msg->content_protection->hdcp2_spec->TCPPort);
917                         }
918                 }
919         } else if (!g_strcmp0(type, STRING_WFD_DISPLAY_EDID)) {
920                 msg->display_edid = g_new0(WFDDisplayEdid, 1);
921                 if (strlen(v)) {
922                         WFD_SKIP_SPACE(v);
923                         if (strstr(v, STRING_WFD_NONE)) {
924                                 msg->display_edid->edid_supported = 0;
925                         } else {
926                                 msg->display_edid->edid_supported = 1;
927                                 WFD_READ_UINT32(msg->display_edid->edid_block_count);
928                                 WFD_SKIP_SPACE(v);
929                                 if (msg->display_edid->edid_block_count) {
930                                         gchar *edid_string = v;
931                                         int i = 0, j = 0, size = 0;
932                                         guint32 payload_size = EDID_BLOCK_SIZE * msg->display_edid->edid_block_count;
933                                         msg->display_edid->edid_payload = g_malloc(payload_size);
934                                         size = EDID_BLOCK_SIZE * msg->display_edid->edid_block_count * 2;
935                                         for (; i < size; j++) {
936                                                 int k = 0, kk = 0;
937                                                 if (edid_string[i] > 0x29 && edid_string[i] < 0x40) k = edid_string[i] - 48;
938                                                 else if (edid_string[i] > 0x60 && edid_string[i] < 0x67) k = edid_string[i] - 87;
939                                                 else if (edid_string[i] > 0x40 && edid_string[i] < 0x47) k = edid_string[i] - 55;
940
941                                                 if (edid_string[i + 1] > 0x29 && edid_string[i + 1] < 0x40) kk = edid_string[i + 1] - 48;
942                                                 else if (edid_string[i + 1] > 0x60 && edid_string[i + 1] < 0x67) kk = edid_string[i + 1] - 87;
943                                                 else if (edid_string[i + 1] > 0x40 && edid_string[i + 1] < 0x47) kk = edid_string[i + 1] - 55;
944
945                                                 msg->display_edid->edid_payload[j] = (k << 4) | kk;
946                                                 i += 2;
947                                         }
948                                         /*memcpy(msg->display_edid->edid_payload, v, payload_size); */
949                                         v += (payload_size * 2);
950                                 } else v += strlen(v);
951                         }
952                 }
953         } else if (!g_strcmp0(type, STRING_WFD_COUPLED_SINK)) {
954                 msg->coupled_sink = g_new0(WFDCoupledSink, 1);
955                 if (strlen(v)) {
956                         msg->coupled_sink->coupled_sink_cap = g_new0(WFDCoupled_sink_cap, 1);
957                         WFD_SKIP_SPACE(v);
958                         WFD_READ_UINT32(msg->coupled_sink->coupled_sink_cap->status);
959                         WFD_SKIP_SPACE(v);
960                         WFD_READ_STRING(msg->coupled_sink->coupled_sink_cap->sink_address);
961                 }
962         } else if (!g_strcmp0(type, STRING_WFD_TRIGGER_METHOD)) {
963                 msg->trigger_method = g_new0(WFDTriggerMethod, 1);
964                 if (strlen(v)) {
965                         WFD_SKIP_SPACE(v);
966                         WFD_READ_STRING(msg->trigger_method->wfd_trigger_method);
967                 }
968         } else if (!g_strcmp0(type, STRING_WFD_PRESENTATION_URL)) {
969                 msg->presentation_url = g_new0(WFDPresentationUrl, 1);
970                 if (strlen(v)) {
971                         WFD_SKIP_SPACE(v);
972                         WFD_READ_STRING(msg->presentation_url->wfd_url0);
973                         WFD_SKIP_SPACE(v);
974                         WFD_READ_STRING(msg->presentation_url->wfd_url1);
975                 }
976         } else if (!g_strcmp0(type, STRING_WFD_CLIENT_RTP_PORTS)) {
977                 msg->client_rtp_ports = g_new0(WFDClientRtpPorts, 1);
978                 if (strlen(v)) {
979                         WFD_SKIP_SPACE(v);
980                         WFD_READ_STRING(msg->client_rtp_ports->profile);
981                         WFD_SKIP_SPACE(v);
982                         WFD_READ_UINT32_DIGIT(msg->client_rtp_ports->rtp_port0);
983                         WFD_SKIP_SPACE(v);
984                         WFD_READ_UINT32_DIGIT(msg->client_rtp_ports->rtp_port1);
985                         WFD_SKIP_SPACE(v);
986                         WFD_READ_STRING(msg->client_rtp_ports->mode);
987                 }
988         } else if (!g_strcmp0(type, STRING_WFD_ROUTE)) {
989                 msg->route = g_new0(WFDRoute, 1);
990                 if (strlen(v)) {
991                         WFD_SKIP_SPACE(v);
992                         WFD_READ_STRING(msg->route->destination);
993                 }
994         } else if (!g_strcmp0(type, STRING_WFD_I2C)) {
995                 msg->I2C = g_new0(WFDI2C, 1);
996                 if (strlen(v)) {
997                         msg->I2C->I2CPresent = TRUE;
998                         WFD_SKIP_SPACE(v);
999                         WFD_READ_UINT32_DIGIT(msg->I2C->I2C_port);
1000                         if (msg->I2C->I2C_port) msg->I2C->I2CPresent = TRUE;
1001                 }
1002         } else if (!g_strcmp0(type, STRING_WFD_AV_FORMAT_CHANGE_TIMING)) {
1003                 msg->av_format_change_timing = g_new0(WFDAVFormatChangeTiming, 1);
1004                 if (strlen(v)) {
1005                         WFD_SKIP_SPACE(v);
1006                         WFD_READ_UINT32(msg->av_format_change_timing->PTS);
1007                         WFD_SKIP_SPACE(v);
1008                         WFD_READ_UINT32(msg->av_format_change_timing->DTS);
1009                 }
1010         } else if (!g_strcmp0(type, STRING_WFD_PREFERRED_DISPLAY_MODE)) {
1011                 msg->preferred_display_mode = g_new0(WFDPreferredDisplayMode, 1);
1012                 if (strlen(v)) {
1013                         WFD_SKIP_SPACE(v);
1014                         if (!strstr(v, STRING_WFD_NONE)) {
1015                                 msg->preferred_display_mode->displaymodesupported = FALSE;
1016                         } else {
1017                                 WFD_READ_UINT32(msg->preferred_display_mode->p_clock);
1018                                 WFD_SKIP_SPACE(v);
1019                                 WFD_READ_UINT32(msg->preferred_display_mode->H);
1020                                 WFD_SKIP_SPACE(v);
1021                                 WFD_READ_UINT32(msg->preferred_display_mode->HB);
1022                                 WFD_SKIP_SPACE(v);
1023                                 WFD_READ_UINT32(msg->preferred_display_mode->HSPOL_HSOFF);
1024                                 WFD_SKIP_SPACE(v);
1025                                 WFD_READ_UINT32(msg->preferred_display_mode->HSW);
1026                                 WFD_SKIP_SPACE(v);
1027                                 WFD_READ_UINT32(msg->preferred_display_mode->V);
1028                                 WFD_SKIP_SPACE(v);
1029                                 WFD_READ_UINT32(msg->preferred_display_mode->VB);
1030                                 WFD_SKIP_SPACE(v);
1031                                 WFD_READ_UINT32(msg->preferred_display_mode->VSPOL_VSOFF);
1032                                 WFD_SKIP_SPACE(v);
1033                                 WFD_READ_UINT32(msg->preferred_display_mode->VSW);
1034                                 WFD_SKIP_SPACE(v);
1035                                 WFD_READ_UINT32(msg->preferred_display_mode->VBS3D);
1036                                 WFD_SKIP_SPACE(v);
1037                                 WFD_READ_UINT32(msg->preferred_display_mode->V2d_s3d_modes);
1038                                 WFD_SKIP_SPACE(v);
1039                                 WFD_READ_UINT32(msg->preferred_display_mode->P_depth);
1040                                 WFD_SKIP_SPACE(v);
1041                                 WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.profile);
1042                                 WFD_SKIP_SPACE(v);
1043                                 WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.level);
1044                                 WFD_SKIP_SPACE(v);
1045                                 WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.misc_params.CEA_Support);
1046                                 WFD_SKIP_SPACE(v);
1047                                 WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.misc_params.VESA_Support);
1048                                 WFD_SKIP_SPACE(v);
1049                                 WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.misc_params.HH_Support);
1050                                 WFD_SKIP_SPACE(v);
1051                                 WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.misc_params.latency);
1052                                 WFD_SKIP_SPACE(v);
1053                                 WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.misc_params.min_slice_size);
1054                                 WFD_SKIP_SPACE(v);
1055                                 WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.misc_params.slice_enc_params);
1056                                 WFD_SKIP_SPACE(v);
1057                                 WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.misc_params.frame_rate_control_support);
1058                                 WFD_SKIP_SPACE(v);
1059                                 WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.max_hres);
1060                                 WFD_SKIP_SPACE(v);
1061                                 WFD_READ_UINT32(msg->preferred_display_mode->H264_codec.max_vres);
1062                                 WFD_SKIP_SPACE(v);
1063                         }
1064                 }
1065         } else if (!g_strcmp0(type, STRING_WFD_UIBC_CAPABILITY)) {
1066                 msg->uibc_capability = g_new0(WFDUibcCapability, 1);
1067                 if (strstr(v, STRING_WFD_INPUT_CATEGORY_LIST)) {
1068                         gchar *tstring = NULL;
1069                         msg->uibc_capability->uibcsupported = TRUE;
1070                         WFD_SKIP_SPACE(v);
1071                         WFD_READ_CHAR_END_STRING(tstring, '=');
1072                         if (!g_strcmp0(tstring, STRING_WFD_INPUT_CATEGORY_LIST)) {
1073                                 gchar temp2[8192] = {0};
1074                                 guint rem_len = 0, read_len = 0;
1075                                 WFD_READ_CHAR_END_STRING(tstring, ';');
1076                                 rem_len = strlen(tstring);
1077                                 do {
1078                                         WFD_SKIP_SPACE(v);
1079                                         read_string_char_ended(temp2, 8192, ',', tstring + read_len);
1080                                         read_len += (strlen(temp2) + 1);
1081                                         if (strstr(temp2, STRING_WFD_GENERIC)) msg->uibc_capability->input_category_list.input_cat |= WFD_UIBC_INPUT_CAT_GENERIC;
1082                                         else if (strstr(temp2, STRING_WFD_HIDC)) msg->uibc_capability->input_category_list.input_cat |= WFD_UIBC_INPUT_CAT_HIDC;
1083                                         else msg->uibc_capability->input_category_list.input_cat |= WFD_UIBC_INPUT_CAT_UNKNOWN;
1084                                 } while (read_len < rem_len);
1085
1086                                 result = strstr(v, STRING_WFD_GENERIC_CAP_LIST);
1087                                 if (result != NULL) {
1088                                         memset(temp2, 0, 8192);
1089                                         rem_len = 0;
1090                                         read_len = 0;
1091                                         v = result;
1092                                         WFD_READ_CHAR_END_STRING(tstring, '=');
1093                                         if (!g_strcmp0(tstring, STRING_WFD_GENERIC_CAP_LIST)) {
1094                                                 WFD_SKIP_SPACE(v);
1095                                                 WFD_READ_CHAR_END_STRING(tstring, ';');
1096                                                 rem_len = strlen(tstring);
1097                                                 do {
1098                                                         read_string_char_ended(temp2, 8192, ',', tstring + read_len);
1099                                                         read_len += (strlen(temp2) + 1);
1100                                                         if (strstr(temp2, STRING_WFD_KEYBOARD)) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_KEYBOARD;
1101                                                         else if (strstr(temp2, STRING_WFD_MOUSE)) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_MOUSE;
1102                                                         else if (strstr(temp2, STRING_WFD_SINGLE_TOUCH)) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_SINGLETOUCH;
1103                                                         else if (strstr(temp2, STRING_WFD_MULTI_TOUCH)) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_MULTITOUCH;
1104                                                         else if (strstr(temp2, STRING_WFD_JOYSTICK)) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_JOYSTICK;
1105                                                         else if (strstr(temp2, STRING_WFD_CAMERA)) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_CAMERA;
1106                                                         else if (strstr(temp2, STRING_WFD_GESTURE)) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_GESTURE;
1107                                                         else if (strstr(temp2, STRING_WFD_REMOTE_CONTROL)) msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_REMOTECONTROL;
1108                                                         else msg->uibc_capability->generic_cap_list.inp_type |= WFD_UIBC_INPUT_TYPE_UNKNOWN;
1109                                                 } while (read_len < rem_len);
1110                                         }
1111                                 }
1112                                 result = strstr(v, STRING_WFD_HIDC_CAP_LIST);
1113                                 if (result != NULL) {
1114                                         v = result;
1115                                         WFD_SKIP_SPACE(v);
1116                                         WFD_READ_CHAR_END_STRING(tstring, '=');
1117                                         if (!g_strcmp0(tstring, STRING_WFD_HIDC_CAP_LIST)) {
1118                                                 gchar inp_type[8192];
1119                                                 gchar inp_path[8192];
1120                                                 memset(temp2, 0, 8192);
1121                                                 rem_len = 0;
1122                                                 read_len = 0;
1123                                                 detailed_cap *temp_cap;
1124                                                 WFD_READ_CHAR_END_STRING(tstring, ';');
1125                                                 rem_len = strlen(tstring);
1126                                                 msg->uibc_capability->hidc_cap_list.next = g_new0(detailed_cap, 1);
1127                                                 temp_cap = msg->uibc_capability->hidc_cap_list.next;
1128                                                 do {
1129                                                         msg->uibc_capability->hidc_cap_list.cap_count++;
1130                                                         read_string_char_ended(temp2, 8192, ',', tstring + read_len);
1131                                                         read_len += (strlen(temp2) + 1);
1132                                                         read_string_type_and_value(inp_type, inp_path, sizeof(inp_type), sizeof(inp_path), '/', temp2);
1133                                                         if (strstr(inp_type, STRING_WFD_KEYBOARD)) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_KEYBOARD;
1134                                                         else if (strstr(inp_type, STRING_WFD_MOUSE)) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_MOUSE;
1135                                                         else if (strstr(inp_type, STRING_WFD_SINGLE_TOUCH)) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_SINGLETOUCH;
1136                                                         else if (strstr(inp_type, STRING_WFD_MULTI_TOUCH)) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_MULTITOUCH;
1137                                                         else if (strstr(inp_type, STRING_WFD_JOYSTICK)) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_JOYSTICK;
1138                                                         else if (strstr(inp_type, STRING_WFD_CAMERA)) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_CAMERA;
1139                                                         else if (strstr(inp_type, STRING_WFD_GESTURE)) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_GESTURE;
1140                                                         else if (strstr(inp_type, STRING_WFD_REMOTE_CONTROL)) temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_REMOTECONTROL;
1141                                                         else temp_cap->p.inp_type = WFD_UIBC_INPUT_TYPE_UNKNOWN;
1142
1143                                                         if (strstr(inp_path, STRING_WFD_INFRARED)) temp_cap->p.inp_path = WFD_UIBC_INPUT_PATH_INFRARED;
1144                                                         else if (strstr(inp_path, STRING_WFD_USB)) temp_cap->p.inp_path = WFD_UIBC_INPUT_PATH_USB;
1145                                                         else if (strstr(inp_path, STRING_WFD_BT)) temp_cap->p.inp_path = WFD_UIBC_INPUT_PATH_BT;
1146                                                         else if (strstr(inp_path, STRING_WFD_ZIGBEE)) temp_cap->p.inp_path = WFD_UIBC_INPUT_PATH_ZIGBEE;
1147                                                         else if (strstr(inp_path, STRING_WFD_WIFI)) temp_cap->p.inp_path = WFD_UIBC_INPUT_PATH_WIFI;
1148                                                         else if (strstr(inp_path, STRING_WFD_NO_SP)) temp_cap->p.inp_path = WFD_UIBC_INPUT_PATH_NOSP;
1149                                                         else temp_cap->p.inp_path = WFD_UIBC_INPUT_PATH_UNKNOWN;
1150                                                         if (read_len < rem_len) {
1151                                                                 temp_cap->next = g_new0(detailed_cap, 1);
1152                                                                 temp_cap = temp_cap->next;
1153                                                         }
1154                                                 } while (read_len < rem_len);
1155                                         }
1156                                 }
1157                                 result = strstr(v, STRING_WFD_PORT);
1158                                 if (result != NULL) {
1159                                         v = result;
1160                                         WFD_READ_CHAR_END_STRING(tstring, '=');
1161                                         if (!g_strcmp0(tstring, STRING_WFD_PORT)) {
1162                                                 WFD_SKIP_EQUAL(v);
1163                                                 WFD_READ_CHAR_END_STRING(tstring, ';');
1164                                                 if (!strstr(tstring, STRING_WFD_NONE)) {
1165                                                         msg->uibc_capability->tcp_port = strtoul(tstring, NULL, 10);
1166                                                 }
1167                                         }
1168                                 }
1169                         }
1170                 } else if (strstr(v, STRING_WFD_NONE)) {
1171                         msg->uibc_capability->uibcsupported = FALSE;
1172                 }
1173         } else if (!g_strcmp0(type, STRING_WFD_UIBC_SETTING)) {
1174                 msg->uibc_setting = g_new0(WFDUibcSetting, 1);
1175                 if (strlen(v)) {
1176                         WFD_SKIP_SPACE(v);
1177                         if (!g_strcmp0(v, STRING_WFD_ENABLE))
1178                                 msg->uibc_setting->uibc_setting = TRUE;
1179                         else
1180                                 msg->uibc_setting->uibc_setting = FALSE;
1181                 }
1182         } else if (!g_strcmp0(type, STRING_WFD_STANDBY_RESUME_CAPABILITY)) {
1183                 msg->standby_resume_capability = g_new0(WFDStandbyResumeCapability, 1);
1184                 if (strlen(v)) {
1185                         WFD_SKIP_SPACE(v);
1186                         if (!g_strcmp0(v, STRING_WFD_SUPPORTED))
1187                                 msg->standby_resume_capability->standby_resume_cap = TRUE;
1188                         else
1189                                 msg->standby_resume_capability->standby_resume_cap = FALSE;
1190                 }
1191         } else if (!g_strcmp0(type, STRING_WFD_STANDBY)) {
1192                 msg->standby = g_new0(WFDStandby, 1);
1193                 msg->standby->wfd_standby = TRUE;
1194         } else if (!g_strcmp0(type, STRING_WFD_CONNECTOR_TYPE)) {
1195                 msg->connector_type = g_new0(WFDConnectorType, 1);
1196                 if (strlen(v)) {
1197                         msg->connector_type->supported = TRUE;
1198                         WFD_SKIP_SPACE(v);
1199                         WFD_READ_UINT32(msg->connector_type->connector_type);
1200                 }
1201         } else if (!g_strcmp0(type, STRING_WFD_IDR_REQUEST)) {
1202                 msg->idr_request = g_new0(WFDIdrRequest, 1);
1203                 msg->idr_request->idr_request = TRUE;
1204         }
1205
1206         return TRUE;
1207 }
1208
1209 /**
1210 * wfdconfig_message_parse_buffer:
1211 * @data: the start of the buffer
1212 * @size: the size of the buffer
1213 * @msg: the result #WFDMessage
1214 *
1215 * Parse the contents of @size bytes pointed to by @data and store the result in
1216 * @msg.
1217 *
1218 * Returns: #WFD_OK on success.
1219 */
1220 WFDResult
1221 wfdconfig_message_parse_buffer(const guint8 *data, guint size, WFDMessage *msg)
1222 {
1223         const gchar *p;
1224         gchar buffer[MAX_LINE_LEN] = {0};
1225         guint idx = 0;
1226
1227         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
1228         g_return_val_if_fail(data != NULL, WFD_EINVAL);
1229         g_return_val_if_fail(size != 0, WFD_EINVAL);
1230
1231         p = (const gchar *) data;
1232         while (TRUE) {
1233
1234                 if (*p == '\0')
1235                         break;
1236
1237                 idx = 0;
1238                 while (*p != '\n' && *p != '\r' && *p != '\0') {
1239                         if (idx < sizeof(buffer) - 1)
1240                                 buffer[idx++] = *p;
1241                         p++;
1242                 }
1243                 buffer[idx] = '\0';
1244                 wfdconfig_parse_line(msg, buffer);
1245
1246                 if (*p == '\0')
1247                         break;
1248                 p += 2;
1249         }
1250
1251         return WFD_OK;
1252 }
1253
1254 /**
1255 * wfdconfig_message_dump:
1256 * @msg: a #WFDMessage
1257 *
1258 * Dump the parsed contents of @msg to stdout.
1259 *
1260 * Returns: a #WFDResult.
1261 */
1262 WFDResult
1263 wfdconfig_message_dump(const WFDMessage *msg)
1264 {
1265         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
1266         wfd_debug("===========WFD Message dump=========");
1267
1268         if (msg->audio_codecs) {
1269                 guint i = 0;
1270                 wfd_debug("Audio supported formats : ");
1271                 for (; i < msg->audio_codecs->count; i++) {
1272                         wfd_debug("Codec: %s", msg->audio_codecs->list[i].audio_format);
1273                         if (!strcmp(msg->audio_codecs->list[i].audio_format, STRING_WFD_LPCM)) {
1274                                 if (msg->audio_codecs->list[i].modes & WFD_FREQ_44100)
1275                                         wfd_debug("     Freq: %d", 44100);
1276                                 if (msg->audio_codecs->list[i].modes & WFD_FREQ_48000)
1277                                         wfd_debug("     Freq: %d", 48000);
1278                                 wfd_debug("     Channels: %d", 2);
1279                         }
1280                         if (!strcmp(msg->audio_codecs->list[i].audio_format, STRING_WFD_AAC)) {
1281                                 wfd_debug("     Freq: %d", 48000);
1282                                 if (msg->audio_codecs->list[i].modes & WFD_CHANNEL_2)
1283                                         wfd_debug("     Channels: %d", 2);
1284                                 if (msg->audio_codecs->list[i].modes & WFD_CHANNEL_4)
1285                                         wfd_debug("     Channels: %d", 4);
1286                                 if (msg->audio_codecs->list[i].modes & WFD_CHANNEL_6)
1287                                         wfd_debug("     Channels: %d", 6);
1288                                 if (msg->audio_codecs->list[i].modes & WFD_CHANNEL_8)
1289                                         wfd_debug("     Channels: %d", 8);
1290                         }
1291                         if (!strcmp(msg->audio_codecs->list[i].audio_format, STRING_WFD_AC3)) {
1292                                 wfd_debug("     Freq: %d", 48000);
1293                                 if (msg->audio_codecs->list[i].modes & WFD_CHANNEL_2)
1294                                         wfd_debug("     Channels: %d", 2);
1295                                 if (msg->audio_codecs->list[i].modes & WFD_CHANNEL_4)
1296                                         wfd_debug("     Channels: %d", 4);
1297                                 if (msg->audio_codecs->list[i].modes & WFD_CHANNEL_6)
1298                                         wfd_debug("     Channels: %d", 6);
1299                         }
1300                         wfd_debug("     Bitwidth: %d", 16);
1301                         wfd_debug("     Latency: %d", msg->audio_codecs->list[i].latency);
1302                 }
1303         }
1304
1305
1306         if (msg->video_formats) {
1307                 wfd_debug("Video supported formats : ");
1308                 if (msg->video_formats->list) {
1309                         wfd_debug("Codec: H264");
1310                         guint nativeindex = 0;
1311                         if ((msg->video_formats->list->native & 0x7) == WFD_VIDEO_CEA_RESOLUTION) {
1312                                 wfd_debug("     Native type: CEA");
1313                         } else if ((msg->video_formats->list->native & 0x7) == WFD_VIDEO_VESA_RESOLUTION) {
1314                                 wfd_debug("     Native type: VESA");
1315                         } else if ((msg->video_formats->list->native & 0x7) == WFD_VIDEO_HH_RESOLUTION) {
1316                                 wfd_debug("     Native type: HH");
1317                         }
1318                         nativeindex = msg->video_formats->list->native >> 3;
1319                         wfd_debug("     Resolution: %d", (1 << nativeindex));
1320
1321                         if (msg->video_formats->list->H264_codec.profile & WFD_H264_BASE_PROFILE) {
1322                                 wfd_debug("     Profile: BASE");
1323                         } else if (msg->video_formats->list->H264_codec.profile & WFD_H264_HIGH_PROFILE) {
1324                                 wfd_debug("     Profile: HIGH");
1325                         }
1326                         if (msg->video_formats->list->H264_codec.level & WFD_H264_LEVEL_3_1) {
1327                                 wfd_debug("     Level: 3.1");
1328                         } else if (msg->video_formats->list->H264_codec.level & WFD_H264_LEVEL_3_2) {
1329                                 wfd_debug("     Level: 3.2");
1330                         } else if (msg->video_formats->list->H264_codec.level & WFD_H264_LEVEL_4) {
1331                                 wfd_debug("     Level: 4");
1332                         } else if (msg->video_formats->list->H264_codec.level & WFD_H264_LEVEL_4_1) {
1333                                 wfd_debug("     Level: 4.1");
1334                         } else if (msg->video_formats->list->H264_codec.level & WFD_H264_LEVEL_4_2) {
1335                                 wfd_debug("     Level: 4.2");
1336                         }
1337                         wfd_debug("     Latency: %d", msg->video_formats->list->H264_codec.misc_params.latency);
1338                         wfd_debug("     min_slice_size: %x", msg->video_formats->list->H264_codec.misc_params.min_slice_size);
1339                         wfd_debug("     slice_enc_params: %x", msg->video_formats->list->H264_codec.misc_params.slice_enc_params);
1340                         wfd_debug("     frame_rate_control_support: %x", msg->video_formats->list->H264_codec.misc_params.frame_rate_control_support);
1341                         if (msg->video_formats->list->H264_codec.max_hres) {
1342                                 wfd_debug("     Max Width: %04d", msg->video_formats->list->H264_codec.max_hres);
1343                         }
1344                         if (msg->video_formats->list->H264_codec.max_vres) {
1345                                 wfd_debug("     Max Height: %04d", msg->video_formats->list->H264_codec.max_vres);
1346                         }
1347                 }
1348         }
1349
1350         if (msg->video_3d_formats) {
1351                 wfd_debug("wfd_3d_formats");
1352         }
1353
1354         if (msg->content_protection) {
1355                 wfd_debug(STRING_WFD_CONTENT_PROTECTION);
1356         }
1357
1358         if (msg->display_edid) {
1359                 wfd_debug(STRING_WFD_DISPLAY_EDID);
1360         }
1361
1362         if (msg->coupled_sink) {
1363                 wfd_debug(STRING_WFD_COUPLED_SINK);
1364         }
1365
1366         if (msg->trigger_method) {
1367                 wfd_debug("     Trigger type: %s", msg->trigger_method->wfd_trigger_method);
1368         }
1369
1370         if (msg->presentation_url) {
1371                 wfd_debug(STRING_WFD_PRESENTATION_URL);
1372         }
1373
1374         if (msg->client_rtp_ports) {
1375                 wfd_debug(" Client RTP Ports : ");
1376                 if (msg->client_rtp_ports->profile) {
1377                         wfd_debug("%s", msg->client_rtp_ports->profile);
1378                         wfd_debug("     %d", msg->client_rtp_ports->rtp_port0);
1379                         wfd_debug("     %d", msg->client_rtp_ports->rtp_port1);
1380                         wfd_debug("     %s", msg->client_rtp_ports->mode);
1381                 }
1382         }
1383
1384         if (msg->route) {
1385                 wfd_debug(STRING_WFD_ROUTE);
1386         }
1387
1388         if (msg->I2C) {
1389                 wfd_debug(STRING_WFD_I2C);
1390         }
1391
1392         if (msg->av_format_change_timing) {
1393                 wfd_debug(STRING_WFD_AV_FORMAT_CHANGE_TIMING);
1394         }
1395
1396         if (msg->preferred_display_mode) {
1397                 wfd_debug(STRING_WFD_PREFERRED_DISPLAY_MODE);
1398         }
1399
1400         if (msg->uibc_capability) {
1401                 wfd_debug("wfd_uibc_capability \r");
1402                 wfd_debug("input category list:");
1403                 if (msg->uibc_capability->input_category_list.input_cat & WFD_UIBC_INPUT_CAT_GENERIC)
1404                         wfd_debug(STRING_WFD_GENERIC);
1405                 if (msg->uibc_capability->input_category_list.input_cat & WFD_UIBC_INPUT_CAT_HIDC)
1406                         wfd_debug(STRING_WFD_HIDC);
1407                 if (!msg->uibc_capability->input_category_list.input_cat)
1408                         wfd_debug(STRING_WFD_NONE);
1409                 if (msg->uibc_capability->input_category_list.input_cat & WFD_UIBC_INPUT_CAT_GENERIC) {
1410                         wfd_debug("generic cap list: ");
1411                         if (msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_KEYBOARD)
1412                                 wfd_debug("keyboard ");
1413                         if (msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_MOUSE)
1414                                 wfd_debug("mouse ");
1415                         if (msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_SINGLETOUCH)
1416                                 wfd_debug("single-touch ");
1417                         if (msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_MULTITOUCH)
1418                                 wfd_debug("multi-touch ");
1419                         if (msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_JOYSTICK)
1420                                 wfd_debug("joystick ");
1421                         if (msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_CAMERA)
1422                                 wfd_debug("camera ");
1423                         if (msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_GESTURE)
1424                                 wfd_debug("gesture ");
1425                         if (msg->uibc_capability->generic_cap_list.inp_type & WFD_UIBC_INPUT_TYPE_REMOTECONTROL)
1426                                 wfd_debug("remote control ");
1427                         if (!msg->uibc_capability->generic_cap_list.inp_type)
1428                                 wfd_debug("none ");
1429                 }
1430                 if (msg->uibc_capability->input_category_list.input_cat & WFD_UIBC_INPUT_CAT_HIDC) {
1431                         wfd_debug("hidc cap list:");
1432                         if (msg->uibc_capability->hidc_cap_list.cap_count) {
1433                                 detailed_cap *temp_cap = msg->uibc_capability->hidc_cap_list.next;
1434                                 while (temp_cap) {
1435                                         if (temp_cap->p.inp_type & WFD_UIBC_INPUT_TYPE_KEYBOARD) {
1436                                                 wfd_debug("keyboard ");
1437                                         } else if (temp_cap->p.inp_type & WFD_UIBC_INPUT_TYPE_MOUSE) {
1438                                                 wfd_debug("mouse ");
1439                                         } else if (temp_cap->p.inp_type & WFD_UIBC_INPUT_TYPE_SINGLETOUCH) {
1440                                                 wfd_debug("single-touch ");
1441                                         } else if (temp_cap->p.inp_type & WFD_UIBC_INPUT_TYPE_MULTITOUCH) {
1442                                                 wfd_debug("multi-touch ");
1443                                         } else if (temp_cap->p.inp_type & WFD_UIBC_INPUT_TYPE_JOYSTICK) {
1444                                                 wfd_debug("joystick ");
1445                                         } else if (temp_cap->p.inp_type & WFD_UIBC_INPUT_TYPE_CAMERA) {
1446                                                 wfd_debug("camera ");
1447                                         } else if (temp_cap->p.inp_type & WFD_UIBC_INPUT_TYPE_GESTURE) {
1448                                                 wfd_debug("gesture ");
1449                                         } else if (temp_cap->p.inp_type & WFD_UIBC_INPUT_TYPE_REMOTECONTROL) {
1450                                                 wfd_debug("remote control ");
1451                                         } else if (!temp_cap->p.inp_type) {
1452                                                 wfd_debug("none ");
1453                                         }
1454                                         if (temp_cap->p.inp_path & WFD_UIBC_INPUT_PATH_INFRARED) {
1455                                                 wfd_debug(STRING_WFD_INFRARED);
1456                                         } else if (temp_cap->p.inp_path & WFD_UIBC_INPUT_PATH_USB) {
1457                                                 wfd_debug(STRING_WFD_USB);
1458                                         } else if (temp_cap->p.inp_path & WFD_UIBC_INPUT_PATH_BT) {
1459                                                 wfd_debug(STRING_WFD_BT);
1460                                         } else if (temp_cap->p.inp_path & WFD_UIBC_INPUT_PATH_WIFI) {
1461                                                 wfd_debug(STRING_WFD_WIFI);
1462                                         } else if (temp_cap->p.inp_path & WFD_UIBC_INPUT_PATH_ZIGBEE) {
1463                                                 wfd_debug(STRING_WFD_ZIGBEE);
1464                                         } else if (temp_cap->p.inp_path & WFD_UIBC_INPUT_PATH_NOSP) {
1465                                                 wfd_debug(STRING_WFD_NO_SP);
1466                                         } else if (!temp_cap->p.inp_path) {
1467                                                 wfd_debug(STRING_WFD_NONE);
1468                                         }
1469                                         temp_cap = temp_cap->next;
1470                                 }
1471                         }
1472                 }
1473                 if (msg->uibc_capability->tcp_port)
1474                         wfd_debug("tcp port:%u", msg->uibc_capability->tcp_port);
1475                 if (!msg->uibc_capability->tcp_port)
1476                         wfd_debug("tcp port: none");
1477         }
1478
1479         if (msg->uibc_setting) {
1480                 wfd_debug("wfd_uibc_setting: ");
1481                 if (msg->uibc_setting->uibc_setting) {
1482                         wfd_debug("true");
1483                 } else wfd_debug("false");
1484         }
1485
1486         if (msg->standby_resume_capability) {
1487                 wfd_debug(STRING_WFD_STANDBY_RESUME_CAPABILITY);
1488         }
1489
1490         if (msg->standby) {
1491                 wfd_debug(STRING_WFD_STANDBY);
1492         }
1493
1494         if (msg->connector_type) {
1495                 wfd_debug(STRING_WFD_CONNECTOR_TYPE);
1496         }
1497
1498         if (msg->idr_request) {
1499                 wfd_debug(STRING_WFD_IDR_REQUEST);
1500         }
1501
1502         wfd_debug("===============================================");
1503         return WFD_OK;
1504 }
1505
1506 WFDResult wfdconfig_set_supported_audio_format(WFDMessage *msg, WFDAudioFormats aCodec, guint aFreq, guint aChanels,
1507                                                guint aBitwidth, guint32 aLatency)
1508 {
1509         guint temp = aCodec;
1510         guint i = 0;
1511         guint pcm = 0, aac = 0, ac3 = 0;
1512
1513         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
1514
1515         if (!msg->audio_codecs)
1516                 msg->audio_codecs = g_new0(WFDAudioCodeclist, 1);
1517
1518         if (aCodec != WFD_AUDIO_UNKNOWN) {
1519                 while (temp) {
1520                         msg->audio_codecs->count++;
1521                         temp >>= 1;
1522                 }
1523                 msg->audio_codecs->list = g_new0(WFDAudioCodec, msg->audio_codecs->count);
1524                 for (; i < msg->audio_codecs->count; i++) {
1525                         if ((aCodec & WFD_AUDIO_LPCM) && (!pcm)) {
1526                                 msg->audio_codecs->list[i].audio_format = g_strdup(STRING_WFD_LPCM);
1527                                 msg->audio_codecs->list[i].modes = aFreq;
1528                                 msg->audio_codecs->list[i].latency = aLatency;
1529                                 pcm = 1;
1530                         } else if ((aCodec & WFD_AUDIO_AAC) && (!aac)) {
1531                                 msg->audio_codecs->list[i].audio_format = g_strdup(STRING_WFD_AAC);
1532                                 msg->audio_codecs->list[i].modes = aChanels;
1533                                 msg->audio_codecs->list[i].latency = aLatency;
1534                                 aac = 1;
1535                         } else if ((aCodec & WFD_AUDIO_AC3) && (!ac3)) {
1536                                 msg->audio_codecs->list[i].audio_format = g_strdup(STRING_WFD_AC3);
1537                                 msg->audio_codecs->list[i].modes = aChanels;
1538                                 msg->audio_codecs->list[i].latency = aLatency;
1539                                 ac3 = 1;
1540                         }
1541                 }
1542         }
1543         return WFD_OK;
1544 }
1545
1546 WFDResult wfdconfig_set_prefered_audio_format(WFDMessage *msg, WFDAudioFormats aCodec, WFDAudioFreq aFreq, WFDAudioChannels aChanels,
1547                                               guint aBitwidth, guint32 aLatency)
1548 {
1549
1550         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
1551
1552         if (!msg->audio_codecs)
1553                 msg->audio_codecs = g_new0(WFDAudioCodeclist, 1);
1554
1555         msg->audio_codecs->list = g_new0(WFDAudioCodec, 1);
1556         msg->audio_codecs->count = 1;
1557         if (aCodec == WFD_AUDIO_LPCM) {
1558                 msg->audio_codecs->list->audio_format = g_strdup(STRING_WFD_LPCM);
1559                 msg->audio_codecs->list->modes = aFreq;
1560                 msg->audio_codecs->list->latency = aLatency;
1561         } else if (aCodec == WFD_AUDIO_AAC) {
1562                 msg->audio_codecs->list->audio_format = g_strdup(STRING_WFD_AAC);
1563                 msg->audio_codecs->list->modes = aChanels;
1564                 msg->audio_codecs->list->latency = aLatency;
1565         } else if (aCodec == WFD_AUDIO_AC3) {
1566                 msg->audio_codecs->list->audio_format = g_strdup(STRING_WFD_AC3);
1567                 msg->audio_codecs->list->modes = aChanels;
1568                 msg->audio_codecs->list->latency = aLatency;
1569         }
1570         return WFD_OK;
1571 }
1572
1573 WFDResult wfdconfig_get_supported_audio_format(WFDMessage *msg, guint *aCodec, guint *aFreq, guint *aChanels,
1574                                                guint *aBitwidth, guint32 *aLatency)
1575 {
1576         guint i = 0;
1577         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
1578         g_return_val_if_fail(msg->audio_codecs != NULL, WFD_EINVAL);
1579
1580         for (; i < msg->audio_codecs->count; i++) {
1581                 if (!g_strcmp0(msg->audio_codecs->list[i].audio_format, STRING_WFD_LPCM)) {
1582                         *aCodec |= WFD_AUDIO_LPCM;
1583                         *aFreq |= msg->audio_codecs->list[i].modes;
1584                         *aChanels |= WFD_CHANNEL_2;
1585                         *aBitwidth = 16;
1586                         *aLatency = msg->audio_codecs->list[i].latency;
1587                 } else if (!g_strcmp0(msg->audio_codecs->list[i].audio_format, STRING_WFD_AAC)) {
1588                         *aCodec |= WFD_AUDIO_AAC;
1589                         *aFreq |= WFD_FREQ_48000;
1590                         *aChanels |= msg->audio_codecs->list[i].modes;
1591                         *aBitwidth = 16;
1592                         *aLatency = msg->audio_codecs->list[i].latency;
1593                 } else if (!g_strcmp0(msg->audio_codecs->list[i].audio_format, STRING_WFD_AC3)) {
1594                         *aCodec |= WFD_AUDIO_AC3;
1595                         *aFreq |= WFD_FREQ_48000;
1596                         *aChanels |= msg->audio_codecs->list[i].modes;
1597                         *aBitwidth = 16;
1598                         *aLatency = msg->audio_codecs->list[i].latency;
1599                 }
1600         }
1601         return WFD_OK;
1602 }
1603
1604 WFDResult wfdconfig_get_prefered_audio_format(WFDMessage *msg, WFDAudioFormats *aCodec, WFDAudioFreq *aFreq, WFDAudioChannels *aChanels,
1605                                               guint *aBitwidth, guint32 *aLatency)
1606 {
1607         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
1608
1609         if (!g_strcmp0(msg->audio_codecs->list->audio_format, STRING_WFD_LPCM)) {
1610                 *aCodec = WFD_AUDIO_LPCM;
1611                 *aFreq = msg->audio_codecs->list->modes;
1612                 *aChanels = WFD_CHANNEL_2;
1613                 *aBitwidth = 16;
1614                 *aLatency = msg->audio_codecs->list->latency;
1615         } else if (!g_strcmp0(msg->audio_codecs->list->audio_format, STRING_WFD_AAC)) {
1616                 *aCodec = WFD_AUDIO_AAC;
1617                 *aFreq = WFD_FREQ_48000;
1618                 *aChanels = msg->audio_codecs->list->modes;
1619                 *aBitwidth = 16;
1620                 *aLatency = msg->audio_codecs->list->latency;
1621         } else if (!g_strcmp0(msg->audio_codecs->list->audio_format, STRING_WFD_AC3)) {
1622                 *aCodec = WFD_AUDIO_AC3;
1623                 *aFreq = WFD_FREQ_48000;
1624                 *aChanels = msg->audio_codecs->list->modes;
1625                 *aBitwidth = 16;
1626                 *aLatency = msg->audio_codecs->list->latency;
1627         }
1628         return WFD_OK;
1629 }
1630
1631 WFDResult wfdconfig_set_supported_video_format(WFDMessage *msg, WFDVideoCodecs vCodec,
1632                                                WFDVideoNativeResolution vNative, guint64 vNativeResolution,
1633                                                guint64 vCEAResolution, guint64 vVESAResolution, guint64 vHHResolution,
1634                                                guint vProfile, guint vLevel, guint32 vLatency, guint32 vMaxHeight,
1635                                                guint32 vMaxWidth, guint32 min_slice_size, guint32 slice_enc_params, guint frame_rate_control)
1636 {
1637         guint nativeindex = 0;
1638         guint64 temp = vNativeResolution;
1639
1640         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
1641
1642         if (!msg->video_formats)
1643                 msg->video_formats = g_new0(WFDVideoCodeclist, 1);
1644
1645         if (vCodec != WFD_VIDEO_UNKNOWN) {
1646                 msg->video_formats->list = g_new0(WFDVideoCodec, 1);
1647                 while (temp) {
1648                         nativeindex++;
1649                         temp >>= 1;
1650                 }
1651
1652                 msg->video_formats->list->native = nativeindex - 1;
1653                 msg->video_formats->list->native <<= 3;
1654
1655                 if (vNative == WFD_VIDEO_VESA_RESOLUTION)
1656                         msg->video_formats->list->native |= 1;
1657                 else if (vNative == WFD_VIDEO_HH_RESOLUTION)
1658                         msg->video_formats->list->native |= 2;
1659
1660                 msg->video_formats->list->preferred_display_mode_supported = 1;
1661                 msg->video_formats->list->H264_codec.profile = vProfile;
1662                 msg->video_formats->list->H264_codec.level = vLevel;
1663                 msg->video_formats->list->H264_codec.max_hres = vMaxWidth;
1664                 msg->video_formats->list->H264_codec.max_vres = vMaxHeight;
1665                 msg->video_formats->list->H264_codec.misc_params.CEA_Support = vCEAResolution;
1666                 msg->video_formats->list->H264_codec.misc_params.VESA_Support = vVESAResolution;
1667                 msg->video_formats->list->H264_codec.misc_params.HH_Support = vHHResolution;
1668                 msg->video_formats->list->H264_codec.misc_params.latency = vLatency;
1669                 msg->video_formats->list->H264_codec.misc_params.min_slice_size = min_slice_size;
1670                 msg->video_formats->list->H264_codec.misc_params.slice_enc_params = slice_enc_params;
1671                 msg->video_formats->list->H264_codec.misc_params.frame_rate_control_support = frame_rate_control;
1672         }
1673         return WFD_OK;
1674 }
1675
1676 WFDResult wfdconfig_set_prefered_video_format(WFDMessage *msg, WFDVideoCodecs vCodec,
1677                                               WFDVideoNativeResolution vNative, guint64 vNativeResolution,
1678                                               WFDVideoCEAResolution vCEAResolution, WFDVideoVESAResolution vVESAResolution,
1679                                               WFDVideoHHResolution vHHResolution,       WFDVideoH264Profile vProfile,
1680                                               WFDVideoH264Level vLevel, guint32 vLatency, guint32 vMaxHeight,
1681                                               guint32 vMaxWidth, guint32 min_slice_size, guint32 slice_enc_params, guint frame_rate_control)
1682 {
1683         guint nativeindex = 0;
1684         guint64 temp = vNativeResolution;
1685
1686         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
1687
1688         if (!msg->video_formats)
1689                 msg->video_formats = g_new0(WFDVideoCodeclist, 1);
1690         msg->video_formats->list = g_new0(WFDVideoCodec, 1);
1691
1692         while (temp) {
1693                 nativeindex++;
1694                 temp >>= 1;
1695         }
1696
1697         if (nativeindex) msg->video_formats->list->native = nativeindex - 1;
1698         msg->video_formats->list->native <<= 3;
1699
1700         if (vNative == WFD_VIDEO_VESA_RESOLUTION)
1701                 msg->video_formats->list->native |= 1;
1702         else if (vNative == WFD_VIDEO_HH_RESOLUTION)
1703                 msg->video_formats->list->native |= 2;
1704
1705         msg->video_formats->list->preferred_display_mode_supported = 0;
1706         msg->video_formats->list->H264_codec.profile = vProfile;
1707         msg->video_formats->list->H264_codec.level = vLevel;
1708         msg->video_formats->list->H264_codec.max_hres = vMaxWidth;
1709         msg->video_formats->list->H264_codec.max_vres = vMaxHeight;
1710         msg->video_formats->list->H264_codec.misc_params.CEA_Support = vCEAResolution;
1711         msg->video_formats->list->H264_codec.misc_params.VESA_Support = vVESAResolution;
1712         msg->video_formats->list->H264_codec.misc_params.HH_Support = vHHResolution;
1713         msg->video_formats->list->H264_codec.misc_params.latency = vLatency;
1714         msg->video_formats->list->H264_codec.misc_params.min_slice_size = min_slice_size;
1715         msg->video_formats->list->H264_codec.misc_params.slice_enc_params = slice_enc_params;
1716         msg->video_formats->list->H264_codec.misc_params.frame_rate_control_support = frame_rate_control;
1717         return WFD_OK;
1718 }
1719
1720 WFDResult wfdconfig_get_supported_video_format(WFDMessage *msg, WFDVideoCodecs *vCodec,
1721                                                WFDVideoNativeResolution *vNative, guint64 *vNativeResolution,
1722                                                guint64 *vCEAResolution, guint64 *vVESAResolution, guint64 *vHHResolution,
1723                                                guint *vProfile, guint *vLevel, guint32 *vLatency, guint32 *vMaxHeight,
1724                                                guint32 *vMaxWidth, guint32 *min_slice_size, guint32 *slice_enc_params, guint *frame_rate_control)
1725 {
1726         guint nativeindex = 0;
1727
1728         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
1729         g_return_val_if_fail(msg->video_formats != NULL, WFD_EINVAL);
1730         g_return_val_if_fail(msg->video_formats->list != NULL, WFD_EINVAL);
1731
1732         *vCodec = WFD_VIDEO_H264;
1733         *vNative = msg->video_formats->list->native & 0x7;
1734         nativeindex = msg->video_formats->list->native >> 3;
1735         *vNativeResolution = (guint64)1 << nativeindex;
1736         *vProfile = msg->video_formats->list->H264_codec.profile;
1737         *vLevel = msg->video_formats->list->H264_codec.level;
1738         *vMaxWidth = msg->video_formats->list->H264_codec.max_hres;
1739         *vMaxHeight = msg->video_formats->list->H264_codec.max_vres;
1740         *vCEAResolution = msg->video_formats->list->H264_codec.misc_params.CEA_Support;
1741         *vVESAResolution = msg->video_formats->list->H264_codec.misc_params.VESA_Support;
1742         *vHHResolution = msg->video_formats->list->H264_codec.misc_params.HH_Support;
1743         *vLatency = msg->video_formats->list->H264_codec.misc_params.latency;
1744         *min_slice_size = msg->video_formats->list->H264_codec.misc_params.min_slice_size;
1745         *slice_enc_params = msg->video_formats->list->H264_codec.misc_params.slice_enc_params;
1746         *frame_rate_control = msg->video_formats->list->H264_codec.misc_params.frame_rate_control_support;
1747         return WFD_OK;
1748 }
1749
1750 WFDResult wfdconfig_get_prefered_video_format(WFDMessage *msg, WFDVideoCodecs *vCodec,
1751                                               WFDVideoNativeResolution *vNative, guint64 *vNativeResolution,
1752                                               WFDVideoCEAResolution *vCEAResolution, WFDVideoVESAResolution *vVESAResolution,
1753                                               WFDVideoHHResolution *vHHResolution,      WFDVideoH264Profile *vProfile,
1754                                               WFDVideoH264Level *vLevel, guint32 *vLatency, guint32 *vMaxHeight,
1755                                               guint32 *vMaxWidth, guint32 *min_slice_size, guint32 *slice_enc_params, guint *frame_rate_control)
1756 {
1757         guint nativeindex = 0;
1758         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
1759         g_return_val_if_fail(msg->video_formats != NULL, WFD_EINVAL);
1760         g_return_val_if_fail(msg->video_formats->list != NULL, WFD_EINVAL);
1761
1762         *vCodec = WFD_VIDEO_H264;
1763         *vNative = msg->video_formats->list->native & 0x7;
1764         nativeindex = msg->video_formats->list->native >> 3;
1765         *vNativeResolution = (guint64)1 << nativeindex;
1766         *vProfile = msg->video_formats->list->H264_codec.profile;
1767         *vLevel = msg->video_formats->list->H264_codec.level;
1768         *vMaxWidth = msg->video_formats->list->H264_codec.max_hres;
1769         *vMaxHeight = msg->video_formats->list->H264_codec.max_vres;
1770         *vCEAResolution = msg->video_formats->list->H264_codec.misc_params.CEA_Support;
1771         *vVESAResolution = msg->video_formats->list->H264_codec.misc_params.VESA_Support;
1772         *vHHResolution = msg->video_formats->list->H264_codec.misc_params.HH_Support;
1773         *vLatency = msg->video_formats->list->H264_codec.misc_params.latency;
1774         *min_slice_size = msg->video_formats->list->H264_codec.misc_params.min_slice_size;
1775         *slice_enc_params = msg->video_formats->list->H264_codec.misc_params.slice_enc_params;
1776         *frame_rate_control = msg->video_formats->list->H264_codec.misc_params.frame_rate_control_support;
1777         return WFD_OK;
1778 }
1779
1780 WFDResult wfdconfig_set_contentprotection_type(WFDMessage *msg, WFDHDCPProtection hdcpversion, guint32 TCPPort)
1781 {
1782         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
1783
1784         if (!msg->content_protection) msg->content_protection = g_new0(WFDContentProtection, 1);
1785         if (hdcpversion == WFD_HDCP_NONE) return WFD_OK;
1786         msg->content_protection->hdcp2_spec = g_new0(WFDHdcp2Spec, 1);
1787         if (hdcpversion == WFD_HDCP_2_0) msg->content_protection->hdcp2_spec->hdcpversion = g_strdup(STRING_WFD_HDCP2_0);
1788         else if (hdcpversion == WFD_HDCP_2_1) msg->content_protection->hdcp2_spec->hdcpversion = g_strdup(STRING_WFD_HDCP2_1);
1789         char str[11] = {0, };
1790         snprintf(str, 11, "port=%d", TCPPort);
1791         msg->content_protection->hdcp2_spec->TCPPort = g_strdup(str);
1792         return WFD_OK;
1793 }
1794
1795 WFDResult wfdconfig_get_contentprotection_type(WFDMessage *msg, WFDHDCPProtection *hdcpversion, guint32 *TCPPort)
1796 {
1797         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
1798         if (msg->content_protection && msg->content_protection->hdcp2_spec) {
1799                 char *result = NULL;
1800                 char *ptr = NULL;
1801                 if (!g_strcmp0(msg->content_protection->hdcp2_spec->hdcpversion, STRING_WFD_NONE)) {
1802                         wfd_warning("HDCP none");
1803                         *hdcpversion = WFD_HDCP_NONE;
1804                         *TCPPort = 0;
1805                         return WFD_OK;
1806                 }
1807                 if (!g_strcmp0(msg->content_protection->hdcp2_spec->hdcpversion, STRING_WFD_HDCP2_0)) *hdcpversion = WFD_HDCP_2_0;
1808                 else if (!g_strcmp0(msg->content_protection->hdcp2_spec->hdcpversion, STRING_WFD_HDCP2_1)) *hdcpversion = WFD_HDCP_2_1;
1809                 else {
1810                         wfd_warning("Unknown protection type");
1811                         *hdcpversion = WFD_HDCP_NONE;
1812                         *TCPPort = 0;
1813                         return WFD_OK;
1814                 }
1815
1816                 result = strtok_r(msg->content_protection->hdcp2_spec->TCPPort, "=", &ptr);
1817                 while (result != NULL) {
1818                         result = strtok_r(NULL, "=", &ptr);
1819                         *TCPPort = atoi(result);
1820                         break;
1821                 }
1822         } else *hdcpversion = WFD_HDCP_NONE;
1823         return WFD_OK;
1824 }
1825
1826 WFDResult wfdconfig_set_display_EDID(WFDMessage *msg, gboolean edid_supported, guint32 edid_blockcount, gchar *edid_playload)
1827 {
1828         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
1829         if (!msg->display_edid) msg->display_edid = g_new0(WFDDisplayEdid, 1);
1830         msg->display_edid->edid_supported = edid_supported;
1831         if (!edid_supported) return WFD_OK;
1832         msg->display_edid->edid_block_count = edid_blockcount;
1833         if (edid_blockcount) {
1834                 msg->display_edid->edid_payload = g_malloc(128 * edid_blockcount);
1835                 if (!msg->display_edid->edid_payload)
1836                         memcpy(msg->display_edid->edid_payload, edid_playload, 128 * edid_blockcount);
1837         } else msg->display_edid->edid_payload = g_strdup(STRING_WFD_NONE);
1838         return WFD_OK;
1839 }
1840
1841 WFDResult wfdconfig_get_display_EDID(WFDMessage *msg, gboolean *edid_supported, guint32 *edid_blockcount, gchar **edid_playload)
1842 {
1843         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
1844         if (msg->display_edid) {
1845                 if (msg->display_edid->edid_supported) {
1846                         *edid_blockcount = msg->display_edid->edid_block_count;
1847                         if (msg->display_edid->edid_block_count) {
1848                                 char *temp;
1849                                 temp = g_malloc(EDID_BLOCK_SIZE * msg->display_edid->edid_block_count);
1850                                 if (temp) {
1851                                         memset(temp, 0, EDID_BLOCK_SIZE * msg->display_edid->edid_block_count);
1852                                         memcpy(temp, msg->display_edid->edid_payload, EDID_BLOCK_SIZE * msg->display_edid->edid_block_count);
1853                                         *edid_playload = temp;
1854                                         *edid_supported = TRUE;
1855                                 }
1856                         } else *edid_playload = g_strdup(STRING_WFD_NONE);
1857                 }
1858         } else *edid_supported = FALSE;
1859         return WFD_OK;
1860 }
1861
1862 WFDResult wfdconfig_set_coupled_sink(WFDMessage *msg, WFDCoupledSinkStatus status, gchar *sink_address)
1863 {
1864         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
1865         if (!msg->coupled_sink) msg->coupled_sink = g_new0(WFDCoupledSink, 1);
1866         if (status == WFD_SINK_UNKNOWN) return WFD_OK;
1867         msg->coupled_sink->coupled_sink_cap = g_new0(WFDCoupled_sink_cap, 1);
1868         msg->coupled_sink->coupled_sink_cap->status = status;
1869         msg->coupled_sink->coupled_sink_cap->sink_address = g_strdup(sink_address);
1870         return WFD_OK;
1871 }
1872
1873 WFDResult wfdconfig_get_coupled_sink(WFDMessage *msg, WFDCoupledSinkStatus *status, gchar **sink_address)
1874 {
1875         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
1876         if (msg->coupled_sink && msg->coupled_sink->coupled_sink_cap) {
1877                 *status = msg->coupled_sink->coupled_sink_cap->status;
1878                 *sink_address = g_strdup(msg->coupled_sink->coupled_sink_cap->sink_address);
1879         } else *status = WFD_SINK_UNKNOWN;
1880         return WFD_OK;
1881 }
1882
1883 WFDResult wfdconfig_set_trigger_type(WFDMessage *msg, WFDTrigger trigger)
1884 {
1885         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
1886
1887         if (!msg->trigger_method)
1888                 msg->trigger_method = g_new0(WFDTriggerMethod, 1);
1889         if (trigger == WFD_TRIGGER_SETUP)
1890                 msg->trigger_method->wfd_trigger_method = g_strdup(STRING_WFD_SETUP);
1891         else if (trigger == WFD_TRIGGER_PAUSE)
1892                 msg->trigger_method->wfd_trigger_method = g_strdup(STRING_WFD_PAUSE);
1893         else if (trigger == WFD_TRIGGER_TEARDOWN)
1894                 msg->trigger_method->wfd_trigger_method = g_strdup(STRING_WFD_TEARDOWN);
1895         else if (trigger == WFD_TRIGGER_PLAY)
1896                 msg->trigger_method->wfd_trigger_method = g_strdup(STRING_WFD_PLAY);
1897         else
1898                 return WFD_EINVAL;
1899         return WFD_OK;
1900 }
1901
1902 WFDResult wfdconfig_get_trigger_type(WFDMessage *msg, WFDTrigger *trigger)
1903 {
1904         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
1905         if (!g_strcmp0(msg->trigger_method->wfd_trigger_method, STRING_WFD_SETUP))
1906                 *trigger = WFD_TRIGGER_SETUP;
1907         else if (!g_strcmp0(msg->trigger_method->wfd_trigger_method, STRING_WFD_PAUSE))
1908                 *trigger = WFD_TRIGGER_PAUSE;
1909         else if (!g_strcmp0(msg->trigger_method->wfd_trigger_method, STRING_WFD_TEARDOWN))
1910                 *trigger = WFD_TRIGGER_TEARDOWN;
1911         else if (!g_strcmp0(msg->trigger_method->wfd_trigger_method, STRING_WFD_PLAY))
1912                 *trigger = WFD_TRIGGER_PLAY;
1913         else {
1914                 *trigger = WFD_TRIGGER_UNKNOWN;
1915                 return WFD_EINVAL;
1916         }
1917         return WFD_OK;
1918 }
1919
1920 WFDResult wfdconfig_set_presentation_url(WFDMessage *msg, gchar *wfd_url0, gchar *wfd_url1)
1921 {
1922         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
1923         if (!msg->presentation_url) msg->presentation_url = g_new0(WFDPresentationUrl, 1);
1924         if (wfd_url0) msg->presentation_url->wfd_url0 = g_strdup(wfd_url0);
1925         if (wfd_url1) msg->presentation_url->wfd_url1 = g_strdup(wfd_url1);
1926         return WFD_OK;
1927 }
1928
1929 WFDResult wfdconfig_get_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) {
1933                 *wfd_url0 = g_strdup(msg->presentation_url->wfd_url0);
1934                 *wfd_url1 = g_strdup(msg->presentation_url->wfd_url1);
1935         }
1936         return WFD_OK;
1937 }
1938
1939 WFDResult wfdconfig_set_prefered_RTP_ports(WFDMessage *msg, WFDRTSPTransMode trans, WFDRTSPProfile profile,
1940                                            WFDRTSPLowerTrans lowertrans, guint32 rtp_port0, guint32 rtp_port1)
1941 {
1942         GString *lines;
1943         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
1944
1945         if (!msg->client_rtp_ports)
1946                 msg->client_rtp_ports = g_new0(WFDClientRtpPorts, 1);
1947
1948         if (trans != WFD_RTSP_TRANS_UNKNOWN) {
1949                 lines = g_string_new("");
1950                 if (trans == WFD_RTSP_TRANS_RTP)        g_string_append_printf(lines, STRING_WFD_RTP);
1951                 else if (trans == WFD_RTSP_TRANS_RDT) g_string_append_printf(lines, STRING_WFD_RDT);
1952
1953                 if (profile != WFD_RTSP_PROFILE_UNKNOWN) g_string_append_printf(lines, "/");
1954
1955                 if (profile == WFD_RTSP_PROFILE_AVP) g_string_append_printf(lines, STRING_WFD_AVP);
1956                 else if (profile == WFD_RTSP_PROFILE_SAVP) g_string_append_printf(lines, STRING_WFD_SAVP);
1957
1958                 if (lowertrans != WFD_RTSP_LOWER_TRANS_UNKNOWN) g_string_append_printf(lines, "/");
1959
1960                 if (lowertrans == WFD_RTSP_LOWER_TRANS_UDP) {
1961                         g_string_append_printf(lines, STRING_WFD_UDP);
1962                         g_string_append_printf(lines, ";");
1963                         g_string_append_printf(lines, STRING_WFD_UNICAST);
1964                 } else if (lowertrans == WFD_RTSP_LOWER_TRANS_UDP_MCAST) {
1965                         g_string_append_printf(lines, STRING_WFD_UDP);
1966                         g_string_append_printf(lines, ";");
1967                         g_string_append_printf(lines, STRING_WFD_MULTICAST);
1968                 } else if (lowertrans == WFD_RTSP_LOWER_TRANS_TCP) {
1969                         g_string_append_printf(lines, STRING_WFD_TCP);
1970                         g_string_append_printf(lines, ";");
1971                         g_string_append_printf(lines, STRING_WFD_UNICAST);
1972                 } else if (lowertrans == WFD_RTSP_LOWER_TRANS_HTTP) {
1973                         g_string_append_printf(lines, STRING_WFD_TCP_HTTP);
1974                 }
1975
1976                 msg->client_rtp_ports->profile = g_string_free(lines, FALSE);
1977                 msg->client_rtp_ports->rtp_port0 = rtp_port0;
1978                 msg->client_rtp_ports->rtp_port1 = rtp_port1;
1979                 msg->client_rtp_ports->mode = g_strdup("mode=play");
1980         }
1981         return WFD_OK;
1982 }
1983
1984 WFDResult wfdconfig_get_prefered_RTP_ports(WFDMessage *msg, WFDRTSPTransMode *trans, WFDRTSPProfile *profile,
1985                                            WFDRTSPLowerTrans *lowertrans, guint32 *rtp_port0, guint32 *rtp_port1)
1986 {
1987         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
1988         g_return_val_if_fail(msg->client_rtp_ports != NULL, WFD_EINVAL);
1989
1990         if (g_strrstr(msg->client_rtp_ports->profile, STRING_WFD_RTP)) *trans = WFD_RTSP_TRANS_RTP;
1991         if (g_strrstr(msg->client_rtp_ports->profile, STRING_WFD_RDT)) *trans = WFD_RTSP_TRANS_RDT;
1992         if (g_strrstr(msg->client_rtp_ports->profile, STRING_WFD_AVP)) *profile = WFD_RTSP_PROFILE_AVP;
1993         if (g_strrstr(msg->client_rtp_ports->profile, STRING_WFD_SAVP)) *profile = WFD_RTSP_PROFILE_SAVP;
1994         if (g_strrstr(msg->client_rtp_ports->profile, STRING_WFD_UDP) &&
1995                 g_strrstr(msg->client_rtp_ports->profile, STRING_WFD_UNICAST)) *lowertrans = WFD_RTSP_LOWER_TRANS_UDP;
1996         if (g_strrstr(msg->client_rtp_ports->profile, STRING_WFD_UDP) &&
1997                 g_strrstr(msg->client_rtp_ports->profile, STRING_WFD_MULTICAST)) *lowertrans = WFD_RTSP_LOWER_TRANS_UDP_MCAST;
1998         if (g_strrstr(msg->client_rtp_ports->profile, STRING_WFD_TCP) &&
1999                 g_strrstr(msg->client_rtp_ports->profile, STRING_WFD_UNICAST)) *lowertrans = WFD_RTSP_LOWER_TRANS_TCP;
2000         if (g_strrstr(msg->client_rtp_ports->profile, STRING_WFD_TCP_HTTP)) *lowertrans = WFD_RTSP_LOWER_TRANS_HTTP;
2001
2002         *rtp_port0 = msg->client_rtp_ports->rtp_port0;
2003         *rtp_port1 = msg->client_rtp_ports->rtp_port1;
2004
2005         return WFD_OK;
2006 }
2007
2008 WFDResult wfdconfig_set_audio_sink_type(WFDMessage *msg, WFDSinkType sinktype)
2009 {
2010         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
2011         if (!msg->route) msg->route = g_new0(WFDRoute, 1);
2012         if (sinktype == WFD_PRIMARY_SINK) msg->route->destination = g_strdup(STRING_WFD_PRIMARY);
2013         else if (sinktype == WFD_SECONDARY_SINK) msg->route->destination = g_strdup(STRING_WFD_SECONDARY);
2014         return WFD_OK;
2015 }
2016
2017 WFDResult wfdconfig_get_audio_sink_type(WFDMessage *msg, WFDSinkType *sinktype)
2018 {
2019         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
2020         if (msg->route) {
2021                 if (!g_strcmp0(msg->route->destination, STRING_WFD_PRIMARY)) *sinktype = WFD_PRIMARY_SINK;
2022                 else if (!g_strcmp0(msg->route->destination, STRING_WFD_SECONDARY)) *sinktype = WFD_SECONDARY_SINK;
2023         }
2024         return WFD_OK;
2025 }
2026
2027 WFDResult wfdconfig_set_I2C_port(WFDMessage *msg, gboolean i2csupport, guint32 i2cport)
2028 {
2029         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
2030         if (!msg->I2C) msg->I2C = g_new0(WFDI2C, 1);
2031         msg->I2C->I2CPresent = i2csupport;
2032         msg->I2C->I2C_port = i2cport;
2033         return WFD_OK;
2034 }
2035
2036 WFDResult wfdconfig_get_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->I2CPresent) {
2040                 *i2csupport = msg->I2C->I2CPresent;
2041                 *i2cport = msg->I2C->I2C_port;
2042         } else *i2csupport = FALSE;
2043         return WFD_OK;
2044 }
2045
2046 WFDResult wfdconfig_set_av_format_change_timing(WFDMessage *msg, guint64 PTS, guint64 DTS)
2047 {
2048         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
2049         if (!msg->av_format_change_timing) msg->av_format_change_timing = g_new0(WFDAVFormatChangeTiming, 1);
2050         msg->av_format_change_timing->PTS = PTS;
2051         msg->av_format_change_timing->DTS = DTS;
2052         return WFD_OK;
2053 }
2054
2055 WFDResult wfdconfig_get_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) {
2059                 *PTS = msg->av_format_change_timing->PTS;
2060                 *DTS = msg->av_format_change_timing->DTS;
2061         }
2062         return WFD_OK;
2063 }
2064
2065 WFDResult wfdconfig_set_uibc_capability(WFDMessage *msg, guint32 input_category, guint32 inp_type, WFDHIDCTypePathPair *inp_pair,
2066                                         guint32 inp_type_path_count, guint32 tcp_port)
2067 {
2068         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
2069         if (!msg->uibc_capability) msg->uibc_capability = g_new0(WFDUibcCapability, 1);
2070         msg->uibc_capability->uibcsupported = TRUE;
2071         msg->uibc_capability->input_category_list.input_cat = input_category;
2072         msg->uibc_capability->generic_cap_list.inp_type = inp_type;
2073         msg->uibc_capability->hidc_cap_list.cap_count = inp_type_path_count;
2074         if (msg->uibc_capability->hidc_cap_list.cap_count) {
2075                 detailed_cap *temp_cap;
2076                 guint i = 0;
2077                 msg->uibc_capability->hidc_cap_list.next = g_new0(detailed_cap, 1);
2078                 temp_cap = msg->uibc_capability->hidc_cap_list.next;
2079                 for (; i < inp_type_path_count;) {
2080                         temp_cap->p.inp_type = inp_pair[i].inp_type;
2081                         temp_cap->p.inp_path = inp_pair[i].inp_path;
2082                         i++;
2083                         if (i < inp_type_path_count) {
2084                                 temp_cap->next = g_new0(detailed_cap, 1);
2085                                 temp_cap = temp_cap->next;
2086                         }
2087                 }
2088         }
2089         msg->uibc_capability->tcp_port = tcp_port;
2090         return WFD_OK;
2091 }
2092
2093 WFDResult wfdconfig_get_uibc_capability(WFDMessage *msg, guint32 *input_category, guint32 *inp_type, WFDHIDCTypePathPair **inp_pair,
2094                                         guint32 *inp_type_path_count, guint32 *tcp_port)
2095 {
2096         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
2097         if (msg->uibc_capability && msg->uibc_capability->uibcsupported) {
2098                 *input_category = msg->uibc_capability->input_category_list.input_cat;
2099                 *inp_type = msg->uibc_capability->generic_cap_list.inp_type;
2100                 *inp_type_path_count = msg->uibc_capability->hidc_cap_list.cap_count;
2101                 if (msg->uibc_capability->hidc_cap_list.cap_count) {
2102                         detailed_cap *temp_cap;
2103                         guint i = 0;
2104                         *inp_pair = g_new0(WFDHIDCTypePathPair, msg->uibc_capability->hidc_cap_list.cap_count);
2105                         temp_cap = msg->uibc_capability->hidc_cap_list.next;
2106                         while (temp_cap) {
2107                                 (*(inp_pair))[i].inp_type = temp_cap->p.inp_type;
2108                                 (*(inp_pair))[i].inp_path = temp_cap->p.inp_path;
2109                                 temp_cap = temp_cap->next;
2110                                 i++;
2111                         }
2112                 }
2113                 *tcp_port = msg->uibc_capability->tcp_port;
2114         }
2115         return WFD_OK;
2116 }
2117
2118 WFDResult wfdconfig_set_uibc_status(WFDMessage *msg, gboolean uibc_enable)
2119 {
2120         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
2121         if (!msg->uibc_setting) msg->uibc_setting = g_new0(WFDUibcSetting, 1);
2122         msg->uibc_setting->uibc_setting = uibc_enable;
2123         return WFD_OK;
2124 }
2125
2126 WFDResult wfdconfig_get_uibc_status(WFDMessage *msg, gboolean *uibc_enable)
2127 {
2128         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
2129         if (msg->uibc_setting) *uibc_enable = msg->uibc_setting->uibc_setting;
2130         return WFD_OK;
2131 }
2132 #ifdef STANDBY_RESUME_CAPABILITY
2133 WFDResult wfdconfig_set_standby_resume_capability(WFDMessage *msg, gboolean supported)
2134 {
2135         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
2136         if (!msg->standby_resume_capability) msg->standby_resume_capability = g_new0(WFDStandbyResumeCapability, 1);
2137         msg->standby_resume_capability->standby_resume_cap = supported;
2138         return WFD_OK;
2139 }
2140
2141 WFDResult wfdconfig_get_standby_resume_capability(WFDMessage *msg, gboolean *supported)
2142 {
2143         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
2144         if (msg->standby_resume_capability) *supported = msg->standby_resume_capability->standby_resume_cap;
2145         return WFD_OK;
2146 }
2147 #endif
2148 WFDResult wfdconfig_set_standby(WFDMessage *msg, gboolean standby_enable)
2149 {
2150         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
2151         if (!msg->standby) msg->standby = g_new0(WFDStandby, 1);
2152         msg->standby->wfd_standby = standby_enable;
2153         return WFD_OK;
2154 }
2155
2156 WFDResult wfdconfig_get_standby(WFDMessage *msg, gboolean *standby_enable)
2157 {
2158         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
2159         if (msg->standby) *standby_enable = msg->standby->wfd_standby;
2160         return WFD_OK;
2161 }
2162
2163 WFDResult wfdconfig_set_connector_type(WFDMessage *msg, WFDConnector connector)
2164 {
2165         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
2166         if (!msg->connector_type) msg->connector_type = g_new0(WFDConnectorType, 1);
2167         msg->connector_type->connector_type = connector;
2168         return WFD_OK;
2169 }
2170
2171 WFDResult wfdconfig_get_connector_type(WFDMessage *msg, WFDConnector *connector)
2172 {
2173         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
2174         if (msg->connector_type) *connector = msg->connector_type->connector_type;
2175         return WFD_OK;
2176 }
2177
2178 WFDResult wfdconfig_set_idr_request(WFDMessage *msg)
2179 {
2180         g_return_val_if_fail(msg != NULL, WFD_EINVAL);
2181         if (!msg->idr_request) msg->idr_request = g_new0(WFDIdrRequest, 1);
2182         msg->idr_request->idr_request = TRUE;
2183         return WFD_OK;
2184 }