1
0
mirror of https://github.com/DigitalDevices/dddvb.git synced 2023-10-10 13:37:43 +02:00

Bodo patches

This commit is contained in:
none 2021-02-03 18:03:51 +01:00
parent e5e6e44b76
commit 8b787bbc0d
5 changed files with 128 additions and 4 deletions

View File

@ -14,9 +14,11 @@
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <stddef.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netdb.h>
#include <net/if.h>
#include <net/ethernet.h>
@ -66,6 +68,32 @@ int streamsock(const char *port, int family, struct sockaddr *sadr)
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,
uint8_t application_type, uint16_t application_manufacturer,
uint16_t manufacturer_code, uint8_t menu_string_length,
@ -357,10 +385,17 @@ static void handle_ci(struct dddvb_ca *ca)
int len;
int sock, i;
struct sockaddr sadr;
char port[6];
char port[6], path[32];
snprintf(port, sizeof(port), "%u", (uint16_t) (8888 + ca->nr));
sock = streamsock(port, AF_INET, &sadr);
if (ca->dd->cam_family == 1) {
snprintf(port, sizeof(port), "%u", (uint16_t) (8888 + ca->nr));
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) {
dbgprintf(DEBUG_CA, "listen error");
return;
@ -466,6 +501,8 @@ static int mmi_close_callback(void *arg, uint8_t slot_id, uint16_t snum,
struct dddvb_ca *ca = arg;
ca->mmi_state = MMI_STATE_CLOSED;
if (ca->dd->cam_proto == 2)
sendstringx(ca->sock, "CLOSE", 0, NULL);
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,
MMI_DISPLAY_REPLY_ID_MMI_MODE_ACK, &reply);
ca->mmi_state = MMI_STATE_OPEN;
if (ca->dd->cam_proto == 2)
sendstringx(ca->sock, "OPEN", 0, NULL);
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;
if (ca->sock >= 0) {
if (ca->dd->cam_proto == 1)
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_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;
struct dddvb_ca *ca = arg;
if (ca->sock >= 0) {
if ((ca->sock >= 0) && (ca->dd->cam_proto == 1)) {
if (title->text_length)
sendstring(ca->sock, "%.*s\n", title->text_length, title->text);
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)
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;
return 0;
}

View File

@ -152,6 +152,9 @@ struct dddvb {
struct dddvb_fe dvbfe[DDDVB_MAX_DVB_FE];
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;
};

View File

@ -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)
{
pthread_mutex_init(&dd->uni_lock, 0);
@ -961,6 +986,23 @@ int dddvb_dvb_init(struct dddvb *dd)
parse_config(dd, "", "scif", &scif_config);
set_lnb(dd, 0, 0, 9750000, 10600000, 11700000);
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);
}

View File

@ -4,6 +4,7 @@
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
int sendlen(int sock, char *buf, int len)
@ -33,6 +34,34 @@ int sendstring(int sock, char *fmt, ...)
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)
{
struct timespec ts;

View File

@ -4,5 +4,6 @@
time_t mtime(time_t *t);
int sendlen(int sock, char *buf, int len);
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_ */