/*
* Broadcom UPnP module SSDP implementation
*
* Copyright (C) 2008, Broadcom Corporation
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
* the contents of this file may not be disclosed to third parties, copied
* or duplicated in any form, in whole or in part, without the prior
* written permission of Broadcom Corporation.
*
* $Id: ssdp.c,v 1.1.1.2 2008/10/01 02:44:47 jack Exp $
*/
#include <upnp.h>
#include <ILibParsers.h>
#ifdef UI_GTK_SUPPORT
#include <gui.h>
#endif
struct upnp_method ssdp_ctrlpoint_methods[] =
{
{"HTTP/1.1 ", sizeof("HTTP/1.1 ")-1, METHOD_HTTP_RESPONSE, ssdp_msearch_response_process},
{0, 0, 0, 0}
};
//static int read_header(UPNP_CONTEXT *, struct upnp_method *);
static struct upnp_state ssdp_ctrlpoint_fsm[] =
{
{upnp_http_fsm_init, 0},
{read_ssdp_header, 0},
{parse_method, ssdp_ctrlpoint_methods},
{parse_uri, 0},
{parse_msghdr, 0},
{upnp_http_fsm_dispatch, ssdp_ctrlpoint_methods},
{0, 0}
};
int hasUpnpActionInputArgument(struct UPnPAction *action)
{
struct UPnPActionArgument *arg = NULL;
if(action)
{
arg = action->Args;
while(arg)
{
if( strcmp(arg->Direction, "in") == 0 )
return TRUE;
arg = arg->Next;
}
}
return FALSE;
}
struct UPnPDevice * find_device(struct UPnPDevice *device, const char *udn)
{
struct UPnPDevice *e_Device = device->EmbeddedDevices;
struct UPnPDevice *t_Device;
if(device!=NULL)
{
if( strcmp(udn, device->UDN) == 0 )
return device;
}
while(e_Device!=NULL)
{
t_Device = find_device(e_Device, udn);
if(t_Device)
return t_Device;
e_Device = e_Device->Next;
}
return NULL;
}
struct UPnPService * find_service(struct UPnPDevice *device, const char *uuid)
{
struct UPnPDevice *e_Device = device->EmbeddedDevices;
struct UPnPService *service;
struct UPnPService *e_service;
service = device->Services;
while(service!=NULL)
{
if( strcmp(uuid, service->ServiceId) == 0 )
return service;
service = service->Next;
}
while(e_Device!=NULL)
{
e_service = find_service(e_Device, uuid);
if(e_service)
return e_service;
e_Device = e_Device->Next;
}
return NULL;
}
struct UPnPService * find_service_by_sid(struct UPnPDevice *device, const char *sid)
{
struct UPnPDevice *e_Device = device->EmbeddedDevices;
struct UPnPService *service;
struct UPnPService *e_service;
service = device->Services;
while(service!=NULL)
{
if( service->SubscriptionID!=NULL && strcmp(sid, service->SubscriptionID) == 0 )
return service;
service = service->Next;
}
while(e_Device!=NULL)
{
e_service = find_service_by_sid(e_Device, sid);
if(e_service)
return e_service;
e_Device = e_Device->Next;
}
return NULL;
}
struct UPnPService * find_upnp_service(UPNP_CONTEXT *context, const char *uuid)
{
struct UPnPDevice *rootdevice;
struct UPnPService *service;
UPNP_INTERFACE *ifp;
for (ifp = context->iflist; ifp; ifp = ifp->next)
{
context->focus_ifp = ifp;
rootdevice = ifp->rootdevice;
while(rootdevice)
{
service = find_service(rootdevice, uuid);
if(service)
return service;
rootdevice = rootdevice->Next;
}
}
return NULL;
}
struct UPnPDevice * find_upnp_device(UPNP_CONTEXT *context, const char *udn)
{
struct UPnPDevice *rootdevice;
struct UPnPDevice *device;
UPNP_INTERFACE *ifp;
for (ifp = context->iflist; ifp; ifp = ifp->next)
{
context->focus_ifp = ifp;
rootdevice = ifp->rootdevice;
while(rootdevice)
{
device = find_device(rootdevice, udn);
if(device)
return device;
rootdevice = rootdevice->Next;
}
}
return NULL;
}
struct UPnPService * find_upnp_service_by_sid(UPNP_CONTEXT *context, const char *sid)
{
struct UPnPDevice *rootdevice;
struct UPnPService *service;
UPNP_INTERFACE *ifp;
for (ifp = context->iflist; ifp; ifp = ifp->next)
{
context->focus_ifp = ifp;
rootdevice = ifp->rootdevice;
while(rootdevice)
{
service = find_service_by_sid(rootdevice, sid);
if(service)
return service;
rootdevice = rootdevice->Next;
}
}
return NULL;
}
struct UPnPAction * find_upnp_action(struct UPnPService *service, const char *name)
{
struct UPnPAction *action = service->Actions;
while(action)
{
if( strcmp(action->Name, name)==0 )
return action;
action = action->Next;
}
return NULL;
}
struct UPnPActionArgument * find_upnp_action_argument(struct UPnPAction *action, const char *name)
{
struct UPnPActionArgument *arg = action->Args;
while(arg)
{
if( strcmp(arg->Name, name)==0 )
return arg;
arg = arg->Next;
}
return NULL;
}
struct UPnPStateVariable * find_upnp_state_variable(struct UPnPService *service, const char *name)
{
struct UPnPStateVariable *variable = service->Variables;
while(variable)
{
if( strcmp(variable->Name, name)==0 )
return variable;
variable = variable->Next;
}
return NULL;
}
/* Read SSDP header */
#if 0
static int read_header(UPNP_CONTEXT *context, struct upnp_method *methods)
{
//UPNP_INTERFACE *ifp = context->focus_ifp;
UPNP_INTERFACE *ifp = context->iflist;
socklen_t size = sizeof(struct sockaddr_in);
int len;
memset(&context->dst_addr, 0, size);
len = recvfrom(context->fd, context->buf, sizeof(context->buf),
0, (struct sockaddr *)&context->dst_addr, &size);
/* Read done */
if (len > 0) {
/* locate UPnP interface for the multicast socket */
while (ifp) {
if ((ifp->ipaddr.s_addr & ifp->netmask.s_addr) ==
(context->dst_addr.sin_addr.s_addr & ifp->netmask.s_addr)) {
/* Set focus interface */
context->focus_ifp = ifp;
break;
}
ifp = ifp->next;
}
if (ifp == NULL)
{
upnp_syslog(LOG_ERR, "Not found correct interface %s",
inet_ntoa(context->dst_addr.sin_addr));
return -1;
}
context->buf[len] = 0;
context->end = len;
context->dst = &context->dst_addr;
/* Get message header */
get_msghdr(context);
if (context->status != 0)
{
upnp_syslog(LOG_ERR, "Erro occured when get message header");
return -1;
}else{
upnp_syslog(LOG_ERR, "Recv message len NULL");
}
return 0;
}
return -1;
}
#endif
/* Send out SSDP packet */
void
upnp_msearch_send(UPNP_CONTEXT *context)
{
struct sockaddr_in dst;
char *buf = context->head_buffer;
int len = strlen(buf);
/*
* if caller does not specify a unicast address, send multicast
* (239.255.255.250)
*/
if (context->dst == 0) {
/* Assign mutlicast interface to send */
struct in_addr inaddr = context->focus_ifp->ipaddr;
setsockopt(context->MSEARCH_Response_Socket,
IPPROTO_IP, IP_MULTICAST_IF, (void *)&inaddr, sizeof(inaddr));
/* Send to SSDP_ADDR:SSDP_PORT */
#if defined(__ECOS)
dst.sin_len = sizeof(struct sockaddr_in);
#endif
dst.sin_family = AF_INET;
dst.sin_port = htons(SSDP_PORT);
inet_aton(SSDP_ADDR, &dst.sin_addr);
/* Send packet */
sendto(context->MSEARCH_Response_Socket, buf, len, 0, (struct sockaddr *)&dst, sizeof(dst));
return;
}
else {
dst = *context->dst;
/* Send packet */
sendto(context->ssdp_sock, buf, len, 0, (struct sockaddr *)&dst, sizeof(dst));
return;
}
}
void msearch_msg_send(UPNP_CONTEXT *context)
{
UPNP_INTERFACE *ifp;
int bufferlength;
char *buf = context->head_buffer;
context->dst = 0;
memset(buf, 0, sizeof(context->head_buffer));
bufferlength = sprintf(buf,"M-SEARCH * HTTP/1.1\r\nMX: 10\r\nST: %s\r\nHOST: 239.255.255.250:1900\r\nMAN: \"ssdp:discover\"\r\n\r\n",
"urn:schemas-upnp-org:device:InternetGatewayDevice:1");//"ssdp:all";
for (ifp = context->iflist; ifp; ifp = ifp->next)
{
context->focus_ifp = ifp;
upnp_msearch_send(context);
}
}
void msearch_response_process(UPNP_CONTEXT *context, int fd)
{
context->fd = fd;
upnp_http_fsm_engine(context, ssdp_ctrlpoint_fsm);
return;
}
int ssdp_msearch_response_process(UPNP_CONTEXT *context)
{
char name[128];
int type;
char *host;
char *nt;
char *st;
char *usn;
char
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
UPNP TR064 test tool (135个子文件)
output.0 248KB
traces.0 47KB
output.1 248KB
traces.1 20KB
_header:CONNECTION=close 0B
_header:CONTENT-LENGTH=3834 0B
_header:PRAGMA=no-cache 0B
Makefile.am 644B
Makefile.am 363B
Makefile.am 360B
AUTHORS 0B
interface.c.bak 23KB
exam_0.glade.bak 9KB
exam_0.gladep.bak 273B
interface.h.bak 99B
upnp_ctrlpoint.c 61KB
ILibParsers.c 60KB
gui.c 42KB
interface.c 40KB
soap_my.c 27KB
gena.c 23KB
cmd_proc.c 18KB
soap.c 16KB
upnp_http.c 15KB
ssdp.c 13KB
md5.c 10KB
linux_main.c 9KB
interface.c 8KB
upnp_util.c 8KB
linux_osl.c 7KB
fd_proc.c 7KB
upnp_device.c 7KB
callbacks.c 5KB
gui.c 4KB
support.c 4KB
support.c 4KB
upnp_description.c 3KB
upnp_req.c 3KB
utils.c 2KB
callbacks.c 2KB
gui_main.c 1KB
main.c 985B
debug.c 151B
ChangeLog 0B
ChangeLog 0B
configure 247KB
exam_0.glade 9KB
exam_0.gladep 273B
upnp_type.h 10KB
ILibParsers.h 8KB
gui.h 4KB
upnp_linux_osl.h 4KB
upnp_http.h 3KB
md5.h 3KB
UPnPControlPointStructs.h 3KB
callbacks.h 3KB
upnp_ctrlpoint.h 2KB
upnp_util.h 2KB
config.h 2KB
support.h 2KB
support.h 2KB
ssdp.h 2KB
gena.h 1KB
upnp_description.h 1KB
callbacks.h 1KB
upnp_req.h 1KB
upnp.h 1KB
soap.h 1KB
upnp_device.h 901B
upnp_osl.h 720B
init.h 689B
conf.h 579B
debug.h 365B
utils.h 255B
interface.h 229B
interface.h 95B
Makefile.in 19KB
Makefile.in 13KB
Makefile.in 13KB
Makefile.in.in 8KB
Makefile.in 8KB
config.h.in 2KB
configure.in 621B
POTFILES.in 114B
stamp-h.in 10B
config.log 22KB
export.log 3KB
aclocal.m4 50KB
Makefile 19KB
Makefile 13KB
Makefile 13KB
Makefile 8KB
Makefile 3KB
Makefile_err 2KB
Makefile_gui_autogen 1KB
Makefile_signal_file_gui 2KB
mkinstalldirs 2KB
NEWS 0B
interface.Po 33KB
support.Po 33KB
共 135 条
- 1
- 2
资源评论
- zqzx11479628892015-11-09这是TR069协议中的一部分吗 为什么编译无法通过
- planet-frontier2016-12-15代码中有几处编译不过的地方,不过挺好改的,算是挺好的软件。另外windows上可以下载device spy工具来测试TR-064协议
- anew992016-07-15谢谢分享,学习了!
lovejava759
- 粉丝: 0
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功