File nut/app/httpd_upnp/upnp.c

* Copyright (c) 2011 by Michael Fischer. All rights reserved.
* This work based on source from proconX Pty Ltd. Therefore * partial copyright by: Copyright (c) 2010 proconX Pty Ltd.
* Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met:
* 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the author nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE.
***************************************************************************** * History:
* 27.05.2011 mifi First Version based on source from proconX Pty Ltd. * Information about UPnP can be found at "www.upnp.org". * Note: I had no success with the UPnP Device Validator * from the "Open Software Projects". The old original * Intel tools from the book "UPnP Design by Example" * works a little bit better, but has problems too.


Included Files


Preprocessor definitions

#define __MAIN_C__

#define UPNP_FULFIL_SPEC 0

#define UPNP_SERVICE_STACK

#define UPNP_CGI_NAME "upnp.cgi"

#define UPNP_UUID_PART1 "56F9C1D5-5083-4ee5-A6B3-"

#define SSDP_IP 0xfaffffefU

#define SSDP_PORT 1900

#define SSDP_BUFFER_SIZE 512

#define SSDP_NOTIFY_TIMEOUT 300000U


Local Variables

HTTP_TEXT_XML
static char HTTP_TEXT_XML[]
Used in: LocationCGIHandler()  

NOTIFY_ALIVE
static char NOTIFY_ALIVE[]

Used in: SendNotifyAliveChunk()  

NOTIFY_BYE
static char NOTIFY_BYE[]

Used in: SSDPTask()  

MSEARCH_RESPONSE
static char MSEARCH_RESPONSE[]

Used in: SSDPTask()  

HTML_UPNP
static char HTML_UPNP[]

Used in: LocationCGIHandler()  

dev
static NUTDEVICE* dev

Used in: upnp_Init()  

nif
static IFNET* nif

Used in: LocationCGIHandler()  
  SSDPTask()  
  SendNotifyAliveChunk()  
  upnp_Init()  

MyUSN
static char MyUSN[48]

Used in: SSDPTask()  
  SendNotifyAliveChunk()  

ServerInfo
static char ServerInfo[32]

Used in: SSDPTask()  
  SendNotifyAliveChunk()  

Global Function NotifyTask()

void NotifyTask ( void* arg )
Prototyped in: nut/app/httpd_upnp/upnp.c
Calls: SendNotifyAlive() nut/app/httpd_upnp/upnp.c
  NutSleep(), NutThreadYield(), NutUdpCreateSocket(), malloc()
Used in: upnp_Init() nut/app/httpd_upnp/upnp.c

Global Function SSDPTask()

void SSDPTask ( void* arg )
Prototyped in: nut/app/httpd_upnp/upnp.c
Calls: GetRand() nut/app/httpd_upnp/upnp.c
  SendNotifyAlive() nut/app/httpd_upnp/upnp.c
  NutSleep(), NutThreadYield(), NutUdpCreateSocket(), NutUdpReceiveFrom(), NutUdpSendTo(), inet_ntoa(), malloc(), sprintf(), strstr(), strtol()
Used in: upnp_Init() nut/app/httpd_upnp/upnp.c
References Variables: MSEARCH_RESPONSE nut/app/httpd_upnp/upnp.c
  MyUSN nut/app/httpd_upnp/upnp.c
  NOTIFY_BYE nut/app/httpd_upnp/upnp.c
  ServerInfo nut/app/httpd_upnp/upnp.c
  nif nut/app/httpd_upnp/upnp.c

Global Function upnp_Init()

void upnp_Init ( void )
Calls: NutDeviceLookup(), NutNetIfAddMcastAddr(), NutRegisterCgi(), NutThreadCreate(), printf(), puts()
Called by: NutAppMain() nut/app/httpd_upnp/httpserv.c
References Functions: LocationCGIHandler() nut/app/httpd_upnp/upnp.c
  NotifyTask() nut/app/httpd_upnp/upnp.c
  SSDPTask() nut/app/httpd_upnp/upnp.c
References Variables: dev nut/app/httpd_upnp/upnp.c
  nif nut/app/httpd_upnp/upnp.c

Local Function GetRand()

static uint32_t GetRand ( uint32_t MaxValue )
Calls: rand()
Called by: SSDPTask() nut/app/httpd_upnp/upnp.c
  SendNotifyAlive() nut/app/httpd_upnp/upnp.c

Local Function LocationCGIHandler()

static int LocationCGIHandler ( FILE* stream, REQUEST* req )
Calls: NutHttpSendHeaderBottom(), NutHttpSendHeaderTop(), fprintf(), inet_ntoa()
Used in: upnp_Init() nut/app/httpd_upnp/upnp.c
References Variables: HTML_UPNP nut/app/httpd_upnp/upnp.c
  HTTP_TEXT_XML nut/app/httpd_upnp/upnp.c
  nif nut/app/httpd_upnp/upnp.c

Local Function SendNotifyAlive()

static void SendNotifyAlive ( char* Buffer, UDPSOCKET* TxSock )
Calls: GetRand() nut/app/httpd_upnp/upnp.c
  SendNotifyAliveChunk() nut/app/httpd_upnp/upnp.c
  NutSleep()
Called by: NotifyTask() nut/app/httpd_upnp/upnp.c
  SSDPTask() nut/app/httpd_upnp/upnp.c

Local Function SendNotifyAliveChunk()

static void SendNotifyAliveChunk ( char* Buffer, UDPSOCKET* TxSock )
Calls: NutSleep(), NutUdpSendTo(), inet_ntoa(), sprintf()
Called by: SendNotifyAlive() nut/app/httpd_upnp/upnp.c
References Variables: MyUSN nut/app/httpd_upnp/upnp.c
  NOTIFY_ALIVE nut/app/httpd_upnp/upnp.c
  ServerInfo nut/app/httpd_upnp/upnp.c
  nif nut/app/httpd_upnp/upnp.c