52#define LOG_MODULE "BR"
53#define LOG_LEVEL LOG_LEVEL_NONE
55uint8_t command_context;
57void packet_sent(uint8_t sessionid, uint8_t status, uint8_t tx);
58void nbr_print_stat(
void);
61PROCESS(border_router_cmd_process,
"Border router cmd process");
64hextoi(
const uint8_t *buf,
int len)
67 for(; len > 0; len--, buf++) {
68 if(*buf >=
'0' && *buf <=
'9') {
69 v = (v << 4) + ((*buf -
'0') & 0xf);
70 }
else if(*buf >=
'a' && *buf <=
'f') {
71 v = (v << 4) + ((*buf -
'a' + 10) & 0xf);
72 }
else if(*buf >=
'A' && *buf <=
'F') {
73 v = (v << 4) + ((*buf -
'A' + 10) & 0xf);
82dectoi(
const uint8_t *buf,
int len)
89 return hextoi(buf + 1, len - 1);
91 if(*buf ==
'0' && *(buf + 1) ==
'x' && len > 2) {
92 return hextoi(buf + 2, len - 2);
99 for(; len > 0; len--, buf++) {
100 if(*buf <
'0' || *buf >
'9') {
103 v = (v * 10) + ((*buf -
'0') & 0xf);
105 return negative ? -v : v;
114border_router_cmd_handler(
const uint8_t *data,
int len)
118 LOG_DBG(
"Got configuration message of type %c\n", data[1]);
119 if(command_context == CMD_CONTEXT_STDIO) {
123 printf(
"Performing Global Repair...\n");
129 int channel = dectoi(&data[2], len - 2);
130 set_param[5] = channel & 0xff;
131 write_to_slip(set_param,
sizeof(set_param));
137 int pan_id = dectoi(&data[2], len - 2);
138 set_param[4] = (pan_id >> 8) & 0xff;
139 set_param[5] = pan_id & 0xff;
140 write_to_slip(set_param,
sizeof(set_param));
146 }
else if(command_context == CMD_CONTEXT_RADIO) {
150 LOG_DBG(
"Setting MAC address\n");
151 border_router_set_mac(&data[2]);
155 printf(
"Channel is %d\n", data[5]);
158 printf(
"PAN_ID is 0x%04x\n", (data[4] << 8) + data[5]);
162 LOG_DBG(
"Packet data report for sid:%d st:%d tx:%d\n",
163 data[2], data[3], data[4]);
164 packet_sent(data[2], data[3], data[4]);
170 }
else if(data[0] ==
'?') {
171 LOG_DBG(
"Got request message of type %c\n", data[1]);
172 if(data[1] ==
'M' && command_context == CMD_CONTEXT_STDIO) {
174 char *hexchar =
"0123456789abcdef";
180 buf[2 + j * 2] = hexchar[
uip_lladdr.addr[j] >> 4];
181 buf[3 + j * 2] = hexchar[
uip_lladdr.addr[j] & 15];
185 }
else if(data[1] ==
'C' && command_context == CMD_CONTEXT_STDIO) {
188 write_to_slip(set_param,
sizeof(set_param));
190 }
else if(data[1] ==
'P' && command_context == CMD_CONTEXT_STDIO) {
193 write_to_slip(set_param,
sizeof(set_param));
195 }
else if(data[1] ==
'S') {
196 border_router_print_stat();
204border_router_cmd_output(
const uint8_t *data,
int data_len)
207 printf(
"CMD output: ");
208 for(i = 0; i < data_len; i++) {
209 printf(
"%c", data[i]);
215serial_shell_output(
const char *str)
223 static struct pt shell_input_pt;
230 if(ev == serial_line_event_message && data != NULL) {
231 LOG_DBG(
"Got serial data!!! %s of len: %zd\n",
232 (
char *)data, strlen((
char *)data));
233 command_context = CMD_CONTEXT_STDIO;
234 if(!cmd_input(data, strlen((
char *)data))) {
237 shell_input(&shell_input_pt, serial_shell_output,
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.
uip_lladdr_t uip_lladdr
Host L2 address.
#define UIP_LLADDR_LEN
802.15.4 address
Header file for the logging system.
Routing driver header file.
Generic serial I/O process header filer.
Main header file for the Contiki shell.
void(* global_repair)(const char *str)
Triggers a global topology repair.
Header file for the IP address manipulation library.