1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2008 VideoLAN
6 * Authors: Christophe Massiot <massiot@via.ecp.fr>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
31 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <sys/socket.h>
35 #include <netinet/in.h>
36 #include <arpa/inet.h>
43 #include <bitstream/mpeg/psi.h>
44 #include <bitstream/dvb/si.h>
45 #include <bitstream/dvb/si_print.h>
46 #include <bitstream/mpeg/psi_print.h>
54 unsigned int i_timeout_seconds
= 15;
56 print_type_t i_print_type
= PRINT_TEXT
;
60 char psz_client_socket
[PATH_MAX
] = {0};
62 static iconv_t iconv_handle
= (iconv_t
)-1;
64 static void clean_client_socket() {
70 if ( psz_client_socket
[0] )
72 unlink( psz_client_socket
);
73 psz_client_socket
[0] = '\0';
77 /*****************************************************************************
78 * The following two functions are from biTStream's examples and are under the
79 * WTFPL (see LICENSE.WTFPL).
80 ****************************************************************************/
81 __attribute__ ((format(printf
, 2, 3)))
82 static void psi_print(void *_unused
, const char *psz_format
, ...)
84 char psz_fmt
[strlen(psz_format
) + 2];
86 va_start(args
, psz_format
);
87 strcpy(psz_fmt
, psz_format
);
88 strcat(psz_fmt
, "\n");
89 vprintf(psz_fmt
, args
);
93 __attribute__ ((format(printf
, 1, 2)))
94 void return_error( const char *psz_format
, ... )
99 clean_client_socket();
101 va_start( args
, psz_format
);
102 if ( i_print_type
== PRINT_XML
)
103 snprintf( psz_fmt
, sizeof(psz_fmt
) - 1, "<ERROR msg=\"%s\"/>\n", psz_format
);
105 snprintf( psz_fmt
, sizeof(psz_fmt
) - 1, "ERROR: %s\n", psz_format
);
106 psz_fmt
[sizeof(psz_fmt
) - 1] = '\0';
107 vfprintf( stderr
, psz_fmt
, args
);
112 static char *iconv_append_null(const char *p_string
, size_t i_length
)
114 char *psz_string
= malloc(i_length
+ 1);
115 memcpy(psz_string
, p_string
, i_length
);
116 psz_string
[i_length
] = '\0';
120 const char *psz_native_charset
= "UTF-8//IGNORE";
122 char *psi_iconv(void *_unused
, const char *psz_encoding
,
123 char *p_string
, size_t i_length
)
125 static const char *psz_current_encoding
= "";
127 char *psz_string
, *p
;
130 if (!strcmp(psz_encoding
, psz_native_charset
))
131 return iconv_append_null(p_string
, i_length
);
133 if (iconv_handle
!= (iconv_t
)-1 &&
134 strcmp(psz_encoding
, psz_current_encoding
)) {
135 iconv_close(iconv_handle
);
136 iconv_handle
= (iconv_t
)-1;
139 if (iconv_handle
== (iconv_t
)-1)
140 iconv_handle
= iconv_open(psz_native_charset
, psz_encoding
);
141 if (iconv_handle
== (iconv_t
)-1) {
142 msg_Warn(NULL
, "couldn't open converter from %s to %s (%m)", psz_encoding
,
144 return iconv_append_null(p_string
, i_length
);
146 psz_current_encoding
= psz_encoding
;
148 /* converted strings can be up to six times larger */
149 i_out_length
= i_length
* 6;
150 p
= psz_string
= malloc(i_out_length
);
151 if (iconv(iconv_handle
, &p_string
, &i_length
, &p
, &i_out_length
) == (size_t)-1) {
152 msg_Warn(NULL
, "couldn't convert from %s to %s (%m)", psz_encoding
,
155 return iconv_append_null(p_string
, i_length
);
158 msg_Warn(NULL
, "partial conversion from %s to %s", psz_encoding
,
165 void print_pids_header( void )
167 if ( i_print_type
== PRINT_XML
)
171 void print_pids_footer( void )
173 if ( i_print_type
== PRINT_XML
)
177 void print_pid(uint16_t i_pid
, ts_pid_info_t
*p_info
)
179 if ( p_info
->i_packets
== 0 )
181 if ( i_print_type
== PRINT_TEXT
)
182 printf("pid %d packn %lu ccerr %lu tserr %lu scramble %d Bps %lu seen %"PRId64
"\n",
186 p_info
->i_transport_errors
,
187 p_info
->i_scrambling
,
188 p_info
->i_bytes_per_sec
,
189 now
- p_info
->i_last_packet_ts
192 printf("<PID pid=\"%d\" packn=\"%lu\" ccerr=\"%lu\" tserr=\"%lu\" scramble=\"%d\" Bps=\"%lu\" seen=\"%"PRId64
"\" />\n",
196 p_info
->i_transport_errors
,
197 p_info
->i_scrambling
,
198 p_info
->i_bytes_per_sec
,
199 now
- p_info
->i_last_packet_ts
203 void print_pids( uint8_t *p_data
)
207 for ( i_pid
= 0; i_pid
< MAX_PIDS
; i_pid
++ ) {
208 ts_pid_info_t
*p_info
= (ts_pid_info_t
*)(p_data
+ i_pid
* sizeof(ts_pid_info_t
));
209 print_pid( i_pid
, p_info
);
214 void print_eit_events(uint8_t *p_eit
, f_print pf_print
, void *print_opaque
, f_iconv pf_iconv
, void *iconv_opaque
, print_type_t i_print_type
)
218 while ((p_event
= eit_get_event(p_eit
, j
)) != NULL
) {
221 int duration
, hour
, min
, sec
;
224 start_ts
= dvb_time_format_UTC(eitn_get_start_time(p_event
), NULL
, start_str
);
226 dvb_time_decode_bcd(eitn_get_duration_bcd(p_event
), &duration
, &hour
, &min
, &sec
);
228 switch (i_print_type
) {
230 pf_print(print_opaque
, "<EVENT id=\"%u\" start_time=\"%ld\" start_time_dec=\"%s\""
231 " duration=\"%u\" duration_dec=\"%u:%02u:%02u\""
232 " running=\"%d\" free_CA=\"%d\">",
233 eitn_get_event_id(p_event
),
235 duration
, hour
, min
, sec
,
236 eitn_get_running(p_event
),
241 pf_print(print_opaque
, " * EVENT id=%u start_time=%ld start_time_dec=\"%s\" duration=%u duration_dec=%u:%02u:%02u running=%d free_CA=%d",
242 eitn_get_event_id(p_event
),
244 duration
, hour
, min
, sec
,
245 eitn_get_running(p_event
),
250 descs_print(eitn_get_descs(p_event
), pf_print
, print_opaque
,
251 pf_iconv
, iconv_opaque
, i_print_type
);
253 switch (i_print_type
) {
255 pf_print(print_opaque
, "</EVENT>");
263 void print_eit(uint8_t *p_eit
, unsigned int i_eit_size
, f_print pf_print
, void *print_opaque
, f_iconv pf_iconv
, void *iconv_opaque
, print_type_t i_print_type
)
265 uint8_t *p_eit_end
= p_eit
+ i_eit_size
;
266 uint8_t i_tid
= psi_get_tableid(p_eit
);
267 const char *psz_tid
= "unknown";
269 if (i_tid
== EIT_TABLE_ID_PF_ACTUAL
)
270 psz_tid
= "actual_pf";
271 else if (i_tid
== EIT_TABLE_ID_PF_OTHER
)
272 psz_tid
= "other_pf";
273 else if (i_tid
>= EIT_TABLE_ID_SCHED_ACTUAL_FIRST
&& i_tid
<= EIT_TABLE_ID_SCHED_ACTUAL_LAST
)
274 psz_tid
= "actual_schedule";
275 else if (i_tid
>= EIT_TABLE_ID_SCHED_OTHER_FIRST
&& i_tid
<= EIT_TABLE_ID_SCHED_OTHER_LAST
)
276 psz_tid
= "other_schedule";
278 switch (i_print_type
) {
280 pf_print(print_opaque
,
281 "<EIT tableid=\"0x%02x\" type=\"%s\" service_id=\"%u\""
283 " current_next=\"%u\""
284 " tsid=\"%u\" onid=\"%u\">",
287 psi_get_version(p_eit
),
288 !psi_get_current(p_eit
) ? 0 : 1,
294 pf_print(print_opaque
,
295 "new EIT tableid=0x%02x type=%s service_id=%u version=%u%s"
300 psi_get_version(p_eit
),
301 !psi_get_current(p_eit
) ? " (next)" : "",
307 while (p_eit
< p_eit_end
) {
308 print_eit_events(p_eit
, pf_print
, print_opaque
, pf_iconv
, iconv_opaque
, i_print_type
);
309 p_eit
+= psi_get_length( p_eit
) + PSI_HEADER_SIZE
;
312 switch (i_print_type
) {
314 pf_print(print_opaque
, "</EIT>");
317 pf_print(print_opaque
, "end EIT");
321 struct dvblastctl_option
{
327 static const struct dvblastctl_option options
[] =
329 { "reload", 0, CMD_RELOAD
},
330 { "shutdown", 0, CMD_SHUTDOWN
},
332 { "fe_status", 0, CMD_FRONTEND_STATUS
},
333 { "mmi_status", 0, CMD_MMI_STATUS
},
335 { "mmi_slot_status", 1, CMD_MMI_SLOT_STATUS
}, /* arg: slot */
336 { "mmi_open", 1, CMD_MMI_OPEN
}, /* arg: slot */
337 { "mmi_close", 1, CMD_MMI_CLOSE
}, /* arg: slot */
338 { "mmi_get", 1, CMD_MMI_RECV
}, /* arg: slot */
339 { "mmi_send_text", 1, CMD_MMI_SEND_TEXT
}, /* arg: slot, en50221_mmi_object_t */
340 { "mmi_send_choice", 2, CMD_MMI_SEND_CHOICE
}, /* arg: slot, en50221_mmi_object_t */
342 { "get_pat", 0, CMD_GET_PAT
},
343 { "get_cat", 0, CMD_GET_CAT
},
344 { "get_nit", 0, CMD_GET_NIT
},
345 { "get_sdt", 0, CMD_GET_SDT
},
346 { "get_eit_pf", 1, CMD_GET_EIT_PF
}, /* arg: service_id (uint16_t) */
347 { "get_eit_schedule", 1, CMD_GET_EIT_SCHEDULE
}, /* arg: service_id (uint16_t) */
348 { "get_pmt", 1, CMD_GET_PMT
}, /* arg: service_id (uint16_t) */
349 { "get_pids", 0, CMD_GET_PIDS
},
350 { "get_pid", 1, CMD_GET_PID
}, /* arg: pid (uint16_t) */
357 printf("DVBlastctl %s (%s)\n", VERSION
, VERSION_EXTRA
);
358 printf("Usage: dvblastctl -r <remote socket> [-x <text|xml>] [cmd]\n");
359 printf("Options:\n");
360 printf(" -r --remote-socket <name> Set socket name to <name>.\n" );
361 printf(" -t --timeout <seconds> Set socket read/write timeout in seconds (default 15).\n" );
362 printf(" -j --system-charset <name> Character set used for output (default UTF-8//IGNORE)\n" );
363 printf(" -x --print <text|xml> Choose output format for info commands.\n" );
364 printf("Control commands:\n");
365 printf(" reload Reload configuration.\n");
366 printf(" shutdown Shutdown DVBlast.\n");
367 #ifdef HAVE_DVB_SUPPORT
368 printf("Status commands:\n");
369 printf(" fe_status Read frontend status information.\n");
370 printf(" mmi_status Read CAM status.\n");
371 printf("MMI commands:\n");
372 printf(" mmi_slot_status <slot> Read MMI slot status.\n");
373 printf(" mmi_open <slot> Open MMI slot.\n");
374 printf(" mmi_close <slot> Close MMI slot.\n");
375 printf(" mmi_get <slot> Read MMI slot.\n");
376 printf(" mmi_send_text <slot> <text> Send text to MMI slot.\n");
377 printf(" mmi_send_choice <slot> <choice> Send choice to MMI slot.\n");
379 printf("Demux info commands:\n");
380 printf(" get_pat Return last PAT table.\n");
381 printf(" get_cat Return last CAT table.\n");
382 printf(" get_nit Return last NIT table.\n");
383 printf(" get_sdt Return last SDT table.\n");
384 printf(" get_eit_pf <service_id> Return last EIT present/following data.\n");
385 printf(" get_eit_schedule <service_id> Return last EIT schedule data.\n");
386 printf(" get_pmt <service_id> Return last PMT table.\n");
387 printf(" get_pids Return info about all pids.\n");
388 printf(" get_pid <pid> Return info for chosen pid only.\n");
393 int main( int i_argc
, char **ppsz_argv
)
395 char *client_socket_tmpl
= "dvblastctl.clientsock.XXXXXX";
396 char *psz_srv_socket
= NULL
;
398 char *p_cmd
, *p_arg1
= NULL
, *p_arg2
= NULL
;
400 struct sockaddr_un sun_client
, sun_server
;
401 uint8_t p_buffer
[COMM_BUFFER_SIZE
];
402 uint8_t *p_data
= p_buffer
+ COMM_HEADER_SIZE
;
404 struct dvblastctl_option opt
= { 0, 0, 0 };
410 static const struct option long_options
[] =
412 {"remote-socket", required_argument
, NULL
, 'r'},
413 {"timeout", required_argument
, NULL
, 't'},
414 {"system-charset", required_argument
, NULL
, 'j'},
415 {"print", required_argument
, NULL
, 'x'},
416 {"help", no_argument
, NULL
, 'h'},
420 if ( (c
= getopt_long(i_argc
, ppsz_argv
, "r:t:x:j:h", long_options
, NULL
)) == -1 )
426 psz_srv_socket
= optarg
;
430 i_timeout_seconds
= (unsigned int)strtoul(optarg
, NULL
, 10);
434 psz_native_charset
= optarg
;
438 if ( !strcmp(optarg
, "text") )
439 i_print_type
= PRINT_TEXT
;
440 else if ( !strcmp(optarg
, "xml") )
441 i_print_type
= PRINT_XML
;
443 msg_Warn( NULL
, "unrecognized print type %s", optarg
);
444 /* Make stdout line-buffered */
445 setvbuf(stdout
, NULL
, _IOLBF
, 0);
454 /* Validate commands */
455 #define usage_error(msg, ...) \
457 msg_Err( NULL, msg, ##__VA_ARGS__ ); \
460 p_cmd
= ppsz_argv
[optind
];
461 p_arg1
= ppsz_argv
[optind
+ 1];
462 p_arg2
= ppsz_argv
[optind
+ 2];
464 if ( !psz_srv_socket
)
465 usage_error( "Remote socket is not set.\n" );
468 usage_error( "Command is not set.\n" );
472 if ( streq(ppsz_argv
[optind
], options
[i
].opt
) )
477 } while ( options
[++i
].opt
);
480 usage_error( "Unknown command: %s\n", p_cmd
);
482 if ( opt
.nparams
== 1 && !p_arg1
)
483 usage_error( "%s option needs parameter.\n", opt
.opt
);
485 if ( opt
.nparams
== 2 && (!p_arg1
|| !p_arg2
) )
486 usage_error( "%s option needs two parameters.\n", opt
.opt
);
489 /* Create client socket name */
490 char *tmpdir
= getenv("TMPDIR");
491 snprintf( psz_client_socket
, PATH_MAX
- 1, "%s/%s",
492 tmpdir
? tmpdir
: "/tmp", client_socket_tmpl
);
493 psz_client_socket
[PATH_MAX
- 1] = '\0';
495 int tmp_fd
= mkstemp(psz_client_socket
);
498 unlink(psz_client_socket
);
500 return_error( "Cannot build UNIX socket %s (%s)", psz_client_socket
, strerror(errno
) );
503 if ( (i_fd
= socket( AF_UNIX
, SOCK_DGRAM
, 0 )) < 0 )
504 return_error( "Cannot create UNIX socket (%s)", strerror(errno
) );
506 i
= COMM_MAX_MSG_CHUNK
;
507 setsockopt( i_fd
, SOL_SOCKET
, SO_RCVBUF
, &i
, sizeof(i
) );
509 memset( &sun_client
, 0, sizeof(sun_client
) );
510 sun_client
.sun_family
= AF_UNIX
;
511 strncpy( sun_client
.sun_path
, psz_client_socket
,
512 sizeof(sun_client
.sun_path
) );
513 sun_client
.sun_path
[sizeof(sun_client
.sun_path
) - 1] = '\0';
515 if ( bind( i_fd
, (struct sockaddr
*)&sun_client
,
516 SUN_LEN(&sun_client
) ) < 0 )
517 return_error( "Cannot bind (%s)", strerror(errno
) );
519 memset( &sun_server
, 0, sizeof(sun_server
) );
520 sun_server
.sun_family
= AF_UNIX
;
521 strncpy( sun_server
.sun_path
, psz_srv_socket
, sizeof(sun_server
.sun_path
) );
522 sun_server
.sun_path
[sizeof(sun_server
.sun_path
) - 1] = '\0';
524 p_buffer
[0] = COMM_HEADER_MAGIC
;
525 p_buffer
[1] = opt
.cmd
;
526 memset( p_buffer
+ 2, 0, COMM_HEADER_SIZE
- 2 );
527 i_size
= COMM_HEADER_SIZE
;
529 /* Handle commands that send parameters */
535 case CMD_FRONTEND_STATUS
:
542 /* These commands need no special handling because they have no parameters */
545 case CMD_GET_EIT_SCHEDULE
:
548 uint16_t i_sid
= atoi(p_arg1
);
549 i_size
= COMM_HEADER_SIZE
+ 2;
550 p_data
[0] = (uint8_t)((i_sid
>> 8) & 0xff);
551 p_data
[1] = (uint8_t)(i_sid
& 0xff);
556 i_pid
= (uint16_t)atoi(p_arg1
);
557 i_size
= COMM_HEADER_SIZE
+ 2;
558 p_data
[0] = (uint8_t)((i_pid
>> 8) & 0xff);
559 p_data
[1] = (uint8_t)(i_pid
& 0xff);
562 #ifdef HAVE_DVB_SUPPORT
563 case CMD_MMI_SEND_TEXT
:
565 struct cmd_mmi_send
*p_cmd
= (struct cmd_mmi_send
*)p_data
;
566 p_cmd
->i_slot
= atoi(p_arg1
);
568 en50221_mmi_object_t object
;
569 object
.i_object_type
= EN50221_MMI_ANSW
;
570 if ( !p_arg2
|| p_arg2
[0] == '\0' )
572 object
.u
.answ
.b_ok
= 0;
573 object
.u
.answ
.psz_answ
= "";
577 object
.u
.answ
.b_ok
= 1;
578 object
.u
.answ
.psz_answ
= p_arg2
;
580 i_size
= COMM_BUFFER_SIZE
- COMM_HEADER_SIZE
581 - ((void *)&p_cmd
->object
- (void *)p_cmd
);
582 if ( en50221_SerializeMMIObject( (uint8_t *)&p_cmd
->object
,
583 &i_size
, &object
) == -1 )
584 return_error( "Comm buffer is too small" );
586 i_size
+= COMM_HEADER_SIZE
587 + ((void *)&p_cmd
->object
- (void *)p_cmd
);
590 case CMD_MMI_SEND_CHOICE
:
592 struct cmd_mmi_send
*p_cmd
= (struct cmd_mmi_send
*)p_data
;
593 p_cmd
->i_slot
= atoi(p_arg1
);
595 i_size
= COMM_HEADER_SIZE
+ sizeof(struct cmd_mmi_send
);
596 p_cmd
->object
.i_object_type
= EN50221_MMI_MENU_ANSW
;
597 p_cmd
->object
.u
.menu_answ
.i_choice
= atoi(p_arg2
);
600 case CMD_MMI_SLOT_STATUS
:
605 p_data
[0] = atoi(p_arg1
);
606 i_size
= COMM_HEADER_SIZE
+ 1;
611 /* This should not happen */
612 return_error( "Unhandled option (%d)", opt
.cmd
);
615 if ( i_timeout_seconds
> 0 ) {
616 struct timeval tv_timeout
= {
617 .tv_sec
= i_timeout_seconds
,
620 if ( setsockopt( i_fd
, SOL_SOCKET
, SO_SNDTIMEO
, &tv_timeout
, sizeof( tv_timeout
) ) != 0 )
621 return_error( "Cannot set SO_SNDTIMEO (%s)", strerror(errno
) );
623 if ( setsockopt( i_fd
, SOL_SOCKET
, SO_RCVTIMEO
, &tv_timeout
, sizeof( tv_timeout
) ) != 0 )
624 return_error( "Cannot set SO_RCVTIMEO (%s)", strerror(errno
) );
627 /* Send command and receive answer */
628 if ( sendto( i_fd
, p_buffer
, i_size
, 0, (struct sockaddr
*)&sun_server
,
629 SUN_LEN(&sun_server
) ) < 0 )
630 return_error( "Cannot send comm socket (%s)", strerror(errno
) );
632 uint32_t i_packet_size
= 0, i_received
= 0;
634 i_size
= recv( i_fd
, p_buffer
+ i_received
, COMM_MAX_MSG_CHUNK
, 0 );
637 if ( !i_packet_size
) {
638 uint32_t *p_packet_size
= (uint32_t *)&p_buffer
[4];
639 i_packet_size
= *p_packet_size
;
640 if ( i_packet_size
> COMM_BUFFER_SIZE
) {
645 i_received
+= i_size
;
646 } while ( i_received
< i_packet_size
);
648 clean_client_socket();
649 if ( i_packet_size
< COMM_HEADER_SIZE
)
650 return_error( "Cannot recv from comm socket, size:%"PRIu32
" (%s)", i_packet_size
, strerror(errno
) );
653 if ( p_buffer
[0] != COMM_HEADER_MAGIC
)
654 return_error( "Wrong protocol version 0x%x", p_buffer
[0] );
658 ctl_cmd_answer_t c_answer
= p_buffer
[1];
669 return_error( "Request failed" );
673 return_error( "Internal error" );
677 return_error( "No data" );
685 uint8_t *p_flat_data
= p_buffer
+ COMM_HEADER_SIZE
;
686 unsigned int i_flat_data_size
= i_packet_size
- COMM_HEADER_SIZE
;
687 uint8_t **pp_sections
= psi_unpack_sections( p_flat_data
, i_flat_data_size
);
690 return_error( "Error unpacking PSI" );
696 case RET_PAT
: pat_table_print( pp_sections
, psi_print
, NULL
, i_print_type
); break;
697 case RET_CAT
: cat_table_print( pp_sections
, psi_print
, NULL
, i_print_type
); break;
698 case RET_NIT
: nit_table_print( pp_sections
, psi_print
, NULL
, psi_iconv
, NULL
, i_print_type
); break;
699 case RET_SDT
: sdt_table_print( pp_sections
, psi_print
, NULL
, psi_iconv
, NULL
, i_print_type
); break;
700 default: break; /* Can't happen */
703 psi_table_free( pp_sections
);
709 case RET_EIT_SCHEDULE
:
711 uint8_t *p_eit_data
= p_buffer
+ COMM_HEADER_SIZE
;
712 unsigned int i_eit_data_size
= i_received
- COMM_HEADER_SIZE
;
713 print_eit( p_eit_data
, i_eit_data_size
, psi_print
, NULL
, psi_iconv
, NULL
, i_print_type
);
719 pmt_print( p_data
, psi_print
, NULL
, psi_iconv
, NULL
, i_print_type
);
726 print_pid( i_pid
, (ts_pid_info_t
*)p_data
);
733 print_pids( p_data
);
737 #ifdef HAVE_DVB_SUPPORT
738 case RET_FRONTEND_STATUS
:
741 struct ret_frontend_status
*p_ret
=
742 (struct ret_frontend_status
*)&p_buffer
[COMM_HEADER_SIZE
];
743 if ( i_packet_size
!= COMM_HEADER_SIZE
+ sizeof(struct ret_frontend_status
) )
744 return_error( "Bad frontend status" );
746 if ( i_print_type
== PRINT_XML
)
747 printf("<FRONTEND>\n");
749 #define PRINT_TYPE( x ) \
751 if ( i_print_type == PRINT_XML ) \
752 printf( " <TYPE type=\"%s\"/>\n", STRINGIFY(x) ); \
754 printf( "type: %s\n", STRINGIFY(x) ); \
756 switch ( p_ret
->info
.type
)
758 case FE_QPSK
: PRINT_TYPE(QPSK
); break;
759 case FE_QAM
: PRINT_TYPE(QAM
); break;
760 case FE_OFDM
: PRINT_TYPE(OFDM
); break;
761 case FE_ATSC
: PRINT_TYPE(ATSC
); break;
762 default : PRINT_TYPE(UNKNOWN
); break;
766 #define PRINT_INFO( x ) \
768 if ( i_print_type == PRINT_XML ) \
769 printf( " <SETTING %s=\"%u\"/>\n", STRINGIFY(x), p_ret->info.x ); \
771 printf( "%s: %u\n", STRINGIFY(x), p_ret->info.x ); \
774 if ( i_print_type
== PRINT_XML
)
775 printf( " <SETTING name=\"%s\"/>\n", p_ret
->info
.name
);
777 printf( "name: %s\n", p_ret
->info
.name
);
779 PRINT_INFO( frequency_min
);
780 PRINT_INFO( frequency_max
);
781 PRINT_INFO( frequency_stepsize
);
782 PRINT_INFO( frequency_tolerance
);
783 PRINT_INFO( symbol_rate_min
);
784 PRINT_INFO( symbol_rate_max
);
785 PRINT_INFO( symbol_rate_tolerance
);
786 PRINT_INFO( notifier_delay
);
789 if ( i_print_type
== PRINT_TEXT
)
790 printf("\ncapability list:\n");
792 #define PRINT_CAPS( x ) \
794 if ( p_ret->info.caps & (FE_##x) ) { \
795 if ( i_print_type == PRINT_XML ) { \
796 printf( " <CAPABILITY %s=\"1\"/>\n", STRINGIFY(x) ); \
798 printf( "%s\n", STRINGIFY(x) ); \
802 PRINT_CAPS( IS_STUPID
);
803 PRINT_CAPS( CAN_INVERSION_AUTO
);
804 PRINT_CAPS( CAN_FEC_1_2
);
805 PRINT_CAPS( CAN_FEC_2_3
);
806 PRINT_CAPS( CAN_FEC_3_4
);
807 PRINT_CAPS( CAN_FEC_4_5
);
808 PRINT_CAPS( CAN_FEC_5_6
);
809 PRINT_CAPS( CAN_FEC_6_7
);
810 PRINT_CAPS( CAN_FEC_7_8
);
811 PRINT_CAPS( CAN_FEC_8_9
);
812 PRINT_CAPS( CAN_FEC_AUTO
);
813 PRINT_CAPS( CAN_QPSK
);
814 PRINT_CAPS( CAN_QAM_16
);
815 PRINT_CAPS( CAN_QAM_32
);
816 PRINT_CAPS( CAN_QAM_64
);
817 PRINT_CAPS( CAN_QAM_128
);
818 PRINT_CAPS( CAN_QAM_256
);
819 PRINT_CAPS( CAN_QAM_AUTO
);
820 PRINT_CAPS( CAN_TRANSMISSION_MODE_AUTO
);
821 PRINT_CAPS( CAN_BANDWIDTH_AUTO
);
822 PRINT_CAPS( CAN_GUARD_INTERVAL_AUTO
);
823 PRINT_CAPS( CAN_HIERARCHY_AUTO
);
824 PRINT_CAPS( CAN_MUTE_TS
);
826 #if DVBAPI_VERSION >= 301
827 PRINT_CAPS( CAN_8VSB
);
828 PRINT_CAPS( CAN_16VSB
);
829 PRINT_CAPS( NEEDS_BENDING
);
830 PRINT_CAPS( CAN_RECOVER
);
832 #if DVBAPI_VERSION >= 500
833 PRINT_CAPS( HAS_EXTENDED_CAPS
);
835 #if DVBAPI_VERSION >= 501
836 PRINT_CAPS( CAN_2G_MODULATION
);
838 #if DVBAPI_VERSION >= 508
839 PRINT_CAPS( CAN_TURBO_FEC
);
840 PRINT_CAPS( CAN_MULTISTREAM
);
844 if ( i_print_type
== PRINT_TEXT
)
845 printf("\nstatus:\n");
847 #define PRINT_STATUS( x ) \
849 if ( p_ret->i_status & (FE_##x) ) { \
850 if ( i_print_type == PRINT_XML ) { \
851 printf( " <STATUS status=\"%s\"/>\n", STRINGIFY(x) ); \
853 printf( "%s\n", STRINGIFY(x) ); \
857 PRINT_STATUS( HAS_SIGNAL
);
858 PRINT_STATUS( HAS_CARRIER
);
859 PRINT_STATUS( HAS_VITERBI
);
860 PRINT_STATUS( HAS_SYNC
);
861 PRINT_STATUS( HAS_LOCK
);
862 PRINT_STATUS( REINIT
);
865 if ( p_ret
->i_status
& FE_HAS_LOCK
)
867 if ( i_print_type
== PRINT_XML
)
869 printf(" <VALUE bit_error_rate=\"%u\"/>\n", p_ret
->i_ber
);
870 printf(" <VALUE signal_strength=\"%u\"/>\n", p_ret
->i_strength
);
871 printf(" <VALUE SNR=\"%u\"/>\n", p_ret
->i_snr
);
873 printf("\nBit error rate: %u\n", p_ret
->i_ber
);
874 printf("Signal strength: %u\n", p_ret
->i_strength
);
875 printf("SNR: %u\n", p_ret
->i_snr
);
880 if ( i_print_type
== PRINT_XML
)
881 printf("</FRONTEND>\n" );
889 struct ret_mmi_status
*p_ret
=
890 (struct ret_mmi_status
*)&p_buffer
[COMM_HEADER_SIZE
];
891 if ( i_packet_size
!= COMM_HEADER_SIZE
+ sizeof(struct ret_mmi_status
) )
892 return_error( "Bad MMI status" );
894 printf("CA interface with %d %s, type:\n", p_ret
->caps
.slot_num
,
895 p_ret
->caps
.slot_num
== 1 ? "slot" : "slots");
896 #define PRINT_CAPS( x, s ) \
897 if ( p_ret->caps.slot_type & (CA_##x) ) \
899 PRINT_CAPS( CI
, "CI high level interface" );
900 PRINT_CAPS( CI_LINK
, "CI link layer level interface" );
901 PRINT_CAPS( CI_PHYS
, "CI physical layer level interface (not supported)" );
902 PRINT_CAPS( DESCR
, "built-in descrambler" );
903 PRINT_CAPS( SC
, "simple smartcard interface" );
906 printf("\n%d available %s\n", p_ret
->caps
.descr_num
,
907 p_ret
->caps
.descr_num
== 1 ? "descrambler (key)" :
908 "descramblers (keys)");
909 #define PRINT_DESC( x ) \
910 if ( p_ret->caps.descr_type & (CA_##x) ) \
911 printf( STRINGIFY(x) "\n" );
917 exit( p_ret
->caps
.slot_num
);
921 case RET_MMI_SLOT_STATUS
:
923 struct ret_mmi_slot_status
*p_ret
=
924 (struct ret_mmi_slot_status
*)&p_buffer
[COMM_HEADER_SIZE
];
925 if ( i_packet_size
< COMM_HEADER_SIZE
+ sizeof(struct ret_mmi_slot_status
) )
926 return_error( "Bad MMI slot status" );
928 printf("CA slot #%u: ", p_ret
->sinfo
.num
);
930 #define PRINT_TYPE( x, s ) \
931 if ( p_ret->sinfo.type & (CA_##x) ) \
934 PRINT_TYPE( CI
, "high level, " );
935 PRINT_TYPE( CI_LINK
, "link layer level, " );
936 PRINT_TYPE( CI_PHYS
, "physical layer level, " );
939 if ( p_ret
->sinfo
.flags
& CA_CI_MODULE_READY
)
941 printf("module present and ready\n");
945 if ( p_ret
->sinfo
.flags
& CA_CI_MODULE_PRESENT
)
946 printf("module present, not ready\n");
948 printf("module not present\n");
956 struct ret_mmi_recv
*p_ret
=
957 (struct ret_mmi_recv
*)&p_buffer
[COMM_HEADER_SIZE
];
958 if ( i_packet_size
< COMM_HEADER_SIZE
+ sizeof(struct ret_mmi_recv
) )
959 return_error( "Bad MMI recv" );
961 en50221_UnserializeMMIObject( &p_ret
->object
, i_packet_size
962 - COMM_HEADER_SIZE
- ((void *)&p_ret
->object
- (void *)p_ret
) );
964 switch ( p_ret
->object
.i_object_type
)
966 case EN50221_MMI_ENQ
:
967 printf("%s\n", p_ret
->object
.u
.enq
.psz_text
);
968 printf("(empty to cancel)\n");
969 exit(p_ret
->object
.u
.enq
.b_blind
? 253 : 254);
972 case EN50221_MMI_MENU
:
973 printf("%s\n", p_ret
->object
.u
.menu
.psz_title
);
974 printf("%s\n", p_ret
->object
.u
.menu
.psz_subtitle
);
975 printf("0 - Cancel\n");
976 for ( i
= 0; i
< p_ret
->object
.u
.menu
.i_choices
; i
++ )
977 printf("%d - %s\n", i
+ 1,
978 p_ret
->object
.u
.menu
.ppsz_choices
[i
]);
979 printf("%s\n", p_ret
->object
.u
.menu
.psz_bottom
);
980 exit(p_ret
->object
.u
.menu
.i_choices
);
983 case EN50221_MMI_LIST
:
984 printf("%s\n", p_ret
->object
.u
.menu
.psz_title
);
985 printf("%s\n", p_ret
->object
.u
.menu
.psz_subtitle
);
986 for ( i
= 0; i
< p_ret
->object
.u
.menu
.i_choices
; i
++ )
987 printf("%s\n", p_ret
->object
.u
.menu
.ppsz_choices
[i
]);
988 printf("%s\n", p_ret
->object
.u
.menu
.psz_bottom
);
989 printf("(0 to cancel)\n");
994 return_error( "Unknown MMI object" );
1004 return_error( "Unknown command answer: %u", c_answer
);
1007 if (iconv_handle
!= (iconv_t
)-1) {
1008 iconv_close(iconv_handle
);
1009 iconv_handle
= (iconv_t
)-1;