Second attempt. Modify the generation of the 12-digit classic AirPlay service name prefix so that it depends on the service name as well as the hardware address.

This commit is contained in:
Mike Brady
2022-11-17 10:31:51 +00:00
parent 75aa150e0e
commit 03d291f464
6 changed files with 56 additions and 16 deletions
+1
View File
@@ -159,6 +159,7 @@ typedef struct {
int mqtt_enable_remote;
char *mqtt_empty_payload_substitute;
#endif
uint8_t ap1_prefix[6];
uint8_t hw_addr[8]; // only needs 6 but 8 is handy when converting this to a number
int port;
int udp_port_base;
+4 -4
View File
@@ -1221,8 +1221,8 @@ int dacp_get_volume(int32_t *the_actual_volume) {
http_response = dacp_get_speaker_list((dacp_spkr_stuff *)&speaker_info, 50, &speaker_count);
if (http_response == 200) {
// get our machine number
uint16_t *hn = (uint16_t *)config.hw_addr;
uint32_t *ln = (uint32_t *)(config.hw_addr + 2);
uint16_t *hn = (uint16_t *)config.ap1_prefix;
uint32_t *ln = (uint32_t *)(config.ap1_prefix + 2);
uint64_t t1 = ntohs(*hn);
uint64_t t2 = ntohl(*ln);
int64_t machine_number = (t1 << 32) + t2; // this form is useful
@@ -1275,8 +1275,8 @@ int dacp_set_volume(int32_t vo) {
http_response = dacp_get_speaker_list((dacp_spkr_stuff *)&speaker_info, 50, &speaker_count);
if (http_response == 200) {
// get our machine number
uint16_t *hn = (uint16_t *)config.hw_addr;
uint32_t *ln = (uint32_t *)(config.hw_addr + 2);
uint16_t *hn = (uint16_t *)config.ap1_prefix;
uint32_t *ln = (uint32_t *)(config.ap1_prefix + 2);
uint64_t t1 = ntohs(*hn);
uint64_t t2 = ntohl(*ln);
int64_t machine_number = (t1 << 32) + t2; // this form is useful
+1 -1
View File
@@ -69,7 +69,7 @@ void mdns_register(char **txt_records, char **secondary_txt_records) {
char *p = ap1_service_name;
int i;
for (i = 0; i < 6; i++) {
snprintf(p, 3, "%02X", config.hw_addr[i]);
snprintf(p, 3, "%02X", config.ap1_prefix[i]);
p += 2;
}
*p++ = '@';
+7 -7
View File
@@ -380,7 +380,6 @@ static void init_buffer(rtsp_conn_info *conn) {
buffers_allocated++;
}
}
debug(1, "%" PRId64 " buffers allocated, %" PRId64 " buffers released.", buffers_allocated, buffers_released);
}
static void free_audio_buffers(rtsp_conn_info *conn) {
@@ -389,6 +388,7 @@ static void free_audio_buffers(rtsp_conn_info *conn) {
free(conn->audio_buffer[i].data);
buffers_released++;
}
debug(1, "%" PRId64 " buffers allocated, %" PRId64 " buffers released.", buffers_allocated, buffers_released);
}
int first_possibly_missing_frame = -1;
@@ -1730,14 +1730,14 @@ void player_thread_cleanup_handler(void *arg) {
int64_t elapsedMin = (time_playing / 60) % 60;
int64_t elapsedSec = time_playing % 60;
if (conn->frame_rate_valid)
inform("Connection %d: Playback Stopped. Total playing time %02" PRId64 ":%02" PRId64
inform("Connection %d: Playback stopped. Total playing time %02" PRId64 ":%02" PRId64
":%02" PRId64 ". "
"Output: %0.2f (raw), %0.2f (corrected) "
"frames per second.",
conn->connection_number, elapsedHours, elapsedMin, elapsedSec, conn->raw_frame_rate,
conn->corrected_frame_rate);
else
inform("Connection %d: Playback Stopped. Total playing time %02" PRId64 ":%02" PRId64
inform("Connection %d: Playback stopped. Total playing time %02" PRId64 ":%02" PRId64
":%02" PRId64 ".",
conn->connection_number, elapsedHours, elapsedMin, elapsedSec);
}
@@ -2745,14 +2745,14 @@ void *player_thread_func(void *arg) {
send_ssnc_metadata('styp', "Classic", strlen("Classic"), 1);
#endif
if (config.statistics_requested)
inform("Connection %d: Playback Started at frame %" PRId64 " -- AirPlay 1 Compatible.",
inform("Connection %d: Playback started at frame %" PRId64 " -- AirPlay 1 Compatible.",
conn->connection_number, inframe->given_timestamp);
} else {
#ifdef CONFIG_METADATA_HUB
send_ssnc_metadata('styp', "Realtime", strlen("Realtime"), 1);
#endif
if (config.statistics_requested)
inform("Connection %d: Playback Started at frame %" PRId64 " -- AirPlay 2 Realtime.",
inform("Connection %d: Playback started at frame %" PRId64 " -- AirPlay 2 Realtime.",
conn->connection_number, inframe->given_timestamp);
}
} else {
@@ -2760,7 +2760,7 @@ void *player_thread_func(void *arg) {
send_ssnc_metadata('styp', "Buffered", strlen("Buffered"), 1);
#endif
if (config.statistics_requested)
inform("Connection %d: Playback Started at frame %" PRId64 " -- AirPlay 2 Buffered.",
inform("Connection %d: Playback started at frame %" PRId64 " -- AirPlay 2 Buffered.",
conn->connection_number, inframe->given_timestamp);
}
#else
@@ -2768,7 +2768,7 @@ void *player_thread_func(void *arg) {
send_ssnc_metadata('styp', "Classic", strlen("Classic"), 1);
#endif
if (config.statistics_requested)
inform("Connection %d: Playback Started at frame %" PRId64 " -- AirPlay 1.", conn->connection_number, inframe->given_timestamp);
inform("Connection %d: Playback started at frame %" PRId64 " -- AirPlay 1.", conn->connection_number, inframe->given_timestamp);
#endif
}
// not too sure if abs() is implemented for int64_t, so we'll do it manually
+4 -4
View File
@@ -1333,7 +1333,7 @@ enum rtsp_read_request_response rtsp_read_request(rtsp_conn_info *conn, rtsp_mes
while (msg_size < 0) {
if (conn->stop != 0) {
debug(3, "Connection %d: shutdown requested.", conn->connection_number);
debug(3, "Connection %d: Shutdown requested by client.", conn->connection_number);
reply = rtsp_read_request_response_immediate_shutdown_requested;
goto shutdown;
}
@@ -1342,7 +1342,7 @@ enum rtsp_read_request_response rtsp_read_request(rtsp_conn_info *conn, rtsp_mes
if (nread == 0) {
// a blocking read that returns zero means eof -- implies connection closed by client
debug(1, "Connection %d: RTSP connection closed by client.",
debug(1, "Connection %d: Connection closed by client.",
conn->connection_number);
reply = rtsp_read_request_response_channel_closed;
// Note: the socket will be closed when the thread exits
@@ -4751,7 +4751,7 @@ static void apple_challenge(int fd, rtsp_message *req, rtsp_message *resp) {
}
for (i = 0; i < 6; i++)
*bp++ = config.hw_addr[i];
*bp++ = config.ap1_prefix[i];
int buflen, resplen;
buflen = bp - buf;
@@ -5005,7 +5005,7 @@ void rtsp_conversation_thread_cleanup_function(void *arg) {
conn->audio_socket = 0;
}
if (conn->fd > 0) {
debug(1, "Connection %d: terminating -- closing RTSP connection socket %d: from %s:%u to self at %s:%u.",
debug(2, "Connection %d: terminating -- closing RTSP connection socket %d: from %s:%u to self at %s:%u.",
conn->connection_number, conn->fd, conn->client_ip_string, conn->client_rtsp_port,
conn->self_ip_string, conn->self_rtsp_port);
close(conn->fd);
+39
View File
@@ -2454,6 +2454,45 @@ int main(int argc, char **argv) {
soxr_time_check_thread_started = 1;
#endif
// calculate the 12-hex-digit prefix by hashing the service name.
uint8_t ap_md5[16];
debug(1,"size of hw_addr is %u.", sizeof(config.hw_addr));
#ifdef CONFIG_OPENSSL
MD5_CTX ctx;
MD5_Init(&ctx);
MD5_Update(&ctx, config.service_name, strlen(config.service_name));
MD5_Update(&ctx, config.hw_addr, sizeof(config.hw_addr));
MD5_Final(ap_md5, &ctx);
#endif
#ifdef CONFIG_MBEDTLS
#if MBEDTLS_VERSION_MINOR >= 7
mbedtls_md5_context tctx;
mbedtls_md5_starts_ret(&tctx);
mbedtls_md5_update_ret(&tctx, (unsigned char *)config.service_name, strlen(config.service_name));
mbedtls_md5_update_ret(&tctx, (unsigned char *)config.hw_addr, sizeof(config.hw_addr));
mbedtls_md5_finish_ret(&tctx, ap_md5);
#else
mbedtls_md5_context tctx;
mbedtls_md5_starts(&tctx);
mbedtls_md5_update(&tctx, (unsigned char *)config.service_name, strlen(config.service_name));
mbedtls_md5_update(&tctx, (unsigned char *)config.hw_addr, sizeof(config.hw_addr));
mbedtls_md5_finish(&tctx, ap_md5);
#endif
#endif
#ifdef CONFIG_POLARSSL
md5_context tctx;
md5_starts(&tctx);
md5_update(&tctx, (unsigned char *)config.service_name, strlen(config.service_name));
md5_update(&tctx, (unsigned char *)config.hw_addr, sizeof(config.hw_addr));
md5_finish(&tctx, ap_md5);
#endif
memcpy(config.ap1_prefix, ap_md5, sizeof(config.ap1_prefix));
#ifdef CONFIG_METADATA
metadata_init(); // create the metadata pipe if necessary
#endif