BOOL DumpDeviceDescr(_In_ HDEVINFO Devs, _In_ PSP_DEVINFO_DATA DevInfo) /*++ Routine Description: Write device description to stdout Arguments: Devs )_ uniquely identify device DevInfo ) Return Value: TRUE if success --*/ { LPTSTR desc; desc = GetDeviceDescription(Devs,DevInfo); if(!desc) { return FALSE; } Padding(1); FormatToStream(stdout,MSG_DUMP_DESCRIPTION,desc); delete [] desc; return TRUE; }
BOOL DumpDevice(_In_ HDEVINFO Devs, _In_ PSP_DEVINFO_DATA DevInfo) /*++ Routine Description: Write device instance & description to stdout Arguments: Devs )_ uniquely identify device DevInfo ) Return Value: TRUE if success --*/ { LPTSTR desc; BOOL b; desc = GetDeviceDescription(Devs,DevInfo); b = DumpDeviceWithInfo(Devs,DevInfo,desc); if(desc) { delete [] desc; } return b; }
std::string LoadedDeviceAdapter::GetDeviceDescription(const std::string& deviceName) const { ModuleStringBuffer descBuf(this, "GetDeviceDescription"); bool ok = GetDeviceDescription(deviceName.c_str(), descBuf.GetBuffer(), descBuf.GetMaxStrLen()); if (!ok) { throw CMMError("Cannot get description for device " + ToQuotedString(deviceName) + " of device adapter module " + ToQuotedString(name_)); } return descBuf.Get(); }
mDNSexport void LNT_SendDiscoveryMsg(mDNS *m) { static const char msg[] = "M-SEARCH * HTTP/1.1\r\n" "Host:239.255.255.250:1900\r\n" "ST:urn:schemas-upnp-org:service:WAN%sConnection:1\r\n" "Man:\"ssdp:discover\"\r\n" "MX:3\r\n\r\n"; static const mDNSAddr multicastDest = { mDNSAddrType_IPv4, { { { 239, 255, 255, 250 } } } }; mDNSu8* buf = (mDNSu8*)&m->omsg; //m->omsg is 8952 bytes, which is plenty unsigned int bufLen; if (!mDNSIPPortIsZero(m->UPnPRouterPort)) { if (m->SSDPSocket) { debugf("LNT_SendDiscoveryMsg destroying SSDPSocket %p", &m->SSDPSocket); mDNSPlatformUDPClose(m->SSDPSocket); m->SSDPSocket = mDNSNULL; } if (mDNSIPPortIsZero(m->UPnPSOAPPort) && !m->tcpDeviceInfo.sock) GetDeviceDescription(m, &m->tcpDeviceInfo); return; } // Always query for WANIPConnection in the first SSDP packet if (m->retryIntervalGetAddr <= NATMAP_INIT_RETRY) m->SSDPWANPPPConnection = mDNSfalse; // Create message bufLen = mDNS_snprintf((char*)buf, sizeof(m->omsg), msg, m->SSDPWANPPPConnection ? "PPP" : "IP"); debugf("LNT_SendDiscoveryMsg Router %.4a Current External Address %.4a", &m->Router.ip.v4, &m->ExternalAddress); if (!mDNSIPv4AddressIsZero(m->Router.ip.v4)) { if (!m->SSDPSocket) { m->SSDPSocket = mDNSPlatformUDPSocket(m, zeroIPPort); debugf("LNT_SendDiscoveryMsg created SSDPSocket %p", &m->SSDPSocket); } mDNSPlatformSendUDP(m, buf, buf + bufLen, 0, m->SSDPSocket, &m->Router, SSDPPort); mDNSPlatformSendUDP(m, buf, buf + bufLen, 0, m->SSDPSocket, &multicastDest, SSDPPort); } m->SSDPWANPPPConnection = !m->SSDPWANPPPConnection; }
// This function parses the response to our SSDP discovery message. Basically, we look to make sure this is a response // referencing a service we care about (WANIPConnection or WANPPPConnection), then look for the "Location:" header and copy the addressing and // URL info we need. mDNSexport void LNT_ConfigureRouterInfo(mDNS *m, const mDNSInterfaceID InterfaceID, mDNSu8 *data, mDNSu16 len) { char *ptr = (char *)data; char *end = (char *)data + len; char *stop = ptr; if (!mDNSIPPortIsZero(m->UPnPRouterPort)) return; // already have the info we need // The formatting of the HTTP header is not always the same when it comes to the placement of // the service and location strings, so we just look for each of them from the beginning for every response // figure out if this is a message from a service we care about while (ptr && ptr != end) { if (*ptr == 'W' && (strncasecmp(ptr, "WANIPConnection:1", 17) == 0)) break; ptr++; } if (ptr == end) { ptr = (char *)data; while (ptr && ptr != end) { if (*ptr == 'W' && (strncasecmp(ptr, "WANPPPConnection:1", 18) == 0)) break; ptr++; } } if (ptr == mDNSNULL || ptr == end) return; // not a message we care about // find "Location:", starting from the beginning ptr = (char *)data; while (ptr && ptr != end) { if ((*ptr & 0xDF) == 'L' && (strncasecmp(ptr, "Location:", 9) == 0)) break; // find the first 'L'; is this Location? if not, keep looking ptr++; } if (ptr == mDNSNULL || ptr == end) { mDNSASLLog((uuid_t *)&m->asl_uuid, "natt.legacy.ssdp", "failure", "Location", ""); return; // not a message we care about } ptr += 9; //Skip over 'Location:' while (*ptr == ' ' && ptr < end) ptr++; // skip over spaces if (ptr >= end) return; // find the end of the line for (stop = ptr; stop != end; stop++) { if (*stop == '\r') { end = stop; break; } } // fill in default port m->UPnPRouterPort = mDNSOpaque16fromIntVal(80); // free string pointers and set to NULL if (m->UPnPRouterAddressString != mDNSNULL) { mDNSPlatformMemFree(m->UPnPRouterAddressString); m->UPnPRouterAddressString = mDNSNULL; } if (m->UPnPRouterURL != mDNSNULL) { mDNSPlatformMemFree(m->UPnPRouterURL); m->UPnPRouterURL = mDNSNULL; } // the Router URL should look something like "/dyndev/uuid:0013-108c-4b3f0000f3dc" if (ParseHttpUrl(ptr, end, &m->UPnPRouterAddressString, &m->UPnPRouterPort, &m->UPnPRouterURL) != mStatus_NoError) { mDNSASLLog((uuid_t *)&m->asl_uuid, "natt.legacy.ssdp", "failure", "Parse URL", ""); return; } m->UPnPInterfaceID = InterfaceID; if (m->UPnPRouterAddressString == mDNSNULL) { mDNSASLLog((uuid_t *)&m->asl_uuid, "natt.legacy.ssdp", "failure", "Router address", ""); LogMsg("LNT_ConfigureRouterInfo: UPnPRouterAddressString is NULL"); } else LogInfo("LNT_ConfigureRouterInfo: Router address string [%s]", m->UPnPRouterAddressString); if (m->UPnPRouterURL == mDNSNULL) { mDNSASLLog((uuid_t *)&m->asl_uuid, "natt.legacy.ssdp", "failure", "Router path", ""); LogMsg("LNT_ConfigureRouterInfo: UPnPRouterURL is NULL"); } else LogInfo("LNT_ConfigureRouterInfo: Router URL [%s]", m->UPnPRouterURL); LogInfo("LNT_ConfigureRouterInfo: Router port %d", mDNSVal16(m->UPnPRouterPort)); LogInfo("LNT_ConfigureRouterInfo: Router interface %d", m->UPnPInterfaceID); // Don't need the SSDP socket anymore if (m->SSDPSocket) { debugf("LNT_ConfigureRouterInfo destroying SSDPSocket %p", &m->SSDPSocket); mDNSPlatformUDPClose(m->SSDPSocket); m->SSDPSocket = mDNSNULL; } mDNSASLLog((uuid_t *)&m->asl_uuid, "natt.legacy.ssdp", "success", "success", ""); // now send message to get the device description GetDeviceDescription(m, &m->tcpDeviceInfo); }