mirror of
https://github.com/DigitalDevices/dddvb.git
synced 2023-10-10 13:37:43 +02:00
Bodo patches
This commit is contained in:
parent
e5e6e44b76
commit
8b787bbc0d
53
lib/src/ca.c
53
lib/src/ca.c
@ -14,9 +14,11 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <sys/un.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include <net/ethernet.h>
|
#include <net/ethernet.h>
|
||||||
@ -66,6 +68,32 @@ int streamsock(const char *port, int family, struct sockaddr *sadr)
|
|||||||
return sock;
|
return sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int unixsock(const char *path)
|
||||||
|
{
|
||||||
|
unlink(path);
|
||||||
|
|
||||||
|
struct sockaddr_un sa;
|
||||||
|
size_t hlen = offsetof(struct sockaddr_un, sun_path);
|
||||||
|
size_t pathlen = strlen(path);
|
||||||
|
if (pathlen > sizeof(sa.sun_path))
|
||||||
|
return(-1);
|
||||||
|
memset(&sa, 0, hlen);
|
||||||
|
sa.sun_family = AF_UNIX;
|
||||||
|
if (pathlen > 0)
|
||||||
|
memcpy(sa.sun_path, path, pathlen);
|
||||||
|
|
||||||
|
int sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
|
if (sock == -1)
|
||||||
|
return(-1);
|
||||||
|
|
||||||
|
if (bind(sock, (struct sockaddr *) &sa, (socklen_t) (hlen + pathlen)) == -1) {
|
||||||
|
close(sock);
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(sock);
|
||||||
|
}
|
||||||
|
|
||||||
static int ai_callback(void *arg, uint8_t slot_id, uint16_t session_number,
|
static int ai_callback(void *arg, uint8_t slot_id, uint16_t session_number,
|
||||||
uint8_t application_type, uint16_t application_manufacturer,
|
uint8_t application_type, uint16_t application_manufacturer,
|
||||||
uint16_t manufacturer_code, uint8_t menu_string_length,
|
uint16_t manufacturer_code, uint8_t menu_string_length,
|
||||||
@ -357,10 +385,17 @@ static void handle_ci(struct dddvb_ca *ca)
|
|||||||
int len;
|
int len;
|
||||||
int sock, i;
|
int sock, i;
|
||||||
struct sockaddr sadr;
|
struct sockaddr sadr;
|
||||||
char port[6];
|
char port[6], path[32];
|
||||||
|
|
||||||
|
if (ca->dd->cam_family == 1) {
|
||||||
snprintf(port, sizeof(port), "%u", (uint16_t) (8888 + ca->nr));
|
snprintf(port, sizeof(port), "%u", (uint16_t) (8888 + ca->nr));
|
||||||
sock = streamsock(port, AF_INET, &sadr);
|
sock = streamsock(port, AF_INET, &sadr);
|
||||||
|
} else if (ca->dd->cam_family == 2) {
|
||||||
|
snprintf(path, sizeof(path), "/var/run/resiplayer/cam%u", ca->nr);
|
||||||
|
sock = unixsock(path);
|
||||||
|
} else {
|
||||||
|
sock = -1;
|
||||||
|
}
|
||||||
if (listen(sock, 4) < 0) {
|
if (listen(sock, 4) < 0) {
|
||||||
dbgprintf(DEBUG_CA, "listen error");
|
dbgprintf(DEBUG_CA, "listen error");
|
||||||
return;
|
return;
|
||||||
@ -466,6 +501,8 @@ static int mmi_close_callback(void *arg, uint8_t slot_id, uint16_t snum,
|
|||||||
struct dddvb_ca *ca = arg;
|
struct dddvb_ca *ca = arg;
|
||||||
|
|
||||||
ca->mmi_state = MMI_STATE_CLOSED;
|
ca->mmi_state = MMI_STATE_CLOSED;
|
||||||
|
if (ca->dd->cam_proto == 2)
|
||||||
|
sendstringx(ca->sock, "CLOSE", 0, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -492,6 +529,8 @@ static int mmi_display_control_callback(void *arg, uint8_t slot_id, uint16_t snu
|
|||||||
en50221_app_mmi_display_reply(ca->stdcam->mmi_resource, snum,
|
en50221_app_mmi_display_reply(ca->stdcam->mmi_resource, snum,
|
||||||
MMI_DISPLAY_REPLY_ID_MMI_MODE_ACK, &reply);
|
MMI_DISPLAY_REPLY_ID_MMI_MODE_ACK, &reply);
|
||||||
ca->mmi_state = MMI_STATE_OPEN;
|
ca->mmi_state = MMI_STATE_OPEN;
|
||||||
|
if (ca->dd->cam_proto == 2)
|
||||||
|
sendstringx(ca->sock, "OPEN", 0, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -502,7 +541,10 @@ static int mmi_enq_callback(void *arg, uint8_t slot_id, uint16_t snum,
|
|||||||
struct dddvb_ca *ca = arg;
|
struct dddvb_ca *ca = arg;
|
||||||
|
|
||||||
if (ca->sock >= 0) {
|
if (ca->sock >= 0) {
|
||||||
|
if (ca->dd->cam_proto == 1)
|
||||||
sendstring(ca->sock, "%.*s: ", text_size, text);
|
sendstring(ca->sock, "%.*s: ", text_size, text);
|
||||||
|
if (ca->dd->cam_proto == 2)
|
||||||
|
sendstringx(ca->sock, "ENQ", text_size, text);
|
||||||
}
|
}
|
||||||
//mmi_enq_blind = blind_answer;
|
//mmi_enq_blind = blind_answer;
|
||||||
//mmi_enq_length = expected_answer_length;
|
//mmi_enq_length = expected_answer_length;
|
||||||
@ -520,7 +562,7 @@ static int mmi_menu_callback(void *arg, uint8_t slot_id, uint16_t snum,
|
|||||||
uint32_t i;
|
uint32_t i;
|
||||||
struct dddvb_ca *ca = arg;
|
struct dddvb_ca *ca = arg;
|
||||||
|
|
||||||
if (ca->sock >= 0) {
|
if ((ca->sock >= 0) && (ca->dd->cam_proto == 1)) {
|
||||||
if (title->text_length)
|
if (title->text_length)
|
||||||
sendstring(ca->sock, "%.*s\n", title->text_length, title->text);
|
sendstring(ca->sock, "%.*s\n", title->text_length, title->text);
|
||||||
if (sub_title->text_length)
|
if (sub_title->text_length)
|
||||||
@ -530,6 +572,13 @@ static int mmi_menu_callback(void *arg, uint8_t slot_id, uint16_t snum,
|
|||||||
if (bottom->text_length)
|
if (bottom->text_length)
|
||||||
sendstring(ca->sock, "%.*s\n", bottom->text_length, bottom->text);
|
sendstring(ca->sock, "%.*s\n", bottom->text_length, bottom->text);
|
||||||
}
|
}
|
||||||
|
if (ca->dd->cam_proto == 2) {
|
||||||
|
sendstringx(ca->sock, "MENU", title->text_length, title->text);
|
||||||
|
sendstringx(ca->sock, "MSUB", sub_title->text_length, sub_title->text);
|
||||||
|
for (i = 0; i < item_count; i++)
|
||||||
|
sendstringx(ca->sock, "ITEM", items[i].text_length, items[i].text);
|
||||||
|
sendstringx(ca->sock, "MEND", bottom->text_length, bottom->text);
|
||||||
|
}
|
||||||
ca->mmi_state = MMI_STATE_MENU;
|
ca->mmi_state = MMI_STATE_MENU;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -152,6 +152,9 @@ struct dddvb {
|
|||||||
struct dddvb_fe dvbfe[DDDVB_MAX_DVB_FE];
|
struct dddvb_fe dvbfe[DDDVB_MAX_DVB_FE];
|
||||||
struct dddvb_ca dvbca[DDDVB_MAX_DVB_CA];
|
struct dddvb_ca dvbca[DDDVB_MAX_DVB_CA];
|
||||||
|
|
||||||
|
unsigned int cam_family;
|
||||||
|
unsigned int cam_proto;
|
||||||
|
unsigned int cam_port;
|
||||||
|
|
||||||
unsigned int get_ts:1;
|
unsigned int get_ts:1;
|
||||||
};
|
};
|
||||||
|
@ -954,6 +954,31 @@ void lnb_config(struct dddvb *dd, char *name, char *val)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ca_config(struct dddvb *dd, char *name, char *val)
|
||||||
|
{
|
||||||
|
if (!name || !val)
|
||||||
|
return;
|
||||||
|
char *p = strpbrk(val, "\r\n");
|
||||||
|
if (p)
|
||||||
|
*p = 0;
|
||||||
|
if (!strcasecmp(name, "family")) {
|
||||||
|
if (!strcasecmp(val, "tcp")) {
|
||||||
|
dd->cam_family = 1;
|
||||||
|
} else if (!strcasecmp(val, "unix")) {
|
||||||
|
dd->cam_family = 2;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!strcasecmp(name, "proto")) {
|
||||||
|
dd->cam_proto = strtoul(val, NULL, 10);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!strcasecmp(name, "port")) {
|
||||||
|
dd->cam_port = strtoul(val, NULL, 10);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int dddvb_dvb_init(struct dddvb *dd)
|
int dddvb_dvb_init(struct dddvb *dd)
|
||||||
{
|
{
|
||||||
pthread_mutex_init(&dd->uni_lock, 0);
|
pthread_mutex_init(&dd->uni_lock, 0);
|
||||||
@ -961,6 +986,23 @@ int dddvb_dvb_init(struct dddvb *dd)
|
|||||||
parse_config(dd, "", "scif", &scif_config);
|
parse_config(dd, "", "scif", &scif_config);
|
||||||
set_lnb(dd, 0, 0, 9750000, 10600000, 11700000);
|
set_lnb(dd, 0, 0, 9750000, 10600000, 11700000);
|
||||||
parse_config(dd, "", "LNB", &lnb_config);
|
parse_config(dd, "", "LNB", &lnb_config);
|
||||||
|
parse_config(dd, "", "CA", &ca_config);
|
||||||
|
{
|
||||||
|
if (dd->cam_family == 0)
|
||||||
|
dd->cam_family = 1;
|
||||||
|
if (dd->cam_proto == 0) {
|
||||||
|
switch (dd->cam_family) {
|
||||||
|
case 1:
|
||||||
|
dd->cam_proto = 1;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
dd->cam_proto = 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dd->cam_port == 0)
|
||||||
|
dd->cam_port = 8888;
|
||||||
|
}
|
||||||
scan_dvbca(dd);
|
scan_dvbca(dd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
int sendlen(int sock, char *buf, int len)
|
int sendlen(int sock, char *buf, int len)
|
||||||
@ -33,6 +34,34 @@ int sendstring(int sock, char *fmt, ...)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sendstringx(int sock, const char *label, uint32_t text_length, const uint8_t *text)
|
||||||
|
{
|
||||||
|
if (sock < 0)
|
||||||
|
return(-1);
|
||||||
|
|
||||||
|
uint8_t buf[strlen(label) + 1 + text_length * 3 + 2];
|
||||||
|
|
||||||
|
strcpy(buf, label);
|
||||||
|
int len = strlen(buf);
|
||||||
|
buf[len++] = 0x20;
|
||||||
|
while (text_length--) {
|
||||||
|
int c = *text++;
|
||||||
|
if (c == 0x5C) {
|
||||||
|
buf[len++] = 0x5C;
|
||||||
|
buf[len++] = 0x5C;
|
||||||
|
} else if ((c < 0x20) || (c > 0x7E)) {
|
||||||
|
buf[len++] = 0x5C;
|
||||||
|
snprintf(buf+len, 3, "%02X", c);
|
||||||
|
len += 2;
|
||||||
|
} else {
|
||||||
|
buf[len++] = (uint8_t) c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buf[len++] = 0x0A;
|
||||||
|
sendlen(sock, buf, len);
|
||||||
|
return(len);
|
||||||
|
}
|
||||||
|
|
||||||
time_t mtime(time_t *t)
|
time_t mtime(time_t *t)
|
||||||
{
|
{
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
|
@ -4,5 +4,6 @@
|
|||||||
time_t mtime(time_t *t);
|
time_t mtime(time_t *t);
|
||||||
int sendlen(int sock, char *buf, int len);
|
int sendlen(int sock, char *buf, int len);
|
||||||
int sendstring(int sock, char *fmt, ...);
|
int sendstring(int sock, char *fmt, ...);
|
||||||
|
int sendstringx(int sock, const char *label, uint32_t text_length, const uint8_t *text);
|
||||||
|
|
||||||
#endif /* _DDDVB_TOOLS_H_ */
|
#endif /* _DDDVB_TOOLS_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user