Microchip® Advanced Software Framework

websocket.c File Reference
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include "contiki-net.h"
#include "websocket-http-client.h"
#include "cfs/cfs.h"
#include "lib/petsciiconv.h"
#include "mdns.h"
#include "websocket.h"
#include "net/ip/uip-debug.h"

Data Structures

struct  websocket_frame_hdr
 
struct  websocket_frame_mask
 

Macros

#define _DEBUG_   DEBUG_NONE
 
#define MAX_HOSTLEN   16
 
#define MAX_PATHLEN   100
 
#define MIN(a, b)   ((a) < (b)? (a): (b))
 
#define WEBSOCKET_FIN_BIT   0x80
 
#define WEBSOCKET_LEN_MASK   0x7f
 
#define WEBSOCKET_MASK_BIT   0x80
 
#define WEBSOCKET_OPCODE_BIN   0x02
 
#define WEBSOCKET_OPCODE_CLOSE   0x08
 
#define WEBSOCKET_OPCODE_CONT   0x00
 
#define WEBSOCKET_OPCODE_MASK   0x0f
 
#define WEBSOCKET_OPCODE_PING   0x09
 
#define WEBSOCKET_OPCODE_PONG   0x0a
 
#define WEBSOCKET_OPCODE_TEXT   0x01
 

Functions

static void call (struct websocket *s, websocket_result r, uint8_t *data, uint16_t datalen)
 
 LIST (websocketlist)
 
static int parse_url (const char *url, char *host, uint16_t *portptr, char *path)
 
 PROCESS (websocket_process,"Websockets process")
 
 PROCESS_THREAD (websocket_process, ev, data)
 
static int receive_header_byte (struct websocket *s, uint8_t byte)
 
static int send_data (struct websocket *s, const void *data, uint16_t datalen, uint8_t data_type_opcode)
 
static int start_get (struct websocket *s)
 
void websocket_close (struct websocket *s)
 
void websocket_http_client_aborted (struct websocket_http_client_state *client_state)
 
void websocket_http_client_closed (struct websocket_http_client_state *client_state)
 
void websocket_http_client_connected (struct websocket_http_client_state *client_state)
 
void websocket_http_client_datahandler (struct websocket_http_client_state *client_state, uint8_t *data, uint16_t datalen)
 
void websocket_http_client_timedout (struct websocket_http_client_state *client_state)
 
void websocket_init (void)
 
websocket_result websocket_open (struct websocket *s, const char *url, const char *subprotocol, websocket_callback c)
 
int websocket_ping (struct websocket *s)
 
int websocket_send (struct websocket *s, const uint8_t *data, uint16_t datalen)
 
int websocket_send_str (struct websocket *s, const char *str)
 

Variables

static uint8_t inited = 0
 

#define _DEBUG_   DEBUG_NONE
#define MAX_HOSTLEN   16
#define MAX_PATHLEN   100

Referenced by parse_url(), and start_get().

#define MIN (   a,
 
)    ((a) < (b)? (a): (b))
#define WEBSOCKET_FIN_BIT   0x80

Referenced by send_data(), and websocket_ping().

#define WEBSOCKET_LEN_MASK   0x7f
#define WEBSOCKET_MASK_BIT   0x80
#define WEBSOCKET_OPCODE_BIN   0x02
#define WEBSOCKET_OPCODE_CLOSE   0x08
#define WEBSOCKET_OPCODE_CONT   0x00
#define WEBSOCKET_OPCODE_MASK   0x0f
#define WEBSOCKET_OPCODE_PING   0x09
#define WEBSOCKET_OPCODE_PONG   0x0a
#define WEBSOCKET_OPCODE_TEXT   0x01

LIST ( websocketlist  )
static int parse_url ( const char *  url,
char *  host,
uint16_t *  portptr,
char *  path 
)
static
PROCESS ( websocket_process  ,
"Websockets process  
)
void websocket_close ( struct websocket s)
void websocket_http_client_aborted ( struct websocket_http_client_state client_state)
void websocket_http_client_closed ( struct websocket_http_client_state client_state)
void websocket_http_client_connected ( struct websocket_http_client_state client_state)
void websocket_http_client_timedout ( struct websocket_http_client_state client_state)
void websocket_init ( void  )

References inited, list_init(), NULL, and process_start().

Referenced by websocket_open().

int websocket_send ( struct websocket s,
const uint8_t *  data,
uint16_t  datalen 
)

References send_data, and WEBSOCKET_OPCODE_BIN.

int websocket_send_str ( struct websocket s,
const char *  str 
)

References send_data, and WEBSOCKET_OPCODE_TEXT.

uint8_t inited = 0
static