52 #define LOG_MODULE "BR" 53 #define LOG_LEVEL LOG_LEVEL_NONE 55 uint8_t command_context;
57 void packet_sent(uint8_t sessionid, uint8_t status, uint8_t tx);
58 void nbr_print_stat(
void);
61 PROCESS(border_router_cmd_process,
"Border router cmd process");
63 static const uint8_t *
64 hextoi(
const uint8_t *buf,
int len,
int *v)
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);
81 static const uint8_t *
82 dectoi(
const uint8_t *buf,
int len,
int *v)
90 return hextoi(buf + 1, len - 1, v);
92 if(*buf ==
'0' && *(buf + 1) ==
'x' && len > 2) {
93 return hextoi(buf + 2, len - 2, v);
99 for(; len > 0; len--, buf++) {
100 if(*buf < '0' || *buf >
'9') {
103 *v = (*v * 10) + ((*buf -
'0') & 0xf);
117 border_router_cmd_handler(
const uint8_t *data,
int len)
121 LOG_DBG(
"Got configuration message of type %c\n", data[1]);
122 if(command_context == CMD_CONTEXT_STDIO) {
126 printf(
"Performing Global Repair...\n");
133 dectoi(&data[2], len - 2, &channel);
135 set_param[5] = channel & 0xff;
136 write_to_slip(set_param,
sizeof(set_param));
144 dectoi(&data[2], len - 2, &pan_id);
145 set_param[4] = (pan_id >> 8) & 0xff;
146 set_param[5] = pan_id & 0xff;
147 write_to_slip(set_param,
sizeof(set_param));
153 }
else if(command_context == CMD_CONTEXT_RADIO) {
157 LOG_DBG(
"Setting MAC address\n");
158 border_router_set_mac(&data[2]);
162 printf(
"Channel is %d\n", data[5]);
165 printf(
"PAN_ID is 0x%04x\n", (data[4] << 8) + data[5]);
169 LOG_DBG(
"Packet data report for sid:%d st:%d tx:%d\n",
170 data[2], data[3], data[4]);
177 }
else if(data[0] ==
'?') {
178 LOG_DBG(
"Got request message of type %c\n", data[1]);
179 if(data[1] ==
'M' && command_context == CMD_CONTEXT_STDIO) {
181 char *hexchar =
"0123456789abcdef";
187 buf[2 + j * 2] = hexchar[
uip_lladdr.addr[j] >> 4];
188 buf[3 + j * 2] = hexchar[
uip_lladdr.addr[j] & 15];
192 }
else if(data[1] ==
'C' && command_context == CMD_CONTEXT_STDIO) {
195 write_to_slip(set_param,
sizeof(set_param));
197 }
else if(data[1] ==
'P' && command_context == CMD_CONTEXT_STDIO) {
200 write_to_slip(set_param,
sizeof(set_param));
202 }
else if(data[1] ==
'S') {
203 border_router_print_stat();
211 border_router_cmd_output(
const uint8_t *data,
int data_len)
214 printf(
"CMD output: ");
215 for(i = 0; i < data_len; i++) {
216 printf(
"%c", data[i]);
222 serial_shell_output(
const char *str)
230 static struct pt shell_input_pt;
238 LOG_DBG(
"Got serial data!!! %s of len: %u\n",
239 (
char *)data, (
unsigned)strlen((
char *)data));
240 command_context = CMD_CONTEXT_STDIO;
241 if(cmd_input(data, strlen((
char *)data))) {
245 PROCESS_PT_SPAWN(&shell_input_pt, shell_input(&shell_input_pt, serial_shell_output, data));
uip_lladdr_t uip_lladdr
Host L2 address.
#define PROCESS(name, strname)
Declare a process.
Main header file for the Contiki shell
Border router header file
#define PROCESS_BEGIN()
Define the beginning of a process.
#define PROCESS_END()
Define the end of a process.
static void packet_sent(void *ptr, int status, int transmissions)
Callback function for the MAC packet sent callback.
Channel used for radio communication.
void(* global_repair)(const char *str)
Triggers a global topology repair.
#define UIP_LLADDR_LEN
802.15.4 address
Header file for the IP address manipulation library.
The personal area network identifier (PAN ID), which is used by the h/w frame filtering functionality...
Routing driver header file
#define PROCESS_YIELD()
Yield the currently running process.
void shell_init(void)
Initializes Shell module.
Sets up some commands for the border router
process_event_t serial_line_event_message
Event posted when a line of input has been received.
Generic serial I/O process header filer.
#define PROCESS_PT_SPAWN(pt, thread)
Spawn a protothread from the process.
PROCESS_THREAD(cc2538_rf_process, ev, data)
Implementation of the cc2538 RF driver process.
Header file for the logging system