|
13 | 13 | #include <fcntl.h> |
14 | 14 | #include <stdlib.h> |
15 | 15 | #include <string.h> |
16 | | -#include "platform.h" |
| 16 | +#include "../crosstools/src/platform.h" |
17 | 17 | #include <assert.h> |
18 | 18 |
|
19 | 19 | #include <sys/stat.h> |
|
32 | 32 | #endif |
33 | 33 | #endif |
34 | 34 |
|
35 | | -#include "cross_thread.h" |
| 35 | +#include "../crosstools/src/cross_thread.h" |
36 | 36 | #include "raop_client.h" |
37 | | -#include "cross_net.h" |
38 | | -#include "cross_ssl.h" |
| 37 | +#include "../crosstools/src/cross_net.h" |
| 38 | +#include "../crosstools/src/cross_ssl.h" |
39 | 39 | #include "cross_util.h" |
40 | 40 | #include "cross_log.h" |
41 | 41 | #include "http_fetcher.h" |
| 42 | +#include "pairing.h" |
42 | 43 |
|
43 | 44 | #define RAOP_SEC(ntp) ((uint32_t)((ntp) >> 32)) |
44 | 45 | #define RAOP_FRAC(ntp) ((uint32_t)(ntp)) |
@@ -123,6 +124,7 @@ static int print_usage(char *argv[]) |
123 | 124 |
|
124 | 125 | "\t[-if <ipaddress>] (IP of the interface to bind to)\n" |
125 | 126 |
|
| 127 | + "\t[-pair] enter pairing mode for AppleTV\n" |
126 | 128 | "\t[-debug <debug level>] (0 = silent)\n", |
127 | 129 | name); |
128 | 130 | return -1; |
@@ -324,28 +326,34 @@ int main(int argc, char *argv[]) |
324 | 326 | int i, n = -1, level = 3; |
325 | 327 | raop_crypto_t crypto = RAOP_CLEAR; |
326 | 328 | uint64_t start = 0, start_at = 0, last = 0, frames = 0; |
327 | | - bool alac = false, encryption = false, auth = false; |
| 329 | + bool alac = false, encryption = false, auth = false, pairing_mode = false; |
328 | 330 | char *passwd = "", *secret = "", *md = "0,1,2", *et = "0,4", *am = "", *pk = "", *pw = ""; |
329 | 331 | char *iface = NULL; |
330 | 332 | uint32_t glNetmask; |
331 | 333 | char glInterface[16] = "?"; |
332 | 334 | static struct in_addr glHost; |
| 335 | + char *pair_udn = NULL; |
| 336 | + char *pair_secret = NULL; |
333 | 337 |
|
334 | 338 | // parse arguments |
335 | 339 | for (i = 1; i < argc; i++) |
336 | 340 | { |
337 | | - if (!strcmp(argv[i], "-ntp")) |
| 341 | + if (!strcmp(argv[i], "-pair")) |
| 342 | + { |
| 343 | + pairing_mode = true; |
| 344 | + } |
| 345 | + else if (!strcmp(argv[i], "-ntp")) |
338 | 346 | { |
339 | 347 | uint64_t t = raopcl_get_ntp(NULL); |
340 | 348 | printf("%" PRIu64 "\n", t); |
341 | 349 | exit(0); |
342 | 350 | } |
343 | | - if (!strcmp(argv[i], "-check")) |
| 351 | + else if (!strcmp(argv[i], "-check")) |
344 | 352 | { |
345 | 353 | printf("cliraop check\n"); |
346 | 354 | exit(0); |
347 | 355 | } |
348 | | - if (!strcmp(argv[i], "-port")) |
| 356 | + else if (!strcmp(argv[i], "-port")) |
349 | 357 | { |
350 | 358 | player.port = atoi(argv[++i]); |
351 | 359 | } |
@@ -447,6 +455,23 @@ int main(int argc, char *argv[]) |
447 | 455 | LOG_INFO("Binding to %s [%s] with mask 0x%08x", inet_ntoa(glHost), iface, ntohl(glNetmask)); |
448 | 456 | NFREE(iface); |
449 | 457 |
|
| 458 | + if (pairing_mode) |
| 459 | + { |
| 460 | + // Initialize platform/SSL for pairing |
| 461 | + netsock_init(); |
| 462 | + cross_ssl_load(); |
| 463 | + |
| 464 | + if (AppleTVpairing(NULL, &pair_udn, &pair_secret)) |
| 465 | + { |
| 466 | + printf("\nPairing successful!\nUDN: %s\nSecret: %s\n", pair_udn ? pair_udn : "(none)", pair_secret ? pair_secret : "(none)"); |
| 467 | + } |
| 468 | + else |
| 469 | + { |
| 470 | + printf("Pairing failed.\n"); |
| 471 | + } |
| 472 | + exit(0); |
| 473 | + } |
| 474 | + |
450 | 475 | if (!player.hostname) |
451 | 476 | return print_usage(argv); |
452 | 477 | if (!fname) |
|
0 commit comments