]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Second attempt. Modify the generation of the 12-digit classic AirPlay service name...
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Thu, 17 Nov 2022 10:31:51 +0000 (10:31 +0000)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Thu, 17 Nov 2022 10:31:51 +0000 (10:31 +0000)
common.h
dacp.c
mdns.c
player.c
rtsp.c
shairport.c

index a3f21126e5165d547f9ed86493aeea43190d8357..9f323e1b5a2c36c4965c3e5875a960363ff6a5b8 100644 (file)
--- a/common.h
+++ b/common.h
@@ -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;
diff --git a/dacp.c b/dacp.c
index d557de240cd078456780ca746d3c4f732911c508..49692491f934bb7449df2f25bb54d4a344106774 100644 (file)
--- a/dacp.c
+++ b/dacp.c
@@ -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
diff --git a/mdns.c b/mdns.c
index 9a5465c13e007cb8e7508db69600a83e53c53b18..0536641370b8de11a109593d407c2fb2cf0af2cc 100644 (file)
--- a/mdns.c
+++ b/mdns.c
@@ -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++ = '@';
index ec282c1c9de615d719784110fe074c7db375ed45..d7fa7fdc7d6de1a3dfd376307f682078add78d4a 100644 (file)
--- a/player.c
+++ b/player.c
@@ -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
diff --git a/rtsp.c b/rtsp.c
index 0a940b055407c0062adadf5779a41c4d6e9655e6..f5a97e6804248c1ef810ed4c139eb65b1ca06145 100644 (file)
--- a/rtsp.c
+++ b/rtsp.c
@@ -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);
index ac40c11f1990aa702b6c9fc8c40a82df9dde2da2..07d2c2341ba5003f8b7ccf4ec1268161df0fc408 100644 (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