@@ -85,7 +85,7 @@ static const IPAddress MDNS_MULTICAST_ADDR(224, 0, 0, 251);
85
85
static const int MDNS_MULTICAST_TTL = 1 ;
86
86
static const int MDNS_PORT = 5353 ;
87
87
88
- MDNSResponder::MDNSResponder () : _conn(0 ) { _services = 0 ; }
88
+ MDNSResponder::MDNSResponder () : _conn(0 ) { _services = 0 ; _arduinoAuth = false ; }
89
89
MDNSResponder::~MDNSResponder () {}
90
90
91
91
bool MDNSResponder::begin (const char * domain){
@@ -101,8 +101,6 @@ bool MDNSResponder::begin(const char* domain){
101
101
_hostName[i] = tolower (domain[i]);
102
102
_hostName[n] = ' \0 ' ;
103
103
104
- os_strcpy (_boardName, ARDUINO_BOARD);
105
-
106
104
// Open the MDNS socket if it isn't already open.
107
105
if (!_conn) {
108
106
uint32_t ourIp = _getOurIp ();
@@ -372,7 +370,10 @@ void MDNSResponder::_parsePacket(){
372
370
return _reply (responseMask, (serviceName), (protoName), servicePort);
373
371
}
374
372
375
-
373
+ void MDNSResponder::enableArduino (uint16_t port, bool auth){
374
+ _arduinoAuth = auth;
375
+ addService (" arduino" , " tcp" , port);
376
+ }
376
377
377
378
void MDNSResponder::_reply (uint8_t replyMask, char * service, char *proto, uint16_t port){
378
379
int i;
@@ -439,24 +440,53 @@ void MDNSResponder::_reply(uint8_t replyMask, char * service, char *proto, uint1
439
440
440
441
// TXT Response
441
442
if (replyMask & 0x4 ){
442
- if (replyMask & 0x8 ){// send the name
443
- uint8_t txtHead[2 ] = {0xC0 , (uint8_t )(36 + serviceLen)};
444
- _conn->append (reinterpret_cast <const char *>(txtHead), 2 );
443
+ if (replyMask & 0x8 ){
444
+ uint8_t txtHead[10 ] = {
445
+ 0xC0 , (uint8_t )(36 + serviceLen),// send the name
446
+ 0x00 , 0x10 , // Type TXT
447
+ 0x80 , 0x01 , // Class IN, with cache flush
448
+ 0x00 , 0x00 , 0x11 , 0x94 , // TTL 4500
449
+ };
450
+ _conn->append (reinterpret_cast <const char *>(txtHead), 10 );
445
451
}
446
452
447
- uint8_t boardNameLen = os_strlen (_boardName);
448
-
449
- uint8_t txt[24 ] = {
450
- 0x00 , 0x10 , // Type TXT
451
- 0x80 , 0x01 , // Class IN, with cache flush
452
- 0x00 , 0x00 , 0x11 , 0x94 , // TTL 4500
453
- 0x00 , 0x0e , // DATA LEN
454
- (uint8_t )(6 + boardNameLen), // strlen(board=) + strlen(boardName)
455
- 0x62 , 0x6f , 0x61 , 0x72 , 0x64 , 0x3d // board=
456
- };
457
- _conn->append (reinterpret_cast <const char *>(txt), 17 );
458
- _conn->append (reinterpret_cast <const char *>(_boardName), boardNameLen);
459
-
453
+ if (strcmp (reinterpret_cast <const char *>(" arduino" ), service) == 0 ){
454
+ // arduino
455
+ // arduino service dependance should be removed and properties abstracted
456
+ const char *tcpCheckExtra = " tcp_check=no" ;
457
+ uint8_t tcpCheckExtraLen = os_strlen (tcpCheckExtra);
458
+
459
+ const char *sshUploadExtra = " ssh_upload=no" ;
460
+ uint8_t sshUploadExtraLen = os_strlen (sshUploadExtra);
461
+
462
+ char boardName[64 ];
463
+ const char *boardExtra = " board=" ;
464
+ os_sprintf (boardName, " %s%s\0 " , boardExtra, ARDUINO_BOARD);
465
+ uint8_t boardNameLen = os_strlen (boardName);
466
+
467
+ char authUpload[16 ];
468
+ const char *authUploadExtra = " auth_upload=" ;
469
+ os_sprintf (authUpload, " %s%s\0 " , authUploadExtra, reinterpret_cast <const char *>((_arduinoAuth)?" yes" :" no" ));
470
+ uint8_t authUploadLen = os_strlen (authUpload);
471
+
472
+ uint16_t textDataLen = (1 + boardNameLen) + (1 + tcpCheckExtraLen) + (1 + sshUploadExtraLen) + (1 + authUploadLen);
473
+ uint8_t txt[2 ] = {(uint8_t )(textDataLen >> 8 ), (uint8_t )(textDataLen)}; // DATA LEN
474
+ _conn->append (reinterpret_cast <const char *>(txt), 2 );
475
+
476
+ _conn->append (reinterpret_cast <const char *>(&boardNameLen), 1 );
477
+ _conn->append (reinterpret_cast <const char *>(boardName), boardNameLen);
478
+ _conn->append (reinterpret_cast <const char *>(&authUploadLen), 1 );
479
+ _conn->append (reinterpret_cast <const char *>(authUpload), authUploadLen);
480
+ _conn->append (reinterpret_cast <const char *>(&tcpCheckExtraLen), 1 );
481
+ _conn->append (reinterpret_cast <const char *>(tcpCheckExtra), tcpCheckExtraLen);
482
+ _conn->append (reinterpret_cast <const char *>(&sshUploadExtraLen), 1 );
483
+ _conn->append (reinterpret_cast <const char *>(sshUploadExtra), sshUploadExtraLen);
484
+ } else {
485
+ // not arduino
486
+ // we should figure out an API so TXT properties can be added for services
487
+ uint8_t txt[2 ] = {0 ,0 };
488
+ _conn->append (reinterpret_cast <const char *>(txt), 2 );
489
+ }
460
490
}
461
491
462
492
// SRV Response
0 commit comments