Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple UUID generation from SSDP discovery #1140

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions src/minisatip.c
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,9 @@ void set_options(int argc, char *argv[]) {
// FBC setup
if (!access("/proc/stb/frontend/0/fbc_connect", W_OK))
set_slave_adapters("2-7:0");

// Generate the static SAT>IP UUID
generate_uuid(&opts);
}

#define RBUF 32000
Expand Down Expand Up @@ -1434,10 +1437,6 @@ int read_rtsp(sockets *s) {

#define JSON_STATE_MAXLEN (256 * 1024)

char uuid[50];
int uuidi;
USockAddr ssdp_sa;

int read_http(sockets *s) {
char *arg[50];
char buf[2000]; // the XML should not be larger than 1400 as it will create
Expand Down Expand Up @@ -1547,7 +1546,7 @@ int read_http(sockets *s) {
if (strncmp(arg[0], "GET", 3) && strncmp(arg[0], "POST", 4) && !is_head)
REPLY_AND_RETURN(503);

if (uuidi == 0 && !opts.disable_ssdp)
if (!opts.disable_ssdp)
ssdp_discovery(s);

if (strcmp(arg[1], "/" DESC_XML) == 0) {
Expand Down Expand Up @@ -1577,7 +1576,7 @@ int read_http(sockets *s) {
strcpy(adapters, "DVBS2-0,");
adapters[strlen(adapters) - 1] = 0;
snprintf(buf, sizeof(buf), xml, opts.name_app, app_name, opts.name_app,
uuid, opts.http_host, adapters,
opts.uuid, opts.http_host, adapters,
opts.playlist ? opts.playlist : "");
sprintf(headers,
"Cache-Control: no-cache\r\nContent-type: "
Expand Down Expand Up @@ -1669,23 +1668,19 @@ int close_http(sockets *s) {
#define DEFAULT_LOG LOG_SSDP

int ssdp_notify(sockets *s, int alive) {
char buf[500], mac[15] = "00000000000000";
char buf[500];
char nt[3][60];
int ptr = 0;
char *op = alive ? "Discovery" : "ByeBye";

char uuid1[] = "11223344-9999-0000-b7ae";
int i;
s->wtime = getTick();
if (uuidi == 0) {
uuidi = 1;
get_mac_address(mac);
sprintf(uuid, "%s-%s", uuid1, mac);
// use IPv4 only as disc_host is multicast IPv4
fill_sockaddr(&ssdp_sa, opts.disc_host, 1900, 1);
}

USockAddr ssdp_sa;
// use IPv4 only as disc_host is multicast IPv4
fill_sockaddr(&ssdp_sa, opts.disc_host, 1900, 1);
Jalle19 marked this conversation as resolved.
Show resolved Hide resolved
strcpy(nt[0], "::upnp:rootdevice");
sprintf(nt[1], "::uuid:%s", uuid);
sprintf(nt[1], "::uuid:%s", opts.uuid);
strcpy(nt[2], "::urn:ses-com:device:SatIPServer:1");

if (s->type != TYPE_UDP)
Expand All @@ -1706,7 +1701,7 @@ int ssdp_notify(sockets *s, int alive) {
if (alive)
strcatf(buf, ptr, "SERVER: Linux/1.0 UPnP/1.1 %s/%s\r\n",
opts.name_app, version);
strcatf(buf, ptr, "USN: uuid:%s%s\r\n", uuid, i == 1 ? "" : nt[i]);
strcatf(buf, ptr, "USN: uuid:%s%s\r\n", opts.uuid, i == 1 ? "" : nt[i]);
strcatf(buf, ptr, "BOOTID.UPNP.ORG: %d\r\n", opts.bootid);
strcatf(buf, ptr, "CONFIGID.UPNP.ORG: 0\r\n");
if (alive)
Expand All @@ -1725,7 +1720,15 @@ int ssdp_notify(sockets *s, int alive) {
return 0;
}

int ssdp_discovery(sockets *s) { return ssdp_notify(s, 1); }
int ssdp_discovery_sent = 0;
int ssdp_discovery(sockets *s) {
// Send discovery once only
if (!ssdp_discovery_sent) {
ssdp_discovery_sent = 1;
return ssdp_notify(s, 1);
}
return 0;
}

int ssdp_byebye(sockets *s) { return ssdp_notify(s, 0); }

Expand Down Expand Up @@ -1754,13 +1757,13 @@ int ssdp_reply(sockets *s) {
int did = 0;
int ptr = 0;

if (uuidi == 0)
if (!opts.disable_ssdp)
ssdp_discovery(s);

s->rtime = s->wtime; // consider the timeout of the discovery operation

ruuid = strcasestr((const char *)s->buf, "uuid:");
if (ruuid && strncmp(uuid, strip(ruuid + 5), strlen(uuid)) == 0) {
if (ruuid && strncmp(opts.uuid, strip(ruuid + 5), strlen(opts.uuid)) == 0) {
LOGM("Dropping packet from the same UUID as mine (from %s:%d)",
get_sockaddr_host(s->sa, ra, sizeof(ra)),
get_sockaddr_port(s->sa));
Expand Down Expand Up @@ -1823,7 +1826,7 @@ int ssdp_reply(sockets *s) {

ptr = 0;
strcatf(buf, ptr, reply, get_current_timestamp(), opts.http_host,
opts.xml_path, opts.name_app, version, uuid, opts.bootid, did);
opts.xml_path, opts.name_app, version, opts.uuid, opts.bootid, did);

LOGM("Send Reply SSDP packet (fd: %d) %s:%d, bootid: %d deviceid: %d http: "
"%s",
Expand Down Expand Up @@ -2144,7 +2147,7 @@ _symbols minisatip_sym[] = {
{"has_pmt", VAR_INT, &has_pmt, 1, 0, 0},
{"name_app", VAR_PSTRING, &opts.name_app, 0, 0, 0},
{"http_host", VAR_PSTRING, &opts.http_host, 0, 0, 0},
{"uuid", VAR_STRING, uuid, 0, 0, 0},
{"uuid", VAR_STRING, &opts.uuid, 0, 0, 0},
{"bootid", VAR_INT, &opts.bootid, 1, 0, 0},
{"deviceid", VAR_INT, &opts.device_id, 1, 0, 0},
{"http_port", VAR_INT, &opts.http_port, 1, 0, 0},
Expand Down
9 changes: 9 additions & 0 deletions src/opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
*/

#include "opts.h"
#include "socketworks.h"
#include "utils.h"
#include "utils/logging/logging.h"
#include <stdio.h>
#include <string.h>

void parse_dvbapi_opt(char *optarg, struct_opts_t *optz) {
Expand Down Expand Up @@ -60,3 +62,10 @@ void parse_dvbapi_opt(char *optarg, struct_opts_t *optz) {
LOG("Not filtering out encrypted packets from pids=all streams");
}
}

void generate_uuid(struct_opts_t *optz) {
char uuid1[] = "11223344-9999-0000-b7ae";
char mac[15] = "00000000000000";
get_mac_address(mac);
sprintf(optz->uuid, "%s-%s", uuid1, mac);
}
2 changes: 2 additions & 0 deletions src/opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef struct struct_opts {
int run_pid;
char *disc_host; // discover host
char mac[13];
char uuid[50];
unsigned int log, debug, slog, start_rtp, http_port;
int timeout_sec;
int force_sadapter, force_tadapter, force_cadapter;
Expand Down Expand Up @@ -91,6 +92,7 @@ typedef struct struct_opts {
} struct_opts_t;

void parse_dvbapi_opt(char *optarg, struct_opts_t *optz);
void generate_uuid(struct_opts_t *optz);

extern struct_opts_t opts;

Expand Down
Loading