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