Microchip® Advanced Software Framework

cgi.c File Reference

CGI request function handlers.

Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.

#include <string.h>
#include <FreeRTOS.h>
#include <task.h>
#include <lwip/ip.h>
#include <lwip/ip_addr.h>
#include <lwip/netif.h>
#include <lwip/tcpip.h>
#include <lwip/stats.h>
#include <lwip/opt.h>
#include "httpd.h"
#include "cgi.h"
#include "sysclk.h"
#include "conf_eth.h"
#include "lwip/memp_std.h"

Data Structures

struct  archnames
 

Macros

#define CGI_MATCH_EXT   2 /* Select item in table if the extention match */
 
#define CGI_MATCH_NAME   3 /* Select item in table if the string is content */
 
#define CGI_MATCH_NONE   0
 
#define CGI_MATCH_WORD   1 /* Select item in table only if string match */
 
#define CHIPID_ARCH
 
#define CHIPID_EPRCOC
 
#define CHIPID_NVPSIZ
 
#define CHIPID_NVTYP
 
#define CHIPID_SRAMSIZ
 
#define FREERTOS_STATS_BUFLEN   512
 
#define IP_ADDR_TO_INT_TUPLE(addr)
 
#define LWIP_MEMPOOL(name, num, size, desc)   desc,
 
#define TX_REQ_BUFLEN   1024
 

Functions

static int cgi_chipInfo (struct netconn *client, const char *name, char *recv_buf, size_t recv_len)
 Send the chip ID information. More...
 
static int cgi_error (struct netconn *client, const char *name, char *recv_buf, size_t recv_len)
 Used to handle unsupported CGI requests. More...
 
http_handler_t cgi_search (const char *name, HttpCGI *table)
 CGI request search engine. More...
 
static int cgi_status (struct netconn *client, const char *name, char *recv_buf, size_t recv_len)
 Send a JSON string representing the board status. More...
 
static const char * chipid_archnames (unsigned value)
 Return the chip architecture name. More...
 
static const char * chipid_eproc_name (int idx)
 Return the chip ID name. More...
 
static const char * chipid_nvpsize (int idx)
 Return the non volatile programmable memory size. More...
 
static const char * chipid_sramsize (int idx)
 Return the chip SRAM size. More...
 

Variables

static const char _unknown [] = "unknown"
 
static sys_sem_t cgi_sem
 
HttpCGI cgi_table []
 
static struct archnames chip_id_archnames []
 
static const char *const chip_id_eproc_names []
 
static const char *const chip_id_nvpsize []
 
static const char *const chip_id_sramsize []
 
static int8_t freertos_stats [FREERTOS_STATS_BUFLEN]
 
static uint8_t tx_buf [TX_REQ_BUFLEN]
 

#define CGI_MATCH_EXT   2 /* Select item in table if the extention match */

Referenced by cgi_search().

#define CGI_MATCH_NAME   3 /* Select item in table if the string is content */

Referenced by cgi_search().

#define CGI_MATCH_NONE   0
#define CGI_MATCH_WORD   1 /* Select item in table only if string match */
#define CHIPID_ARCH
Value:
(((CHIPID->CHIPID_CIDR) & \
CHIPID_CIDR_ARCH_Msk) >> CHIPID_CIDR_ARCH_Pos)

Referenced by cgi_chipInfo().

#define CHIPID_EPRCOC
Value:
(((CHIPID->CHIPID_CIDR) & \
CHIPID_CIDR_EPROC_Msk) >> CHIPID_CIDR_EPROC_Pos)

Referenced by cgi_chipInfo().

#define CHIPID_NVPSIZ
Value:
(((CHIPID->CHIPID_CIDR) & \
CHIPID_CIDR_NVPSIZ_Msk) >> CHIPID_CIDR_NVPSIZ_Pos)

Referenced by cgi_chipInfo().

#define CHIPID_NVTYP
Value:
(((CHIPID->CHIPID_CIDR) & \
CHIPID_CIDR_NVPTYP_Msk) >> CHIPID_CIDR_NVPTYP_Pos)
#define CHIPID_SRAMSIZ
Value:
(((CHIPID->CHIPID_CIDR) & \
CHIPID_CIDR_SRAMSIZ_Msk) >> CHIPID_CIDR_SRAMSIZ_Pos)

Referenced by cgi_chipInfo().

#define FREERTOS_STATS_BUFLEN   512

Referenced by cgi_status().

#define IP_ADDR_TO_INT_TUPLE (   addr)
Value:
(int)((addr) >> 0 & 0xff), \
(int)((addr) >> 8 & 0xff), \
(int)((addr) >> 16 & 0xff), \
(int)((addr) >> 24 & 0xff)
struct sockaddr_in addr
Definition: common/components/wifi/winc3400/simple_roaming_udp_client_example/main.c:153

Referenced by cgi_status().

#define LWIP_MEMPOOL (   name,
  num,
  size,
  desc 
)    desc,
#define TX_REQ_BUFLEN   1024

static int cgi_chipInfo ( struct netconn *  client,
const char *  name,
char *  recv_buf,
size_t  recv_len 
)
static

Send the chip ID information.

Parameters
nameNot used.
recv_bufReceive buffer.
recv_lenReceive buffer length.
Returns
0.

References CHIPID_ARCH, chipid_archnames(), CHIPID_EPRCOC, chipid_eproc_name(), CHIPID_NVPSIZ, chipid_nvpsize, CHIPID_SRAMSIZ, chipid_sramsize, HTTP_CONTENT_JSON, http_sendOk(), sys_arch_sem_wait(), sys_sem_signal(), and tx_buf.

static int cgi_error ( struct netconn *  client,
const char *  name,
char *  recv_buf,
size_t  recv_len 
)
static

Used to handle unsupported CGI requests.

Parameters
nameNot used.
recv_bufReceive buffer.
recv_lenReceive buffer length.
Returns
-1.
http_handler_t cgi_search ( const char *  name,
HttpCGI table 
)

CGI request search engine.

Parameters
nameCGI request name.
tableCGI handler table.
Returns
A valid function handler for the specified CGI request, NULL otherwise.

References CGI_MATCH_EXT, CGI_MATCH_NAME, get_ext(), HttpCGI::handler, NULL, sys_sem_new(), and sys_sem_valid().

Referenced by http_request().

static int cgi_status ( struct netconn *  client,
const char *  name,
char *  recv_buf,
size_t  recv_len 
)
static

Send a JSON string representing the board status.

Parameters
nameNot used.
recv_bufReceive buffer.
recv_lenReceive buffer length.
Returns
0.

References freertos_stats, FREERTOS_STATS_BUFLEN, HTTP_CONTENT_JSON, http_sendOk(), IP_ADDR_TO_INT_TUPLE, MEMP_MAX, status, sys_arch_sem_wait(), sys_sem_signal(), tx_buf, vTaskGetRunTimeStats(), and xTaskGetTickCount().

static const char* chipid_archnames ( unsigned  value)
static

Return the chip architecture name.

Parameters
idxIndex in the chip_id_archnames table.
Returns
The chip architecture name.

References _unknown, chip_id_archnames, and archnames::name.

Referenced by cgi_chipInfo().

static const char* chipid_eproc_name ( int  idx)
static

Return the chip ID name.

Parameters
idxIndex in the chip_id_eproc_names table.
Returns
The chip id name.

References _unknown, and chip_id_eproc_names.

Referenced by cgi_chipInfo().

static const char* chipid_nvpsize ( int  idx)
static

Return the non volatile programmable memory size.

Parameters
idxIndex in the chip_id_nvpsize table.
Returns
The chip non volatile programmable memory size.

References _unknown, and chip_id_nvpsize.

static const char* chipid_sramsize ( int  idx)
static

Return the chip SRAM size.

Parameters
idxIndex in the chip_id_sramsize table.
Returns
The chip SRAM size.

References _unknown, and chip_id_sramsize.

const char _unknown[] = "unknown"
static
sys_sem_t cgi_sem
static
HttpCGI cgi_table[]
Initial value:
= {
{ CGI_MATCH_NAME, "error", cgi_error },
{ CGI_MATCH_NAME, "status", cgi_status },
{ CGI_MATCH_NAME, "get_chipinfo", cgi_chipInfo },
{ CGI_MATCH_NONE, NULL, NULL }
}
static int cgi_chipInfo(struct netconn *client, const char *name, char *recv_buf, size_t recv_len)
Send the chip ID information.
Definition: cgi.c:386
static int cgi_status(struct netconn *client, const char *name, char *recv_buf, size_t recv_len)
Send a JSON string representing the board status.
Definition: cgi.c:212
#define CGI_MATCH_NAME
Definition: cgi.c:51
#define CGI_MATCH_NONE
Definition: cgi.c:48
#define NULL
Definition: wilc/bsp/include/nm_bsp.h:70
static int cgi_error(struct netconn *client, const char *name, char *recv_buf, size_t recv_len)
Used to handle unsupported CGI requests.
Definition: cgi.c:193

Referenced by http_request().

struct archnames chip_id_archnames[]
static

Referenced by chipid_archnames().

const char* const chip_id_eproc_names[]
static
Initial value:
= {
"arm946es",
"arm7tdmi",
"cortex-m3",
"arm920t",
"arm926ejs",
"cortex-a5",
"cortex-m4"
}
static const char _unknown[]
Definition: cgi.c:71

Referenced by chipid_eproc_name().

const char* const chip_id_nvpsize[]
static
Initial value:
= {
"none",
"8K bytes",
"16K bytes",
"32K bytes",
"64K bytes",
"128K bytes",
"256K bytes",
"512K bytes",
"1024K bytes",
"2048K bytes",
}
static const char _unknown[]
Definition: cgi.c:71

Referenced by chipid_nvpsize().

const char* const chip_id_sramsize[]
static
Initial value:
= {
"48K bytes",
"1K bytes",
"2K bytes",
"6K bytes",
"112K bytes",
"4K bytes",
"80K bytes",
"160K bytes",
"8K bytes",
"16K bytes",
"32K bytes",
"64K bytes",
"128K bytes",
"256K bytes",
"96K bytes",
"512K bytes",
}

Referenced by chipid_sramsize().

int8_t freertos_stats[FREERTOS_STATS_BUFLEN]
static

Referenced by cgi_status().

uint8_t tx_buf[TX_REQ_BUFLEN]
static

Referenced by cgi_chipInfo(), and cgi_status().