54#define LOG_MODULE "BR"
55#define LOG_LEVEL LOG_LEVEL_NONE
57uint8_t command_context;
59void packet_sent(uint8_t sessionid, uint8_t status, uint8_t tx);
60void nbr_print_stat(
void);
63PROCESS(border_router_cmd_process,
"Border router cmd process");
66hextoi(
const uint8_t *buf,
int len)
69 for(; len > 0; len--, buf++) {
70 if(*buf >=
'0' && *buf <=
'9') {
71 v = (v << 4) + ((*buf -
'0') & 0xf);
72 }
else if(*buf >=
'a' && *buf <=
'f') {
73 v = (v << 4) + ((*buf -
'a' + 10) & 0xf);
74 }
else if(*buf >=
'A' && *buf <=
'F') {
75 v = (v << 4) + ((*buf -
'A' + 10) & 0xf);
84dectoi(
const uint8_t *buf,
int len)
91 return hextoi(buf + 1, len - 1);
93 if(*buf ==
'0' && *(buf + 1) ==
'x' && len > 2) {
94 return hextoi(buf + 2, len - 2);
101 for(; len > 0; len--, buf++) {
102 if(*buf <
'0' || *buf >
'9') {
105 v = (v * 10) + ((*buf -
'0') & 0xf);
107 return negative ? -v : v;
116border_router_cmd_handler(
const uint8_t *data,
int len)
120 LOG_DBG(
"Got configuration message of type %c\n", data[1]);
121 if(command_context == CMD_CONTEXT_STDIO) {
125 printf(
"Performing Global Repair...\n");
126 NETSTACK_ROUTING.global_repair(
"Command");
129 int channel = dectoi(&data[2], len - 2);
130#if BORDER_ROUTER_SERIAL_RADIO
134 set_param[5] = channel & 0xff;
135 write_to_slip(set_param,
sizeof(set_param));
140 int pan_id = dectoi(&data[2], len - 2);
141#if BORDER_ROUTER_SERIAL_RADIO
145 set_param[4] = (pan_id >> 8) & 0xff;
146 set_param[5] = pan_id & 0xff;
147 write_to_slip(set_param,
sizeof(set_param));
154 }
else if(command_context == CMD_CONTEXT_RADIO) {
158 LOG_DBG(
"Setting MAC address\n");
159 border_router_set_mac(&data[2]);
163 printf(
"Channel is %d\n", data[5]);
166 printf(
"PAN_ID is 0x%04x\n", (data[4] << 8) + data[5]);
170 LOG_DBG(
"Packet data report for sid:%d st:%d tx:%d\n",
171 data[2], data[3], data[4]);
178 }
else if(data[0] ==
'?') {
179 LOG_DBG(
"Got request message of type %c\n", data[1]);
180 if(data[1] ==
'M' && command_context == CMD_CONTEXT_STDIO) {
182 char *hexchar =
"0123456789abcdef";
188 buf[2 + j * 2] = hexchar[
uip_lladdr.addr[j] >> 4];
189 buf[3 + j * 2] = hexchar[
uip_lladdr.addr[j] & 15];
193 }
else if(data[1] ==
'C' && command_context == CMD_CONTEXT_STDIO) {
196 write_to_slip(set_param,
sizeof(set_param));
198 }
else if(data[1] ==
'P' && command_context == CMD_CONTEXT_STDIO) {
201 write_to_slip(set_param,
sizeof(set_param));
203 }
else if(data[1] ==
'S') {
204 border_router_print_stat();
212border_router_cmd_output(
const uint8_t *data,
int data_len)
215 printf(
"CMD output: ");
216 for(i = 0; i < data_len; i++) {
217 printf(
"%c", data[i]);
223serial_shell_output(
const char *str)
237 static struct pt shell_input_pt;
244 if(ev == serial_line_event_message && data != NULL) {
245 LOG_DBG(
"Got serial data!!! %s of len: %zd\n",
246 (
char *)data, strlen((
char *)data));
247 command_context = CMD_CONTEXT_STDIO;
248 if(!cmd_input(data, strlen((
char *)data))) {
CBOR-over-SLIP protocol for talking to the serialradio firmware (examples/serialradio) from the nativ...
void br_cbor_send_set_param(uint8_t msg_id, uint16_t param, int32_t value)
Set a radio parameter on the serial radio (SET_PARAM).
void serial_shell_init(void)
Initializes Serial Shell module.
Sets up some commands for the border router.
Border router header file.
#define PROCESS(name, strname)
Declare a process.
#define PROCESS_PT_SPAWN(pt, thread)
Spawn a protothread from the process.
#define PROCESS_BEGIN()
Define the beginning of a process.
#define PROCESS_END()
Define the end of a process.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_YIELD()
Yield the currently running process.
@ RADIO_PARAM_CHANNEL
Channel used for radio communication.
@ RADIO_PARAM_PAN_ID
The personal area network identifier (PAN ID), which is used by the h/w frame filtering functionality...
void shell_init(void)
Initializes Shell module.
char shell_input(struct pt *pt, shell_output_func output, const char *cmd)
A protothread that is spawned by a Shell driver when receiving a new line.
static void packet_sent(void *ptr, int status, int transmissions)
Callback function for the MAC packet sent callback.
uip_lladdr_t uip_lladdr
Host L2 address.
#define UIP_LLADDR_LEN
802.15.4 address
Header file for the logging system.
Header file for the radio API.
Routing driver header file.
Generic serial I/O process header filer.
Main header file for the Contiki shell.
Header file for the IP address manipulation library.