UPnP, Universal Plug and Play,通用即插即用。
协议
- SSDP: Simple Service Discovery Protocol, for discovering UPnP devices on the local network.
- SCPD: Service Control Point Definition, for defining the actions offered by the various services.
- SOAP: Simple Object Access Protocol, for actually calling actions.
SSDP Discovery
UPnP官方文档第10页开始描述Discovery,细节非常清晰,仔细阅读即可,取它一张图概述
Discovery:Search:Request with M-SEARCH
char buffer[1024];
int bufferlength = snprintf(buffer,1024,"M-SEARCH * HTTP/1.1\r\nMX: 3\r\nST: %s\r\nHOST: 239.255.255.250:1900\r\nMAN: \"ssdp:discover\"\r\n\r\n",ST);
int sockfd=socket(AF_INET,SOCK_DGRAM,0);
struct sockaddr_in addr;
addr.sin_family =AF_INET;
addr.sin_port =htons(1900);
addr.sin_addr.s_addr = inet_addr("239.255.255.250");
sendto(sockfd,buffer,bufferlength,0,(struct sockaddr*)&addr,sizeof(addr));
ST | description |
---|---|
ssdp:all | Search for all devices and services. |
upnp:rootdevice | Search for root devices only. |
uuid:device-UUID | Search for a particular device. Device UUID specified by UPnP vendor. |
urn:schemas-upnp-org:device:deviceType:v | Search for any device of this type. Device type and version defined by UPnP Forum working committee. |
urn:schemas-upnp-org:service:serviceType:v | Search for any service of this type. Service type and version defined by UPnP Forum working committee. |
urn:domain-name:device:deviceType:v | Search for any device of this type. Domain name, device type and version defined by UPnP vendor. Period characters in the domain name must be replaced with hyphens in accordance with RFC 2141. |
urn:domain-name:service:serviceType:v | Search for any service of this type. Domain name, service type and version defined by UPnP vendor. Period characters in the domain name must be replaced with hyphens in accordance with RFC 2141. |
Discovery:Search:Response
这是我自己调试RK3036开发板时M-SEARCH收到的响应输出:
D/lollipop_mix( 152): LOCATION: http://192.168.2.5:62008/
D/lollipop_mix( 152): DATE: Thu, 30 Dec 2021 09:06:30 GMT
D/lollipop_mix( 152): EXT:
D/lollipop_mix( 152): SERVER: ANDROID, UPnP/1.0, Intel MicroStack/1.0.2718
D/lollipop_mix( 152): USN: uuid:9A:1A:CE:9E:E3:7B@www.basicgo.net::urn:schemas-upnp-org:service:UsbDisplay:1
D/lollipop_mix( 152): CACHE-CONTROL: max-age=1800
D/lollipop_mix( 152): ST: HUAWEI ALP-AL00:7B