fixed coding style (space after most keywords)

This commit is contained in:
Oliver Hahm 2013-06-24 22:37:35 +02:00
parent 5bae4f841d
commit c8bee9e554
112 changed files with 1914 additions and 1914 deletions

View File

@ -31,7 +31,7 @@ number_of_highest_bit(unsigned v)
r |= (v >> 1); r |= (v >> 1);
#else #else
r = 0; r = 0;
while(v >>= 1) { // unroll for more speed... while (v >>= 1) { // unroll for more speed...
r++; r++;
} }
@ -45,7 +45,7 @@ number_of_lowest_bit(register unsigned v)
{ {
register unsigned r = 0; register unsigned r = 0;
while((v & 0x01) == 0) { while ((v & 0x01) == 0) {
v >>= 1; v >>= 1;
r++; r++;
}; };
@ -58,7 +58,7 @@ number_of_bits_set(unsigned v)
{ {
unsigned c; // c accumulates the total bits set in v unsigned c; // c accumulates the total bits set in v
for(c = 0; v; c++) { for (c = 0; v; c++) {
v &= v - 1; // clear the least significant bit set v &= v - 1; // clear the least significant bit set
} }

View File

@ -16,7 +16,7 @@ int cib_get(cib_t *cib)
{ {
int avail = cib_avail(cib); int avail = cib_avail(cib);
if(avail > 0) { if (avail > 0) {
return (int)(cib->read_count++ & ~cib->complement); return (int)(cib->read_count++ & ~cib->complement);
} }
@ -27,7 +27,7 @@ int cib_put(cib_t *cib)
{ {
int avail = cib_avail(cib); int avail = cib_avail(cib);
if((int)(avail + cib->complement) < 0) { if ((int)(avail + cib->complement) < 0) {
return (int)(cib->write_count++ & ~(cib->complement)); return (int)(cib->write_count++ & ~(cib->complement));
} }

View File

@ -21,13 +21,13 @@
/* inserts new_node after node */ /* inserts new_node after node */
void clist_add(clist_node_t **node, clist_node_t *new_node) void clist_add(clist_node_t **node, clist_node_t *new_node)
{ {
if(*node != NULL) { if (*node != NULL) {
new_node->next = (*node); new_node->next = (*node);
new_node->prev = (*node)->prev; new_node->prev = (*node)->prev;
(*node)->prev->next = new_node; (*node)->prev->next = new_node;
(*node)->prev = new_node; (*node)->prev = new_node;
if((*node)->prev == *node) { if ((*node)->prev == *node) {
(*node)->prev = new_node; (*node)->prev = new_node;
} }
} }
@ -41,11 +41,11 @@ void clist_add(clist_node_t **node, clist_node_t *new_node)
/* removes node. */ /* removes node. */
void clist_remove(clist_node_t **list, clist_node_t *node) void clist_remove(clist_node_t **list, clist_node_t *node)
{ {
if(node->next != node) { if (node->next != node) {
node->prev->next = node->next; node->prev->next = node->next;
node->next->prev = node->prev; node->next->prev = node->prev;
if(node == *list) { if (node == *list) {
*list = node->next; *list = node->next;
} }
} }
@ -58,11 +58,11 @@ void clist_print(clist_node_t *clist)
{ {
clist_node_t *start = clist; clist_node_t *start = clist;
while(clist != NULL) { while (clist != NULL) {
printf("list entry: %u prev=%u next=%u\n", clist->data, clist->prev->data, clist->next->data); printf("list entry: %u prev=%u next=%u\n", clist->data, clist->prev->data, clist->next->data);
clist = clist->next; clist = clist->next;
if(clist == start) { if (clist == start) {
break; break;
} }
} }

View File

@ -55,9 +55,9 @@ void hwtimer_spin(unsigned long ticks)
{ {
unsigned long co = hwtimer_arch_now() + ticks; unsigned long co = hwtimer_arch_now() + ticks;
while(hwtimer_arch_now() > co); while (hwtimer_arch_now() > co);
while(hwtimer_arch_now() < co); while (hwtimer_arch_now() < co);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -75,7 +75,7 @@ void hwtimer_init_comp(uint32_t fcpu)
lifo_init(lifo, ARCH_MAXTIMERS); lifo_init(lifo, ARCH_MAXTIMERS);
for(int i = 0; i < ARCH_MAXTIMERS; i++) { for (int i = 0; i < ARCH_MAXTIMERS; i++) {
lifo_insert(lifo, i); lifo_insert(lifo, i);
} }
} }
@ -84,7 +84,7 @@ void hwtimer_init_comp(uint32_t fcpu)
int hwtimer_active(void) int hwtimer_active(void)
{ {
return (! lifo_empty(lifo)); return (!lifo_empty(lifo));
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -98,7 +98,7 @@ unsigned long hwtimer_now(void)
void hwtimer_wait(unsigned long ticks) void hwtimer_wait(unsigned long ticks)
{ {
if(ticks <= 6 || inISR()) { if (ticks <= 6 || inISR()) {
hwtimer_spin(ticks); hwtimer_spin(ticks);
return; return;
} }
@ -106,7 +106,7 @@ void hwtimer_wait(unsigned long ticks)
/* -2 is to adjust the real value */ /* -2 is to adjust the real value */
int res = hwtimer_set(ticks - 2, hwtimer_wakeup, (void*)(unsigned int)(active_thread->pid)); int res = hwtimer_set(ticks - 2, hwtimer_wakeup, (void*)(unsigned int)(active_thread->pid));
if(res == -1) { if (res == -1) {
hwtimer_spin(ticks); hwtimer_spin(ticks);
return; return;
} }
@ -119,14 +119,14 @@ void hwtimer_wait(unsigned long ticks)
static int _hwtimer_set(unsigned long offset, void (*callback)(void*), void *ptr, bool absolute) static int _hwtimer_set(unsigned long offset, void (*callback)(void*), void *ptr, bool absolute)
{ {
if(!inISR()) { if (!inISR()) {
dINT(); dINT();
} }
int n = lifo_get(lifo); int n = lifo_get(lifo);
if(n == -1) { if (n == -1) {
if(! inISR()) { if (!inISR()) {
eINT(); eINT();
} }
@ -137,7 +137,7 @@ static int _hwtimer_set(unsigned long offset, void (*callback)(void*), void *ptr
timer[n].callback = callback; timer[n].callback = callback;
timer[n].data = ptr; timer[n].data = ptr;
if(absolute) { if (absolute) {
hwtimer_arch_set_absolute(offset, n); hwtimer_arch_set_absolute(offset, n);
} }
else { else {
@ -146,7 +146,7 @@ static int _hwtimer_set(unsigned long offset, void (*callback)(void*), void *ptr
lpm_prevent_sleep++; lpm_prevent_sleep++;
if(!inISR()) { if (!inISR()) {
eINT(); eINT();
} }

View File

@ -94,7 +94,7 @@ int msg_receive(msg_t *m);
* @brief Send a message, block until reply received. * @brief Send a message, block until reply received.
* *
* This function sends a message to target_pid and then blocks until target has sent a reply. * This function sends a message to target_pid and then blocks until target has sent a reply.
* @note CAUTION! Use this function only when receiver is already waiting. If not use simple msg_send() * @note CAUTION!Use this function only when receiver is already waiting. If not use simple msg_send()
* @param m pointer to preallocated msg * @param m pointer to preallocated msg
* @param reply pointer to preallocated msg. Reply will be written here. * @param reply pointer to preallocated msg. Reply will be written here.
* @param target pid the pid of the target process * @param target pid the pid of the target process

View File

@ -42,8 +42,8 @@ extern int main(void);
static void idle_thread(void) static void idle_thread(void)
{ {
while(1) { while (1) {
if(lpm_prevent_sleep) { if (lpm_prevent_sleep) {
lpm_set(LPM_IDLE); lpm_set(LPM_IDLE);
} }
else { else {
@ -73,11 +73,11 @@ void kernel_init(void)
sched_init(); sched_init();
if(thread_create(idle_stack, sizeof(idle_stack), PRIORITY_IDLE, CREATE_WOUT_YIELD | CREATE_STACKTEST, idle_thread, idle_name) < 0) { if (thread_create(idle_stack, sizeof(idle_stack), PRIORITY_IDLE, CREATE_WOUT_YIELD | CREATE_STACKTEST, idle_thread, idle_name) < 0) {
printf("kernel_init(): error creating idle task.\n"); printf("kernel_init(): error creating idle task.\n");
} }
if(thread_create(main_stack, sizeof(main_stack), PRIORITY_MAIN, CREATE_WOUT_YIELD | CREATE_STACKTEST, MAIN_FUNC, main_name) < 0) { if (thread_create(main_stack, sizeof(main_stack), PRIORITY_MAIN, CREATE_WOUT_YIELD | CREATE_STACKTEST, MAIN_FUNC, main_name) < 0) {
printf("kernel_init(): error creating main task.\n"); printf("kernel_init(): error creating main task.\n");
} }

View File

@ -7,7 +7,7 @@ int lifo_empty(int *array)
void lifo_init(int *array, int n) void lifo_init(int *array, int n)
{ {
for(int i = 0; i <= n; i++) { for (int i = 0; i <= n; i++) {
array[i] = -1; array[i] = -1;
} }
} }
@ -23,7 +23,7 @@ int lifo_get(int *array)
{ {
int head = array[0]; int head = array[0];
if(head != -1) { if (head != -1) {
array[0] = array[head + 1]; array[0] = array[head + 1];
} }

View File

@ -32,7 +32,7 @@ static int queue_msg(tcb_t *target, msg_t *m)
{ {
int n = cib_put(&(target->msg_queue)); int n = cib_put(&(target->msg_queue));
if(n != -1) { if (n != -1) {
target->msg_array[n] = *m; target->msg_array[n] = *m;
return 1; return 1;
} }
@ -42,7 +42,7 @@ static int queue_msg(tcb_t *target, msg_t *m)
int msg_send(msg_t *m, unsigned int target_pid, bool block) int msg_send(msg_t *m, unsigned int target_pid, bool block)
{ {
if(inISR()) { if (inISR()) {
return msg_send_int(m, target_pid); return msg_send_int(m, target_pid);
} }
@ -50,23 +50,23 @@ int msg_send(msg_t *m, unsigned int target_pid, bool block)
m->sender_pid = thread_pid; m->sender_pid = thread_pid;
if(m->sender_pid == target_pid) { if (m->sender_pid == target_pid) {
return -1; return -1;
} }
if(target == NULL) { if (target == NULL) {
return -1; return -1;
} }
dINT(); dINT();
if(target->status != STATUS_RECEIVE_BLOCKED) { if (target->status != STATUS_RECEIVE_BLOCKED) {
if(target->msg_array && queue_msg(target, m)) { if (target->msg_array && queue_msg(target, m)) {
eINT(); eINT();
return 1; return 1;
} }
if(!block) { if (!block) {
DEBUG("%s: receiver not waiting. block=%u\n", active_thread->name, block); DEBUG("%s: receiver not waiting. block=%u\n", active_thread->name, block);
eINT(); eINT();
return 0; return 0;
@ -84,7 +84,7 @@ int msg_send(msg_t *m, unsigned int target_pid, bool block)
int newstatus; int newstatus;
if(active_thread->status == STATUS_REPLY_BLOCKED) { if (active_thread->status == STATUS_REPLY_BLOCKED) {
newstatus = STATUS_REPLY_BLOCKED; newstatus = STATUS_REPLY_BLOCKED;
} }
else { else {
@ -113,7 +113,7 @@ int msg_send_int(msg_t *m, unsigned int target_pid)
{ {
tcb_t *target = (tcb_t *) sched_threads[target_pid]; tcb_t *target = (tcb_t *) sched_threads[target_pid];
if(target->status == STATUS_RECEIVE_BLOCKED) { if (target->status == STATUS_RECEIVE_BLOCKED) {
DEBUG("msg_send_int: direct msg copy from %i to %i.\n", thread_getpid(), target_pid); DEBUG("msg_send_int: direct msg copy from %i to %i.\n", thread_getpid(), target_pid);
m->sender_pid = target_pid; m->sender_pid = target_pid;
@ -151,7 +151,7 @@ int msg_reply(msg_t *m, msg_t *reply)
tcb_t *target = (tcb_t*) sched_threads[m->sender_pid]; tcb_t *target = (tcb_t*) sched_threads[m->sender_pid];
if(target->status != STATUS_REPLY_BLOCKED) { if (target->status != STATUS_REPLY_BLOCKED) {
DEBUG("%s: msg_reply(): target \"%s\" not waiting for reply.", active_thread->name, target->name); DEBUG("%s: msg_reply(): target \"%s\" not waiting for reply.", active_thread->name, target->name);
restoreIRQ(state); restoreIRQ(state);
return -1; return -1;
@ -172,7 +172,7 @@ int msg_reply_int(msg_t *m, msg_t *reply)
{ {
tcb_t *target = (tcb_t*) sched_threads[m->sender_pid]; tcb_t *target = (tcb_t*) sched_threads[m->sender_pid];
if(target->status != STATUS_REPLY_BLOCKED) { if (target->status != STATUS_REPLY_BLOCKED) {
DEBUG("%s: msg_reply_int(): target \"%s\" not waiting for reply.", active_thread->name, target->name); DEBUG("%s: msg_reply_int(): target \"%s\" not waiting for reply.", active_thread->name, target->name);
return -1; return -1;
} }
@ -193,11 +193,11 @@ int msg_receive(msg_t *m)
int n = -1; int n = -1;
if(me->msg_array) { if (me->msg_array) {
n = cib_get(&(me->msg_queue)); n = cib_get(&(me->msg_queue));
} }
if(n >= 0) { if (n >= 0) {
DEBUG("%s: msg_receive(): We've got a queued message.\n", active_thread->name); DEBUG("%s: msg_receive(): We've got a queued message.\n", active_thread->name);
*m = me->msg_array[n]; *m = me->msg_array[n];
} }
@ -207,10 +207,10 @@ int msg_receive(msg_t *m)
queue_node_t *node = queue_remove_head(&(me->msg_waiters)); queue_node_t *node = queue_remove_head(&(me->msg_waiters));
if(node == NULL) { if (node == NULL) {
DEBUG("%s: msg_receive(): No thread in waiting list.\n", active_thread->name); DEBUG("%s: msg_receive(): No thread in waiting list.\n", active_thread->name);
if(n < 0) { if (n < 0) {
DEBUG("%s: msg_receive(): No msg in queue. Going blocked.\n", active_thread->name); DEBUG("%s: msg_receive(): No msg in queue. Going blocked.\n", active_thread->name);
sched_set_status(me, STATUS_RECEIVE_BLOCKED); sched_set_status(me, STATUS_RECEIVE_BLOCKED);
@ -226,7 +226,7 @@ int msg_receive(msg_t *m)
DEBUG("%s: msg_receive(): Wakeing up waiting thread.\n", active_thread->name); DEBUG("%s: msg_receive(): Wakeing up waiting thread.\n", active_thread->name);
tcb_t *sender = (tcb_t*) node->data; tcb_t *sender = (tcb_t*) node->data;
if(n >= 0) { if (n >= 0) {
/* we've already got a messgage from the queue. as there is a /* we've already got a messgage from the queue. as there is a
* waiter, take it's message into the just freed queue space. * waiter, take it's message into the just freed queue space.
*/ */
@ -249,7 +249,7 @@ int msg_receive(msg_t *m)
int msg_init_queue(msg_t *array, int num) int msg_init_queue(msg_t *array, int num)
{ {
/* make sure brainfuck condition is met */ /* make sure brainfuck condition is met */
if(num && (num & (num - 1)) == 0) { if (num && (num & (num - 1)) == 0) {
tcb_t *me = (tcb_t*) active_thread; tcb_t *me = (tcb_t*) active_thread;
me->msg_array = array; me->msg_array = array;
cib_init(&(me->msg_queue), num); cib_init(&(me->msg_queue), num);

View File

@ -52,7 +52,7 @@ int mutex_lock(struct mutex_t *mutex)
{ {
DEBUG("%s: trying to get mutex. val: %u\n", active_thread->name, mutex->val); DEBUG("%s: trying to get mutex. val: %u\n", active_thread->name, mutex->val);
if(atomic_set_return(&mutex->val, 1) != 0) { if (atomic_set_return(&mutex->val, 1) != 0) {
/* mutex was locked. */ /* mutex was locked. */
mutex_wait(mutex); mutex_wait(mutex);
} }
@ -65,7 +65,7 @@ void mutex_wait(struct mutex_t *mutex)
int irqstate = disableIRQ(); int irqstate = disableIRQ();
DEBUG("%s: Mutex in use. %u\n", active_thread->name, mutex->val); DEBUG("%s: Mutex in use. %u\n", active_thread->name, mutex->val);
if(mutex->val == 0) { if (mutex->val == 0) {
/* somebody released the mutex. return. */ /* somebody released the mutex. return. */
mutex->val = thread_pid; mutex->val = thread_pid;
DEBUG("%s: mutex_wait early out. %u\n", active_thread->name, mutex->val); DEBUG("%s: mutex_wait early out. %u\n", active_thread->name, mutex->val);
@ -96,8 +96,8 @@ void mutex_unlock(struct mutex_t *mutex, int yield)
DEBUG("%s: unlocking mutex. val: %u pid: %u\n", active_thread->name, mutex->val, thread_pid); DEBUG("%s: unlocking mutex. val: %u pid: %u\n", active_thread->name, mutex->val, thread_pid);
int irqstate = disableIRQ(); int irqstate = disableIRQ();
if(mutex->val != 0) { if (mutex->val != 0) {
if(mutex->queue.next) { if (mutex->queue.next) {
queue_node_t *next = queue_remove_head(&(mutex->queue)); queue_node_t *next = queue_remove_head(&(mutex->queue));
tcb_t *process = (tcb_t*) next->data; tcb_t *process = (tcb_t*) next->data;
DEBUG("%s: waking up waiter %s.\n", process->name); DEBUG("%s: waking up waiter %s.\n", process->name);

View File

@ -31,7 +31,7 @@ void *_malloc(size_t size)
DEBUG("_malloc(): allocating block of size %u at 0x%X.\n", (unsigned int) size, (unsigned int)ptr); DEBUG("_malloc(): allocating block of size %u at 0x%X.\n", (unsigned int) size, (unsigned int)ptr);
if(ptr != (void*) - 1) { if (ptr != (void*) - 1) {
return ptr; return ptr;
} }
else { else {

View File

@ -23,8 +23,8 @@
void queue_remove(queue_node_t *root, queue_node_t *node) void queue_remove(queue_node_t *root, queue_node_t *node)
{ {
while(root->next != NULL) { while (root->next != NULL) {
if(root->next == node) { if (root->next == node) {
root->next = node->next; root->next = node->next;
node->next = NULL; node->next = NULL;
return; return;
@ -38,7 +38,7 @@ queue_node_t *queue_remove_head(queue_node_t *root)
{ {
queue_node_t *head = root->next; queue_node_t *head = root->next;
if(head != NULL) { if (head != NULL) {
root->next = head->next; root->next = head->next;
} }
@ -47,7 +47,7 @@ queue_node_t *queue_remove_head(queue_node_t *root)
void queue_add_tail(queue_node_t *node, queue_node_t *new_obj) void queue_add_tail(queue_node_t *node, queue_node_t *new_obj)
{ {
while(node->next != NULL) { while (node->next != NULL) {
node = node->next; node = node->next;
} }
@ -65,8 +65,8 @@ void queue_priority_add(queue_node_t *root, queue_node_t *new_obj)
{ {
queue_node_t *node = root; queue_node_t *node = root;
while(node->next != NULL) { while (node->next != NULL) {
if(node->next->priority > new_obj->priority) { if (node->next->priority > new_obj->priority) {
new_obj->next = node->next; new_obj->next = node->next;
node->next = new_obj; node->next = new_obj;
return; return;
@ -83,8 +83,8 @@ void queue_priority_add_generic(queue_node_t *root, queue_node_t *new_obj, int (
{ {
queue_node_t *node = root; queue_node_t *node = root;
while(node->next != NULL) { while (node->next != NULL) {
if(cmp(node->next, new_obj) < 0) { if (cmp(node->next, new_obj) < 0) {
new_obj->next = node->next; new_obj->next = node->next;
node->next = new_obj; node->next = new_obj;
return; return;
@ -102,7 +102,7 @@ void queue_print(queue_node_t *node)
{ {
printf("queue:\n"); printf("queue:\n");
while(node->next != NULL) { while (node->next != NULL) {
node = node->next; node = node->next;
printf("Data: %u Priority: %u\n", node->data, node->priority); printf("Data: %u Priority: %u\n", node->data, node->priority);
} }

View File

@ -50,7 +50,7 @@ void sched_init()
printf("Scheduler..."); printf("Scheduler...");
int i; int i;
for(i = 0; i < MAXTHREADS; i++) { for (i = 0; i < MAXTHREADS; i++) {
sched_threads[i] = NULL; sched_threads[i] = NULL;
#if SCHEDSTATISTICS #if SCHEDSTATISTICS
pidlist[i].laststart = 0; pidlist[i].laststart = 0;
@ -62,7 +62,7 @@ void sched_init()
active_thread = NULL; active_thread = NULL;
thread_pid = -1; thread_pid = -1;
for(i = 0; i < SCHED_PRIO_LEVELS; i++) { for (i = 0; i < SCHED_PRIO_LEVELS; i++) {
runqueues[i] = NULL; runqueues[i] = NULL;
} }
@ -75,14 +75,14 @@ void sched_run()
tcb_t *my_active_thread = (tcb_t *)active_thread; tcb_t *my_active_thread = (tcb_t *)active_thread;
if(my_active_thread) { if (my_active_thread) {
if(my_active_thread->status == STATUS_RUNNING) { if (my_active_thread->status == STATUS_RUNNING) {
my_active_thread->status = STATUS_PENDING; my_active_thread->status = STATUS_PENDING;
} }
#ifdef SCHED_TEST_STACK #ifdef SCHED_TEST_STACK
if(*((unsigned int *)my_active_thread->stack_start) != (unsigned int) my_active_thread->stack_start) { if (*((unsigned int *)my_active_thread->stack_start) != (unsigned int) my_active_thread->stack_start) {
printf("scheduler(): stack overflow detected, task=%s pid=%u\n", my_active_thread->name, my_active_thread->pid); printf("scheduler(): stack overflow detected, task=%s pid=%u\n", my_active_thread->name, my_active_thread->pid);
} }
@ -95,7 +95,7 @@ void sched_run()
extern unsigned long hwtimer_now(void); extern unsigned long hwtimer_now(void);
unsigned int time = hwtimer_now(); unsigned int time = hwtimer_now();
if(my_active_thread && (pidlist[my_active_thread->pid].laststart)) { if (my_active_thread && (pidlist[my_active_thread->pid].laststart)) {
pidlist[my_active_thread->pid].runtime += time - pidlist[my_active_thread->pid].laststart; pidlist[my_active_thread->pid].runtime += time - pidlist[my_active_thread->pid].laststart;
} }
@ -103,10 +103,10 @@ void sched_run()
DEBUG("\nscheduler: previous task: %s\n", (my_active_thread == NULL) ? "none" : my_active_thread->name); DEBUG("\nscheduler: previous task: %s\n", (my_active_thread == NULL) ? "none" : my_active_thread->name);
if(num_tasks == 0) { if (num_tasks == 0) {
DEBUG("scheduler: no tasks left.\n"); DEBUG("scheduler: no tasks left.\n");
while(! num_tasks) { while (!num_tasks) {
/* loop until a new task arrives */ /* loop until a new task arrives */
; ;
} }
@ -116,7 +116,7 @@ void sched_run()
my_active_thread = NULL; my_active_thread = NULL;
while(! my_active_thread) { while (!my_active_thread) {
int nextrq = number_of_lowest_bit(runqueue_bitcache); int nextrq = number_of_lowest_bit(runqueue_bitcache);
clist_node_t next = *(runqueues[nextrq]); clist_node_t next = *(runqueues[nextrq]);
DEBUG("scheduler: first in queue: %s\n", ((tcb_t *)next.data)->name); DEBUG("scheduler: first in queue: %s\n", ((tcb_t *)next.data)->name);
@ -129,7 +129,7 @@ void sched_run()
#endif #endif
#ifdef MODULE_NSS #ifdef MODULE_NSS
if(active_thread && active_thread->pid != last_pid) { if (active_thread && active_thread->pid != last_pid) {
last_pid = active_thread->pid; last_pid = active_thread->pid;
} }
@ -138,9 +138,9 @@ void sched_run()
DEBUG("scheduler: next task: %s\n", my_active_thread->name); DEBUG("scheduler: next task: %s\n", my_active_thread->name);
if(my_active_thread != active_thread) { if (my_active_thread != active_thread) {
if(active_thread != NULL) { /* TODO: necessary? */ if (active_thread != NULL) { /* TODO: necessary? */
if(active_thread->status == STATUS_RUNNING) { if (active_thread->status == STATUS_RUNNING) {
active_thread->status = STATUS_PENDING ; active_thread->status = STATUS_PENDING ;
} }
} }
@ -162,19 +162,19 @@ void sched_register_cb(void (*callback)(uint32_t, uint32_t))
void sched_set_status(tcb_t *process, unsigned int status) void sched_set_status(tcb_t *process, unsigned int status)
{ {
if(status & STATUS_ON_RUNQUEUE) { if (status & STATUS_ON_RUNQUEUE) {
if(!(process->status & STATUS_ON_RUNQUEUE)) { if (!(process->status & STATUS_ON_RUNQUEUE)) {
DEBUG("adding process %s to runqueue %u.\n", process->name, process->priority); DEBUG("adding process %s to runqueue %u.\n", process->name, process->priority);
clist_add(&runqueues[process->priority], &(process->rq_entry)); clist_add(&runqueues[process->priority], &(process->rq_entry));
runqueue_bitcache |= 1 << process->priority; runqueue_bitcache |= 1 << process->priority;
} }
} }
else { else {
if(process->status & STATUS_ON_RUNQUEUE) { if (process->status & STATUS_ON_RUNQUEUE) {
DEBUG("removing process %s from runqueue %u.\n", process->name, process->priority); DEBUG("removing process %s from runqueue %u.\n", process->name, process->priority);
clist_remove(&runqueues[process->priority], &(process->rq_entry)); clist_remove(&runqueues[process->priority], &(process->rq_entry));
if(! runqueues[process->priority]) { if (!runqueues[process->priority]) {
runqueue_bitcache &= ~(1 << process->priority); runqueue_bitcache &= ~(1 << process->priority);
} }
} }
@ -187,8 +187,8 @@ void sched_switch(uint16_t current_prio, uint16_t other_prio, int in_isr)
{ {
DEBUG("%s: %i %i %i\n", active_thread->name, (int)current_prio, (int)other_prio, in_isr); DEBUG("%s: %i %i %i\n", active_thread->name, (int)current_prio, (int)other_prio, in_isr);
if(current_prio <= other_prio) { if (current_prio <= other_prio) {
if(in_isr) { if (in_isr) {
sched_context_switch_request = 1; sched_context_switch_request = 1;
} }
else { else {

View File

@ -40,7 +40,7 @@ int thread_getlastpid()
unsigned int thread_getstatus(int pid) unsigned int thread_getstatus(int pid)
{ {
if(sched_threads[pid] == NULL) { if (sched_threads[pid] == NULL) {
return STATUS_NOT_FOUND; return STATUS_NOT_FOUND;
} }
@ -49,7 +49,7 @@ unsigned int thread_getstatus(int pid)
void thread_sleep() void thread_sleep()
{ {
if(inISR()) { if (inISR()) {
return; return;
} }
@ -64,18 +64,18 @@ int thread_wakeup(int pid)
DEBUG("thread_wakeup: Trying to wakeup PID %i...\n", pid); DEBUG("thread_wakeup: Trying to wakeup PID %i...\n", pid);
int isr = inISR(); int isr = inISR();
if(! isr) { if (!isr) {
DEBUG("thread_wakeup: Not in interrupt.\n"); DEBUG("thread_wakeup: Not in interrupt.\n");
dINT(); dINT();
} }
int result = sched_threads[pid]->status; int result = sched_threads[pid]->status;
if(result == STATUS_SLEEPING) { if (result == STATUS_SLEEPING) {
DEBUG("thread_wakeup: Thread is sleeping.\n"); DEBUG("thread_wakeup: Thread is sleeping.\n");
sched_set_status((tcb_t *)sched_threads[pid], STATUS_RUNNING); sched_set_status((tcb_t *)sched_threads[pid], STATUS_RUNNING);
if(!isr) { if (!isr) {
eINT(); eINT();
thread_yield(); thread_yield();
} }
@ -88,7 +88,7 @@ int thread_wakeup(int pid)
else { else {
DEBUG("thread_wakeup: Thread is not sleeping!\n"); DEBUG("thread_wakeup: Thread is not sleeping!\n");
if(!isr) { if (!isr) {
eINT(); eINT();
} }
@ -101,7 +101,7 @@ int thread_measure_stack_usage(char *stack)
unsigned int *stackp = (unsigned int *)stack; unsigned int *stackp = (unsigned int *)stack;
/* assumption that the comparison fails before or after end of stack */ /* assumption that the comparison fails before or after end of stack */
while(*stackp == (unsigned int)stackp) { while (*stackp == (unsigned int)stackp) {
stackp++; stackp++;
} }
@ -118,28 +118,28 @@ int thread_create(char *stack, int stacksize, char priority, int flags, void (*f
/* align tcb address on 32bit boundary */ /* align tcb address on 32bit boundary */
unsigned int tcb_address = (unsigned int) stack + stacksize; unsigned int tcb_address = (unsigned int) stack + stacksize;
if(tcb_address & 1) { if (tcb_address & 1) {
tcb_address--; tcb_address--;
stacksize--; stacksize--;
} }
if(tcb_address & 2) { if (tcb_address & 2) {
tcb_address -= 2; tcb_address -= 2;
stacksize -= 2; stacksize -= 2;
} }
tcb_t *cb = (tcb_t *) tcb_address; tcb_t *cb = (tcb_t *) tcb_address;
if(priority >= SCHED_PRIO_LEVELS) { if (priority >= SCHED_PRIO_LEVELS) {
return -EINVAL; return -EINVAL;
} }
if(flags & CREATE_STACKTEST) { if (flags & CREATE_STACKTEST) {
/* assign each int of the stack the value of it's address */ /* assign each int of the stack the value of it's address */
unsigned int *stackmax = (unsigned int *)((char *)stack + stacksize); unsigned int *stackmax = (unsigned int *)((char *)stack + stacksize);
unsigned int *stackp = (unsigned int *)stack; unsigned int *stackp = (unsigned int *)stack;
while(stackp < stackmax) { while (stackp < stackmax) {
*stackp = (unsigned int)stackp; *stackp = (unsigned int)stackp;
stackp++; stackp++;
} }
@ -149,14 +149,14 @@ int thread_create(char *stack, int stacksize, char priority, int flags, void (*f
*stack = (unsigned int)stack; *stack = (unsigned int)stack;
} }
if(! inISR()) { if (!inISR()) {
dINT(); dINT();
} }
int pid = 0; int pid = 0;
while(pid < MAXTHREADS) { while (pid < MAXTHREADS) {
if(sched_threads[pid] == NULL) { if (sched_threads[pid] == NULL) {
sched_threads[pid] = cb; sched_threads[pid] = cb;
cb->pid = pid; cb->pid = pid;
break; break;
@ -165,10 +165,10 @@ int thread_create(char *stack, int stacksize, char priority, int flags, void (*f
pid++; pid++;
} }
if(pid == MAXTHREADS) { if (pid == MAXTHREADS) {
DEBUG("thread_create(): too many threads!\n"); DEBUG("thread_create(): too many threads!\n");
if(! inISR()) { if (!inISR()) {
eINT(); eINT();
} }
@ -201,14 +201,14 @@ int thread_create(char *stack, int stacksize, char priority, int flags, void (*f
DEBUG("Created thread %s. PID: %u. Priority: %u.\n", name, cb->pid, priority); DEBUG("Created thread %s. PID: %u. Priority: %u.\n", name, cb->pid, priority);
if(flags & CREATE_SLEEPING) { if (flags & CREATE_SLEEPING) {
sched_set_status(cb, STATUS_SLEEPING); sched_set_status(cb, STATUS_SLEEPING);
} }
else { else {
sched_set_status(cb, STATUS_PENDING); sched_set_status(cb, STATUS_PENDING);
if(!(flags & CREATE_WOUT_YIELD)) { if (!(flags & CREATE_WOUT_YIELD)) {
if(! inISR()) { if (!inISR()) {
eINT(); eINT();
thread_yield(); thread_yield();
} }
@ -218,7 +218,7 @@ int thread_create(char *stack, int stacksize, char priority, int flags, void (*f
} }
} }
if(!inISR() && active_thread != NULL) { if (!inISR() && active_thread != NULL) {
eINT(); eINT();
} }

View File

@ -55,7 +55,7 @@ char *thread_stack_init(void *task_func, void *stack_start, int stack_size)
*stk = (unsigned int)(stack_start + stack_size) - 4; *stk = (unsigned int)(stack_start + stack_size) - 4;
/* build base stack */ /* build base stack */
for(int i = REGISTER_CNT; i >= 0 ; i--) { for (int i = REGISTER_CNT; i >= 0 ; i--) {
stk--; stk--;
*stk = i; *stk = i;
} }
@ -80,7 +80,7 @@ void thread_print_stack(void)
register int i = 0; register int i = 0;
s += 5; s += 5;
while(*s != STACK_MARKER) { while (*s != STACK_MARKER) {
printf("STACK (%u) addr=%X = %X \n", i, (unsigned int) s, (unsigned int) *s); printf("STACK (%u) addr=%X = %X \n", i, (unsigned int) s, (unsigned int) *s);
s++; s++;
i++; i++;
@ -97,5 +97,5 @@ __attribute__((naked, noreturn)) void arm_reset(void)
WDFEED = 0xAA; WDFEED = 0xAA;
WDFEED = 0x55; WDFEED = 0x55;
while(1); while (1);
} }

View File

@ -49,35 +49,35 @@ and the mailinglist (subscription via web site)
#include <thread.h> #include <thread.h>
void FIQ_Routine(void) __attribute__((interrupt("FIQ"))); void FIQ_Routine(void) __attribute__((interrupt("FIQ")));
//void SWI_Routine (void) __attribute__ ((interrupt("SWI"))); //void SWI_Routine (void) __attribute__((interrupt("SWI")));
void UNDEF_Routine(void) __attribute__((interrupt("UNDEF"))); void UNDEF_Routine(void) __attribute__((interrupt("UNDEF")));
void IRQ_Routine(void) void IRQ_Routine(void)
{ {
printf("Kernel Panic,\nEarly IRQ call\n"); printf("Kernel Panic,\nEarly IRQ call\n");
while(1) {}; while (1) {};
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
void FIQ_Routine(void) void FIQ_Routine(void)
{ {
printf("Kernel Panic,\nEarly FIQ call\n"); printf("Kernel Panic,\nEarly FIQ call\n");
while(1) {}; while (1) {};
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
void SWI_Routine(void) void SWI_Routine(void)
{ {
printf("Kernel Panic,\nEarly SWI call\n"); printf("Kernel Panic,\nEarly SWI call\n");
while(1) {}; while (1) {};
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
void DEBUG_Routine(void) void DEBUG_Routine(void)
{ {
printf("DEBUG hit."); printf("DEBUG hit.");
while(1) {}; while (1) {};
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
volatile int arm_abortflag = 0; volatile int arm_abortflag = 0;
@ -95,7 +95,7 @@ void abtorigin(const char *vector, u_long *lnk_ptr1)
__asm__ __volatile__("mov %0, sp" : "=r"(sp)); // copy sp __asm__ __volatile__("mov %0, sp" : "=r"(sp)); // copy sp
__asm__ __volatile__("msr cpsr_c, %0" :: "r"(cpsr)); // switch back to abt mode __asm__ __volatile__("msr cpsr_c, %0" :: "r"(cpsr)); // switch back to abt mode
printf("#! %s abort at %p (0x%08lX) originating from %p (0x%08lX) in mode 0x%X\n", printf("#!%s abort at %p (0x%08lX) originating from %p (0x%08lX) in mode 0x%X\n",
vector, (void *)lnk_ptr1, *(lnk_ptr1), (void *)lnk_ptr2, *(lnk_ptr2), spsr vector, (void *)lnk_ptr1, *(lnk_ptr1), (void *)lnk_ptr2, *(lnk_ptr2), spsr
); );
stdio_flush(); stdio_flush();
@ -108,7 +108,7 @@ void UNDEF_Routine(void)
register u_long *lnk_ptr; register u_long *lnk_ptr;
__asm__ __volatile__("sub %0, lr, #8" : "=r"(lnk_ptr)); // get aborting instruction __asm__ __volatile__("sub %0, lr, #8" : "=r"(lnk_ptr)); // get aborting instruction
if(arm_abortflag == 0) { if (arm_abortflag == 0) {
arm_abortflag = 1; // remember state (if printing should fail again) arm_abortflag = 1; // remember state (if printing should fail again)
abtorigin("undef", lnk_ptr); abtorigin("undef", lnk_ptr);
} }
@ -121,7 +121,7 @@ void PABT_Routine(void)
register u_long *lnk_ptr; register u_long *lnk_ptr;
__asm__ __volatile__("sub %0, lr, #8" : "=r"(lnk_ptr)); // get aborting instruction __asm__ __volatile__("sub %0, lr, #8" : "=r"(lnk_ptr)); // get aborting instruction
if(arm_abortflag == 0) { if (arm_abortflag == 0) {
arm_abortflag = 1; // remember state (if printing should fail again) arm_abortflag = 1; // remember state (if printing should fail again)
abtorigin("pabt", lnk_ptr); abtorigin("pabt", lnk_ptr);
} }
@ -134,7 +134,7 @@ void DABT_Routine(void)
register u_long *lnk_ptr; register u_long *lnk_ptr;
__asm__ __volatile__("sub %0, lr, #8" : "=r"(lnk_ptr)); // get aborting instruction __asm__ __volatile__("sub %0, lr, #8" : "=r"(lnk_ptr)); // get aborting instruction
if(arm_abortflag == 0) { if (arm_abortflag == 0) {
arm_abortflag = 1; // remember state (if printing should fail again) arm_abortflag = 1; // remember state (if printing should fail again)
abtorigin("data", lnk_ptr); abtorigin("data", lnk_ptr);
} }
@ -161,7 +161,7 @@ bl_init_data(void)
p2 = &_data; p2 = &_data;
p3 = &_edata; p3 = &_edata;
while(p2 < p3) { while (p2 < p3) {
*p2++ = *p1++; *p2++ = *p1++;
} }
@ -170,7 +170,7 @@ bl_init_data(void)
p1 = &__bss_start; p1 = &__bss_start;
p2 = &__bss_end; p2 = &__bss_end;
while(p1 < p2) { while (p1 < p2) {
*p1++ = 0; *p1++ = 0;
} }
} }

View File

@ -35,37 +35,37 @@ static void timer_irq(void)
{ {
short timer = 0; short timer = 0;
if(T0IR) { if (T0IR) {
timer = 0; timer = 0;
} }
else if(T1IR) { else if (T1IR) {
timer = 4; timer = 4;
} }
else if(T2IR) { else if (T2IR) {
timer = 8; timer = 8;
} }
volatile unsigned long base = get_base_address(timer); volatile unsigned long base = get_base_address(timer);
if(*VULP(base + TXIR) & BIT0) { if (*VULP(base + TXIR) & BIT0) {
*VULP(base + TXMCR) &= ~BIT0; *VULP(base + TXMCR) &= ~BIT0;
*VULP(base + TXIR) = BIT0; *VULP(base + TXIR) = BIT0;
int_handler(timer); int_handler(timer);
} }
if(*VULP(base + TXIR) & BIT1) { if (*VULP(base + TXIR) & BIT1) {
*VULP(base + TXMCR) &= ~BIT3; *VULP(base + TXMCR) &= ~BIT3;
*VULP(base + TXIR) = BIT1; *VULP(base + TXIR) = BIT1;
int_handler(timer + 1); int_handler(timer + 1);
} }
if(*VULP(base + TXIR) & BIT2) { if (*VULP(base + TXIR) & BIT2) {
*VULP(base + TXMCR) &= ~BIT6; *VULP(base + TXMCR) &= ~BIT6;
*VULP(base + TXIR) = BIT2; *VULP(base + TXIR) = BIT2;
int_handler(timer + 2); int_handler(timer + 2);
} }
if(*VULP(base + TXIR) & BIT3) { if (*VULP(base + TXIR) & BIT3) {
*VULP(base + TXMCR) &= ~BIT9; *VULP(base + TXMCR) &= ~BIT9;
*VULP(base + TXIR) = BIT3; *VULP(base + TXIR) = BIT3;
int_handler(timer + 3); int_handler(timer + 3);

View File

@ -39,20 +39,20 @@ uint8_t flashrom_write(uint8_t *dst, char *src, size_t size)
sec = iap_get_sector((uint32_t) dst); sec = iap_get_sector((uint32_t) dst);
if(sec == INVALID_ADDRESS) { if (sec == INVALID_ADDRESS) {
DEBUG("Invalid address\n"); DEBUG("Invalid address\n");
return 0; return 0;
} }
/* check sector */ /* check sector */
if(blank_check_sector(sec, sec) == SECTOR_NOT_BLANK) { if (blank_check_sector(sec, sec) == SECTOR_NOT_BLANK) {
DEBUG("Warning: Sector %i not blank\n", sec); DEBUG("Warning: Sector %i not blank\n", sec);
} }
/* prepare sector */ /* prepare sector */
err = prepare_sectors(sec, sec); err = prepare_sectors(sec, sec);
if(err) { if (err) {
DEBUG("\n-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION: %u\n", err); DEBUG("\n-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION: %u\n", err);
return 0; return 0;
} }
@ -62,7 +62,7 @@ uint8_t flashrom_write(uint8_t *dst, char *src, size_t size)
err = copy_ram_to_flash((uint32_t) dst, (uint32_t) src, 256); err = copy_ram_to_flash((uint32_t) dst, (uint32_t) src, 256);
restoreIRQ(intstate); restoreIRQ(intstate);
if(err) { if (err) {
DEBUG("ERROR: COPY_RAM_TO_FLASH: %u\n", err); DEBUG("ERROR: COPY_RAM_TO_FLASH: %u\n", err);
/* set interrupts back and return */ /* set interrupts back and return */
restoreIRQ(intstate); restoreIRQ(intstate);
@ -72,7 +72,7 @@ uint8_t flashrom_write(uint8_t *dst, char *src, size_t size)
else { else {
err = compare((uint32_t) dst, (uint32_t) src, 256); err = compare((uint32_t) dst, (uint32_t) src, 256);
if(err) { if (err) {
DEBUG("ERROR: COMPARE: %i (at position %u)\n", err, iap_result[1]); DEBUG("ERROR: COMPARE: %i (at position %u)\n", err, iap_result[1]);
return 0; return 0;
} }
@ -90,19 +90,19 @@ uint8_t flashrom_erase(uint8_t *addr)
uint8_t sec = iap_get_sector((uint32_t) addr); uint8_t sec = iap_get_sector((uint32_t) addr);
unsigned intstate; unsigned intstate;
if(sec == INVALID_ADDRESS) { if (sec == INVALID_ADDRESS) {
DEBUG("Invalid address\n"); DEBUG("Invalid address\n");
return 0; return 0;
} }
/* check sector */ /* check sector */
if(!blank_check_sector(sec, sec)) { if (!blank_check_sector(sec, sec)) {
DEBUG("Sector already blank!\n"); DEBUG("Sector already blank!\n");
return 1; return 1;
} }
/* prepare sector */ /* prepare sector */
if(prepare_sectors(sec, sec)) { if (prepare_sectors(sec, sec)) {
DEBUG("-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION --\n"); DEBUG("-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION --\n");
return 0; return 0;
} }
@ -110,7 +110,7 @@ uint8_t flashrom_erase(uint8_t *addr)
intstate = disableIRQ(); intstate = disableIRQ();
/* erase sector */ /* erase sector */
if(erase_sectors(sec, sec)) { if (erase_sectors(sec, sec)) {
DEBUG("-- ERROR: ERASE SECTOR --\n"); DEBUG("-- ERROR: ERASE SECTOR --\n");
restoreIRQ(intstate); restoreIRQ(intstate);
return 0; return 0;
@ -119,7 +119,7 @@ uint8_t flashrom_erase(uint8_t *addr)
restoreIRQ(intstate); restoreIRQ(intstate);
/* check again */ /* check again */
if(blank_check_sector(sec, sec)) { if (blank_check_sector(sec, sec)) {
DEBUG("-- ERROR: BLANK_CHECK_SECTOR\n"); DEBUG("-- ERROR: BLANK_CHECK_SECTOR\n");
return 0; return 0;
} }

View File

@ -27,14 +27,14 @@ void __attribute__((__no_instrument_function__)) profiling_init(void)
{ {
uint16_t i; uint16_t i;
for(i = 0; i < MAX_TRACED_FUNCTIONS; i++) { for (i = 0; i < MAX_TRACED_FUNCTIONS; i++) {
functions[i].address = 0; functions[i].address = 0;
functions[i].time = 0; functions[i].time = 0;
functions[i].consumption = 0; functions[i].consumption = 0;
functions[i].counter = 0; functions[i].counter = 0;
} }
for(i = 0; i < PROFILING_STACK_SIZE; i++) { for (i = 0; i < PROFILING_STACK_SIZE; i++) {
profiling_stack[i] = 0; profiling_stack[i] = 0;
} }
@ -47,8 +47,8 @@ static int16_t __attribute__((__no_instrument_function__)) get_function_index(ui
{ {
uint16_t i; uint16_t i;
for(i = 0; i < MAX_TRACED_FUNCTIONS; i++) { for (i = 0; i < MAX_TRACED_FUNCTIONS; i++) {
if(functions[i].address == addr) { if (functions[i].address == addr) {
return i; return i;
} }
} }
@ -58,24 +58,24 @@ static int16_t __attribute__((__no_instrument_function__)) get_function_index(ui
void __attribute__((__no_instrument_function__)) __cyg_profile_func_enter(void *func, void *caller) void __attribute__((__no_instrument_function__)) __cyg_profile_func_enter(void *func, void *caller)
{ {
if(!profiling) { if (!profiling) {
return; return;
} }
int16_t idx = get_function_index((uint32_t) func); int16_t idx = get_function_index((uint32_t) func);
/* if function is not yet on traced */ /* if function is not yet on traced */
if((idx < 0) && (traced_functions < MAX_TRACED_FUNCTIONS)) { if ((idx < 0) && (traced_functions < MAX_TRACED_FUNCTIONS)) {
idx = traced_functions++; idx = traced_functions++;
functions[idx].address = (uint32_t) func; functions[idx].address = (uint32_t) func;
} }
/* maximu of traceable functions reached */ /* maximu of traceable functions reached */
else if(idx < 0) { else if (idx < 0) {
return; return;
} }
/* check if a profiled function is pending */ /* check if a profiled function is pending */
if(function_pending && (profiling_stack[profiling_sp] != idx)) { if (function_pending && (profiling_stack[profiling_sp] != idx)) {
functions[idx].time += T0TC - functions[idx].start_time; functions[idx].time += T0TC - functions[idx].start_time;
//functions[idx].consumption += ltc4150_get_intcount() - functions[idx].consumption_start; //functions[idx].consumption += ltc4150_get_intcount() - functions[idx].consumption_start;
functions[idx].consumption += ltc4150_get_total_mAh() - functions[idx].consumption_start; functions[idx].consumption += ltc4150_get_total_mAh() - functions[idx].consumption_start;
@ -94,13 +94,13 @@ void __attribute__((__no_instrument_function__)) __cyg_profile_func_enter(void
void __attribute__((__no_instrument_function__)) __cyg_profile_func_exit(void *func, void *caller) void __attribute__((__no_instrument_function__)) __cyg_profile_func_exit(void *func, void *caller)
{ {
if(!profiling) { if (!profiling) {
return; return;
} }
int16_t idx = get_function_index((uint32_t) func); int16_t idx = get_function_index((uint32_t) func);
if(idx >= 0) { if (idx >= 0) {
functions[idx].time += T0TC - functions[idx].start_time; functions[idx].time += T0TC - functions[idx].start_time;
//functions[idx].consumption += ltc4150_get_intcount() - functions[idx].consumption_start; //functions[idx].consumption += ltc4150_get_intcount() - functions[idx].consumption_start;
functions[idx].consumption += ltc4150_get_total_mAh() - functions[idx].consumption_start; functions[idx].consumption += ltc4150_get_total_mAh() - functions[idx].consumption_start;
@ -110,8 +110,8 @@ void __attribute__((__no_instrument_function__)) __cyg_profile_func_exit(void *f
function_pending = 0; function_pending = 0;
/* if another function is pending */ /* if another function is pending */
if(profiling_sp) { if (profiling_sp) {
if(--profiling_sp) { if (--profiling_sp) {
functions[profiling_stack[profiling_sp]].start_time = T0TC; functions[profiling_stack[profiling_sp]].start_time = T0TC;
functions[profiling_stack[profiling_sp]].consumption_start = ltc4150_get_total_mAh(); functions[profiling_stack[profiling_sp]].consumption_start = ltc4150_get_total_mAh();
} }
@ -122,7 +122,7 @@ void profiling_stats(void)
{ {
uint16_t i; uint16_t i;
for(i = 0; i < traced_functions; i++) { for (i = 0; i < traced_functions; i++) {
// printf("Function @%04lX was running %u times for %lu ticks, consuming %li ltc-ticks\n", functions[i].address, functions[i].counter, functions[i].time, functions[i].consumption); // printf("Function @%04lX was running %u times for %lu ticks, consuming %li ltc-ticks\n", functions[i].address, functions[i].counter, functions[i].time, functions[i].consumption);
printf("Function @%04lX was running %u times for %lu ticks, consuming %lf mAh\n", functions[i].address, functions[i].counter, functions[i].time, functions[i].consumption); printf("Function @%04lX was running %u times for %lu ticks, consuming %lf mAh\n", functions[i].address, functions[i].counter, functions[i].time, functions[i].consumption);
} }

View File

@ -88,7 +88,7 @@ volatile static uint8_t iUsedHeap = 0;
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
void heap_stats(void) void heap_stats(void)
{ {
for(int i = 0; i < NUM_HEAPS; i++) for (int i = 0; i < NUM_HEAPS; i++)
printf("# heap %i: %p -- %p -> %p (%li of %li free)\n", i, heap_start[i], heap[i], heap_max[i], printf("# heap %i: %p -- %p -> %p (%li of %li free)\n", i, heap_start[i], heap[i], heap_max[i],
(uint32_t)heap_max[i] - (uint32_t)heap[i], (uint32_t)heap_max[i] - (uint32_t)heap_start[i]); (uint32_t)heap_max[i] - (uint32_t)heap[i], (uint32_t)heap_max[i] - (uint32_t)heap_start[i]);
} }
@ -100,7 +100,7 @@ void __assert_func(const char *file, int line, const char *func, const char *fai
trace_number(TRACELOG_EV_ASSERTION, line); trace_number(TRACELOG_EV_ASSERTION, line);
syslog(SL_EMERGENCY, "assert", "%s() in %s:%u\n", func, file, line); syslog(SL_EMERGENCY, "assert", "%s() in %s:%u\n", func, file, line);
#endif #endif
printf("#! assertion %s failed\n\t%s() in %s:%u\n", failedexpr, func, file, line); printf("#!assertion %s failed\n\t%s() in %s:%u\n", failedexpr, func, file, line);
_exit(3); _exit(3);
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
@ -111,7 +111,7 @@ void __assert(const char *file, int line, const char *failedexpr)
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
caddr_t _sbrk_r(struct _reent *r, size_t incr) caddr_t _sbrk_r(struct _reent *r, size_t incr)
{ {
if(incr < 0) { if (incr < 0) {
puts("[syscalls] Negative Values for _sbrk_r are not supported"); puts("[syscalls] Negative Values for _sbrk_r are not supported");
r->_errno = ENOMEM; r->_errno = ENOMEM;
return NULL; return NULL;
@ -120,14 +120,14 @@ caddr_t _sbrk_r(struct _reent *r, size_t incr)
uint32_t cpsr = disableIRQ(); uint32_t cpsr = disableIRQ();
/* check all heaps for a chunk of the requested size */ /* check all heaps for a chunk of the requested size */
for(; iUsedHeap < NUM_HEAPS; iUsedHeap++) { for (; iUsedHeap < NUM_HEAPS; iUsedHeap++) {
caddr_t new_heap = heap[iUsedHeap] + incr; caddr_t new_heap = heap[iUsedHeap] + incr;
#ifdef MODULE_TRACELOG #ifdef MODULE_TRACELOG
trace_pointer(TRACELOG_EV_MEMORY, heap[iUsedHeap]); trace_pointer(TRACELOG_EV_MEMORY, heap[iUsedHeap]);
#endif #endif
if(new_heap <= heap_max[iUsedHeap]) { if (new_heap <= heap_max[iUsedHeap]) {
caddr_t prev_heap = heap[iUsedHeap]; caddr_t prev_heap = heap[iUsedHeap];
#ifdef MODULE_TRACELOG #ifdef MODULE_TRACELOG
trace_pointer(TRACELOG_EV_MEMORY, new_heap); trace_pointer(TRACELOG_EV_MEMORY, new_heap);
@ -153,7 +153,7 @@ int _isatty_r(struct _reent *r, int fd)
{ {
r->_errno = 0; r->_errno = 0;
if(fd == STDOUT_FILENO || fd == STDERR_FILENO) { if (fd == STDOUT_FILENO || fd == STDERR_FILENO) {
return 1; return 1;
} }
else { else {
@ -208,7 +208,7 @@ int _fstat_r(struct _reent *r, int fd, struct stat *st)
r->_errno = 0; r->_errno = 0;
memset(st, 0, sizeof(*st)); memset(st, 0, sizeof(*st));
if(fd == STDOUT_FILENO || fd == STDERR_FILENO) { if (fd == STDOUT_FILENO || fd == STDERR_FILENO) {
st->st_mode = S_IFCHR; st->st_mode = S_IFCHR;
ret = 0; ret = 0;
} }
@ -237,10 +237,10 @@ int _write_r(struct _reent *r, int fd, const void *data, unsigned int count)
case STDOUT_FILENO: case STDOUT_FILENO:
case STDERR_FILENO: case STDERR_FILENO:
#if FEUERWARE_CONF_ENABLE_HAL #if FEUERWARE_CONF_ENABLE_HAL
if(stdio != NULL) { if (stdio != NULL) {
result = chardevice_write(stdio, (char *)data, count); result = chardevice_write(stdio, (char *)data, count);
} }
else if(hal_state == HAL_NOT_INITIALIZED) { else if (hal_state == HAL_NOT_INITIALIZED) {
result = fw_puts((char *)data, count); result = fw_puts((char *)data, count);
} }
@ -306,12 +306,12 @@ void _exit(int n)
#ifdef MODULE_TRACELOG #ifdef MODULE_TRACELOG
trace_number(TRACELOG_EV_EXIT, n); trace_number(TRACELOG_EV_EXIT, n);
#endif #endif
printf("#! exit %i: resetting\n", n); printf("#!exit %i: resetting\n", n);
stdio_flush(); stdio_flush();
arm_reset(); arm_reset();
while(1); while (1);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int _getpid(void) int _getpid(void)

View File

@ -17,27 +17,27 @@ uint8_t cc110x_strobe(uint8_t c)
uint16_t int_state, gdo_state; uint16_t int_state, gdo_state;
/* Check for valid strobe command */ /* Check for valid strobe command */
if((c == 0xBD) || ((c > RF_SRES) && (c < RF_SNOP))) { if ((c == 0xBD) || ((c > RF_SRES) && (c < RF_SNOP))) {
int_state = disableIRQ(); int_state = disableIRQ();
/* Clear the Status read flag */ /* Clear the Status read flag */
RF1AIFCTL1 &= ~(RFSTATIFG); RF1AIFCTL1 &= ~(RFSTATIFG);
/* Wait for radio to be ready for next instruction */ /* Wait for radio to be ready for next instruction */
while(!(RF1AIFCTL1 & RFINSTRIFG)); while (!(RF1AIFCTL1 & RFINSTRIFG));
/* Write the strobe instruction */ /* Write the strobe instruction */
if((c > RF_SRES) && (c < RF_SNOP)) { if ((c > RF_SRES) && (c < RF_SNOP)) {
gdo_state = cc110x_read_reg(IOCFG2); /* buffer IOCFG2 state */ gdo_state = cc110x_read_reg(IOCFG2); /* buffer IOCFG2 state */
cc110x_write_reg(IOCFG2, 0x29); /* c-ready to GDO2 */ cc110x_write_reg(IOCFG2, 0x29); /* c-ready to GDO2 */
RF1AINSTRB = c; RF1AINSTRB = c;
if((RF1AIN & 0x04) == 0x04) { /* chip at sleep mode */ if ((RF1AIN & 0x04) == 0x04) { /* chip at sleep mode */
if((c == RF_SXOFF) || (c == RF_SPWD) || (c == RF_SWOR)) { } if ((c == RF_SXOFF) || (c == RF_SPWD) || (c == RF_SWOR)) { }
else { else {
while((RF1AIN & 0x04) == 0x04); /* c-ready ? */ while ((RF1AIN & 0x04) == 0x04); /* c-ready ? */
hwtimer_wait(RTIMER_TICKS(9800)); /* Delay for ~810usec at 12MHz CPU clock */ hwtimer_wait(RTIMER_TICKS(9800)); /* Delay for ~810usec at 12MHz CPU clock */
} }
@ -51,7 +51,7 @@ uint8_t cc110x_strobe(uint8_t c)
statusByte = RF1ASTATB; statusByte = RF1ASTATB;
while(!(RF1AIFCTL1 & RFSTATIFG)); while (!(RF1AIFCTL1 & RFSTATIFG));
restoreIRQ(int_state); restoreIRQ(int_state);
} }
@ -94,11 +94,11 @@ void cc110x_write_reg(uint8_t addr, uint8_t value)
int_state = disableIRQ(); int_state = disableIRQ();
while(!(RF1AIFCTL1 & RFINSTRIFG)); /* Wait for the Radio to be ready for the next instruction */ while (!(RF1AIFCTL1 & RFINSTRIFG)); /* Wait for the Radio to be ready for the next instruction */
RF1AINSTRW = ((addr | RF_REGWR) << 8) + value; /* Send address + Instruction */ RF1AINSTRW = ((addr | RF_REGWR) << 8) + value; /* Send address + Instruction */
while(!(RFDINIFG & RF1AIFCTL1)); while (!(RFDINIFG & RF1AIFCTL1));
i = RF1ADOUTB; /* Reset RFDOUTIFG flag which contains status byte */ i = RF1ADOUTB; /* Reset RFDOUTIFG flag which contains status byte */
@ -132,12 +132,12 @@ void cc110x_readburst_reg(uint8_t addr, char *buffer, uint8_t count)
int_state = disableIRQ(); int_state = disableIRQ();
while(!(RF1AIFCTL1 & RFINSTRIFG)); /* Wait for the Radio to be ready for next instruction */ while (!(RF1AIFCTL1 & RFINSTRIFG)); /* Wait for the Radio to be ready for next instruction */
RF1AINSTR1B = (addr | RF_REGRD); /* Send address + Instruction */ RF1AINSTR1B = (addr | RF_REGRD); /* Send address + Instruction */
for(i = 0; i < (count - 1); i++) { for (i = 0; i < (count - 1); i++) {
while(!(RFDOUTIFG & RF1AIFCTL1)); /* Wait for the Radio Core to update the RF1ADOUTB reg */ while (!(RFDOUTIFG & RF1AIFCTL1)); /* Wait for the Radio Core to update the RF1ADOUTB reg */
buffer[i] = RF1ADOUT1B; /* Read DOUT from Radio Core + clears RFDOUTIFG */ buffer[i] = RF1ADOUT1B; /* Read DOUT from Radio Core + clears RFDOUTIFG */
/* Also initiates auo-read for next DOUT byte */ /* Also initiates auo-read for next DOUT byte */
@ -155,12 +155,12 @@ void cc110x_read_fifo(char *buffer, uint8_t count)
int_state = disableIRQ(); int_state = disableIRQ();
while(!(RF1AIFCTL1 & RFINSTRIFG)); /* Wait for the Radio to be ready for next instruction */ while (!(RF1AIFCTL1 & RFINSTRIFG)); /* Wait for the Radio to be ready for next instruction */
RF1AINSTR1B = (RF_RXFIFORD); /* Send address + Instruction */ RF1AINSTR1B = (RF_RXFIFORD); /* Send address + Instruction */
for(i = 0; i < (count - 1); i++) { for (i = 0; i < (count - 1); i++) {
while(!(RFDOUTIFG & RF1AIFCTL1)); /* Wait for the Radio Core to update the RF1ADOUTB reg */ while (!(RFDOUTIFG & RF1AIFCTL1)); /* Wait for the Radio Core to update the RF1ADOUTB reg */
buffer[i] = RF1ADOUT1B; /* Read DOUT from Radio Core + clears RFDOUTIFG */ buffer[i] = RF1ADOUT1B; /* Read DOUT from Radio Core + clears RFDOUTIFG */
/* Also initiates auo-read for next DOUT byte */ /* Also initiates auo-read for next DOUT byte */
@ -184,14 +184,14 @@ uint8_t cc110x_writeburst_reg(uint8_t addr, char *buffer, uint8_t count)
int_state = disableIRQ(); int_state = disableIRQ();
while(!(RF1AIFCTL1 & RFINSTRIFG)); /* Wait for the Radio to be ready for next instruction */ while (!(RF1AIFCTL1 & RFINSTRIFG)); /* Wait for the Radio to be ready for next instruction */
RF1AINSTRW = ((addr | RF_REGWR) << 8) + buffer[0]; /* Send address + Instruction */ RF1AINSTRW = ((addr | RF_REGWR) << 8) + buffer[0]; /* Send address + Instruction */
for(i = 1; i < count; i++) { for (i = 1; i < count; i++) {
RF1ADINB = buffer[i]; /* Send data */ RF1ADINB = buffer[i]; /* Send data */
while(!(RFDINIFG & RF1AIFCTL1)); /* Wait for TX to finish */ while (!(RFDINIFG & RF1AIFCTL1)); /* Wait for TX to finish */
} }
i = RF1ADOUTB; /* Reset RFDOUTIFG flag which contains status byte */ i = RF1ADOUTB; /* Reset RFDOUTIFG flag which contains status byte */

View File

@ -77,7 +77,7 @@ uint16_t adc12_single_conversion(uint16_t ref, uint16_t sht, uint16_t channel)
/* Wait until ADC12 has finished */ /* Wait until ADC12 has finished */
hwtimer_wait(5); hwtimer_wait(5);
while(!adc12_data_ready); while (!adc12_data_ready);
/* Shut down ADC12 */ /* Shut down ADC12 */
ADC12CTL0 &= ~(ADC12ENC | ADC12SC | sht); ADC12CTL0 &= ~(ADC12ENC | ADC12SC | sht);

View File

@ -55,8 +55,8 @@ void gpioint_init(void)
{ {
uint8_t i, j; uint8_t i, j;
for(i = 0; i < INT_PORTS; i++) { for (i = 0; i < INT_PORTS; i++) {
for(j = 0; j < BITMASK_SIZE; j++) { for (j = 0; j < BITMASK_SIZE; j++) {
cb[i][j] = NULL; cb[i][j] = NULL;
debounce_time[i][j] = 0; debounce_time[i][j] = 0;
} }
@ -67,18 +67,18 @@ bool gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback)
{ {
int8_t base; int8_t base;
if((port >= PORTINT_MIN) && (port <= PORTINT_MAX)) { if ((port >= PORTINT_MIN) && (port <= PORTINT_MAX)) {
/* set the callback function */ /* set the callback function */
base = number_of_highest_bit(bitmask); base = number_of_highest_bit(bitmask);
if(base >= 0) { if (base >= 0) {
cb[port - PORTINT_MIN][base] = callback; cb[port - PORTINT_MIN][base] = callback;
} }
else { else {
return false; return false;
} }
if(flags & GPIOINT_DEBOUNCE) { if (flags & GPIOINT_DEBOUNCE) {
debounce_flags[port - PORTINT_MIN] |= bitmask; debounce_flags[port - PORTINT_MIN] |= bitmask;
} }
else { else {
@ -98,17 +98,17 @@ bool gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback)
P1IFG &= ~bitmask; P1IFG &= ~bitmask;
/* trigger on rising... */ /* trigger on rising... */
if(flags & GPIOINT_RISING_EDGE) { if (flags & GPIOINT_RISING_EDGE) {
P1IES &= bitmask; P1IES &= bitmask;
} }
/* ...or falling edge */ /* ...or falling edge */
if(flags & GPIOINT_FALLING_EDGE) { if (flags & GPIOINT_FALLING_EDGE) {
P1IES |= bitmask; P1IES |= bitmask;
} }
/* disable interrupt */ /* disable interrupt */
if(flags == GPIOINT_DISABLE) { if (flags == GPIOINT_DISABLE) {
P1IE &= ~bitmask; P1IE &= ~bitmask;
} }
@ -127,11 +127,11 @@ bool gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback)
P2IFG &= ~bitmask; P2IFG &= ~bitmask;
/* trigger on rising... */ /* trigger on rising... */
if(flags == GPIOINT_RISING_EDGE) { if (flags == GPIOINT_RISING_EDGE) {
P2IES &= bitmask; P2IES &= bitmask;
} }
/* ...or falling edge */ /* ...or falling edge */
else if(flags == GPIOINT_FALLING_EDGE) { else if (flags == GPIOINT_FALLING_EDGE) {
P2IES |= bitmask; P2IES |= bitmask;
} }
/* or disable interrupt */ /* or disable interrupt */
@ -168,14 +168,14 @@ interrupt(PORT1_VECTOR) __attribute__((naked)) port1_isr(void)
ifg_num = (p1iv >> 1) - 1; ifg_num = (p1iv >> 1) - 1;
/* check interrupt source */ /* check interrupt source */
if(debounce_flags[0] & p1ifg) { if (debounce_flags[0] & p1ifg) {
/* check if bouncing */ /* check if bouncing */
diff = hwtimer_now() - debounce_time[0][ifg_num]; diff = hwtimer_now() - debounce_time[0][ifg_num];
if(diff > DEBOUNCE_TIMEOUT) { if (diff > DEBOUNCE_TIMEOUT) {
debounce_time[0][ifg_num] = hwtimer_now(); debounce_time[0][ifg_num] = hwtimer_now();
if(cb[0][ifg_num] != NULL) { if (cb[0][ifg_num] != NULL) {
cb[0][ifg_num](); cb[0][ifg_num]();
} }
} }
@ -185,7 +185,7 @@ interrupt(PORT1_VECTOR) __attribute__((naked)) port1_isr(void)
} }
} }
else { else {
if(cb[0][ifg_num] != NULL) { if (cb[0][ifg_num] != NULL) {
cb[0][ifg_num](); cb[0][ifg_num]();
} }
} }
@ -213,15 +213,15 @@ interrupt(PORT2_VECTOR) __attribute__((naked)) port2_isr(void)
ifg_num = (p2iv >> 1) - 1; ifg_num = (p2iv >> 1) - 1;
/* check interrupt source */ /* check interrupt source */
if(debounce_flags[1] & p2ifg) { if (debounce_flags[1] & p2ifg) {
/* check if bouncing */ /* check if bouncing */
diff = hwtimer_now() - debounce_time[1][ifg_num]; diff = hwtimer_now() - debounce_time[1][ifg_num];
if(diff > DEBOUNCE_TIMEOUT) { if (diff > DEBOUNCE_TIMEOUT) {
debounce_time[1][ifg_num] = hwtimer_now(); debounce_time[1][ifg_num] = hwtimer_now();
c1++; c1++;
if(cb[1][ifg_num] != NULL) { if (cb[1][ifg_num] != NULL) {
cb[1][ifg_num](); cb[1][ifg_num]();
} }
} }
@ -232,7 +232,7 @@ interrupt(PORT2_VECTOR) __attribute__((naked)) port2_isr(void)
} }
} }
else { else {
if(cb[1][ifg_num] != NULL) { if (cb[1][ifg_num] != NULL) {
cb[1][ifg_num](); cb[1][ifg_num]();
} }
} }

View File

@ -57,7 +57,7 @@ void rtc_disable(void)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void rtc_set_localtime(struct tm *localt) void rtc_set_localtime(struct tm *localt)
{ {
if(localt == NULL) { if (localt == NULL) {
return; return;
} }
@ -91,14 +91,14 @@ void rtc_get_localtime(struct tm *localt)
uint8_t i; uint8_t i;
uint16_t tmpyear; uint16_t tmpyear;
if(localt == NULL) { if (localt == NULL) {
return; return;
} }
while(!success) { while (!success) {
for(i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
/* try again when RTC is in transition */ /* try again when RTC is in transition */
if(!(RTCCTL1 & RTCRDY_H)) { if (!(RTCCTL1 & RTCRDY_H)) {
break; break;
} }
@ -144,22 +144,22 @@ void rtc_get_localtime(struct tm *localt)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void rtc_set_alarm(struct tm *localt, rtc_alarm_mask_t mask) void rtc_set_alarm(struct tm *localt, rtc_alarm_mask_t mask)
{ {
if(mask & RTC_ALARM_MIN) { if (mask & RTC_ALARM_MIN) {
RTCAMIN = localt->tm_min; RTCAMIN = localt->tm_min;
RTCAMIN |= BIT7; RTCAMIN |= BIT7;
} }
if(mask & RTC_ALARM_HOUR) { if (mask & RTC_ALARM_HOUR) {
RTCAHOUR = localt->tm_hour; RTCAHOUR = localt->tm_hour;
RTCAHOUR |= BIT7; RTCAHOUR |= BIT7;
} }
if(mask & RTC_ALARM_DOW) { if (mask & RTC_ALARM_DOW) {
RTCADOW = localt->tm_wday; RTCADOW = localt->tm_wday;
RTCADOW |= BIT7; RTCADOW |= BIT7;
} }
if(mask & RTC_ALARM_DOM) { if (mask & RTC_ALARM_DOM) {
RTCADAY = localt->tm_mday; RTCADAY = localt->tm_mday;
RTCADAY |= BIT7; RTCADAY |= BIT7;
} }
@ -185,11 +185,11 @@ interrupt(RTC_VECTOR) __attribute__((naked)) rtc_isr(void)
__enter_isr(); __enter_isr();
/* RTC is save to write for up to one second now */ /* RTC is save to write for up to one second now */
if(RTCIV == RTC_RTCRDYIFG) { if (RTCIV == RTC_RTCRDYIFG) {
/* disable interrupt */ /* disable interrupt */
//RTCCTL0 &= ~RTCRDYIE; //RTCCTL0 &= ~RTCRDYIE;
if(set_time) { if (set_time) {
set_time = 0; set_time = 0;
/* set previous set time and reset it */ /* set previous set time and reset it */
RTCSEC = time_to_set.tm_sec; RTCSEC = time_to_set.tm_sec;
@ -202,14 +202,14 @@ interrupt(RTC_VECTOR) __attribute__((naked)) rtc_isr(void)
RTCYEARH = (time_to_set.tm_year + 1900) >> 0x08; RTCYEARH = (time_to_set.tm_year + 1900) >> 0x08;
} }
if(rtc_second_pid) { if (rtc_second_pid) {
msg_t m; msg_t m;
m.type = RTC_SECOND; m.type = RTC_SECOND;
msg_send_int(&m, rtc_second_pid); msg_send_int(&m, rtc_second_pid);
} }
} }
/* RTC alarm */ /* RTC alarm */
else if(RTCIV == RTC_RTCAIFG) { else if (RTCIV == RTC_RTCAIFG) {
} }
__exit_isr(); __exit_isr();

View File

@ -21,7 +21,7 @@ void timerA_init(void)
volatile unsigned int *ccr = &TA0CCR0; volatile unsigned int *ccr = &TA0CCR0;
volatile unsigned int *ctl = &TA0CCTL0; volatile unsigned int *ctl = &TA0CCTL0;
for(int i = 0; i < ARCH_MAXTIMERS; i++) { for (int i = 0; i < ARCH_MAXTIMERS; i++) {
*(ccr + i) = 0; *(ccr + i) = 0;
*(ctl + i) &= ~(CCIFG); *(ctl + i) &= ~(CCIFG);
*(ctl + i) &= ~(CCIE); *(ctl + i) &= ~(CCIE);
@ -46,7 +46,7 @@ interrupt(TIMER0_A1_VECTOR) __attribute__((naked)) timer0_a1_5_isr(void)
short taiv = TA0IV; short taiv = TA0IV;
short timer; short timer;
if(taiv & TAIFG) { if (taiv & TAIFG) {
DEBUG("Overflow\n"); DEBUG("Overflow\n");
} }
else { else {

View File

@ -25,7 +25,7 @@ bool cpu_install_irq(int IntNumber, void *HandlerAddr, int Priority)
VICIntEnClear = 1 << IntNumber; /* Disable Interrupt */ VICIntEnClear = 1 << IntNumber; /* Disable Interrupt */
if(IntNumber >= VIC_SIZE) { if (IntNumber >= VIC_SIZE) {
return (false); return (false);
} }
else { else {

View File

@ -24,15 +24,15 @@ void lpc2387_pclk_scale(uint32_t source, uint32_t target, uint32_t *pclksel, uin
uint32_t pclkdiv; uint32_t pclkdiv;
*prescale = source / target; *prescale = source / target;
if((*prescale % 16) == 0) { if ((*prescale % 16) == 0) {
*pclksel = 3; *pclksel = 3;
pclkdiv = 8; pclkdiv = 8;
} }
else if((*prescale % 8) == 0) { else if ((*prescale % 8) == 0) {
*pclksel = 0; *pclksel = 0;
pclkdiv = 4; pclkdiv = 4;
} }
else if((*prescale % 4) == 0) { else if ((*prescale % 4) == 0) {
*pclksel = 2; *pclksel = 2;
pclkdiv = 2; pclkdiv = 2;
} }
@ -43,7 +43,7 @@ void lpc2387_pclk_scale(uint32_t source, uint32_t target, uint32_t *pclksel, uin
*prescale /= pclkdiv; *prescale /= pclkdiv;
if(*prescale % 2) { if (*prescale % 2) {
(*prescale)++; (*prescale)++;
} }
} }
@ -77,7 +77,7 @@ bool install_irq(int IntNumber, void *HandlerAddr, int Priority)
VICIntEnClr = 1 << IntNumber; /* Disable Interrupt */ VICIntEnClr = 1 << IntNumber; /* Disable Interrupt */
if(IntNumber >= VIC_SIZE) { if (IntNumber >= VIC_SIZE) {
return (false); return (false);
} }
else { else {

View File

@ -87,21 +87,21 @@ gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback)
unsigned long cpsr = disableIRQ(); unsigned long cpsr = disableIRQ();
*en_clr |= bitmask; /* clear interrupt */ *en_clr |= bitmask; /* clear interrupt */
if((flags & GPIOINT_FALLING_EDGE) != 0) { if ((flags & GPIOINT_FALLING_EDGE) != 0) {
*en_f |= bitmask; /* enable falling edge */ *en_f |= bitmask; /* enable falling edge */
} }
else { else {
*en_f &= ~bitmask; /* disable falling edge */ *en_f &= ~bitmask; /* disable falling edge */
} }
if((flags & GPIOINT_RISING_EDGE) != 0) { if ((flags & GPIOINT_RISING_EDGE) != 0) {
*en_r |= bitmask; /* enable rising edge */ *en_r |= bitmask; /* enable rising edge */
} }
else { else {
*en_r &= ~bitmask; /* disable rising edge */ *en_r &= ~bitmask; /* disable rising edge */
} }
if(((flags & (GPIOINT_FALLING_EDGE | GPIOINT_RISING_EDGE)) != 0)) { if (((flags & (GPIOINT_FALLING_EDGE | GPIOINT_RISING_EDGE)) != 0)) {
cbdata[bit].callback = callback; cbdata[bit].callback = callback;
} }
@ -119,8 +119,8 @@ static void __attribute__((__no_instrument_function__)) test_irq(int port, unsig
/* Test each bit of rising and falling masks, if set trigger interrupt /* Test each bit of rising and falling masks, if set trigger interrupt
* on corresponding device */ * on corresponding device */
do { do {
if((pcb->callback != NULL)) { if ((pcb->callback != NULL)) {
if((r_mask & 1) | (f_mask & 1)) { if ((r_mask & 1) | (f_mask & 1)) {
pcb->callback(); /* pass to handler */ pcb->callback(); /* pass to handler */
} }
} }
@ -129,7 +129,7 @@ static void __attribute__((__no_instrument_function__)) test_irq(int port, unsig
r_mask >>= 1UL; r_mask >>= 1UL;
pcb++; pcb++;
} }
while((f_mask != 0) || (r_mask != 0)); while ((f_mask != 0) || (r_mask != 0));
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void GPIO_IRQHandler(void) __attribute__((interrupt("IRQ"))); void GPIO_IRQHandler(void) __attribute__((interrupt("IRQ")));
@ -142,7 +142,7 @@ void GPIO_IRQHandler(void) __attribute__((interrupt("IRQ")));
*/ */
void __attribute__((__no_instrument_function__)) GPIO_IRQHandler(void) void __attribute__((__no_instrument_function__)) GPIO_IRQHandler(void)
{ {
if(IO_INT_STAT & BIT0) { /* interrupt(s) on PORT0 pending */ if (IO_INT_STAT & BIT0) { /* interrupt(s) on PORT0 pending */
unsigned long int_stat_f = IO0_INT_STAT_F; /* save content */ unsigned long int_stat_f = IO0_INT_STAT_F; /* save content */
unsigned long int_stat_r = IO0_INT_STAT_R; /* save content */ unsigned long int_stat_r = IO0_INT_STAT_R; /* save content */
@ -152,7 +152,7 @@ void __attribute__((__no_instrument_function__)) GPIO_IRQHandler(void)
test_irq(0, int_stat_f, int_stat_r, gpioint0); test_irq(0, int_stat_f, int_stat_r, gpioint0);
} }
if(IO_INT_STAT & BIT2) { /* interrupt(s) on PORT2 pending */ if (IO_INT_STAT & BIT2) { /* interrupt(s) on PORT2 pending */
unsigned long int_stat_f = IO2_INT_STAT_F; /* save content */ unsigned long int_stat_f = IO2_INT_STAT_F; /* save content */
unsigned long int_stat_r = IO2_INT_STAT_R; /* save content */ unsigned long int_stat_r = IO2_INT_STAT_R; /* save content */

View File

@ -107,7 +107,7 @@ uint16_t adc_read(uint8_t channel)
uint32_t regVal, adc_data; uint32_t regVal, adc_data;
/* channel number is 0 through 7 */ /* channel number is 0 through 7 */
if(channel >= ADC_NUM) { if (channel >= ADC_NUM) {
channel = 0; /* reset channel number to 0 */ channel = 0; /* reset channel number to 0 */
} }
@ -122,19 +122,19 @@ uint16_t adc_read(uint8_t channel)
t2 = hwtimer_now(); t2 = hwtimer_now();
#endif #endif
while(1) { while (1) {
/* read result of A/D conversion */ /* read result of A/D conversion */
regVal = *(volatile unsigned long *)(AD0_BASE_ADDR + ADC_OFFSET + ADC_INDEX * channel); regVal = *(volatile unsigned long *)(AD0_BASE_ADDR + ADC_OFFSET + ADC_INDEX * channel);
/* wait until end of A/D convert */ /* wait until end of A/D convert */
if(regVal & ADC_DONE) { if (regVal & ADC_DONE) {
break; break;
} }
} }
AD0CR &= 0xF8FFFFFF; /* stop ADC now */ AD0CR &= 0xF8FFFFFF; /* stop ADC now */
if(regVal & ADC_OVERRUN) { /* save data when it's not overrun, otherwise, return zero */ if (regVal & ADC_OVERRUN) { /* save data when it's not overrun, otherwise, return zero */
return 0; return 0;
} }

View File

@ -53,14 +53,14 @@ void lpm_init(void)
void lpm_begin_awake(void) void lpm_begin_awake(void)
{ {
if(lpm >= LPM_SLEEP) { // wake up from deep sleep if (lpm >= LPM_SLEEP) { // wake up from deep sleep
init_clks1(); init_clks1();
} }
} }
void lpm_end_awake(void) void lpm_end_awake(void)
{ {
if(lpm >= LPM_SLEEP) { // wake up from deep sleep if (lpm >= LPM_SLEEP) { // wake up from deep sleep
init_clks2(); init_clks2();
} }
@ -73,7 +73,7 @@ void lpm_awake(void)
unsigned long usec = RTC_CTC; unsigned long usec = RTC_CTC;
#endif #endif
if(lpm >= LPM_SLEEP) { // wake up from deep sleep if (lpm >= LPM_SLEEP) { // wake up from deep sleep
/* benchmark */ /* benchmark */
init_clks1(); init_clks1();
init_clks2(); init_clks2();
@ -93,13 +93,13 @@ enum lpm_mode lpm_set(enum lpm_mode target)
enum lpm_mode last_lpm = lpm; enum lpm_mode last_lpm = lpm;
/* calculate target mcu power mode */ /* calculate target mcu power mode */
if(target == LPM_IDLE) { if (target == LPM_IDLE) {
target_flags = PM_IDLE; target_flags = PM_IDLE;
} }
else if(target == LPM_SLEEP) { else if (target == LPM_SLEEP) {
target_flags = PM_SLEEP; target_flags = PM_SLEEP;
} }
else if(target == LPM_POWERDOWN) { else if (target == LPM_POWERDOWN) {
target_flags = PM_POWERDOWN; target_flags = PM_POWERDOWN;
} }
else { else {

View File

@ -4,115 +4,115 @@
uint8_t iap_get_sector(uint32_t addr) uint8_t iap_get_sector(uint32_t addr)
{ {
if((addr >= 0x00000000) && (addr <= 0x00000FFF)) { if ((addr >= 0x00000000) && (addr <= 0x00000FFF)) {
return 0; return 0;
} }
if((addr >= 0x00001000) && (addr <= 0x00001FFF)) { if ((addr >= 0x00001000) && (addr <= 0x00001FFF)) {
return 1; return 1;
} }
if((addr >= 0x00002000) && (addr <= 0x00002FFF)) { if ((addr >= 0x00002000) && (addr <= 0x00002FFF)) {
return 2; return 2;
} }
if((addr >= 0x00003000) && (addr <= 0x00003FFF)) { if ((addr >= 0x00003000) && (addr <= 0x00003FFF)) {
return 3; return 3;
} }
if((addr >= 0x00004000) && (addr <= 0x00004FFF)) { if ((addr >= 0x00004000) && (addr <= 0x00004FFF)) {
return 4; return 4;
} }
if((addr >= 0x00005000) && (addr <= 0x00005FFF)) { if ((addr >= 0x00005000) && (addr <= 0x00005FFF)) {
return 5; return 5;
} }
if((addr >= 0x00006000) && (addr <= 0x00006FFF)) { if ((addr >= 0x00006000) && (addr <= 0x00006FFF)) {
return 6; return 6;
} }
if((addr >= 0x00007000) && (addr <= 0x00007FFF)) { if ((addr >= 0x00007000) && (addr <= 0x00007FFF)) {
return 7; return 7;
} }
if((addr >= 0x00008000) && (addr <= 0x0000FFFF)) { if ((addr >= 0x00008000) && (addr <= 0x0000FFFF)) {
return 8; return 8;
} }
if((addr >= 0x00010000) && (addr <= 0x00017FFF)) { if ((addr >= 0x00010000) && (addr <= 0x00017FFF)) {
return 9; return 9;
} }
if((addr >= 0x00018000) && (addr <= 0x0001FFFF)) { if ((addr >= 0x00018000) && (addr <= 0x0001FFFF)) {
return 10; return 10;
} }
if((addr >= 0x00020000) && (addr <= 0x00027FFF)) { if ((addr >= 0x00020000) && (addr <= 0x00027FFF)) {
return 11; return 11;
} }
if((addr >= 0x00028000) && (addr <= 0x0002FFFF)) { if ((addr >= 0x00028000) && (addr <= 0x0002FFFF)) {
return 12; return 12;
} }
if((addr >= 0x00030000) && (addr <= 0x00037FFF)) { if ((addr >= 0x00030000) && (addr <= 0x00037FFF)) {
return 13; return 13;
} }
if((addr >= 0x00038000) && (addr <= 0x0003FFFF)) { if ((addr >= 0x00038000) && (addr <= 0x0003FFFF)) {
return 14; return 14;
} }
if((addr >= 0x00040000) && (addr <= 0x00047FFF)) { if ((addr >= 0x00040000) && (addr <= 0x00047FFF)) {
return 15; return 15;
} }
if((addr >= 0x00048000) && (addr <= 0x0004FFFF)) { if ((addr >= 0x00048000) && (addr <= 0x0004FFFF)) {
return 16; return 16;
} }
if((addr >= 0x00050000) && (addr <= 0x00057FFF)) { if ((addr >= 0x00050000) && (addr <= 0x00057FFF)) {
return 17; return 17;
} }
if((addr >= 0x00058000) && (addr <= 0x0005FFFF)) { if ((addr >= 0x00058000) && (addr <= 0x0005FFFF)) {
return 18; return 18;
} }
if((addr >= 0x00060000) && (addr <= 0x00067FFF)) { if ((addr >= 0x00060000) && (addr <= 0x00067FFF)) {
return 19; return 19;
} }
if((addr >= 0x00068000) && (addr <= 0x0006FFFF)) { if ((addr >= 0x00068000) && (addr <= 0x0006FFFF)) {
return 20; return 20;
} }
if((addr >= 0x00070000) && (addr <= 0x00077FFF)) { if ((addr >= 0x00070000) && (addr <= 0x00077FFF)) {
return 21; return 21;
} }
if((addr >= 0x00078000) && (addr <= 0x00078FFF)) { if ((addr >= 0x00078000) && (addr <= 0x00078FFF)) {
return 22; return 22;
} }
if((addr >= 0x00079000) && (addr <= 0x00079FFF)) { if ((addr >= 0x00079000) && (addr <= 0x00079FFF)) {
return 23; return 23;
} }
if((addr >= 0x0007A000) && (addr <= 0x0007AFFF)) { if ((addr >= 0x0007A000) && (addr <= 0x0007AFFF)) {
return 24; return 24;
} }
if((addr >= 0x0007B000) && (addr <= 0x0007BFFF)) { if ((addr >= 0x0007B000) && (addr <= 0x0007BFFF)) {
return 25; return 25;
} }
if((addr >= 0x0007C000) && (addr <= 0x0007CFFF)) { if ((addr >= 0x0007C000) && (addr <= 0x0007CFFF)) {
return 26; return 26;
} }
if((addr >= 0x0007D000) && (addr <= 0x0007DFFF)) { if ((addr >= 0x0007D000) && (addr <= 0x0007DFFF)) {
return 27; return 27;
} }

View File

@ -110,16 +110,16 @@ void Isr_MCI(void)
xs = XferStat; xs = XferStat;
if(ms & 0x400) { /* A block transfer completed (DataBlockEnd) */ if (ms & 0x400) { /* A block transfer completed (DataBlockEnd) */
if(xs & 1) { /* In card read operation */ if (xs & 1) { /* In card read operation */
if(ms & 0x100) { /* When last block is received (DataEnd), */ if (ms & 0x100) { /* When last block is received (DataEnd), */
GPDMA_SOFT_BREQ = 0x10; /* Pop off remaining data in the MCIFIFO */ GPDMA_SOFT_BREQ = 0x10; /* Pop off remaining data in the MCIFIFO */
} }
n = (XferWp + 1) % N_BUF; /* Next write buffer */ n = (XferWp + 1) % N_BUF; /* Next write buffer */
XferWp = n; XferWp = n;
if(n == XferRp) { if (n == XferRp) {
xs |= 4; /* Check block overrun */ xs |= 4; /* Check block overrun */
} }
} }
@ -127,7 +127,7 @@ void Isr_MCI(void)
n = (XferRp + 1) % N_BUF; /* Next read buffer */ n = (XferRp + 1) % N_BUF; /* Next read buffer */
XferRp = n; XferRp = n;
if(n == XferWp) { if (n == XferWp) {
xs |= 4; /* Check block underrun */ xs |= 4; /* Check block underrun */
} }
} }
@ -143,12 +143,12 @@ void Isr_MCI(void)
void Isr_GPDMA(void) void Isr_GPDMA(void)
{ {
if(GPDMA_INT_TCSTAT & BIT0) { if (GPDMA_INT_TCSTAT & BIT0) {
GPDMA_INT_TCCLR = 0x01; /* Clear GPDMA interrupt flag */ GPDMA_INT_TCCLR = 0x01; /* Clear GPDMA interrupt flag */
if(XferStat & 2) { if (XferStat & 2) {
/* In write operation */ /* In write operation */
if(--XferWc == N_BUF) { /* Terminate LLI */ if (--XferWc == N_BUF) { /* Terminate LLI */
LinkList[XferRp % N_BUF][2] = 0; LinkList[XferRp % N_BUF][2] = 0;
} }
} }
@ -180,7 +180,7 @@ static void ready_reception(unsigned int blks, unsigned int bs)
dma_ctrl = 0x88492000 | (bs / 4); /* 1_000_1_0_00_010_010_010_010_************ */ dma_ctrl = 0x88492000 | (bs / 4); /* 1_000_1_0_00_010_010_010_010_************ */
/* Create link list */ /* Create link list */
for(n = 0; n < N_BUF; n++) { for (n = 0; n < N_BUF; n++) {
LinkList[n][0] = (unsigned long)&MCI_FIFO; LinkList[n][0] = (unsigned long)&MCI_FIFO;
LinkList[n][1] = (unsigned long)DmaBuff[n]; LinkList[n][1] = (unsigned long)DmaBuff[n];
LinkList[n][2] = (unsigned long)LinkList[(n + 1) % N_BUF]; LinkList[n][2] = (unsigned long)LinkList[(n + 1) % N_BUF];
@ -207,7 +207,7 @@ static void ready_reception(unsigned int blks, unsigned int bs)
MCI_CLEAR = 0x72A; /* Clear status flags */ MCI_CLEAR = 0x72A; /* Clear status flags */
MCI_MASK0 = 0x72A; /* DataBlockEnd StartBitErr DataEnd RxOverrun DataTimeOut DataCrcFail */ MCI_MASK0 = 0x72A; /* DataBlockEnd StartBitErr DataEnd RxOverrun DataTimeOut DataCrcFail */
for(n = 0; bs > 1; bs >>= 1, n += 0x10); for (n = 0; bs > 1; bs >>= 1, n += 0x10);
MCI_DATA_CTRL = n | 0xB; /* Start to receive data blocks */ MCI_DATA_CTRL = n | 0xB; /* Start to receive data blocks */
} }
@ -234,7 +234,7 @@ static void start_transmission(unsigned char blks)
dma_ctrl = 0x84492080; /* 1_000_0_1_00_010_010_010_010_000010000000 */ dma_ctrl = 0x84492080; /* 1_000_0_1_00_010_010_010_010_000010000000 */
/* Create link list */ /* Create link list */
for(n = 0; n < N_BUF; n++) { for (n = 0; n < N_BUF; n++) {
LinkList[n][0] = (unsigned long)DmaBuff[n]; LinkList[n][0] = (unsigned long)DmaBuff[n];
LinkList[n][1] = (unsigned long)&MCI_FIFO; LinkList[n][1] = (unsigned long)&MCI_FIFO;
LinkList[n][2] = (n == blks - 1) ? 0 : (unsigned long)LinkList[(n + 1) % N_BUF]; LinkList[n][2] = (n == blks - 1) ? 0 : (unsigned long)LinkList[(n + 1) % N_BUF];
@ -382,8 +382,8 @@ static int send_cmd(unsigned int idx, unsigned long arg, unsigned int rt, unsign
{ {
unsigned int s, mc; unsigned int s, mc;
if(idx & 0x80) { /* Send a CMD55 prior to the specified command if it is ACMD class */ if (idx & 0x80) { /* Send a CMD55 prior to the specified command if it is ACMD class */
if(!send_cmd(CMD55, (unsigned long)CardRCA << 16, 1, buff) /* When CMD55 is faild, */ if (!send_cmd(CMD55, (unsigned long)CardRCA << 16, 1, buff) /* When CMD55 is faild, */
|| !(buff[0] & 0x00000020)) { || !(buff[0] & 0x00000020)) {
return 0; /* exit with error */ return 0; /* exit with error */
} }
@ -395,20 +395,20 @@ static int send_cmd(unsigned int idx, unsigned long arg, unsigned int rt, unsign
MCI_COMMAND = 0; /* Cancel to transmit command */ MCI_COMMAND = 0; /* Cancel to transmit command */
MCI_CLEAR = 0x0C5; /* Clear status flags */ MCI_CLEAR = 0x0C5; /* Clear status flags */
for(s = 0; s < 10; s++) { for (s = 0; s < 10; s++) {
MCI_STATUS; /* Skip lock out time of command reg. */ MCI_STATUS; /* Skip lock out time of command reg. */
} }
} }
while(MCI_STATUS & 0x00800); while (MCI_STATUS & 0x00800);
MCI_ARGUMENT = arg; /* Set the argument into argument register */ MCI_ARGUMENT = arg; /* Set the argument into argument register */
mc = 0x400 | idx; /* Enable bit + index */ mc = 0x400 | idx; /* Enable bit + index */
if(rt == 1) { if (rt == 1) {
mc |= 0x040; /* Set Response bit to reveice short resp */ mc |= 0x040; /* Set Response bit to reveice short resp */
} }
if(rt > 1) { if (rt > 1) {
mc |= 0x0C0; /* Set Response and LongResp bit to receive long resp */ mc |= 0x0C0; /* Set Response and LongResp bit to receive long resp */
} }
@ -417,35 +417,35 @@ static int send_cmd(unsigned int idx, unsigned long arg, unsigned int rt, unsign
//Timer[1] = 100; //Timer[1] = 100;
uint32_t timerstart = hwtimer_now(); uint32_t timerstart = hwtimer_now();
for(;;) { /* Wait for end of the cmd/resp transaction */ for (;;) { /* Wait for end of the cmd/resp transaction */
//if (!Timer[1]) return 0; //if (!Timer[1]) return 0;
if(hwtimer_now() - timerstart > 10000) { if (hwtimer_now() - timerstart > 10000) {
return 0; return 0;
} }
s = MCI_STATUS; /* Get the transaction status */ s = MCI_STATUS; /* Get the transaction status */
if(rt == 0) { if (rt == 0) {
if(s & 0x080) { if (s & 0x080) {
return 1; /* CmdSent */ return 1; /* CmdSent */
} }
} }
else { else {
if(s & 0x040) { if (s & 0x040) {
break; /* CmdRespEnd */ break; /* CmdRespEnd */
} }
if(s & 0x001) { if (s & 0x001) {
/* CmdCrcFail */ /* CmdCrcFail */
if(idx == 1 || idx == 12 || idx == 41) { /* Ignore CRC error on CMD1/12/41 */ if (idx == 1 || idx == 12 || idx == 41) { /* Ignore CRC error on CMD1/12/41 */
break; break;
} }
return 0; return 0;
} }
if(s & 0x004) { if (s & 0x004) {
return 0; /* CmdTimeOut */ return 0; /* CmdTimeOut */
} }
} }
@ -453,7 +453,7 @@ static int send_cmd(unsigned int idx, unsigned long arg, unsigned int rt, unsign
buff[0] = MCI_RESP0; /* Read the response words */ buff[0] = MCI_RESP0; /* Read the response words */
if(rt == 2) { if (rt == 2) {
buff[1] = MCI_RESP1; buff[1] = MCI_RESP1;
buff[2] = MCI_RESP2; buff[2] = MCI_RESP2;
buff[3] = MCI_RESP3; buff[3] = MCI_RESP3;
@ -480,8 +480,8 @@ static int wait_ready(unsigned short tmr)
uint32_t stoppoll = hwtimer_now() + tmr * 100; uint32_t stoppoll = hwtimer_now() + tmr * 100;
bool bBreak = false; bool bBreak = false;
while(hwtimer_now() < stoppoll/*Timer[0]*/) { while (hwtimer_now() < stoppoll/*Timer[0]*/) {
if(send_cmd(CMD13, (unsigned long) CardRCA << 16, 1, &rc) && ((rc & 0x01E00) == 0x00800)) { if (send_cmd(CMD13, (unsigned long) CardRCA << 16, 1, &rc) && ((rc & 0x01E00) == 0x00800)) {
bBreak = true; bBreak = true;
break; break;
} }
@ -529,7 +529,7 @@ DSTATUS MCI_initialize(void)
unsigned long resp[4]; unsigned long resp[4];
unsigned char ty; unsigned char ty;
if(Stat & STA_NODISK) { if (Stat & STA_NODISK) {
return Stat; /* No card in the socket */ return Stat; /* No card in the socket */
} }
@ -551,23 +551,23 @@ DSTATUS MCI_initialize(void)
uint32_t start = hwtimer_now(); uint32_t start = hwtimer_now();
/* SDC Ver2 */ /* SDC Ver2 */
if(send_cmd(CMD8, 0x1AA, 1, resp) && (resp[0] & 0xFFF) == 0x1AA) { if (send_cmd(CMD8, 0x1AA, 1, resp) && (resp[0] & 0xFFF) == 0x1AA) {
/* The card can work at vdd range of 2.7-3.6V */ /* The card can work at vdd range of 2.7-3.6V */
DEBUG("SDC Ver. 2\n"); DEBUG("SDC Ver. 2\n");
do { /* Wait while card is busy state (use ACMD41 with HCS bit) */ do { /* Wait while card is busy state (use ACMD41 with HCS bit) */
/* This loop will take a time. Insert wai_tsk(1) here for multitask envilonment. */ /* This loop will take a time. Insert wai_tsk(1) here for multitask envilonment. */
if(hwtimer_now() > start + 1000000/*!Timer[0]*/) { if (hwtimer_now() > start + 1000000/*!Timer[0]*/) {
DEBUG("%s, %d: Timeout #1\n", __FILE__, __LINE__); DEBUG("%s, %d: Timeout #1\n", __FILE__, __LINE__);
goto di_fail; goto di_fail;
} }
} }
while(!send_cmd(ACMD41, 0x40FF8000, 1, resp) || !(resp[0] & 0x80000000)); while (!send_cmd(ACMD41, 0x40FF8000, 1, resp) || !(resp[0] & 0x80000000));
ty = (resp[0] & 0x40000000) ? CT_SD2 | CT_BLOCK : CT_SD2; /* Check CCS bit in the OCR */ ty = (resp[0] & 0x40000000) ? CT_SD2 | CT_BLOCK : CT_SD2; /* Check CCS bit in the OCR */
} }
else { /* SDC Ver1 or MMC */ else { /* SDC Ver1 or MMC */
if(send_cmd(ACMD41, 0x00FF8000, 1, resp)) { if (send_cmd(ACMD41, 0x00FF8000, 1, resp)) {
DEBUG("SDC Ver. 1\n"); DEBUG("SDC Ver. 1\n");
ty = CT_SD1; ty = CT_SD1;
cmd = ACMD41; /* ACMD41 is accepted -> SDC Ver1 */ cmd = ACMD41; /* ACMD41 is accepted -> SDC Ver1 */
@ -582,13 +582,13 @@ DSTATUS MCI_initialize(void)
DEBUG("%s, %d: %lX\n", __FILE__, __LINE__, resp[0]); DEBUG("%s, %d: %lX\n", __FILE__, __LINE__, resp[0]);
/* This loop will take a time. Insert wai_tsk(1) here for multitask envilonment. */ /* This loop will take a time. Insert wai_tsk(1) here for multitask envilonment. */
if(hwtimer_now() > start + 1000000/*!Timer[0]*/) { if (hwtimer_now() > start + 1000000/*!Timer[0]*/) {
DEBUG("now: %lu, started at: %lu\n", hwtimer_now(), start); DEBUG("now: %lu, started at: %lu\n", hwtimer_now(), start);
DEBUG("%s, %d: Timeout #2\n", __FILE__, __LINE__); DEBUG("%s, %d: Timeout #2\n", __FILE__, __LINE__);
goto di_fail; goto di_fail;
} }
} }
while(!send_cmd(cmd, 0x00FF8000, 1, resp) || !(resp[0] & 0x80000000)); while (!send_cmd(cmd, 0x00FF8000, 1, resp) || !(resp[0] & 0x80000000));
} }
CardType = ty; /* Save card type */ CardType = ty; /* Save card type */
@ -596,19 +596,19 @@ DSTATUS MCI_initialize(void)
/*---- Card is 'ready' state ----*/ /*---- Card is 'ready' state ----*/
if(!send_cmd(CMD2, 0, 2, resp)) { if (!send_cmd(CMD2, 0, 2, resp)) {
DEBUG("%s, %d: Failed entering ident state", __FILE__, __LINE__); DEBUG("%s, %d: Failed entering ident state", __FILE__, __LINE__);
goto di_fail; /* Enter ident state */ goto di_fail; /* Enter ident state */
} }
for(n = 0; n < 4; n++) { for (n = 0; n < 4; n++) {
bswap_cp(&CardInfo[n * 4 + 16], &resp[n]); /* Save CID */ bswap_cp(&CardInfo[n * 4 + 16], &resp[n]); /* Save CID */
} }
/*---- Card is 'ident' state ----*/ /*---- Card is 'ident' state ----*/
if(ty & CT_SDC) { /* SDC: Get generated RCA and save it */ if (ty & CT_SDC) { /* SDC: Get generated RCA and save it */
if(!send_cmd(CMD3, 0, 1, resp)) { if (!send_cmd(CMD3, 0, 1, resp)) {
DEBUG("%s, %d: Failed generating RCA\n", __FILE__, __LINE__); DEBUG("%s, %d: Failed generating RCA\n", __FILE__, __LINE__);
goto di_fail; goto di_fail;
} }
@ -616,7 +616,7 @@ DSTATUS MCI_initialize(void)
CardRCA = (unsigned short)(resp[0] >> 16); CardRCA = (unsigned short)(resp[0] >> 16);
} }
else { /* MMC: Assign RCA to the card */ else { /* MMC: Assign RCA to the card */
if(!send_cmd(CMD3, 1 << 16, 1, resp)) { if (!send_cmd(CMD3, 1 << 16, 1, resp)) {
goto di_fail; goto di_fail;
} }
@ -625,23 +625,23 @@ DSTATUS MCI_initialize(void)
/*---- Card is 'stby' state ----*/ /*---- Card is 'stby' state ----*/
if(!send_cmd(CMD9, (unsigned long)CardRCA << 16, 2, resp)) { /* Get CSD and save it */ if (!send_cmd(CMD9, (unsigned long)CardRCA << 16, 2, resp)) { /* Get CSD and save it */
goto di_fail; goto di_fail;
} }
for(n = 0; n < 4; n++) { for (n = 0; n < 4; n++) {
bswap_cp(&CardInfo[n * 4], &resp[n]); bswap_cp(&CardInfo[n * 4], &resp[n]);
} }
if(!send_cmd(CMD7, (unsigned long)CardRCA << 16, 1, resp)) { /* Select card */ if (!send_cmd(CMD7, (unsigned long)CardRCA << 16, 1, resp)) { /* Select card */
//printf("MCI CMD7 fail\n"); //printf("MCI CMD7 fail\n");
goto di_fail; goto di_fail;
} }
/*---- Card is 'tran' state ----*/ /*---- Card is 'tran' state ----*/
if(!(ty & CT_BLOCK)) { /* Set data block length to 512 (for byte addressing cards) */ if (!(ty & CT_BLOCK)) { /* Set data block length to 512 (for byte addressing cards) */
if(!send_cmd(CMD16, 512, 1, resp) || (resp[0] & 0xFDF90000)) { if (!send_cmd(CMD16, 512, 1, resp) || (resp[0] & 0xFDF90000)) {
//printf("MCI CMD16 fail\n"); //printf("MCI CMD16 fail\n");
goto di_fail; goto di_fail;
} }
@ -649,8 +649,8 @@ DSTATUS MCI_initialize(void)
#if USE_4BIT #if USE_4BIT
if(ty & CT_SDC) { /* Set wide bus mode (for SDCs) */ if (ty & CT_SDC) { /* Set wide bus mode (for SDCs) */
if(!send_cmd(ACMD6, 2, 1, resp) /* Set bus mode of SDC */ if (!send_cmd(ACMD6, 2, 1, resp) /* Set bus mode of SDC */
|| (resp[0] & 0xFDF90000)) { || (resp[0] & 0xFDF90000)) {
//printf("MCI ACMD6 fail\n"); //printf("MCI ACMD6 fail\n");
goto di_fail; goto di_fail;
@ -703,19 +703,19 @@ DRESULT MCI_read(unsigned char *buff, unsigned long sector, unsigned char count)
unsigned char rp; unsigned char rp;
if(count < 1 || count > 127) { if (count < 1 || count > 127) {
return RES_PARERR; /* Check parameter */ return RES_PARERR; /* Check parameter */
} }
if(Stat & STA_NOINIT) { if (Stat & STA_NOINIT) {
return RES_NOTRDY; /* Check drive status */ return RES_NOTRDY; /* Check drive status */
} }
if(!(CardType & CT_BLOCK)) { if (!(CardType & CT_BLOCK)) {
sector *= 512; /* Convert LBA to byte address if needed */ sector *= 512; /* Convert LBA to byte address if needed */
} }
if(!wait_ready(500)) { if (!wait_ready(500)) {
return RES_ERROR; /* Make sure that card is tran state */ return RES_ERROR; /* Make sure that card is tran state */
} }
@ -723,17 +723,17 @@ DRESULT MCI_read(unsigned char *buff, unsigned long sector, unsigned char count)
cmd = (count > 1) ? CMD18 : CMD17; /* Transfer type: Single block or Multiple block */ cmd = (count > 1) ? CMD18 : CMD17; /* Transfer type: Single block or Multiple block */
if(send_cmd(cmd, sector, 1, &resp) /* Start to read */ if (send_cmd(cmd, sector, 1, &resp) /* Start to read */
&& !(resp & 0xC0580000)) { && !(resp & 0xC0580000)) {
rp = 0; rp = 0;
do { do {
while((rp == XferWp) && !(XferStat & 0xC)) { while ((rp == XferWp) && !(XferStat & 0xC)) {
/* Wait for block arrival */ /* Wait for block arrival */
/* This loop will take a time. Replace it with sync process for multitask envilonment. */ /* This loop will take a time. Replace it with sync process for multitask envilonment. */
} }
if(XferStat & 0xC) { if (XferStat & 0xC) {
break; /* Abort if any error has occured */ break; /* Abort if any error has occured */
} }
@ -741,15 +741,15 @@ DRESULT MCI_read(unsigned char *buff, unsigned long sector, unsigned char count)
XferRp = rp = (rp + 1) % N_BUF; /* Next DMA buffer */ XferRp = rp = (rp + 1) % N_BUF; /* Next DMA buffer */
if(XferStat & 0xC) { if (XferStat & 0xC) {
break; /* Abort if overrun has occured */ break; /* Abort if overrun has occured */
} }
buff += 512; /* Next user buffer address */ buff += 512; /* Next user buffer address */
} }
while(--count); while (--count);
if(cmd == CMD18) { /* Terminate to read (MB) */ if (cmd == CMD18) { /* Terminate to read (MB) */
send_cmd(CMD12, 0, 1, &resp); send_cmd(CMD12, 0, 1, &resp);
} }
} }
@ -777,33 +777,33 @@ DRESULT MCI_write(const unsigned char *buff, unsigned long sector, unsigned char
unsigned int cmd; unsigned int cmd;
unsigned char wp, xc; unsigned char wp, xc;
if(count < 1 || count > 127) { if (count < 1 || count > 127) {
return RES_PARERR; /* Check parameter */ return RES_PARERR; /* Check parameter */
} }
if(Stat & STA_NOINIT) { if (Stat & STA_NOINIT) {
return RES_NOTRDY; /* Check drive status */ return RES_NOTRDY; /* Check drive status */
} }
if(Stat & STA_PROTECT) { if (Stat & STA_PROTECT) {
return RES_WRPRT; /* Check write protection */ return RES_WRPRT; /* Check write protection */
} }
if(!(CardType & CT_BLOCK)) { if (!(CardType & CT_BLOCK)) {
sector *= 512; /* Convert LBA to byte address if needed */ sector *= 512; /* Convert LBA to byte address if needed */
} }
if(!wait_ready(500)) { if (!wait_ready(500)) {
return RES_ERROR; /* Make sure that card is tran state */ return RES_ERROR; /* Make sure that card is tran state */
} }
if(count == 1) { /* Single block write */ if (count == 1) { /* Single block write */
cmd = CMD24; cmd = CMD24;
} }
else { /* Multiple block write */ else { /* Multiple block write */
cmd = (CardType & CT_SDC) ? ACMD23 : CMD23; cmd = (CardType & CT_SDC) ? ACMD23 : CMD23;
if(!send_cmd(cmd, count, 1, &rc) /* Preset number of blocks to write */ if (!send_cmd(cmd, count, 1, &rc) /* Preset number of blocks to write */
|| (rc & 0xC0580000)) { || (rc & 0xC0580000)) {
return RES_ERROR; return RES_ERROR;
} }
@ -811,7 +811,7 @@ DRESULT MCI_write(const unsigned char *buff, unsigned long sector, unsigned char
cmd = CMD25; cmd = CMD25;
} }
if(!send_cmd(cmd, sector, 1, &rc) /* Send a write command */ if (!send_cmd(cmd, sector, 1, &rc) /* Send a write command */
|| (rc & 0xC0580000)) { || (rc & 0xC0580000)) {
return RES_ERROR; return RES_ERROR;
} }
@ -825,24 +825,24 @@ DRESULT MCI_write(const unsigned char *buff, unsigned long sector, unsigned char
count--; count--;
buff += 512; /* Next user buffer address */ buff += 512; /* Next user buffer address */
} }
while(count && wp < N_BUF); while (count && wp < N_BUF);
XferWp = wp = wp % N_BUF; XferWp = wp = wp % N_BUF;
start_transmission(xc); /* Start transmission */ start_transmission(xc); /* Start transmission */
while(count) { while (count) {
while((wp == XferRp) && !(XferStat & 0xC)) { /* Wait for block FIFO not full */ while ((wp == XferRp) && !(XferStat & 0xC)) { /* Wait for block FIFO not full */
/* This loop will take a time. Replace it with sync process for multitask envilonment. */ /* This loop will take a time. Replace it with sync process for multitask envilonment. */
} }
if(XferStat & 0xC) { if (XferStat & 0xC) {
break; /* Abort if block underrun or any MCI error has occured */ break; /* Abort if block underrun or any MCI error has occured */
} }
Copy_un2al(DmaBuff[wp], (unsigned char *)(unsigned int)buff, 512); /* Push a block */ Copy_un2al(DmaBuff[wp], (unsigned char *)(unsigned int)buff, 512); /* Push a block */
XferWp = wp = (wp + 1) % N_BUF; /* Next DMA buffer */ XferWp = wp = (wp + 1) % N_BUF; /* Next DMA buffer */
if(XferStat & 0xC) { if (XferStat & 0xC) {
break; /* Abort if block underrun has occured */ break; /* Abort if block underrun has occured */
} }
@ -850,15 +850,15 @@ DRESULT MCI_write(const unsigned char *buff, unsigned long sector, unsigned char
buff += 512; /* Next user buffer address */ buff += 512; /* Next user buffer address */
} }
while(!(XferStat & 0xC)); /* Wait for all blocks sent (block underrun) */ while (!(XferStat & 0xC)); /* Wait for all blocks sent (block underrun) */
if(XferStat & 0x8) { if (XferStat & 0x8) {
count = 1; /* Abort if any MCI error has occured */ count = 1; /* Abort if any MCI error has occured */
} }
stop_transfer(); /* Close data path */ stop_transfer(); /* Close data path */
if(cmd == CMD25 && (CardType & CT_SDC)) { /* Terminate to write (SDC w/MB) */ if (cmd == CMD25 && (CardType & CT_SDC)) { /* Terminate to write (SDC w/MB) */
send_cmd(CMD12, 0, 1, &rc); send_cmd(CMD12, 0, 1, &rc);
} }
@ -883,7 +883,7 @@ DRESULT MCI_ioctl(
unsigned long resp[4], d, *dp, st, ed; unsigned long resp[4], d, *dp, st, ed;
if(Stat & STA_NOINIT) { if (Stat & STA_NOINIT) {
return RES_NOTRDY; return RES_NOTRDY;
} }
@ -891,14 +891,14 @@ DRESULT MCI_ioctl(
switch(ctrl) { switch(ctrl) {
case CTRL_SYNC : /* Make sure that all data has been written on the media */ case CTRL_SYNC : /* Make sure that all data has been written on the media */
if(wait_ready(500)) { /* Wait for card enters tarn state */ if (wait_ready(500)) { /* Wait for card enters tarn state */
res = RES_OK; res = RES_OK;
} }
break; break;
case GET_SECTOR_COUNT : /* Get number of sectors on the disk (unsigned long) */ case GET_SECTOR_COUNT : /* Get number of sectors on the disk (unsigned long) */
if((CardInfo[0] >> 6) == 1) { /* SDC CSD v2.0 */ if ((CardInfo[0] >> 6) == 1) { /* SDC CSD v2.0 */
d = ((unsigned short)CardInfo[8] << 8) + CardInfo[9] + 1; d = ((unsigned short)CardInfo[8] << 8) + CardInfo[9] + 1;
*(unsigned long *)buff = d << 10; *(unsigned long *)buff = d << 10;
} }
@ -917,11 +917,11 @@ DRESULT MCI_ioctl(
break; break;
case GET_BLOCK_SIZE : /* Get erase block size in unit of sectors (unsigned long) */ case GET_BLOCK_SIZE : /* Get erase block size in unit of sectors (unsigned long) */
if(CardType & CT_SD2) { /* SDC ver 2.00 */ if (CardType & CT_SD2) { /* SDC ver 2.00 */
*(unsigned long *)buff = 16UL << (CardInfo[10] >> 4); *(unsigned long *)buff = 16UL << (CardInfo[10] >> 4);
} }
else { /* SDC ver 1.XX or MMC */ else { /* SDC ver 1.XX or MMC */
if(CardType & CT_SD1) { /* SDC v1 */ if (CardType & CT_SD1) { /* SDC v1 */
*(unsigned long *)buff = (((CardInfo[10] & 63) << 1) + ((unsigned short)(CardInfo[11] & 128) >> 7) + 1) << ((CardInfo[13] >> 6) - 1); *(unsigned long *)buff = (((CardInfo[10] & 63) << 1) + ((unsigned short)(CardInfo[11] & 128) >> 7) + 1) << ((CardInfo[13] >> 6) - 1);
} }
else { /* MMC */ else { /* MMC */
@ -933,7 +933,7 @@ DRESULT MCI_ioctl(
break; break;
case CTRL_ERASE_SECTOR : /* Erase a block of sectors */ case CTRL_ERASE_SECTOR : /* Erase a block of sectors */
if(!(CardType & CT_SDC) || (!(CardInfo[0] >> 6) && !(CardInfo[10] & 0x40))) { if (!(CardType & CT_SDC) || (!(CardInfo[0] >> 6) && !(CardInfo[10] & 0x40))) {
break; /* Check if sector erase can be applied to the card */ break; /* Check if sector erase can be applied to the card */
} }
@ -941,12 +941,12 @@ DRESULT MCI_ioctl(
st = dp[0]; st = dp[0];
ed = dp[1]; ed = dp[1];
if(!(CardType & CT_BLOCK)) { if (!(CardType & CT_BLOCK)) {
st *= 512; st *= 512;
ed *= 512; ed *= 512;
} }
if(send_cmd(CMD32, st, 1, resp) && send_cmd(CMD33, ed, 1, resp) && send_cmd(CMD38, 0, 1, resp) && wait_ready(30000)) { if (send_cmd(CMD32, st, 1, resp) && send_cmd(CMD33, ed, 1, resp) && send_cmd(CMD38, 0, 1, resp) && wait_ready(30000)) {
res = RES_OK; res = RES_OK;
} }
@ -991,15 +991,15 @@ DRESULT MCI_ioctl(
break; break;
case MMC_GET_SDSTAT : /* Receive SD status as a data block (64 bytes) */ case MMC_GET_SDSTAT : /* Receive SD status as a data block (64 bytes) */
if(CardType & CT_SDC) { /* SDC */ if (CardType & CT_SDC) { /* SDC */
if(wait_ready(500)) { if (wait_ready(500)) {
ready_reception(1, 64); /* Ready to receive data blocks */ ready_reception(1, 64); /* Ready to receive data blocks */
if(send_cmd(ACMD13, 0, 1, resp) /* Start to read */ if (send_cmd(ACMD13, 0, 1, resp) /* Start to read */
&& !(resp[0] & 0xC0580000)) { && !(resp[0] & 0xC0580000)) {
while((XferWp == 0) && !(XferStat & 0xC)); while ((XferWp == 0) && !(XferStat & 0xC));
if(!(XferStat & 0xC)) { if (!(XferStat & 0xC)) {
Copy_al2un(buff, DmaBuff[0], 64); Copy_al2un(buff, DmaBuff[0], 64);
res = RES_OK; res = RES_OK;
} }

View File

@ -51,7 +51,7 @@ static volatile time_t epoch;
void void
rtc_set_localtime(struct tm *localt) rtc_set_localtime(struct tm *localt)
{ {
if(localt == NULL) { if (localt == NULL) {
return; return;
} }
@ -84,7 +84,7 @@ void rtc_reset(void)
void void
rtc_set_alarm(struct tm *localt, enum rtc_alarm_mask mask) rtc_set_alarm(struct tm *localt, enum rtc_alarm_mask mask)
{ {
if(localt != NULL) { if (localt != NULL) {
RTC_ALSEC = localt->tm_sec; RTC_ALSEC = localt->tm_sec;
RTC_ALMIN = localt->tm_min; RTC_ALMIN = localt->tm_min;
RTC_ALHOUR = localt->tm_hour; RTC_ALHOUR = localt->tm_hour;
@ -105,7 +105,7 @@ rtc_set_alarm(struct tm *localt, enum rtc_alarm_mask mask)
enum rtc_alarm_mask enum rtc_alarm_mask
rtc_get_alarm(struct tm *localt) rtc_get_alarm(struct tm *localt)
{ {
if(localt != NULL) { if (localt != NULL) {
localt->tm_sec = RTC_ALSEC; localt->tm_sec = RTC_ALSEC;
localt->tm_min = RTC_ALMIN; localt->tm_min = RTC_ALMIN;
localt->tm_hour = RTC_ALHOUR; localt->tm_hour = RTC_ALHOUR;
@ -125,17 +125,17 @@ void RTC_IRQHandler(void)
{ {
lpm_begin_awake(); lpm_begin_awake();
if(RTC_ILR & ILR_RTSSF) { if (RTC_ILR & ILR_RTSSF) {
/* sub second interrupt (does not need flag-clearing) */ /* sub second interrupt (does not need flag-clearing) */
} }
else if(RTC_ILR & ILR_RTCCIF) { else if (RTC_ILR & ILR_RTCCIF) {
/* counter increase interrupt */ /* counter increase interrupt */
RTC_ILR |= ILR_RTCCIF; RTC_ILR |= ILR_RTCCIF;
epoch += 60 * 60; /* add 1 hour */ epoch += 60 * 60; /* add 1 hour */
} }
else if(RTC_ILR & ILR_RTCALF) { else if (RTC_ILR & ILR_RTCALF) {
RTC_ILR |= ILR_RTCALF; RTC_ILR |= ILR_RTCALF;
RTC_AMR = 0xff; /* disable alarm irq */ RTC_AMR = 0xff; /* disable alarm irq */
DEBUG("Ring\n"); DEBUG("Ring\n");
@ -169,7 +169,7 @@ void rtc_init(void)
/* initialize clock with valid unix compatible values /* initialize clock with valid unix compatible values
* If RTC_YEAR contains an value larger unix time_t we must reset. */ * If RTC_YEAR contains an value larger unix time_t we must reset. */
if(RTC_YEAR > 2037) { if (RTC_YEAR > 2037) {
rtc_reset(); rtc_reset();
} }
@ -188,7 +188,7 @@ time_t rtc_time(struct timeval *time)
sec = RTC_SEC; sec = RTC_SEC;
min = RTC_MIN; min = RTC_MIN;
while(usec != (RTC_CTC >> 1)) { while (usec != (RTC_CTC >> 1)) {
usec = (RTC_CTC >> 1); usec = (RTC_CTC >> 1);
sec = RTC_SEC; sec = RTC_SEC;
min = RTC_MIN; min = RTC_MIN;
@ -197,7 +197,7 @@ time_t rtc_time(struct timeval *time)
sec += min * 60; /* add number of minutes */ sec += min * 60; /* add number of minutes */
sec += epoch; /* add precalculated epoch in hour granularity */ sec += epoch; /* add precalculated epoch in hour granularity */
if(time != NULL) { if (time != NULL) {
usec = usec * 15625; usec = usec * 15625;
usec >>= 9; usec >>= 9;
time->tv_sec = sec; time->tv_sec = sec;
@ -217,7 +217,7 @@ void rtc_disable(void)
void void
rtc_get_localtime(struct tm *localt) rtc_get_localtime(struct tm *localt)
{ {
if(localt != NULL) { if (localt != NULL) {
localt->tm_sec = RTC_SEC; localt->tm_sec = RTC_SEC;
localt->tm_min = RTC_MIN; localt->tm_min = RTC_MIN;
localt->tm_hour = RTC_HOUR; localt->tm_hour = RTC_HOUR;
@ -234,7 +234,7 @@ void gettimeofday_r(struct _reent *r, struct timeval *ptimeval, struct timezone
{ {
r->_errno = 0; r->_errno = 0;
if(ptimeval != NULL) { if (ptimeval != NULL) {
rtc_time(ptimeval); rtc_time(ptimeval);
} }
} }

View File

@ -63,7 +63,7 @@ char *thread_stack_init(void *task_func, void *stack_start, int stack_size)
--stk; --stk;
/* Space for registers. */ /* Space for registers. */
for(unsigned int i = 15; i > 4; i--) { for (unsigned int i = 15; i > 4; i--) {
*stk = i; *stk = i;
--stk; --stk;
} }

View File

@ -31,11 +31,11 @@ void flashrom_write(uint8_t *dst, uint8_t *src, size_t size)
FCTL3 = FWKEY; /* Lock = 0 */ FCTL3 = FWKEY; /* Lock = 0 */
busy_wait(); busy_wait();
for(i = size; i > 0; i--) { for (i = size; i > 0; i--) {
FCTL1 = FWKEY | WRT; FCTL1 = FWKEY | WRT;
*dst = *src; /* program Flash word */ *dst = *src; /* program Flash word */
while(!(FCTL3 & WAIT)) { while (!(FCTL3 & WAIT)) {
nop(); nop();
} }
} }
@ -82,7 +82,7 @@ void finish(uint8_t istate)
static inline void busy_wait(void) static inline void busy_wait(void)
{ {
/* Wait for BUSY = 0, not needed unless run from RAM */ /* Wait for BUSY = 0, not needed unless run from RAM */
while(FCTL3 & 0x0001) { while (FCTL3 & 0x0001) {
nop(); nop();
} }
} }

View File

@ -70,14 +70,14 @@ void hwtimer_arch_init(void (*handler)(int), uint32_t fcpu)
void hwtimer_arch_enable_interrupt(void) void hwtimer_arch_enable_interrupt(void)
{ {
for(int i = 0; i < ARCH_MAXTIMERS; i++) { for (int i = 0; i < ARCH_MAXTIMERS; i++) {
TA0_enable_interrupt(i); TA0_enable_interrupt(i);
} }
} }
void hwtimer_arch_disable_interrupt(void) void hwtimer_arch_disable_interrupt(void)
{ {
for(int i = 0; i < ARCH_MAXTIMERS; i++) { for (int i = 0; i < ARCH_MAXTIMERS; i++) {
TA0_disable_interrupt(i); TA0_disable_interrupt(i);
} }
} }

View File

@ -86,7 +86,7 @@ inline void __exit_isr(void)
{ {
__inISR = 0; __inISR = 0;
if(sched_context_switch_request) { if (sched_context_switch_request) {
sched_run(); sched_run();
} }

View File

@ -84,7 +84,7 @@ extern volatile uint32_t cpu_speed;
void msp430_set_cpu_speed(uint32_t speed); void msp430_set_cpu_speed(uint32_t speed);
void msp430_cpu_init(void); /* Rename to cpu_init() later! */ void msp430_cpu_init(void); /* Rename to cpu_init() later!*/
#define cpu_init() msp430_cpu_init() #define cpu_init() msp430_cpu_init()
void msp430_init_dco(void); void msp430_init_dco(void);

View File

@ -12,7 +12,7 @@ unsigned int disableIRQ()
__asm__("mov.w r2,%0" : "=r"(state)); __asm__("mov.w r2,%0" : "=r"(state));
state &= GIE; state &= GIE;
if(state) { if (state) {
dINT(); dINT();
} }
@ -25,7 +25,7 @@ unsigned int enableIRQ()
__asm__("mov.w r2,%0" : "=r"(state)); __asm__("mov.w r2,%0" : "=r"(state));
state &= GIE; state &= GIE;
if(!state) { if (!state) {
eINT(); eINT();
} }
@ -34,7 +34,7 @@ unsigned int enableIRQ()
void restoreIRQ(unsigned int state) void restoreIRQ(unsigned int state)
{ {
if(state) { if (state) {
eINT(); eINT();
} }
} }

View File

@ -113,7 +113,7 @@ msp430_cpu_init(void)
// lpm_init(); // lpm_init();
eint(); eint();
if((uintptr_t)cur_break & 1) { /* Workaround for msp430-ld bug! */ if ((uintptr_t)cur_break & 1) { /* Workaround for msp430-ld bug!*/
cur_break++; cur_break++;
} }
} }
@ -136,7 +136,7 @@ void *sbrk(int incr)
asmv("mov r1, %0" : "=r"(stack_pointer)); asmv("mov r1, %0" : "=r"(stack_pointer));
stack_pointer -= STACK_EXTRA; stack_pointer -= STACK_EXTRA;
if(incr > (stack_pointer - cur_break)) { if (incr > (stack_pointer - cur_break)) {
return (void *) - 1; /* ENOMEM */ return (void *) - 1; /* ENOMEM */
} }

View File

@ -31,11 +31,11 @@ void flashrom_write(uint8_t *dst, uint8_t *src, size_t size)
FCTL3 = FWKEY; /* Lock = 0 */ FCTL3 = FWKEY; /* Lock = 0 */
busy_wait(); busy_wait();
for(i = size; i > 0; i--) { for (i = size; i > 0; i--) {
FCTL1 = FWKEY | WRT; FCTL1 = FWKEY | WRT;
*dst = *src; /* program Flash word */ *dst = *src; /* program Flash word */
while(!(FCTL3 & WAIT)) { while (!(FCTL3 & WAIT)) {
nop(); nop();
} }
} }
@ -82,7 +82,7 @@ void finish(uint8_t istate)
static inline void busy_wait(void) static inline void busy_wait(void)
{ {
/* Wait for BUSY = 0, not needed unless run from RAM */ /* Wait for BUSY = 0, not needed unless run from RAM */
while(FCTL3 & 0x0001) { while (FCTL3 & 0x0001) {
nop(); nop();
} }
} }

View File

@ -17,7 +17,7 @@ void timerA_init(void)
volatile unsigned int *ccr = &TA0CCR0; volatile unsigned int *ccr = &TA0CCR0;
volatile unsigned int *ctl = &TA0CCTL0; volatile unsigned int *ctl = &TA0CCTL0;
for(int i = 0; i < ARCH_MAXTIMERS; i++) { for (int i = 0; i < ARCH_MAXTIMERS; i++) {
*ccr = 0; *ccr = 0;
*ctl &= ~(CCIFG); *ctl &= ~(CCIFG);
*ctl &= ~(CCIE); *ctl &= ~(CCIE);
@ -42,7 +42,7 @@ interrupt(TIMERA1_VECTOR) __attribute__((naked)) timer_isr(void)
short taiv = TA0IV; short taiv = TA0IV;
if(taiv & TAIFG) { if (taiv & TAIFG) {
// puts("msp430/hwtimer_cpu TAIFG set!"); // puts("msp430/hwtimer_cpu TAIFG set!");
// TA0CTL &= ~TAIFG; // TA0CTL &= ~TAIFG;
// ticks += 0xFFFF; // ticks += 0xFFFF;

View File

@ -85,19 +85,19 @@ void schedule_timer(void)
{ {
int l = next_timer; int l = next_timer;
for( for (
int i = ((next_timer + 1) % ARCH_MAXTIMERS); int i = ((next_timer + 1) % ARCH_MAXTIMERS);
i != next_timer; i != next_timer;
i = ((i + 1) % ARCH_MAXTIMERS) i = ((i + 1) % ARCH_MAXTIMERS)
) { ) {
if(native_hwtimer_isset[l] != 1) { if (native_hwtimer_isset[l] != 1) {
/* make sure we dont compare to garbage in the following /* make sure we dont compare to garbage in the following
* if condition */ * if condition */
l = i; l = i;
} }
if( if (
(native_hwtimer_isset[i] == 1) && (native_hwtimer_isset[i] == 1) &&
(tv2ticks(&(native_hwtimer[i].it_value)) < tv2ticks(&(native_hwtimer[l].it_value))) (tv2ticks(&(native_hwtimer[i].it_value)) < tv2ticks(&(native_hwtimer[l].it_value)))
) { ) {
@ -111,8 +111,8 @@ void schedule_timer(void)
/* l could still point to some unused (garbage) timer if no timers /* l could still point to some unused (garbage) timer if no timers
* are set at all */ * are set at all */
if(native_hwtimer_isset[next_timer] == 1) { if (native_hwtimer_isset[next_timer] == 1) {
if(setitimer(ITIMER_REAL, &native_hwtimer[next_timer], NULL) == -1) { if (setitimer(ITIMER_REAL, &native_hwtimer[next_timer], NULL) == -1) {
err(1, "schedule_timer"); err(1, "schedule_timer");
} }
else { else {
@ -140,7 +140,7 @@ void hwtimer_isr_timer()
native_hwtimer_isset[next_timer] = 0; native_hwtimer_isset[next_timer] = 0;
schedule_timer(); schedule_timer();
if(native_hwtimer_irq[i] == 1) { if (native_hwtimer_irq[i] == 1) {
DEBUG("hwtimer_isr_timer(): calling hwtimer.int_handler(%i)\n", i); DEBUG("hwtimer_isr_timer(): calling hwtimer.int_handler(%i)\n", i);
int_handler(i); int_handler(i);
} }
@ -153,7 +153,7 @@ void hwtimer_arch_enable_interrupt(void)
{ {
DEBUG("hwtimer_arch_enable_interrupt()\n"); DEBUG("hwtimer_arch_enable_interrupt()\n");
if(register_interrupt(SIGALRM, hwtimer_isr_timer) != 0) { if (register_interrupt(SIGALRM, hwtimer_isr_timer) != 0) {
DEBUG("darn!\n\n"); DEBUG("darn!\n\n");
} }
@ -164,7 +164,7 @@ void hwtimer_arch_disable_interrupt(void)
{ {
DEBUG("hwtimer_arch_disable_interrupt()\n"); DEBUG("hwtimer_arch_disable_interrupt()\n");
if(unregister_interrupt(SIGALRM) != 0) { if (unregister_interrupt(SIGALRM) != 0) {
DEBUG("darn!\n\n"); DEBUG("darn!\n\n");
} }
@ -186,7 +186,7 @@ void hwtimer_arch_set(unsigned long offset, short timer)
{ {
DEBUG("hwtimer_arch_set(%li, %i)\n", offset, timer); DEBUG("hwtimer_arch_set(%li, %i)\n", offset, timer);
if(offset < HWTIMERMINOFFSET) { if (offset < HWTIMERMINOFFSET) {
offset = HWTIMERMINOFFSET; offset = HWTIMERMINOFFSET;
DEBUG("hwtimer_arch_set: offset < MIN, set to: %i\n", offset); DEBUG("hwtimer_arch_set: offset < MIN, set to: %i\n", offset);
} }
@ -227,7 +227,7 @@ unsigned long hwtimer_arch_now(void)
t.tv_nsec = mts.tv_nsec; t.tv_nsec = mts.tv_nsec;
#else #else
if(clock_gettime(CLOCK_MONOTONIC, &t) == -1) { if (clock_gettime(CLOCK_MONOTONIC, &t) == -1) {
err(1, "hwtimer_arch_now: clock_gettime"); err(1, "hwtimer_arch_now: clock_gettime");
} }
@ -247,7 +247,7 @@ void hwtimer_arch_init(void (*handler)(int), uint32_t fcpu)
hwtimer_arch_disable_interrupt(); hwtimer_arch_disable_interrupt();
int_handler = handler; int_handler = handler;
for(int i = 0; i < ARCH_MAXTIMERS; i++) { for (int i = 0; i < ARCH_MAXTIMERS; i++) {
native_hwtimer_irq[i] = 0; native_hwtimer_irq[i] = 0;
native_hwtimer_isset[i] = 0; native_hwtimer_isset[i] = 0;
native_hwtimer[i].it_interval.tv_sec = 0; native_hwtimer[i].it_interval.tv_sec = 0;

View File

@ -53,19 +53,19 @@ void print_thread_sigmask(ucontext_t *cp)
{ {
sigset_t *p = &cp->uc_sigmask; sigset_t *p = &cp->uc_sigmask;
if(sigemptyset(p) == -1) { if (sigemptyset(p) == -1) {
err(1, "print_thread_sigmask: sigemptyset"); err(1, "print_thread_sigmask: sigemptyset");
} }
for(int i = 1; i < (NSIG); i++) { for (int i = 1; i < (NSIG); i++) {
if(native_irq_handlers[i].func != NULL) { if (native_irq_handlers[i].func != NULL) {
printf("%s: %s\n", printf("%s: %s\n",
strsignal(i), strsignal(i),
(sigismember(&native_sig_set, i) ? "blocked" : "unblocked") (sigismember(&native_sig_set, i) ? "blocked" : "unblocked")
); );
} }
if(sigismember(p, i)) { if (sigismember(p, i)) {
printf("%s: pending\n", strsignal(i)); printf("%s: pending\n", strsignal(i));
} }
} }
@ -76,8 +76,8 @@ void print_sigmasks(void)
ucontext_t *p; ucontext_t *p;
//tcb_t *cb = NULL; //tcb_t *cb = NULL;
for(int i = 0; i < MAXTHREADS; i++) { for (int i = 0; i < MAXTHREADS; i++) {
if(sched_threads[i] != NULL) { if (sched_threads[i] != NULL) {
printf("%s:\n", sched_threads[i]->name); printf("%s:\n", sched_threads[i]->name);
//print_thread_sigmask(sched_threads[i]->sp); //print_thread_sigmask(sched_threads[i]->sp);
p = (ucontext_t *)(sched_threads[i]->stack_start); p = (ucontext_t *)(sched_threads[i]->stack_start);
@ -92,31 +92,31 @@ void native_print_signals()
sigset_t p, q; sigset_t p, q;
puts("native signals:\n"); puts("native signals:\n");
if(sigemptyset(&p) == -1) { if (sigemptyset(&p) == -1) {
err(1, "native_print_signals: sigemptyset"); err(1, "native_print_signals: sigemptyset");
} }
if(sigpending(&p) == -1) { if (sigpending(&p) == -1) {
err(1, "native_print_signals: sigpending"); err(1, "native_print_signals: sigpending");
} }
if(sigprocmask(SIG_SETMASK, NULL, &q) == -1) { if (sigprocmask(SIG_SETMASK, NULL, &q) == -1) {
err(1, "native_print_signals(): sigprocmask"); err(1, "native_print_signals(): sigprocmask");
} }
for(int i = 1; i < (NSIG); i++) { for (int i = 1; i < (NSIG); i++) {
if(native_irq_handlers[i].func != NULL || i == SIGUSR1) { if (native_irq_handlers[i].func != NULL || i == SIGUSR1) {
printf("%s: %s in active thread\n", printf("%s: %s in active thread\n",
strsignal(i), strsignal(i),
(sigismember(&native_sig_set, i) ? "blocked" : "unblocked") (sigismember(&native_sig_set, i) ? "blocked" : "unblocked")
); );
} }
if(sigismember(&p, i)) { if (sigismember(&p, i)) {
printf("%s: pending\n", strsignal(i)); printf("%s: pending\n", strsignal(i));
} }
if(sigismember(&q, i)) { if (sigismember(&q, i)) {
printf("%s: blocked in this context\n", strsignal(i)); printf("%s: blocked in this context\n", strsignal(i));
} }
} }
@ -133,21 +133,21 @@ unsigned disableIRQ(void)
_native_in_syscall = 1; _native_in_syscall = 1;
DEBUG("disableIRQ()\n"); DEBUG("disableIRQ()\n");
if(sigfillset(&mask) == -1) { if (sigfillset(&mask) == -1) {
err(1, "disableIRQ(): sigfillset"); err(1, "disableIRQ(): sigfillset");
} }
if(native_interrupts_enabled == 1) { if (native_interrupts_enabled == 1) {
DEBUG("sigprocmask(..native_sig_set)\n"); DEBUG("sigprocmask(..native_sig_set)\n");
if(sigprocmask(SIG_SETMASK, &mask, &native_sig_set) == -1) { if (sigprocmask(SIG_SETMASK, &mask, &native_sig_set) == -1) {
err(1, "disableIRQ(): sigprocmask"); err(1, "disableIRQ(): sigprocmask");
} }
} }
else { else {
DEBUG("sigprocmask()\n"); DEBUG("sigprocmask()\n");
if(sigprocmask(SIG_SETMASK, &mask, NULL) == -1) { if (sigprocmask(SIG_SETMASK, &mask, NULL) == -1) {
err(1, "disableIRQ(): sigprocmask()"); err(1, "disableIRQ(): sigprocmask()");
} }
} }
@ -155,7 +155,7 @@ unsigned disableIRQ(void)
prev_state = native_interrupts_enabled; prev_state = native_interrupts_enabled;
native_interrupts_enabled = 0; native_interrupts_enabled = 0;
if(_native_sigpend > 0) { if (_native_sigpend > 0) {
DEBUG("\n\n\t\treturn from syscall, calling native_irq_handler\n\n"); DEBUG("\n\n\t\treturn from syscall, calling native_irq_handler\n\n");
_native_in_syscall = 0; _native_in_syscall = 0;
printf("calling swapcontext()\n"); printf("calling swapcontext()\n");
@ -180,7 +180,7 @@ unsigned enableIRQ(void)
_native_in_syscall = 1; _native_in_syscall = 1;
DEBUG("enableIRQ()\n"); DEBUG("enableIRQ()\n");
if(sigprocmask(SIG_SETMASK, &native_sig_set, NULL) == -1) { if (sigprocmask(SIG_SETMASK, &native_sig_set, NULL) == -1) {
err(1, "enableIRQ(): sigprocmask()"); err(1, "enableIRQ(): sigprocmask()");
} }
@ -189,7 +189,7 @@ unsigned enableIRQ(void)
//print_sigmasks(); //print_sigmasks();
//native_print_signals(); //native_print_signals();
if(_native_sigpend > 0) { if (_native_sigpend > 0) {
DEBUG("\n\n\t\treturn from syscall, calling native_irq_handler\n\n"); DEBUG("\n\n\t\treturn from syscall, calling native_irq_handler\n\n");
_native_in_syscall = 0; _native_in_syscall = 0;
printf("calling swapcontext()\n"); printf("calling swapcontext()\n");
@ -208,7 +208,7 @@ void restoreIRQ(unsigned state)
{ {
DEBUG("restoreIRQ()\n"); DEBUG("restoreIRQ()\n");
if(state == 1) { if (state == 1) {
enableIRQ(); enableIRQ();
} }
else { else {
@ -243,12 +243,12 @@ int _native_popsig(void)
nleft = sizeof(int); nleft = sizeof(int);
i = 0; i = 0;
while((nleft > 0) && ((nread = read(pipefd[0], &sig + i, nleft)) != -1)) { while ((nleft > 0) && ((nread = read(pipefd[0], &sig + i, nleft)) != -1)) {
i += nread; i += nread;
nleft -= nread; nleft -= nread;
} }
if(nread == -1) { if (nread == -1) {
err(1, "_native_popsig(): read()"); err(1, "_native_popsig(): read()");
} }
@ -265,16 +265,16 @@ void native_irq_handler()
DEBUG("\n\n\t\tnative_irq_handler\n\n"); DEBUG("\n\n\t\tnative_irq_handler\n\n");
while(_native_sigpend > 0) { while (_native_sigpend > 0) {
sig = _native_popsig(); sig = _native_popsig();
_native_sigpend--; _native_sigpend--;
if(native_irq_handlers[sig].func != NULL) { if (native_irq_handlers[sig].func != NULL) {
DEBUG("calling interrupt handler for %i\n", sig); DEBUG("calling interrupt handler for %i\n", sig);
native_irq_handlers[sig].func(); native_irq_handlers[sig].func();
} }
else if(sig == SIGUSR1) { else if (sig == SIGUSR1) {
DEBUG("ignoring SIGUSR1\n"); DEBUG("ignoring SIGUSR1\n");
} }
else { else {
@ -296,12 +296,12 @@ void native_isr_entry(int sig, siginfo_t *info, void *context)
{ {
DEBUG("\n\n\t\tnative_isr_entry\n\n"); DEBUG("\n\n\t\tnative_isr_entry\n\n");
if(native_interrupts_enabled == 0) { if (native_interrupts_enabled == 0) {
errx(1, "interrupts are off, but I caught a signal."); errx(1, "interrupts are off, but I caught a signal.");
} }
/* save the signal */ /* save the signal */
if(write(pipefd[1], &sig, sizeof(int)) == -1) { if (write(pipefd[1], &sig, sizeof(int)) == -1) {
err(1, "native_isr_entry(): write()"); err(1, "native_isr_entry(): write()");
} }
@ -311,7 +311,7 @@ void native_isr_entry(int sig, siginfo_t *info, void *context)
makecontext(&native_isr_context, native_irq_handler, 0); makecontext(&native_isr_context, native_irq_handler, 0);
_native_cur_ctx = (ucontext_t *)active_thread->sp; _native_cur_ctx = (ucontext_t *)active_thread->sp;
if(_native_in_syscall == 0) { if (_native_in_syscall == 0) {
_native_in_isr = 1; _native_in_isr = 1;
DEBUG("\n\n\t\treturn to _native_sig_leave_tramp\n\n"); DEBUG("\n\n\t\treturn to _native_sig_leave_tramp\n\n");
#ifdef __MACH__ #ifdef __MACH__
@ -343,7 +343,7 @@ int register_interrupt(int sig, void *handler)
struct sigaction sa; struct sigaction sa;
DEBUG("XXX: register_interrupt()\n"); DEBUG("XXX: register_interrupt()\n");
if(sigdelset(&native_sig_set, sig)) { if (sigdelset(&native_sig_set, sig)) {
err(1, "register_interrupt: sigdelset"); err(1, "register_interrupt: sigdelset");
} }
@ -352,13 +352,13 @@ int register_interrupt(int sig, void *handler)
sa.sa_sigaction = (void *) native_isr_entry; sa.sa_sigaction = (void *) native_isr_entry;
/* sa.sa_handler = (void*) native_isr_entry; */ /* sa.sa_handler = (void*) native_isr_entry; */
if(sigemptyset(&sa.sa_mask) == -1) { if (sigemptyset(&sa.sa_mask) == -1) {
err(1, "register_interrupt: sigemptyset"); err(1, "register_interrupt: sigemptyset");
} }
sa.sa_flags = SA_RESTART | SA_SIGINFO | SA_ONSTACK; sa.sa_flags = SA_RESTART | SA_SIGINFO | SA_ONSTACK;
if(sigaction(sig, &sa, NULL)) { if (sigaction(sig, &sa, NULL)) {
err(1, "register_interrupt: sigaction"); err(1, "register_interrupt: sigaction");
} }
@ -376,7 +376,7 @@ int unregister_interrupt(int sig)
struct sigaction sa; struct sigaction sa;
DEBUG("XXX: unregister_interrupt()\n"); DEBUG("XXX: unregister_interrupt()\n");
if(sigaddset(&native_sig_set, sig) == -1) { if (sigaddset(&native_sig_set, sig) == -1) {
err(1, "unregister_interrupt: sigaddset"); err(1, "unregister_interrupt: sigaddset");
} }
@ -385,13 +385,13 @@ int unregister_interrupt(int sig)
/* sa.sa_sigaction = SIG_IGN; */ /* sa.sa_sigaction = SIG_IGN; */
sa.sa_handler = SIG_IGN; sa.sa_handler = SIG_IGN;
if(sigemptyset(&sa.sa_mask) == -1) { if (sigemptyset(&sa.sa_mask) == -1) {
err(1, "unregister_interrupt: sigemptyset"); err(1, "unregister_interrupt: sigemptyset");
} }
sa.sa_flags = SA_RESTART | SA_SIGINFO | SA_ONSTACK; sa.sa_flags = SA_RESTART | SA_SIGINFO | SA_ONSTACK;
if(sigaction(sig, &sa, NULL)) { if (sigaction(sig, &sa, NULL)) {
err(1, "unregister_interrupt: sigaction"); err(1, "unregister_interrupt: sigaction");
} }
@ -413,13 +413,13 @@ void native_interrupt_init(void)
native_interrupts_enabled = 1; native_interrupts_enabled = 1;
_native_sigpend = 0; _native_sigpend = 0;
for(int i = 0; i < 255; i++) { for (int i = 0; i < 255; i++) {
native_irq_handlers[i].func = NULL; native_irq_handlers[i].func = NULL;
} }
sa.sa_sigaction = (void *) native_isr_entry; sa.sa_sigaction = (void *) native_isr_entry;
if(sigemptyset(&sa.sa_mask) == -1) { if (sigemptyset(&sa.sa_mask) == -1) {
err(1, "native_interrupt_init: sigemptyset"); err(1, "native_interrupt_init: sigemptyset");
} }
@ -430,23 +430,23 @@ void native_interrupt_init(void)
err(1, "native_interrupt_init: sigemptyset"); err(1, "native_interrupt_init: sigemptyset");
} }
*/ */
if(sigprocmask(SIG_SETMASK, NULL, &native_sig_set) == -1) { if (sigprocmask(SIG_SETMASK, NULL, &native_sig_set) == -1) {
err(1, "native_interrupt_init(): sigprocmask"); err(1, "native_interrupt_init(): sigprocmask");
} }
if(sigdelset(&native_sig_set, SIGUSR1) == -1) { if (sigdelset(&native_sig_set, SIGUSR1) == -1) {
err(1, "native_interrupt_init: sigdelset"); err(1, "native_interrupt_init: sigdelset");
} }
if(sigaction(SIGUSR1, &sa, NULL)) { if (sigaction(SIGUSR1, &sa, NULL)) {
err(1, "native_interrupt_init: sigaction"); err(1, "native_interrupt_init: sigaction");
} }
if(getcontext(&native_isr_context) == -1) { if (getcontext(&native_isr_context) == -1) {
err(1, "native_isr_entry(): getcontext()"); err(1, "native_isr_entry(): getcontext()");
} }
if(sigfillset(&(native_isr_context.uc_sigmask)) == -1) { if (sigfillset(&(native_isr_context.uc_sigmask)) == -1) {
err(1, "native_isr_entry(): sigfillset()"); err(1, "native_isr_entry(): sigfillset()");
} }
@ -460,7 +460,7 @@ void native_interrupt_init(void)
sigstk.ss_size = SIGSTKSZ; sigstk.ss_size = SIGSTKSZ;
sigstk.ss_flags = 0; sigstk.ss_flags = 0;
if(sigaltstack(&sigstk, NULL) < 0) { if (sigaltstack(&sigstk, NULL) < 0) {
err(1, "main: sigaltstack"); err(1, "main: sigaltstack");
} }
@ -468,7 +468,7 @@ void native_interrupt_init(void)
_native_in_syscall = 0; _native_in_syscall = 0;
if(pipe(pipefd) == -1) { if (pipe(pipefd) == -1) {
err(1, "native_interrupt_init(): pipe()"); err(1, "native_interrupt_init(): pipe()");
} }

View File

@ -48,12 +48,12 @@ void _native_lpm_sleep()
retval = select(1, &_native_uart_rfds, NULL, NULL, NULL); retval = select(1, &_native_uart_rfds, NULL, NULL, NULL);
DEBUG("_native_lpm_sleep: retval: %i\n", retval); DEBUG("_native_lpm_sleep: retval: %i\n", retval);
if(retval != -1) { if (retval != -1) {
/* uart ready, handle input */ /* uart ready, handle input */
/* TODO: switch to ISR context */ /* TODO: switch to ISR context */
_native_handle_uart0_input(); _native_handle_uart0_input();
} }
else if(errno != EINTR) { else if (errno != EINTR) {
/* select failed for reason other than signal */ /* select failed for reason other than signal */
err(1, "lpm_set(): select()"); err(1, "lpm_set(): select()");
} }
@ -63,7 +63,7 @@ void _native_lpm_sleep()
pause(); pause();
#endif #endif
if(_native_sigpend > 0) { if (_native_sigpend > 0) {
DEBUG("\n\n\t\treturn from syscall, calling native_irq_handler\n\n"); DEBUG("\n\n\t\treturn from syscall, calling native_irq_handler\n\n");
_native_in_syscall = 0; _native_in_syscall = 0;
_native_in_isr = 1; _native_in_isr = 1;

View File

@ -63,7 +63,7 @@ char *thread_stack_init(void *task_func, void *stack_start, int stacksize)
stacksize -= sizeof(ucontext_t); stacksize -= sizeof(ucontext_t);
#endif #endif
if(getcontext(p) == -1) { if (getcontext(p) == -1) {
err(1, "thread_stack_init(): getcontext()"); err(1, "thread_stack_init(): getcontext()");
} }
@ -72,7 +72,7 @@ char *thread_stack_init(void *task_func, void *stack_start, int stacksize)
p->uc_stack.ss_flags = 0; p->uc_stack.ss_flags = 0;
p->uc_link = &end_context; p->uc_link = &end_context;
if(sigemptyset(&(p->uc_sigmask)) == -1) { if (sigemptyset(&(p->uc_sigmask)) == -1) {
err(1, "thread_stack_init(): sigemptyset()"); err(1, "thread_stack_init(): sigemptyset()");
} }
@ -93,7 +93,7 @@ void cpu_switch_context_exit(void)
ctx = (ucontext_t *)(active_thread->sp); ctx = (ucontext_t *)(active_thread->sp);
eINT(); // XXX: workaround for bug (?) in sched_task_exit eINT(); // XXX: workaround for bug (?) in sched_task_exit
if(setcontext(ctx) == -1) { if (setcontext(ctx) == -1) {
err(1, "cpu_switch_context_exit(): setcontext():"); err(1, "cpu_switch_context_exit(): setcontext():");
} }
} }
@ -113,10 +113,10 @@ void thread_yield()
nc = (ucontext_t *)(active_thread->sp); nc = (ucontext_t *)(active_thread->sp);
if(nc != oc) { if (nc != oc) {
DEBUG("thread_yield(): calling swapcontext(%s)\n\n", active_thread->name); DEBUG("thread_yield(): calling swapcontext(%s)\n\n", active_thread->name);
if(swapcontext(oc, nc) == -1) { if (swapcontext(oc, nc) == -1) {
err(1, "thread_yield(): swapcontext()"); err(1, "thread_yield(): swapcontext()");
} }
} }
@ -127,7 +127,7 @@ void thread_yield()
void native_cpu_init() void native_cpu_init()
{ {
if(getcontext(&end_context) == -1) { if (getcontext(&end_context) == -1) {
err(1, "end_context(): getcontext()"); err(1, "end_context(): getcontext()");
} }

View File

@ -55,10 +55,10 @@ void rtc_get_localtime(struct tm *localt)
{ {
time_t t; time_t t;
if(native_rtc_enabled == 1) { if (native_rtc_enabled == 1) {
t = time(NULL); t = time(NULL);
if(localtime_r(&t, localt) == NULL) { if (localtime_r(&t, localt) == NULL) {
err(1, "rtc_get_localtime: localtime_r"); err(1, "rtc_get_localtime: localtime_r");
} }
} }

View File

@ -19,10 +19,10 @@ void *resend_thread_f(void *args)
uint8_t seq_num = *((uint8_t *)args); uint8_t seq_num = *((uint8_t *)args);
struct send_slot *slot = &(slwin_stat.send_win[seq_num % BORDER_SWS]); struct send_slot *slot = &(slwin_stat.send_win[seq_num % BORDER_SWS]);
while(1) { while (1) {
usleep(BORDER_SL_TIMEOUT); usleep(BORDER_SL_TIMEOUT);
if(seq_num == ((border_packet_t *)(slot->frame))->seq_num) { if (seq_num == ((border_packet_t *)(slot->frame))->seq_num) {
writepacket(slot->frame, slot->frame_len); writepacket(slot->frame, slot->frame_len);
} }
else { else {
@ -45,7 +45,7 @@ void init_threeway_handshake(const struct in6_addr *addr)
writepacket((uint8_t *)syn, sizeof(border_syn_packet_t)); writepacket((uint8_t *)syn, sizeof(border_syn_packet_t));
usleep(BORDER_SL_TIMEOUT); usleep(BORDER_SL_TIMEOUT);
} }
while(!connection_established); while (!connection_established);
} }
void signal_connection_established(void) void signal_connection_established(void)
@ -62,7 +62,7 @@ void flowcontrol_init(const struct in6_addr *addr)
sem_init(&slwin_stat.send_win_not_full, 0, BORDER_SWS); sem_init(&slwin_stat.send_win_not_full, 0, BORDER_SWS);
for(i = 0; i < BORDER_SWS; i++) { for (i = 0; i < BORDER_SWS; i++) {
slwin_stat.send_win[i].frame_len = 0; slwin_stat.send_win[i].frame_len = 0;
} }
@ -70,7 +70,7 @@ void flowcontrol_init(const struct in6_addr *addr)
slwin_stat.next_exp = 0; slwin_stat.next_exp = 0;
for(i = 0; i < BORDER_RWS; i++) { for (i = 0; i < BORDER_RWS; i++) {
slwin_stat.recv_win[i].received = 0; slwin_stat.recv_win[i].received = 0;
slwin_stat.recv_win[i].frame_len = 0; slwin_stat.recv_win[i].frame_len = 0;
} }
@ -120,8 +120,8 @@ void flowcontrol_send_over_tty(border_packet_t *packet, int len)
void flowcontrol_deliver_from_tty(const border_packet_t *packet, int len) void flowcontrol_deliver_from_tty(const border_packet_t *packet, int len)
{ {
if(packet->type == BORDER_PACKET_ACK_TYPE) { if (packet->type == BORDER_PACKET_ACK_TYPE) {
if(in_window(packet->seq_num, slwin_stat.last_ack + 1, slwin_stat.last_frame)) { if (in_window(packet->seq_num, slwin_stat.last_ack + 1, slwin_stat.last_frame)) {
do { do {
struct send_slot *slot; struct send_slot *slot;
slot = &(slwin_stat.send_win[++slwin_stat.last_ack % BORDER_SWS]); slot = &(slwin_stat.send_win[++slwin_stat.last_ack % BORDER_SWS]);
@ -133,7 +133,7 @@ void flowcontrol_deliver_from_tty(const border_packet_t *packet, int len)
slot->frame_len = 0; slot->frame_len = 0;
sem_post(&slwin_stat.send_win_not_full); sem_post(&slwin_stat.send_win_not_full);
} }
while(slwin_stat.last_ack != packet->seq_num); while (slwin_stat.last_ack != packet->seq_num);
} }
} }
else { else {
@ -141,7 +141,7 @@ void flowcontrol_deliver_from_tty(const border_packet_t *packet, int len)
slot = &slwin_stat.recv_win[packet->seq_num % BORDER_RWS]; slot = &slwin_stat.recv_win[packet->seq_num % BORDER_RWS];
if(!in_window(packet->seq_num, if (!in_window(packet->seq_num,
slwin_stat.next_exp, slwin_stat.next_exp,
slwin_stat.next_exp + BORDER_RWS - 1)) { slwin_stat.next_exp + BORDER_RWS - 1)) {
return; return;
@ -150,8 +150,8 @@ void flowcontrol_deliver_from_tty(const border_packet_t *packet, int len)
memcpy(slot->frame, (uint8_t *)packet, len); memcpy(slot->frame, (uint8_t *)packet, len);
slot->received = 1; slot->received = 1;
if(packet->seq_num == slwin_stat.next_exp) { if (packet->seq_num == slwin_stat.next_exp) {
while(slot->received) { while (slot->received) {
demultiplex((border_packet_t *)slot->frame, slot->frame_len); demultiplex((border_packet_t *)slot->frame, slot->frame_len);
memset(&slot->frame, 0, BUFFER_SIZE); memset(&slot->frame, 0, BUFFER_SIZE);
slot->received = 0; slot->received = 0;

View File

@ -10,7 +10,7 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
if(argc < 4) { if (argc < 4) {
fprintf(stderr, "Usage: %s r_addr if_name tty_dev\n", argv[0]); fprintf(stderr, "Usage: %s r_addr if_name tty_dev\n", argv[0]);
return -1; return -1;
} }
@ -22,12 +22,12 @@ int main(int argc, char **argv)
char tty_dev[DEV_LEN]; char tty_dev[DEV_LEN];
strncpy(tty_dev, argv[3], DEV_LEN); strncpy(tty_dev, argv[3], DEV_LEN);
if(border_initialize(if_name, addr, tty_dev) == 0) { if (border_initialize(if_name, addr, tty_dev) == 0) {
#ifdef BORDER_TESTING #ifdef BORDER_TESTING
char ping_addr[IPV6_ADDR_LEN]; char ping_addr[IPV6_ADDR_LEN];
float interval; float interval;
if(argc < 9) { if (argc < 9) {
fprintf(stderr, "Usage: %s r_addr if_name tty_dev ping_id result_dir skeleton_file ping_count interval\n", argv[0]); fprintf(stderr, "Usage: %s r_addr if_name tty_dev ping_id result_dir skeleton_file ping_count interval\n", argv[0]);
return -1; return -1;
} }
@ -38,7 +38,7 @@ int main(int argc, char **argv)
start_test(ping_addr, argv[5], argv[6], atoi(argv[7]), interval); start_test(ping_addr, argv[5], argv[6], atoi(argv[7]), interval);
#else #else
while(1); while (1);
#endif #endif
} }

View File

@ -19,7 +19,7 @@ uint8_t serial_in_buf[BUFFER_SIZE];
uint8_t *get_serial_out_buffer(int offset) uint8_t *get_serial_out_buffer(int offset)
{ {
if(offset > BUFFER_SIZE) { if (offset > BUFFER_SIZE) {
return NULL; return NULL;
} }
@ -28,7 +28,7 @@ uint8_t *get_serial_out_buffer(int offset)
uint8_t *get_serial_in_buffer(int offset) uint8_t *get_serial_in_buffer(int offset)
{ {
if(offset > BUFFER_SIZE) { if (offset > BUFFER_SIZE) {
return NULL; return NULL;
} }
@ -56,33 +56,33 @@ int readpacket(uint8_t *packet_buf, size_t size)
uint8_t esc = 0; uint8_t esc = 0;
uint8_t translate = 1; uint8_t translate = 1;
while((line_buf_ptr - packet_buf) < size - 1) { while ((line_buf_ptr - packet_buf) < size - 1) {
byte = serial_read_byte(); byte = serial_read_byte();
if(translate && byte == END) { if (translate && byte == END) {
break; break;
} }
if(line_buf_ptr == packet_buf && byte != 0) { if (line_buf_ptr == packet_buf && byte != 0) {
translate = 0; translate = 0;
} }
if(line_buf_ptr > packet_buf && !translate && byte == '\n') { if (line_buf_ptr > packet_buf && !translate && byte == '\n') {
*line_buf_ptr++ = '\0'; *line_buf_ptr++ = '\0';
return line_buf_ptr - packet_buf; return line_buf_ptr - packet_buf;
} }
if(translate) { if (translate) {
if(esc) { if (esc) {
esc = 0; esc = 0;
switch(byte) { switch(byte) {
case(END_ESC): { case (END_ESC): {
*line_buf_ptr++ = END; *line_buf_ptr++ = END;
continue; continue;
} }
case(ESC_ESC): { case (ESC_ESC): {
*line_buf_ptr++ = ESC; *line_buf_ptr++ = ESC;
continue; continue;
} }
@ -92,7 +92,7 @@ int readpacket(uint8_t *packet_buf, size_t size)
} }
} }
if(byte == ESC) { if (byte == ESC) {
esc = 1; esc = 1;
continue; continue;
} }
@ -112,20 +112,20 @@ int writepacket(uint8_t *packet_buf, size_t size)
uint8_t *byte_ptr = packet_buf; uint8_t *byte_ptr = packet_buf;
uint8_t *tmp_ptr = packet_tmp; uint8_t *tmp_ptr = packet_tmp;
if(2 * size + 1 > BUFFER_SIZE) { if (2 * size + 1 > BUFFER_SIZE) {
return -1; return -1;
} }
while((byte_ptr - packet_buf) < size) { while ((byte_ptr - packet_buf) < size) {
switch(*byte_ptr) { switch(*byte_ptr) {
case(END): { case (END): {
*byte_ptr = END_ESC; *byte_ptr = END_ESC;
*tmp_ptr = ESC; *tmp_ptr = ESC;
tmp_ptr++; tmp_ptr++;
break; break;
} }
case(ESC): { case (ESC): {
*byte_ptr = ESC_ESC; *byte_ptr = ESC_ESC;
*tmp_ptr = ESC; *tmp_ptr = ESC;
tmp_ptr++; tmp_ptr++;
@ -151,18 +151,18 @@ int writepacket(uint8_t *packet_buf, size_t size)
void demultiplex(const border_packet_t *packet, int len) void demultiplex(const border_packet_t *packet, int len)
{ {
switch(packet->type) { switch(packet->type) {
case(BORDER_PACKET_RAW_TYPE): { case (BORDER_PACKET_RAW_TYPE): {
printf("\033[00;33m[via serial interface] %s\033[00m\n", printf("\033[00;33m[via serial interface] %s\033[00m\n",
((unsigned char *)packet) + sizeof(border_packet_t) ((unsigned char *)packet) + sizeof(border_packet_t)
); );
break; break;
} }
case(BORDER_PACKET_L3_TYPE): { case (BORDER_PACKET_L3_TYPE): {
border_l3_header_t *l3_header_buf = (border_l3_header_t *)packet; border_l3_header_t *l3_header_buf = (border_l3_header_t *)packet;
switch(l3_header_buf->ethertype) { switch(l3_header_buf->ethertype) {
case(ETHERTYPE_IPV6): { case (ETHERTYPE_IPV6): {
printf("INFO: IPv6-Packet %d received\n", l3_header_buf->seq_num); printf("INFO: IPv6-Packet %d received\n", l3_header_buf->seq_num);
struct ip6_hdr *ip6_buf = (struct ip6_hdr *)(((unsigned char *)packet) + sizeof(border_l3_header_t)); struct ip6_hdr *ip6_buf = (struct ip6_hdr *)(((unsigned char *)packet) + sizeof(border_l3_header_t));
border_send_ipv6_over_tun(get_tun_fd(), ip6_buf); border_send_ipv6_over_tun(get_tun_fd(), ip6_buf);
@ -177,24 +177,24 @@ void demultiplex(const border_packet_t *packet, int len)
break; break;
} }
case(BORDER_PACKET_CONF_TYPE): { case (BORDER_PACKET_CONF_TYPE): {
border_conf_header_t *conf_header_buf = (border_conf_header_t *)packet; border_conf_header_t *conf_header_buf = (border_conf_header_t *)packet;
switch(conf_header_buf->conftype) { switch(conf_header_buf->conftype) {
case(BORDER_CONF_SYNACK): { case (BORDER_CONF_SYNACK): {
printf("INFO: SYNACK-Packet %d received\n", conf_header_buf->seq_num); printf("INFO: SYNACK-Packet %d received\n", conf_header_buf->seq_num);
signal_connection_established(); signal_connection_established();
break; break;
} }
case(BORDER_CONF_CONTEXT): { case (BORDER_CONF_CONTEXT): {
printf("INFO: Context packet (%d) received, " printf("INFO: Context packet (%d) received, "
"but nothing is implemented yet for this case.\n", "but nothing is implemented yet for this case.\n",
conf_header_buf->seq_num); conf_header_buf->seq_num);
break; break;
} }
case(BORDER_CONF_IPADDR): { case (BORDER_CONF_IPADDR): {
char str_addr[IPV6_ADDR_LEN]; char str_addr[IPV6_ADDR_LEN];
border_addr_packet_t *addr_packet = (border_addr_packet_t *)packet; border_addr_packet_t *addr_packet = (border_addr_packet_t *)packet;

View File

@ -61,20 +61,20 @@ int open_serial_port(const char *port_name)
{ {
int r; int r;
if(port_fd >= 0) { if (port_fd >= 0) {
close(port_fd); close(port_fd);
} }
port_fd = open(port_name, O_RDWR); port_fd = open(port_name, O_RDWR);
if(port_fd < 0) { if (port_fd < 0) {
report_open_error(port_name, errno); report_open_error(port_name, errno);
return -1; return -1;
} }
r = set_baud(baud_rate); r = set_baud(baud_rate);
if(r == 0) { if (r == 0) {
printf("Port \"%s\" opened at %s baud\r\n", printf("Port \"%s\" opened at %s baud\r\n",
port_name, baud_rate); port_name, baud_rate);
} }
@ -89,7 +89,7 @@ int open_serial_port(const char *port_name)
/* attempt to set low latency mode, but don't worry if we can't */ /* attempt to set low latency mode, but don't worry if we can't */
r = ioctl(port_fd, TIOCGSERIAL, &kernel_serial_settings); r = ioctl(port_fd, TIOCGSERIAL, &kernel_serial_settings);
if(r < 0) { if (r < 0) {
return 0; return 0;
} }
@ -118,20 +118,20 @@ static void report_open_error(const char *filename, int err)
printf("\r\n"); printf("\r\n");
printf("Unable to open \"%s\"\r\n", filename); printf("Unable to open \"%s\"\r\n", filename);
if(err == EACCES) { if (err == EACCES) {
printf("You don't have permission to access %s\r\n", filename); printf("You don't have permission to access %s\r\n", filename);
} }
r = stat(filename, &info); r = stat(filename, &info);
if(r < 0) { if (r < 0) {
if(errno == ENOENT) { if (errno == ENOENT) {
printf("file %s does not exist\r\n", filename); printf("file %s does not exist\r\n", filename);
} }
else if(errno == ELOOP) { else if (errno == ELOOP) {
printf("too many symbolic links\r\n"); printf("too many symbolic links\r\n");
} }
else if(errno == EACCES) { else if (errno == EACCES) {
printf("permission denied to get file status\r\n"); printf("permission denied to get file status\r\n");
} }
else { else {
@ -146,7 +146,7 @@ static void report_open_error(const char *filename, int err)
p = getpwuid(my_uid); p = getpwuid(my_uid);
if(p) { if (p) {
snprintf(my_uname, sizeof(my_uname), snprintf(my_uname, sizeof(my_uname),
"\"%s\" (gid=%d)", p->pw_name, (int)my_uid); "\"%s\" (gid=%d)", p->pw_name, (int)my_uid);
} }
@ -157,7 +157,7 @@ static void report_open_error(const char *filename, int err)
p = getpwuid(info.st_uid); p = getpwuid(info.st_uid);
if(p) { if (p) {
snprintf(file_uname, sizeof(file_uname), snprintf(file_uname, sizeof(file_uname),
"\"%s\" (uid=%d)", p->pw_name, (int)info.st_uid); "\"%s\" (uid=%d)", p->pw_name, (int)info.st_uid);
} }
@ -168,7 +168,7 @@ static void report_open_error(const char *filename, int err)
g = getgrgid(my_gid); g = getgrgid(my_gid);
if(g) { if (g) {
snprintf(my_gname, sizeof(my_gname), snprintf(my_gname, sizeof(my_gname),
"\"%s\" (gid=%d)", g->gr_name, (int)my_gid); "\"%s\" (gid=%d)", g->gr_name, (int)my_gid);
} }
@ -179,7 +179,7 @@ static void report_open_error(const char *filename, int err)
g = getgrgid(info.st_gid); g = getgrgid(info.st_gid);
if(g) { if (g) {
snprintf(file_gname, sizeof(file_gname), snprintf(file_gname, sizeof(file_gname),
"\"%s\" (uid=%d)", g->gr_name, (int)info.st_gid); "\"%s\" (uid=%d)", g->gr_name, (int)info.st_gid);
} }
@ -193,7 +193,7 @@ static void report_open_error(const char *filename, int err)
perm = info.st_mode; perm = info.st_mode;
if((perm & S_IROTH) && (perm & S_IWOTH)) { if ((perm & S_IROTH) && (perm & S_IWOTH)) {
printf("%s has read/write permission for everybody\r\n", printf("%s has read/write permission for everybody\r\n",
filename); filename);
} }
@ -201,19 +201,19 @@ static void report_open_error(const char *filename, int err)
printf("%s is not read/write for everybody, so\r\n", filename); printf("%s is not read/write for everybody, so\r\n", filename);
printf(" you must match either user or group permission\r\n"); printf(" you must match either user or group permission\r\n");
if((perm & S_IRUSR) && (perm & S_IWUSR)) { if ((perm & S_IRUSR) && (perm & S_IWUSR)) {
printf("%s has read/write permission for user %s\r\n", printf("%s has read/write permission for user %s\r\n",
filename, file_uname); filename, file_uname);
perm_ok = 1; perm_ok = 1;
} }
if((perm & S_IRGRP) && (perm & S_IWGRP)) { if ((perm & S_IRGRP) && (perm & S_IWGRP)) {
printf("%s has read/write permission for group %s\r\n", printf("%s has read/write permission for group %s\r\n",
filename, file_gname); filename, file_gname);
perm_ok = 1; perm_ok = 1;
} }
if(perm_ok == 0) { if (perm_ok == 0) {
printf("%s does not read/write permission for user or group!\r\n", printf("%s does not read/write permission for user or group!\r\n",
filename); filename);
} }
@ -269,7 +269,7 @@ void send_break_signal(void)
void close_serial_port(void) void close_serial_port(void)
{ {
if(port_fd >= 0) { if (port_fd >= 0) {
close(port_fd); close(port_fd);
port_fd = -1; port_fd = -1;
} }
@ -278,43 +278,43 @@ void close_serial_port(void)
tcflag_t baud_name_to_flags(const char *baud_name) tcflag_t baud_name_to_flags(const char *baud_name)
{ {
if(strcmp(baud_name, "230400") == 0) { if (strcmp(baud_name, "230400") == 0) {
return B230400; return B230400;
} }
if(strcmp(baud_name, "115200") == 0) { if (strcmp(baud_name, "115200") == 0) {
return B115200; return B115200;
} }
if(strcmp(baud_name, "57600") == 0) { if (strcmp(baud_name, "57600") == 0) {
return B57600; return B57600;
} }
if(strcmp(baud_name, "38400") == 0) { if (strcmp(baud_name, "38400") == 0) {
return B38400; return B38400;
} }
if(strcmp(baud_name, "19200") == 0) { if (strcmp(baud_name, "19200") == 0) {
return B19200; return B19200;
} }
if(strcmp(baud_name, "9600") == 0) { if (strcmp(baud_name, "9600") == 0) {
return B9600; return B9600;
} }
if(strcmp(baud_name, "4800") == 0) { if (strcmp(baud_name, "4800") == 0) {
return B4800; return B4800;
} }
if(strcmp(baud_name, "2400") == 0) { if (strcmp(baud_name, "2400") == 0) {
return B2400; return B2400;
} }
if(strcmp(baud_name, "1200") == 0) { if (strcmp(baud_name, "1200") == 0) {
return B1200; return B1200;
} }
if(strcmp(baud_name, "300") == 0) { if (strcmp(baud_name, "300") == 0) {
return B300; return B300;
} }
@ -328,19 +328,19 @@ int set_baud(const char *baud_name)
tcflag_t baud; tcflag_t baud;
int r; int r;
if(port_fd < 0) { if (port_fd < 0) {
return -1; return -1;
} }
baud = baud_name_to_flags(baud_name); baud = baud_name_to_flags(baud_name);
if(baud == B0) { if (baud == B0) {
return -2; return -2;
} }
r = tcgetattr(port_fd, &port_setting); r = tcgetattr(port_fd, &port_setting);
if(r != 0) { if (r != 0) {
return -3; return -3;
} }
@ -350,7 +350,7 @@ int set_baud(const char *baud_name)
port_setting.c_lflag = 0; port_setting.c_lflag = 0;
r = tcsetattr(port_fd, TCSAFLUSH, &port_setting); r = tcsetattr(port_fd, TCSAFLUSH, &port_setting);
if(r != 0) { if (r != 0) {
return -4; return -4;
} }
@ -375,12 +375,12 @@ void set_rts(int val)
result = ioctl(port_fd, TIOCMGET, &flags); result = ioctl(port_fd, TIOCMGET, &flags);
if(result == -1) { if (result == -1) {
printf("Error %i while reading port io flags\n", errno); printf("Error %i while reading port io flags\n", errno);
return; return;
} }
if(val) { if (val) {
flags |= TIOCM_RTS; flags |= TIOCM_RTS;
} }
else { else {
@ -389,7 +389,7 @@ void set_rts(int val)
result = ioctl(port_fd, TIOCMSET, &flags); result = ioctl(port_fd, TIOCMSET, &flags);
if(result == -1) { if (result == -1) {
printf("Error %i while setting port io flags\n", errno); printf("Error %i while setting port io flags\n", errno);
} }
} }
@ -407,12 +407,12 @@ void set_dtr(int val)
result = ioctl(port_fd, TIOCMGET, &flags); result = ioctl(port_fd, TIOCMGET, &flags);
if(result == -1) { if (result == -1) {
printf("Error %i while reading port io flags\n", errno); printf("Error %i while reading port io flags\n", errno);
return; return;
} }
if(val) { if (val) {
flags |= TIOCM_DTR; flags |= TIOCM_DTR;
} }
else { else {
@ -421,7 +421,7 @@ void set_dtr(int val)
result = ioctl(port_fd, TIOCMSET, &flags); result = ioctl(port_fd, TIOCMSET, &flags);
if(result == -1) { if (result == -1) {
printf("Error %i while setting port io flags\n", errno); printf("Error %i while setting port io flags\n", errno);
} }
} }

View File

@ -2,7 +2,7 @@
int serial_add8(uint8_t s, uint8_t n) int serial_add8(uint8_t s, uint8_t n)
{ {
if(n > 127) { if (n > 127) {
return -1; return -1;
} }
@ -12,7 +12,7 @@ int serial_add8(uint8_t s, uint8_t n)
int serial_add16(uint16_t s, uint16_t n) int serial_add16(uint16_t s, uint16_t n)
{ {
if(n > 32767) { if (n > 32767) {
return -1; return -1;
} }
@ -22,7 +22,7 @@ int serial_add16(uint16_t s, uint16_t n)
int serial_add32(uint32_t s, uint32_t n) int serial_add32(uint32_t s, uint32_t n)
{ {
if(n > 2147483647) { if (n > 2147483647) {
return -1; return -1;
} }
@ -32,15 +32,15 @@ int serial_add32(uint32_t s, uint32_t n)
serial_comp_res_t serial_comp8(uint8_t s1, uint8_t s2) serial_comp_res_t serial_comp8(uint8_t s1, uint8_t s2)
{ {
if(s1 == s2) { if (s1 == s2) {
return EQUAL; return EQUAL;
} }
if((s1 < s2 && s1 - s2 < 128) || (s1 > s2 && s1 - s2 > 128)) { if ((s1 < s2 && s1 - s2 < 128) || (s1 > s2 && s1 - s2 > 128)) {
return LESS; return LESS;
} }
if((s1 < s2 && s1 - s2 > 128) || (s1 > s2 && s1 - s2 < 128)) { if ((s1 < s2 && s1 - s2 > 128) || (s1 > s2 && s1 - s2 < 128)) {
return GREATER; return GREATER;
} }
@ -49,15 +49,15 @@ serial_comp_res_t serial_comp8(uint8_t s1, uint8_t s2)
serial_comp_res_t serial_comp16(uint16_t s1, uint16_t s2) serial_comp_res_t serial_comp16(uint16_t s1, uint16_t s2)
{ {
if(s1 == s2) { if (s1 == s2) {
return EQUAL; return EQUAL;
} }
if((s1 < s2 && s1 - s2 < 32768) || (s1 > s2 && s1 - s2 > 32768)) { if ((s1 < s2 && s1 - s2 < 32768) || (s1 > s2 && s1 - s2 > 32768)) {
return LESS; return LESS;
} }
if((s1 < s2 && s1 - s2 > 32768) || (s1 > s2 && s1 - s2 < 32768)) { if ((s1 < s2 && s1 - s2 > 32768) || (s1 > s2 && s1 - s2 < 32768)) {
return GREATER; return GREATER;
} }
@ -66,15 +66,15 @@ serial_comp_res_t serial_comp16(uint16_t s1, uint16_t s2)
serial_comp_res_t serial_comp32(uint32_t s1, uint32_t s2) serial_comp_res_t serial_comp32(uint32_t s1, uint32_t s2)
{ {
if(s1 == s2) { if (s1 == s2) {
return EQUAL; return EQUAL;
} }
if((s1 < s2 && s1 - s2 < 2147483648) || (s1 > s2 && s1 - s2 > 2147483648)) { if ((s1 < s2 && s1 - s2 < 2147483648) || (s1 > s2 && s1 - s2 > 2147483648)) {
return LESS; return LESS;
} }
if((s1 < s2 && s1 - s2 > 2147483648) || (s1 > s2 && s1 - s2 < 2147483648)) { if ((s1 < s2 && s1 - s2 > 2147483648) || (s1 > s2 && s1 - s2 < 2147483648)) {
return GREATER; return GREATER;
} }

View File

@ -58,11 +58,11 @@ void *serial_reader_f(void *arg)
unsigned char buf[BUFFER_SIZE]; unsigned char buf[BUFFER_SIZE];
border_packet_t *packet_buf; border_packet_t *packet_buf;
while(1) { while (1) {
int n = readpacket(buf, BUFFER_SIZE); int n = readpacket(buf, BUFFER_SIZE);
if(n > 0) { if (n > 0) {
if(buf[0] == 0) { if (buf[0] == 0) {
packet_buf = (border_packet_t *)buf; packet_buf = (border_packet_t *)buf;
flowcontrol_deliver_from_tty(packet_buf, n); flowcontrol_deliver_from_tty(packet_buf, n);
continue; continue;
@ -95,10 +95,10 @@ void *tun_reader_f(void *args)
unsigned char data[BUFFER_SIZE]; unsigned char data[BUFFER_SIZE];
size_t bytes; size_t bytes;
while(1) { while (1) {
bytes = read(tun_fd, (void *)data, BUFFER_SIZE); bytes = read(tun_fd, (void *)data, BUFFER_SIZE);
if(bytes > 0) { if (bytes > 0) {
bytes = tun_to_serial_packet(tun_in_buf, (uint8_t *)data, bytes); bytes = tun_to_serial_packet(tun_in_buf, (uint8_t *)data, bytes);
flowcontrol_send_over_tty((border_packet_t *)tun_in_buf, bytes); flowcontrol_send_over_tty((border_packet_t *)tun_in_buf, bytes);
} }
@ -121,14 +121,14 @@ void border_send_ipv6_over_tun(int fd, const struct ip6_hdr *packet)
int tun_set_owner(int fd, const uid_t *uid, const gid_t *gid) int tun_set_owner(int fd, const uid_t *uid, const gid_t *gid)
{ {
if(uid != NULL) { if (uid != NULL) {
if(*uid != -1 && ioctl(fd, TUNSETOWNER, *uid)) { if (*uid != -1 && ioctl(fd, TUNSETOWNER, *uid)) {
return -1; return -1;
} }
} }
if(gid != NULL) { if (gid != NULL) {
if(*gid != -1 && ioctl(fd, TUNSETGROUP, *gid)) { if (*gid != -1 && ioctl(fd, TUNSETGROUP, *gid)) {
return -1; return -1;
} }
} }
@ -143,7 +143,7 @@ int tun_add_addr(const char *ip_addr)
printf("INFO: ip addr add %s dev %s\n", ip_addr, tun_if_name); printf("INFO: ip addr add %s dev %s\n", ip_addr, tun_if_name);
sprintf(command, "ip addr add %s dev %s", ip_addr, tun_if_name); sprintf(command, "ip addr add %s dev %s", ip_addr, tun_if_name);
if(system(command) != 0) { if (system(command) != 0) {
return -1; return -1;
} }
@ -165,7 +165,7 @@ int open_tun(char *if_name, int flags)
*/ */
/* open the clone device */ /* open the clone device */
if((fd = open(TUNDEV, O_RDWR)) < 0) { if ((fd = open(TUNDEV, O_RDWR)) < 0) {
return fd; return fd;
} }
@ -174,7 +174,7 @@ int open_tun(char *if_name, int flags)
ifr.ifr_flags = flags; /* IFF_TUN or IFF_TAP, plus maybe IFF_NO_PI */ ifr.ifr_flags = flags; /* IFF_TUN or IFF_TAP, plus maybe IFF_NO_PI */
if(*if_name) { if (*if_name) {
/* if a device name was specified, put it in the structure; otherwise, /* if a device name was specified, put it in the structure; otherwise,
* the kernel will try to allocate the "next" device of the * the kernel will try to allocate the "next" device of the
* specified type */ * specified type */
@ -182,7 +182,7 @@ int open_tun(char *if_name, int flags)
} }
/* try to create the device */ /* try to create the device */
if((err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0) { if ((err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0) {
close(fd); close(fd);
return err; return err;
} }
@ -207,13 +207,13 @@ int border_update_context(uint8_t cid, const struct in6_addr *prefix,
uint8_t len, uint8_t comp, uint8_t len, uint8_t comp,
uint16_t lifetime) uint16_t lifetime)
{ {
if(cid >= MAXIMUM_CONTEXTS) { if (cid >= MAXIMUM_CONTEXTS) {
return -1; return -1;
} }
len = (len <= 128) ? len : 128; len = (len <= 128) ? len : 128;
if(context_empty(cid)) { if (context_empty(cid)) {
context_cache[cid].version = get_abro_version(); context_cache[cid].version = get_abro_version();
} }
else { else {
@ -233,11 +233,11 @@ int border_update_context(uint8_t cid, const struct in6_addr *prefix,
int border_renew_existing_context(uint8_t cid) int border_renew_existing_context(uint8_t cid)
{ {
if(cid >= MAXIMUM_CONTEXTS) { if (cid >= MAXIMUM_CONTEXTS) {
return -1; return -1;
} }
if(context_empty(cid)) { if (context_empty(cid)) {
return -1; return -1;
} }
@ -248,11 +248,11 @@ int border_renew_existing_context(uint8_t cid)
void border_remove_context(uint8_t cid) void border_remove_context(uint8_t cid)
{ {
if(cid >= MAXIMUM_CONTEXTS) { if (cid >= MAXIMUM_CONTEXTS) {
return; return;
} }
if(context_empty(cid)) { if (context_empty(cid)) {
return; return;
} }
@ -268,7 +268,7 @@ int border_add_addr(const char *ip_addr)
{ {
struct in6_addr parsed_addr; struct in6_addr parsed_addr;
if(inet_pton(AF_INET6, ip_addr, &parsed_addr) != 1) { if (inet_pton(AF_INET6, ip_addr, &parsed_addr) != 1) {
return -1; return -1;
} }
@ -289,11 +289,11 @@ int border_initialize(char *if_name, const char *ip_addr, const char *tty_dev)
strtok(ip_addr_cpy, "/"); strtok(ip_addr_cpy, "/");
if((res = inet_pton(AF_INET6, ip_addr_cpy, &parsed_addr)) != 1) { if ((res = inet_pton(AF_INET6, ip_addr_cpy, &parsed_addr)) != 1) {
return res; return res;
} }
if((res = init_multiplex(tty_dev)) != 0) { if ((res = init_multiplex(tty_dev)) != 0) {
return res; return res;
} }
@ -304,16 +304,16 @@ int border_initialize(char *if_name, const char *ip_addr, const char *tty_dev)
strncpy(tun_if_name, if_name, IF_NAME_LEN); strncpy(tun_if_name, if_name, IF_NAME_LEN);
if((res = system(command)) != 0) { if ((res = system(command)) != 0) {
return res; return res;
} }
if((res = tun_add_addr(ip_addr)) != 0) { if ((res = tun_add_addr(ip_addr)) != 0) {
return res; return res;
} }
// initialize context cache as empty. // initialize context cache as empty.
for(i = 0; i < MAXIMUM_CONTEXTS; i++) { for (i = 0; i < MAXIMUM_CONTEXTS; i++) {
context_cache[i].cid = 0xFF; context_cache[i].cid = 0xFF;
} }

View File

@ -22,14 +22,14 @@ void init_file(const char *skeleton_file_name,
skeleton_file = fopen(skeleton_file_name, "r"); skeleton_file = fopen(skeleton_file_name, "r");
while(fgets(line, 1024, skeleton_file) != NULL) { while (fgets(line, 1024, skeleton_file) != NULL) {
if(strncmp(line, "# sending window size=%d\n", 1024) == 0) { if (strncmp(line, "# sending window size=%d\n", 1024) == 0) {
fprintf(stats_file, line, BORDER_SWS); fprintf(stats_file, line, BORDER_SWS);
} }
else if(strncmp(line, "# count=%ld (-c)\n", 1024) == 0) { else if (strncmp(line, "# count=%ld (-c)\n", 1024) == 0) {
fprintf(stats_file, line, runs_per_test); fprintf(stats_file, line, runs_per_test);
} }
else if(strncmp(line, "# interval=%f (-i)\n", 1024) == 0) { else if (strncmp(line, "# interval=%f (-i)\n", 1024) == 0) {
fprintf(stats_file, line, interval); fprintf(stats_file, line, interval);
} }
else { else {
@ -42,7 +42,7 @@ int testing_init(const char *stats_file_name,
const char *skeleton_file_name, const char *skeleton_file_name,
int runs_per_test, float interval) int runs_per_test, float interval)
{ {
if(stats_file != NULL) { if (stats_file != NULL) {
return -1; return -1;
} }
@ -51,7 +51,7 @@ int testing_init(const char *stats_file_name,
stats_file = fopen(stats_file_name, "w"); stats_file = fopen(stats_file_name, "w");
if(stats_file == NULL) { if (stats_file == NULL) {
return -1; return -1;
} }
@ -63,7 +63,7 @@ int testing_destroy()
{ {
int res, i; int res, i;
for(i = 0; i < run_counter; i++) { for (i = 0; i < run_counter; i++) {
fprintf(stats_file, "%7d\t%3d\t%7ld\n", fprintf(stats_file, "%7d\t%3d\t%7ld\n",
i, stats[i].seq_num, stats[i].time_diff i, stats[i].seq_num, stats[i].time_diff
); );
@ -82,7 +82,7 @@ int testing_destroy()
void testing_start(uint8_t seq_num) void testing_start(uint8_t seq_num)
{ {
if(stats_file == NULL) { if (stats_file == NULL) {
return; return;
} }
@ -91,7 +91,7 @@ void testing_start(uint8_t seq_num)
void testing_stop(uint8_t seq_num) void testing_stop(uint8_t seq_num)
{ {
if(stats_file == NULL) { if (stats_file == NULL) {
return; return;
} }
@ -123,7 +123,7 @@ void generate_filename(
today = time(NULL); today = time(NULL);
tmp = localtime(&today); tmp = localtime(&today);
if(tmp == NULL) { if (tmp == NULL) {
perror("localtime"); perror("localtime");
return; return;
} }
@ -141,9 +141,9 @@ void generate_filename(
count++ count++
); );
} }
while((test = fopen(filename, "r")) != NULL); while ((test = fopen(filename, "r")) != NULL);
if(test != NULL) { if (test != NULL) {
fclose(test); fclose(test);
} }
} }

View File

@ -102,7 +102,7 @@ int cc1100_send_csmaca(radio_address_t address, protocol_t protocol, int priorit
} }
/* Calculate collisions per second */ /* Calculate collisions per second */
if(collision_state == COLLISION_STATE_INITIAL) { if (collision_state == COLLISION_STATE_INITIAL) {
timex_t now; timex_t now;
vtimer_now(&now); vtimer_now(&now);
collision_measurement_start = now.microseconds; collision_measurement_start = now.microseconds;
@ -110,21 +110,21 @@ int cc1100_send_csmaca(radio_address_t address, protocol_t protocol, int priorit
collisions_per_sec = 0; collisions_per_sec = 0;
collision_state = COLLISION_STATE_MEASURE; collision_state = COLLISION_STATE_MEASURE;
} }
else if(collision_state == COLLISION_STATE_MEASURE) { else if (collision_state == COLLISION_STATE_MEASURE) {
timex_t now; timex_t now;
vtimer_now(&now); vtimer_now(&now);
uint64_t timespan = now.microseconds - collision_measurement_start; uint64_t timespan = now.microseconds - collision_measurement_start;
if(timespan > 1000000) { if (timespan > 1000000) {
collisions_per_sec = (collision_count * 1000000) / (double) timespan; collisions_per_sec = (collision_count * 1000000) / (double) timespan;
if(collisions_per_sec > 0.5 && collisions_per_sec <= 2.2) { if (collisions_per_sec > 0.5 && collisions_per_sec <= 2.2) {
timex_t now; timex_t now;
vtimer_now(&now); vtimer_now(&now);
collision_measurement_start = now.microseconds; collision_measurement_start = now.microseconds;
collision_state = COLLISION_STATE_KEEP; collision_state = COLLISION_STATE_KEEP;
} }
else if(collisions_per_sec > 2.2) { else if (collisions_per_sec > 2.2) {
timex_t now; timex_t now;
vtimer_now(&now); vtimer_now(&now);
collision_measurement_start = now.microseconds; collision_measurement_start = now.microseconds;
@ -135,21 +135,21 @@ int cc1100_send_csmaca(radio_address_t address, protocol_t protocol, int priorit
} }
} }
} }
else if(collision_state == COLLISION_STATE_KEEP) { else if (collision_state == COLLISION_STATE_KEEP) {
timex_t now; timex_t now;
vtimer_now(&now); vtimer_now(&now);
uint64_t timespan = now.microseconds - collision_measurement_start; uint64_t timespan = now.microseconds - collision_measurement_start;
if(timespan > 5000000) { if (timespan > 5000000) {
collision_state = COLLISION_STATE_INITIAL; collision_state = COLLISION_STATE_INITIAL;
} }
} }
/* Adjust initial window size according to collision rate */ /* Adjust initial window size according to collision rate */
if(collisions_per_sec > 0.5 && collisions_per_sec <= 2.2) { if (collisions_per_sec > 0.5 && collisions_per_sec <= 2.2) {
min_window_size *= 2; min_window_size *= 2;
} }
else if(collisions_per_sec > 2.2) { else if (collisions_per_sec > 2.2) {
min_window_size *= 4; min_window_size *= 4;
} }
@ -158,7 +158,7 @@ int cc1100_send_csmaca(radio_address_t address, protocol_t protocol, int priorit
uint32_t total; /* Holds the total wait time before send try */ uint32_t total; /* Holds the total wait time before send try */
uint32_t cs_timeout; /* Current carrier sense timeout value */ uint32_t cs_timeout; /* Current carrier sense timeout value */
if(protocol == 0) { if (protocol == 0) {
return RADIO_INVALID_PARAM; /* Not allowed, protocol id must be greater zero */ return RADIO_INVALID_PARAM; /* Not allowed, protocol id must be greater zero */
} }
@ -168,13 +168,13 @@ int cc1100_send_csmaca(radio_address_t address, protocol_t protocol, int priorit
send_csmaca_calls++; send_csmaca_calls++;
int fail_percentage = (send_csmaca_calls_cs_timeout * 100) / send_csmaca_calls; int fail_percentage = (send_csmaca_calls_cs_timeout * 100) / send_csmaca_calls;
if(fail_percentage == 0) { if (fail_percentage == 0) {
fail_percentage = 1; fail_percentage = 1;
} }
cs_timeout = CARRIER_SENSE_TIMEOUT / fail_percentage; cs_timeout = CARRIER_SENSE_TIMEOUT / fail_percentage;
if(cs_timeout < CARRIER_SENSE_TIMEOUT_MIN) { if (cs_timeout < CARRIER_SENSE_TIMEOUT_MIN) {
cs_timeout = CARRIER_SENSE_TIMEOUT_MIN; cs_timeout = CARRIER_SENSE_TIMEOUT_MIN;
} }
@ -182,19 +182,19 @@ int cc1100_send_csmaca(radio_address_t address, protocol_t protocol, int priorit
window: window:
if(backoff != 0) { if (backoff != 0) {
goto cycle; /* If backoff was 0 */ goto cycle; /* If backoff was 0 */
} }
windowSize *= 2; /* ...double the current window size */ windowSize *= 2; /* ...double the current window size */
if(windowSize > max_window_size) { if (windowSize > max_window_size) {
windowSize = max_window_size; /* This is the maximum size allowed */ windowSize = max_window_size; /* This is the maximum size allowed */
} }
backoff = rand() % windowSize; /* ...and choose new backoff */ backoff = rand() % windowSize; /* ...and choose new backoff */
if(backoff < 0) { if (backoff < 0) {
backoff *= -1; backoff *= -1;
} }
@ -204,8 +204,8 @@ cycle:
cs_hwtimer_id = hwtimer_set(cs_timeout, /* Set hwtimer to set CS timeout flag */ cs_hwtimer_id = hwtimer_set(cs_timeout, /* Set hwtimer to set CS timeout flag */
cs_timeout_cb, NULL); cs_timeout_cb, NULL);
while(cc1100_cs_read()) { /* Wait until air is free */ while (cc1100_cs_read()) { /* Wait until air is free */
if(cs_timeout_flag) { if (cs_timeout_flag) {
send_csmaca_calls_cs_timeout++; send_csmaca_calls_cs_timeout++;
#ifndef CSMACA_MAC_AGGRESSIVE_MODE #ifndef CSMACA_MAC_AGGRESSIVE_MODE
cc1100_phy_mutex_unlock(); cc1100_phy_mutex_unlock();
@ -222,12 +222,12 @@ cycle:
cc1100_cs_write_cca(1); /* Air is free now */ cc1100_cs_write_cca(1); /* Air is free now */
cc1100_cs_set_enabled(true); cc1100_cs_set_enabled(true);
if(cc1100_cs_read()) { if (cc1100_cs_read()) {
goto window; /* GDO0 triggers on rising edge, so */ goto window; /* GDO0 triggers on rising edge, so */
} }
/* test once after interrupt is enabled */ /* test once after interrupt is enabled */
if(backoff > 0) { if (backoff > 0) {
backoff--; /* Decrement backoff counter */ backoff--; /* Decrement backoff counter */
} }
@ -238,9 +238,9 @@ cycle:
cs_hwtimer_id = hwtimer_set(total, /* Set hwtimer to set CS timeout flag */ cs_hwtimer_id = hwtimer_set(total, /* Set hwtimer to set CS timeout flag */
cs_timeout_cb, NULL); cs_timeout_cb, NULL);
while(!cs_timeout_flag while (!cs_timeout_flag
|| !cc1100_cs_read_cca()) { /* Wait until timeout is finished */ || !cc1100_cs_read_cca()) { /* Wait until timeout is finished */
if(cc1100_cs_read_cca() == 0) { /* Is the air still free? */ if (cc1100_cs_read_cca() == 0) { /* Is the air still free? */
hwtimer_remove(cs_hwtimer_id); hwtimer_remove(cs_hwtimer_id);
goto window; /* No. Go back to new wait period. */ goto window; /* No. Go back to new wait period. */
} }
@ -252,7 +252,7 @@ send:
#endif #endif
int res = cc1100_send(address, protocol, priority, payload, payload_len); int res = cc1100_send(address, protocol, priority, payload, payload_len);
if(res < 0) { if (res < 0) {
collision_count++; collision_count++;
} }

View File

@ -85,7 +85,7 @@ static uint8_t pa_table[] = { ///< PATABLE with available output powers
0xCC, ///< + 7 dBm 0xCC, ///< + 7 dBm
0xC6, ///< + 9 dBm 0xC6, ///< + 9 dBm
0xC3 ///< +10 dBm 0xC3 ///< +10 dBm
}; /* If PATABLE is changed in size, adjust MAX_OUTPUT_POWER definition in CC1100 interface! */ }; /* If PATABLE is changed in size, adjust MAX_OUTPUT_POWER definition in CC1100 interface!*/
static int8_t pa_table_dBm[] = { ///< Values of the PATABLE in dBm static int8_t pa_table_dBm[] = { ///< Values of the PATABLE in dBm
-52, -52,
@ -176,12 +176,12 @@ static bool spi_receive_packet_variable(uint8_t *rxBuffer, uint8_t length)
uint8_t packetLength = 0; uint8_t packetLength = 0;
/* Any bytes available in RX FIFO? */ /* Any bytes available in RX FIFO? */
if((cc1100_spi_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) { if ((cc1100_spi_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) {
/* Read length byte (first byte in RX FIFO) */ /* Read length byte (first byte in RX FIFO) */
packetLength = cc1100_spi_read_reg(CC1100_RXFIFO); packetLength = cc1100_spi_read_reg(CC1100_RXFIFO);
/* Read data from RX FIFO and store in rxBuffer */ /* Read data from RX FIFO and store in rxBuffer */
if(packetLength <= length) { if (packetLength <= length) {
/* Put length byte at first position in RX Buffer */ /* Put length byte at first position in RX Buffer */
rxBuffer[0] = packetLength; rxBuffer[0] = packetLength;
@ -197,7 +197,7 @@ static bool spi_receive_packet_variable(uint8_t *rxBuffer, uint8_t length)
/* MSB of LQI is the CRC_OK bit */ /* MSB of LQI is the CRC_OK bit */
rflags.CRC_STATE = (status[I_LQI] & CRC_OK) >> 7; rflags.CRC_STATE = (status[I_LQI] & CRC_OK) >> 7;
if(!rflags.CRC_STATE) { if (!rflags.CRC_STATE) {
cc1100_statistic.packets_in_crc_fail++; cc1100_statistic.packets_in_crc_fail++;
} }
@ -221,7 +221,7 @@ bool cc1100_spi_receive_packet(uint8_t *rxBuffer, uint8_t length)
{ {
uint8_t pkt_len_cfg = cc1100_spi_read_reg(CC1100_PKTCTRL0) & PKT_LENGTH_CONFIG; uint8_t pkt_len_cfg = cc1100_spi_read_reg(CC1100_PKTCTRL0) & PKT_LENGTH_CONFIG;
if(pkt_len_cfg == VARIABLE_PKTLEN) { if (pkt_len_cfg == VARIABLE_PKTLEN) {
return spi_receive_packet_variable(rxBuffer, length); return spi_receive_packet_variable(rxBuffer, length);
} }
@ -236,7 +236,7 @@ bool cc1100_spi_receive_packet(uint8_t *rxBuffer, uint8_t length)
void cc1100_set_idle(void) void cc1100_set_idle(void)
{ {
if(radio_state == RADIO_WOR) { if (radio_state == RADIO_WOR) {
/* Wake up the chip from WOR/sleep */ /* Wake up the chip from WOR/sleep */
cc110x_spi_select(); cc110x_spi_select();
hwtimer_wait(RTIMER_TICKS(122)); hwtimer_wait(RTIMER_TICKS(122));
@ -253,7 +253,7 @@ void cc1100_set_idle(void)
static void wakeup_from_rx(void) static void wakeup_from_rx(void)
{ {
if(radio_state != RADIO_RX) { if (radio_state != RADIO_RX) {
return; return;
} }
@ -279,7 +279,7 @@ static void setup_rx_mode(void)
*/ */
static void wakeup_from_wor(void) static void wakeup_from_wor(void)
{ {
if(radio_state != RADIO_WOR) { if (radio_state != RADIO_WOR) {
return; return;
} }
@ -304,7 +304,7 @@ void switch_to_wor2(void)
cc1100_wor_config.rx_time_reg); /* Configure RX_TIME (for use in WOR) */ cc1100_wor_config.rx_time_reg); /* Configure RX_TIME (for use in WOR) */
cc1100_spi_write_reg(CC1100_MCSM0, 0x18); /* Turn on FS-Autocal */ cc1100_spi_write_reg(CC1100_MCSM0, 0x18); /* Turn on FS-Autocal */
if(rflags.WOR_RST) { if (rflags.WOR_RST) {
cc1100_spi_strobe(CC1100_SWORRST); /* Resets the real time clock */ cc1100_spi_strobe(CC1100_SWORRST); /* Resets the real time clock */
rflags.WOR_RST = false; rflags.WOR_RST = false;
} }
@ -320,7 +320,7 @@ static void hwtimer_switch_to_wor2_wrapper(void *ptr)
{ {
wor_hwtimer_id = -1; /* kernel timer handler function called, clear timer id */ wor_hwtimer_id = -1; /* kernel timer handler function called, clear timer id */
if(rflags.TX) { if (rflags.TX) {
return; /* Stability: don't allow WOR timers at this point */ return; /* Stability: don't allow WOR timers at this point */
} }
@ -334,13 +334,13 @@ static void hwtimer_switch_to_wor2_wrapper(void *ptr)
static void switch_to_wor(void) static void switch_to_wor(void)
{ {
/* Any incoming packet? */ /* Any incoming packet? */
if(cc110x_get_gdo2()) { if (cc110x_get_gdo2()) {
/* Then don't go to WOR now */ /* Then don't go to WOR now */
return; return;
} }
/* Step 1: Set chip for random interval (1..RX_INTERVAL) to power down mode */ /* Step 1: Set chip for random interval (1..RX_INTERVAL) to power down mode */
if(!rflags.MAN_WOR) { if (!rflags.MAN_WOR) {
rflags.MAN_WOR = true; rflags.MAN_WOR = true;
radio_state = RADIO_WOR; radio_state = RADIO_WOR;
/* Go to power down mode */ /* Go to power down mode */
@ -351,7 +351,7 @@ static void switch_to_wor(void)
int r = (rand() / (double)(RAND_MAX + 1.0)) * (cc1100_wor_config.rx_interval * 100.0) + 20; int r = (rand() / (double)(RAND_MAX + 1.0)) * (cc1100_wor_config.rx_interval * 100.0) + 20;
wor_hwtimer_id = hwtimer_set(r, cc1100_hwtimer_go_receive_wrapper, NULL); wor_hwtimer_id = hwtimer_set(r, cc1100_hwtimer_go_receive_wrapper, NULL);
if(wor_hwtimer_id == -1) { if (wor_hwtimer_id == -1) {
rflags.KT_RES_ERR = true; rflags.KT_RES_ERR = true;
/* No hwtimer available, go immediately to WOR mode. */ /* No hwtimer available, go immediately to WOR mode. */
/* Else never receiving packets again... */ /* Else never receiving packets again... */
@ -370,7 +370,7 @@ static void switch_to_wor(void)
wor_hwtimer_id = hwtimer_set((cc1100_wor_config.rx_time_ms * 100 + 150), wor_hwtimer_id = hwtimer_set((cc1100_wor_config.rx_time_ms * 100 + 150),
hwtimer_switch_to_wor2_wrapper, NULL); /* add 1,5 ms secure time */ hwtimer_switch_to_wor2_wrapper, NULL); /* add 1,5 ms secure time */
if(wor_hwtimer_id == -1) { if (wor_hwtimer_id == -1) {
rflags.KT_RES_ERR = true; rflags.KT_RES_ERR = true;
} }
} }
@ -428,7 +428,7 @@ static bool cc1100_set_mode0(uint8_t mode, uint16_t opt_mode_data)
result = cc1100_phy_calc_wor_settings(opt_mode_data); result = cc1100_phy_calc_wor_settings(opt_mode_data);
/* If settings can be applied, set new mode and burst count */ /* If settings can be applied, set new mode and burst count */
if(result != -1) { if (result != -1) {
radio_mode = mode; radio_mode = mode;
cc1100_go_idle = wakeup_from_wor; cc1100_go_idle = wakeup_from_wor;
cc1100_go_receive = switch_to_wor; cc1100_go_receive = switch_to_wor;
@ -469,7 +469,7 @@ bool cc1100_set_mode(uint8_t mode, uint16_t opt_mode_data)
bool result = cc1100_set_mode0(mode, opt_mode_data); bool result = cc1100_set_mode0(mode, opt_mode_data);
/* If mode change was successful (mode is valid) */ /* If mode change was successful (mode is valid) */
if(result) { if (result) {
/* Setup new mode configuration */ /* Setup new mode configuration */
cc1100_setup_mode(); cc1100_setup_mode();
/* Reset statistics */ /* Reset statistics */
@ -535,11 +535,11 @@ void cc1100_hwtimer_go_receive_wrapper(void *ptr)
wor_hwtimer_id = -1; wor_hwtimer_id = -1;
/* Stability: don't allow WOR timers at this point */ /* Stability: don't allow WOR timers at this point */
if(rflags.TX) { if (rflags.TX) {
return; return;
} }
if(radio_state == RADIO_PWD) { if (radio_state == RADIO_PWD) {
/* Go to RX state, listen for packets as long as WOR_TIMEOUT_2 */ /* Go to RX state, listen for packets as long as WOR_TIMEOUT_2 */
cc1100_spi_strobe(CC1100_SRX); cc1100_spi_strobe(CC1100_SRX);
hwtimer_wait(IDLE_TO_RX_TIME); hwtimer_wait(IDLE_TO_RX_TIME);
@ -547,7 +547,7 @@ void cc1100_hwtimer_go_receive_wrapper(void *ptr)
/* Set hwtimer to put CC1100 back to WOR after WOR_TIMEOUT_2 */ /* Set hwtimer to put CC1100 back to WOR after WOR_TIMEOUT_2 */
wor_hwtimer_id = hwtimer_set(WOR_TIMEOUT_2, cc1100_hwtimer_go_receive_wrapper, NULL); wor_hwtimer_id = hwtimer_set(WOR_TIMEOUT_2, cc1100_hwtimer_go_receive_wrapper, NULL);
if(wor_hwtimer_id == -1) { if (wor_hwtimer_id == -1) {
rflags.KT_RES_ERR = true; rflags.KT_RES_ERR = true;
/* No hwtimer available, go immediately to WOR mode. */ /* No hwtimer available, go immediately to WOR mode. */
/* Else never receiving packets again... */ /* Else never receiving packets again... */
@ -594,7 +594,7 @@ void cc1100_send_raw(uint8_t *tx_buffer, uint8_t size)
/* or equal to PACKET_LENGTH (62 bytes). So the receiver */ /* or equal to PACKET_LENGTH (62 bytes). So the receiver */
/* can put the whole packet in its RX-FIFO (with appended */ /* can put the whole packet in its RX-FIFO (with appended */
/* packet status bytes). */ /* packet status bytes). */
if(size > PACKET_LENGTH) { if (size > PACKET_LENGTH) {
return; return;
} }
@ -613,10 +613,10 @@ void cc1100_send_raw(uint8_t *tx_buffer, uint8_t size)
cc1100_spi_strobe(CC1100_STX); cc1100_spi_strobe(CC1100_STX);
/* Wait for GDO2 to be set -> sync word transmitted */ /* Wait for GDO2 to be set -> sync word transmitted */
while(cc110x_get_gdo2() == 0) { while (cc110x_get_gdo2() == 0) {
abort_count++; abort_count++;
if(abort_count > CC1100_SYNC_WORD_TX_TIME) { if (abort_count > CC1100_SYNC_WORD_TX_TIME) {
/* Abort waiting. CC1100 maybe in wrong mode */ /* Abort waiting. CC1100 maybe in wrong mode */
/* e.g. sending preambles for always */ /* e.g. sending preambles for always */
puts("[CC1100 TX] fatal error\n"); puts("[CC1100 TX] fatal error\n");
@ -627,7 +627,7 @@ void cc1100_send_raw(uint8_t *tx_buffer, uint8_t size)
restoreIRQ(cpsr); restoreIRQ(cpsr);
/* Wait for GDO2 to be cleared -> end of packet */ /* Wait for GDO2 to be cleared -> end of packet */
while(cc110x_get_gdo2() != 0); while (cc110x_get_gdo2() != 0);
/* Experimental - TOF Measurement */ /* Experimental - TOF Measurement */
cc110x_after_send(); cc110x_after_send();
@ -650,7 +650,7 @@ read_register(uint8_t r)
/* Have to put radio back to WOR/RX if old radio state */ /* Have to put radio back to WOR/RX if old radio state */
/* was WOR/RX, otherwise no action is necessary */ /* was WOR/RX, otherwise no action is necessary */
if(old_state == RADIO_WOR || old_state == RADIO_RX) { if (old_state == RADIO_WOR || old_state == RADIO_RX) {
cc1100_go_receive(); cc1100_go_receive();
} }
@ -669,7 +669,7 @@ write_register(uint8_t r, uint8_t value)
/* Have to put radio back to WOR/RX if old radio state */ /* Have to put radio back to WOR/RX if old radio state */
/* was WOR/RX, otherwise no action is necessary */ /* was WOR/RX, otherwise no action is necessary */
if(old_state == RADIO_WOR || old_state == RADIO_RX) { if (old_state == RADIO_WOR || old_state == RADIO_RX) {
cc1100_go_receive(); cc1100_go_receive();
} }
} }
@ -688,7 +688,7 @@ uint8_t cc1100_get_channel(void)
bool bool
cc1100_set_channel(uint8_t channr) cc1100_set_channel(uint8_t channr)
{ {
if(channr > MAX_CHANNR) { if (channr > MAX_CHANNR) {
return false; return false;
} }
@ -700,7 +700,7 @@ cc1100_set_channel(uint8_t channr)
bool bool
cc1100_set_output_power(uint8_t pa_idx) cc1100_set_output_power(uint8_t pa_idx)
{ {
if(pa_idx >= sizeof(pa_table)) { if (pa_idx >= sizeof(pa_table)) {
return false; return false;
} }
@ -725,7 +725,7 @@ char *cc1100_get_marc_state(void)
/* Have to put radio back to WOR/RX if old radio state */ /* Have to put radio back to WOR/RX if old radio state */
/* was WOR/RX, otherwise no action is necessary */ /* was WOR/RX, otherwise no action is necessary */
if(old_state == RADIO_WOR || old_state == RADIO_RX) { if (old_state == RADIO_WOR || old_state == RADIO_RX) {
cc1100_go_receive(); cc1100_go_receive();
} }
@ -840,7 +840,7 @@ void cc1100_init(void)
int cc1100_get_avg_transmission_duration(void) int cc1100_get_avg_transmission_duration(void)
{ {
if(radio_mode == CC1100_MODE_WOR) { if (radio_mode == CC1100_MODE_WOR) {
/* Transmission duration ~ RX interval */ /* Transmission duration ~ RX interval */
/* Double value because of MAC delay. */ /* Double value because of MAC delay. */
return 2 * cc1100_wor_config.rx_interval; return 2 * cc1100_wor_config.rx_interval;
@ -859,13 +859,13 @@ radio_address_t cc1100_get_address(void)
bool cc1100_set_address(radio_address_t address) bool cc1100_set_address(radio_address_t address)
{ {
if(address < MIN_UID || address > MAX_UID) { if (address < MIN_UID || address > MAX_UID) {
return false; return false;
} }
uint8_t id = (uint8_t) address; uint8_t id = (uint8_t) address;
if(radio_state != RADIO_UNKNOWN) { if (radio_state != RADIO_UNKNOWN) {
write_register(CC1100_ADDR, id); write_register(CC1100_ADDR, id);
} }
@ -879,7 +879,7 @@ rd_set_mode(int mode)
int result; int result;
/* Get current radio mode */ /* Get current radio mode */
if(radio_state == RADIO_UNKNOWN || radio_state == RADIO_PWD) { if (radio_state == RADIO_UNKNOWN || radio_state == RADIO_PWD) {
result = RADIO_MODE_OFF; result = RADIO_MODE_OFF;
} }
else { else {
@ -917,7 +917,7 @@ void cc1100_cs_init(void)
{ {
cc1100_go_idle(); /* Wake CC1100 up from Wake-On-Radio mode */ cc1100_go_idle(); /* Wake CC1100 up from Wake-On-Radio mode */
if(radio_state == RADIO_RX) { /* If radio in RX mode */ if (radio_state == RADIO_RX) { /* If radio in RX mode */
cc1100_spi_strobe(CC1100_SIDLE); /* Go back to IDLE for calibration */ cc1100_spi_strobe(CC1100_SIDLE); /* Go back to IDLE for calibration */
} }
@ -932,7 +932,7 @@ void cc1100_cs_init(void)
void cc1100_cs_set_enabled(bool enabled) void cc1100_cs_set_enabled(bool enabled)
{ {
if(enabled) { if (enabled) {
/* Enable carrier sense detection (GDO0 interrupt) */ /* Enable carrier sense detection (GDO0 interrupt) */
cc110x_gdo0_enable(); cc110x_gdo0_enable();
} }

View File

@ -272,7 +272,7 @@ bool cc1100_spi_receive_packet(uint8_t *rxBuffer, uint8_t length);
* buffer must match the CC1100 packet format (so address interpretation * buffer must match the CC1100 packet format (so address interpretation
* succeeds). * succeeds).
* <p> * <p>
* This function is not mode safe! The radio must be woke up before * This function is not mode safe!The radio must be woke up before
* sending and has to be put back manually to receive mode. * sending and has to be put back manually to receive mode.
* *
* @param tx_buffer Data source buffer. * @param tx_buffer Data source buffer.

View File

@ -174,7 +174,7 @@ void cc1100_phy_init()
rx_buffer_size = 0; rx_buffer_size = 0;
/* Initialize RX-Buffer (clear content) */ /* Initialize RX-Buffer (clear content) */
for(i = 0; i < RX_BUFF_SIZE; i++) { for (i = 0; i < RX_BUFF_SIZE; i++) {
rx_buffer->packet.length = 0; rx_buffer->packet.length = 0;
} }
@ -194,10 +194,10 @@ void cc1100_phy_init()
cc1100_event_handler_function, cc1100_event_handler_name); cc1100_event_handler_function, cc1100_event_handler_name);
/* Active watchdog for the first time */ /* Active watchdog for the first time */
if(radio_mode == CC1100_MODE_CONSTANT_RX) { if (radio_mode == CC1100_MODE_CONSTANT_RX) {
cc1100_watch_dog_period.microseconds = CC1100_WATCHDOG_PERIOD; cc1100_watch_dog_period.microseconds = CC1100_WATCHDOG_PERIOD;
if(cc1100_watch_dog_period.microseconds != 0) { if (cc1100_watch_dog_period.microseconds != 0) {
timex_t temp = timex_set(0, 5000000L); timex_t temp = timex_set(0, 5000000L);
vtimer_set_msg(&cc1100_watch_dog, temp, cc1100_event_handler_pid, NULL); vtimer_set_msg(&cc1100_watch_dog, temp, cc1100_event_handler_pid, NULL);
} }
@ -210,7 +210,7 @@ void cc1100_phy_init()
void cc1100_phy_mutex_lock(void) void cc1100_phy_mutex_lock(void)
{ {
if(active_thread->pid != cc1100_mutex_pid) { if (active_thread->pid != cc1100_mutex_pid) {
mutex_lock(&cc1100_mutex); mutex_lock(&cc1100_mutex);
cc1100_mutex_pid = active_thread->pid; cc1100_mutex_pid = active_thread->pid;
} }
@ -274,7 +274,7 @@ void cc1100_print_config(void)
printf("Retransmissions (broadcast): %u - always\r\n", cc1100_retransmission_count_bc); printf("Retransmissions (broadcast): %u - always\r\n", cc1100_retransmission_count_bc);
printf("Output power setting: %s\r\n", cc1100_get_output_power(buf)); printf("Output power setting: %s\r\n", cc1100_get_output_power(buf));
if(radio_mode == CC1100_MODE_WOR) { if (radio_mode == CC1100_MODE_WOR) {
printf("RX polling interval: %u ms\r\n", cc1100_wor_config.rx_interval); printf("RX polling interval: %u ms\r\n", cc1100_wor_config.rx_interval);
printf("WOR receive time: 0x%.2X (%f ms)\r\n", cc1100_wor_config.rx_time_reg, printf("WOR receive time: 0x%.2X (%f ms)\r\n", cc1100_wor_config.rx_time_reg,
cc1100_wor_config.rx_time_ms); cc1100_wor_config.rx_time_ms);
@ -312,7 +312,7 @@ int cc1100_phy_calc_wor_settings(uint16_t millis)
uint16_t event0_min = (uint16_t)(t_packet_interval * 8) + 1 + 10; uint16_t event0_min = (uint16_t)(t_packet_interval * 8) + 1 + 10;
/* Check if given value is in allowed range */ /* Check if given value is in allowed range */
if(millis < event0_min || millis > EVENT0_MAX) { if (millis < event0_min || millis > EVENT0_MAX) {
return -1; return -1;
} }
@ -323,7 +323,7 @@ int cc1100_phy_calc_wor_settings(uint16_t millis)
/* Calculate new value for EVENT0 */ /* Calculate new value for EVENT0 */
double tmp = (millis * 26) / (double) 750; double tmp = (millis * 26) / (double) 750;
if(wor_res == 1) { if (wor_res == 1) {
tmp /= 32; tmp /= 32;
} }
@ -334,22 +334,22 @@ int cc1100_phy_calc_wor_settings(uint16_t millis)
int i; int i;
double rx_timeouts[DUTY_CYCLE_SIZE]; double rx_timeouts[DUTY_CYCLE_SIZE];
for(i = 0; i < DUTY_CYCLE_SIZE; i++) { for (i = 0; i < DUTY_CYCLE_SIZE; i++) {
rx_timeouts[i] = (millis * duty_cycle[wor_res][i]) / 100; rx_timeouts[i] = (millis * duty_cycle[wor_res][i]) / 100;
} }
/* Calculate index for optimal rx_timeout (MCSM2.RX_TIME) (if possible) */ /* Calculate index for optimal rx_timeout (MCSM2.RX_TIME) (if possible) */
int idx = -1; int idx = -1;
for(i = DUTY_CYCLE_SIZE - 1; i >= 0; i--) { for (i = DUTY_CYCLE_SIZE - 1; i >= 0; i--) {
if(rx_timeouts[i] > t_packet_interval) { if (rx_timeouts[i] > t_packet_interval) {
idx = i; idx = i;
break; break;
} }
} }
/* If no index found, exit here (configuration with given value is not possible) */ /* If no index found, exit here (configuration with given value is not possible) */
if(idx == -1) { if (idx == -1) {
return -1; return -1;
} }
@ -381,12 +381,12 @@ static bool contains_seq_entry(uint8_t src, uint8_t id)
vtimer_now(&now_timex); vtimer_now(&now_timex);
uint64_t now = now_timex.microseconds; uint64_t now = now_timex.microseconds;
for(i = 0; i < MAX_SEQ_BUFFER_SIZE; i++) { for (i = 0; i < MAX_SEQ_BUFFER_SIZE; i++) {
if((seq_buffer[i].source == src) && (seq_buffer[i].identification == id)) { if ((seq_buffer[i].source == src) && (seq_buffer[i].identification == id)) {
/* Check if time stamp is OK */ /* Check if time stamp is OK */
cmp = (radio_mode == CC1100_MODE_WOR) ? cc1100_wor_config.rx_interval : 16000; /* constant RX ~16ms */ cmp = (radio_mode == CC1100_MODE_WOR) ? cc1100_wor_config.rx_interval : 16000; /* constant RX ~16ms */
if((now - seq_buffer[i].m_ticks) <= cmp) { if ((now - seq_buffer[i].m_ticks) <= cmp) {
return true; return true;
} }
else { else {
@ -405,8 +405,8 @@ static void add_seq_entry(uint8_t src, uint8_t id)
* lost (especially important in constant RX mode). */ * lost (especially important in constant RX mode). */
int i; int i;
for(i = 0; i < MAX_SEQ_BUFFER_SIZE; i++) { for (i = 0; i < MAX_SEQ_BUFFER_SIZE; i++) {
if(seq_buffer[i].source == src) { if (seq_buffer[i].source == src) {
seq_buffer[i].source = 0; /* Reset */ seq_buffer[i].source = 0; /* Reset */
} }
} }
@ -425,7 +425,7 @@ static void add_seq_entry(uint8_t src, uint8_t id)
seq_buffer_pos++; seq_buffer_pos++;
if(seq_buffer_pos == MAX_SEQ_BUFFER_SIZE) { if (seq_buffer_pos == MAX_SEQ_BUFFER_SIZE) {
seq_buffer_pos = 0; seq_buffer_pos = 0;
} }
} }
@ -442,7 +442,7 @@ static void send_link_level_ack(uint8_t dest)
radio_state = RADIO_SEND_ACK; /* Set state to "Sending ACK" */ radio_state = RADIO_SEND_ACK; /* Set state to "Sending ACK" */
cc1100_spi_write_reg(CC1100_MCSM0, 0x08); /* Turn off FS-Autocal */ cc1100_spi_write_reg(CC1100_MCSM0, 0x08); /* Turn off FS-Autocal */
cc1100_spi_write_reg(CC1100_MCSM1, 0x00); /* TX_OFFMODE = IDLE */ cc1100_spi_write_reg(CC1100_MCSM1, 0x00); /* TX_OFFMODE = IDLE */
ack.length = 3; /* possible packet in txBuffer! */ ack.length = 3; /* possible packet in txBuffer!*/
ack.address = dest; ack.address = dest;
ack.phy_src = rflags.RSSI; ack.phy_src = rflags.RSSI;
ack.flags = (LAYER_1_PROTOCOL_LL_ACK << 1); ack.flags = (LAYER_1_PROTOCOL_LL_ACK << 1);
@ -460,7 +460,7 @@ static bool send_burst(cc1100_packet_layer0_t *packet, uint8_t retries, uint8_t
radio_state = RADIO_SEND_BURST; radio_state = RADIO_SEND_BURST;
rflags.LL_ACK = false; rflags.LL_ACK = false;
for(i = 1; i <= cc1100_burst_count; i++) { for (i = 1; i <= cc1100_burst_count; i++) {
/* /*
* Number of bytes to send is: * Number of bytes to send is:
* length of phy payload (packet->length) * length of phy payload (packet->length)
@ -475,7 +475,7 @@ static bool send_burst(cc1100_packet_layer0_t *packet, uint8_t retries, uint8_t
/* Delay until predefined "send" interval has passed */ /* Delay until predefined "send" interval has passed */
timer_tick_t now = hwtimer_now(); timer_tick_t now = hwtimer_now();
if(t > now) { if (t > now) {
hwtimer_wait(t - now); hwtimer_wait(t - now);
} }
@ -486,7 +486,7 @@ static bool send_burst(cc1100_packet_layer0_t *packet, uint8_t retries, uint8_t
* have the broadcast address at startup and would stop the burst * have the broadcast address at startup and would stop the burst
* by sending an ACK). * by sending an ACK).
*/ */
if(rflags.LL_ACK && packet->address != CC1100_BROADCAST_ADDRESS) { if (rflags.LL_ACK && packet->address != CC1100_BROADCAST_ADDRESS) {
cc1100_statistic.raw_packets_out_acked += i; cc1100_statistic.raw_packets_out_acked += i;
break; break;
} }
@ -496,7 +496,7 @@ static bool send_burst(cc1100_packet_layer0_t *packet, uint8_t retries, uint8_t
* Note: Event broadcast packets can be sent repeatedly if in * Note: Event broadcast packets can be sent repeatedly if in
* constant RX mode. In WOR mode it is not necessary, so * constant RX mode. In WOR mode it is not necessary, so
* set retry count to zero.*/ * set retry count to zero.*/
if(!rflags.LL_ACK && retries > 0) { if (!rflags.LL_ACK && retries > 0) {
return send_burst(packet, retries - 1, rtc + 1); return send_burst(packet, retries - 1, rtc + 1);
} }
@ -504,7 +504,7 @@ static bool send_burst(cc1100_packet_layer0_t *packet, uint8_t retries, uint8_t
rflags.RETC = rtc; rflags.RETC = rtc;
rflags.RPS = rtc * cc1100_burst_count + i; rflags.RPS = rtc * cc1100_burst_count + i;
if(i > cc1100_burst_count) { if (i > cc1100_burst_count) {
rflags.RPS--; rflags.RPS--;
} }
@ -516,7 +516,7 @@ static bool send_burst(cc1100_packet_layer0_t *packet, uint8_t retries, uint8_t
/* Burst from any other node is definitely over */ /* Burst from any other node is definitely over */
last_seq_num = 0; last_seq_num = 0;
if(packet->address != CC1100_BROADCAST_ADDRESS && !rflags.LL_ACK) { if (packet->address != CC1100_BROADCAST_ADDRESS && !rflags.LL_ACK) {
return false; return false;
} }
@ -543,24 +543,24 @@ int cc1100_send(radio_address_t addr, protocol_t protocol, int priority, char *p
address = addr; address = addr;
/* Loopback not supported */ /* Loopback not supported */
if(address == cc1100_get_address()) { if (address == cc1100_get_address()) {
return_code = RADIO_ADDR_OUT_OF_RANGE; return_code = RADIO_ADDR_OUT_OF_RANGE;
goto mode_before_final; goto mode_before_final;
} }
/* Check address */ /* Check address */
if(address > MAX_UID) { if (address > MAX_UID) {
return_code = RADIO_ADDR_OUT_OF_RANGE; return_code = RADIO_ADDR_OUT_OF_RANGE;
goto mode_before_final; goto mode_before_final;
} }
/* Packet too long */ /* Packet too long */
if(payload_len > MAX_DATA_LENGTH) { if (payload_len > MAX_DATA_LENGTH) {
return_code = RADIO_PAYLOAD_TOO_LONG; return_code = RADIO_PAYLOAD_TOO_LONG;
goto mode_before_final; goto mode_before_final;
} }
if(radio_state == RADIO_PWD) { if (radio_state == RADIO_PWD) {
return_code = RADIO_WRONG_MODE; return_code = RADIO_WRONG_MODE;
goto mode_before_final; goto mode_before_final;
} }
@ -591,10 +591,10 @@ int cc1100_send(radio_address_t addr, protocol_t protocol, int priority, char *p
return_code = result ? payload_len : RADIO_OP_FAILED; return_code = result ? payload_len : RADIO_OP_FAILED;
/* Collect statistics */ /* Collect statistics */
if(address != CC1100_BROADCAST_ADDRESS) { if (address != CC1100_BROADCAST_ADDRESS) {
cc1100_statistic.packets_out++; cc1100_statistic.packets_out++;
if(result) { if (result) {
cc1100_statistic.packets_out_acked++; cc1100_statistic.packets_out_acked++;
} }
} }
@ -627,7 +627,7 @@ bool cc1100_set_packet_monitor(packet_monitor_t monitor)
int cc1100_set_packet_handler(protocol_t protocol, packet_handler_t handler) int cc1100_set_packet_handler(protocol_t protocol, packet_handler_t handler)
{ {
if(protocol > 7) { if (protocol > 7) {
return -1; /* Only 3-bit value allowed */ return -1; /* Only 3-bit value allowed */
} }
@ -638,27 +638,27 @@ static void cc1100_event_handler_function(void)
{ {
msg_t m; msg_t m;
while(1) { while (1) {
if(cc1100_watch_dog_period.microseconds != 0) { if (cc1100_watch_dog_period.microseconds != 0) {
vtimer_remove(&cc1100_watch_dog); vtimer_remove(&cc1100_watch_dog);
} }
/* Test if any resource error has occurred */ /* Test if any resource error has occurred */
if(rflags.KT_RES_ERR) { if (rflags.KT_RES_ERR) {
rflags.KT_RES_ERR = false; rflags.KT_RES_ERR = false;
/* possibly do something, e.g. log error condition */ /* possibly do something, e.g. log error condition */
} }
if(m.type == MSG_TIMER) { if (m.type == MSG_TIMER) {
uint8_t state; uint8_t state;
if(radio_mode == CC1100_MODE_CONSTANT_RX) { if (radio_mode == CC1100_MODE_CONSTANT_RX) {
state = cc1100_spi_read_status(CC1100_MARCSTATE) & MARC_STATE; state = cc1100_spi_read_status(CC1100_MARCSTATE) & MARC_STATE;
if((state < 13 || state > 15) && radio_state == RADIO_RX && !rflags.TX) { if ((state < 13 || state > 15) && radio_state == RADIO_RX && !rflags.TX) {
cc1100_statistic.watch_dog_resets++; cc1100_statistic.watch_dog_resets++;
if(state != 1) { if (state != 1) {
cc1100_spi_strobe(CC1100_SIDLE); cc1100_spi_strobe(CC1100_SIDLE);
} }
@ -672,11 +672,11 @@ static void cc1100_event_handler_function(void)
} }
} }
while(rx_buffer_size > 0) { while (rx_buffer_size > 0) {
rx_buffer_t *packet = &rx_buffer[rx_buffer_head]; rx_buffer_t *packet = &rx_buffer[rx_buffer_head];
protocol_t p = R_FLAGS_PROTOCOL(packet->packet.flags); protocol_t p = R_FLAGS_PROTOCOL(packet->packet.flags);
if(packet_monitor != NULL) { if (packet_monitor != NULL) {
packet_monitor((void *)&packet->packet.data, packet->packet.length, p, &packet->info); packet_monitor((void *)&packet->packet.data, packet->packet.length, p, &packet->info);
} }
@ -685,7 +685,7 @@ static void cc1100_event_handler_function(void)
rx_buffer_size--; rx_buffer_size--;
rx_buffer_head++; rx_buffer_head++;
if(rx_buffer_head == RX_BUFF_SIZE) { if (rx_buffer_head == RX_BUFF_SIZE) {
rx_buffer_head = 0; rx_buffer_head = 0;
} }
@ -694,8 +694,8 @@ static void cc1100_event_handler_function(void)
dINT(); dINT();
if(rx_buffer_size == 0) { if (rx_buffer_size == 0) {
if(cc1100_watch_dog_period.microseconds != 0) { if (cc1100_watch_dog_period.microseconds != 0) {
timex_t temp = timex_set(0, cc1100_watch_dog_period.microseconds * 1000000L); timex_t temp = timex_set(0, cc1100_watch_dog_period.microseconds * 1000000L);
vtimer_set_msg(&cc1100_watch_dog, temp, vtimer_set_msg(&cc1100_watch_dog, temp,
cc1100_event_handler_pid, NULL); cc1100_event_handler_pid, NULL);
@ -725,7 +725,7 @@ void cc1100_phy_rx_handler(void)
cc1100_statistic.packets_in++; cc1100_statistic.packets_in++;
/* If WOR timer set, delete it now (new one will be set at end of ISR) */ /* If WOR timer set, delete it now (new one will be set at end of ISR) */
if(wor_hwtimer_id != -1) { if (wor_hwtimer_id != -1) {
hwtimer_remove(wor_hwtimer_id); hwtimer_remove(wor_hwtimer_id);
wor_hwtimer_id = -1; wor_hwtimer_id = -1;
} }
@ -733,7 +733,7 @@ void cc1100_phy_rx_handler(void)
/* Transfer packet into temporary buffer position */ /* Transfer packet into temporary buffer position */
res = cc1100_spi_receive_packet((uint8_t *) & (rx_buffer[rx_buffer_tail].packet), sizeof(cc1100_packet_layer0_t)); res = cc1100_spi_receive_packet((uint8_t *) & (rx_buffer[rx_buffer_tail].packet), sizeof(cc1100_packet_layer0_t));
if(res) { if (res) {
/* Get packet pointer and store additional data in packet info structure */ /* Get packet pointer and store additional data in packet info structure */
cc1100_packet_layer0_t *p = &(rx_buffer[rx_buffer_tail].packet); cc1100_packet_layer0_t *p = &(rx_buffer[rx_buffer_tail].packet);
rx_buffer[rx_buffer_tail].info.phy_src = p->phy_src; rx_buffer[rx_buffer_tail].info.phy_src = p->phy_src;
@ -749,9 +749,9 @@ void cc1100_phy_rx_handler(void)
/* If received packet was an ACK (here we must be in /* If received packet was an ACK (here we must be in
* TX lock state, otherwise we don't expect an ACK) */ * TX lock state, otherwise we don't expect an ACK) */
if(protocol == LAYER_1_PROTOCOL_LL_ACK && rflags.TX) { if (protocol == LAYER_1_PROTOCOL_LL_ACK && rflags.TX) {
/* And packet was for us */ /* And packet was for us */
if(p->address == cc1100_get_address()) { if (p->address == cc1100_get_address()) {
/* Stop the burst */ /* Stop the burst */
rflags.LL_ACK = true; rflags.LL_ACK = true;
rflags.RSSI_SEND = p->phy_src; rflags.RSSI_SEND = p->phy_src;
@ -768,14 +768,14 @@ void cc1100_phy_rx_handler(void)
/* If we are sending a burst, don't accept packets. /* If we are sending a burst, don't accept packets.
* Only ACKs are processed (for stopping the burst). * Only ACKs are processed (for stopping the burst).
* Same if state machine is in TX lock. */ * Same if state machine is in TX lock. */
if(radio_state == RADIO_SEND_BURST || rflags.TX) { if (radio_state == RADIO_SEND_BURST || rflags.TX) {
cc1100_statistic.packets_in_while_tx++; cc1100_statistic.packets_in_while_tx++;
return; return;
} }
/* If buffer is currently full -> don't check sequence numbers, send /* If buffer is currently full -> don't check sequence numbers, send
* ACK and restore state (keep always one position free for temporary packets) */ * ACK and restore state (keep always one position free for temporary packets) */
if(rx_buffer_size >= RX_BUFF_SIZE - 1) { if (rx_buffer_size >= RX_BUFF_SIZE - 1) {
goto send_ack; goto send_ack;
} }
@ -788,9 +788,9 @@ void cc1100_phy_rx_handler(void)
dup = true; dup = true;
/* If new and last sequence number are the same, then discard packet */ /* If new and last sequence number are the same, then discard packet */
if(last_seq_num != new_seq_num) { if (last_seq_num != new_seq_num) {
/* Do a more precise check (takes more time) with larger buffer */ /* Do a more precise check (takes more time) with larger buffer */
if(!contains_seq_entry(p->phy_src, identification)) { if (!contains_seq_entry(p->phy_src, identification)) {
/* Sequence number is new, no duplicate packet */ /* Sequence number is new, no duplicate packet */
dup = false; dup = false;
@ -800,13 +800,13 @@ void cc1100_phy_rx_handler(void)
/* Make temporary packet in RX buffer to a "real" packet which is processed */ /* Make temporary packet in RX buffer to a "real" packet which is processed */
rx_buffer_size++; rx_buffer_size++;
if(rx_buffer_size > cc1100_statistic.rx_buffer_max) { if (rx_buffer_size > cc1100_statistic.rx_buffer_max) {
cc1100_statistic.rx_buffer_max = rx_buffer_size; cc1100_statistic.rx_buffer_max = rx_buffer_size;
} }
rx_buffer_tail++; rx_buffer_tail++;
if(rx_buffer_tail == RX_BUFF_SIZE) { if (rx_buffer_tail == RX_BUFF_SIZE) {
rx_buffer_tail = 0; rx_buffer_tail = 0;
} }
@ -822,8 +822,8 @@ void cc1100_phy_rx_handler(void)
send_ack: send_ack:
/* If packet was send directly to us, send an ACK packet back to sender. /* If packet was send directly to us, send an ACK packet back to sender.
* But only not if the packet itself was a LL-ACK! */ * But only not if the packet itself was a LL-ACK!*/
if(p->address == cc1100_get_address() && protocol != LAYER_1_PROTOCOL_LL_ACK) { if (p->address == cc1100_get_address() && protocol != LAYER_1_PROTOCOL_LL_ACK) {
send_link_level_ack(p->phy_src); send_link_level_ack(p->phy_src);
/* After LL-ACK burst is over, reset number */ /* After LL-ACK burst is over, reset number */
@ -831,13 +831,13 @@ void cc1100_phy_rx_handler(void)
} }
/* If duplicate packet detected, clear rxBuffer position */ /* If duplicate packet detected, clear rxBuffer position */
if(dup) { if (dup) {
cc1100_statistic.packets_in_dups++; cc1100_statistic.packets_in_dups++;
} }
/* If packet interrupted this nodes send call, /* If packet interrupted this nodes send call,
* don't change anything after this point. */ * don't change anything after this point. */
if(radio_state == RADIO_AIR_FREE_WAITING) { if (radio_state == RADIO_AIR_FREE_WAITING) {
cc1100_spi_strobe(CC1100_SRX); cc1100_spi_strobe(CC1100_SRX);
hwtimer_wait(IDLE_TO_RX_TIME); hwtimer_wait(IDLE_TO_RX_TIME);
return; return;
@ -849,7 +849,7 @@ void cc1100_phy_rx_handler(void)
cc1100_spi_write_reg(CC1100_MCSM0, 0x08); * Turn off FS-Autocal cc1100_spi_write_reg(CC1100_MCSM0, 0x08); * Turn off FS-Autocal
cc1100_spi_write_reg(CC1100_MCSM2, 0x07); /* Configure RX_TIME (until end of packet) */ cc1100_spi_write_reg(CC1100_MCSM2, 0x07); /* Configure RX_TIME (until end of packet) */
if(radio_mode == CC1100_MODE_CONSTANT_RX) { if (radio_mode == CC1100_MODE_CONSTANT_RX) {
cc1100_spi_strobe(CC1100_SRX); cc1100_spi_strobe(CC1100_SRX);
hwtimer_wait(IDLE_TO_RX_TIME); hwtimer_wait(IDLE_TO_RX_TIME);
radio_state = RADIO_RX; radio_state = RADIO_RX;
@ -864,7 +864,7 @@ void cc1100_phy_rx_handler(void)
/* Set hwtimer to put CC1100 back to RX after WOR_TIMEOUT_1 */ /* Set hwtimer to put CC1100 back to RX after WOR_TIMEOUT_1 */
wor_hwtimer_id = hwtimer_set(WOR_TIMEOUT_1, cc1100_hwtimer_go_receive_wrapper, NULL); wor_hwtimer_id = hwtimer_set(WOR_TIMEOUT_1, cc1100_hwtimer_go_receive_wrapper, NULL);
if(wor_hwtimer_id == -1) { if (wor_hwtimer_id == -1) {
/* Signal hwtimer resource error, radio stays in RX, /* Signal hwtimer resource error, radio stays in RX,
* so no big problem, only energy is wasted. */ * so no big problem, only energy is wasted. */
rflags.KT_RES_ERR = true; rflags.KT_RES_ERR = true;
@ -881,14 +881,14 @@ void cc1100_phy_rx_handler(void)
/* If packet interrupted this nodes send call, /* If packet interrupted this nodes send call,
* don't change anything after this point. */ * don't change anything after this point. */
if(radio_state == RADIO_AIR_FREE_WAITING) { if (radio_state == RADIO_AIR_FREE_WAITING) {
cc1100_spi_strobe(CC1100_SRX); cc1100_spi_strobe(CC1100_SRX);
hwtimer_wait(IDLE_TO_RX_TIME); hwtimer_wait(IDLE_TO_RX_TIME);
return; return;
} }
/* If currently sending, exit here (don't go to RX/WOR) */ /* If currently sending, exit here (don't go to RX/WOR) */
if(radio_state == RADIO_SEND_BURST) { if (radio_state == RADIO_SEND_BURST) {
cc1100_statistic.packets_in_while_tx++; cc1100_statistic.packets_in_while_tx++;
return; return;
} }

View File

@ -64,7 +64,7 @@ cc1100_spi_writeburst_reg(uint8_t addr, char *src, uint8_t count)
cc110x_spi_select(); cc110x_spi_select();
cc110x_txrx(addr | CC1100_WRITE_BURST); cc110x_txrx(addr | CC1100_WRITE_BURST);
while(i < count) { while (i < count) {
cc110x_txrx(src[i]); cc110x_txrx(src[i]);
i++; i++;
} }
@ -82,7 +82,7 @@ cc1100_spi_readburst_reg(uint8_t addr, char *buffer, uint8_t count)
cc110x_spi_select(); cc110x_spi_select();
cc110x_txrx(addr | CC1100_READ_BURST); cc110x_txrx(addr | CC1100_READ_BURST);
while(i < count) { while (i < count) {
buffer[i] = cc110x_txrx(NOBYTE); buffer[i] = cc110x_txrx(NOBYTE);
i++; i++;
} }

View File

@ -55,11 +55,11 @@ void cc110x_rx_handler(void)
res = receive_packet((uint8_t *)&(cc110x_rx_buffer[rx_buffer_next].packet), sizeof(cc110x_packet_t)); res = receive_packet((uint8_t *)&(cc110x_rx_buffer[rx_buffer_next].packet), sizeof(cc110x_packet_t));
if(res) { if (res) {
/* If we are sending a burst, don't accept packets. /* If we are sending a burst, don't accept packets.
* Only ACKs are processed (for stopping the burst). * Only ACKs are processed (for stopping the burst).
* Same if state machine is in TX lock. */ * Same if state machine is in TX lock. */
if(radio_state == RADIO_SEND_BURST || rflags.TX) { if (radio_state == RADIO_SEND_BURST || rflags.TX) {
cc110x_statistic.packets_in_while_tx++; cc110x_statistic.packets_in_while_tx++;
return; return;
} }
@ -79,7 +79,7 @@ void cc110x_rx_handler(void)
#ifdef DBG_IGNORE #ifdef DBG_IGNORE
if(is_ignored(cc110x_rx_buffer[rx_buffer_next].packet.phy_src)) { if (is_ignored(cc110x_rx_buffer[rx_buffer_next].packet.phy_src)) {
LED_RED_TOGGLE; LED_RED_TOGGLE;
return; return;
} }
@ -87,7 +87,7 @@ void cc110x_rx_handler(void)
#endif #endif
/* notify transceiver thread if any */ /* notify transceiver thread if any */
if(transceiver_pid) { if (transceiver_pid) {
msg_t m; msg_t m;
m.type = (uint16_t) RCV_PKT_CC1100; m.type = (uint16_t) RCV_PKT_CC1100;
m.content.value = rx_buffer_next; m.content.value = rx_buffer_next;
@ -95,7 +95,7 @@ void cc110x_rx_handler(void)
} }
/* shift to next buffer element */ /* shift to next buffer element */
if(++rx_buffer_next == RX_BUF_SIZE) { if (++rx_buffer_next == RX_BUF_SIZE) {
rx_buffer_next = 0; rx_buffer_next = 0;
} }
@ -111,14 +111,14 @@ void cc110x_rx_handler(void)
/* If packet interrupted this nodes send call, /* If packet interrupted this nodes send call,
* don't change anything after this point. */ * don't change anything after this point. */
if(radio_state == RADIO_AIR_FREE_WAITING) { if (radio_state == RADIO_AIR_FREE_WAITING) {
cc110x_strobe(CC1100_SRX); cc110x_strobe(CC1100_SRX);
hwtimer_wait(IDLE_TO_RX_TIME); hwtimer_wait(IDLE_TO_RX_TIME);
return; return;
} }
/* If currently sending, exit here (don't go to RX/WOR) */ /* If currently sending, exit here (don't go to RX/WOR) */
if(radio_state == RADIO_SEND_BURST) { if (radio_state == RADIO_SEND_BURST) {
cc110x_statistic.packets_in_while_tx++; cc110x_statistic.packets_in_while_tx++;
return; return;
} }
@ -135,12 +135,12 @@ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length)
uint8_t packetLength = 0; uint8_t packetLength = 0;
/* Any bytes available in RX FIFO? */ /* Any bytes available in RX FIFO? */
if((cc110x_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) { if ((cc110x_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) {
/* Read length byte (first byte in RX FIFO) */ /* Read length byte (first byte in RX FIFO) */
cc110x_read_fifo((char *) &packetLength, 1); cc110x_read_fifo((char *) &packetLength, 1);
/* Read data from RX FIFO and store in rxBuffer */ /* Read data from RX FIFO and store in rxBuffer */
if(packetLength <= length) { if (packetLength <= length) {
/* Put length byte at first position in RX Buffer */ /* Put length byte at first position in RX Buffer */
rxBuffer[0] = packetLength; rxBuffer[0] = packetLength;
@ -157,7 +157,7 @@ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length)
/* MSB of LQI is the CRC_OK bit */ /* MSB of LQI is the CRC_OK bit */
rflags.CRC_STATE = (status[I_LQI] & CRC_OK) >> 7; rflags.CRC_STATE = (status[I_LQI] & CRC_OK) >> 7;
if(!rflags.CRC_STATE) { if (!rflags.CRC_STATE) {
cc110x_statistic.packets_in_crc_fail++; cc110x_statistic.packets_in_crc_fail++;
} }
@ -183,7 +183,7 @@ static uint8_t receive_packet(uint8_t *rxBuffer, uint8_t length)
{ {
uint8_t pkt_len_cfg = cc110x_read_reg(CC1100_PKTCTRL0) & PKT_LENGTH_CONFIG; uint8_t pkt_len_cfg = cc110x_read_reg(CC1100_PKTCTRL0) & PKT_LENGTH_CONFIG;
if(pkt_len_cfg == VARIABLE_PKTLEN) { if (pkt_len_cfg == VARIABLE_PKTLEN) {
return receive_packet_variable(rxBuffer, length); return receive_packet_variable(rxBuffer, length);
} }
@ -202,11 +202,11 @@ uint8_t cc110x_add_ignored(radio_address_t addr)
{ {
uint8_t i = 0; uint8_t i = 0;
while((i < IGN_MAX) && ignored_addr[i++]) { while ((i < IGN_MAX) && ignored_addr[i++]) {
printf("i: %hu\n", i); printf("i: %hu\n", i);
} }
if(i > IGN_MAX) { if (i > IGN_MAX) {
return 0; return 0;
} }
@ -218,8 +218,8 @@ static uint8_t is_ignored(radio_address_t addr)
{ {
uint8_t i; uint8_t i;
for(i = 0; i < IGN_MAX; i++) { for (i = 0; i < IGN_MAX; i++) {
if(ignored_addr[i] == addr) { if (ignored_addr[i] == addr) {
return 1; return 1;
} }
} }

View File

@ -47,7 +47,7 @@ uint8_t cc110x_send(cc110x_packet_t *packet)
* or equal to PACKET_LENGTH (62 bytes). So the receiver * or equal to PACKET_LENGTH (62 bytes). So the receiver
* can put the whole packet in its RX-FIFO (with appended * can put the whole packet in its RX-FIFO (with appended
* packet status bytes).*/ * packet status bytes).*/
if(size > PACKET_LENGTH) { if (size > PACKET_LENGTH) {
return 0; return 0;
} }
@ -68,10 +68,10 @@ uint8_t cc110x_send(cc110x_packet_t *packet)
cc110x_strobe(CC1100_STX); cc110x_strobe(CC1100_STX);
/* Wait for GDO2 to be set -> sync word transmitted */ /* Wait for GDO2 to be set -> sync word transmitted */
while(cc110x_get_gdo2() == 0) { while (cc110x_get_gdo2() == 0) {
abort_count++; abort_count++;
if(abort_count > CC1100_SYNC_WORD_TX_TIME) { if (abort_count > CC1100_SYNC_WORD_TX_TIME) {
/* Abort waiting. CC1100 maybe in wrong mode */ /* Abort waiting. CC1100 maybe in wrong mode */
/* e.g. sending preambles for always */ /* e.g. sending preambles for always */
puts("[CC1100 TX] fatal error\n"); puts("[CC1100 TX] fatal error\n");
@ -82,7 +82,7 @@ uint8_t cc110x_send(cc110x_packet_t *packet)
restoreIRQ(cpsr); restoreIRQ(cpsr);
/* Wait for GDO2 to be cleared -> end of packet */ /* Wait for GDO2 to be cleared -> end of packet */
while(cc110x_get_gdo2() != 0); while (cc110x_get_gdo2() != 0);
/* Experimental - TOF Measurement */ /* Experimental - TOF Measurement */

View File

@ -132,13 +132,13 @@ radio_address_t cc110x_get_address()
radio_address_t cc110x_set_address(radio_address_t address) radio_address_t cc110x_set_address(radio_address_t address)
{ {
if((address < MIN_UID) || (address > MAX_UID)) { if ((address < MIN_UID) || (address > MAX_UID)) {
return 0; return 0;
} }
uint8_t id = (uint8_t) address; uint8_t id = (uint8_t) address;
if(radio_state != RADIO_UNKNOWN) { if (radio_state != RADIO_UNKNOWN) {
write_register(CC1100_ADDR, id); write_register(CC1100_ADDR, id);
} }
@ -151,7 +151,7 @@ radio_address_t cc110x_set_config_address(radio_address_t address)
{ {
radio_address_t a = cc110x_set_address(address); radio_address_t a = cc110x_set_address(address);
if(a) { if (a) {
sysconfig.radio_address = a; sysconfig.radio_address = a;
} }
@ -162,7 +162,7 @@ radio_address_t cc110x_set_config_address(radio_address_t address)
void cc110x_set_monitor(uint8_t mode) void cc110x_set_monitor(uint8_t mode)
{ {
if(mode) { if (mode) {
write_register(CC1100_PKTCTRL1, (0x04)); write_register(CC1100_PKTCTRL1, (0x04));
} }
else { else {
@ -185,7 +185,7 @@ void cc110x_switch_to_rx(void)
void cc110x_wakeup_from_rx(void) void cc110x_wakeup_from_rx(void)
{ {
if(radio_state != RADIO_RX) { if (radio_state != RADIO_RX) {
return; return;
} }
@ -210,7 +210,7 @@ char *cc110x_get_marc_state(void)
/* Have to put radio back to WOR/RX if old radio state /* Have to put radio back to WOR/RX if old radio state
* was WOR/RX, otherwise no action is necessary */ * was WOR/RX, otherwise no action is necessary */
if(old_state == RADIO_WOR || old_state == RADIO_RX) { if (old_state == RADIO_WOR || old_state == RADIO_RX) {
cc110x_switch_to_rx(); cc110x_switch_to_rx();
} }
@ -320,7 +320,7 @@ int16_t cc110x_set_channel(uint8_t channr)
{ {
uint8_t state = cc110x_read_status(CC1100_MARCSTATE) & MARC_STATE; uint8_t state = cc110x_read_status(CC1100_MARCSTATE) & MARC_STATE;
if((state != 1) && (channr > MAX_CHANNR)) { if ((state != 1) && (channr > MAX_CHANNR)) {
return -1; return -1;
} }
@ -334,7 +334,7 @@ int16_t cc110x_set_config_channel(uint8_t channr)
{ {
int16_t c = cc110x_set_channel(channr); int16_t c = cc110x_set_channel(channr);
if(c) { if (c) {
sysconfig.radio_channel = c; sysconfig.radio_channel = c;
} }
@ -386,7 +386,7 @@ static void write_register(uint8_t r, uint8_t value)
/* Have to put radio back to WOR/RX if old radio state /* Have to put radio back to WOR/RX if old radio state
* was WOR/RX, otherwise no action is necessary */ * was WOR/RX, otherwise no action is necessary */
if((old_state == RADIO_WOR) || (old_state == RADIO_RX)) { if ((old_state == RADIO_WOR) || (old_state == RADIO_RX)) {
cc110x_switch_to_rx(); cc110x_switch_to_rx();
} }
} }
@ -396,7 +396,7 @@ static int rd_set_mode(int mode)
int result; int result;
/* Get current radio mode */ /* Get current radio mode */
if((radio_state == RADIO_UNKNOWN) || (radio_state == RADIO_PWD)) { if ((radio_state == RADIO_UNKNOWN) || (radio_state == RADIO_PWD)) {
result = RADIO_MODE_OFF; result = RADIO_MODE_OFF;
} }
else { else {

View File

@ -65,7 +65,7 @@ uint8_t cc110x_writeburst_reg(uint8_t addr, char *src, uint8_t count)
cc110x_spi_select(); cc110x_spi_select();
cc110x_txrx(addr | CC1100_WRITE_BURST); cc110x_txrx(addr | CC1100_WRITE_BURST);
while(i < count) { while (i < count) {
cc110x_txrx(src[i]); cc110x_txrx(src[i]);
i++; i++;
} }
@ -82,7 +82,7 @@ void cc110x_readburst_reg(uint8_t addr, char *buffer, uint8_t count)
cc110x_spi_select(); cc110x_spi_select();
cc110x_txrx(addr | CC1100_READ_BURST); cc110x_txrx(addr | CC1100_READ_BURST);
while(i < count) { while (i < count) {
buffer[i] = cc110x_txrx(NOBYTE); buffer[i] = cc110x_txrx(NOBYTE);
i++; i++;
} }

View File

@ -121,7 +121,7 @@ void __attribute__((__no_instrument_function__)) ltc4150_interrupt(void)
{ {
uint32_t now = hwtimer_now(); uint32_t now = hwtimer_now();
if(now >= last_int_time) { if (now >= last_int_time) {
last_int_duration = now - last_int_time; last_int_duration = now - last_int_time;
} }
else { else {

View File

@ -116,8 +116,8 @@ static uint8_t write_byte(uint8_t value)
SHT11_DATA_OUT; SHT11_DATA_OUT;
/* send value bit by bit to sht11 */ /* send value bit by bit to sht11 */
for(i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
if(value & BIT7) { if (value & BIT7) {
SHT11_DATA_HIGH; SHT11_DATA_HIGH;
hwtimer_wait(SHT11_DATA_WAIT); hwtimer_wait(SHT11_DATA_WAIT);
} }
@ -152,12 +152,12 @@ static uint8_t read_byte(uint8_t ack)
hwtimer_wait(SHT11_DATA_WAIT); hwtimer_wait(SHT11_DATA_WAIT);
/* read value bit by bit */ /* read value bit by bit */
for(i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
value = value << 1; value = value << 1;
SHT11_SCK_HIGH; SHT11_SCK_HIGH;
hwtimer_wait(SHT11_CLK_WAIT); hwtimer_wait(SHT11_CLK_WAIT);
if(SHT11_DATA) { if (SHT11_DATA) {
/* increase data by one when DATA is high */ /* increase data by one when DATA is high */
value++; value++;
} }
@ -169,7 +169,7 @@ static uint8_t read_byte(uint8_t ack)
/* send ack if necessary */ /* send ack if necessary */
SHT11_DATA_OUT; SHT11_DATA_OUT;
if(ack) { if (ack) {
SHT11_DATA_LOW; SHT11_DATA_LOW;
hwtimer_wait(SHT11_DATA_WAIT); hwtimer_wait(SHT11_DATA_WAIT);
} }
@ -233,7 +233,7 @@ static void connection_reset(void)
SHT11_SCK_LOW; SHT11_SCK_LOW;
hwtimer_wait(SHT11_CLK_WAIT); hwtimer_wait(SHT11_CLK_WAIT);
for(i = 0; i < 9; i++) { for (i = 0; i < 9; i++) {
clk_signal(); clk_signal();
} }
@ -252,10 +252,10 @@ static uint8_t measure(uint8_t *p_value, uint8_t *p_checksum, uint8_t mode)
hwtimer_wait(HWTIMER_TICKS(1000)); hwtimer_wait(HWTIMER_TICKS(1000));
/* wait untile sensor has finished measurement or timeout */ /* wait untile sensor has finished measurement or timeout */
for(i = 0; (i < SHT11_MEASURE_TIMEOUT) && (!error); i++) { for (i = 0; (i < SHT11_MEASURE_TIMEOUT) && (!error); i++) {
ack = SHT11_DATA; ack = SHT11_DATA;
if(!ack) { if (!ack) {
break; break;
} }
@ -326,7 +326,7 @@ uint8_t sht11_read_sensor(sht11_val_t *value, sht11_mode_t mode)
const float T2 = +0.00008; const float T2 = +0.00008;
/* check for valid buffer */ /* check for valid buffer */
if(value == NULL) { if (value == NULL) {
return 0; return 0;
} }
@ -338,30 +338,30 @@ uint8_t sht11_read_sensor(sht11_val_t *value, sht11_mode_t mode)
connection_reset(); connection_reset();
/* measure humidity */ /* measure humidity */
if(mode & HUMIDITY) { if (mode & HUMIDITY) {
error += (!measure((uint8_t *) &humi_int, &checksum, SHT11_MEASURE_HUMI)); error += (!measure((uint8_t *) &humi_int, &checksum, SHT11_MEASURE_HUMI));
} }
/* measure temperature */ /* measure temperature */
if(mode & TEMPERATURE) { if (mode & TEMPERATURE) {
error += (!measure((uint8_t *) &temp_int, &checksum, SHT11_MEASURE_TEMP)); error += (!measure((uint8_t *) &temp_int, &checksum, SHT11_MEASURE_TEMP));
} }
/* break on error */ /* break on error */
if(error != 0) { if (error != 0) {
connection_reset(); connection_reset();
mutex_unlock(&sht11_mutex, 0); mutex_unlock(&sht11_mutex, 0);
return 0; return 0;
} }
if(mode & TEMPERATURE) { if (mode & TEMPERATURE) {
value->temperature = D1 + (D2 * ((float) temp_int)) + sht11_temperature_offset; value->temperature = D1 + (D2 * ((float) temp_int)) + sht11_temperature_offset;
} }
if(mode & HUMIDITY) { if (mode & HUMIDITY) {
value->relhum = C1 + (C2 * ((float) humi_int)) + (C3 * ((float) humi_int) * ((float) humi_int)); value->relhum = C1 + (C2 * ((float) humi_int)) + (C3 * ((float) humi_int) * ((float) humi_int));
if(mode & TEMPERATURE) { if (mode & TEMPERATURE) {
value->relhum_temp = (value->temperature - 25) * (T1 + (T2 * (float) humi_int)) + value->relhum; value->relhum_temp = (value->temperature - 25) * (T1 + (T2 * (float) humi_int)) + value->relhum;
} }
} }

View File

@ -30,7 +30,7 @@
static int min(int a, int b) static int min(int a, int b)
{ {
if(b > a) { if (b > a) {
return a; return a;
} }
else { else {
@ -49,15 +49,15 @@ void chardev_loop(ringbuffer_t *rb)
puts("UART0 thread started."); puts("UART0 thread started.");
while(1) { while (1) {
msg_receive(&m); msg_receive(&m);
if(m.sender_pid != pid) { if (m.sender_pid != pid) {
DEBUG("Receiving message from another thread\n"); DEBUG("Receiving message from another thread\n");
switch(m.type) { switch(m.type) {
case OPEN: case OPEN:
if(reader_pid == -1) { if (reader_pid == -1) {
reader_pid = m.sender_pid; reader_pid = m.sender_pid;
/* no error */ /* no error */
m.content.value = 0; m.content.value = 0;
@ -70,7 +70,7 @@ void chardev_loop(ringbuffer_t *rb)
break; break;
case READ: case READ:
if(m.sender_pid != reader_pid) { if (m.sender_pid != reader_pid) {
m.content.value = -EINVAL; m.content.value = -EINVAL;
r = NULL; r = NULL;
msg_reply(&m, &m); msg_reply(&m, &m);
@ -82,7 +82,7 @@ void chardev_loop(ringbuffer_t *rb)
break; break;
case CLOSE: case CLOSE:
if(m.sender_pid == reader_pid) { if (m.sender_pid == reader_pid) {
DEBUG("uart0_thread: closing file from %i\n", reader_pid); DEBUG("uart0_thread: closing file from %i\n", reader_pid);
reader_pid = -1; reader_pid = -1;
r = NULL; r = NULL;
@ -101,7 +101,7 @@ void chardev_loop(ringbuffer_t *rb)
} }
} }
if(rb->avail && (r != NULL)) { if (rb->avail && (r != NULL)) {
int state = disableIRQ(); int state = disableIRQ();
int nbytes = min(r->nbytes, rb->avail); int nbytes = min(r->nbytes, rb->avail);
DEBUG("uart0_thread [%i]: sending %i bytes received from %i to pid %i\n", pid, nbytes, m.sender_pid, reader_pid); DEBUG("uart0_thread [%i]: sending %i bytes received from %i to pid %i\n", pid, nbytes, m.sender_pid, reader_pid);

View File

@ -6,7 +6,7 @@ unsigned long hash_string(unsigned char *str)
unsigned long hash = 5381; unsigned long hash = 5381;
int c; int c;
while((c = *str++)) { while ((c = *str++)) {
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
} }

View File

@ -35,13 +35,13 @@ create_hashtable(uint32_t minsize,
unsigned int pindex, size = primes[0]; unsigned int pindex, size = primes[0];
/* Check requested hashtable isn't too large */ /* Check requested hashtable isn't too large */
if(minsize > (1u << 30)) { if (minsize > (1u << 30)) {
return NULL; return NULL;
} }
/* Enforce size as prime */ /* Enforce size as prime */
for(pindex = 0; pindex < prime_table_length; pindex++) { for (pindex = 0; pindex < prime_table_length; pindex++) {
if(primes[pindex] > minsize) { if (primes[pindex] > minsize) {
size = primes[pindex]; size = primes[pindex];
break; break;
} }
@ -49,13 +49,13 @@ create_hashtable(uint32_t minsize,
h = (struct hashtable *)malloc(sizeof(struct hashtable)); h = (struct hashtable *)malloc(sizeof(struct hashtable));
if(NULL == h) { if (NULL == h) {
return NULL; /*oom*/ return NULL; /*oom*/
} }
h->table = (struct entry **)malloc(sizeof(struct entry *) * size); h->table = (struct entry **)malloc(sizeof(struct entry *) * size);
if(NULL == h->table) { if (NULL == h->table) {
free(h); /*oom*/ free(h); /*oom*/
return NULL; return NULL;
} }
@ -95,7 +95,7 @@ hashtable_expand(struct hashtable *h)
unsigned int newsize, i, index; unsigned int newsize, i, index;
/* Check we're not hitting max capacity */ /* Check we're not hitting max capacity */
if(h->primeindex == (prime_table_length - 1)) { if (h->primeindex == (prime_table_length - 1)) {
return 0; return 0;
} }
@ -103,13 +103,13 @@ hashtable_expand(struct hashtable *h)
newtable = (struct entry **)malloc(sizeof(struct entry *) * newsize); newtable = (struct entry **)malloc(sizeof(struct entry *) * newsize);
if(NULL != newtable) { if (NULL != newtable) {
memset(newtable, 0, newsize * sizeof(struct entry *)); memset(newtable, 0, newsize * sizeof(struct entry *));
/* This algorithm is not 'stable'. ie. it reverses the list /* This algorithm is not 'stable'. ie. it reverses the list
* when it transfers entries between the tables */ * when it transfers entries between the tables */
for(i = 0; i < h->tablelength; i++) { for (i = 0; i < h->tablelength; i++) {
while(NULL != (e = h->table[i])) { while (NULL != (e = h->table[i])) {
h->table[i] = e->next; h->table[i] = e->next;
index = indexFor(newsize, e->h); index = indexFor(newsize, e->h);
e->next = newtable[index]; e->next = newtable[index];
@ -125,7 +125,7 @@ hashtable_expand(struct hashtable *h)
newtable = (struct entry **) newtable = (struct entry **)
realloc(h->table, newsize * sizeof(struct entry *)); realloc(h->table, newsize * sizeof(struct entry *));
if(NULL == newtable) { if (NULL == newtable) {
(h->primeindex)--; (h->primeindex)--;
return 0; return 0;
} }
@ -133,11 +133,11 @@ hashtable_expand(struct hashtable *h)
h->table = newtable; h->table = newtable;
memset(newtable[h->tablelength], 0, newsize - h->tablelength); memset(newtable[h->tablelength], 0, newsize - h->tablelength);
for(i = 0; i < h->tablelength; i++) { for (i = 0; i < h->tablelength; i++) {
for(pE = &(newtable[i]), e = *pE; e != NULL; e = *pE) { for (pE = &(newtable[i]), e = *pE; e != NULL; e = *pE) {
index = indexFor(newsize, e->h); index = indexFor(newsize, e->h);
if(index == i) { if (index == i) {
pE = &(e->next); pE = &(e->next);
} }
else { else {
@ -169,7 +169,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v)
unsigned int index; unsigned int index;
struct entry *e; struct entry *e;
if(++(h->entrycount) > h->loadlimit) { if (++(h->entrycount) > h->loadlimit) {
/* Ignore the return value. If expand fails, we should /* Ignore the return value. If expand fails, we should
* still try cramming just this value into the existing table * still try cramming just this value into the existing table
* -- we may not have memory for a larger table, but one more * -- we may not have memory for a larger table, but one more
@ -179,7 +179,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v)
e = (struct entry *)malloc(sizeof(struct entry)); e = (struct entry *)malloc(sizeof(struct entry));
if(NULL == e) { if (NULL == e) {
--(h->entrycount); /*oom*/ --(h->entrycount); /*oom*/
return 0; return 0;
} }
@ -203,9 +203,9 @@ hashtable_search(struct hashtable *h, void *k)
index = indexFor(h->tablelength, hashvalue); index = indexFor(h->tablelength, hashvalue);
e = h->table[index]; e = h->table[index];
while(NULL != e) { while (NULL != e) {
/* Check hash value to short circuit heavier comparison */ /* Check hash value to short circuit heavier comparison */
if((hashvalue == e->h) && (h->eqfn(k, e->k))) { if ((hashvalue == e->h) && (h->eqfn(k, e->k))) {
return e->v; return e->v;
} }
@ -232,9 +232,9 @@ hashtable_remove(struct hashtable *h, void *k)
pE = &(h->table[index]); pE = &(h->table[index]);
e = *pE; e = *pE;
while(NULL != e) { while (NULL != e) {
/* Check hash value to short circuit heavier comparison */ /* Check hash value to short circuit heavier comparison */
if((hashvalue == e->h) && (h->eqfn(k, e->k))) { if ((hashvalue == e->h) && (h->eqfn(k, e->k))) {
*pE = e->next; *pE = e->next;
h->entrycount--; h->entrycount--;
v = e->v; v = e->v;
@ -259,11 +259,11 @@ hashtable_destroy(struct hashtable *h, int free_values)
struct entry *e, *f; struct entry *e, *f;
struct entry **table = h->table; struct entry **table = h->table;
if(free_values) { if (free_values) {
for(i = 0; i < h->tablelength; i++) { for (i = 0; i < h->tablelength; i++) {
e = table[i]; e = table[i];
while(NULL != e) { while (NULL != e) {
f = e; f = e;
e = e->next; e = e->next;
freekey(f->k); freekey(f->k);
@ -273,10 +273,10 @@ hashtable_destroy(struct hashtable *h, int free_values)
} }
} }
else { else {
for(i = 0; i < h->tablelength; i++) { for (i = 0; i < h->tablelength; i++) {
e = table[i]; e = table[i];
while(NULL != e) { while (NULL != e) {
f = e; f = e;
e = e->next; e = e->next;
freekey(f->k); freekey(f->k);

View File

@ -20,7 +20,7 @@ struct hashtable;
* *
* (initialise k and v to suitable values) * (initialise k and v to suitable values)
* *
* if (! hashtable_insert(h,k,v) ) * if (!hashtable_insert(h,k,v) )
* { exit(-1); } * { exit(-1); }
* *
* if (NULL == (found = hashtable_search(h,k) )) * if (NULL == (found = hashtable_search(h,k) ))

View File

@ -41,20 +41,20 @@ void ringbuffer_init(ringbuffer_t *rb, char *buffer, unsigned int bufsize)
void rb_add_elements(ringbuffer_t *rb, char *buf, int n) void rb_add_elements(ringbuffer_t *rb, char *buf, int n)
{ {
for(int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
rb_add_element(rb, buf[i]); rb_add_element(rb, buf[i]);
} }
} }
void rb_add_element(ringbuffer_t *rb, char c) void rb_add_element(ringbuffer_t *rb, char c)
{ {
if(rb->avail == rb->size) { if (rb->avail == rb->size) {
rb_get_element(rb); rb_get_element(rb);
} }
rb->buf[rb->end++] = c; rb->buf[rb->end++] = c;
if(rb->end >= rb->size) { if (rb->end >= rb->size) {
rb->end = 0; rb->end = 0;
} }
@ -63,7 +63,7 @@ void rb_add_element(ringbuffer_t *rb, char c)
int rb_get_element(ringbuffer_t *rb) int rb_get_element(ringbuffer_t *rb)
{ {
if(rb->avail == 0) { if (rb->avail == 0) {
return -1; return -1;
} }
@ -71,7 +71,7 @@ int rb_get_element(ringbuffer_t *rb)
int c = (char)rb->buf[rb->start++]; int c = (char)rb->buf[rb->start++];
if(rb->start >= rb->size) { if (rb->start >= rb->size) {
rb->start = 0; rb->start = 0;
} }
@ -82,7 +82,7 @@ int rb_get_elements(ringbuffer_t *rb, char *buf, int n)
{ {
int count = 0; int count = 0;
while(rb->avail && (count < n)) { while (rb->avail && (count < n)) {
buf[count++] = rb_get_element(rb); buf[count++] = rb_get_element(rb);
} }

View File

@ -52,7 +52,7 @@ static volatile bool echo_on = false;
static void close_file_handle(void) static void close_file_handle(void)
{ {
if(fh != NULL) { if (fh != NULL) {
fclose(fh); fclose(fh);
fh = NULL; fh = NULL;
} }
@ -60,9 +60,9 @@ static void close_file_handle(void)
static void write_to_file(char *str, int str_len) static void write_to_file(char *str, int str_len)
{ {
if(fh != NULL && str_len > 0) { if (fh != NULL && str_len > 0) {
if(fwrite(str, sizeof(char), str_len, fh) != str_len) { if (fwrite(str, sizeof(char), str_len, fh) != str_len) {
if(echo_on && logd_stack_size >= LOGD_STACK_SIZE_CONSOLE) { if (echo_on && logd_stack_size >= LOGD_STACK_SIZE_CONSOLE) {
printf("LOGD [WARN]: file write failed, closing file\n"); printf("LOGD [WARN]: file write failed, closing file\n");
} }
@ -70,8 +70,8 @@ static void write_to_file(char *str, int str_len)
return; return;
} }
if(fflush(fh) == EOF) { if (fflush(fh) == EOF) {
if(echo_on && logd_stack_size >= LOGD_STACK_SIZE_CONSOLE) { if (echo_on && logd_stack_size >= LOGD_STACK_SIZE_CONSOLE) {
printf("LOGD [WARN]: file write failed, closing file\n"); printf("LOGD [WARN]: file write failed, closing file\n");
} }
@ -82,8 +82,8 @@ static void write_to_file(char *str, int str_len)
else { else {
fh = fopen("/LOGD.LOG", "w"); fh = fopen("/LOGD.LOG", "w");
if(!fh) { if (!fh) {
if(echo_on && logd_stack_size >= LOGD_STACK_SIZE_CONSOLE) { if (echo_on && logd_stack_size >= LOGD_STACK_SIZE_CONSOLE) {
printf("LOGD [WARN]: file reopen failed, damn!\n"); printf("LOGD [WARN]: file reopen failed, damn!\n");
} }
} }
@ -99,16 +99,16 @@ static void logd_process(void)
log_queue_t *node; log_queue_t *node;
do { do {
if(!exit_flag) { if (!exit_flag) {
msg_receive(&m); msg_receive(&m);
} }
mutex_lock(&log_mutex); mutex_lock(&log_mutex);
while((node = (log_queue_t *) list_remove_head(&log_msg_queue)) != NULL) { while ((node = (log_queue_t *) list_remove_head(&log_msg_queue)) != NULL) {
write_to_file(node->str, node->str_len); write_to_file(node->str, node->str_len);
if(echo_on && logd_stack_size >= LOGD_STACK_SIZE_CONSOLE) { if (echo_on && logd_stack_size >= LOGD_STACK_SIZE_CONSOLE) {
printf("%s", node->str); printf("%s", node->str);
} }
@ -119,7 +119,7 @@ static void logd_process(void)
mutex_unlock(&log_mutex, 0); mutex_unlock(&log_mutex, 0);
} }
while(m.type != MSG_EXIT && !exit_flag); while (m.type != MSG_EXIT && !exit_flag);
/* Logging thread is terminating, close log file */ /* Logging thread is terminating, close log file */
close_file_handle(); close_file_handle();
@ -131,7 +131,7 @@ static void logd_init0(void)
{ {
fh = fopen("/LOGD.LOG", "w"); fh = fopen("/LOGD.LOG", "w");
if(!fh) { if (!fh) {
return; return;
} }
@ -156,11 +156,11 @@ bool logd_log(char *str, int str_len)
msg m; msg m;
/* Test if logd process was created */ /* Test if logd process was created */
if(log_pid == -1) { if (log_pid == -1) {
/* no logd created, because fopen() on log file failed. So try again */ /* no logd created, because fopen() on log file failed. So try again */
logd_init0(); logd_init0();
if(log_pid == -1) { if (log_pid == -1) {
/* Still errors opening log file, exit now */ /* Still errors opening log file, exit now */
return false; return false;
} }
@ -168,13 +168,13 @@ bool logd_log(char *str, int str_len)
log_queue_t *lq = malloc(sizeof(*lq)); log_queue_t *lq = malloc(sizeof(*lq));
if(lq == NULL) { if (lq == NULL) {
return false; return false;
} }
lq->str = malloc(sizeof(char) * str_len + 1); /* 1 byte for string termination char */ lq->str = malloc(sizeof(char) * str_len + 1); /* 1 byte for string termination char */
if(lq->str == NULL) { if (lq->str == NULL) {
free(lq); free(lq);
return false; return false;
} }
@ -196,7 +196,7 @@ void logd_exit(void)
msg m; msg m;
/* Test if logd process was created */ /* Test if logd process was created */
if(log_pid == -1) { if (log_pid == -1) {
return; return;
} }

View File

@ -15,119 +15,119 @@
/* /*
* Protocols (RFC 1700) * Protocols (RFC 1700)
*/ */
#define IPPROTO_IP 0 /* dummy for IP */ #define IPPROTO_IP (0) /* dummy for IP */
#define IPPROTO_HOPOPTS 0 /* IP6 hop-by-hop options */ #define IPPROTO_HOPOPTS (0) /* IP6 hop-by-hop options */
#define IPPROTO_ICMP 1 /* control message protocol */ #define IPPROTO_ICMP (1) /* control message protocol */
#define IPPROTO_IGMP 2 /* group mgmt protocol */ #define IPPROTO_IGMP (2) /* group mgmt protocol */
#define IPPROTO_GGP 3 /* gateway^2 (deprecated) */ #define IPPROTO_GGP (3) /* gateway^2 (deprecated) */
#define IPPROTO_IPV4 4 /* IPv4 encapsulation */ #define IPPROTO_IPV4 (4) /* IPv4 encapsulation */
#define IPPROTO_IPIP IPPROTO_IPV4 /* for compatibility */ #define IPPROTO_IPIP IPPROTO_IPV4 /* for compatibility */
#define IPPROTO_TCP 6 /* tcp */ #define IPPROTO_TCP (6) /* tcp */
#define IPPROTO_ST 7 /* Stream protocol II */ #define IPPROTO_ST (7) /* Stream protocol II */
#define IPPROTO_EGP 8 /* exterior gateway protocol */ #define IPPROTO_EGP (8) /* exterior gateway protocol */
#define IPPROTO_PIGP 9 /* private interior gateway */ #define IPPROTO_PIGP (9) /* private interior gateway */
#define IPPROTO_RCCMON 10 /* BBN RCC Monitoring */ #define IPPROTO_RCCMON (10) /* BBN RCC Monitoring */
#define IPPROTO_NVPII 11 /* network voice protocol*/ #define IPPROTO_NVPII (11) /* network voice protocol*/
#define IPPROTO_PUP 12 /* pup */ #define IPPROTO_PUP (12) /* pup */
#define IPPROTO_ARGUS 13 /* Argus */ #define IPPROTO_ARGUS (13) /* Argus */
#define IPPROTO_EMCON 14 /* EMCON */ #define IPPROTO_EMCON (14) /* EMCON */
#define IPPROTO_XNET 15 /* Cross Net Debugger */ #define IPPROTO_XNET (15) /* Cross Net Debugger */
#define IPPROTO_CHAOS 16 /* Chaos*/ #define IPPROTO_CHAOS (16) /* Chaos*/
#define IPPROTO_UDP 17 /* user datagram protocol */ #define IPPROTO_UDP (17) /* user datagram protocol */
#define IPPROTO_MUX 18 /* Multiplexing */ #define IPPROTO_MUX (18) /* Multiplexing */
#define IPPROTO_MEAS 19 /* DCN Measurement Subsystems */ #define IPPROTO_MEAS (19) /* DCN Measurement Subsystems */
#define IPPROTO_HMP 20 /* Host Monitoring */ #define IPPROTO_HMP (20) /* Host Monitoring */
#define IPPROTO_PRM 21 /* Packet Radio Measurement */ #define IPPROTO_PRM (21) /* Packet Radio Measurement */
#define IPPROTO_IDP 22 /* xns idp */ #define IPPROTO_IDP (22) /* xns idp */
#define IPPROTO_TRUNK1 23 /* Trunk-1 */ #define IPPROTO_TRUNK1 (23) /* Trunk-1 */
#define IPPROTO_TRUNK2 24 /* Trunk-2 */ #define IPPROTO_TRUNK2 (24) /* Trunk-2 */
#define IPPROTO_LEAF1 25 /* Leaf-1 */ #define IPPROTO_LEAF1 (25) /* Leaf-1 */
#define IPPROTO_LEAF2 26 /* Leaf-2 */ #define IPPROTO_LEAF2 (26) /* Leaf-2 */
#define IPPROTO_RDP 27 /* Reliable Data */ #define IPPROTO_RDP (27) /* Reliable Data */
#define IPPROTO_IRTP 28 /* Reliable Transaction */ #define IPPROTO_IRTP (28) /* Reliable Transaction */
#define IPPROTO_TP 29 /* tp-4 w/ class negotiation */ #define IPPROTO_TP (29) /* tp-4 w/ class negotiation */
#define IPPROTO_BLT 30 /* Bulk Data Transfer */ #define IPPROTO_BLT (30) /* Bulk Data Transfer */
#define IPPROTO_NSP 31 /* Network Services */ #define IPPROTO_NSP (31) /* Network Services */
#define IPPROTO_INP 32 /* Merit Internodal */ #define IPPROTO_INP (32) /* Merit Internodal */
#define IPPROTO_SEP 33 /* Sequential Exchange */ #define IPPROTO_SEP (33) /* Sequential Exchange */
#define IPPROTO_3PC 34 /* Third Party Connect */ #define IPPROTO_3PC (34) /* Third Party Connect */
#define IPPROTO_IDPR 35 /* InterDomain Policy Routing */ #define IPPROTO_IDPR (35) /* InterDomain Policy Routing */
#define IPPROTO_XTP 36 /* XTP */ #define IPPROTO_XTP (36) /* XTP */
#define IPPROTO_DDP 37 /* Datagram Delivery */ #define IPPROTO_DDP (37) /* Datagram Delivery */
#define IPPROTO_CMTP 38 /* Control Message Transport */ #define IPPROTO_CMTP (38) /* Control Message Transport */
#define IPPROTO_TPXX 39 /* TP++ Transport */ #define IPPROTO_TPXX (39) /* TP++ Transport */
#define IPPROTO_IL 40 /* IL transport protocol */ #define IPPROTO_IL (40) /* IL transport protocol */
#define IPPROTO_IPV6 41 /* IP6 header */ #define IPPROTO_IPV6 (41) /* IP6 header */
#define IPPROTO_SDRP 42 /* Source Demand Routing */ #define IPPROTO_SDRP (42) /* Source Demand Routing */
#define IPPROTO_ROUTING 43 /* IP6 routing header */ #define IPPROTO_ROUTING (43) /* IP6 routing header */
#define IPPROTO_FRAGMENT 44 /* IP6 fragmentation header */ #define IPPROTO_FRAGMENT (44) /* IP6 fragmentation header */
#define IPPROTO_IDRP 45 /* InterDomain Routing*/ #define IPPROTO_IDRP (45) /* InterDomain Routing*/
#define IPPROTO_RSVP 46 /* resource reservation */ #define IPPROTO_RSVP (46) /* resource reservation */
#define IPPROTO_GRE 47 /* General Routing Encap. */ #define IPPROTO_GRE (47) /* General Routing Encap. */
#define IPPROTO_MHRP 48 /* Mobile Host Routing */ #define IPPROTO_MHRP (48) /* Mobile Host Routing */
#define IPPROTO_BHA 49 /* BHA */ #define IPPROTO_BHA (49) /* BHA */
#define IPPROTO_ESP 50 /* IP6 Encap Sec. Payload */ #define IPPROTO_ESP (50) /* IP6 Encap Sec. Payload */
#define IPPROTO_AH 51 /* IP6 Auth Header */ #define IPPROTO_AH (51) /* IP6 Auth Header */
#define IPPROTO_INLSP 52 /* Integ. Net Layer Security */ #define IPPROTO_INLSP (52) /* Integ. Net Layer Security */
#define IPPROTO_SWIPE 53 /* IP with encryption */ #define IPPROTO_SWIPE (53) /* IP with encryption */
#define IPPROTO_NHRP 54 /* Next Hop Resolution */ #define IPPROTO_NHRP (54) /* Next Hop Resolution */
/* 55-57: Unassigned */ /* 55-57: Unassigned */
#define IPPROTO_ICMPV6 58 /* ICMP6 */ #define IPPROTO_ICMPV6 (58) /* ICMP6 */
#define IPPROTO_NONE 59 /* IP6 no next header */ #define IPPROTO_NONE (59) /* IP6 no next header */
#define IPPROTO_DSTOPTS 60 /* IP6 destination option */ #define IPPROTO_DSTOPTS (60) /* IP6 destination option */
#define IPPROTO_AHIP 61 /* any host internal protocol */ #define IPPROTO_AHIP (61) /* any host internal protocol */
#define IPPROTO_CFTP 62 /* CFTP */ #define IPPROTO_CFTP (62) /* CFTP */
#define IPPROTO_HELLO 63 /* "hello" routing protocol */ #define IPPROTO_HELLO (63) /* "hello" routing protocol */
#define IPPROTO_SATEXPAK 64 /* SATNET/Backroom EXPAK */ #define IPPROTO_SATEXPAK (64) /* SATNET/Backroom EXPAK */
#define IPPROTO_KRYPTOLAN 65 /* Kryptolan */ #define IPPROTO_KRYPTOLAN (65) /* Kryptolan */
#define IPPROTO_RVD 66 /* Remote Virtual Disk */ #define IPPROTO_RVD (66) /* Remote Virtual Disk */
#define IPPROTO_IPPC 67 /* Pluribus Packet Core */ #define IPPROTO_IPPC (67) /* Pluribus Packet Core */
#define IPPROTO_ADFS 68 /* Any distributed FS */ #define IPPROTO_ADFS (68) /* Any distributed FS */
#define IPPROTO_SATMON 69 /* Satnet Monitoring */ #define IPPROTO_SATMON (69) /* Satnet Monitoring */
#define IPPROTO_VISA 70 /* VISA Protocol */ #define IPPROTO_VISA (70) /* VISA Protocol */
#define IPPROTO_IPCV 71 /* Packet Core Utility */ #define IPPROTO_IPCV (71) /* Packet Core Utility */
#define IPPROTO_CPNX 72 /* Comp. Prot. Net. Executive */ #define IPPROTO_CPNX (72) /* Comp. Prot. Net. Executive */
#define IPPROTO_CPHB 73 /* Comp. Prot. HeartBeat */ #define IPPROTO_CPHB (73) /* Comp. Prot. HeartBeat */
#define IPPROTO_WSN 74 /* Wang Span Network */ #define IPPROTO_WSN (74) /* Wang Span Network */
#define IPPROTO_PVP 75 /* Packet Video Protocol */ #define IPPROTO_PVP (75) /* Packet Video Protocol */
#define IPPROTO_BRSATMON 76 /* BackRoom SATNET Monitoring */ #define IPPROTO_BRSATMON (76) /* BackRoom SATNET Monitoring */
#define IPPROTO_ND 77 /* Sun net disk proto (temp.) */ #define IPPROTO_ND (77) /* Sun net disk proto (temp.) */
#define IPPROTO_WBMON 78 /* WIDEBAND Monitoring */ #define IPPROTO_WBMON (78) /* WIDEBAND Monitoring */
#define IPPROTO_WBEXPAK 79 /* WIDEBAND EXPAK */ #define IPPROTO_WBEXPAK (79) /* WIDEBAND EXPAK */
#define IPPROTO_EON 80 /* ISO cnlp */ #define IPPROTO_EON (80) /* ISO cnlp */
#define IPPROTO_VMTP 81 /* VMTP */ #define IPPROTO_VMTP (81) /* VMTP */
#define IPPROTO_SVMTP 82 /* Secure VMTP */ #define IPPROTO_SVMTP (82) /* Secure VMTP */
#define IPPROTO_VINES 83 /* Banyon VINES */ #define IPPROTO_VINES (83) /* Banyon VINES */
#define IPPROTO_TTP 84 /* TTP */ #define IPPROTO_TTP (84) /* TTP */
#define IPPROTO_IGP 85 /* NSFNET-IGP */ #define IPPROTO_IGP (85) /* NSFNET-IGP */
#define IPPROTO_DGP 86 /* dissimilar gateway prot. */ #define IPPROTO_DGP (86) /* dissimilar gateway prot. */
#define IPPROTO_TCF 87 /* TCF */ #define IPPROTO_TCF (87) /* TCF */
#define IPPROTO_IGRP 88 /* Cisco/GXS IGRP */ #define IPPROTO_IGRP (88) /* Cisco/GXS IGRP */
#define IPPROTO_OSPFIGP 89 /* OSPFIGP */ #define IPPROTO_OSPFIGP (89) /* OSPFIGP */
#define IPPROTO_SRPC 90 /* Strite RPC protocol */ #define IPPROTO_SRPC (90) /* Strite RPC protocol */
#define IPPROTO_LARP 91 /* Locus Address Resoloution */ #define IPPROTO_LARP (91) /* Locus Address Resoloution */
#define IPPROTO_MTP 92 /* Multicast Transport */ #define IPPROTO_MTP (92) /* Multicast Transport */
#define IPPROTO_AX25 93 /* AX.25 Frames */ #define IPPROTO_AX25 (93) /* AX.25 Frames */
#define IPPROTO_IPEIP 94 /* IP encapsulated in IP */ #define IPPROTO_IPEIP (94) /* IP encapsulated in IP */
#define IPPROTO_MICP 95 /* Mobile Int.ing control */ #define IPPROTO_MICP (95) /* Mobile Int.ing control */
#define IPPROTO_SCCSP 96 /* Semaphore Comm. security */ #define IPPROTO_SCCSP (96) /* Semaphore Comm. security */
#define IPPROTO_ETHERIP 97 /* Ethernet IP encapsulation */ #define IPPROTO_ETHERIP (97) /* Ethernet IP encapsulation */
#define IPPROTO_ENCAP 98 /* encapsulation header */ #define IPPROTO_ENCAP (98) /* encapsulation header */
#define IPPROTO_APES 99 /* any private encr. scheme */ #define IPPROTO_APES (99) /* any private encr. scheme */
#define IPPROTO_GMTP 100 /* GMTP*/ #define IPPROTO_GMTP (100) /* GMTP*/
#define IPPROTO_IPCOMP 108 /* payload compression (IPComp) */ #define IPPROTO_IPCOMP (108) /* payload compression (IPComp) */
/* 101-254: Partly Unassigned */ /* 101-254: Partly Unassigned */
#define IPPROTO_PIM 103 /* Protocol Independent Mcast */ #define IPPROTO_PIM (103) /* Protocol Independent Mcast */
#define IPPROTO_PGM 113 /* PGM */ #define IPPROTO_PGM (113) /* PGM */
/* 255: Reserved */ /* 255: Reserved */
/* BSD Private, local use, namespace incursion */ /* BSD Private, local use, namespace incursion */
#define IPPROTO_DIVERT 254 /* divert pseudo-protocol */ #define IPPROTO_DIVERT (254) /* divert pseudo-protocol */
#define IPPROTO_RAW 255 /* raw IP packet */ #define IPPROTO_RAW (255) /* raw IP packet */
#define IPPROTO_MAX 256 #define IPPROTO_MAX (256)
/* last return value of *_input(), meaning "all job for this pkt is done". */ /* last return value of *_input(), meaning "all job for this pkt is done". */
#define IPPROTO_DONE 257 #define IPPROTO_DONE (257)
#define IN_LOOPBACKNET 127 /* official! */ #define IN_LOOPBACKNET (127) /* official! */
#endif /* IN_H_ */ #endif /* IN_H_ */

View File

@ -147,7 +147,7 @@ void print_internal_socket(socket_internal_t *current_socket_internal)
socket_internal_t *getSocket(uint8_t s) socket_internal_t *getSocket(uint8_t s)
{ {
if(exists_socket(s)) { if (exists_socket(s)) {
return &(sockets[s - 1]); return &(sockets[s - 1]);
} }
else { else {
@ -160,8 +160,8 @@ void print_sockets(void)
int i; int i;
printf("\n--- Socket list: ---\n"); printf("\n--- Socket list: ---\n");
for(i = 1; i < MAX_SOCKETS + 1; i++) { for (i = 1; i < MAX_SOCKETS + 1; i++) {
if(getSocket(i) != NULL) { if (getSocket(i) != NULL) {
print_internal_socket(getSocket(i)); print_internal_socket(getSocket(i));
} }
} }
@ -169,7 +169,7 @@ void print_sockets(void)
bool exists_socket(uint8_t socket) bool exists_socket(uint8_t socket)
{ {
if(sockets[socket - 1].socket_id == 0) { if (sockets[socket - 1].socket_id == 0) {
return false; return false;
} }
else { else {
@ -184,7 +184,7 @@ void close_socket(socket_internal_t *current_socket)
bool isUDPSocket(uint8_t s) bool isUDPSocket(uint8_t s)
{ {
if((exists_socket(s)) && if ((exists_socket(s)) &&
(getSocket(s)->socket_values.domain == PF_INET6) && (getSocket(s)->socket_values.domain == PF_INET6) &&
(getSocket(s)->socket_values.type == SOCK_DGRAM) && (getSocket(s)->socket_values.type == SOCK_DGRAM) &&
((getSocket(s)->socket_values.protocol == IPPROTO_UDP) || ((getSocket(s)->socket_values.protocol == IPPROTO_UDP) ||
@ -198,7 +198,7 @@ bool isUDPSocket(uint8_t s)
bool isTCPSocket(uint8_t s) bool isTCPSocket(uint8_t s)
{ {
if((exists_socket(s)) && if ((exists_socket(s)) &&
(getSocket(s)->socket_values.domain == PF_INET6) && (getSocket(s)->socket_values.domain == PF_INET6) &&
(getSocket(s)->socket_values.type == SOCK_STREAM) && (getSocket(s)->socket_values.type == SOCK_STREAM) &&
((getSocket(s)->socket_values.protocol == IPPROTO_TCP) || ((getSocket(s)->socket_values.protocol == IPPROTO_TCP) ||
@ -214,12 +214,12 @@ int bind_udp_socket(int s, sockaddr6_t *name, int namelen, uint8_t pid)
{ {
int i; int i;
if(!exists_socket(s)) { if (!exists_socket(s)) {
return -1; return -1;
} }
for(i = 1; i < MAX_SOCKETS + 1; i++) { for (i = 1; i < MAX_SOCKETS + 1; i++) {
if(isUDPSocket(i) && if (isUDPSocket(i) &&
(getSocket(i)->socket_values.local_address.sin6_port == name->sin6_port)) { (getSocket(i)->socket_values.local_address.sin6_port == name->sin6_port)) {
return -1; return -1;
} }
@ -234,12 +234,12 @@ int bind_tcp_socket(int s, sockaddr6_t *name, int namelen, uint8_t pid)
{ {
int i; int i;
if(!exists_socket(s)) { if (!exists_socket(s)) {
return -1; return -1;
} }
for(i = 1; i < MAX_SOCKETS + 1; i++) { for (i = 1; i < MAX_SOCKETS + 1; i++) {
if(isTCPSocket(i) && if (isTCPSocket(i) &&
(getSocket(i)->socket_values.local_address.sin6_port == name->sin6_port)) { (getSocket(i)->socket_values.local_address.sin6_port == name->sin6_port)) {
return -1; return -1;
} }
@ -255,11 +255,11 @@ int socket(int domain, int type, int protocol)
{ {
int i = 1; int i = 1;
while(getSocket(i) != NULL) { while (getSocket(i) != NULL) {
i++; i++;
} }
if(i > MAX_SOCKETS + 1) { if (i > MAX_SOCKETS + 1) {
return -1; return -1;
} }
else { else {
@ -277,8 +277,8 @@ socket_internal_t *get_udp_socket(ipv6_hdr_t *ipv6_header, udp_hdr_t *udp_header
{ {
uint8_t i = 1; uint8_t i = 1;
while(i < MAX_SOCKETS + 1) { while (i < MAX_SOCKETS + 1) {
if(isUDPSocket(i) && if (isUDPSocket(i) &&
(getSocket(i)->socket_values.local_address.sin6_port == (getSocket(i)->socket_values.local_address.sin6_port ==
udp_header->dst_port)) { udp_header->dst_port)) {
return getSocket(i); return getSocket(i);
@ -309,16 +309,16 @@ socket_internal_t *get_tcp_socket(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header
uint8_t compare[16]; uint8_t compare[16];
memset(compare, 0, 16); memset(compare, 0, 16);
while(i < MAX_SOCKETS + 1) { while (i < MAX_SOCKETS + 1) {
current_socket = getSocket(i); current_socket = getSocket(i);
/* Check for matching 4 touple, ESTABLISHED connection */ /* Check for matching 4 touple, ESTABLISHED connection */
if(isTCPSocket(i) && is_four_touple(current_socket, ipv6_header, if (isTCPSocket(i) && is_four_touple(current_socket, ipv6_header,
tcp_header)) { tcp_header)) {
return current_socket; return current_socket;
} }
/* Sockets in LISTEN and SYN_RCVD state should only be tested on local TCP values */ /* Sockets in LISTEN and SYN_RCVD state should only be tested on local TCP values */
else if(isTCPSocket(i) && else if (isTCPSocket(i) &&
((current_socket->socket_values.tcp_control.state == LISTEN) || ((current_socket->socket_values.tcp_control.state == LISTEN) ||
(current_socket->socket_values.tcp_control.state == SYN_RCVD)) && (current_socket->socket_values.tcp_control.state == SYN_RCVD)) &&
(current_socket->socket_values.local_address.sin6_addr.uint8[15] == (current_socket->socket_values.local_address.sin6_addr.uint8[15] ==
@ -344,8 +344,8 @@ uint16_t get_free_source_port(uint8_t protocol)
uint16_t biggest_port = EPHEMERAL_PORTS - 1; uint16_t biggest_port = EPHEMERAL_PORTS - 1;
/* Remember biggest ephemeral port number used so far and add 1 */ /* Remember biggest ephemeral port number used so far and add 1 */
for(i = 0; i < MAX_SOCKETS; i++) { for (i = 0; i < MAX_SOCKETS; i++) {
if((sockets[i].socket_values.protocol == protocol) && if ((sockets[i].socket_values.protocol == protocol) &&
(sockets[i].socket_values.local_address.sin6_port > biggest_port)) { (sockets[i].socket_values.local_address.sin6_port > biggest_port)) {
biggest_port = sockets[i].socket_values.local_address.sin6_port; biggest_port = sockets[i].socket_values.local_address.sin6_port;
} }
@ -382,17 +382,17 @@ void set_tcp_packet(tcp_hdr_t *tcp_hdr, uint16_t src_port, uint16_t dst_port,
/* Check for consistent ACK and SEQ number */ /* Check for consistent ACK and SEQ number */
int check_tcp_consistency(socket_t *current_tcp_socket, tcp_hdr_t *tcp_header) int check_tcp_consistency(socket_t *current_tcp_socket, tcp_hdr_t *tcp_header)
{ {
if(IS_TCP_ACK(tcp_header->reserved_flags)) { if (IS_TCP_ACK(tcp_header->reserved_flags)) {
if(tcp_header->ack_nr > (current_tcp_socket->tcp_control.send_nxt)) { if (tcp_header->ack_nr > (current_tcp_socket->tcp_control.send_nxt)) {
/* ACK of not yet sent byte, discard */ /* ACK of not yet sent byte, discard */
return ACK_NO_TOO_BIG; return ACK_NO_TOO_BIG;
} }
else if(tcp_header->ack_nr <= (current_tcp_socket->tcp_control.send_una)) { else if (tcp_header->ack_nr <= (current_tcp_socket->tcp_control.send_una)) {
/* ACK of previous segments, maybe dropped? */ /* ACK of previous segments, maybe dropped? */
return ACK_NO_TOO_SMALL; return ACK_NO_TOO_SMALL;
} }
} }
else if((current_tcp_socket->tcp_control.rcv_nxt > 0) && (tcp_header->seq_nr < current_tcp_socket->tcp_control.rcv_nxt)) { else if ((current_tcp_socket->tcp_control.rcv_nxt > 0) && (tcp_header->seq_nr < current_tcp_socket->tcp_control.rcv_nxt)) {
/* segment repetition, maybe ACK got lost? */ /* segment repetition, maybe ACK got lost? */
return SEQ_NO_TOO_SMALL; return SEQ_NO_TOO_SMALL;
} }
@ -402,8 +402,8 @@ int check_tcp_consistency(socket_t *current_tcp_socket, tcp_hdr_t *tcp_header)
void switch_tcp_packet_byte_order(tcp_hdr_t *current_tcp_packet) void switch_tcp_packet_byte_order(tcp_hdr_t *current_tcp_packet)
{ {
if(current_tcp_packet->dataOffset_reserved * 4 > TCP_HDR_LEN) { if (current_tcp_packet->dataOffset_reserved * 4 > TCP_HDR_LEN) {
if(*(((uint8_t *)current_tcp_packet) + TCP_HDR_LEN) == TCP_MSS_OPTION) { if (*(((uint8_t *)current_tcp_packet) + TCP_HDR_LEN) == TCP_MSS_OPTION) {
uint8_t *packet_pointer = (uint8_t *)current_tcp_packet; uint8_t *packet_pointer = (uint8_t *)current_tcp_packet;
packet_pointer += (TCP_HDR_LEN + 2); packet_pointer += (TCP_HDR_LEN + 2);
uint8_t mss1 = *packet_pointer; uint8_t mss1 = *packet_pointer;
@ -412,7 +412,7 @@ void switch_tcp_packet_byte_order(tcp_hdr_t *current_tcp_packet)
*(packet_pointer + 1) = mss1; *(packet_pointer + 1) = mss1;
} }
if(*(((uint8_t *)current_tcp_packet) + TCP_HDR_LEN) == TCP_TS_OPTION) { if (*(((uint8_t *)current_tcp_packet) + TCP_HDR_LEN) == TCP_TS_OPTION) {
/* TODO: Timestamp option not implemented */ /* TODO: Timestamp option not implemented */
} }
} }
@ -429,7 +429,7 @@ int send_tcp(socket_internal_t *current_socket, tcp_hdr_t *current_tcp_packet,
socket_t *current_tcp_socket = &current_socket->socket_values; socket_t *current_tcp_socket = &current_socket->socket_values;
uint8_t header_length = TCP_HDR_LEN / 4; uint8_t header_length = TCP_HDR_LEN / 4;
if(IS_TCP_SYN(flags) || IS_TCP_SYN_ACK(flags)) { if (IS_TCP_SYN(flags) || IS_TCP_SYN_ACK(flags)) {
tcp_mss_option_t current_mss_option; tcp_mss_option_t current_mss_option;
header_length += sizeof(tcp_mss_option_t) / 4; header_length += sizeof(tcp_mss_option_t) / 4;
@ -464,7 +464,7 @@ int send_tcp(socket_internal_t *current_socket, tcp_hdr_t *current_tcp_packet,
temp_ipv6_header, flags, temp_ipv6_header, flags,
payload_length); payload_length);
if(compressed_size == 0) { if (compressed_size == 0) {
/* Error in compressing tcp packet header */ /* Error in compressing tcp packet header */
return -1; return -1;
} }
@ -506,7 +506,7 @@ int connect(int socket, sockaddr6_t *addr, uint32_t addrlen)
/* Check if socket exists */ /* Check if socket exists */
current_int_tcp_socket = getSocket(socket); current_int_tcp_socket = getSocket(socket);
if(current_int_tcp_socket == NULL) { if (current_int_tcp_socket == NULL) {
return -1; return -1;
} }
@ -558,7 +558,7 @@ int connect(int socket, sockaddr6_t *addr, uint32_t addrlen)
msg_from_server.type = TCP_RETRY; msg_from_server.type = TCP_RETRY;
while(msg_from_server.type == TCP_RETRY) { while (msg_from_server.type == TCP_RETRY) {
/* Send packet */ /* Send packet */
send_tcp(current_int_tcp_socket, current_tcp_packet, temp_ipv6_header, send_tcp(current_int_tcp_socket, current_tcp_packet, temp_ipv6_header,
TCP_SYN, 0); TCP_SYN, 0);
@ -566,7 +566,7 @@ int connect(int socket, sockaddr6_t *addr, uint32_t addrlen)
/* wait for SYN ACK or RETRY */ /* wait for SYN ACK or RETRY */
msg_receive(&msg_from_server); msg_receive(&msg_from_server);
if(msg_from_server.type == TCP_TIMEOUT) { if (msg_from_server.type == TCP_TIMEOUT) {
#ifdef TCP_HC #ifdef TCP_HC
/* We did not send anything successful so restore last context */ /* We did not send anything successful so restore last context */
memcpy(&current_tcp_socket->tcp_control.tcp_context, memcpy(&current_tcp_socket->tcp_control.tcp_context,
@ -576,7 +576,7 @@ int connect(int socket, sockaddr6_t *addr, uint32_t addrlen)
} }
#ifdef TCP_HC #ifdef TCP_HC
else if(msg_from_server.type == TCP_RETRY) { else if (msg_from_server.type == TCP_RETRY) {
/* We retry sending a packet so set everything to last values again */ /* We retry sending a packet so set everything to last values again */
memcpy(&current_tcp_socket->tcp_control.tcp_context, memcpy(&current_tcp_socket->tcp_control.tcp_context,
&saved_tcp_context, sizeof(tcp_hc_context_t)); &saved_tcp_context, sizeof(tcp_hc_context_t));
@ -589,13 +589,13 @@ int connect(int socket, sockaddr6_t *addr, uint32_t addrlen)
tcp_hdr_t *tcp_header = ((tcp_hdr_t *)(msg_from_server.content.ptr)); tcp_hdr_t *tcp_header = ((tcp_hdr_t *)(msg_from_server.content.ptr));
/* Check for consistency */ /* Check for consistency */
if(tcp_header->ack_nr != current_tcp_socket->tcp_control.send_nxt + 1) { if (tcp_header->ack_nr != current_tcp_socket->tcp_control.send_nxt + 1) {
printf("TCP packets not consistent!\n"); printf("TCP packets not consistent!\n");
} }
/* Got SYN ACK from Server */ /* Got SYN ACK from Server */
/* Refresh foreign TCP socket information */ /* Refresh foreign TCP socket information */
if((tcp_header->dataOffset_reserved * 4 > TCP_HDR_LEN) && if ((tcp_header->dataOffset_reserved * 4 > TCP_HDR_LEN) &&
(*(((uint8_t *)tcp_header) + TCP_HDR_LEN) == TCP_MSS_OPTION)) { (*(((uint8_t *)tcp_header) + TCP_HDR_LEN) == TCP_MSS_OPTION)) {
current_tcp_socket->tcp_control.mss = current_tcp_socket->tcp_control.mss =
*((uint16_t *)(((uint8_t *)tcp_header) + TCP_HDR_LEN + 2)); *((uint16_t *)(((uint8_t *)tcp_header) + TCP_HDR_LEN + 2));
@ -627,7 +627,7 @@ int connect(int socket, sockaddr6_t *addr, uint32_t addrlen)
sizeof(tcp_hc_context_t)); sizeof(tcp_hc_context_t));
#endif #endif
while(msg_from_server.type != TCP_RETRY) { while (msg_from_server.type != TCP_RETRY) {
/* Send packet */ /* Send packet */
send_tcp(current_int_tcp_socket, current_tcp_packet, temp_ipv6_header, send_tcp(current_int_tcp_socket, current_tcp_packet, temp_ipv6_header,
TCP_ACK, 0); TCP_ACK, 0);
@ -635,13 +635,13 @@ int connect(int socket, sockaddr6_t *addr, uint32_t addrlen)
msg_receive(&msg_from_server); msg_receive(&msg_from_server);
#ifdef TCP_HC #ifdef TCP_HC
if(msg_from_server.type == TCP_SYN_ACK) { if (msg_from_server.type == TCP_SYN_ACK) {
/* TCP_SYN_ACK from server arrived again, copy old context and /* TCP_SYN_ACK from server arrived again, copy old context and
* send TCP_ACK again */ * send TCP_ACK again */
memcpy(&current_tcp_socket->tcp_control.tcp_context, memcpy(&current_tcp_socket->tcp_control.tcp_context,
&saved_tcp_context, sizeof(tcp_hc_context_t)); &saved_tcp_context, sizeof(tcp_hc_context_t));
} }
else if(msg_from_server.type == TCP_RETRY) { else if (msg_from_server.type == TCP_RETRY) {
/* We waited for RTT, no TCP_SYN_ACK received, so we assume the /* We waited for RTT, no TCP_SYN_ACK received, so we assume the
* TCP_ACK packet arrived safely */ * TCP_ACK packet arrived safely */
} }
@ -664,7 +664,7 @@ void calculate_rto(tcp_cb_t *tcp_control, long current_time)
double rttvar = tcp_control->rttvar; double rttvar = tcp_control->rttvar;
double rto = tcp_control->rto; double rto = tcp_control->rto;
if((srtt == 0) && (rttvar == 0) && (rto == TCP_INITIAL_ACK_TIMEOUT)) { if ((srtt == 0) && (rttvar == 0) && (rto == TCP_INITIAL_ACK_TIMEOUT)) {
/* First calculation */ /* First calculation */
srtt = rtt; srtt = rtt;
rttvar = 0.5 * rtt; rttvar = 0.5 * rtt;
@ -679,7 +679,7 @@ void calculate_rto(tcp_cb_t *tcp_control, long current_time)
(TCP_TIMER_RESOLUTION) : (4 * rttvar)); (TCP_TIMER_RESOLUTION) : (4 * rttvar));
} }
if(rto < SECOND) { if (rto < SECOND) {
rto = SECOND; rto = SECOND;
} }
@ -701,7 +701,7 @@ int32_t send(int s, void *msg, uint32_t len, int flags)
tcp_hdr_t *current_tcp_packet = ((tcp_hdr_t *)(&send_buffer[IPV6_HDR_LEN])); tcp_hdr_t *current_tcp_packet = ((tcp_hdr_t *)(&send_buffer[IPV6_HDR_LEN]));
/* Check if socket exists and is TCP socket */ /* Check if socket exists and is TCP socket */
if(!isTCPSocket(s)) { if (!isTCPSocket(s)) {
return -1; return -1;
} }
@ -709,7 +709,7 @@ int32_t send(int s, void *msg, uint32_t len, int flags)
current_tcp_socket = &current_int_tcp_socket->socket_values; current_tcp_socket = &current_int_tcp_socket->socket_values;
/* Check for ESTABLISHED STATE */ /* Check for ESTABLISHED STATE */
if(current_tcp_socket->tcp_control.state != ESTABLISHED) { if (current_tcp_socket->tcp_control.state != ESTABLISHED) {
return -1; return -1;
} }
@ -718,7 +718,7 @@ int32_t send(int s, void *msg, uint32_t len, int flags)
recv_msg.type = UNDEFINED; recv_msg.type = UNDEFINED;
while(1) { while (1) {
current_tcp_socket->tcp_control.no_of_retries = 0; current_tcp_socket->tcp_control.no_of_retries = 0;
#ifdef TCP_HC #ifdef TCP_HC
@ -729,12 +729,12 @@ int32_t send(int s, void *msg, uint32_t len, int flags)
sizeof(tcp_hc_context_t) - 1); sizeof(tcp_hc_context_t) - 1);
#endif #endif
while(recv_msg.type != TCP_ACK) { while (recv_msg.type != TCP_ACK) {
/* Add packet data */ /* Add packet data */
if(current_tcp_socket->tcp_control.send_wnd > if (current_tcp_socket->tcp_control.send_wnd >
current_tcp_socket->tcp_control.mss) { current_tcp_socket->tcp_control.mss) {
/* Window size > Maximum Segment Size */ /* Window size > Maximum Segment Size */
if((len - total_sent_bytes) > current_tcp_socket->tcp_control.mss) { if ((len - total_sent_bytes) > current_tcp_socket->tcp_control.mss) {
memcpy(&send_buffer[IPV6_HDR_LEN + TCP_HDR_LEN], msg, memcpy(&send_buffer[IPV6_HDR_LEN + TCP_HDR_LEN], msg,
current_tcp_socket->tcp_control.mss); current_tcp_socket->tcp_control.mss);
sent_bytes = current_tcp_socket->tcp_control.mss; sent_bytes = current_tcp_socket->tcp_control.mss;
@ -749,7 +749,7 @@ int32_t send(int s, void *msg, uint32_t len, int flags)
} }
else { else {
/* Window size <= Maximum Segment Size */ /* Window size <= Maximum Segment Size */
if((len - total_sent_bytes) > current_tcp_socket->tcp_control.send_wnd) { if ((len - total_sent_bytes) > current_tcp_socket->tcp_control.send_wnd) {
memcpy(&send_buffer[IPV6_HDR_LEN + TCP_HDR_LEN], msg, memcpy(&send_buffer[IPV6_HDR_LEN + TCP_HDR_LEN], msg,
current_tcp_socket->tcp_control.send_wnd); current_tcp_socket->tcp_control.send_wnd);
sent_bytes = current_tcp_socket->tcp_control.send_wnd; sent_bytes = current_tcp_socket->tcp_control.send_wnd;
@ -766,7 +766,7 @@ int32_t send(int s, void *msg, uint32_t len, int flags)
current_tcp_socket->tcp_control.send_nxt += sent_bytes; current_tcp_socket->tcp_control.send_nxt += sent_bytes;
current_tcp_socket->tcp_control.send_wnd -= sent_bytes; current_tcp_socket->tcp_control.send_wnd -= sent_bytes;
if(send_tcp(current_int_tcp_socket, current_tcp_packet, if (send_tcp(current_int_tcp_socket, current_tcp_packet,
temp_ipv6_header, 0, sent_bytes) != 1) { temp_ipv6_header, 0, sent_bytes) != 1) {
/* Error while sending tcp data */ /* Error while sending tcp data */
current_tcp_socket->tcp_control.send_nxt -= sent_bytes; current_tcp_socket->tcp_control.send_nxt -= sent_bytes;
@ -788,14 +788,14 @@ int32_t send(int s, void *msg, uint32_t len, int flags)
switch(recv_msg.type) { switch(recv_msg.type) {
case TCP_ACK: { case TCP_ACK: {
if(current_tcp_socket->tcp_control.no_of_retries == 0) { if (current_tcp_socket->tcp_control.no_of_retries == 0) {
calculate_rto(&current_tcp_socket->tcp_control, calculate_rto(&current_tcp_socket->tcp_control,
hwtimer_now()); hwtimer_now());
} }
tcp_hdr_t *tcp_header = ((tcp_hdr_t *)(recv_msg.content.ptr)); tcp_hdr_t *tcp_header = ((tcp_hdr_t *)(recv_msg.content.ptr));
if((current_tcp_socket->tcp_control.send_nxt == if ((current_tcp_socket->tcp_control.send_nxt ==
tcp_header->ack_nr) && (total_sent_bytes == len)) { tcp_header->ack_nr) && (total_sent_bytes == len)) {
current_tcp_socket->tcp_control.send_una = tcp_header->ack_nr; current_tcp_socket->tcp_control.send_una = tcp_header->ack_nr;
current_tcp_socket->tcp_control.send_nxt = tcp_header->ack_nr; current_tcp_socket->tcp_control.send_nxt = tcp_header->ack_nr;
@ -807,7 +807,7 @@ int32_t send(int s, void *msg, uint32_t len, int flags)
#endif #endif
return sent_bytes; return sent_bytes;
} }
else if((current_tcp_socket->tcp_control.send_nxt == else if ((current_tcp_socket->tcp_control.send_nxt ==
tcp_header->ack_nr) && (total_sent_bytes != len)) { tcp_header->ack_nr) && (total_sent_bytes != len)) {
current_tcp_socket->tcp_control.send_una = tcp_header->ack_nr; current_tcp_socket->tcp_control.send_una = tcp_header->ack_nr;
current_tcp_socket->tcp_control.send_nxt = tcp_header->ack_nr; current_tcp_socket->tcp_control.send_nxt = tcp_header->ack_nr;
@ -864,7 +864,7 @@ int32_t send(int s, void *msg, uint32_t len, int flags)
uint8_t read_from_socket(socket_internal_t *current_int_tcp_socket, uint8_t read_from_socket(socket_internal_t *current_int_tcp_socket,
void *buf, int len) void *buf, int len)
{ {
if(len >= current_int_tcp_socket->tcp_input_buffer_end) { if (len >= current_int_tcp_socket->tcp_input_buffer_end) {
mutex_lock(&current_int_tcp_socket->tcp_buffer_mutex); mutex_lock(&current_int_tcp_socket->tcp_buffer_mutex);
uint8_t read_bytes = current_int_tcp_socket->tcp_input_buffer_end; uint8_t read_bytes = current_int_tcp_socket->tcp_input_buffer_end;
memcpy(buf, current_int_tcp_socket->tcp_input_buffer, memcpy(buf, current_int_tcp_socket->tcp_input_buffer,
@ -896,7 +896,7 @@ int recv(int s, void *buf, uint32_t len, int flags)
socket_internal_t *current_int_tcp_socket; socket_internal_t *current_int_tcp_socket;
/* Check if socket exists */ /* Check if socket exists */
if(!isTCPSocket(s)) { if (!isTCPSocket(s)) {
printf("INFO: NO TCP SOCKET!\n"); printf("INFO: NO TCP SOCKET!\n");
return -1; return -1;
} }
@ -906,23 +906,23 @@ int recv(int s, void *buf, uint32_t len, int flags)
/* Setting Thread PID */ /* Setting Thread PID */
current_int_tcp_socket->recv_pid = thread_getpid(); current_int_tcp_socket->recv_pid = thread_getpid();
if(current_int_tcp_socket->tcp_input_buffer_end > 0) { if (current_int_tcp_socket->tcp_input_buffer_end > 0) {
return read_from_socket(current_int_tcp_socket, buf, len); return read_from_socket(current_int_tcp_socket, buf, len);
} }
msg_receive(&m_recv); msg_receive(&m_recv);
if((exists_socket(s)) && (current_int_tcp_socket->tcp_input_buffer_end > 0)) { if ((exists_socket(s)) && (current_int_tcp_socket->tcp_input_buffer_end > 0)) {
read_bytes = read_from_socket(current_int_tcp_socket, buf, len); read_bytes = read_from_socket(current_int_tcp_socket, buf, len);
net_msg_reply(&m_recv, &m_send, UNDEFINED); net_msg_reply(&m_recv, &m_send, UNDEFINED);
return read_bytes; return read_bytes;
} }
/* Received FIN */ /* Received FIN */
if(m_recv.type == CLOSE_CONN) { if (m_recv.type == CLOSE_CONN) {
/* Sent FIN_ACK, wait for ACK */ /* Sent FIN_ACK, wait for ACK */
msg_receive(&m_recv); msg_receive(&m_recv);
/* Received ACK, return with closed socket! */ /* Received ACK, return with closed socket!*/
return -1; return -1;
} }
@ -933,7 +933,7 @@ int recv(int s, void *buf, uint32_t len, int flags)
int32_t recvfrom(int s, void *buf, uint32_t len, int flags, sockaddr6_t *from, int32_t recvfrom(int s, void *buf, uint32_t len, int flags, sockaddr6_t *from,
uint32_t *fromlen) uint32_t *fromlen)
{ {
if(isUDPSocket(s)) { if (isUDPSocket(s)) {
msg_t m_recv, m_send; msg_t m_recv, m_send;
ipv6_hdr_t *ipv6_header; ipv6_hdr_t *ipv6_header;
udp_hdr_t *udp_header; udp_hdr_t *udp_header;
@ -957,7 +957,7 @@ int32_t recvfrom(int s, void *buf, uint32_t len, int flags, sockaddr6_t *from,
msg_reply(&m_recv, &m_send); msg_reply(&m_recv, &m_send);
return udp_header->length - UDP_HDR_LEN; return udp_header->length - UDP_HDR_LEN;
} }
else if(isTCPSocket(s)) { else if (isTCPSocket(s)) {
return recv(s, buf, len, flags); return recv(s, buf, len, flags);
} }
else { else {
@ -969,7 +969,7 @@ int32_t recvfrom(int s, void *buf, uint32_t len, int flags, sockaddr6_t *from,
int32_t sendto(int s, const void *msg, uint32_t len, int flags, int32_t sendto(int s, const void *msg, uint32_t len, int flags,
sockaddr6_t *to, uint32_t tolen) sockaddr6_t *to, uint32_t tolen)
{ {
if(isUDPSocket(s) && if (isUDPSocket(s) &&
(getSocket(s)->socket_values.foreign_address.sin6_port == 0)) { (getSocket(s)->socket_values.foreign_address.sin6_port == 0)) {
uint8_t send_buffer[BUFFER_SIZE]; uint8_t send_buffer[BUFFER_SIZE];
@ -1004,8 +1004,8 @@ int close(int s)
{ {
socket_internal_t *current_socket = getSocket(s); socket_internal_t *current_socket = getSocket(s);
if(current_socket != NULL) { if (current_socket != NULL) {
if(isTCPSocket(s)) { if (isTCPSocket(s)) {
/* Variables */ /* Variables */
msg_t m_recv; msg_t m_recv;
uint8_t send_buffer[BUFFER_SIZE]; uint8_t send_buffer[BUFFER_SIZE];
@ -1013,12 +1013,12 @@ int close(int s)
tcp_hdr_t *current_tcp_packet = ((tcp_hdr_t *)(&send_buffer[IPV6_HDR_LEN])); tcp_hdr_t *current_tcp_packet = ((tcp_hdr_t *)(&send_buffer[IPV6_HDR_LEN]));
/* Check if socket exists and is TCP socket */ /* Check if socket exists and is TCP socket */
if(!isTCPSocket(s)) { if (!isTCPSocket(s)) {
return -1; return -1;
} }
/* Check for ESTABLISHED STATE */ /* Check for ESTABLISHED STATE */
if(current_socket->socket_values.tcp_control.state != ESTABLISHED) { if (current_socket->socket_values.tcp_control.state != ESTABLISHED) {
close_socket(current_socket); close_socket(current_socket);
return 1; return 1;
} }
@ -1039,7 +1039,7 @@ int close(int s)
close_socket(current_socket); close_socket(current_socket);
return 1; return 1;
} }
else if(isUDPSocket(s)) { else if (isUDPSocket(s)) {
close_socket(current_socket); close_socket(current_socket);
return 1; return 1;
} }
@ -1053,21 +1053,21 @@ int close(int s)
int bind(int s, sockaddr6_t *name, int namelen) int bind(int s, sockaddr6_t *name, int namelen)
{ {
if(exists_socket(s)) { if (exists_socket(s)) {
socket_t *current_socket = &getSocket(s)->socket_values; socket_t *current_socket = &getSocket(s)->socket_values;
switch(current_socket->domain) { switch(current_socket->domain) {
case(PF_INET): { case (PF_INET): {
/* Not provided */ /* Not provided */
return -1; return -1;
break; break;
} }
case(PF_INET6): { case (PF_INET6): {
switch(current_socket->type) { switch(current_socket->type) {
/* TCP */ /* TCP */
case(SOCK_STREAM): { case (SOCK_STREAM): {
if((current_socket->protocol == 0) || if ((current_socket->protocol == 0) ||
(current_socket->protocol == IPPROTO_TCP)) { (current_socket->protocol == IPPROTO_TCP)) {
return bind_tcp_socket(s, name, namelen, return bind_tcp_socket(s, name, namelen,
thread_getpid()); thread_getpid());
@ -1082,8 +1082,8 @@ int bind(int s, sockaddr6_t *name, int namelen)
} }
/* UDP */ /* UDP */
case(SOCK_DGRAM): { case (SOCK_DGRAM): {
if((current_socket->protocol == 0) || if ((current_socket->protocol == 0) ||
(current_socket->protocol == IPPROTO_UDP)) { (current_socket->protocol == IPPROTO_UDP)) {
return bind_udp_socket(s, name, namelen, return bind_udp_socket(s, name, namelen,
thread_getpid()); thread_getpid());
@ -1097,13 +1097,13 @@ int bind(int s, sockaddr6_t *name, int namelen)
break; break;
} }
case(SOCK_SEQPACKET): { case (SOCK_SEQPACKET): {
/* not provided */ /* not provided */
return -1; return -1;
break; break;
} }
case(SOCK_RAW): { case (SOCK_RAW): {
/* not provided */ /* not provided */
return -1; return -1;
break; break;
@ -1118,7 +1118,7 @@ int bind(int s, sockaddr6_t *name, int namelen)
break; break;
} }
case(PF_UNIX): { case (PF_UNIX): {
/* Not provided */ /* Not provided */
return -1; return -1;
break; break;
@ -1135,7 +1135,7 @@ int bind(int s, sockaddr6_t *name, int namelen)
int listen(int s, int backlog) int listen(int s, int backlog)
{ {
if(isTCPSocket(s) && getSocket(s)->socket_values.tcp_control.state == CLOSED) { if (isTCPSocket(s) && getSocket(s)->socket_values.tcp_control.state == CLOSED) {
socket_internal_t *current_socket = getSocket(s); socket_internal_t *current_socket = getSocket(s);
current_socket->socket_values.tcp_control.state = LISTEN; current_socket->socket_values.tcp_control.state = LISTEN;
return 0; return 0;
@ -1152,19 +1152,19 @@ socket_internal_t *getWaitingConnectionSocket(int socket,
int i; int i;
socket_internal_t *current_socket, *listening_socket = getSocket(socket); socket_internal_t *current_socket, *listening_socket = getSocket(socket);
for(i = 1; i < MAX_SOCKETS + 1; i++) { for (i = 1; i < MAX_SOCKETS + 1; i++) {
current_socket = getSocket(i); current_socket = getSocket(i);
/* Connection establishment ACK, Check for 4 touple and state */ /* Connection establishment ACK, Check for 4 touple and state */
if((ipv6_header != NULL) && (tcp_header != NULL)) { if ((ipv6_header != NULL) && (tcp_header != NULL)) {
if(is_four_touple(current_socket, ipv6_header, tcp_header) && if (is_four_touple(current_socket, ipv6_header, tcp_header) &&
(current_socket->socket_values.tcp_control.state == SYN_RCVD)) { (current_socket->socket_values.tcp_control.state == SYN_RCVD)) {
return current_socket; return current_socket;
} }
} }
/* Connection establishment SYN ACK, check only for port and state */ /* Connection establishment SYN ACK, check only for port and state */
else { else {
if((current_socket->socket_values.tcp_control.state == SYN_RCVD) && if ((current_socket->socket_values.tcp_control.state == SYN_RCVD) &&
(current_socket->socket_values.local_address.sin6_port == (current_socket->socket_values.local_address.sin6_port ==
listening_socket->socket_values.local_address.sin6_port)) { listening_socket->socket_values.local_address.sin6_port)) {
return current_socket; return current_socket;
@ -1202,7 +1202,7 @@ int handle_new_tcp_connection(socket_internal_t *current_queued_int_socket,
/* Set message type to Retry for while loop */ /* Set message type to Retry for while loop */
msg_recv_client_ack.type = TCP_RETRY; msg_recv_client_ack.type = TCP_RETRY;
while(msg_recv_client_ack.type == TCP_RETRY) { while (msg_recv_client_ack.type == TCP_RETRY) {
/* Send packet */ /* Send packet */
send_tcp(current_queued_int_socket, syn_ack_packet, temp_ipv6_header, send_tcp(current_queued_int_socket, syn_ack_packet, temp_ipv6_header,
TCP_SYN_ACK, 0); TCP_SYN_ACK, 0);
@ -1210,7 +1210,7 @@ int handle_new_tcp_connection(socket_internal_t *current_queued_int_socket,
/* wait for ACK from Client */ /* wait for ACK from Client */
msg_receive(&msg_recv_client_ack); msg_receive(&msg_recv_client_ack);
if(msg_recv_client_ack.type == TCP_TIMEOUT) { if (msg_recv_client_ack.type == TCP_TIMEOUT) {
/* Set status of internal socket back to LISTEN */ /* Set status of internal socket back to LISTEN */
server_socket->socket_values.tcp_control.state = LISTEN; server_socket->socket_values.tcp_control.state = LISTEN;
@ -1224,7 +1224,7 @@ int handle_new_tcp_connection(socket_internal_t *current_queued_int_socket,
tcp_header = ((tcp_hdr_t *)(msg_recv_client_ack.content.ptr)); tcp_header = ((tcp_hdr_t *)(msg_recv_client_ack.content.ptr));
/* Check for consistency */ /* Check for consistency */
if(tcp_header->ack_nr != current_queued_socket->tcp_control.send_nxt + 1) { if (tcp_header->ack_nr != current_queued_socket->tcp_control.send_nxt + 1) {
printf("TCP packets not consistent!\n"); printf("TCP packets not consistent!\n");
} }
@ -1265,11 +1265,11 @@ int accept(int s, sockaddr6_t *addr, uint32_t *addrlen)
{ {
socket_internal_t *server_socket = getSocket(s); socket_internal_t *server_socket = getSocket(s);
if(isTCPSocket(s) && (server_socket->socket_values.tcp_control.state == LISTEN)) { if (isTCPSocket(s) && (server_socket->socket_values.tcp_control.state == LISTEN)) {
socket_internal_t *current_queued_socket = socket_internal_t *current_queued_socket =
getWaitingConnectionSocket(s, NULL, NULL); getWaitingConnectionSocket(s, NULL, NULL);
if(current_queued_socket != NULL) { if (current_queued_socket != NULL) {
return handle_new_tcp_connection(current_queued_socket, return handle_new_tcp_connection(current_queued_socket,
server_socket, thread_getpid()); server_socket, thread_getpid());
} }
@ -1278,7 +1278,7 @@ int accept(int s, sockaddr6_t *addr, uint32_t *addrlen)
msg_t msg_recv_client_syn; msg_t msg_recv_client_syn;
msg_recv_client_syn.type = UNDEFINED; msg_recv_client_syn.type = UNDEFINED;
while(msg_recv_client_syn.type != TCP_SYN) { while (msg_recv_client_syn.type != TCP_SYN) {
msg_receive(&msg_recv_client_syn); msg_receive(&msg_recv_client_syn);
} }
@ -1312,7 +1312,7 @@ socket_internal_t *new_tcp_queued_socket(ipv6_hdr_t *ipv6_header,
&ipv6_header->destaddr); &ipv6_header->destaddr);
/* Foreign TCP information */ /* Foreign TCP information */
if((tcp_header->dataOffset_reserved * 4 > TCP_HDR_LEN) && if ((tcp_header->dataOffset_reserved * 4 > TCP_HDR_LEN) &&
(*(((uint8_t *)tcp_header) + TCP_HDR_LEN) == TCP_MSS_OPTION)) { (*(((uint8_t *)tcp_header) + TCP_HDR_LEN) == TCP_MSS_OPTION)) {
current_queued_socket->socket_values.tcp_control.mss = current_queued_socket->socket_values.tcp_control.mss =
*((uint16_t *)(((uint8_t *)tcp_header) + TCP_HDR_LEN + 2)); *((uint16_t *)(((uint8_t *)tcp_header) + TCP_HDR_LEN + 2));

View File

@ -52,7 +52,7 @@ void printArrayRange_tcp(uint8_t *udp_header, uint16_t len)
int i = 0; int i = 0;
printf("-------------MEMORY-------------\n"); printf("-------------MEMORY-------------\n");
for(i = 0; i < len; i++) { for (i = 0; i < len; i++) {
printf("%#x ", *(udp_header + i)); printf("%#x ", *(udp_header + i));
} }
@ -77,7 +77,7 @@ uint8_t handle_payload(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header,
uint8_t tcp_payload_len = ipv6_header->length - TCP_HDR_LEN; uint8_t tcp_payload_len = ipv6_header->length - TCP_HDR_LEN;
uint8_t acknowledged_bytes = 0; uint8_t acknowledged_bytes = 0;
if(tcp_payload_len > tcp_socket->socket_values.tcp_control.rcv_wnd) { if (tcp_payload_len > tcp_socket->socket_values.tcp_control.rcv_wnd) {
mutex_lock(&tcp_socket->tcp_buffer_mutex); mutex_lock(&tcp_socket->tcp_buffer_mutex);
memcpy(tcp_socket->tcp_input_buffer, payload, memcpy(tcp_socket->tcp_input_buffer, payload,
tcp_socket->socket_values.tcp_control.rcv_wnd); tcp_socket->socket_values.tcp_control.rcv_wnd);
@ -98,7 +98,7 @@ uint8_t handle_payload(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header,
mutex_unlock(&tcp_socket->tcp_buffer_mutex, 0); mutex_unlock(&tcp_socket->tcp_buffer_mutex, 0);
} }
if(thread_getstatus(tcp_socket->recv_pid) == STATUS_RECEIVE_BLOCKED) { if (thread_getstatus(tcp_socket->recv_pid) == STATUS_RECEIVE_BLOCKED) {
net_msg_send_recv(&m_send_tcp, &m_recv_tcp, tcp_socket->recv_pid, UNDEFINED); net_msg_send_recv(&m_send_tcp, &m_recv_tcp, tcp_socket->recv_pid, UNDEFINED);
} }
@ -111,25 +111,25 @@ void handle_tcp_ack_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header,
msg_t m_recv_tcp, m_send_tcp; msg_t m_recv_tcp, m_send_tcp;
uint8_t target_pid; uint8_t target_pid;
if(tcp_socket->socket_values.tcp_control.state == LAST_ACK) { if (tcp_socket->socket_values.tcp_control.state == LAST_ACK) {
target_pid = tcp_socket->recv_pid; target_pid = tcp_socket->recv_pid;
close_socket(tcp_socket); close_socket(tcp_socket);
msg_send(&m_send_tcp, target_pid, 0); msg_send(&m_send_tcp, target_pid, 0);
return; return;
} }
else if(tcp_socket->socket_values.tcp_control.state == CLOSING) { else if (tcp_socket->socket_values.tcp_control.state == CLOSING) {
msg_send(&m_send_tcp, tcp_socket->recv_pid, 0); msg_send(&m_send_tcp, tcp_socket->recv_pid, 0);
msg_send(&m_send_tcp, tcp_socket->send_pid, 0); msg_send(&m_send_tcp, tcp_socket->send_pid, 0);
return; return;
} }
else if(getWaitingConnectionSocket(tcp_socket->socket_id, ipv6_header, else if (getWaitingConnectionSocket(tcp_socket->socket_id, ipv6_header,
tcp_header) != NULL) { tcp_header) != NULL) {
m_send_tcp.content.ptr = (char *)tcp_header; m_send_tcp.content.ptr = (char *)tcp_header;
net_msg_send_recv(&m_send_tcp, &m_recv_tcp, tcp_socket->recv_pid, TCP_ACK); net_msg_send_recv(&m_send_tcp, &m_recv_tcp, tcp_socket->recv_pid, TCP_ACK);
return; return;
} }
else if(tcp_socket->socket_values.tcp_control.state == ESTABLISHED) { else if (tcp_socket->socket_values.tcp_control.state == ESTABLISHED) {
if(check_tcp_consistency(&tcp_socket->socket_values, tcp_header) == PACKET_OK) { if (check_tcp_consistency(&tcp_socket->socket_values, tcp_header) == PACKET_OK) {
m_send_tcp.content.ptr = (char *)tcp_header; m_send_tcp.content.ptr = (char *)tcp_header;
net_msg_send(&m_send_tcp, tcp_socket->send_pid, 0, TCP_ACK); net_msg_send(&m_send_tcp, tcp_socket->send_pid, 0, TCP_ACK);
return; return;
@ -150,11 +150,11 @@ void handle_tcp_syn_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header,
{ {
msg_t m_send_tcp; msg_t m_send_tcp;
if(tcp_socket->socket_values.tcp_control.state == LISTEN) { if (tcp_socket->socket_values.tcp_control.state == LISTEN) {
socket_internal_t *new_socket = new_tcp_queued_socket(ipv6_header, socket_internal_t *new_socket = new_tcp_queued_socket(ipv6_header,
tcp_header); tcp_header);
if(new_socket != NULL) { if (new_socket != NULL) {
#ifdef TCP_HC #ifdef TCP_HC
update_tcp_hc_context(true, new_socket, tcp_header); update_tcp_hc_context(true, new_socket, tcp_header);
#endif #endif
@ -179,7 +179,7 @@ void handle_tcp_syn_ack_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header,
{ {
msg_t m_send_tcp; msg_t m_send_tcp;
if(tcp_socket->socket_values.tcp_control.state == SYN_SENT) { if (tcp_socket->socket_values.tcp_control.state == SYN_SENT) {
m_send_tcp.content.ptr = (char *) tcp_header; m_send_tcp.content.ptr = (char *) tcp_header;
net_msg_send(&m_send_tcp, tcp_socket->recv_pid, 0, TCP_SYN_ACK); net_msg_send(&m_send_tcp, tcp_socket->recv_pid, 0, TCP_SYN_ACK);
} }
@ -205,7 +205,7 @@ void handle_tcp_fin_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header,
current_tcp_socket->tcp_control.tcp_context.hc_type = COMPRESSED_HEADER; current_tcp_socket->tcp_control.tcp_context.hc_type = COMPRESSED_HEADER;
#endif #endif
if(current_tcp_socket->tcp_control.state == FIN_WAIT_1) { if (current_tcp_socket->tcp_control.state == FIN_WAIT_1) {
current_tcp_socket->tcp_control.state = CLOSING; current_tcp_socket->tcp_control.state = CLOSING;
send_tcp(tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_FIN_ACK, 0); send_tcp(tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_FIN_ACK, 0);
@ -253,9 +253,9 @@ void handle_tcp_no_flags_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header,
ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t *)(&send_buffer)); ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t *)(&send_buffer));
tcp_hdr_t *current_tcp_packet = ((tcp_hdr_t *)(&send_buffer[IPV6_HDR_LEN])); tcp_hdr_t *current_tcp_packet = ((tcp_hdr_t *)(&send_buffer[IPV6_HDR_LEN]));
if(tcp_payload_len > 0) { if (tcp_payload_len > 0) {
if(check_tcp_consistency(current_tcp_socket, tcp_header) == PACKET_OK) { if (check_tcp_consistency(current_tcp_socket, tcp_header) == PACKET_OK) {
read_bytes = handle_payload(ipv6_header, tcp_header, tcp_socket, payload); read_bytes = handle_payload(ipv6_header, tcp_header, tcp_socket, payload);
/* Refresh TCP status values */ /* Refresh TCP status values */
@ -295,7 +295,7 @@ void tcp_packet_handler(void)
socket_internal_t *tcp_socket = NULL; socket_internal_t *tcp_socket = NULL;
uint16_t chksum; uint16_t chksum;
while(1) { while (1) {
msg_receive(&m_recv_ip); msg_receive(&m_recv_ip);
ipv6_header = ((ipv6_hdr_t *)m_recv_ip.content.ptr); ipv6_header = ((ipv6_hdr_t *)m_recv_ip.content.ptr);
@ -311,7 +311,7 @@ void tcp_packet_handler(void)
payload = (uint8_t *)(m_recv_ip.content.ptr + IPV6_HDR_LEN + payload = (uint8_t *)(m_recv_ip.content.ptr + IPV6_HDR_LEN +
tcp_header->dataOffset_reserved * 4); tcp_header->dataOffset_reserved * 4);
if((chksum == 0xffff) && (tcp_socket != NULL)) { if ((chksum == 0xffff) && (tcp_socket != NULL)) {
#ifdef TCP_HC #ifdef TCP_HC
update_tcp_hc_context(true, tcp_socket, tcp_header); update_tcp_hc_context(true, tcp_socket, tcp_header);
#endif #endif

View File

@ -33,10 +33,10 @@ socket_internal_t *get_tcp_socket_by_context(ipv6_hdr_t *current_ipv6_header,
{ {
socket_internal_t *temp_socket; socket_internal_t *temp_socket;
for(int i = 1; i < MAX_SOCKETS + 1; i++) { for (int i = 1; i < MAX_SOCKETS + 1; i++) {
temp_socket = getSocket(i); temp_socket = getSocket(i);
if((temp_socket != NULL) && if ((temp_socket != NULL) &&
(ipv6_get_addr_match(&temp_socket->socket_values.foreign_address.sin6_addr, (ipv6_get_addr_match(&temp_socket->socket_values.foreign_address.sin6_addr,
&current_ipv6_header->srcaddr) == 128) && &current_ipv6_header->srcaddr) == 128) &&
(ipv6_get_addr_match(&temp_socket->socket_values.local_address.sin6_addr, (ipv6_get_addr_match(&temp_socket->socket_values.local_address.sin6_addr,
@ -56,7 +56,7 @@ void update_tcp_hc_context(bool incoming, socket_internal_t *current_socket,
tcp_hc_context_t *current_context = tcp_hc_context_t *current_context =
&current_socket->socket_values.tcp_control.tcp_context; &current_socket->socket_values.tcp_control.tcp_context;
if(incoming) { if (incoming) {
current_context->ack_rcv = current_tcp_packet->ack_nr; current_context->ack_rcv = current_tcp_packet->ack_nr;
current_context->seq_rcv = current_tcp_packet->seq_nr; current_context->seq_rcv = current_tcp_packet->seq_nr;
current_context->wnd_rcv = current_tcp_packet->window; current_context->wnd_rcv = current_tcp_packet->window;
@ -81,7 +81,7 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket,
uint16_t packet_size = 0; uint16_t packet_size = 0;
/* Connection establisment phase, use FULL_HEADER TCP */ /* Connection establisment phase, use FULL_HEADER TCP */
if(tcp_context->hc_type == FULL_HEADER) { if (tcp_context->hc_type == FULL_HEADER) {
/* draft-aayadi-6lowpan-tcphc-01: 5.1 Full header TCP segment. /* draft-aayadi-6lowpan-tcphc-01: 5.1 Full header TCP segment.
* Establishing Connection */ * Establishing Connection */
@ -111,7 +111,7 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket,
return packet_size; return packet_size;
} }
/* Check for header compression type: COMPRESSED_HEADER */ /* Check for header compression type: COMPRESSED_HEADER */
else if(tcp_context->hc_type == COMPRESSED_HEADER) { else if (tcp_context->hc_type == COMPRESSED_HEADER) {
/* draft-aayadi-6lowpan-tcphc-01: 5.1 Compressed header TCP segment. */ /* draft-aayadi-6lowpan-tcphc-01: 5.1 Compressed header TCP segment. */
/* Temporary variable for TCP_HC_Header Bytes */ /* Temporary variable for TCP_HC_Header Bytes */
@ -141,12 +141,12 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket,
/*----------------------------------*/ /*----------------------------------*/
/*| Sequence number handling |*/ /*| Sequence number handling |*/
/*----------------------------------*/ /*----------------------------------*/
if(full_tcp_header.seq_nr == tcp_context->seq_snd) { if (full_tcp_header.seq_nr == tcp_context->seq_snd) {
/* Nothing to do, Seq = (0|0) */ /* Nothing to do, Seq = (0|0) */
} }
/* If the 24 most significant bits haven't changed from previous /* If the 24 most significant bits haven't changed from previous
* packet, don't transmit them */ * packet, don't transmit them */
else if((full_tcp_header.seq_nr & 0xFFFFFF00) == (tcp_context->seq_snd & else if ((full_tcp_header.seq_nr & 0xFFFFFF00) == (tcp_context->seq_snd &
0xFFFFFF00)) { 0xFFFFFF00)) {
/* Seq = (0|1) */ /* Seq = (0|1) */
tcp_hc_header |= 0x0400; tcp_hc_header |= 0x0400;
@ -159,7 +159,7 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket,
} }
/* If the 16 most significant bits haven't changed from previous packet, /* If the 16 most significant bits haven't changed from previous packet,
* don't transmit them */ * don't transmit them */
else if((full_tcp_header.seq_nr & 0xFFFF0000) == (tcp_context->seq_snd & 0xFFFF0000)) { else if ((full_tcp_header.seq_nr & 0xFFFF0000) == (tcp_context->seq_snd & 0xFFFF0000)) {
/* Seq = (1|0) */ /* Seq = (1|0) */
tcp_hc_header |= 0x0800; tcp_hc_header |= 0x0800;
@ -184,17 +184,17 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket,
/*----------------------------------*/ /*----------------------------------*/
/*| Acknowledgment number handling |*/ /*| Acknowledgment number handling |*/
/*----------------------------------*/ /*----------------------------------*/
if((IS_TCP_ACK(full_tcp_header.reserved_flags) && if ((IS_TCP_ACK(full_tcp_header.reserved_flags) &&
(tcp_cb->tcp_context.ack_snd == full_tcp_header.ack_nr))) { (tcp_cb->tcp_context.ack_snd == full_tcp_header.ack_nr))) {
tcp_context->ack_snd = tcp_context->seq_rcv; tcp_context->ack_snd = tcp_context->seq_rcv;
} }
if(full_tcp_header.ack_nr == tcp_context->ack_snd) { if (full_tcp_header.ack_nr == tcp_context->ack_snd) {
/* Nothing to do, Ack = (0|0) */ /* Nothing to do, Ack = (0|0) */
} }
/* If the 24 most significant bits haven't changed from previous packet, /* If the 24 most significant bits haven't changed from previous packet,
* don't transmit them */ * don't transmit them */
else if((full_tcp_header.ack_nr & 0xFFFFFF00) == (tcp_context->ack_snd & else if ((full_tcp_header.ack_nr & 0xFFFFFF00) == (tcp_context->ack_snd &
0xFFFFFF00)) { 0xFFFFFF00)) {
/* Ack = (0|1) */ /* Ack = (0|1) */
tcp_hc_header |= 0x0100; tcp_hc_header |= 0x0100;
@ -207,7 +207,7 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket,
} }
/* If the 16 most significant bits haven't changed from previous packet, /* If the 16 most significant bits haven't changed from previous packet,
* don't transmit them */ * don't transmit them */
else if((full_tcp_header.ack_nr & 0xFFFF0000) == (tcp_context->ack_snd & else if ((full_tcp_header.ack_nr & 0xFFFF0000) == (tcp_context->ack_snd &
0xFFFF0000)) { 0xFFFF0000)) {
/* Ack = (1|0) */ /* Ack = (1|0) */
tcp_hc_header |= 0x0200; tcp_hc_header |= 0x0200;
@ -234,12 +234,12 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket,
/*----------------------------------*/ /*----------------------------------*/
/*| Window handling |*/ /*| Window handling |*/
/*----------------------------------*/ /*----------------------------------*/
if(full_tcp_header.window == tcp_context->wnd_snd) { if (full_tcp_header.window == tcp_context->wnd_snd) {
/* Nothing to do, Wnd = (0|0) */ /* Nothing to do, Wnd = (0|0) */
} }
/* If the 8 most significant bits haven't changed from previous packet, /* If the 8 most significant bits haven't changed from previous packet,
* don't transmit them */ * don't transmit them */
else if((full_tcp_header.window & 0xFF00) == (tcp_context->wnd_snd & 0xFF00)) { else if ((full_tcp_header.window & 0xFF00) == (tcp_context->wnd_snd & 0xFF00)) {
/* Wnd = (0|1) */ /* Wnd = (0|1) */
tcp_hc_header |= 0x0040; tcp_hc_header |= 0x0040;
@ -250,7 +250,7 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket,
} }
/* If the 8 less significant bits haven't changed from previous packet, /* If the 8 less significant bits haven't changed from previous packet,
* don't transmit them */ * don't transmit them */
else if((full_tcp_header.window & 0x00FF) == (tcp_context->wnd_snd & else if ((full_tcp_header.window & 0x00FF) == (tcp_context->wnd_snd &
0x00FF)) { 0x00FF)) {
/* Wnd = (1|0) */ /* Wnd = (1|0) */
tcp_hc_header |= 0x0080; tcp_hc_header |= 0x0080;
@ -273,7 +273,7 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket,
} }
/* FIN flag */ /* FIN flag */
if(IS_TCP_FIN(full_tcp_header.reserved_flags)) { if (IS_TCP_FIN(full_tcp_header.reserved_flags)) {
/* F = (1) */ /* F = (1) */
tcp_hc_header |= 0x0008; tcp_hc_header |= 0x0008;
} }
@ -304,7 +304,7 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket,
return packet_size; return packet_size;
} }
/* Check for header compression type: MOSTLY_COMPRESSED_HEADER */ /* Check for header compression type: MOSTLY_COMPRESSED_HEADER */
else if(tcp_context->hc_type == MOSTLY_COMPRESSED_HEADER) { else if (tcp_context->hc_type == MOSTLY_COMPRESSED_HEADER) {
/* draft-aayadi-6lowpan-tcphc-01: 5.1 Compressed header TCP segment. */ /* draft-aayadi-6lowpan-tcphc-01: 5.1 Compressed header TCP segment. */
/* Temporary variable for TCP_HC_Header Bytes */ /* Temporary variable for TCP_HC_Header Bytes */
@ -369,7 +369,7 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket,
packet_size += 2; packet_size += 2;
/* FIN flag */ /* FIN flag */
if(IS_TCP_FIN(full_tcp_header.reserved_flags)) { if (IS_TCP_FIN(full_tcp_header.reserved_flags)) {
/* F = (1) */ /* F = (1) */
tcp_hc_header |= 0x0008; tcp_hc_header |= 0x0008;
} }
@ -410,15 +410,15 @@ socket_internal_t *decompress_tcp_packet(ipv6_hdr_t *temp_ipv6_header)
uint16_t packet_size = 0; uint16_t packet_size = 0;
/* Full header TCP segment */ /* Full header TCP segment */
if(*(((uint8_t *)temp_ipv6_header) + IPV6_HDR_LEN) == 0x01) { if (*(((uint8_t *)temp_ipv6_header) + IPV6_HDR_LEN) == 0x01) {
switch_tcp_packet_byte_order(((tcp_hdr_t *)(((uint8_t *)temp_ipv6_header) + switch_tcp_packet_byte_order(((tcp_hdr_t *)(((uint8_t *)temp_ipv6_header) +
IPV6_HDR_LEN + 3))); IPV6_HDR_LEN + 3)));
current_socket = get_tcp_socket(temp_ipv6_header, current_socket = get_tcp_socket(temp_ipv6_header,
((tcp_hdr_t *)(((uint8_t *)temp_ipv6_header) + ((tcp_hdr_t *)(((uint8_t *)temp_ipv6_header) +
IPV6_HDR_LEN + 3))); IPV6_HDR_LEN + 3)));
if(current_socket != NULL) { if (current_socket != NULL) {
if(current_socket->socket_values.tcp_control.state == LISTEN) { if (current_socket->socket_values.tcp_control.state == LISTEN) {
memcpy(&current_socket->socket_values.tcp_control.tcp_context.context_id, memcpy(&current_socket->socket_values.tcp_control.tcp_context.context_id,
((uint8_t *)temp_ipv6_header) + IPV6_HDR_LEN + 1, 2); ((uint8_t *)temp_ipv6_header) + IPV6_HDR_LEN + 1, 2);
current_socket->socket_values.tcp_control.tcp_context.context_id = current_socket->socket_values.tcp_control.tcp_context.context_id =
@ -455,11 +455,11 @@ socket_internal_t *decompress_tcp_packet(ipv6_hdr_t *temp_ipv6_header)
uint8_t header_type = UNDEFINED; uint8_t header_type = UNDEFINED;
if(BITSET(tcp_hc_header, 15) && !BITSET(tcp_hc_header, 14) && if (BITSET(tcp_hc_header, 15) && !BITSET(tcp_hc_header, 14) &&
!BITSET(tcp_hc_header, 13)) { !BITSET(tcp_hc_header, 13)) {
header_type = MOSTLY_COMPRESSED_HEADER; header_type = MOSTLY_COMPRESSED_HEADER;
} }
else if(BITSET(tcp_hc_header, 15) && BITSET(tcp_hc_header, 14) && else if (BITSET(tcp_hc_header, 15) && BITSET(tcp_hc_header, 14) &&
!BITSET(tcp_hc_header, 13)) { !BITSET(tcp_hc_header, 13)) {
header_type = COMPRESSED_HEADER; header_type = COMPRESSED_HEADER;
} }
@ -472,7 +472,7 @@ socket_internal_t *decompress_tcp_packet(ipv6_hdr_t *temp_ipv6_header)
socket_internal_t *current_socket = socket_internal_t *current_socket =
get_tcp_socket_by_context(temp_ipv6_header, current_context); get_tcp_socket_by_context(temp_ipv6_header, current_context);
if(current_socket == NULL) { if (current_socket == NULL) {
printf("Current Socket == NULL!\n"); printf("Current Socket == NULL!\n");
return NULL; return NULL;
} }
@ -484,12 +484,12 @@ socket_internal_t *decompress_tcp_packet(ipv6_hdr_t *temp_ipv6_header)
/*----------------------------------*/ /*----------------------------------*/
/*| Sequence number handling |*/ /*| Sequence number handling |*/
/*----------------------------------*/ /*----------------------------------*/
if(!BITSET(tcp_hc_header, 11) && !BITSET(tcp_hc_header, 10)) { if (!BITSET(tcp_hc_header, 11) && !BITSET(tcp_hc_header, 10)) {
/* Seq = (0|0), sequence number didn't change, copy old value */ /* Seq = (0|0), sequence number didn't change, copy old value */
memcpy(&full_tcp_header.seq_nr, &current_tcp_context->seq_rcv, 4); memcpy(&full_tcp_header.seq_nr, &current_tcp_context->seq_rcv, 4);
} }
/* The 24 most significant bits haven't changed from previous packet */ /* The 24 most significant bits haven't changed from previous packet */
else if(!BITSET(tcp_hc_header, 11) && BITSET(tcp_hc_header, 10)) { else if (!BITSET(tcp_hc_header, 11) && BITSET(tcp_hc_header, 10)) {
/* Seq = (0|1), copy 1 byte of tcp_hc packet and 3 bytes from /* Seq = (0|1), copy 1 byte of tcp_hc packet and 3 bytes from
* previous packet */ * previous packet */
full_tcp_header.seq_nr |= *packet_buffer; full_tcp_header.seq_nr |= *packet_buffer;
@ -499,7 +499,7 @@ socket_internal_t *decompress_tcp_packet(ipv6_hdr_t *temp_ipv6_header)
packet_size += 1; packet_size += 1;
} }
/* If the 16 most significant bits haven't changed from previous packet */ /* If the 16 most significant bits haven't changed from previous packet */
else if(BITSET(tcp_hc_header, 11) && !BITSET(tcp_hc_header, 10)) { else if (BITSET(tcp_hc_header, 11) && !BITSET(tcp_hc_header, 10)) {
/* Seq = (1|0), copy 2 bytes of tcp_hc packet and 2 bytes from /* Seq = (1|0), copy 2 bytes of tcp_hc packet and 2 bytes from
* previous packet */ * previous packet */
full_tcp_header.seq_nr |= NTOHS(*((uint16_t *)packet_buffer)); full_tcp_header.seq_nr |= NTOHS(*((uint16_t *)packet_buffer));
@ -519,12 +519,12 @@ socket_internal_t *decompress_tcp_packet(ipv6_hdr_t *temp_ipv6_header)
/*----------------------------------*/ /*----------------------------------*/
/*| Acknowledgment number handling |*/ /*| Acknowledgment number handling |*/
/*----------------------------------*/ /*----------------------------------*/
if(!BITSET(tcp_hc_header, 9) && !BITSET(tcp_hc_header, 8)) { if (!BITSET(tcp_hc_header, 9) && !BITSET(tcp_hc_header, 8)) {
/* Ack = (0|0), acknowledgment number didn't change, copy old value */ /* Ack = (0|0), acknowledgment number didn't change, copy old value */
memcpy(&full_tcp_header.ack_nr, &current_tcp_context->ack_rcv, 4); memcpy(&full_tcp_header.ack_nr, &current_tcp_context->ack_rcv, 4);
} }
/* The 24 most significant bits haven't changed from previous packet */ /* The 24 most significant bits haven't changed from previous packet */
else if(!BITSET(tcp_hc_header, 9) && BITSET(tcp_hc_header, 8)) { else if (!BITSET(tcp_hc_header, 9) && BITSET(tcp_hc_header, 8)) {
/* Ack = (0|1), copy 1 byte of tcp_hc packet and 3 bytes from /* Ack = (0|1), copy 1 byte of tcp_hc packet and 3 bytes from
* previous packet */ * previous packet */
full_tcp_header.ack_nr |= *packet_buffer; full_tcp_header.ack_nr |= *packet_buffer;
@ -534,7 +534,7 @@ socket_internal_t *decompress_tcp_packet(ipv6_hdr_t *temp_ipv6_header)
SET_TCP_ACK(full_tcp_header.reserved_flags); SET_TCP_ACK(full_tcp_header.reserved_flags);
} }
/* If the 16 most significant bits haven't changed from previous packet */ /* If the 16 most significant bits haven't changed from previous packet */
else if(BITSET(tcp_hc_header, 9) && !BITSET(tcp_hc_header, 8)) { else if (BITSET(tcp_hc_header, 9) && !BITSET(tcp_hc_header, 8)) {
/* Ack = (1|0), copy 2 bytes of tcp_hc packet and 2 bytes from /* Ack = (1|0), copy 2 bytes of tcp_hc packet and 2 bytes from
* previous packet */ * previous packet */
full_tcp_header.ack_nr |= NTOHS(*((uint16_t *)packet_buffer)); full_tcp_header.ack_nr |= NTOHS(*((uint16_t *)packet_buffer));
@ -551,7 +551,7 @@ socket_internal_t *decompress_tcp_packet(ipv6_hdr_t *temp_ipv6_header)
packet_buffer += 4; packet_buffer += 4;
packet_size += 4; packet_size += 4;
if(header_type == COMPRESSED_HEADER) { if (header_type == COMPRESSED_HEADER) {
SET_TCP_ACK(full_tcp_header.reserved_flags); SET_TCP_ACK(full_tcp_header.reserved_flags);
} }
} }
@ -559,12 +559,12 @@ socket_internal_t *decompress_tcp_packet(ipv6_hdr_t *temp_ipv6_header)
/*----------------------------------*/ /*----------------------------------*/
/*| Window handling |*/ /*| Window handling |*/
/*----------------------------------*/ /*----------------------------------*/
if(!BITSET(tcp_hc_header, 7) && !BITSET(tcp_hc_header, 6)) { if (!BITSET(tcp_hc_header, 7) && !BITSET(tcp_hc_header, 6)) {
/* Wnd = (0|0), copy old value */ /* Wnd = (0|0), copy old value */
memcpy(&full_tcp_header.window, &current_tcp_context->wnd_rcv, 2); memcpy(&full_tcp_header.window, &current_tcp_context->wnd_rcv, 2);
} }
/* The 8 most significant bits haven't changed from previous packet */ /* The 8 most significant bits haven't changed from previous packet */
else if(!BITSET(tcp_hc_header, 7) && BITSET(tcp_hc_header, 6)) { else if (!BITSET(tcp_hc_header, 7) && BITSET(tcp_hc_header, 6)) {
/* Wnd = (0|1), copy 1 byte of tcp_hc packet and 1 byte from /* Wnd = (0|1), copy 1 byte of tcp_hc packet and 1 byte from
* previous packet */ * previous packet */
full_tcp_header.window |= *packet_buffer; full_tcp_header.window |= *packet_buffer;
@ -573,7 +573,7 @@ socket_internal_t *decompress_tcp_packet(ipv6_hdr_t *temp_ipv6_header)
packet_size += 1; packet_size += 1;
} }
/* If the 8 less significant bits haven't changed from previous packet */ /* If the 8 less significant bits haven't changed from previous packet */
else if(BITSET(tcp_hc_header, 7) && !BITSET(tcp_hc_header, 6)) { else if (BITSET(tcp_hc_header, 7) && !BITSET(tcp_hc_header, 6)) {
/* Wnd = (1|0), copy 1 byte of tcp_hc packet and 1 byte from previous packet */ /* Wnd = (1|0), copy 1 byte of tcp_hc packet and 1 byte from previous packet */
full_tcp_header.window |= ((*((uint16_t *)packet_buffer)) & 0xFF00); full_tcp_header.window |= ((*((uint16_t *)packet_buffer)) & 0xFF00);
full_tcp_header.window |= ((current_tcp_context->wnd_rcv) & 0x00FF); full_tcp_header.window |= ((current_tcp_context->wnd_rcv) & 0x00FF);
@ -590,9 +590,9 @@ socket_internal_t *decompress_tcp_packet(ipv6_hdr_t *temp_ipv6_header)
} }
/* FIN flag */ /* FIN flag */
if(BITSET(tcp_hc_header, 3)) { if (BITSET(tcp_hc_header, 3)) {
/* F = (1) */ /* F = (1) */
if(IS_TCP_ACK(full_tcp_header.reserved_flags)) { if (IS_TCP_ACK(full_tcp_header.reserved_flags)) {
SET_TCP_FIN_ACK(full_tcp_header.reserved_flags); SET_TCP_FIN_ACK(full_tcp_header.reserved_flags);
} }
else { else {

View File

@ -33,25 +33,25 @@ void handle_synchro_timeout(socket_internal_t *current_socket)
{ {
msg_t send; msg_t send;
if(thread_getstatus(current_socket->recv_pid) == STATUS_RECEIVE_BLOCKED) { if (thread_getstatus(current_socket->recv_pid) == STATUS_RECEIVE_BLOCKED) {
timex_t now; timex_t now;
vtimer_now(&now); vtimer_now(&now);
if((current_socket->socket_values.tcp_control.no_of_retries == 0) && if ((current_socket->socket_values.tcp_control.no_of_retries == 0) &&
(timex_sub(now, (timex_sub(now,
current_socket->socket_values.tcp_control.last_packet_time).microseconds > current_socket->socket_values.tcp_control.last_packet_time).microseconds >
TCP_SYN_INITIAL_TIMEOUT)) { TCP_SYN_INITIAL_TIMEOUT)) {
current_socket->socket_values.tcp_control.no_of_retries++; current_socket->socket_values.tcp_control.no_of_retries++;
net_msg_send(&send, current_socket->recv_pid, 0, TCP_RETRY); net_msg_send(&send, current_socket->recv_pid, 0, TCP_RETRY);
} }
else if((current_socket->socket_values.tcp_control.no_of_retries > 0) && else if ((current_socket->socket_values.tcp_control.no_of_retries > 0) &&
(timex_sub(now, (timex_sub(now,
current_socket->socket_values.tcp_control.last_packet_time).microseconds > current_socket->socket_values.tcp_control.last_packet_time).microseconds >
(current_socket->socket_values.tcp_control.no_of_retries * (current_socket->socket_values.tcp_control.no_of_retries *
TCP_SYN_TIMEOUT + TCP_SYN_INITIAL_TIMEOUT))) { TCP_SYN_TIMEOUT + TCP_SYN_INITIAL_TIMEOUT))) {
current_socket->socket_values.tcp_control.no_of_retries++; current_socket->socket_values.tcp_control.no_of_retries++;
if(current_socket->socket_values.tcp_control.no_of_retries > if (current_socket->socket_values.tcp_control.no_of_retries >
TCP_MAX_SYN_RETRIES) { TCP_MAX_SYN_RETRIES) {
net_msg_send(&send, current_socket->recv_pid, 0, TCP_TIMEOUT); net_msg_send(&send, current_socket->recv_pid, 0, TCP_TIMEOUT);
} }
@ -67,16 +67,16 @@ void handle_established(socket_internal_t *current_socket)
msg_t send; msg_t send;
double current_timeout = current_socket->socket_values.tcp_control.rto; double current_timeout = current_socket->socket_values.tcp_control.rto;
if(current_timeout < SECOND) { if (current_timeout < SECOND) {
current_timeout = SECOND; current_timeout = SECOND;
} }
uint8_t i; uint8_t i;
if((current_socket->socket_values.tcp_control.send_nxt > if ((current_socket->socket_values.tcp_control.send_nxt >
current_socket->socket_values.tcp_control.send_una) && current_socket->socket_values.tcp_control.send_una) &&
(thread_getstatus(current_socket->send_pid) == STATUS_RECEIVE_BLOCKED)) { (thread_getstatus(current_socket->send_pid) == STATUS_RECEIVE_BLOCKED)) {
for(i = 0; i < current_socket->socket_values.tcp_control.no_of_retries; for (i = 0; i < current_socket->socket_values.tcp_control.no_of_retries;
i++) { i++) {
current_timeout *= 2; current_timeout *= 2;
} }
@ -84,10 +84,10 @@ void handle_established(socket_internal_t *current_socket)
timex_t now; timex_t now;
vtimer_now(&now); vtimer_now(&now);
if(current_timeout > TCP_ACK_MAX_TIMEOUT) { if (current_timeout > TCP_ACK_MAX_TIMEOUT) {
net_msg_send(&send, current_socket->send_pid, 0, TCP_TIMEOUT); net_msg_send(&send, current_socket->send_pid, 0, TCP_TIMEOUT);
} }
else if(timex_sub(now, current_socket->socket_values.tcp_control.last_packet_time).microseconds > else if (timex_sub(now, current_socket->socket_values.tcp_control.last_packet_time).microseconds >
current_timeout) { current_timeout) {
current_socket->socket_values.tcp_control.no_of_retries++; current_socket->socket_values.tcp_control.no_of_retries++;
net_msg_send(&send, current_socket->send_pid, 0, TCP_RETRY); net_msg_send(&send, current_socket->send_pid, 0, TCP_RETRY);
@ -100,10 +100,10 @@ void check_sockets(void)
socket_internal_t *current_socket; socket_internal_t *current_socket;
uint8_t i = 1; uint8_t i = 1;
while(i < MAX_SOCKETS + 1) { while (i < MAX_SOCKETS + 1) {
current_socket = getSocket(i); current_socket = getSocket(i);
if(isTCPSocket(i)) { if (isTCPSocket(i)) {
switch(current_socket->socket_values.tcp_control.state) { switch(current_socket->socket_values.tcp_control.state) {
case ESTABLISHED: { case ESTABLISHED: {
handle_established(current_socket); handle_established(current_socket);
@ -147,7 +147,7 @@ void tcp_general_timer(void)
vtimer_t tcp_vtimer; vtimer_t tcp_vtimer;
timex_t interval = timex_set(0, TCP_TIMER_RESOLUTION); timex_t interval = timex_set(0, TCP_TIMER_RESOLUTION);
while(1) { while (1) {
inc_global_variables(); inc_global_variables();
check_sockets(); check_sockets();
vtimer_set_wakeup(&tcp_vtimer, interval, thread_getpid()); vtimer_set_wakeup(&tcp_vtimer, interval, thread_getpid());

View File

@ -49,7 +49,7 @@ void udp_packet_handler(void)
socket_internal_t *udp_socket = NULL; socket_internal_t *udp_socket = NULL;
uint16_t chksum; uint16_t chksum;
while(1) { while (1) {
msg_receive(&m_recv_ip); msg_receive(&m_recv_ip);
ipv6_header = ((ipv6_hdr_t *)m_recv_ip.content.ptr); ipv6_header = ((ipv6_hdr_t *)m_recv_ip.content.ptr);
udp_header = ((udp_hdr_t *)(m_recv_ip.content.ptr + IPV6_HDR_LEN)); udp_header = ((udp_hdr_t *)(m_recv_ip.content.ptr + IPV6_HDR_LEN));
@ -57,10 +57,10 @@ void udp_packet_handler(void)
chksum = udp_csum(ipv6_header, udp_header); chksum = udp_csum(ipv6_header, udp_header);
if(chksum == 0xffff) { if (chksum == 0xffff) {
udp_socket = get_udp_socket(ipv6_header, udp_header); udp_socket = get_udp_socket(ipv6_header, udp_header);
if(udp_socket != NULL) { if (udp_socket != NULL) {
m_send_udp.content.ptr = (char *)ipv6_header; m_send_udp.content.ptr = (char *)ipv6_header;
msg_send_receive(&m_send_udp, &m_recv_udp, udp_socket->recv_pid); msg_send_receive(&m_send_udp, &m_recv_udp, udp_socket->recv_pid);
} }

View File

@ -144,18 +144,18 @@ static void rt_extract_routes(uint16_t local_addr, uint8_t length, uint16_t *lis
uint16_t net_id = NETWORK_ADDR_BC(list[0]); /* BC address of source of RREQ */ uint16_t net_id = NETWORK_ADDR_BC(list[0]); /* BC address of source of RREQ */
route_table_entry_t *rte = rt_lookup_route(net_id); /* Should exist (preconfigured) */ route_table_entry_t *rte = rt_lookup_route(net_id); /* Should exist (preconfigured) */
if(rte == NULL) { if (rte == NULL) {
DEBUG("exit [%u]: rt_extract_routes\n", fk_thread->pid); DEBUG("exit [%u]: rt_extract_routes\n", fk_thread->pid);
return; /* else exit here */ return; /* else exit here */
} }
int i = 0; int i = 0;
while(i < length && list[i] != local_addr) { while (i < length && list[i] != local_addr) {
i++; i++;
} }
if(i == length) { if (i == length) {
DEBUG("exit [%u]: rt_extract_routes\n", fk_thread->pid); DEBUG("exit [%u]: rt_extract_routes\n", fk_thread->pid);
return; return;
} }
@ -164,24 +164,24 @@ static void rt_extract_routes(uint16_t local_addr, uint8_t length, uint16_t *lis
int leftNeighbour = -1; int leftNeighbour = -1;
int rightNeighbour = -1; int rightNeighbour = -1;
if(pos > 0) { if (pos > 0) {
leftNeighbour = list[pos - 1]; leftNeighbour = list[pos - 1];
} }
if(pos + 1 != length) { if (pos + 1 != length) {
rightNeighbour = list[pos + 1]; rightNeighbour = list[pos + 1];
} }
i = 0; i = 0;
while(i < length) { while (i < length) {
uint16_t next = list[i]; uint16_t next = list[i];
if(local_addr != next) { if (local_addr != next) {
int distance = pos - i; int distance = pos - i;
int router = leftNeighbour; int router = leftNeighbour;
if(distance < 0) { if (distance < 0) {
router = rightNeighbour; router = rightNeighbour;
distance *= -1; distance *= -1;
} }
@ -217,8 +217,8 @@ static message_queue_entry_t *mq_add(net_message_t *msg)
/* Find the first active RREQ to this destination */ /* Find the first active RREQ to this destination */
int i; int i;
for(i = 0; i < MESSAGE_QUEUE_SIZE; i++) { for (i = 0; i < MESSAGE_QUEUE_SIZE; i++) {
if(message_queue[i].timestamp != 0 && if (message_queue[i].timestamp != 0 &&
message_queue[i].message.destination == msg->destination && message_queue[i].message.destination == msg->destination &&
message_queue[i].retry_count != RREQ_NONE) { message_queue[i].retry_count != RREQ_NONE) {
DEBUG("%s FOUND Duplicated Request to %u.%u in route req queue\n", DEBUG("%s FOUND Duplicated Request to %u.%u in route req queue\n",
@ -234,19 +234,19 @@ static message_queue_entry_t *mq_add(net_message_t *msg)
* even if the new message will get dropped later on because of * even if the new message will get dropped later on because of
* limited queue space. Route to this destination gets queried * limited queue space. Route to this destination gets queried
* again for sure so make new RREQ as soon as possible... */ * again for sure so make new RREQ as soon as possible... */
if(pFirstFoundDup != NULL) { if (pFirstFoundDup != NULL) {
pFirstFoundDup->retry_count = 0; pFirstFoundDup->retry_count = 0;
pFirstFoundDup->timestamp = 1; pFirstFoundDup->timestamp = 1;
mmr_stats.rreq_duplicated++; mmr_stats.rreq_duplicated++;
} }
/* Find free position to insert new message */ /* Find free position to insert new message */
for(i = 0; i < MESSAGE_QUEUE_SIZE; i++) { for (i = 0; i < MESSAGE_QUEUE_SIZE; i++) {
if(message_queue[i].timestamp == 0) { if (message_queue[i].timestamp == 0) {
/* Free position found, add entry */ /* Free position found, add entry */
message_queue[i].message = *msg; message_queue[i].message = *msg;
if(pFirstFoundDup != NULL) { if (pFirstFoundDup != NULL) {
/* There is already a RREQ for this destination, so don't /* There is already a RREQ for this destination, so don't
* generate a new one */ * generate a new one */
message_queue[i].retry_count = RREQ_NONE; message_queue[i].retry_count = RREQ_NONE;
@ -278,8 +278,8 @@ static int mq_msgs_for_destination(uint16_t dst)
DEBUG("call [%u]: mq_msgs_for_destination\n", fk_thread->pid); DEBUG("call [%u]: mq_msgs_for_destination\n", fk_thread->pid);
int i, dst_count = 0; int i, dst_count = 0;
for(i = 0; i < MESSAGE_QUEUE_SIZE; i++) { for (i = 0; i < MESSAGE_QUEUE_SIZE; i++) {
if(message_queue[i].timestamp != 0 && if (message_queue[i].timestamp != 0 &&
message_queue[i].message.destination == dst) { message_queue[i].message.destination == dst) {
dst_count++; dst_count++;
} }
@ -299,8 +299,8 @@ static void mq_remove_msgs_for_destination(uint16_t dst)
DEBUG("call [%u]: mq_remove_msgs_for_destination\n", fk_thread->pid); DEBUG("call [%u]: mq_remove_msgs_for_destination\n", fk_thread->pid);
int i; int i;
for(i = 0; i < MESSAGE_QUEUE_SIZE; i++) { for (i = 0; i < MESSAGE_QUEUE_SIZE; i++) {
if(message_queue[i].timestamp != 0 && if (message_queue[i].timestamp != 0 &&
message_queue[i].message.destination == dst) { message_queue[i].message.destination == dst) {
message_queue[i].timestamp = 0; message_queue[i].timestamp = 0;
} }
@ -326,15 +326,15 @@ static void mq_dequeue_and_send(uint16_t dst)
/* Prioritize packets for given destination, route entry should exist */ /* Prioritize packets for given destination, route entry should exist */
route_table_entry_t *rte = rt_lookup_route(dst); route_table_entry_t *rte = rt_lookup_route(dst);
if(rte != NULL) { if (rte != NULL) {
for(i = 0; i < MESSAGE_QUEUE_SIZE; i++) { for (i = 0; i < MESSAGE_QUEUE_SIZE; i++) {
if(message_queue[i].timestamp != 0 && if (message_queue[i].timestamp != 0 &&
message_queue[i].message.destination == dst) { message_queue[i].message.destination == dst) {
bool res = net_enqueue_for_transmission(&message_queue[i].message, bool res = net_enqueue_for_transmission(&message_queue[i].message,
rte->interface_id, rte->interface_id,
rte->gateway, true); rte->gateway, true);
if(res) { if (res) {
message_queue[i].timestamp = 0; message_queue[i].timestamp = 0;
} }
} }
@ -342,17 +342,17 @@ static void mq_dequeue_and_send(uint16_t dst)
} }
/* Now all other packets */ /* Now all other packets */
for(i = 0; i < MESSAGE_QUEUE_SIZE; i++) { for (i = 0; i < MESSAGE_QUEUE_SIZE; i++) {
if(message_queue[i].timestamp != 0 && if (message_queue[i].timestamp != 0 &&
message_queue[i].message.destination != dst) { message_queue[i].message.destination != dst) {
route_table_entry_t *rte = rt_lookup_route(message_queue[i].message.destination); route_table_entry_t *rte = rt_lookup_route(message_queue[i].message.destination);
if(rte != NULL) { if (rte != NULL) {
bool res = net_enqueue_for_transmission(&message_queue[i].message, bool res = net_enqueue_for_transmission(&message_queue[i].message,
rte->interface_id, rte->interface_id,
rte->gateway, true); rte->gateway, true);
if(res) { if (res) {
message_queue[i].timestamp = 0; message_queue[i].timestamp = 0;
} }
} }
@ -390,9 +390,9 @@ void mmr_init(void)
*/ */
static bool is_route_error(net_message_t *msg) static bool is_route_error(net_message_t *msg)
{ {
if(msg->protocol == LAYER_2_PROTOCOL_MMR) { if (msg->protocol == LAYER_2_PROTOCOL_MMR) {
/* First byte in {RREQ, RREP, RERR} is always type */ /* First byte in {RREQ, RREP, RERR} is always type */
if(msg->payload[0] == MMR_TYPE_RERR) { if (msg->payload[0] == MMR_TYPE_RERR) {
return true; return true;
} }
} }
@ -430,7 +430,7 @@ static void generate_route_reply_message(mmr_rreq_message_t *rreq_msg)
/* interface id and next hop (should be created by RREQ) */ /* interface id and next hop (should be created by RREQ) */
route_table_entry_t *rte = rt_lookup_route(net_msg.destination); route_table_entry_t *rte = rt_lookup_route(net_msg.destination);
if(rte != NULL) { if (rte != NULL) {
/* Send message to next hop */ /* Send message to next hop */
mmr_stats.rrep_originated++; mmr_stats.rrep_originated++;
net_enqueue_for_transmission(&net_msg, rte->interface_id, rte->gateway, true); net_enqueue_for_transmission(&net_msg, rte->interface_id, rte->gateway, true);
@ -486,7 +486,7 @@ static void receive_route_request_message(mmr_rreq_message_t *msg,
uint16_t my_addr = net_get_address_in_subnet(msg->source); uint16_t my_addr = net_get_address_in_subnet(msg->source);
#if (MMR_INFO_LEVEL >= LEVEL_WARN) #if (MMR_INFO_LEVEL >= LEVEL_WARN)
if(my_addr == 0) { if (my_addr == 0) {
puts("MMR [WARN]: received RREQ with unknown network part of source address"); puts("MMR [WARN]: received RREQ with unknown network part of source address");
puts("MMR [WARN]: => can't find own net address in sub net!"); puts("MMR [WARN]: => can't find own net address in sub net!");
} }
@ -494,7 +494,7 @@ static void receive_route_request_message(mmr_rreq_message_t *msg,
#endif #endif
/* If address list of RREQ message has enough space */ /* If address list of RREQ message has enough space */
if(msg->length < ADDRESS_LIST_SIZE) { if (msg->length < ADDRESS_LIST_SIZE) {
/* append our node id to list */ /* append our node id to list */
msg->address[msg->length++] = my_addr; msg->address[msg->length++] = my_addr;
/* add routes with overhearing */ /* add routes with overhearing */
@ -509,7 +509,7 @@ static void receive_route_request_message(mmr_rreq_message_t *msg,
} }
/* If RREQ message was send to us, then send RREP message */ /* If RREQ message was send to us, then send RREP message */
if(msg->destination == my_addr) { if (msg->destination == my_addr) {
/* Don't forward RREQ packet any further => set TTL to zero */ /* Don't forward RREQ packet any further => set TTL to zero */
*packet_info->ttl_ptr = 0; *packet_info->ttl_ptr = 0;
generate_route_reply_message(msg); generate_route_reply_message(msg);
@ -572,7 +572,7 @@ static int compute_rreq_timeout(int ttl, uint16_t dst)
{ {
int t_hop = net_get_interface_transmission_duration(dst); int t_hop = net_get_interface_transmission_duration(dst);
if(t_hop == -1) { if (t_hop == -1) {
t_hop = RREQ_TIMEOUT_PER_TTL * ttl; t_hop = RREQ_TIMEOUT_PER_TTL * ttl;
} }
else { else {
@ -595,7 +595,7 @@ static void rreq_broadcast(message_queue_entry_t *mq_entry)
{ {
DEBUG("call [%u]: rreq_broadcast\n", fk_thread->pid); DEBUG("call [%u]: rreq_broadcast\n", fk_thread->pid);
if(mq_entry->retry_count == RREQ_NONE) { if (mq_entry->retry_count == RREQ_NONE) {
DEBUG("call [%u]: rreq duplicated do not send\n", fk_thread->pid); DEBUG("call [%u]: rreq duplicated do not send\n", fk_thread->pid);
return; return;
} }
@ -624,7 +624,7 @@ static void rreq_broadcast(message_queue_entry_t *mq_entry)
/* Find the broadcast route table entry */ /* Find the broadcast route table entry */
route_table_entry_t *rte = rt_lookup_route(net_msg.destination); route_table_entry_t *rte = rt_lookup_route(net_msg.destination);
if(rte != NULL) { if (rte != NULL) {
/* Next hop address is broadcast address of lower layer */ /* Next hop address is broadcast address of lower layer */
net_enqueue_for_transmission(&net_msg, rte->interface_id, net_enqueue_for_transmission(&net_msg, rte->interface_id,
rte->gateway, true); rte->gateway, true);
@ -643,21 +643,21 @@ static void post_next_rreq_timeout(void)
int i, j = -1; int i, j = -1;
uint32_t now, next = 0xffffffff; uint32_t now, next = 0xffffffff;
for(i = 0; i < MESSAGE_QUEUE_SIZE; i++) { for (i = 0; i < MESSAGE_QUEUE_SIZE; i++) {
if((message_queue[i].timestamp != 0) && (message_queue[i].retry_count != if ((message_queue[i].timestamp != 0) && (message_queue[i].retry_count !=
RREQ_NONE)) { RREQ_NONE)) {
int ttl = message_queue[i].retry_count == 1 ? TTL_START : TTL_THRESHOLD; int ttl = message_queue[i].retry_count == 1 ? TTL_START : TTL_THRESHOLD;
int to = compute_rreq_timeout(ttl, int to = compute_rreq_timeout(ttl,
message_queue[i].message.destination); message_queue[i].message.destination);
if(message_queue[i].timestamp + to < next) { if (message_queue[i].timestamp + to < next) {
next = message_queue[i].timestamp + to; next = message_queue[i].timestamp + to;
j = i; j = i;
} }
} }
} }
if(j == -1) { if (j == -1) {
DEBUG("exit [%u]: post_next_rreq_timeout\n", fk_thread->pid); DEBUG("exit [%u]: post_next_rreq_timeout\n", fk_thread->pid);
return; return;
} }
@ -668,14 +668,14 @@ static void post_next_rreq_timeout(void)
/* If current time greater than RREQ timeout value */ /* If current time greater than RREQ timeout value */
now = rtc_now(); now = rtc_now();
if(now >= next) { if (now >= next) {
/* Schedule RREQ-Timeout immediately */ /* Schedule RREQ-Timeout immediately */
msg m; msg m;
m.type = MSG_TIMER; m.type = MSG_TIMER;
m.content.ptr = (char *)&message_queue[j]; m.content.ptr = (char *)&message_queue[j];
rreq_to_active = true; rreq_to_active = true;
if(msg_send(&m, rreq_timeout_process_pid, false) != 1) { if (msg_send(&m, rreq_timeout_process_pid, false) != 1) {
/* Message could not be send (receiver not waiting), schedule /* Message could not be send (receiver not waiting), schedule
* timer with minimum delay */ * timer with minimum delay */
#if (MMR_INFO_LEVEL >= LEVEL_WARN) #if (MMR_INFO_LEVEL >= LEVEL_WARN)
@ -706,7 +706,7 @@ static void rreq_timeout(message_queue_entry_t *mqe)
DEBUG("call [%u]: rreq_timeout\n", fk_thread->pid); DEBUG("call [%u]: rreq_timeout\n", fk_thread->pid);
/* Test if valid entry passed */ /* Test if valid entry passed */
if(mqe->timestamp == 0) { if (mqe->timestamp == 0) {
#if (MMR_INFO_LEVEL >= LEVEL_WARN) #if (MMR_INFO_LEVEL >= LEVEL_WARN)
puts("MMR [WARN]: invalid message queue entry for RREQ-Timeout"); puts("MMR [WARN]: invalid message queue entry for RREQ-Timeout");
#endif #endif
@ -718,11 +718,11 @@ static void rreq_timeout(message_queue_entry_t *mqe)
/* If found and no messages in queue for destination: return (queued /* If found and no messages in queue for destination: return (queued
* packets are send on reception of RREP); If found but messages in queue: * packets are send on reception of RREP); If found but messages in queue:
* trigger send immediately here! */ * trigger send immediately here!*/
if(rte != NULL) { if (rte != NULL) {
int msg_count = mq_msgs_for_destination(mqe->message.destination); int msg_count = mq_msgs_for_destination(mqe->message.destination);
if(msg_count > 0) { if (msg_count > 0) {
mq_dequeue_and_send(mqe->message.destination); mq_dequeue_and_send(mqe->message.destination);
DEBUG("exit [%u]: rreq_timeout\n", fk_thread->pid); DEBUG("exit [%u]: rreq_timeout\n", fk_thread->pid);
return; return;
@ -739,7 +739,7 @@ static void rreq_timeout(message_queue_entry_t *mqe)
/* Otherwise send new RREQ if below threshold (means also retry count != /* Otherwise send new RREQ if below threshold (means also retry count !=
* RREQ_NONE) */ * RREQ_NONE) */
if(mqe->retry_count < RREQ_THRESHOLD) { if (mqe->retry_count < RREQ_THRESHOLD) {
/* Broadcast new RREQ message (with incremented TTL) */ /* Broadcast new RREQ message (with incremented TTL) */
rreq_broadcast(mqe); rreq_broadcast(mqe);
} }
@ -762,12 +762,12 @@ static void rreq_timeout_process(void)
do { do {
msg_receive(&m); msg_receive(&m);
if(m.type == MSG_TIMER && rreq_to_active) { if (m.type == MSG_TIMER && rreq_to_active) {
rreq_to_active = false; rreq_to_active = false;
rreq_timeout((message_queue_entry_t *)m.content.ptr); rreq_timeout((message_queue_entry_t *)m.content.ptr);
} }
} }
while(m.type != MSG_EXIT); while (m.type != MSG_EXIT);
} }
void mmr_peek(net_message_t *message, packet_info_t *packet_info) void mmr_peek(net_message_t *message, packet_info_t *packet_info)
@ -775,16 +775,16 @@ void mmr_peek(net_message_t *message, packet_info_t *packet_info)
DEBUG("call [%u]: mmr_peek\n", fk_thread->pid); DEBUG("call [%u]: mmr_peek\n", fk_thread->pid);
/* Only look at micro mesh routing messages */ /* Only look at micro mesh routing messages */
if(message->protocol == LAYER_2_PROTOCOL_MMR) { if (message->protocol == LAYER_2_PROTOCOL_MMR) {
uint8_t type = message->payload[0]; uint8_t type = message->payload[0];
uint16_t my_addr = net_get_address_in_subnet(message->source); uint16_t my_addr = net_get_address_in_subnet(message->source);
if(type == MMR_TYPE_RREP) { if (type == MMR_TYPE_RREP) {
/* Add routes to route table */ /* Add routes to route table */
mmr_rrep_message_t *rrep_msg = (mmr_rrep_message_t *)message->payload; mmr_rrep_message_t *rrep_msg = (mmr_rrep_message_t *)message->payload;
#if (MMR_INFO_LEVEL >= LEVEL_WARN) #if (MMR_INFO_LEVEL >= LEVEL_WARN)
if(my_addr == 0) { if (my_addr == 0) {
puts("MMR [WARN]: received RREP with unknown network part of source address"); puts("MMR [WARN]: received RREP with unknown network part of source address");
puts("MMR [WARN]: => can't find own net address in sub net!"); puts("MMR [WARN]: => can't find own net address in sub net!");
} }
@ -792,10 +792,10 @@ void mmr_peek(net_message_t *message, packet_info_t *packet_info)
#endif #endif
rt_extract_routes(my_addr, rrep_msg->length, rrep_msg->address); rt_extract_routes(my_addr, rrep_msg->length, rrep_msg->address);
} }
else if(type == MMR_TYPE_RERR) { else if (type == MMR_TYPE_RERR) {
#if (MMR_INFO_LEVEL >= LEVEL_WARN) #if (MMR_INFO_LEVEL >= LEVEL_WARN)
if(my_addr == 0) { if (my_addr == 0) {
puts("MMR [WARN]: received RERR with unknown network part of source address"); puts("MMR [WARN]: received RERR with unknown network part of source address");
puts("MMR [WARN]: => can't find own net address in sub net!"); puts("MMR [WARN]: => can't find own net address in sub net!");
} }
@ -804,11 +804,11 @@ void mmr_peek(net_message_t *message, packet_info_t *packet_info)
/* If not destination of RERR, then remove route to unavailable /* If not destination of RERR, then remove route to unavailable
* node in RERR packet */ * node in RERR packet */
if(message->destination != my_addr) { if (message->destination != my_addr) {
mmr_rerr_message_t *rerr_msg = mmr_rerr_message_t *rerr_msg =
(mmr_rerr_message_t *)message->payload; (mmr_rerr_message_t *)message->payload;
if(rerr_msg->error_type == RERR_NODE_UNREACHABLE) { if (rerr_msg->error_type == RERR_NODE_UNREACHABLE) {
rt_remove_route(rerr_msg->type_specific_info); rt_remove_route(rerr_msg->type_specific_info);
} }
} }
@ -823,7 +823,7 @@ bool mmr_send(net_message_t *message)
DEBUG("call [%u]: mmr_send\n", fk_thread->pid); DEBUG("call [%u]: mmr_send\n", fk_thread->pid);
bool enqueue = true; bool enqueue = true;
if(message->destination == net_get_address_in_subnet(message->destination)) { if (message->destination == net_get_address_in_subnet(message->destination)) {
#if (MMR_INFO_LEVEL >= LEVEL_WARN) #if (MMR_INFO_LEVEL >= LEVEL_WARN)
puts("MMR [WARN]: message is already at destination, why is routing called?"); puts("MMR [WARN]: message is already at destination, why is routing called?");
#endif #endif
@ -831,7 +831,7 @@ bool mmr_send(net_message_t *message)
return false; return false;
} }
if(NETWORK_ADDR_NET(message->destination) == 0) { if (NETWORK_ADDR_NET(message->destination) == 0) {
#if (MMR_INFO_LEVEL >= LEVEL_WARN) #if (MMR_INFO_LEVEL >= LEVEL_WARN)
puts("MMR [WARN]: NET part of address cannot be 0!"); puts("MMR [WARN]: NET part of address cannot be 0!");
#endif #endif
@ -839,7 +839,7 @@ bool mmr_send(net_message_t *message)
return false; return false;
} }
if(NETWORK_ADDR_HOST(message->destination) == 0) { if (NETWORK_ADDR_HOST(message->destination) == 0) {
#if (MMR_INFO_LEVEL >= LEVEL_INFO) #if (MMR_INFO_LEVEL >= LEVEL_INFO)
puts("MMR [INFO]: broadcast destination, why is routing called? A route entry should exist!"); puts("MMR [INFO]: broadcast destination, why is routing called? A route entry should exist!");
#endif #endif
@ -850,13 +850,13 @@ bool mmr_send(net_message_t *message)
route_table_entry_t *rte = rt_lookup_route(message->destination); route_table_entry_t *rte = rt_lookup_route(message->destination);
/* If next hop address found in routing table, forward message */ /* If next hop address found in routing table, forward message */
if(rte != NULL) { if (rte != NULL) {
DEBUG("exit [%u]: mmr_send\n", fk_thread->pid); DEBUG("exit [%u]: mmr_send\n", fk_thread->pid);
return net_enqueue_for_transmission(message, rte->interface_id, rte->gateway, true); return net_enqueue_for_transmission(message, rte->interface_id, rte->gateway, true);
} }
/* Otherwise, save message in queue; broadcast RREQ message */ /* Otherwise, save message in queue; broadcast RREQ message */
else { else {
if(!enqueue) { if (!enqueue) {
/* Don't enqueue broadcast destinations */ /* Don't enqueue broadcast destinations */
DEBUG("exit [%u]: mmr_send\n", fk_thread->pid); DEBUG("exit [%u]: mmr_send\n", fk_thread->pid);
return false; return false;
@ -864,7 +864,7 @@ bool mmr_send(net_message_t *message)
message_queue_entry_t *mqe = mq_add(message); message_queue_entry_t *mqe = mq_add(message);
if(mqe != NULL) { if (mqe != NULL) {
rreq_broadcast(mqe); rreq_broadcast(mqe);
post_next_rreq_timeout(); post_next_rreq_timeout();
mmr_stats.rreq_originated++; mmr_stats.rreq_originated++;
@ -881,19 +881,19 @@ void mmr_packet_dropped(net_message_t *message, uint16_t next_hop, int error)
{ {
DEBUG("call [%u]: mmr_packet_dropped\n", fk_thread->pid); DEBUG("call [%u]: mmr_packet_dropped\n", fk_thread->pid);
if(error == ROUTE_ERROR_BROKEN_ROUTE) { if (error == ROUTE_ERROR_BROKEN_ROUTE) {
/* Local failure detected - remove all routes through broken link */ /* Local failure detected - remove all routes through broken link */
rt_remove_gateway_routes(next_hop); rt_remove_gateway_routes(next_hop);
mmr_stats.messages_broken_link_on_forward++; mmr_stats.messages_broken_link_on_forward++;
} }
else if(error == ROUTE_ERROR_MISSING_ROUTE) { else if (error == ROUTE_ERROR_MISSING_ROUTE) {
mmr_stats.messages_no_route_avail_on_forward++; mmr_stats.messages_no_route_avail_on_forward++;
} }
/* If source != net_addr, send RERR to source of message */ /* If source != net_addr, send RERR to source of message */
if(message->source != net_get_address_in_subnet(message->source)) { if (message->source != net_get_address_in_subnet(message->source)) {
/* Do not generate RERR if it is already a RERR message */ /* Do not generate RERR if it is already a RERR message */
if(is_route_error(message)) { if (is_route_error(message)) {
DEBUG("exit [%u]: mmr_packet_dropped\n", fk_thread->pid); DEBUG("exit [%u]: mmr_packet_dropped\n", fk_thread->pid);
return; return;
} }
@ -901,7 +901,7 @@ void mmr_packet_dropped(net_message_t *message, uint16_t next_hop, int error)
/* Find next hop to source */ /* Find next hop to source */
route_table_entry_t *rte = rt_lookup_route(message->source); route_table_entry_t *rte = rt_lookup_route(message->source);
if(rte != NULL) { if (rte != NULL) {
generate_route_error_message(message->source, rte->gateway, generate_route_error_message(message->source, rte->gateway,
rte->interface_id, rte->interface_id,
RERR_NODE_UNREACHABLE, RERR_NODE_UNREACHABLE,
@ -926,15 +926,15 @@ void mmr_receive(void *msg, int msg_size, packet_info_t *packet_info)
uint8_t *p = (uint8_t *) msg; uint8_t *p = (uint8_t *) msg;
uint8_t type = p[0]; uint8_t type = p[0];
if(type == MMR_TYPE_RREQ) { if (type == MMR_TYPE_RREQ) {
receive_route_request_message((mmr_rreq_message_t *)msg, packet_info); receive_route_request_message((mmr_rreq_message_t *)msg, packet_info);
mmr_stats.rreq_received++; mmr_stats.rreq_received++;
} }
else if(type == MMR_TYPE_RREP) { else if (type == MMR_TYPE_RREP) {
receive_route_reply_message((mmr_rrep_message_t *)msg, packet_info); receive_route_reply_message((mmr_rrep_message_t *)msg, packet_info);
mmr_stats.rrep_received++; mmr_stats.rrep_received++;
} }
else if(type == MMR_TYPE_RERR) { else if (type == MMR_TYPE_RERR) {
receive_route_error_message((mmr_rerr_message_t *)msg, packet_info); receive_route_error_message((mmr_rerr_message_t *)msg, packet_info);
mmr_stats.rerr_received++; mmr_stats.rerr_received++;
} }

View File

@ -188,45 +188,45 @@ static route_interface_t r_iface = {
ASCCMD(route, CMDFLAG_SERIAL, "[-adfFg] print kernel route table"); ASCCMD(route, CMDFLAG_SERIAL, "[-adfFg] print kernel route table");
CMD_FUNCTION(route, cmdargs) CMD_FUNCTION(route, cmdargs)
{ {
if(cmdargs->arg_size > 0) { if (cmdargs->arg_size > 0) {
char *msg = (char *)cmdargs->args; char *msg = (char *)cmdargs->args;
while(*msg == ' ') { while (*msg == ' ') {
msg++; msg++;
} }
if(*msg == '-' && *(msg + 1) == 'f') { if (*msg == '-' && *(msg + 1) == 'f') {
mms_flush_routes(false); mms_flush_routes(false);
printf("Kernel route table flushed (non-static)!\n"); printf("Kernel route table flushed (non-static)!\n");
return CMD_SUCCESS; return CMD_SUCCESS;
} }
else if(*msg == '-' && *(msg + 1) == 'F') { else if (*msg == '-' && *(msg + 1) == 'F') {
mms_flush_routes(true); mms_flush_routes(true);
printf("Kernel route table flushed (static)!\n"); printf("Kernel route table flushed (static)!\n");
return CMD_SUCCESS; return CMD_SUCCESS;
} }
else if(*msg == '-' && *(msg + 1) == 'd') { else if (*msg == '-' && *(msg + 1) == 'd') {
msg++; msg++;
msg++; msg++;
while(*msg == ' ') { while (*msg == ' ') {
msg++; msg++;
} }
uint16_t address = net_strtoaddr(msg, &msg); uint16_t address = net_strtoaddr(msg, &msg);
if(rt_remove_static_route(address)) { if (rt_remove_static_route(address)) {
printf("Static route deleted successfully!\n"); printf("Static route deleted successfully!\n");
return CMD_SUCCESS; return CMD_SUCCESS;
} }
return CMD_ERROR; return CMD_ERROR;
} }
else if(*msg == '-' && *(msg + 1) == 'g') { else if (*msg == '-' && *(msg + 1) == 'g') {
msg++; msg++;
msg++; msg++;
while(*msg == ' ') { while (*msg == ' ') {
msg++; msg++;
} }
@ -235,11 +235,11 @@ CMD_FUNCTION(route, cmdargs)
printf("%u static route(s) deleted!\n", c); printf("%u static route(s) deleted!\n", c);
return CMD_SUCCESS; return CMD_SUCCESS;
} }
else if(*msg == '-' && *(msg + 1) == 'a') { else if (*msg == '-' && *(msg + 1) == 'a') {
msg++; msg++;
msg++; msg++;
while(*msg == ' ') { while (*msg == ' ') {
msg++; msg++;
} }
@ -248,8 +248,8 @@ CMD_FUNCTION(route, cmdargs)
int metric = (int)strtoul(msg, &msg, 0); int metric = (int)strtoul(msg, &msg, 0);
int iface = (int)strtoul(msg, &msg, 0); int iface = (int)strtoul(msg, &msg, 0);
if(address != 0 && gateway != 0) { if (address != 0 && gateway != 0) {
if(rt_add_static_route(address, gateway, metric, iface)) { if (rt_add_static_route(address, gateway, metric, iface)) {
printf("Static route added successfully!\n"); printf("Static route added successfully!\n");
return CMD_SUCCESS; return CMD_SUCCESS;
} }
@ -281,42 +281,42 @@ CMD_FUNCTION(route, cmdargs)
ASCCMD(ifconfig, CMDFLAG_SERIAL, "[IFACE]: print interface configuration"); ASCCMD(ifconfig, CMDFLAG_SERIAL, "[IFACE]: print interface configuration");
CMD_FUNCTION(ifconfig, cmdargs) CMD_FUNCTION(ifconfig, cmdargs)
{ {
if(cmdargs->arg_size > 0) { if (cmdargs->arg_size > 0) {
char *msg; char *msg;
int iface = (int)strtoul(cmdargs->args, &msg, 0); int iface = (int)strtoul(cmdargs->args, &msg, 0);
if(cmdargs->arg_size > 1) { if (cmdargs->arg_size > 1) {
while(*msg == ' ') { while (*msg == ' ') {
msg++; msg++;
} }
if(*msg == '-' && (*(msg + 1) == 'P' || *(msg + 1) == 'p')) { if (*msg == '-' && (*(msg + 1) == 'P' || *(msg + 1) == 'p')) {
msg++; msg++;
msg++; msg++;
uint8_t power = (uint8_t)strtoul(msg, &msg, 0); uint8_t power = (uint8_t)strtoul(msg, &msg, 0);
if(*msg != '\0') { if (*msg != '\0') {
return CMD_ERROR; return CMD_ERROR;
} }
if(mms_set_output_power(iface, power)) { if (mms_set_output_power(iface, power)) {
printf("Output power set!\n"); printf("Output power set!\n");
return CMD_SUCCESS; return CMD_SUCCESS;
} }
return CMD_ERROR; return CMD_ERROR;
} }
else if(*msg == '-' && (*(msg + 1) == 'A' || *(msg + 1) == 'a')) { else if (*msg == '-' && (*(msg + 1) == 'A' || *(msg + 1) == 'a')) {
msg++; msg++;
msg++; msg++;
while(*msg == ' ') { while (*msg == ' ') {
msg++; msg++;
} }
uint16_t address = net_strtoaddr(msg, &msg); uint16_t address = net_strtoaddr(msg, &msg);
if(mms_set_interface_address(iface, address)) { if (mms_set_interface_address(iface, address)) {
printf("Interface address set!\n"); printf("Interface address set!\n");
return CMD_SUCCESS; return CMD_SUCCESS;
} }
@ -344,7 +344,7 @@ CMD_FUNCTION(ifconfig, cmdargs)
ASCCMD(ping, CMDFLAG_SERIAL, "ping [-bchpstw] destination"); ASCCMD(ping, CMDFLAG_SERIAL, "ping [-bchpstw] destination");
CMD_FUNCTION(ping, cmdargs) CMD_FUNCTION(ping, cmdargs)
{ {
if(cmdargs->arg_size > 0) { if (cmdargs->arg_size > 0) {
int i; int i;
msg m; msg m;
uint8_t count = MMS_PING_PACKETS; uint8_t count = MMS_PING_PACKETS;
@ -358,26 +358,26 @@ CMD_FUNCTION(ping, cmdargs)
const char *msg = cmdargs->args; const char *msg = cmdargs->args;
read_ping_cmd: read_ping_cmd:
while(*msg == ' ') { while (*msg == ' ') {
msg++; msg++;
} }
if(*msg == '-' && (*(msg + 1) == 'B' || *(msg + 1) == 'b')) { if (*msg == '-' && (*(msg + 1) == 'B' || *(msg + 1) == 'b')) {
bc = true; bc = true;
msg++; msg++;
msg++; msg++;
goto read_ping_cmd; goto read_ping_cmd;
} }
else if(*msg == '-' && (*(msg + 1) == 'C' || *(msg + 1) == 'c')) { else if (*msg == '-' && (*(msg + 1) == 'C' || *(msg + 1) == 'c')) {
msg++; msg++;
msg++; msg++;
unsigned long tc = strtoul(msg, (char **)&msg, 0); unsigned long tc = strtoul(msg, (char **)&msg, 0);
if(tc == 0) { if (tc == 0) {
return CMD_ERROR; return CMD_ERROR;
} }
if(tc > 255) { if (tc > 255) {
puts("Not more than 255 ping messages allowed!"); puts("Not more than 255 ping messages allowed!");
return CMD_ERROR; return CMD_ERROR;
} }
@ -385,7 +385,7 @@ CMD_FUNCTION(ping, cmdargs)
count = (uint8_t) tc; count = (uint8_t) tc;
goto read_ping_cmd; goto read_ping_cmd;
} }
else if(*msg == '-' && (*(msg + 1) == 'H' || *(msg + 1) == 'h')) { else if (*msg == '-' && (*(msg + 1) == 'H' || *(msg + 1) == 'h')) {
printf("Usage: ping [-bchpstw] destination\n\n"); printf("Usage: ping [-bchpstw] destination\n\n");
printf(" -b, do a broadcast ping\n"); printf(" -b, do a broadcast ping\n");
printf(" -c <COUNT>, set number of ping messages\n"); printf(" -c <COUNT>, set number of ping messages\n");
@ -399,19 +399,19 @@ CMD_FUNCTION(ping, cmdargs)
printf(" -w <WAIT>, time to wait for a response, in seconds (default: 3)\n\n"); printf(" -w <WAIT>, time to wait for a response, in seconds (default: 3)\n\n");
return CMD_SUCCESS; return CMD_SUCCESS;
} }
else if(*msg == '-' && (*(msg + 1) == 'p' || *(msg + 1) == 'P')) { else if (*msg == '-' && (*(msg + 1) == 'p' || *(msg + 1) == 'P')) {
msg++; msg++;
msg++; msg++;
unsigned long tp = strtoul(msg, (char **)&msg, 0); unsigned long tp = strtoul(msg, (char **)&msg, 0);
if(tp == 0) { if (tp == 0) {
return CMD_ERROR; return CMD_ERROR;
} }
if(tp == 1) { if (tp == 1) {
prio = 0; prio = 0;
} }
else if(tp == 2) { else if (tp == 2) {
prio = 1; prio = 1;
} }
else { else {
@ -420,30 +420,30 @@ CMD_FUNCTION(ping, cmdargs)
goto read_ping_cmd; goto read_ping_cmd;
} }
else if(*msg == '-' && (*(msg + 1) == 's' || *(msg + 1) == 'S')) { else if (*msg == '-' && (*(msg + 1) == 's' || *(msg + 1) == 'S')) {
ping_silent_mode = true; ping_silent_mode = true;
msg++; msg++;
msg++; msg++;
goto read_ping_cmd; goto read_ping_cmd;
} }
else if(*msg == '-' && (*(msg + 1) == 't' || *(msg + 1) == 'T')) { else if (*msg == '-' && (*(msg + 1) == 't' || *(msg + 1) == 'T')) {
msg++; msg++;
msg++; msg++;
unsigned long to = strtoul(msg, (char **)&msg, 0); unsigned long to = strtoul(msg, (char **)&msg, 0);
if(to == 0 || to > 255) { if (to == 0 || to > 255) {
return CMD_ERROR; return CMD_ERROR;
} }
ttl = to; ttl = to;
goto read_ping_cmd; goto read_ping_cmd;
} }
else if(*msg == '-' && (*(msg + 1) == 'w' || *(msg + 1) == 'W')) { else if (*msg == '-' && (*(msg + 1) == 'w' || *(msg + 1) == 'W')) {
msg++; msg++;
msg++; msg++;
unsigned long to = strtoul(msg, (char **)&msg, 0); unsigned long to = strtoul(msg, (char **)&msg, 0);
if(to == 0) { if (to == 0) {
return CMD_ERROR; return CMD_ERROR;
} }
@ -453,20 +453,20 @@ CMD_FUNCTION(ping, cmdargs)
uint16_t address = net_strtoaddr((char *)msg, (char **)&msg); uint16_t address = net_strtoaddr((char *)msg, (char **)&msg);
if(address == 0) { if (address == 0) {
return CMD_ERROR; return CMD_ERROR;
} }
int iface_addr = net_get_address_in_subnet(address); int iface_addr = net_get_address_in_subnet(address);
/* No ping to unsupported network or own address */ /* No ping to unsupported network or own address */
if(iface_addr == 0 || iface_addr == address) { if (iface_addr == 0 || iface_addr == address) {
return CMD_ERROR; return CMD_ERROR;
} }
/* If broadcast destination address, limit TTL to one hop */ /* If broadcast destination address, limit TTL to one hop */
if(address == NETWORK_ADDR_BC(address)) { if (address == NETWORK_ADDR_BC(address)) {
if(!bc) { if (!bc) {
puts("Do you want to ping broadcast? Then -b"); puts("Do you want to ping broadcast? Then -b");
return CMD_ERROR; return CMD_ERROR;
} }
@ -478,7 +478,7 @@ CMD_FUNCTION(ping, cmdargs)
/* Try to malloc duplicate detection buffer */ /* Try to malloc duplicate detection buffer */
dups = (bool *) malloc(count * sizeof(bool)); dups = (bool *) malloc(count * sizeof(bool));
if(dups == NULL) { if (dups == NULL) {
puts("Not enough system memory to fulfill your request!"); puts("Not enough system memory to fulfill your request!");
return CMD_ERROR; return CMD_ERROR;
} }
@ -494,7 +494,7 @@ CMD_FUNCTION(ping, cmdargs)
mms_ping_pid = fk_thread->pid; mms_ping_pid = fk_thread->pid;
long ts_start = (uint32_t)clock_get_systemtime(); long ts_start = (uint32_t)clock_get_systemtime();
for(i = 1; i <= count; i++) { for (i = 1; i <= count; i++) {
/* No duplicate for this sequence number possible */ /* No duplicate for this sequence number possible */
dups[i - 1] = false; dups[i - 1] = false;
/* Send ping echo request to destination */ /* Send ping echo request to destination */
@ -510,7 +510,7 @@ CMD_FUNCTION(ping, cmdargs)
ts_start = (uint32_t)clock_get_systemtime() - ts_start; ts_start = (uint32_t)clock_get_systemtime() - ts_start;
printf("--- %s ping statistics ---\n", adrbuf); printf("--- %s ping statistics ---\n", adrbuf);
if(mms_ping_dups == 0) { if (mms_ping_dups == 0) {
printf("%u packets transmitted, %u received, %u%% packet loss, time %lu ms\n", count, printf("%u packets transmitted, %u received, %u%% packet loss, time %lu ms\n", count,
mms_ping_packets, ((count - mms_ping_packets) * 100) / count, ts_start); mms_ping_packets, ((count - mms_ping_packets) * 100) / count, ts_start);
} }
@ -519,11 +519,11 @@ CMD_FUNCTION(ping, cmdargs)
mms_ping_packets, mms_ping_dups, ((count - mms_ping_packets) * 100) / count, ts_start); mms_ping_packets, mms_ping_dups, ((count - mms_ping_packets) * 100) / count, ts_start);
} }
if(mms_ping_packets > 0) { if (mms_ping_packets > 0) {
printf("rtt min/avg/max = %.2f/%.2f/%.2f ms\n", rtt_min, rtt_avg / (mms_ping_packets + mms_ping_dups), rtt_max); printf("rtt min/avg/max = %.2f/%.2f/%.2f ms\n", rtt_min, rtt_avg / (mms_ping_packets + mms_ping_dups), rtt_max);
} }
if(!ping_bc_mode && mms_ping_packets == count) { if (!ping_bc_mode && mms_ping_packets == count) {
/* Calculate approximate throughput */ /* Calculate approximate throughput */
printf("--- %s throughput statistics ---\n", adrbuf); printf("--- %s throughput statistics ---\n", adrbuf);
float bw = (count * (8 + 4 + 62 + 2) * 1000) / (float)ts_start; /* for CC1100 */ float bw = (count * (8 + 4 + 62 + 2) * 1000) / (float)ts_start; /* for CC1100 */
@ -550,15 +550,15 @@ CMD_FUNCTION(ping, cmdargs)
ASCCMD(ssh, CMDFLAG_SERIAL, "Usage: ssh [-q] destination"); ASCCMD(ssh, CMDFLAG_SERIAL, "Usage: ssh [-q] destination");
CMD_FUNCTION(ssh, cmdargs) CMD_FUNCTION(ssh, cmdargs)
{ {
if(cmdargs->arg_size > 0) { if (cmdargs->arg_size > 0) {
bool quit = false; bool quit = false;
const char *msg = cmdargs->args; const char *msg = cmdargs->args;
while(*msg == ' ') { while (*msg == ' ') {
msg++; msg++;
} }
if(*msg == '-' && (*(msg + 1) == 'Q' || *(msg + 1) == 'q')) { if (*msg == '-' && (*(msg + 1) == 'Q' || *(msg + 1) == 'q')) {
quit = true; quit = true;
msg++; msg++;
msg++; msg++;
@ -566,23 +566,23 @@ CMD_FUNCTION(ssh, cmdargs)
uint16_t address = net_strtoaddr((char *)msg, (char **)&msg); uint16_t address = net_strtoaddr((char *)msg, (char **)&msg);
if(address == 0) { if (address == 0) {
return CMD_ERROR; return CMD_ERROR;
} }
int iface_addr = net_get_address_in_subnet(address); int iface_addr = net_get_address_in_subnet(address);
/* No ssh to unsupported network or own address */ /* No ssh to unsupported network or own address */
if(iface_addr == 0 || iface_addr == address) { if (iface_addr == 0 || iface_addr == address) {
return CMD_ERROR; return CMD_ERROR;
} }
/* If broadcast destination address, also exit here */ /* If broadcast destination address, also exit here */
if(address == NETWORK_ADDR_BC(address)) { if (address == NETWORK_ADDR_BC(address)) {
return CMD_ERROR; return CMD_ERROR;
} }
if(!quit) { if (!quit) {
mms_ssh_connect(address); mms_ssh_connect(address);
} }
else { else {
@ -605,19 +605,19 @@ static void mms_ping_handler(void *message, int message_size,
{ {
mms_ping_message_t *ping = (mms_ping_message_t *)message; mms_ping_message_t *ping = (mms_ping_message_t *)message;
if(ping->type == MMS_PING_ECHO_REQUEST) { if (ping->type == MMS_PING_ECHO_REQUEST) {
ping->type = MMS_PING_ECHO_REPLY; ping->type = MMS_PING_ECHO_REPLY;
net_send((void *)ping, sizeof(mms_ping_message_t), packet_info->source, net_send((void *)ping, sizeof(mms_ping_message_t), packet_info->source,
LAYER_2_PROTOCOL_PING, packet_info->tos, 10); LAYER_2_PROTOCOL_PING, packet_info->tos, 10);
} }
else if(ping->type == MMS_PING_ECHO_REPLY) { else if (ping->type == MMS_PING_ECHO_REPLY) {
if(ping->identifier == mms_ping_last_proc_id) { if (ping->identifier == mms_ping_last_proc_id) {
msg m; msg m;
bool wasDup = false; bool wasDup = false;
char *msgDup; char *msgDup;
char buf[10]; char buf[10];
if(dups[ping->seq_num - 1]) { if (dups[ping->seq_num - 1]) {
wasDup = true; wasDup = true;
mms_ping_dups++; mms_ping_dups++;
msgDup = "(DUP!)"; msgDup = "(DUP!)";
@ -628,30 +628,30 @@ static void mms_ping_handler(void *message, int message_size,
msgDup = ""; msgDup = "";
} }
if(!ping_bc_mode && !wasDup) { if (!ping_bc_mode && !wasDup) {
utimer_remove(&mms_ping_utimer); /* Stop timeout timer */ utimer_remove(&mms_ping_utimer); /* Stop timeout timer */
} }
float ms = ((uint32_t)clock_get_systemtime() - ping->timestamp); float ms = ((uint32_t)clock_get_systemtime() - ping->timestamp);
if(ms < rtt_min) { if (ms < rtt_min) {
rtt_min = ms; rtt_min = ms;
} }
if(ms > rtt_max) { if (ms > rtt_max) {
rtt_max = ms; rtt_max = ms;
} }
rtt_avg += ms; rtt_avg += ms;
if(!ping_silent_mode) { if (!ping_silent_mode) {
net_addrtostr(packet_info->source, buf, sizeof(buf)); net_addrtostr(packet_info->source, buf, sizeof(buf));
printf("%lu bytes from %s: seq=%u ttl=%u time=%.2f ms %s\n", printf("%lu bytes from %s: seq=%u ttl=%u time=%.2f ms %s\n",
sizeof(mms_ping_message_t), buf, sizeof(mms_ping_message_t), buf,
ping->seq_num, *packet_info->ttl_ptr, ms, msgDup); ping->seq_num, *packet_info->ttl_ptr, ms, msgDup);
} }
if(!ping_bc_mode && !wasDup) { if (!ping_bc_mode && !wasDup) {
msg_send(&m, mms_ping_pid, false); msg_send(&m, mms_ping_pid, false);
} }
} }
@ -704,15 +704,15 @@ static void mms_ssh_handler(void *message, int message_size,
char adrbuf[10]; char adrbuf[10];
mms_ssh_message_t *ssh = (mms_ssh_message_t *)message; mms_ssh_message_t *ssh = (mms_ssh_message_t *)message;
if(ssh->type == MMS_SSH_CON_REQUEST) { if (ssh->type == MMS_SSH_CON_REQUEST) {
if(ssh_socket > -1) { if (ssh_socket > -1) {
mms_ssh_reply_connect(packet_info->source, -1, false); mms_ssh_reply_connect(packet_info->source, -1, false);
return; return;
} }
ssh_socket = trans_socket(SOCK_TCPL); ssh_socket = trans_socket(SOCK_TCPL);
if(ssh_socket < 0) { if (ssh_socket < 0) {
mms_ssh_reply_connect(packet_info->source, -1, false); mms_ssh_reply_connect(packet_info->source, -1, false);
return; return;
} }
@ -720,27 +720,27 @@ static void mms_ssh_handler(void *message, int message_size,
trans_connect(ssh_socket, packet_info->source); trans_connect(ssh_socket, packet_info->source);
mms_ssh_reply_connect(packet_info->source, ssh_socket, true); mms_ssh_reply_connect(packet_info->source, ssh_socket, true);
} }
else if(ssh->type == MMS_SSH_CON_ACCEPT) { else if (ssh->type == MMS_SSH_CON_ACCEPT) {
net_addrtostr(packet_info->source, adrbuf, sizeof(adrbuf)); net_addrtostr(packet_info->source, adrbuf, sizeof(adrbuf));
printf("SSH connection accepted by %s\n", adrbuf); printf("SSH connection accepted by %s\n", adrbuf);
} }
else if(ssh->type == MMS_SSH_CON_REJECT) { else if (ssh->type == MMS_SSH_CON_REJECT) {
net_addrtostr(packet_info->source, adrbuf, sizeof(adrbuf)); net_addrtostr(packet_info->source, adrbuf, sizeof(adrbuf));
printf("SSH connection rejected by %s\n", adrbuf); printf("SSH connection rejected by %s\n", adrbuf);
} }
else if(ssh->type == MMS_SSH_CON_CLOSE) { else if (ssh->type == MMS_SSH_CON_CLOSE) {
if(ssh_socket > -1) { if (ssh_socket > -1) {
uint16_t peer; uint16_t peer;
trans_getpeername(ssh_socket, &peer); trans_getpeername(ssh_socket, &peer);
if(peer == packet_info->source) { if (peer == packet_info->source) {
if(trans_close(ssh_socket, CLOSE_IMMEDIATE) == 1) { if (trans_close(ssh_socket, CLOSE_IMMEDIATE) == 1) {
ssh_socket = -1; ssh_socket = -1;
} }
} }
} }
} }
else if(ssh->type == MMS_SSH_DATA) { else if (ssh->type == MMS_SSH_DATA) {
mms_ssh_data_message_t *ssh_data = (mms_ssh_data_message_t *)message; mms_ssh_data_message_t *ssh_data = (mms_ssh_data_message_t *)message;
printf((char *)ssh_data->data); printf((char *)ssh_data->data);
fflush(stderr); fflush(stderr);
@ -749,18 +749,18 @@ static void mms_ssh_handler(void *message, int message_size,
void mms_net_printf(const char *format) void mms_net_printf(const char *format)
{ {
if(ssh_socket > -1) { if (ssh_socket > -1) {
mms_ssh_data_message_t ssh_data; mms_ssh_data_message_t ssh_data;
ssh_data.type = MMS_SSH_DATA; ssh_data.type = MMS_SSH_DATA;
int i = 0; int i = 0;
int len = strlen(format); int len = strlen(format);
while(i < len) { while (i < len) {
int chunk = len - i > (MMS_SSH_DATA_MAX - 1) ? (MMS_SSH_DATA_MAX - 1) : len - i; int chunk = len - i > (MMS_SSH_DATA_MAX - 1) ? (MMS_SSH_DATA_MAX - 1) : len - i;
memset(ssh_data.data, 0, sizeof(ssh_data.data)); memset(ssh_data.data, 0, sizeof(ssh_data.data));
memcpy(ssh_data.data, format + i, chunk); memcpy(ssh_data.data, format + i, chunk);
if(trans_send(ssh_socket, (void *)&ssh_data, sizeof(mms_ssh_data_message_t), if (trans_send(ssh_socket, (void *)&ssh_data, sizeof(mms_ssh_data_message_t),
LAYER_3_PROTOCOL_SSH, PRIORITY_DATA) < 0) { LAYER_3_PROTOCOL_SSH, PRIORITY_DATA) < 0) {
break; break;
} }

View File

@ -39,20 +39,20 @@ static const char *inet_ntop4(const unsigned char *src, char *dst, size_t size)
int n = 0; int n = 0;
char *next = dst; char *next = dst;
if(size < MIN_SIZE) { if (size < MIN_SIZE) {
return NULL; return NULL;
} }
do { do {
unsigned char u = *src++; unsigned char u = *src++;
if(u > 99) { if (u > 99) {
*next++ = '0' + u / 100; *next++ = '0' + u / 100;
u %= 100; u %= 100;
*next++ = '0' + u / 10; *next++ = '0' + u / 10;
u %= 10; u %= 10;
} }
else if(u > 9) { else if (u > 9) {
*next++ = '0' + u / 10; *next++ = '0' + u / 10;
u %= 10; u %= 10;
} }
@ -61,7 +61,7 @@ static const char *inet_ntop4(const unsigned char *src, char *dst, size_t size)
*next++ = '.'; *next++ = '.';
n++; n++;
} }
while(n < 4); while (n < 4);
*--next = 0; *--next = 0;
return dst; return dst;
@ -107,8 +107,8 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size)
next_word |= (unsigned int) *next_src++; next_word |= (unsigned int) *next_src++;
*next_dest++ = next_word; *next_dest++ = next_word;
if(next_word == 0) { if (next_word == 0) {
if(cur.base == -1) { if (cur.base == -1) {
cur.base = i; cur.base = i;
cur.len = 1; cur.len = 1;
} }
@ -117,8 +117,8 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size)
} }
} }
else { else {
if(cur.base != -1) { if (cur.base != -1) {
if(best.base == -1 || cur.len > best.len) { if (best.base == -1 || cur.len > best.len) {
best = cur; best = cur;
} }
@ -128,15 +128,15 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size)
i++; i++;
} }
while(next_src < src_end); while (next_src < src_end);
if(cur.base != -1) { if (cur.base != -1) {
if(best.base == -1 || cur.len > best.len) { if (best.base == -1 || cur.len > best.len) {
best = cur; best = cur;
} }
} }
if(best.base != -1 && best.len < 2) { if (best.base != -1 && best.len < 2) {
best.base = -1; best.base = -1;
} }
@ -145,23 +145,23 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size)
*/ */
tp = tmp; tp = tmp;
for(i = 0; i < (IN6ADDRSZ / INT16SZ);) { for (i = 0; i < (IN6ADDRSZ / INT16SZ);) {
/* Are we inside the best run of 0x00's? */ /* Are we inside the best run of 0x00's? */
if(i == best.base) { if (i == best.base) {
*tp++ = ':'; *tp++ = ':';
i += best.len; i += best.len;
continue; continue;
} }
/* Are we following an initial run of 0x00s or any real hex? */ /* Are we following an initial run of 0x00s or any real hex? */
if(i != 0) { if (i != 0) {
*tp++ = ':'; *tp++ = ':';
} }
/* Is this address an encapsulated IPv4? */ /* Is this address an encapsulated IPv4? */
if(i == 6 && best.base == 0 && if (i == 6 && best.base == 0 &&
(best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
if(!inet_ntop4(src + 12, tp, sizeof tmp - (tp - tmp))) { if (!inet_ntop4(src + 12, tp, sizeof tmp - (tp - tmp))) {
return (NULL); return (NULL);
} }
@ -174,7 +174,7 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size)
} }
/* Was it a trailing run of 0x00's? */ /* Was it a trailing run of 0x00's? */
if(best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) { if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) {
*tp++ = ':'; *tp++ = ':';
} }
@ -183,7 +183,7 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size)
/* /*
* Check for overflow, copy, and we're done. * Check for overflow, copy, and we're done.
*/ */
if((size_t)(tp - tmp) > size) { if ((size_t)(tp - tmp) > size) {
return (NULL); return (NULL);
} }

View File

@ -42,28 +42,28 @@ static int inet_pton4(const char *src, unsigned char *dst)
octets = 0; octets = 0;
*(tp = tmp) = 0; *(tp = tmp) = 0;
while((ch = *src++) != '\0') { while ((ch = *src++) != '\0') {
const char *pch; const char *pch;
if((pch = strchr(digits, ch)) != NULL) { if ((pch = strchr(digits, ch)) != NULL) {
unsigned int new = *tp * 10 + (unsigned int)(pch - digits); unsigned int new = *tp * 10 + (unsigned int)(pch - digits);
if(new > 255) { if (new > 255) {
return (0); return (0);
} }
*tp = new; *tp = new;
if(! saw_digit) { if (!saw_digit) {
if(++octets > 4) { if (++octets > 4) {
return (0); return (0);
} }
saw_digit = 1; saw_digit = 1;
} }
} }
else if(ch == '.' && saw_digit) { else if (ch == '.' && saw_digit) {
if(octets == 4) { if (octets == 4) {
return (0); return (0);
} }
@ -75,7 +75,7 @@ static int inet_pton4(const char *src, unsigned char *dst)
} }
} }
if(octets < 4) { if (octets < 4) {
return (0); return (0);
} }
@ -110,8 +110,8 @@ static int inet_pton6(const char *src, unsigned char *dst)
colonp = NULL; colonp = NULL;
/* Leading :: requires some special handling. */ /* Leading :: requires some special handling. */
if(*src == ':') if (*src == ':')
if(*++src != ':') { if (*++src != ':') {
return (0); return (0);
} }
@ -119,18 +119,18 @@ static int inet_pton6(const char *src, unsigned char *dst)
saw_xdigit = 0; saw_xdigit = 0;
val = 0; val = 0;
while((ch = *src++) != '\0') { while ((ch = *src++) != '\0') {
const char *pch; const char *pch;
if((pch = strchr((xdigits = xdigits_l), ch)) == NULL) { if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) {
pch = strchr((xdigits = xdigits_u), ch); pch = strchr((xdigits = xdigits_u), ch);
} }
if(pch != NULL) { if (pch != NULL) {
val <<= 4; val <<= 4;
val |= (pch - xdigits); val |= (pch - xdigits);
if(val > 0xffff) { if (val > 0xffff) {
return (0); return (0);
} }
@ -138,11 +138,11 @@ static int inet_pton6(const char *src, unsigned char *dst)
continue; continue;
} }
if(ch == ':') { if (ch == ':') {
curtok = src; curtok = src;
if(!saw_xdigit) { if (!saw_xdigit) {
if(colonp) { if (colonp) {
return (0); return (0);
} }
@ -150,7 +150,7 @@ static int inet_pton6(const char *src, unsigned char *dst)
continue; continue;
} }
if(tp + INT16SZ > endp) { if (tp + INT16SZ > endp) {
return (0); return (0);
} }
@ -161,7 +161,7 @@ static int inet_pton6(const char *src, unsigned char *dst)
continue; continue;
} }
if(ch == '.' && ((tp + INADDRSZ) <= endp) && if (ch == '.' && ((tp + INADDRSZ) <= endp) &&
inet_pton4(curtok, tp) > 0) { inet_pton4(curtok, tp) > 0) {
tp += INADDRSZ; tp += INADDRSZ;
saw_xdigit = 0; saw_xdigit = 0;
@ -171,8 +171,8 @@ static int inet_pton6(const char *src, unsigned char *dst)
return (0); return (0);
} }
if(saw_xdigit) { if (saw_xdigit) {
if(tp + INT16SZ > endp) { if (tp + INT16SZ > endp) {
return (0); return (0);
} }
@ -180,7 +180,7 @@ static int inet_pton6(const char *src, unsigned char *dst)
*tp++ = (unsigned char) val & 0xff; *tp++ = (unsigned char) val & 0xff;
} }
if(colonp != NULL) { if (colonp != NULL) {
/* /*
* Since some memmove()'s erroneously fail to handle * Since some memmove()'s erroneously fail to handle
* overlapping regions, we'll do the shift by hand. * overlapping regions, we'll do the shift by hand.
@ -188,7 +188,7 @@ static int inet_pton6(const char *src, unsigned char *dst)
const ssize_t n = tp - colonp; const ssize_t n = tp - colonp;
ssize_t i; ssize_t i;
for(i = 1; i <= n; i++) { for (i = 1; i <= n; i++) {
endp[- i] = colonp[n - i]; endp[- i] = colonp[n - i];
colonp[n - i] = 0; colonp[n - i] = 0;
} }
@ -196,7 +196,7 @@ static int inet_pton6(const char *src, unsigned char *dst)
tp = endp; tp = endp;
} }
if(tp != endp) { if (tp != endp) {
return (0); return (0);
} }

View File

@ -16,7 +16,7 @@ void printArrayRange(uint8_t *array, uint16_t len, char *str)
int i = 0; int i = 0;
printf("-------------%s-------------\n", str); printf("-------------%s-------------\n", str);
for(i = 0; i < len; i++) { for (i = 0; i < len; i++) {
printf("%#x ", *(array + i)); printf("%#x ", *(array + i));
} }
@ -30,8 +30,8 @@ uint16_t csum(uint16_t sum, uint8_t *buf, uint16_t len)
count = len >> 1; count = len >> 1;
if(count) { if (count) {
if(count) { if (count) {
carry = 0; carry = 0;
do { do {
@ -42,17 +42,17 @@ uint16_t csum(uint16_t sum, uint8_t *buf, uint16_t len)
sum += t; sum += t;
carry = (t > sum); carry = (t > sum);
} }
while(count); while (count);
sum += carry; sum += carry;
} }
} }
if(len & 1) { if (len & 1) {
uint16_t u = (*buf << 8); uint16_t u = (*buf << 8);
sum += (*buf << 8); sum += (*buf << 8);
if(sum < u) { if (sum < u) {
sum++; sum++;
} }
} }

View File

@ -69,8 +69,8 @@ int pm_find_handler_index(const pm_table_t *table, protocol_t protocol,
int i; int i;
handler_entry_t *e = &table->handler[start]; handler_entry_t *e = &table->handler[start];
for(i = start; i < table->size; i++, e++) { for (i = start; i < table->size; i++, e++) {
if(e->protocol == protocol) { if (e->protocol == protocol) {
return i; return i;
} }
} }
@ -82,7 +82,7 @@ int pm_set_handler(const pm_table_t *table, protocol_t protocol,
packet_handler_t handler) packet_handler_t handler)
{ {
/* Reject illegal values */ /* Reject illegal values */
if(protocol == 0 || handler == NULL) { if (protocol == 0 || handler == NULL) {
PRINTF("proto %u rejected", protocol); PRINTF("proto %u rejected", protocol);
return -1; return -1;
} }
@ -90,10 +90,10 @@ int pm_set_handler(const pm_table_t *table, protocol_t protocol,
/* Check if there is already a handler for given protocol */ /* Check if there is already a handler for given protocol */
int index = pm_find_handler_index(table, protocol, 0); int index = pm_find_handler_index(table, protocol, 0);
if(index >= 0) { if (index >= 0) {
/* Two handlers for same protocol not allowed because only /* Two handlers for same protocol not allowed because only
* one gets called. This hasn't to be the last one who * one gets called. This hasn't to be the last one who
* registered! */ * registered!*/
PRINTF("proto %u handler found, reset", protocol); PRINTF("proto %u handler found, reset", protocol);
table->handler[index].protocol = 0; table->handler[index].protocol = 0;
table->handler[index].handler = NULL; table->handler[index].handler = NULL;
@ -103,7 +103,7 @@ int pm_set_handler(const pm_table_t *table, protocol_t protocol,
index = pm_find_handler_index(table, 0, 0); index = pm_find_handler_index(table, 0, 0);
/* Store handler if free index found */ /* Store handler if free index found */
if(index >= 0) { if (index >= 0) {
PRINTF("proto %u, set", protocol); PRINTF("proto %u, set", protocol);
table->handler[index].protocol = protocol; table->handler[index].protocol = protocol;
table->handler[index].handler = handler; table->handler[index].handler = handler;
@ -118,8 +118,8 @@ void pm_remove_handler(const pm_table_t *table, protocol_t protocol,
{ {
int i; int i;
for(i = 0; i < table->size; i++) { for (i = 0; i < table->size; i++) {
if(table->handler[i].protocol == protocol && table->handler[i].handler == handler) { if (table->handler[i].protocol == protocol && table->handler[i].handler == handler) {
PRINTF("proto %u handler found, reset", protocol); PRINTF("proto %u handler found, reset", protocol);
table->handler[i].protocol = 0; table->handler[i].protocol = 0;
table->handler[i].handler = NULL; table->handler[i].handler = NULL;
@ -133,11 +133,11 @@ int pm_invoke(const pm_table_t *table, protocol_t protocol, void *payload,
int index = 0; int index = 0;
/* Reject illegal values */ /* Reject illegal values */
if(protocol == 0) { if (protocol == 0) {
return -1; return -1;
} }
if((index = pm_find_handler_index(table, protocol, index)) != -1) { if ((index = pm_find_handler_index(table, protocol, index)) != -1) {
PRINTF("proto %u, invoke", protocol); PRINTF("proto %u, invoke", protocol);
table->handler[index].handler(payload, payload_size, packet_info); table->handler[index].handler(payload, payload_size, packet_info);
} }

View File

@ -37,16 +37,16 @@
void demultiplex(border_packet_t *packet, int len) void demultiplex(border_packet_t *packet, int len)
{ {
switch(packet->type) { switch(packet->type) {
case(BORDER_PACKET_RAW_TYPE): { case (BORDER_PACKET_RAW_TYPE): {
fputs(((char *)packet) + sizeof(border_packet_t), stdin); fputs(((char *)packet) + sizeof(border_packet_t), stdin);
break; break;
} }
case(BORDER_PACKET_L3_TYPE): { case (BORDER_PACKET_L3_TYPE): {
border_l3_header_t *l3_header_buf = (border_l3_header_t *)packet; border_l3_header_t *l3_header_buf = (border_l3_header_t *)packet;
switch(l3_header_buf->ethertype) { switch(l3_header_buf->ethertype) {
case(BORDER_ETHERTYPE_IPV6): { case (BORDER_ETHERTYPE_IPV6): {
ipv6_hdr_t *ipv6_buf = (ipv6_hdr_t *)(((unsigned char *)packet) + sizeof(border_l3_header_t)); ipv6_hdr_t *ipv6_buf = (ipv6_hdr_t *)(((unsigned char *)packet) + sizeof(border_l3_header_t));
border_send_ipv6_over_lowpan(ipv6_buf, 1, 1); border_send_ipv6_over_lowpan(ipv6_buf, 1, 1);
break; break;
@ -60,11 +60,11 @@ void demultiplex(border_packet_t *packet, int len)
break; break;
} }
case(BORDER_PACKET_CONF_TYPE): { case (BORDER_PACKET_CONF_TYPE): {
border_conf_header_t *conf_header_buf = (border_conf_header_t *)packet; border_conf_header_t *conf_header_buf = (border_conf_header_t *)packet;
switch(conf_header_buf->conftype) { switch(conf_header_buf->conftype) {
case(BORDER_CONF_CONTEXT): { case (BORDER_CONF_CONTEXT): {
border_context_packet_t *context = (border_context_packet_t *)packet; border_context_packet_t *context = (border_context_packet_t *)packet;
ipv6_addr_t target_addr; ipv6_addr_t target_addr;
ipv6_set_all_nds_mcast_addr(&target_addr); ipv6_set_all_nds_mcast_addr(&target_addr);
@ -82,7 +82,7 @@ void demultiplex(border_packet_t *packet, int len)
break; break;
} }
case(BORDER_CONF_IPADDR): { case (BORDER_CONF_IPADDR): {
//border_addr_packet_t *addr_packet = (border_addr_packet_t *)packet; //border_addr_packet_t *addr_packet = (border_addr_packet_t *)packet;
/* add address */ /* add address */
break; break;
@ -134,27 +134,27 @@ int readpacket(uint8_t *packet_buf, size_t size)
uint8_t byte = END + 1; uint8_t byte = END + 1;
uint8_t esc = 0; uint8_t esc = 0;
while(1) { while (1) {
byte = uart0_readc(); byte = uart0_readc();
if(byte == END) { if (byte == END) {
break; break;
} }
if((line_buf_ptr - packet_buf) >= size - 1) { if ((line_buf_ptr - packet_buf) >= size - 1) {
return -SIXLOWERROR_ARRAYFULL; return -SIXLOWERROR_ARRAYFULL;
} }
if(esc) { if (esc) {
esc = 0; esc = 0;
switch(byte) { switch(byte) {
case(END_ESC): { case (END_ESC): {
*line_buf_ptr++ = END; *line_buf_ptr++ = END;
continue; continue;
} }
case(ESC_ESC): { case (ESC_ESC): {
*line_buf_ptr++ = ESC; *line_buf_ptr++ = ESC;
continue; continue;
} }
@ -164,7 +164,7 @@ int readpacket(uint8_t *packet_buf, size_t size)
} }
} }
if(byte == ESC) { if (byte == ESC) {
esc = 1; esc = 1;
continue; continue;
} }
@ -179,19 +179,19 @@ int writepacket(uint8_t *packet_buf, size_t size)
{ {
uint8_t *byte_ptr = packet_buf; uint8_t *byte_ptr = packet_buf;
while((byte_ptr - packet_buf) < size) { while ((byte_ptr - packet_buf) < size) {
if((byte_ptr - packet_buf) > BORDER_BUFFER_SIZE) { if ((byte_ptr - packet_buf) > BORDER_BUFFER_SIZE) {
return -1; return -1;
} }
switch(*byte_ptr) { switch(*byte_ptr) {
case(END): { case (END): {
*byte_ptr = END_ESC; *byte_ptr = END_ESC;
uart0_putc(ESC); uart0_putc(ESC);
break; break;
} }
case(ESC): { case (ESC): {
*byte_ptr = ESC_ESC; *byte_ptr = ESC_ESC;
uart0_putc(ESC); uart0_putc(ESC);
break; break;

View File

@ -80,7 +80,7 @@ typedef struct __attribute__((packed)) {
} context; } context;
} border_context_packet_t; } border_context_packet_t;
#define BORDER_BUFFER_SIZE (sizeof (border_l3_header_t) + MTU) #define BORDER_BUFFER_SIZE (sizeof(border_l3_header_t) + MTU)
void demultiplex(border_packet_t *packet, int len); void demultiplex(border_packet_t *packet, int len);
void multiplex_send_ipv6_over_uart(ipv6_hdr_t *packet); void multiplex_send_ipv6_over_uart(ipv6_hdr_t *packet);

View File

@ -73,13 +73,13 @@ ipv6_addr_t flowcontrol_init(void)
sem_init(&slwin_stat.send_win_not_full, BORDER_SWS); sem_init(&slwin_stat.send_win_not_full, BORDER_SWS);
for(i = 0; i < BORDER_SWS; i++) { for (i = 0; i < BORDER_SWS; i++) {
slwin_stat.send_win[i].frame_len = 0; slwin_stat.send_win[i].frame_len = 0;
} }
memset(&slwin_stat.send_win, 0, sizeof(struct send_slot) * BORDER_SWS); memset(&slwin_stat.send_win, 0, sizeof(struct send_slot) * BORDER_SWS);
for(i = 0; i < BORDER_RWS; i++) { for (i = 0; i < BORDER_RWS; i++) {
slwin_stat.recv_win[i].received = 0; slwin_stat.recv_win[i].received = 0;
slwin_stat.recv_win[i].frame_len = 0; slwin_stat.recv_win[i].frame_len = 0;
} }
@ -96,16 +96,16 @@ static void sending_slot(void)
struct send_slot *slot; struct send_slot *slot;
border_packet_t *tmp; border_packet_t *tmp;
while(1) { while (1) {
msg_receive(&m); msg_receive(&m);
seq_num = *((uint8_t *)m.content.ptr); seq_num = *((uint8_t *)m.content.ptr);
slot = &(slwin_stat.send_win[seq_num % BORDER_SWS]); slot = &(slwin_stat.send_win[seq_num % BORDER_SWS]);
tmp = (border_packet_t *)slot->frame; tmp = (border_packet_t *)slot->frame;
if(seq_num == tmp->seq_num) { if (seq_num == tmp->seq_num) {
writepacket(slot->frame, slot->frame_len); writepacket(slot->frame, slot->frame_len);
if(set_timeout(&slot->timeout, BORDER_SL_TIMEOUT, (void *)m.content.ptr) != 0) { if (set_timeout(&slot->timeout, BORDER_SL_TIMEOUT, (void *)m.content.ptr) != 0) {
printf("ERROR: Error invoking timeout timer\n"); printf("ERROR: Error invoking timeout timer\n");
} }
} }
@ -139,7 +139,7 @@ void flowcontrol_send_over_uart(border_packet_t *packet, int len)
memcpy(slot->frame, (uint8_t *)packet, len); memcpy(slot->frame, (uint8_t *)packet, len);
slot->frame_len = len; slot->frame_len = len;
if(set_timeout(&slot->timeout, BORDER_SL_TIMEOUT, (void *)args) != 0) { if (set_timeout(&slot->timeout, BORDER_SL_TIMEOUT, (void *)args) != 0) {
printf("ERROR: Error invoking timeout timer\n"); printf("ERROR: Error invoking timeout timer\n");
return; return;
} }
@ -158,9 +158,9 @@ void send_ack(uint8_t seq_num)
void flowcontrol_deliver_from_uart(border_packet_t *packet, int len) void flowcontrol_deliver_from_uart(border_packet_t *packet, int len)
{ {
if(packet->type == BORDER_PACKET_ACK_TYPE) { if (packet->type == BORDER_PACKET_ACK_TYPE) {
if(in_window(packet->seq_num, slwin_stat.last_ack + 1, slwin_stat.last_frame)) { if (in_window(packet->seq_num, slwin_stat.last_ack + 1, slwin_stat.last_frame)) {
if(synack_seqnum == packet->seq_num) { if (synack_seqnum == packet->seq_num) {
synack_seqnum = -1; synack_seqnum = -1;
sem_signal(&connection_established); sem_signal(&connection_established);
} }
@ -172,7 +172,7 @@ void flowcontrol_deliver_from_uart(border_packet_t *packet, int len)
memset(&slot->frame, 0, BORDER_BUFFER_SIZE); memset(&slot->frame, 0, BORDER_BUFFER_SIZE);
sem_signal(&slwin_stat.send_win_not_full); sem_signal(&slwin_stat.send_win_not_full);
} }
while(slwin_stat.last_ack != packet->seq_num); while (slwin_stat.last_ack != packet->seq_num);
} }
} }
else { else {
@ -180,7 +180,7 @@ void flowcontrol_deliver_from_uart(border_packet_t *packet, int len)
slot = &(slwin_stat.recv_win[packet->seq_num % BORDER_RWS]); slot = &(slwin_stat.recv_win[packet->seq_num % BORDER_RWS]);
if(!in_window(packet->seq_num, if (!in_window(packet->seq_num,
slwin_stat.next_exp, slwin_stat.next_exp,
slwin_stat.next_exp + BORDER_RWS - 1)) { slwin_stat.next_exp + BORDER_RWS - 1)) {
return; return;
@ -189,8 +189,8 @@ void flowcontrol_deliver_from_uart(border_packet_t *packet, int len)
memcpy(slot->frame, (uint8_t *)packet, len); memcpy(slot->frame, (uint8_t *)packet, len);
slot->received = 1; slot->received = 1;
if(packet->seq_num == slwin_stat.next_exp) { if (packet->seq_num == slwin_stat.next_exp) {
while(slot->received) { while (slot->received) {
demultiplex((border_packet_t *)slot->frame, slot->frame_len); demultiplex((border_packet_t *)slot->frame, slot->frame_len);
memset(&slot->frame, 0, BORDER_BUFFER_SIZE); memset(&slot->frame, 0, BORDER_BUFFER_SIZE);
slot->received = 0; slot->received = 0;

View File

@ -44,7 +44,7 @@ uint8_t init_802154_frame(ieee802154_frame_t *frame, uint8_t *buf)
index++; index++;
/* Destination PAN Identifier - 802.15.4 - 2006 - 7.2.1.3 */ /* Destination PAN Identifier - 802.15.4 - 2006 - 7.2.1.3 */
if(frame->fcf.dest_addr_m == 0x02 || frame->fcf.dest_addr_m == 0x03) { if (frame->fcf.dest_addr_m == 0x02 || frame->fcf.dest_addr_m == 0x03) {
buf[index] = ((frame->dest_pan_id >> 8) & 0xff); buf[index] = ((frame->dest_pan_id >> 8) & 0xff);
buf[index + 1] = (frame->dest_pan_id & 0xff); buf[index + 1] = (frame->dest_pan_id & 0xff);
} }
@ -52,12 +52,12 @@ uint8_t init_802154_frame(ieee802154_frame_t *frame, uint8_t *buf)
index += 2; index += 2;
/* Destination Address - 802.15.4 - 2006 - 7.2.1.4 */ /* Destination Address - 802.15.4 - 2006 - 7.2.1.4 */
if(frame->fcf.dest_addr_m == 0x02) { if (frame->fcf.dest_addr_m == 0x02) {
buf[index] = frame->dest_addr[0]; buf[index] = frame->dest_addr[0];
buf[index + 1] = frame->dest_addr[1]; buf[index + 1] = frame->dest_addr[1];
index += 2; index += 2;
} }
else if(frame->fcf.dest_addr_m == 0x03) { else if (frame->fcf.dest_addr_m == 0x03) {
buf[index] = frame->dest_addr[0]; buf[index] = frame->dest_addr[0];
buf[index + 1] = frame->dest_addr[1]; buf[index + 1] = frame->dest_addr[1];
buf[index + 2] = frame->dest_addr[2]; buf[index + 2] = frame->dest_addr[2];
@ -70,8 +70,8 @@ uint8_t init_802154_frame(ieee802154_frame_t *frame, uint8_t *buf)
} }
/* Source PAN Identifier - 802.15.4 - 2006 - 7.2.1.5 */ /* Source PAN Identifier - 802.15.4 - 2006 - 7.2.1.5 */
if(!(frame->fcf.panid_comp & 0x01)) { if (!(frame->fcf.panid_comp & 0x01)) {
if(frame->fcf.src_addr_m == 0x02 || frame->fcf.src_addr_m == 0x03) { if (frame->fcf.src_addr_m == 0x02 || frame->fcf.src_addr_m == 0x03) {
buf[index] = ((frame->src_pan_id >> 8) & 0xff); buf[index] = ((frame->src_pan_id >> 8) & 0xff);
buf[index + 1] = (frame->src_pan_id & 0xff); buf[index + 1] = (frame->src_pan_id & 0xff);
index += 2; index += 2;
@ -79,12 +79,12 @@ uint8_t init_802154_frame(ieee802154_frame_t *frame, uint8_t *buf)
} }
/* Source Address field - 802.15.4 - 2006 - 7.2.1.6 */ /* Source Address field - 802.15.4 - 2006 - 7.2.1.6 */
if(frame->fcf.src_addr_m == 0x02) { if (frame->fcf.src_addr_m == 0x02) {
buf[index] = frame->src_addr[0]; buf[index] = frame->src_addr[0];
buf[index + 1] = frame->src_addr[1]; buf[index + 1] = frame->src_addr[1];
index += 2; index += 2;
} }
else if(frame->fcf.src_addr_m == 0x03) { else if (frame->fcf.src_addr_m == 0x03) {
buf[index] = frame->src_addr[0]; buf[index] = frame->src_addr[0];
buf[index + 1] = frame->src_addr[1]; buf[index + 1] = frame->src_addr[1];
buf[index + 2] = frame->src_addr[2]; buf[index + 2] = frame->src_addr[2];
@ -108,30 +108,30 @@ uint8_t get_802154_hdr_len(ieee802154_frame_t *frame)
{ {
uint8_t len = 0; uint8_t len = 0;
if(frame->fcf.dest_addr_m == 0x02) { if (frame->fcf.dest_addr_m == 0x02) {
len += 2; len += 2;
} }
else if(frame->fcf.dest_addr_m == 0x03) { else if (frame->fcf.dest_addr_m == 0x03) {
len += 8; len += 8;
} }
if(frame->fcf.src_addr_m == 0x02) { if (frame->fcf.src_addr_m == 0x02) {
len += 2; len += 2;
} }
else if(frame->fcf.src_addr_m == 0x03) { else if (frame->fcf.src_addr_m == 0x03) {
len += 8; len += 8;
} }
if((frame->fcf.dest_addr_m == 0x02) || (frame->fcf.dest_addr_m == 0x03)) { if ((frame->fcf.dest_addr_m == 0x02) || (frame->fcf.dest_addr_m == 0x03)) {
len += 2; len += 2;
} }
if((frame->fcf.src_addr_m == 0x02) || (frame->fcf.src_addr_m == 0x03)) { if ((frame->fcf.src_addr_m == 0x02) || (frame->fcf.src_addr_m == 0x03)) {
len += 2; len += 2;
} }
/* if src pan id == dest pan id set compression bit */ /* if src pan id == dest pan id set compression bit */
if(frame->src_pan_id == frame->dest_pan_id) { if (frame->src_pan_id == frame->dest_pan_id) {
frame->fcf.panid_comp = 1; frame->fcf.panid_comp = 1;
len -= 2; len -= 2;
} }
@ -170,19 +170,19 @@ uint8_t read_802154_frame(uint8_t *buf, ieee802154_frame_t *frame, uint8_t len)
index += 2; index += 2;
switch(frame->fcf.dest_addr_m) { switch(frame->fcf.dest_addr_m) {
case(0): { case (0): {
printf("fcf.dest_addr_m: pan identifier/address fields empty\n"); printf("fcf.dest_addr_m: pan identifier/address fields empty\n");
break; break;
} }
case(2): { case (2): {
frame->dest_addr[0] = buf[index]; frame->dest_addr[0] = buf[index];
frame->dest_addr[1] = buf[index + 1]; frame->dest_addr[1] = buf[index + 1];
index += 2; index += 2;
break; break;
} }
case(3): { case (3): {
frame->dest_addr[0] = buf[index]; frame->dest_addr[0] = buf[index];
frame->dest_addr[1] = buf[index + 1]; frame->dest_addr[1] = buf[index + 1];
frame->dest_addr[2] = buf[index + 2]; frame->dest_addr[2] = buf[index + 2];
@ -196,25 +196,25 @@ uint8_t read_802154_frame(uint8_t *buf, ieee802154_frame_t *frame, uint8_t len)
} }
} }
if(!(frame->fcf.panid_comp == 1)) { if (!(frame->fcf.panid_comp == 1)) {
frame->src_pan_id = (((uint16_t)buf[index]) << 8) | buf[index + 1]; frame->src_pan_id = (((uint16_t)buf[index]) << 8) | buf[index + 1];
index += 2; index += 2;
} }
switch(frame->fcf.src_addr_m) { switch(frame->fcf.src_addr_m) {
case(0): { case (0): {
printf("fcf.src_addr_m: pan identifier/address fields empty\n"); printf("fcf.src_addr_m: pan identifier/address fields empty\n");
break; break;
} }
case(2): { case (2): {
frame->src_addr[0] = buf[index]; frame->src_addr[0] = buf[index];
frame->src_addr[1] = buf[index + 1]; frame->src_addr[1] = buf[index + 1];
index += 2; index += 2;
break; break;
} }
case(3): { case (3): {
frame->src_addr[0] = buf[index]; frame->src_addr[0] = buf[index];
frame->src_addr[1] = buf[index + 1]; frame->src_addr[1] = buf[index + 1];
frame->src_addr[2] = buf[index + 2]; frame->src_addr[2] = buf[index + 2];

View File

@ -39,8 +39,8 @@ void reset(rpl_dodag_t *dodag)
uint16_t calc_rank(rpl_parent_t *parent, uint16_t base_rank) uint16_t calc_rank(rpl_parent_t *parent, uint16_t base_rank)
{ {
if(base_rank == 0) { if (base_rank == 0) {
if(parent == NULL) { if (parent == NULL) {
return INFINITE_RANK; return INFINITE_RANK;
} }
@ -49,14 +49,14 @@ uint16_t calc_rank(rpl_parent_t *parent, uint16_t base_rank)
uint16_t add; uint16_t add;
if(parent != NULL) { if (parent != NULL) {
add = parent->dodag->minhoprankincrease; add = parent->dodag->minhoprankincrease;
} }
else { else {
add = DEFAULT_MIN_HOP_RANK_INCREASE; add = DEFAULT_MIN_HOP_RANK_INCREASE;
} }
if(base_rank + add < base_rank) { if (base_rank + add < base_rank) {
return INFINITE_RANK; return INFINITE_RANK;
} }
@ -66,7 +66,7 @@ uint16_t calc_rank(rpl_parent_t *parent, uint16_t base_rank)
/* We simply return the Parent with lower rank */ /* We simply return the Parent with lower rank */
rpl_parent_t *which_parent(rpl_parent_t *p1, rpl_parent_t *p2) rpl_parent_t *which_parent(rpl_parent_t *p1, rpl_parent_t *p2)
{ {
if(p1->rank < p2->rank) { if (p1->rank < p2->rank) {
return p1; return p1;
} }

View File

@ -174,8 +174,8 @@ static rpl_opt_transit_t *get_rpl_opt_transit_buf(uint8_t rpl_msg_len)
/* Diese Funktion findet eine implementierte OF anhand des Objective Code Point */ /* Diese Funktion findet eine implementierte OF anhand des Objective Code Point */
rpl_of_t *rpl_get_of_for_ocp(uint16_t ocp) rpl_of_t *rpl_get_of_for_ocp(uint16_t ocp)
{ {
for(uint16_t i = 0; i < NUMBER_IMPLEMENTED_OFS; i++) { for (uint16_t i = 0; i < NUMBER_IMPLEMENTED_OFS; i++) {
if(ocp == objective_functions[i]->ocp) { if (ocp == objective_functions[i]->ocp) {
return objective_functions[i]; return objective_functions[i];
} }
} }
@ -188,7 +188,7 @@ uint8_t rpl_init(transceiver_type_t trans, uint16_t rpl_address)
mutex_init(&rpl_send_mutex); mutex_init(&rpl_send_mutex);
mutex_init(&rpl_recv_mutex); mutex_init(&rpl_recv_mutex);
if(rpl_address == 0) { if (rpl_address == 0) {
return SIXLOWERROR_ADDRESS; return SIXLOWERROR_ADDRESS;
} }
@ -221,7 +221,7 @@ void rpl_init_root(void)
inst = rpl_new_instance(RPL_DEFAULT_INSTANCE); inst = rpl_new_instance(RPL_DEFAULT_INSTANCE);
if(inst == NULL) { if (inst == NULL) {
printf("Error - No memory for another RPL instance\n"); printf("Error - No memory for another RPL instance\n");
return; return;
} }
@ -231,7 +231,7 @@ void rpl_init_root(void)
dodag = rpl_new_dodag(RPL_DEFAULT_INSTANCE, &my_address); dodag = rpl_new_dodag(RPL_DEFAULT_INSTANCE, &my_address);
if(dodag != NULL) { if (dodag != NULL) {
dodag->of = (struct rpl_of_t*) rpl_get_of_for_ocp(RPL_DEFAULT_OCP); dodag->of = (struct rpl_of_t*) rpl_get_of_for_ocp(RPL_DEFAULT_OCP);
dodag->instance = inst; dodag->instance = inst;
dodag->mop = RPL_DEFAULT_MOP; dodag->mop = RPL_DEFAULT_MOP;
@ -270,7 +270,7 @@ void send_DIO(ipv6_addr_t *destination)
mydodag = rpl_get_my_dodag(); mydodag = rpl_get_my_dodag();
if(mydodag == NULL) { if (mydodag == NULL) {
printf("Error, trying to send DIO without being part of a dodag. This should not happen\n"); printf("Error, trying to send DIO without being part of a dodag. This should not happen\n");
mutex_unlock(&rpl_send_mutex, 0); mutex_unlock(&rpl_send_mutex, 0);
return; return;
@ -292,7 +292,7 @@ void send_DIO(ipv6_addr_t *destination)
rpl_send_dio_buf->dodagid = mydodag->dodag_id; rpl_send_dio_buf->dodagid = mydodag->dodag_id;
int opt_hdr_len = 0; int opt_hdr_len = 0;
/* DODAG Configuration Option! */ /* DODAG Configuration Option!*/
rpl_send_opt_dodag_conf_buf = get_rpl_send_opt_dodag_conf_buf(DIO_BASE_LEN); rpl_send_opt_dodag_conf_buf = get_rpl_send_opt_dodag_conf_buf(DIO_BASE_LEN);
rpl_send_opt_dodag_conf_buf->type = RPL_OPT_DODAG_CONF; rpl_send_opt_dodag_conf_buf->type = RPL_OPT_DODAG_CONF;
rpl_send_opt_dodag_conf_buf->length = RPL_OPT_DODAG_CONF_LEN; rpl_send_opt_dodag_conf_buf->length = RPL_OPT_DODAG_CONF_LEN;
@ -335,7 +335,7 @@ void send_DIS(ipv6_addr_t *destination)
void send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, uint8_t start_index) void send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, uint8_t start_index)
{ {
if(i_am_root) { if (i_am_root) {
return; return;
} }
@ -343,11 +343,11 @@ void send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime,
rpl_dodag_t *my_dodag; rpl_dodag_t *my_dodag;
my_dodag = rpl_get_my_dodag(); my_dodag = rpl_get_my_dodag();
if(destination == NULL) { if (destination == NULL) {
destination = &my_dodag->my_preferred_parent->addr; destination = &my_dodag->my_preferred_parent->addr;
} }
if(default_lifetime) { if (default_lifetime) {
lifetime = my_dodag->default_lifetime; lifetime = my_dodag->default_lifetime;
} }
@ -357,7 +357,7 @@ void send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime,
icmp_send_buf->code = ICMP_CODE_DAO; icmp_send_buf->code = ICMP_CODE_DAO;
icmp_send_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6); icmp_send_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6);
if(my_dodag == NULL) { if (my_dodag == NULL) {
mutex_unlock(&rpl_send_mutex, 0); mutex_unlock(&rpl_send_mutex, 0);
return; return;
} }
@ -373,8 +373,8 @@ void send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime,
uint8_t entries = 0; uint8_t entries = 0;
uint8_t continue_index = 0; uint8_t continue_index = 0;
for(uint8_t i = start_index; i < RPL_MAX_ROUTING_ENTRIES; i++) { for (uint8_t i = start_index; i < RPL_MAX_ROUTING_ENTRIES; i++) {
if(routing_table[i].used) { if (routing_table[i].used) {
rpl_send_opt_target_buf->type = RPL_OPT_TARGET; rpl_send_opt_target_buf->type = RPL_OPT_TARGET;
rpl_send_opt_target_buf->length = RPL_OPT_TARGET_LEN; rpl_send_opt_target_buf->length = RPL_OPT_TARGET_LEN;
rpl_send_opt_target_buf->flags = 0x00; rpl_send_opt_target_buf->flags = 0x00;
@ -393,7 +393,7 @@ void send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime,
entries++; entries++;
} }
if(entries >= 5) { if (entries >= 5) {
/* split DAO, so packages dont get too big. */ /* split DAO, so packages dont get too big. */
/* The value 5 is based on experience */ /* The value 5 is based on experience */
continue_index = i + 1; continue_index = i + 1;
@ -422,7 +422,7 @@ void send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime,
rpl_send(destination, (uint8_t *)icmp_send_buf, plen, PROTO_NUM_ICMPV6, NULL); rpl_send(destination, (uint8_t *)icmp_send_buf, plen, PROTO_NUM_ICMPV6, NULL);
mutex_unlock(&rpl_send_mutex, 0); mutex_unlock(&rpl_send_mutex, 0);
if(continue_index > 1) { if (continue_index > 1) {
send_DAO(destination, lifetime, default_lifetime, continue_index); send_DAO(destination, lifetime, default_lifetime, continue_index);
} }
} }
@ -433,7 +433,7 @@ void send_DAO_ACK(ipv6_addr_t *destination)
rpl_dodag_t *my_dodag; rpl_dodag_t *my_dodag;
my_dodag = rpl_get_my_dodag(); my_dodag = rpl_get_my_dodag();
if(my_dodag == NULL) { if (my_dodag == NULL) {
return; return;
} }
@ -463,7 +463,7 @@ void rpl_process(void)
msg_t m_recv; msg_t m_recv;
msg_init_queue(msg_queue, RPL_PKT_RECV_BUF_SIZE); msg_init_queue(msg_queue, RPL_PKT_RECV_BUF_SIZE);
while(1) { while (1) {
msg_receive(&m_recv); msg_receive(&m_recv);
uint8_t *code; uint8_t *code;
code = ((uint8_t *)m_recv.content.ptr); code = ((uint8_t *)m_recv.content.ptr);
@ -472,25 +472,25 @@ void rpl_process(void)
memcpy(&rpl_buffer, ipv6_buf, ipv6_buf->length + IPV6_HDR_LEN); memcpy(&rpl_buffer, ipv6_buf, ipv6_buf->length + IPV6_HDR_LEN);
switch(*code) { switch(*code) {
case(ICMP_CODE_DIS): { case (ICMP_CODE_DIS): {
recv_rpl_dis(); recv_rpl_dis();
mutex_unlock(&rpl_recv_mutex, 0); mutex_unlock(&rpl_recv_mutex, 0);
break; break;
} }
case(ICMP_CODE_DIO): { case (ICMP_CODE_DIO): {
recv_rpl_dio(); recv_rpl_dio();
mutex_unlock(&rpl_recv_mutex, 0); mutex_unlock(&rpl_recv_mutex, 0);
break; break;
} }
case(ICMP_CODE_DAO): { case (ICMP_CODE_DAO): {
recv_rpl_dao(); recv_rpl_dao();
mutex_unlock(&rpl_recv_mutex, 0); mutex_unlock(&rpl_recv_mutex, 0);
break; break;
} }
case(ICMP_CODE_DAO_ACK): { case (ICMP_CODE_DAO_ACK): {
recv_rpl_dao_ack(); recv_rpl_dao_ack();
mutex_unlock(&rpl_recv_mutex, 0); mutex_unlock(&rpl_recv_mutex, 0);
break; break;
@ -515,19 +515,19 @@ void recv_rpl_dio(void)
rpl_instance_t *dio_inst = rpl_get_instance(rpl_dio_buf->rpl_instanceid); rpl_instance_t *dio_inst = rpl_get_instance(rpl_dio_buf->rpl_instanceid);
rpl_instance_t *my_inst = rpl_get_my_instance(); rpl_instance_t *my_inst = rpl_get_my_instance();
if(dio_inst == NULL) { if (dio_inst == NULL) {
if(my_inst != NULL) { if (my_inst != NULL) {
/* Dieser Knoten ist schon Teil eines DODAGS -> kein beitritt zu anderer Instanz moeglich */ /* Dieser Knoten ist schon Teil eines DODAGS -> kein beitritt zu anderer Instanz moeglich */
return; return;
} }
dio_inst = rpl_new_instance(rpl_dio_buf->rpl_instanceid); dio_inst = rpl_new_instance(rpl_dio_buf->rpl_instanceid);
if(dio_inst == NULL) { if (dio_inst == NULL) {
return; return;
} }
} }
else if(my_inst->id != dio_inst->id) { else if (my_inst->id != dio_inst->id) {
printf("Andere Instanz, wir haben %d es kam aber %d\n", my_inst->id, dio_inst->id); printf("Andere Instanz, wir haben %d es kam aber %d\n", my_inst->id, dio_inst->id);
/* DIO von fremder Instanz ignorieren, Knoten können Momentan nur /* DIO von fremder Instanz ignorieren, Knoten können Momentan nur
* einer Instanz beitreten und das wird die Instanz sein, der sie als * einer Instanz beitreten und das wird die Instanz sein, der sie als
@ -558,35 +558,35 @@ void recv_rpl_dio(void)
* IPV6_HDR_LEN nicht enthalten, also muss nur noch die ICMPV6_HDR_LEN * IPV6_HDR_LEN nicht enthalten, also muss nur noch die ICMPV6_HDR_LEN
* abgezogen werden */ * abgezogen werden */
while(len < (ipv6_buf->length - ICMPV6_HDR_LEN)) { while (len < (ipv6_buf->length - ICMPV6_HDR_LEN)) {
rpl_opt_buf = get_rpl_opt_buf(len); rpl_opt_buf = get_rpl_opt_buf(len);
switch(rpl_opt_buf->type) { switch(rpl_opt_buf->type) {
case(RPL_OPT_PAD1): { case (RPL_OPT_PAD1): {
len += 1; len += 1;
break; break;
} }
case(RPL_OPT_PADN): { case (RPL_OPT_PADN): {
len += rpl_opt_buf->length + 2; len += rpl_opt_buf->length + 2;
break; break;
} }
case(RPL_OPT_DAG_METRIC_CONTAINER): { case (RPL_OPT_DAG_METRIC_CONTAINER): {
len += rpl_opt_buf->length + 2; len += rpl_opt_buf->length + 2;
break; break;
} }
case(RPL_OPT_ROUTE_INFO): { case (RPL_OPT_ROUTE_INFO): {
len += rpl_opt_buf->length + 2; len += rpl_opt_buf->length + 2;
break; break;
} }
case(RPL_OPT_DODAG_CONF): { case (RPL_OPT_DODAG_CONF): {
has_dodag_conf_opt = 1; has_dodag_conf_opt = 1;
if(rpl_opt_buf->length != RPL_OPT_DODAG_CONF_LEN) { if (rpl_opt_buf->length != RPL_OPT_DODAG_CONF_LEN) {
/* error malformed */ /* error malformed */
return; return;
} }
@ -604,8 +604,8 @@ void recv_rpl_dio(void)
break; break;
} }
case(RPL_OPT_PREFIX_INFO): { case (RPL_OPT_PREFIX_INFO): {
if(rpl_opt_buf->length != RPL_OPT_PREFIX_INFO_LEN) { if (rpl_opt_buf->length != RPL_OPT_PREFIX_INFO_LEN) {
/* error malformed */ /* error malformed */
return; return;
} }
@ -623,29 +623,29 @@ void recv_rpl_dio(void)
/* handle packet content... */ /* handle packet content... */
rpl_dodag_t *my_dodag = rpl_get_my_dodag(); rpl_dodag_t *my_dodag = rpl_get_my_dodag();
if(my_dodag == NULL) { if (my_dodag == NULL) {
if(!has_dodag_conf_opt) { if (!has_dodag_conf_opt) {
puts("send DIS"); puts("send DIS");
send_DIS(&ipv6_buf->srcaddr); send_DIS(&ipv6_buf->srcaddr);
return; return;
} }
if(rpl_dio_buf->rank < ROOT_RANK) { if (rpl_dio_buf->rank < ROOT_RANK) {
printf("DIO with Rank < ROOT_RANK\n"); printf("DIO with Rank < ROOT_RANK\n");
return; return;
} }
if(dio_dodag.mop != RPL_DEFAULT_MOP) { if (dio_dodag.mop != RPL_DEFAULT_MOP) {
printf("Required MOP not supported\n"); printf("Required MOP not supported\n");
return; return;
} }
if(dio_dodag.of == NULL) { if (dio_dodag.of == NULL) {
printf("Required objective function not supported\n"); printf("Required objective function not supported\n");
return; return;
} }
if(rpl_dio_buf->rank != INFINITE_RANK) { if (rpl_dio_buf->rank != INFINITE_RANK) {
puts("Will join DODAG\n"); puts("Will join DODAG\n");
ipv6_print_addr(&dio_dodag.dodag_id); ipv6_print_addr(&dio_dodag.dodag_id);
rpl_join_dodag(&dio_dodag, &ipv6_buf->srcaddr, rpl_dio_buf->rank); rpl_join_dodag(&dio_dodag, &ipv6_buf->srcaddr, rpl_dio_buf->rank);
@ -656,10 +656,10 @@ void recv_rpl_dio(void)
} }
} }
if(rpl_equal_id(&my_dodag->dodag_id, &dio_dodag.dodag_id)) { if (rpl_equal_id(&my_dodag->dodag_id, &dio_dodag.dodag_id)) {
/* Mein DODAG */ /* Mein DODAG */
if(RPL_COUNTER_GREATER_THAN(dio_dodag.version, my_dodag->version)) { if (RPL_COUNTER_GREATER_THAN(dio_dodag.version, my_dodag->version)) {
if(my_dodag->my_rank == ROOT_RANK) { if (my_dodag->my_rank == ROOT_RANK) {
/* Jemand hat ein DIO mit einer höheren Version als der richtigen gesendet */ /* Jemand hat ein DIO mit einer höheren Version als der richtigen gesendet */
/* Wir erhöhen diese Version noch einmal, und machen sie zur neuen */ /* Wir erhöhen diese Version noch einmal, und machen sie zur neuen */
printf("[Warning] Inconsistent Dodag Version\n"); printf("[Warning] Inconsistent Dodag Version\n");
@ -673,7 +673,7 @@ void recv_rpl_dio(void)
return; return;
} }
else if(RPL_COUNTER_GREATER_THAN(my_dodag->version, dio_dodag.version)) { else if (RPL_COUNTER_GREATER_THAN(my_dodag->version, dio_dodag.version)) {
/* ein Knoten hat noch eine kleinere Versionsnummer -> mehr DIOs senden */ /* ein Knoten hat noch eine kleinere Versionsnummer -> mehr DIOs senden */
reset_trickletimer(); reset_trickletimer();
return; return;
@ -681,13 +681,13 @@ void recv_rpl_dio(void)
} }
/* Version stimmt, DODAG stimmt */ /* Version stimmt, DODAG stimmt */
if(rpl_dio_buf->rank == INFINITE_RANK) { if (rpl_dio_buf->rank == INFINITE_RANK) {
reset_trickletimer(); reset_trickletimer();
} }
/* Wenn wir root sind, ist nichts weiter zu tun */ /* Wenn wir root sind, ist nichts weiter zu tun */
if(my_dodag->my_rank == ROOT_RANK) { if (my_dodag->my_rank == ROOT_RANK) {
if(rpl_dio_buf->rank != INFINITE_RANK) { if (rpl_dio_buf->rank != INFINITE_RANK) {
trickle_increment_counter(); trickle_increment_counter();
} }
@ -702,11 +702,11 @@ void recv_rpl_dio(void)
rpl_parent_t *parent; rpl_parent_t *parent;
parent = rpl_find_parent(&ipv6_buf->srcaddr); parent = rpl_find_parent(&ipv6_buf->srcaddr);
if(parent == NULL) { if (parent == NULL) {
/* neuen möglichen Elternknoten hinzufuegen */ /* neuen möglichen Elternknoten hinzufuegen */
parent = rpl_new_parent(my_dodag, &ipv6_buf->srcaddr, rpl_dio_buf->rank); parent = rpl_new_parent(my_dodag, &ipv6_buf->srcaddr, rpl_dio_buf->rank);
if(parent == NULL) { if (parent == NULL) {
return; return;
} }
} }
@ -719,7 +719,7 @@ void recv_rpl_dio(void)
parent->rank = rpl_dio_buf->rank; parent->rank = rpl_dio_buf->rank;
rpl_parent_update(parent); rpl_parent_update(parent);
if(rpl_equal_id(&parent->addr, &my_dodag->my_preferred_parent->addr) && (parent->dtsn != rpl_dio_buf->dtsn)) { if (rpl_equal_id(&parent->addr, &my_dodag->my_preferred_parent->addr) && (parent->dtsn != rpl_dio_buf->dtsn)) {
delay_dao(); delay_dao();
} }
@ -731,7 +731,7 @@ void recv_rpl_dis(void)
{ {
rpl_dodag_t *my_dodag = rpl_get_my_dodag(); rpl_dodag_t *my_dodag = rpl_get_my_dodag();
if(my_dodag == NULL) { if (my_dodag == NULL) {
return; return;
} }
@ -739,45 +739,45 @@ void recv_rpl_dis(void)
rpl_dis_buf = get_rpl_dis_buf(); rpl_dis_buf = get_rpl_dis_buf();
int len = DIS_BASE_LEN; int len = DIS_BASE_LEN;
while(len < (ipv6_buf->length - ICMPV6_HDR_LEN)) { while (len < (ipv6_buf->length - ICMPV6_HDR_LEN)) {
rpl_opt_buf = get_rpl_opt_buf(len); rpl_opt_buf = get_rpl_opt_buf(len);
switch(rpl_opt_buf->type) { switch(rpl_opt_buf->type) {
case(RPL_OPT_PAD1): { case (RPL_OPT_PAD1): {
len += 1; len += 1;
break; break;
} }
case(RPL_OPT_PADN): { case (RPL_OPT_PADN): {
len += rpl_opt_buf->length + 2; len += rpl_opt_buf->length + 2;
break; break;
} }
case(RPL_OPT_SOLICITED_INFO): { case (RPL_OPT_SOLICITED_INFO): {
len += RPL_OPT_SOLICITED_INFO_LEN + 2; len += RPL_OPT_SOLICITED_INFO_LEN + 2;
/* extract + check */ /* extract + check */
if(rpl_opt_buf->length != RPL_OPT_SOLICITED_INFO_LEN) { if (rpl_opt_buf->length != RPL_OPT_SOLICITED_INFO_LEN) {
/* error malformed */ /* error malformed */
return; return;
} }
rpl_opt_solicited_buf = get_rpl_opt_solicited_buf(len); rpl_opt_solicited_buf = get_rpl_opt_solicited_buf(len);
if(rpl_opt_solicited_buf->VID_Flags & RPL_DIS_I_MASK) { if (rpl_opt_solicited_buf->VID_Flags & RPL_DIS_I_MASK) {
if(my_dodag->instance->id != rpl_opt_solicited_buf->rplinstanceid) { if (my_dodag->instance->id != rpl_opt_solicited_buf->rplinstanceid) {
return; return;
} }
} }
if(rpl_opt_solicited_buf->VID_Flags & RPL_DIS_D_MASK) { if (rpl_opt_solicited_buf->VID_Flags & RPL_DIS_D_MASK) {
if(!rpl_equal_id(&my_dodag->dodag_id, &rpl_opt_solicited_buf->dodagid)) { if (!rpl_equal_id(&my_dodag->dodag_id, &rpl_opt_solicited_buf->dodagid)) {
return; return;
} }
} }
if(rpl_opt_solicited_buf->VID_Flags & RPL_DIS_V_MASK) { if (rpl_opt_solicited_buf->VID_Flags & RPL_DIS_V_MASK) {
if(my_dodag->version != rpl_opt_solicited_buf->version) { if (my_dodag->version != rpl_opt_solicited_buf->version) {
return; return;
} }
} }
@ -798,7 +798,7 @@ void recv_rpl_dao(void)
{ {
rpl_dodag_t *my_dodag = rpl_get_my_dodag(); rpl_dodag_t *my_dodag = rpl_get_my_dodag();
if(my_dodag == NULL) { if (my_dodag == NULL) {
printf("[Error] got DAO without beeing part of a Dodag\n"); printf("[Error] got DAO without beeing part of a Dodag\n");
return; return;
} }
@ -808,30 +808,30 @@ void recv_rpl_dao(void)
int len = DAO_BASE_LEN; int len = DAO_BASE_LEN;
uint8_t increment_seq = 0; uint8_t increment_seq = 0;
while(len < (ipv6_buf->length - ICMPV6_HDR_LEN)) { while (len < (ipv6_buf->length - ICMPV6_HDR_LEN)) {
rpl_opt_buf = get_rpl_opt_buf(len); rpl_opt_buf = get_rpl_opt_buf(len);
switch(rpl_opt_buf->type) { switch(rpl_opt_buf->type) {
case(RPL_OPT_PAD1): { case (RPL_OPT_PAD1): {
len += 1; len += 1;
break; break;
} }
case(RPL_OPT_PADN): { case (RPL_OPT_PADN): {
len += rpl_opt_buf->length + 2; len += rpl_opt_buf->length + 2;
break; break;
} }
case(RPL_OPT_DAG_METRIC_CONTAINER): { case (RPL_OPT_DAG_METRIC_CONTAINER): {
len += rpl_opt_buf->length + 2; len += rpl_opt_buf->length + 2;
break; break;
} }
case(RPL_OPT_TARGET): { case (RPL_OPT_TARGET): {
rpl_opt_target_buf = get_rpl_opt_target_buf(len); rpl_opt_target_buf = get_rpl_opt_target_buf(len);
if(rpl_opt_target_buf->prefix_length != RPL_DODAG_ID_LEN) { if (rpl_opt_target_buf->prefix_length != RPL_DODAG_ID_LEN) {
printf("prefixes are not supported yet"); printf("prefixes are not supported yet");
break; break;
} }
@ -839,7 +839,7 @@ void recv_rpl_dao(void)
len += rpl_opt_target_buf->length + 2; len += rpl_opt_target_buf->length + 2;
rpl_opt_transit_buf = get_rpl_opt_transit_buf(len); rpl_opt_transit_buf = get_rpl_opt_transit_buf(len);
if(rpl_opt_transit_buf->type != RPL_OPT_TRANSIT) { if (rpl_opt_transit_buf->type != RPL_OPT_TRANSIT) {
printf("[Error] - no Transit Inforamtion to Target Option, type = %d\n", rpl_opt_transit_buf->type); printf("[Error] - no Transit Inforamtion to Target Option, type = %d\n", rpl_opt_transit_buf->type);
break; break;
} }
@ -852,12 +852,12 @@ void recv_rpl_dao(void)
break; break;
} }
case(RPL_OPT_TRANSIT): { case (RPL_OPT_TRANSIT): {
len += rpl_opt_buf->length + 2; len += rpl_opt_buf->length + 2;
break; break;
} }
case(RPL_OPT_TARGET_DESC): { case (RPL_OPT_TARGET_DESC): {
len += rpl_opt_buf->length + 2; len += rpl_opt_buf->length + 2;
break; break;
} }
@ -869,7 +869,7 @@ void recv_rpl_dao(void)
send_DAO_ACK(&ipv6_buf->srcaddr); send_DAO_ACK(&ipv6_buf->srcaddr);
if(increment_seq) { if (increment_seq) {
RPL_COUNTER_INCREMENT(my_dodag->dao_seq); RPL_COUNTER_INCREMENT(my_dodag->dao_seq);
delay_dao(); delay_dao();
} }
@ -879,17 +879,17 @@ void recv_rpl_dao_ack(void)
{ {
rpl_dodag_t *my_dodag = rpl_get_my_dodag(); rpl_dodag_t *my_dodag = rpl_get_my_dodag();
if(my_dodag == NULL) { if (my_dodag == NULL) {
return; return;
} }
rpl_dao_ack_buf = get_rpl_dao_ack_buf(); rpl_dao_ack_buf = get_rpl_dao_ack_buf();
if(rpl_dao_ack_buf->rpl_instanceid != my_dodag->instance->id) { if (rpl_dao_ack_buf->rpl_instanceid != my_dodag->instance->id) {
return; return;
} }
if(rpl_dao_ack_buf->status != 0) { if (rpl_dao_ack_buf->status != 0) {
return; return;
} }
@ -919,21 +919,21 @@ void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_
* der rpl_send_buf verwendet. In diesem Fall muss also keine memcopy * der rpl_send_buf verwendet. In diesem Fall muss also keine memcopy
* Aktion durchgeführt werden, da sich der payload bereits im richtigen * Aktion durchgeführt werden, da sich der payload bereits im richtigen
* Speicherbereich befindet. */ * Speicherbereich befindet. */
if(p_ptr != payload) { if (p_ptr != payload) {
memcpy(p_ptr, payload, p_len); memcpy(p_ptr, payload, p_len);
} }
packet_length = IPV6_HDR_LEN + p_len; packet_length = IPV6_HDR_LEN + p_len;
if(ipv6_prefix_mcast_match(&ipv6_send_buf->destaddr)) { if (ipv6_prefix_mcast_match(&ipv6_send_buf->destaddr)) {
lowpan_init((ieee_802154_long_t *)&(ipv6_send_buf->destaddr.uint16[4]), (uint8_t *)ipv6_send_buf); lowpan_init((ieee_802154_long_t *)&(ipv6_send_buf->destaddr.uint16[4]), (uint8_t *)ipv6_send_buf);
} }
else { else {
/* find right next hop before sending */ /* find right next hop before sending */
ipv6_addr_t *next_hop = rpl_get_next_hop(&ipv6_send_buf->destaddr); ipv6_addr_t *next_hop = rpl_get_next_hop(&ipv6_send_buf->destaddr);
if(next_hop == NULL) { if (next_hop == NULL) {
if(i_am_root) { if (i_am_root) {
/* oops... ich bin root und weiß nicht wohin mit dem paketn */ /* oops... ich bin root und weiß nicht wohin mit dem paketn */
printf("[Error] destination unknown\n"); printf("[Error] destination unknown\n");
return; return;
@ -941,7 +941,7 @@ void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_
else { else {
next_hop = rpl_get_my_preferred_parent(); next_hop = rpl_get_my_preferred_parent();
if(next_hop == NULL) { if (next_hop == NULL) {
/* kein preferred parent eingetragen */ /* kein preferred parent eingetragen */
puts("[Error] no preferred parent, dropping package"); puts("[Error] no preferred parent, dropping package");
return; return;
@ -956,8 +956,8 @@ void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_
ipv6_addr_t *rpl_get_next_hop(ipv6_addr_t *addr) ipv6_addr_t *rpl_get_next_hop(ipv6_addr_t *addr)
{ {
for(uint8_t i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) { for (uint8_t i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) {
if(routing_table[i].used && rpl_equal_id(&routing_table[i].address, addr)) { if (routing_table[i].used && rpl_equal_id(&routing_table[i].address, addr)) {
return &routing_table[i].next_hop; return &routing_table[i].next_hop;
} }
} }
@ -969,13 +969,13 @@ void rpl_add_routing_entry(ipv6_addr_t *addr, ipv6_addr_t *next_hop, uint16_t li
{ {
rpl_routing_entry_t *entry = rpl_find_routing_entry(addr); rpl_routing_entry_t *entry = rpl_find_routing_entry(addr);
if(entry != NULL) { if (entry != NULL) {
entry->lifetime = lifetime; entry->lifetime = lifetime;
return; return;
} }
for(uint8_t i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) { for (uint8_t i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) {
if(!routing_table[i].used) { if (!routing_table[i].used) {
routing_table[i].address = *addr; routing_table[i].address = *addr;
routing_table[i].next_hop = *next_hop; routing_table[i].next_hop = *next_hop;
routing_table[i].lifetime = lifetime; routing_table[i].lifetime = lifetime;
@ -987,8 +987,8 @@ void rpl_add_routing_entry(ipv6_addr_t *addr, ipv6_addr_t *next_hop, uint16_t li
void rpl_del_routing_entry(ipv6_addr_t *addr) void rpl_del_routing_entry(ipv6_addr_t *addr)
{ {
for(uint8_t i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) { for (uint8_t i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) {
if(routing_table[i].used && rpl_equal_id(&routing_table[i].address, addr)) { if (routing_table[i].used && rpl_equal_id(&routing_table[i].address, addr)) {
memset(&routing_table[i], 0, sizeof(routing_table[i])); memset(&routing_table[i], 0, sizeof(routing_table[i]));
return; return;
} }
@ -997,8 +997,8 @@ void rpl_del_routing_entry(ipv6_addr_t *addr)
rpl_routing_entry_t *rpl_find_routing_entry(ipv6_addr_t *addr) rpl_routing_entry_t *rpl_find_routing_entry(ipv6_addr_t *addr)
{ {
for(uint8_t i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) { for (uint8_t i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) {
if(routing_table[i].used && rpl_equal_id(&routing_table[i].address, addr)) { if (routing_table[i].used && rpl_equal_id(&routing_table[i].address, addr)) {
return &routing_table[i]; return &routing_table[i];
} }
} }
@ -1008,7 +1008,7 @@ rpl_routing_entry_t *rpl_find_routing_entry(ipv6_addr_t *addr)
void rpl_clear_routing_table(void) void rpl_clear_routing_table(void)
{ {
for(uint8_t i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) { for (uint8_t i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) {
memset(&routing_table[i], 0, sizeof(routing_table[i])); memset(&routing_table[i], 0, sizeof(routing_table[i]));
} }

View File

@ -32,8 +32,8 @@ rpl_instance_t *rpl_new_instance(uint8_t instanceid)
rpl_instance_t *inst; rpl_instance_t *inst;
rpl_instance_t *end ; rpl_instance_t *end ;
for(inst = &instances[0], end = inst + RPL_MAX_INSTANCES; inst < end; inst++) { for (inst = &instances[0], end = inst + RPL_MAX_INSTANCES; inst < end; inst++) {
if(inst->used == 0) { if (inst->used == 0) {
memset(inst, 0, sizeof(*inst)); memset(inst, 0, sizeof(*inst));
inst->used = 1; inst->used = 1;
inst->id = instanceid; inst->id = instanceid;
@ -45,8 +45,8 @@ rpl_instance_t *rpl_new_instance(uint8_t instanceid)
} }
rpl_instance_t *rpl_get_instance(uint8_t instanceid) rpl_instance_t *rpl_get_instance(uint8_t instanceid)
{ {
for(int i = 0; i < RPL_MAX_INSTANCES; i++) { for (int i = 0; i < RPL_MAX_INSTANCES; i++) {
if(instances[i].used && (instances[i].id == instanceid)) { if (instances[i].used && (instances[i].id == instanceid)) {
return &instances[i]; return &instances[i];
} }
} }
@ -56,8 +56,8 @@ rpl_instance_t *rpl_get_instance(uint8_t instanceid)
rpl_instance_t *rpl_get_my_instance() rpl_instance_t *rpl_get_my_instance()
{ {
for(int i = 0; i < RPL_MAX_INSTANCES; i++) { for (int i = 0; i < RPL_MAX_INSTANCES; i++) {
if(instances[i].joined) { if (instances[i].joined) {
return &instances[i]; return &instances[i];
} }
} }
@ -70,7 +70,7 @@ rpl_dodag_t *rpl_new_dodag(uint8_t instanceid, ipv6_addr_t *dodagid)
rpl_instance_t *inst; rpl_instance_t *inst;
inst = rpl_get_instance(instanceid); inst = rpl_get_instance(instanceid);
if(inst == NULL) { if (inst == NULL) {
printf("Error - No instance found for id %d. This should not happen\n", printf("Error - No instance found for id %d. This should not happen\n",
instanceid); instanceid);
return NULL; return NULL;
@ -79,8 +79,8 @@ rpl_dodag_t *rpl_new_dodag(uint8_t instanceid, ipv6_addr_t *dodagid)
rpl_dodag_t *dodag; rpl_dodag_t *dodag;
rpl_dodag_t *end; rpl_dodag_t *end;
for(dodag = &dodags[0], end = dodag + RPL_MAX_DODAGS; dodag < end; dodag++) { for (dodag = &dodags[0], end = dodag + RPL_MAX_DODAGS; dodag < end; dodag++) {
if(dodag->used == 0) { if (dodag->used == 0) {
memset(dodag, 0, sizeof(*dodag)); memset(dodag, 0, sizeof(*dodag));
dodag->instance = inst; dodag->instance = inst;
dodag->my_rank = INFINITE_RANK; dodag->my_rank = INFINITE_RANK;
@ -96,8 +96,8 @@ rpl_dodag_t *rpl_new_dodag(uint8_t instanceid, ipv6_addr_t *dodagid)
rpl_dodag_t *rpl_get_dodag(ipv6_addr_t *id) rpl_dodag_t *rpl_get_dodag(ipv6_addr_t *id)
{ {
for(int i = 0; i < RPL_MAX_DODAGS; i++) { for (int i = 0; i < RPL_MAX_DODAGS; i++) {
if(dodags[i].used && (rpl_equal_id(&dodags[i].dodag_id, id))) { if (dodags[i].used && (rpl_equal_id(&dodags[i].dodag_id, id))) {
return &dodags[i]; return &dodags[i];
} }
} }
@ -106,8 +106,8 @@ rpl_dodag_t *rpl_get_dodag(ipv6_addr_t *id)
} }
rpl_dodag_t *rpl_get_my_dodag() rpl_dodag_t *rpl_get_my_dodag()
{ {
for(int i = 0; i < RPL_MAX_DODAGS; i++) { for (int i = 0; i < RPL_MAX_DODAGS; i++) {
if(dodags[i].joined) { if (dodags[i].joined) {
return &dodags[i]; return &dodags[i];
} }
} }
@ -128,8 +128,8 @@ void rpl_leave_dodag(rpl_dodag_t *dodag)
bool rpl_equal_id(ipv6_addr_t *id1, ipv6_addr_t *id2) bool rpl_equal_id(ipv6_addr_t *id1, ipv6_addr_t *id2)
{ {
for(uint8_t i = 0; i < 4; i++) { for (uint8_t i = 0; i < 4; i++) {
if(id1->uint32[i] != id2->uint32[i]) { if (id1->uint32[i] != id2->uint32[i]) {
return false; return false;
} }
} }
@ -143,8 +143,8 @@ rpl_parent_t *rpl_new_parent(rpl_dodag_t *dodag, ipv6_addr_t *address, uint16_t
rpl_parent_t *parent; rpl_parent_t *parent;
rpl_parent_t *end; rpl_parent_t *end;
for(parent = &parents[0], end = parents + RPL_MAX_PARENTS; parent < end; parent++) { for (parent = &parents[0], end = parents + RPL_MAX_PARENTS; parent < end; parent++) {
if(parent->used == 0) { if (parent->used == 0) {
memset(parent, 0, sizeof(*parent)); memset(parent, 0, sizeof(*parent));
parent->used = 1; parent->used = 1;
parent->addr = *address; parent->addr = *address;
@ -165,8 +165,8 @@ rpl_parent_t *rpl_find_parent(ipv6_addr_t *address)
rpl_parent_t *parent; rpl_parent_t *parent;
rpl_parent_t *end; rpl_parent_t *end;
for(parent = &parents[0], end = parents + RPL_MAX_PARENTS; parent < end; parent++) { for (parent = &parents[0], end = parents + RPL_MAX_PARENTS; parent < end; parent++) {
if((parent->used) && (rpl_equal_id(address, &parent->addr))) { if ((parent->used) && (rpl_equal_id(address, &parent->addr))) {
return parent; return parent;
} }
} }
@ -178,7 +178,7 @@ void rpl_delete_parent(rpl_parent_t *parent)
{ {
rpl_dodag_t *my_dodag = rpl_get_my_dodag(); rpl_dodag_t *my_dodag = rpl_get_my_dodag();
if((my_dodag != NULL) && rpl_equal_id(&my_dodag->my_preferred_parent->addr, if ((my_dodag != NULL) && rpl_equal_id(&my_dodag->my_preferred_parent->addr,
&parent->addr)) { &parent->addr)) {
my_dodag->my_preferred_parent = NULL; my_dodag->my_preferred_parent = NULL;
} }
@ -191,14 +191,14 @@ void rpl_delete_worst_parent(void)
uint8_t worst = 0xFF; uint8_t worst = 0xFF;
uint16_t max_rank = 0x0000; uint16_t max_rank = 0x0000;
for(int i = 0; i < RPL_MAX_PARENTS; i++) { for (int i = 0; i < RPL_MAX_PARENTS; i++) {
if(parents[i].rank > max_rank) { if (parents[i].rank > max_rank) {
worst = i; worst = i;
max_rank = parents[i].rank; max_rank = parents[i].rank;
} }
} }
if(worst == 0xFF) { if (worst == 0xFF) {
/* Fehler, keine parents -> sollte nicht passieren */ /* Fehler, keine parents -> sollte nicht passieren */
return; return;
} }
@ -212,7 +212,7 @@ void rpl_delete_all_parents(void)
rpl_dodag_t *my_dodag = rpl_get_my_dodag(); rpl_dodag_t *my_dodag = rpl_get_my_dodag();
my_dodag->my_preferred_parent = NULL; my_dodag->my_preferred_parent = NULL;
for(int i = 0; i < RPL_MAX_PARENTS; i++) { for (int i = 0; i < RPL_MAX_PARENTS; i++) {
memset(&parents[i], 0, sizeof(parents[i])); memset(&parents[i], 0, sizeof(parents[i]));
} }
} }
@ -222,13 +222,13 @@ rpl_parent_t *rpl_find_preferred_parent(void)
rpl_parent_t *best = NULL; rpl_parent_t *best = NULL;
rpl_dodag_t *my_dodag = rpl_get_my_dodag(); rpl_dodag_t *my_dodag = rpl_get_my_dodag();
for(uint8_t i = 0; i < RPL_MAX_PARENTS; i++) { for (uint8_t i = 0; i < RPL_MAX_PARENTS; i++) {
if(parents[i].used) { if (parents[i].used) {
if((parents[i].rank == INFINITE_RANK) || (parents[i].lifetime <= 1)) { if ((parents[i].rank == INFINITE_RANK) || (parents[i].lifetime <= 1)) {
puts("bad parent"); puts("bad parent");
continue; continue;
} }
else if(best == NULL) { else if (best == NULL) {
puts("parent"); puts("parent");
best = &parents[i]; best = &parents[i];
} }
@ -238,19 +238,19 @@ rpl_parent_t *rpl_find_preferred_parent(void)
} }
} }
if(best == NULL) { if (best == NULL) {
return NULL; return NULL;
} }
if(!rpl_equal_id(&my_dodag->my_preferred_parent->addr, &best->addr)) { if (!rpl_equal_id(&my_dodag->my_preferred_parent->addr, &best->addr)) {
if(my_dodag->mop != NO_DOWNWARD_ROUTES) { if (my_dodag->mop != NO_DOWNWARD_ROUTES) {
/* send DAO with ZERO_LIFETIME to old parent */ /* send DAO with ZERO_LIFETIME to old parent */
send_DAO(&my_dodag->my_preferred_parent->addr, 0, false, 0); send_DAO(&my_dodag->my_preferred_parent->addr, 0, false, 0);
} }
my_dodag->my_preferred_parent = best; my_dodag->my_preferred_parent = best;
if(my_dodag->mop != NO_DOWNWARD_ROUTES) { if (my_dodag->mop != NO_DOWNWARD_ROUTES) {
delay_dao(); delay_dao();
} }
@ -266,17 +266,17 @@ void rpl_parent_update(rpl_parent_t *parent)
uint16_t old_rank = my_dodag->my_rank; uint16_t old_rank = my_dodag->my_rank;
/* update Parent lifetime */ /* update Parent lifetime */
if(parent != NULL) { if (parent != NULL) {
parent->lifetime = my_dodag->default_lifetime * my_dodag->lifetime_unit; parent->lifetime = my_dodag->default_lifetime * my_dodag->lifetime_unit;
} }
if(rpl_find_preferred_parent() == NULL) { if (rpl_find_preferred_parent() == NULL) {
rpl_local_repair(); rpl_local_repair();
} }
if(rpl_calc_rank(old_rank, my_dodag->minhoprankincrease) != if (rpl_calc_rank(old_rank, my_dodag->minhoprankincrease) !=
rpl_calc_rank(my_dodag->my_rank, my_dodag->minhoprankincrease)) { rpl_calc_rank(my_dodag->my_rank, my_dodag->minhoprankincrease)) {
if(my_dodag->my_rank < my_dodag->min_rank) { if (my_dodag->my_rank < my_dodag->min_rank) {
my_dodag->min_rank = my_dodag->my_rank; my_dodag->min_rank = my_dodag->my_rank;
} }
@ -290,13 +290,13 @@ void rpl_join_dodag(rpl_dodag_t *dodag, ipv6_addr_t *parent, uint16_t parent_ran
rpl_parent_t *preferred_parent; rpl_parent_t *preferred_parent;
my_dodag = rpl_new_dodag(dodag->instance->id, &dodag->dodag_id); my_dodag = rpl_new_dodag(dodag->instance->id, &dodag->dodag_id);
if(my_dodag == NULL) { if (my_dodag == NULL) {
return; return;
} }
preferred_parent = rpl_new_parent(my_dodag, parent, parent_rank); preferred_parent = rpl_new_parent(my_dodag, parent, parent_rank);
if(preferred_parent == NULL) { if (preferred_parent == NULL) {
rpl_del_dodag(my_dodag); rpl_del_dodag(my_dodag);
return; return;
} }
@ -330,7 +330,7 @@ void rpl_global_repair(rpl_dodag_t *dodag, ipv6_addr_t *p_addr, uint16_t rank)
puts("[INFO] Global repair started"); puts("[INFO] Global repair started");
rpl_dodag_t *my_dodag = rpl_get_my_dodag(); rpl_dodag_t *my_dodag = rpl_get_my_dodag();
if(my_dodag == NULL) { if (my_dodag == NULL) {
printf("[Error] - no global repair possible, if not part of a DODAG\n"); printf("[Error] - no global repair possible, if not part of a DODAG\n");
return; return;
} }
@ -340,7 +340,7 @@ void rpl_global_repair(rpl_dodag_t *dodag, ipv6_addr_t *p_addr, uint16_t rank)
my_dodag->dtsn++; my_dodag->dtsn++;
my_dodag->my_preferred_parent = rpl_new_parent(my_dodag, p_addr, rank); my_dodag->my_preferred_parent = rpl_new_parent(my_dodag, p_addr, rank);
if(my_dodag->my_preferred_parent == NULL) { if (my_dodag->my_preferred_parent == NULL) {
printf("[Error] no more parent after global repair\n"); printf("[Error] no more parent after global repair\n");
my_dodag->my_rank = INFINITE_RANK; my_dodag->my_rank = INFINITE_RANK;
} }
@ -362,7 +362,7 @@ void rpl_local_repair(void)
puts("[INFO] Local Repair started"); puts("[INFO] Local Repair started");
rpl_dodag_t *my_dodag = rpl_get_my_dodag(); rpl_dodag_t *my_dodag = rpl_get_my_dodag();
if(my_dodag == NULL) { if (my_dodag == NULL) {
printf("[Error] - no local repair possible, if not part of a DODAG\n"); printf("[Error] - no local repair possible, if not part of a DODAG\n");
return; return;
} }
@ -378,7 +378,7 @@ ipv6_addr_t *rpl_get_my_preferred_parent()
{ {
rpl_dodag_t *my_dodag = rpl_get_my_dodag(); rpl_dodag_t *my_dodag = rpl_get_my_dodag();
if(my_dodag == NULL) { if (my_dodag == NULL) {
return NULL; return NULL;
} }

View File

@ -121,11 +121,11 @@ void trickle_timer_over(void)
ipv6_addr_t mcast; ipv6_addr_t mcast;
ipv6_set_all_nds_mcast_addr(&mcast); ipv6_set_all_nds_mcast_addr(&mcast);
while(1) { while (1) {
thread_sleep(); thread_sleep();
/* Laut RPL Spezifikation soll k=0 wie k= Unendlich behandelt werden, also immer gesendet werden */ /* Laut RPL Spezifikation soll k=0 wie k= Unendlich behandelt werden, also immer gesendet werden */
if((c < k) || (k == 0)) { if ((c < k) || (k == 0)) {
send_DIO(&mcast); send_DIO(&mcast);
} }
} }
@ -133,22 +133,22 @@ void trickle_timer_over(void)
void trickle_interval_over(void) void trickle_interval_over(void)
{ {
while(1) { while (1) {
thread_sleep(); thread_sleep();
I = I * 2; I = I * 2;
printf("TRICKLE new Interval %"PRIu32"\n", I); printf("TRICKLE new Interval %"PRIu32"\n", I);
if(I == 0) { if (I == 0) {
puts("[WARNING] Interval was 0"); puts("[WARNING] Interval was 0");
if(Imax == 0) { if (Imax == 0) {
puts("[WARNING] Imax == 0"); puts("[WARNING] Imax == 0");
} }
I = (Imin << Imax); I = (Imin << Imax);
} }
if(I > (Imin << Imax)) { if (I > (Imin << Imax)) {
I = (Imin << Imax); I = (Imin << Imax);
} }
@ -160,11 +160,11 @@ void trickle_interval_over(void)
I_time = timex_set(0, I * 1000); I_time = timex_set(0, I * 1000);
timex_normalize(&I_time); timex_normalize(&I_time);
if(vtimer_set_wakeup(&trickle_t_timer, t_time, timer_over_pid) != 0) { if (vtimer_set_wakeup(&trickle_t_timer, t_time, timer_over_pid) != 0) {
puts("[ERROR] setting Wakeup"); puts("[ERROR] setting Wakeup");
} }
if(vtimer_set_wakeup(&trickle_I_timer, I_time, interval_over_pid) != 0) { if (vtimer_set_wakeup(&trickle_I_timer, I_time, interval_over_pid) != 0) {
puts("[ERROR] setting Wakeup"); puts("[ERROR] setting Wakeup");
} }
} }
@ -192,16 +192,16 @@ void long_delay_dao(void)
void dao_delay_over(void) void dao_delay_over(void)
{ {
while(1) { while (1) {
thread_sleep(); thread_sleep();
if((ack_received == false) && (dao_counter < DAO_SEND_RETRIES)) { if ((ack_received == false) && (dao_counter < DAO_SEND_RETRIES)) {
dao_counter++; dao_counter++;
send_DAO(NULL, 0, true, 0); send_DAO(NULL, 0, true, 0);
dao_time = timex_set(DEFAULT_WAIT_FOR_DAO_ACK, 0); dao_time = timex_set(DEFAULT_WAIT_FOR_DAO_ACK, 0);
vtimer_set_wakeup(&dao_timer, dao_time, dao_delay_over_pid); vtimer_set_wakeup(&dao_timer, dao_time, dao_delay_over_pid);
} }
else if(ack_received == false) { else if (ack_received == false) {
long_delay_dao(); long_delay_dao();
} }
} }
@ -217,15 +217,15 @@ void rt_timer_over(void)
{ {
rpl_routing_entry_t *rt; rpl_routing_entry_t *rt;
while(1) { while (1) {
rpl_dodag_t *my_dodag = rpl_get_my_dodag(); rpl_dodag_t *my_dodag = rpl_get_my_dodag();
if(my_dodag != NULL) { if (my_dodag != NULL) {
rt = rpl_get_routing_table(); rt = rpl_get_routing_table();
for(uint8_t i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) { for (uint8_t i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) {
if(rt[i].used) { if (rt[i].used) {
if(rt[i].lifetime <= 1) { if (rt[i].lifetime <= 1) {
memset(&rt[i], 0, sizeof(rt[i])); memset(&rt[i], 0, sizeof(rt[i]));
} }
else { else {
@ -235,8 +235,8 @@ void rt_timer_over(void)
} }
/* Parent is NULL for root too */ /* Parent is NULL for root too */
if(my_dodag->my_preferred_parent != NULL) { if (my_dodag->my_preferred_parent != NULL) {
if(my_dodag->my_preferred_parent->lifetime <= 1) { if (my_dodag->my_preferred_parent->lifetime <= 1) {
puts("parent lifetime timeout"); puts("parent lifetime timeout");
rpl_parent_update(NULL); rpl_parent_update(NULL);
} }

View File

@ -31,11 +31,11 @@ int sem_wait(sem_t *sem)
{ {
int res; int res;
if(--(sem->value) <= 0 && !sem->locked) { if (--(sem->value) <= 0 && !sem->locked) {
sem->locked = !(sem->locked); sem->locked = !(sem->locked);
res = mutex_lock(&(sem->mutex)); res = mutex_lock(&(sem->mutex));
if(res < 0) { if (res < 0) {
return res; return res;
} }
} }
@ -45,7 +45,7 @@ int sem_wait(sem_t *sem)
int sem_signal(sem_t *sem) int sem_signal(sem_t *sem)
{ {
if(++(sem->value) > 0 && sem->locked) { if (++(sem->value) > 0 && sem->locked) {
sem->locked = !(sem->locked); sem->locked = !(sem->locked);
mutex_unlock(&(sem->mutex), 0); mutex_unlock(&(sem->mutex), 0);
} }

View File

@ -21,7 +21,7 @@
int serial_add8(uint8_t s, uint8_t n) int serial_add8(uint8_t s, uint8_t n)
{ {
if(n > 127) { if (n > 127) {
return -1; return -1;
} }
@ -31,7 +31,7 @@ int serial_add8(uint8_t s, uint8_t n)
int serial_add16(uint16_t s, uint16_t n) int serial_add16(uint16_t s, uint16_t n)
{ {
if(n > 32767) { if (n > 32767) {
return -1; return -1;
} }
@ -41,7 +41,7 @@ int serial_add16(uint16_t s, uint16_t n)
int serial_add32(uint32_t s, uint32_t n) int serial_add32(uint32_t s, uint32_t n)
{ {
if(n > 2147483647) { if (n > 2147483647) {
return -1; return -1;
} }
@ -51,15 +51,15 @@ int serial_add32(uint32_t s, uint32_t n)
serial_comp_res_t serial_comp8(uint8_t s1, uint8_t s2) serial_comp_res_t serial_comp8(uint8_t s1, uint8_t s2)
{ {
if(s1 == s2) { if (s1 == s2) {
return EQUAL; return EQUAL;
} }
if((s1 < s2 && s1 - s2 < 128) || (s1 > s2 && s1 - s2 > 128)) { if ((s1 < s2 && s1 - s2 < 128) || (s1 > s2 && s1 - s2 > 128)) {
return LESS; return LESS;
} }
if((s1 < s2 && s1 - s2 > 128) || (s1 > s2 && s1 - s2 < 128)) { if ((s1 < s2 && s1 - s2 > 128) || (s1 > s2 && s1 - s2 < 128)) {
return GREATER; return GREATER;
} }
@ -68,15 +68,15 @@ serial_comp_res_t serial_comp8(uint8_t s1, uint8_t s2)
serial_comp_res_t serial_comp16(uint16_t s1, uint16_t s2) serial_comp_res_t serial_comp16(uint16_t s1, uint16_t s2)
{ {
if(s1 == s2) { if (s1 == s2) {
return EQUAL; return EQUAL;
} }
if((s1 < s2 && s1 - s2 < 32768) || (s1 > s2 && s1 - s2 > 32768)) { if ((s1 < s2 && s1 - s2 < 32768) || (s1 > s2 && s1 - s2 > 32768)) {
return LESS; return LESS;
} }
if((s1 < s2 && s1 - s2 > 32768) || (s1 > s2 && s1 - s2 < 32768)) { if ((s1 < s2 && s1 - s2 > 32768) || (s1 > s2 && s1 - s2 < 32768)) {
return GREATER; return GREATER;
} }
@ -85,15 +85,15 @@ serial_comp_res_t serial_comp16(uint16_t s1, uint16_t s2)
serial_comp_res_t serial_comp32(uint32_t s1, uint32_t s2) serial_comp_res_t serial_comp32(uint32_t s1, uint32_t s2)
{ {
if(s1 == s2) { if (s1 == s2) {
return EQUAL; return EQUAL;
} }
if((s1 < s2 && s1 - s2 < 2147483648) || (s1 > s2 && s1 - s2 > 2147483648)) { if ((s1 < s2 && s1 - s2 < 2147483648) || (s1 > s2 && s1 - s2 > 2147483648)) {
return LESS; return LESS;
} }
if((s1 < s2 && s1 - s2 > 2147483648) || (s1 > s2 && s1 - s2 < 2147483648)) { if ((s1 < s2 && s1 - s2 > 2147483648) || (s1 > s2 && s1 - s2 < 2147483648)) {
return GREATER; return GREATER;
} }

View File

@ -48,7 +48,7 @@ uint8_t serial_in_buf[BORDER_BUFFER_SIZE];
uint8_t *get_serial_out_buffer(int offset) uint8_t *get_serial_out_buffer(int offset)
{ {
if(offset > BUFFER_SIZE) { if (offset > BUFFER_SIZE) {
return NULL; return NULL;
} }
@ -57,7 +57,7 @@ uint8_t *get_serial_out_buffer(int offset)
uint8_t *get_serial_in_buffer(int offset) uint8_t *get_serial_in_buffer(int offset)
{ {
if(offset > BUFFER_SIZE) { if (offset > BUFFER_SIZE) {
return NULL; return NULL;
} }
@ -81,13 +81,13 @@ void serial_reader_f(void)
msg_receive(&m); msg_receive(&m);
main_pid = m.sender_pid; main_pid = m.sender_pid;
while(1) { while (1) {
posix_open(uart0_handler_pid, 0); posix_open(uart0_handler_pid, 0);
bytes = readpacket(get_serial_in_buffer(0), BORDER_BUFFER_SIZE); bytes = readpacket(get_serial_in_buffer(0), BORDER_BUFFER_SIZE);
if(bytes < 0) { if (bytes < 0) {
switch(bytes) { switch(bytes) {
case(-SIXLOWERROR_ARRAYFULL): { case (-SIXLOWERROR_ARRAYFULL): {
printf("ERROR: Array was full\n"); printf("ERROR: Array was full\n");
break; break;
} }
@ -103,11 +103,11 @@ void serial_reader_f(void)
uart_buf = (border_packet_t *)get_serial_in_buffer(0); uart_buf = (border_packet_t *)get_serial_in_buffer(0);
if(uart_buf->empty == 0) { if (uart_buf->empty == 0) {
if(uart_buf->type == BORDER_PACKET_CONF_TYPE) { if (uart_buf->type == BORDER_PACKET_CONF_TYPE) {
border_conf_header_t *conf_packet = (border_conf_header_t *)uart_buf; border_conf_header_t *conf_packet = (border_conf_header_t *)uart_buf;
if(conf_packet->conftype == BORDER_CONF_SYN) { if (conf_packet->conftype == BORDER_CONF_SYN) {
m.content.ptr = (char *)conf_packet; m.content.ptr = (char *)conf_packet;
msg_send(&m, main_pid, 1); msg_send(&m, main_pid, 1);
continue; continue;
@ -128,7 +128,7 @@ uint8_t border_initialize(transceiver_type_t trans, ipv6_addr_t *border_router_a
PRIORITY_MAIN - 1, CREATE_STACKTEST, PRIORITY_MAIN - 1, CREATE_STACKTEST,
serial_reader_f, "serial_reader"); serial_reader_f, "serial_reader");
if(border_router_addr == NULL) { if (border_router_addr == NULL) {
border_router_addr = &addr; border_router_addr = &addr;
addr = flowcontrol_init(); addr = flowcontrol_init();
@ -138,7 +138,7 @@ uint8_t border_initialize(transceiver_type_t trans, ipv6_addr_t *border_router_a
* RFC 4944 (Section 6) & RFC 2464 (Section 4) from short address * RFC 4944 (Section 6) & RFC 2464 (Section 4) from short address
* -- for now * -- for now
*/ */
if(border_router_addr->uint16[4] != HTONS(IEEE_802154_PAN_ID ^ 0x0200) || if (border_router_addr->uint16[4] != HTONS(IEEE_802154_PAN_ID ^ 0x0200) ||
border_router_addr->uint16[5] != HTONS(0x00FF) || border_router_addr->uint16[5] != HTONS(0x00FF) ||
border_router_addr->uint16[6] != HTONS(0xFE00) border_router_addr->uint16[6] != HTONS(0xFE00)
) { ) {
@ -146,7 +146,7 @@ uint8_t border_initialize(transceiver_type_t trans, ipv6_addr_t *border_router_a
} }
/* radio-address is 8-bit so this must be tested extra */ /* radio-address is 8-bit so this must be tested extra */
if(border_router_addr->uint8[14] != 0) { if (border_router_addr->uint8[14] != 0) {
return SIXLOWERROR_ADDRESS; return SIXLOWERROR_ADDRESS;
} }
@ -177,18 +177,18 @@ void border_process_lowpan(void)
msg_t m; msg_t m;
ipv6_hdr_t *ipv6_buf; ipv6_hdr_t *ipv6_buf;
while(1) { while (1) {
msg_receive(&m); msg_receive(&m);
ipv6_buf = (ipv6_hdr_t *)m.content.ptr; ipv6_buf = (ipv6_hdr_t *)m.content.ptr;
if(ipv6_buf->nextheader == PROTO_NUM_ICMPV6) { if (ipv6_buf->nextheader == PROTO_NUM_ICMPV6) {
struct icmpv6_hdr_t *icmp_buf = (struct icmpv6_hdr_t *)(((uint8_t *)ipv6_buf) + IPV6_HDR_LEN); struct icmpv6_hdr_t *icmp_buf = (struct icmpv6_hdr_t *)(((uint8_t *)ipv6_buf) + IPV6_HDR_LEN);
if(icmp_buf->type == ICMP_REDIRECT) { if (icmp_buf->type == ICMP_REDIRECT) {
continue; continue;
} }
if(icmpv6_demultiplex(icmp_buf) == 0) { if (icmpv6_demultiplex(icmp_buf) == 0) {
continue; continue;
} }

View File

@ -82,7 +82,7 @@ void sixlowpan_send(ipv6_addr_t *addr, uint8_t *payload, uint16_t p_len,
{ {
uint8_t *p_ptr; uint8_t *p_ptr;
if(next_header == IPPROTO_TCP) { if (next_header == IPPROTO_TCP) {
p_ptr = get_payload_buf_send(ipv6_ext_hdr_len); p_ptr = get_payload_buf_send(ipv6_ext_hdr_len);
ipv6_buf = get_ipv6_buf_send(); ipv6_buf = get_ipv6_buf_send();
} }
@ -115,7 +115,7 @@ void sixlowpan_send(ipv6_addr_t *addr, uint8_t *payload, uint16_t p_len,
int icmpv6_demultiplex(const struct icmpv6_hdr_t *hdr) int icmpv6_demultiplex(const struct icmpv6_hdr_t *hdr)
{ {
switch(hdr->type) { switch(hdr->type) {
case(ICMP_RTR_SOL): { case (ICMP_RTR_SOL): {
puts("INFO: packet type: icmp router solicitation"); puts("INFO: packet type: icmp router solicitation");
/* processing router solicitation */ /* processing router solicitation */
recv_rtr_sol(); recv_rtr_sol();
@ -123,7 +123,7 @@ int icmpv6_demultiplex(const struct icmpv6_hdr_t *hdr)
break; break;
} }
case(ICMP_RTR_ADV): { case (ICMP_RTR_ADV): {
puts("INFO: packet type: icmp router advertisment"); puts("INFO: packet type: icmp router advertisment");
/* processing router advertisment */ /* processing router advertisment */
recv_rtr_adv(); recv_rtr_adv();
@ -131,22 +131,22 @@ int icmpv6_demultiplex(const struct icmpv6_hdr_t *hdr)
break; break;
} }
case(ICMP_NBR_SOL): { case (ICMP_NBR_SOL): {
puts("INFO: packet type: icmp neighbor solicitation"); puts("INFO: packet type: icmp neighbor solicitation");
recv_nbr_sol(); recv_nbr_sol();
break; break;
} }
case(ICMP_NBR_ADV): { case (ICMP_NBR_ADV): {
puts("INFO: packet type: icmp neighbor advertisment"); puts("INFO: packet type: icmp neighbor advertisment");
recv_nbr_adv(); recv_nbr_adv();
break; break;
} }
case(ICMP_RPL_CONTROL): { case (ICMP_RPL_CONTROL): {
puts("INFO: packet type: RPL message"); puts("INFO: packet type: RPL message");
if(rpl_process_pid != 0) { if (rpl_process_pid != 0) {
msg_t m_send; msg_t m_send;
m_send.content.ptr = (char *) &hdr->code; m_send.content.ptr = (char *) &hdr->code;
msg_send(&m_send, rpl_process_pid, 1); msg_send(&m_send, rpl_process_pid, 1);
@ -173,7 +173,7 @@ void ipv6_process(void)
ipv6_init_address(&myaddr, 0xabcd, 0x0, 0x0, 0x0, 0x3612, 0x00ff, 0xfe00, ipv6_init_address(&myaddr, 0xabcd, 0x0, 0x0, 0x0, 0x3612, 0x00ff, 0xfe00,
get_radio_address()); get_radio_address());
while(1) { while (1) {
msg_receive(&m_recv_lowpan); msg_receive(&m_recv_lowpan);
ipv6_buf = (ipv6_hdr_t *)m_recv_lowpan.content.ptr; ipv6_buf = (ipv6_hdr_t *)m_recv_lowpan.content.ptr;
@ -181,7 +181,7 @@ void ipv6_process(void)
/* identifiy packet */ /* identifiy packet */
nextheader = &ipv6_buf->nextheader; nextheader = &ipv6_buf->nextheader;
if((ipv6_get_addr_match(&myaddr, &ipv6_buf->destaddr) >= 112) && if ((ipv6_get_addr_match(&myaddr, &ipv6_buf->destaddr) >= 112) &&
(ipv6_buf->destaddr.uint8[15] != myaddr.uint8[15])) { (ipv6_buf->destaddr.uint8[15] != myaddr.uint8[15])) {
memcpy(get_ipv6_buf_send(), get_ipv6_buf(), memcpy(get_ipv6_buf_send(), get_ipv6_buf(),
IPV6_HDR_LEN + ipv6_buf->length); IPV6_HDR_LEN + ipv6_buf->length);
@ -190,9 +190,9 @@ void ipv6_process(void)
} }
else { else {
switch(*nextheader) { switch(*nextheader) {
case(PROTO_NUM_ICMPV6): { case (PROTO_NUM_ICMPV6): {
/* checksum test*/ /* checksum test*/
if(icmpv6_csum(PROTO_NUM_ICMPV6) != 0xffff) { if (icmpv6_csum(PROTO_NUM_ICMPV6) != 0xffff) {
printf("ERROR: wrong checksum\n"); printf("ERROR: wrong checksum\n");
} }
@ -201,8 +201,8 @@ void ipv6_process(void)
break; break;
} }
case(IPPROTO_TCP): { case (IPPROTO_TCP): {
if(tcp_packet_handler_pid != 0) { if (tcp_packet_handler_pid != 0) {
m_send.content.ptr = (char *) ipv6_buf; m_send.content.ptr = (char *) ipv6_buf;
msg_send_receive(&m_send, &m_recv, tcp_packet_handler_pid); msg_send_receive(&m_send, &m_recv, tcp_packet_handler_pid);
} }
@ -213,8 +213,8 @@ void ipv6_process(void)
break; break;
} }
case(IPPROTO_UDP): { case (IPPROTO_UDP): {
if(udp_packet_handler_pid != 0) { if (udp_packet_handler_pid != 0) {
m_send.content.ptr = (char *) ipv6_buf; m_send.content.ptr = (char *) ipv6_buf;
msg_send_receive(&m_send, &m_recv, udp_packet_handler_pid); msg_send_receive(&m_send, &m_recv, udp_packet_handler_pid);
} }
@ -225,7 +225,7 @@ void ipv6_process(void)
break; break;
} }
case(PROTO_NUM_NONE): { case (PROTO_NUM_NONE): {
printf("INFO: Packet with no Header following the IPv6 Header received.\n"); printf("INFO: Packet with no Header following the IPv6 Header received.\n");
break; break;
} }
@ -242,16 +242,16 @@ void ipv6_process(void)
void ipv6_iface_add_addr(ipv6_addr_t *addr, uint8_t state, uint32_t val_ltime, void ipv6_iface_add_addr(ipv6_addr_t *addr, uint8_t state, uint32_t val_ltime,
uint32_t pref_ltime, uint8_t type) uint32_t pref_ltime, uint8_t type)
{ {
if(ipv6_addr_unspec_match(addr) == 128) { if (ipv6_addr_unspec_match(addr) == 128) {
printf("ERROR: unspecified address (::) can't be assigned to interface.\n"); printf("ERROR: unspecified address (::) can't be assigned to interface.\n");
return; return;
} }
if(ipv6_iface_addr_match(addr) != 0) { if (ipv6_iface_addr_match(addr) != 0) {
return; return;
} }
if(iface_addr_list_count < IFACE_ADDR_LIST_LEN) { if (iface_addr_list_count < IFACE_ADDR_LIST_LEN) {
memcpy(&(iface.addr_list[iface_addr_list_count].addr.uint8[0]), memcpy(&(iface.addr_list[iface_addr_list_count].addr.uint8[0]),
&(addr->uint8[0]), 16); &(addr->uint8[0]), 16);
iface.addr_list[iface_addr_list_count].state = state; iface.addr_list[iface_addr_list_count].state = state;
@ -265,12 +265,12 @@ void ipv6_iface_add_addr(ipv6_addr_t *addr, uint8_t state, uint32_t val_ltime,
iface_addr_list_count++; iface_addr_list_count++;
/* Register to Solicited-Node multicast address according to RFC 4291 */ /* Register to Solicited-Node multicast address according to RFC 4291 */
if(type == ADDR_TYPE_ANYCAST || type == ADDR_TYPE_LINK_LOCAL || if (type == ADDR_TYPE_ANYCAST || type == ADDR_TYPE_LINK_LOCAL ||
type == ADDR_TYPE_GLOBAL || type == ADDR_TYPE_UNICAST) { type == ADDR_TYPE_GLOBAL || type == ADDR_TYPE_UNICAST) {
ipv6_addr_t sol_node_mcast_addr; ipv6_addr_t sol_node_mcast_addr;
ipv6_set_sol_node_mcast_addr(addr, &sol_node_mcast_addr); ipv6_set_sol_node_mcast_addr(addr, &sol_node_mcast_addr);
if(ipv6_iface_addr_match(&sol_node_mcast_addr) == NULL) { if (ipv6_iface_addr_match(&sol_node_mcast_addr) == NULL) {
ipv6_iface_add_addr(&sol_node_mcast_addr, state, val_ltime, pref_ltime, ADDR_TYPE_SOL_NODE_MCAST); ipv6_iface_add_addr(&sol_node_mcast_addr, state, val_ltime, pref_ltime, ADDR_TYPE_SOL_NODE_MCAST);
} }
} }
@ -281,8 +281,8 @@ addr_list_t *ipv6_iface_addr_match(ipv6_addr_t *addr)
{ {
int i; int i;
for(i = 0; i < iface_addr_list_count; i++) { for (i = 0; i < iface_addr_list_count; i++) {
if(memcmp(&(iface.addr_list[i].addr.uint8[0]), if (memcmp(&(iface.addr_list[i].addr.uint8[0]),
&(addr->uint8[0]), 16) == 0) { &(addr->uint8[0]), 16) == 0) {
return &(iface.addr_list[i]); return &(iface.addr_list[i]);
} }
@ -295,8 +295,8 @@ addr_list_t *ipv6_iface_addr_prefix_eq(ipv6_addr_t *addr)
{ {
int i; int i;
for(i = 0; i < iface_addr_list_count; i++) { for (i = 0; i < iface_addr_list_count; i++) {
if(memcmp(&(iface.addr_list[i].addr.uint8[0]), if (memcmp(&(iface.addr_list[i].addr.uint8[0]),
&(addr->uint8[0]), 8) == 0) { &(addr->uint8[0]), 8) == 0) {
return &(iface.addr_list[i]); return &(iface.addr_list[i]);
} }
@ -307,7 +307,7 @@ addr_list_t *ipv6_iface_addr_prefix_eq(ipv6_addr_t *addr)
void ipv6_iface_print_addrs(void) void ipv6_iface_print_addrs(void)
{ {
for(int i = 0; i < iface_addr_list_count; i++) { for (int i = 0; i < iface_addr_list_count; i++) {
ipv6_print_addr(&(iface.addr_list[i].addr)); ipv6_print_addr(&(iface.addr_list[i].addr));
} }
} }
@ -377,13 +377,13 @@ void ipv6_get_saddr(ipv6_addr_t *src, ipv6_addr_t *dst)
uint8_t tmp = 0; uint8_t tmp = 0;
uint8_t bmatch = 0; uint8_t bmatch = 0;
if(!(ipv6_prefix_ll_match(dst)) && !(ipv6_prefix_mcast_match(dst))) { if (!(ipv6_prefix_ll_match(dst)) && !(ipv6_prefix_mcast_match(dst))) {
for(int i = 0; i < IFACE_ADDR_LIST_LEN; i++) { for (int i = 0; i < IFACE_ADDR_LIST_LEN; i++) {
if(iface.addr_list[i].state == ADDR_STATE_PREFERRED) { if (iface.addr_list[i].state == ADDR_STATE_PREFERRED) {
if(!(ipv6_prefix_ll_match(&(iface.addr_list[i].addr)))) { if (!(ipv6_prefix_ll_match(&(iface.addr_list[i].addr)))) {
tmp = ipv6_get_addr_match(dst, &(iface.addr_list[i].addr)); tmp = ipv6_get_addr_match(dst, &(iface.addr_list[i].addr));
if(tmp >= bmatch) { if (tmp >= bmatch) {
bmatch = tmp; bmatch = tmp;
itmp = i; itmp = i;
} }
@ -392,15 +392,15 @@ void ipv6_get_saddr(ipv6_addr_t *src, ipv6_addr_t *dst)
} }
} }
else { else {
for(int j = 0; j < IFACE_ADDR_LIST_LEN; j++) { for (int j = 0; j < IFACE_ADDR_LIST_LEN; j++) {
if((iface.addr_list[j].state == ADDR_STATE_PREFERRED) && if ((iface.addr_list[j].state == ADDR_STATE_PREFERRED) &&
ipv6_prefix_ll_match(&(iface.addr_list[j].addr))) { ipv6_prefix_ll_match(&(iface.addr_list[j].addr))) {
itmp = j; itmp = j;
} }
} }
} }
if(itmp == -1) { if (itmp == -1) {
memset(src, 0, 16); memset(src, 0, 16);
} }
else { else {
@ -412,17 +412,17 @@ uint8_t ipv6_get_addr_match(ipv6_addr_t *src, ipv6_addr_t *dst)
{ {
uint8_t val = 0, xor; uint8_t val = 0, xor;
for(int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
/* if bytes are equal add 8 */ /* if bytes are equal add 8 */
if(src->uint8[i] == dst->uint8[i]) { if (src->uint8[i] == dst->uint8[i]) {
val += 8; val += 8;
} }
else { else {
xor = src->uint8[i] ^ dst->uint8[i]; xor = src->uint8[i] ^ dst->uint8[i];
/* while bits from byte equal add 1 */ /* while bits from byte equal add 1 */
for(int j = 0; j < 8; j++) { for (int j = 0; j < 8; j++) {
if((xor & 0x80) == 0) { if ((xor & 0x80) == 0) {
val++; val++;
xor = xor << 1; xor = xor << 1;
} }
@ -460,7 +460,7 @@ void ipv6_init_address(ipv6_addr_t *addr, uint16_t addr0, uint16_t addr1,
uint8_t ipv6_prefix_ll_match(ipv6_addr_t *addr) uint8_t ipv6_prefix_ll_match(ipv6_addr_t *addr)
{ {
if(addr->uint8[0] == 0xfe && addr->uint8[1] == 0x80) { if (addr->uint8[0] == 0xfe && addr->uint8[1] == 0x80) {
return 1; return 1;
} }
@ -469,7 +469,7 @@ uint8_t ipv6_prefix_ll_match(ipv6_addr_t *addr)
uint8_t ipv6_prefix_mcast_match(ipv6_addr_t *addr) uint8_t ipv6_prefix_mcast_match(ipv6_addr_t *addr)
{ {
if(addr->uint8[0] == 0xff && addr->uint8[1] == 0x02) { if (addr->uint8[0] == 0xff && addr->uint8[1] == 0x02) {
return 1; return 1;
} }
@ -478,7 +478,7 @@ uint8_t ipv6_prefix_mcast_match(ipv6_addr_t *addr)
uint8_t ipv6_addr_unspec_match(ipv6_addr_t *addr) uint8_t ipv6_addr_unspec_match(ipv6_addr_t *addr)
{ {
if((addr->uint16[0] == 0) && (addr->uint16[1] == 0) && if ((addr->uint16[0] == 0) && (addr->uint16[1] == 0) &&
(addr->uint16[2] == 0) && (addr->uint16[3] == 0) && (addr->uint16[2] == 0) && (addr->uint16[3] == 0) &&
(addr->uint16[4] == 0) && (addr->uint16[5] == 0) && (addr->uint16[4] == 0) && (addr->uint16[5] == 0) &&
(addr->uint16[6] == 0) && (addr->uint16[7] == 0)) { (addr->uint16[6] == 0) && (addr->uint16[7] == 0)) {
@ -491,7 +491,7 @@ uint8_t ipv6_addr_unspec_match(ipv6_addr_t *addr)
uint8_t ipv6_addr_sol_node_mcast_match(ipv6_addr_t *addr) uint8_t ipv6_addr_sol_node_mcast_match(ipv6_addr_t *addr)
{ {
/* note: cool if-condition*/ /* note: cool if-condition*/
if((addr->uint8[0] == 0xFF) && (addr->uint8[1] == 0x02) && if ((addr->uint8[0] == 0xFF) && (addr->uint8[1] == 0x02) &&
(addr->uint16[1] == 0x00) && (addr->uint16[2] == 0x00) && (addr->uint16[1] == 0x00) && (addr->uint16[2] == 0x00) &&
(addr->uint16[3] == 0x00) && (addr->uint16[4] == 0x00) && (addr->uint16[3] == 0x00) && (addr->uint16[4] == 0x00) &&
(addr->uint8[10] == 0x00) && (addr->uint8[11] == 0x01) && (addr->uint8[10] == 0x00) && (addr->uint8[11] == 0x01) &&
@ -566,7 +566,7 @@ uint8_t ipv6_is_router(void)
ipv6_set_all_rtrs_mcast_addr(&addr); ipv6_set_all_rtrs_mcast_addr(&addr);
if(ipv6_iface_addr_match(&addr) != NULL) { if (ipv6_iface_addr_match(&addr) != NULL) {
return 1; return 1;
} }

View File

@ -132,10 +132,10 @@ void recv_ieee802154_frame(void)
msg_init_queue(msg_q, RADIO_RCV_BUF_SIZE); msg_init_queue(msg_q, RADIO_RCV_BUF_SIZE);
while(1) { while (1) {
msg_receive(&m); msg_receive(&m);
if(m.type == PKT_PENDING) { if (m.type == PKT_PENDING) {
p = (radio_packet_t *) m.content.ptr; p = (radio_packet_t *) m.content.ptr;
hdrlen = read_802154_frame(p->data, &frame, p->length); hdrlen = read_802154_frame(p->data, &frame, p->length);
@ -148,7 +148,7 @@ void recv_ieee802154_frame(void)
p->processing--; p->processing--;
} }
else if(m.type == ENOBUFFER) { else if (m.type == ENOBUFFER) {
puts("Transceiver buffer full"); puts("Transceiver buffer full");
} }
else { else {
@ -216,7 +216,7 @@ void send_ieee802154_frame(ieee_802154_long_t *addr, uint8_t *payload,
p.length = hdrlen + frame.payload_len; p.length = hdrlen + frame.payload_len;
if(mcast == 0) { if (mcast == 0) {
p.dst = daddr; p.dst = daddr;
} }
else { else {

View File

@ -88,7 +88,7 @@ static abr_cache_t *abr_get_oldest(void);
int min(int a, int b) int min(int a, int b)
{ {
if(a < b) { if (a < b) {
return a; return a;
} }
else { else {
@ -188,7 +188,7 @@ void init_rtr_sol(uint8_t sllao)
opt_hdr_len = RTR_SOL_LEN; opt_hdr_len = RTR_SOL_LEN;
ipv6_buf->length = ICMPV6_HDR_LEN + RTR_SOL_LEN + OPT_STLLAO_MAX_LEN; ipv6_buf->length = ICMPV6_HDR_LEN + RTR_SOL_LEN + OPT_STLLAO_MAX_LEN;
if(sllao == OPT_SLLAO) { if (sllao == OPT_SLLAO) {
opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, opt_hdr_len); opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, opt_hdr_len);
set_llao(opt_stllao_buf, OPT_SLLAO_TYPE, 2); set_llao(opt_stllao_buf, OPT_SLLAO_TYPE, 2);
packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + ipv6_ext_hdr_len + packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + ipv6_ext_hdr_len +
@ -216,18 +216,18 @@ void recv_rtr_sol(void)
ipv6_buf = get_ipv6_buf(); ipv6_buf = get_ipv6_buf();
/* check if source option is set*/ /* check if source option is set*/
if(opt_stllao_buf->type == OPT_SLLAO_TYPE) { if (opt_stllao_buf->type == OPT_SLLAO_TYPE) {
opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, opt_hdr_len); opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, opt_hdr_len);
llao = (uint8_t *)opt_stllao_buf; llao = (uint8_t *)opt_stllao_buf;
opt_hdr_len += (opt_stllao_buf->length) << 3; opt_hdr_len += (opt_stllao_buf->length) << 3;
} }
if(llao != NULL) { if (llao != NULL) {
nbr_entry = nbr_cache_search(&ipv6_buf->srcaddr); nbr_entry = nbr_cache_search(&ipv6_buf->srcaddr);
if(nbr_entry != NULL) { if (nbr_entry != NULL) {
/* found neighbor in cache, update values and check long addr */ /* found neighbor in cache, update values and check long addr */
if(memcmp(&llao[2], &nbr_entry->laddr, 8) == 0) { if (memcmp(&llao[2], &nbr_entry->laddr, 8) == 0) {
nbr_entry->isrouter = 0; nbr_entry->isrouter = 0;
} }
else { else {
@ -246,7 +246,7 @@ void recv_rtr_sol(void)
} }
/* send solicited router advertisment */ /* send solicited router advertisment */
if(abr_count > 0) { if (abr_count > 0) {
init_rtr_adv(&ipv6_buf->srcaddr, 0, 0, OPT_PI, OPT_6CO, OPT_ABRO); init_rtr_adv(&ipv6_buf->srcaddr, 0, 0, OPT_PI, OPT_6CO, OPT_ABRO);
} }
else { else {
@ -266,7 +266,7 @@ uint8_t set_opt_6co_flags(uint8_t compression_flag, uint8_t cid)
{ {
uint8_t flags; uint8_t flags;
if(compression_flag) { if (compression_flag) {
flags = OPT_6CO_FLAG_C; flags = OPT_6CO_FLAG_C;
} }
else { else {
@ -301,7 +301,7 @@ void init_rtr_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8_t pi,
ipv6_buf->nextheader = PROTO_NUM_ICMPV6; ipv6_buf->nextheader = PROTO_NUM_ICMPV6;
ipv6_buf->hoplimit = ND_HOPLIMIT; ipv6_buf->hoplimit = ND_HOPLIMIT;
if(addr == NULL) { if (addr == NULL) {
/* not solicited */ /* not solicited */
ipv6_set_all_nds_mcast_addr(&ipv6_buf->destaddr); ipv6_set_all_nds_mcast_addr(&ipv6_buf->destaddr);
} }
@ -327,7 +327,7 @@ void init_rtr_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8_t pi,
packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + RTR_ADV_LEN; packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + RTR_ADV_LEN;
if(sllao == OPT_SLLAO) { if (sllao == OPT_SLLAO) {
/* set link layer address option */ /* set link layer address option */
opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, opt_hdr_len); opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, opt_hdr_len);
set_llao(opt_stllao_buf, OPT_SLLAO_TYPE, 2); set_llao(opt_stllao_buf, OPT_SLLAO_TYPE, 2);
@ -335,7 +335,7 @@ void init_rtr_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8_t pi,
packet_length += OPT_STLLAO_MAX_LEN; packet_length += OPT_STLLAO_MAX_LEN;
} }
if(mtu == OPT_MTU) { if (mtu == OPT_MTU) {
/* set MTU options */ /* set MTU options */
opt_mtu_buf = get_opt_mtu_buf(ipv6_ext_hdr_len, opt_hdr_len); opt_mtu_buf = get_opt_mtu_buf(ipv6_ext_hdr_len, opt_hdr_len);
opt_mtu_buf->type = OPT_MTU_TYPE; opt_mtu_buf->type = OPT_MTU_TYPE;
@ -348,9 +348,9 @@ void init_rtr_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8_t pi,
/* set payload length field */ /* set payload length field */
if(abro == OPT_ABRO) { if (abro == OPT_ABRO) {
/* set authoritive border router option */ /* set authoritive border router option */
if(abr_count > 0) { if (abr_count > 0) {
msg_abr = abr_get_most_current(); msg_abr = abr_get_most_current();
opt_abro_buf = get_opt_abro_buf(ipv6_ext_hdr_len, opt_hdr_len); opt_abro_buf = get_opt_abro_buf(ipv6_ext_hdr_len, opt_hdr_len);
opt_abro_buf->type = OPT_ABRO_TYPE; opt_abro_buf->type = OPT_ABRO_TYPE;
@ -361,12 +361,12 @@ void init_rtr_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8_t pi,
} }
} }
if(sixco == OPT_6CO) { if (sixco == OPT_6CO) {
/* set 6lowpan context option */ /* set 6lowpan context option */
int contexts_len = 0; int contexts_len = 0;
mutex_lock(&lowpan_context_mutex); mutex_lock(&lowpan_context_mutex);
if(msg_abr == NULL) { if (msg_abr == NULL) {
contexts = lowpan_context_get(); contexts = lowpan_context_get();
contexts_len = lowpan_context_len(); contexts_len = lowpan_context_len();
} }
@ -375,10 +375,10 @@ void init_rtr_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8_t pi,
contexts_len = 0; contexts_len = 0;
for(int i = 0; i < LOWPAN_CONTEXT_MAX; i++) { for (int i = 0; i < LOWPAN_CONTEXT_MAX; i++) {
lowpan_context_t *ctx = abr_get_context(msg_abr, i); lowpan_context_t *ctx = abr_get_context(msg_abr, i);
if(ctx != NULL) { if (ctx != NULL) {
memcpy(&(c_tmp[contexts_len++]), ctx, sizeof(lowpan_context_t)); memcpy(&(c_tmp[contexts_len++]), ctx, sizeof(lowpan_context_t));
} }
} }
@ -387,11 +387,11 @@ void init_rtr_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8_t pi,
memcpy(contexts, c_tmp, contexts_len); memcpy(contexts, c_tmp, contexts_len);
} }
for(int i = 0; i < contexts_len; i++) { for (int i = 0; i < contexts_len; i++) {
opt_6co_hdr_buf = get_opt_6co_hdr_buf(ipv6_ext_hdr_len, opt_hdr_len); opt_6co_hdr_buf = get_opt_6co_hdr_buf(ipv6_ext_hdr_len, opt_hdr_len);
opt_6co_hdr_buf->type = OPT_6CO_TYPE; opt_6co_hdr_buf->type = OPT_6CO_TYPE;
if(contexts[i].length > 64) { if (contexts[i].length > 64) {
opt_6co_hdr_buf->length = OPT_6CO_MAX_LEN; opt_6co_hdr_buf->length = OPT_6CO_MAX_LEN;
} }
else { else {
@ -408,7 +408,7 @@ void init_rtr_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8_t pi,
/* attach prefixes */ /* attach prefixes */
opt_6co_prefix_buf = get_opt_6co_prefix_buf(ipv6_ext_hdr_len, opt_hdr_len); opt_6co_prefix_buf = get_opt_6co_prefix_buf(ipv6_ext_hdr_len, opt_hdr_len);
if(opt_6co_hdr_buf->c_length > 64) { if (opt_6co_hdr_buf->c_length > 64) {
memset((void *)opt_6co_prefix_buf, 0, 16); memset((void *)opt_6co_prefix_buf, 0, 16);
memcpy((void *)opt_6co_prefix_buf, (void *) & (contexts[i].prefix.uint8[0]), opt_6co_hdr_buf->c_length / 8); memcpy((void *)opt_6co_prefix_buf, (void *) & (contexts[i].prefix.uint8[0]), opt_6co_hdr_buf->c_length / 8);
opt_hdr_len += 16; opt_hdr_len += 16;
@ -423,17 +423,17 @@ void init_rtr_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8_t pi,
} }
if(msg_abr != NULL && contexts != NULL) { if (msg_abr != NULL && contexts != NULL) {
free(contexts); free(contexts);
} }
mutex_unlock(&lowpan_context_mutex, 0); mutex_unlock(&lowpan_context_mutex, 0);
} }
if(pi == OPT_PI) { if (pi == OPT_PI) {
/* set prefix option */ /* set prefix option */
for(int i = 0; i < OPT_PI_LIST_LEN; i++) { for (int i = 0; i < OPT_PI_LIST_LEN; i++) {
if(plist[i].inuse && plist[i].adv) { if (plist[i].inuse && plist[i].adv) {
opt_pi_buf = get_opt_pi_buf(ipv6_ext_hdr_len, opt_hdr_len); opt_pi_buf = get_opt_pi_buf(ipv6_ext_hdr_len, opt_hdr_len);
memcpy(&(opt_pi_buf->addr.uint8[0]), &(plist[i].addr.uint8[0]), 16); memcpy(&(opt_pi_buf->addr.uint8[0]), &(plist[i].addr.uint8[0]), 16);
opt_pi_buf->type = OPT_PI_TYPE; opt_pi_buf->type = OPT_PI_TYPE;
@ -470,18 +470,18 @@ void recv_rtr_adv(void)
recvd_cids_len = 0; recvd_cids_len = 0;
/* update interface reachable time and retrans timer */ /* update interface reachable time and retrans timer */
if(rtr_adv_buf->reachable_time != 0) { if (rtr_adv_buf->reachable_time != 0) {
iface.adv_reachable_time = HTONL(rtr_adv_buf->reachable_time); iface.adv_reachable_time = HTONL(rtr_adv_buf->reachable_time);
} }
if(rtr_adv_buf->retrans_timer != 0) { if (rtr_adv_buf->retrans_timer != 0) {
iface.adv_retrans_timer = HTONL(rtr_adv_buf->retrans_timer); iface.adv_retrans_timer = HTONL(rtr_adv_buf->retrans_timer);
} }
def_rtr_entry = def_rtr_lst_search(&ipv6_buf->srcaddr); def_rtr_entry = def_rtr_lst_search(&ipv6_buf->srcaddr);
if(rtr_adv_buf->router_lifetime != 0) { if (rtr_adv_buf->router_lifetime != 0) {
if(def_rtr_entry != NULL) { if (def_rtr_entry != NULL) {
set_remaining_time(&(def_rtr_entry->inval_time), HTONL(rtr_adv_buf->router_lifetime)); set_remaining_time(&(def_rtr_entry->inval_time), HTONL(rtr_adv_buf->router_lifetime));
} }
else { else {
@ -491,7 +491,7 @@ void recv_rtr_adv(void)
} }
else { else {
/* remove router from default router list */ /* remove router from default router list */
if(def_rtr_entry != NULL) { if (def_rtr_entry != NULL) {
def_rtr_lst_rem(def_rtr_entry); def_rtr_lst_rem(def_rtr_entry);
} }
} }
@ -499,40 +499,40 @@ void recv_rtr_adv(void)
mutex_lock(&lowpan_context_mutex); mutex_lock(&lowpan_context_mutex);
/* read options */ /* read options */
while(packet_length > IPV6HDR_ICMPV6HDR_LEN + opt_hdr_len) { while (packet_length > IPV6HDR_ICMPV6HDR_LEN + opt_hdr_len) {
opt_buf = get_opt_buf(ipv6_ext_hdr_len, opt_hdr_len); opt_buf = get_opt_buf(ipv6_ext_hdr_len, opt_hdr_len);
switch(opt_buf->type) { switch(opt_buf->type) {
case(OPT_SLLAO_TYPE): { case (OPT_SLLAO_TYPE): {
break; break;
} }
case(OPT_MTU_TYPE): { case (OPT_MTU_TYPE): {
break; break;
} }
/* rfc 4862 section 5.5.3 */ /* rfc 4862 section 5.5.3 */
case(OPT_PI_TYPE): { case (OPT_PI_TYPE): {
opt_pi_buf = get_opt_pi_buf(ipv6_ext_hdr_len, opt_hdr_len); opt_pi_buf = get_opt_pi_buf(ipv6_ext_hdr_len, opt_hdr_len);
/* crazy condition, read 5.5.3a-b-c for further information */ /* crazy condition, read 5.5.3a-b-c for further information */
if(ipv6_prefix_ll_match(&opt_pi_buf->addr) || if (ipv6_prefix_ll_match(&opt_pi_buf->addr) ||
(HTONL(opt_pi_buf->pref_ltime) > (HTONL(opt_pi_buf->pref_ltime) >
HTONL(opt_pi_buf->val_ltime))) { HTONL(opt_pi_buf->val_ltime))) {
break; break;
} }
else { else {
/* check if on-link flag is set */ /* check if on-link flag is set */
if(opt_pi_buf->l_a_reserved1 & OPT_PI_FLAG_L) { if (opt_pi_buf->l_a_reserved1 & OPT_PI_FLAG_L) {
/* TODO: do on-link pi handling */ /* TODO: do on-link pi handling */
} }
if(opt_pi_buf->l_a_reserved1 & OPT_PI_FLAG_A) { if (opt_pi_buf->l_a_reserved1 & OPT_PI_FLAG_A) {
addr_list_ptr = ipv6_iface_addr_prefix_eq(&opt_pi_buf->addr); addr_list_ptr = ipv6_iface_addr_prefix_eq(&opt_pi_buf->addr);
if(addr_list_ptr == NULL) { if (addr_list_ptr == NULL) {
/* 5.5.3d */ /* 5.5.3d */
if(opt_pi_buf->val_ltime != 0) { if (opt_pi_buf->val_ltime != 0) {
/* iid will also be added here */ /* iid will also be added here */
ipv6_init_addr_prefix(&newaddr, &opt_pi_buf->addr); ipv6_init_addr_prefix(&newaddr, &opt_pi_buf->addr);
/* add into address list /* add into address list
@ -553,7 +553,7 @@ void recv_rtr_adv(void)
set_remaining_time(&(addr_list_ptr->pref_ltime), opt_pi_buf->pref_ltime); set_remaining_time(&(addr_list_ptr->pref_ltime), opt_pi_buf->pref_ltime);
/* 7200 = 2hours in seconds */ /* 7200 = 2hours in seconds */
if(HTONL(opt_pi_buf->val_ltime) > 7200 || if (HTONL(opt_pi_buf->val_ltime) > 7200 ||
HTONL(opt_pi_buf->val_ltime) > HTONL(opt_pi_buf->val_ltime) >
get_remaining_time(&(addr_list_ptr->val_ltime))) { get_remaining_time(&(addr_list_ptr->val_ltime))) {
set_remaining_time(&(addr_list_ptr->val_ltime), HTONL(opt_pi_buf->val_ltime)); set_remaining_time(&(addr_list_ptr->val_ltime), HTONL(opt_pi_buf->val_ltime));
@ -570,7 +570,7 @@ void recv_rtr_adv(void)
break; break;
} }
case(OPT_6CO_TYPE): { case (OPT_6CO_TYPE): {
uint8_t comp; uint8_t comp;
uint8_t num; uint8_t num;
@ -597,7 +597,7 @@ void recv_rtr_adv(void)
break; break;
} }
case(OPT_ABRO_TYPE): { case (OPT_ABRO_TYPE): {
opt_abro_buf = get_opt_abro_buf(ipv6_ext_hdr_len, opt_hdr_len); opt_abro_buf = get_opt_abro_buf(ipv6_ext_hdr_len, opt_hdr_len);
abro_found = 1; abro_found = 1;
abro_version = HTONS(opt_abro_buf->version); abro_version = HTONS(opt_abro_buf->version);
@ -613,17 +613,17 @@ void recv_rtr_adv(void)
opt_hdr_len += (opt_buf->length * 8); opt_hdr_len += (opt_buf->length * 8);
} }
if(abro_found) { if (abro_found) {
int i; int i;
for(i = 0; i < recvd_cids_len; i++) { for (i = 0; i < recvd_cids_len; i++) {
abr_add_context(abro_version, &abro_addr, recvd_cids[i]); abr_add_context(abro_version, &abro_addr, recvd_cids[i]);
} }
} }
mutex_unlock(&lowpan_context_mutex, 0); mutex_unlock(&lowpan_context_mutex, 0);
if(trigger_ns >= 0) { if (trigger_ns >= 0) {
/* send ns - draft-ietf-6lowpan-nd-15#section-5.5.1 /* send ns - draft-ietf-6lowpan-nd-15#section-5.5.1
* *
* section-10.2.4 * section-10.2.4
@ -651,7 +651,7 @@ void init_nbr_sol(ipv6_addr_t *src, ipv6_addr_t *dest, ipv6_addr_t *targ,
ipv6_buf->nextheader = PROTO_NUM_ICMPV6; ipv6_buf->nextheader = PROTO_NUM_ICMPV6;
ipv6_buf->hoplimit = ND_HOPLIMIT; ipv6_buf->hoplimit = ND_HOPLIMIT;
if(dest == NULL) { if (dest == NULL) {
ipv6_set_sol_node_mcast_addr(targ, &(ipv6_buf->destaddr)); ipv6_set_sol_node_mcast_addr(targ, &(ipv6_buf->destaddr));
} }
else { else {
@ -670,15 +670,15 @@ void init_nbr_sol(ipv6_addr_t *src, ipv6_addr_t *dest, ipv6_addr_t *targ,
packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + NBR_SOL_LEN; packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + NBR_SOL_LEN;
if(ipv6_iface_addr_match(targ) == NULL) { if (ipv6_iface_addr_match(targ) == NULL) {
if(src == NULL) { if (src == NULL) {
ipv6_get_saddr(&(ipv6_buf->srcaddr), &(ipv6_buf->destaddr)); ipv6_get_saddr(&(ipv6_buf->srcaddr), &(ipv6_buf->destaddr));
} }
else { else {
memcpy(&(ipv6_buf->srcaddr), src, 16); memcpy(&(ipv6_buf->srcaddr), src, 16);
} }
if(sllao == OPT_SLLAO) { if (sllao == OPT_SLLAO) {
/* set sllao option */ /* set sllao option */
opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, opt_hdr_len); opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, opt_hdr_len);
set_llao(opt_stllao_buf, OPT_SLLAO_TYPE, 1); set_llao(opt_stllao_buf, OPT_SLLAO_TYPE, 1);
@ -688,7 +688,7 @@ void init_nbr_sol(ipv6_addr_t *src, ipv6_addr_t *dest, ipv6_addr_t *targ,
} }
} }
if(aro == OPT_ARO) { if (aro == OPT_ARO) {
/* set aro option */ /* set aro option */
opt_aro_buf = get_opt_aro_buf(ipv6_ext_hdr_len, opt_hdr_len); opt_aro_buf = get_opt_aro_buf(ipv6_ext_hdr_len, opt_hdr_len);
opt_aro_buf->type = OPT_ARO_TYPE; opt_aro_buf->type = OPT_ARO_TYPE;
@ -722,10 +722,10 @@ void recv_nbr_sol(void)
* option condition is that a sllao option is set. thus that we don't * option condition is that a sllao option is set. thus that we don't
* know which option comes first we need to this here */ * know which option comes first we need to this here */
while(packet_length > IPV6HDR_ICMPV6HDR_LEN + opt_hdr_len) { while (packet_length > IPV6HDR_ICMPV6HDR_LEN + opt_hdr_len) {
opt_buf = get_opt_buf(ipv6_ext_hdr_len, opt_hdr_len); opt_buf = get_opt_buf(ipv6_ext_hdr_len, opt_hdr_len);
if(opt_buf->type == OPT_SLLAO_TYPE) { if (opt_buf->type == OPT_SLLAO_TYPE) {
sllao_set = 1; sllao_set = 1;
} }
@ -734,23 +734,23 @@ void recv_nbr_sol(void)
opt_hdr_len = NBR_SOL_LEN; opt_hdr_len = NBR_SOL_LEN;
while(packet_length > IPV6HDR_ICMPV6HDR_LEN + opt_hdr_len) { while (packet_length > IPV6HDR_ICMPV6HDR_LEN + opt_hdr_len) {
opt_buf = get_opt_buf(ipv6_ext_hdr_len, opt_hdr_len); opt_buf = get_opt_buf(ipv6_ext_hdr_len, opt_hdr_len);
switch(opt_buf->type) { switch(opt_buf->type) {
case(OPT_SLLAO_TYPE): { case (OPT_SLLAO_TYPE): {
opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len,
opt_hdr_len); opt_hdr_len);
llao = (uint8_t *)opt_stllao_buf; llao = (uint8_t *)opt_stllao_buf;
if(llao != NULL && if (llao != NULL &&
!(ipv6_addr_unspec_match(&ipv6_buf->srcaddr))) { !(ipv6_addr_unspec_match(&ipv6_buf->srcaddr))) {
nbr_entry = nbr_cache_search(&(ipv6_buf->srcaddr)); nbr_entry = nbr_cache_search(&(ipv6_buf->srcaddr));
if(nbr_entry != NULL) { if (nbr_entry != NULL) {
switch(opt_stllao_buf->length) { switch(opt_stllao_buf->length) {
case(1): { case (1): {
if(memcmp(&llao[2], &(nbr_entry->saddr), 2) == 0) { if (memcmp(&llao[2], &(nbr_entry->saddr), 2) == 0) {
nbr_entry->isrouter = 0; nbr_entry->isrouter = 0;
} }
else { else {
@ -762,8 +762,8 @@ void recv_nbr_sol(void)
break; break;
} }
case(2): { case (2): {
if(memcmp(&llao[2], &(nbr_entry->laddr), 8) == 0) { if (memcmp(&llao[2], &(nbr_entry->laddr), 8) == 0) {
nbr_entry->isrouter = 0; nbr_entry->isrouter = 0;
} }
else { else {
@ -781,7 +781,7 @@ void recv_nbr_sol(void)
} }
else { else {
switch(opt_stllao_buf->length) { switch(opt_stllao_buf->length) {
case(1): { case (1): {
nbr_cache_add(&ipv6_buf->srcaddr, nbr_cache_add(&ipv6_buf->srcaddr,
NULL , 0, NBR_STATUS_STALE, NULL , 0, NBR_STATUS_STALE,
NBR_CACHE_TYPE_TEN, NBR_CACHE_TYPE_TEN,
@ -791,7 +791,7 @@ void recv_nbr_sol(void)
break; break;
} }
case(2): { case (2): {
nbr_cache_add(&ipv6_buf->srcaddr, nbr_cache_add(&ipv6_buf->srcaddr,
(ieee_802154_long_t *)&llao[2], 0, (ieee_802154_long_t *)&llao[2], 0,
NBR_STATUS_STALE, NBR_STATUS_STALE,
@ -809,20 +809,20 @@ void recv_nbr_sol(void)
break; break;
} }
case(OPT_ARO_TYPE): { case (OPT_ARO_TYPE): {
/* check if sllao option is set, and if address src address /* check if sllao option is set, and if address src address
* isn't unspecified - draft-ietf-6lowpan-nd-15#section-6.5 */ * isn't unspecified - draft-ietf-6lowpan-nd-15#section-6.5 */
if(!(ipv6_addr_unspec_match(&ipv6_buf->srcaddr)) && if (!(ipv6_addr_unspec_match(&ipv6_buf->srcaddr)) &&
sllao_set == 1) { sllao_set == 1) {
opt_aro_buf = get_opt_aro_buf(ipv6_ext_hdr_len, opt_aro_buf = get_opt_aro_buf(ipv6_ext_hdr_len,
opt_hdr_len); opt_hdr_len);
if((opt_aro_buf->length == 2) && if ((opt_aro_buf->length == 2) &&
(opt_aro_buf->status == 0)) { (opt_aro_buf->status == 0)) {
/* check neighbor cache for duplicates */ /* check neighbor cache for duplicates */
nbr_entry = nbr_cache_search(&(ipv6_buf->srcaddr)); nbr_entry = nbr_cache_search(&(ipv6_buf->srcaddr));
if(nbr_entry == NULL) { if (nbr_entry == NULL) {
/* create neighbor cache */ /* create neighbor cache */
aro_state = nbr_cache_add(&ipv6_buf->srcaddr, aro_state = nbr_cache_add(&ipv6_buf->srcaddr,
&(opt_aro_buf->eui64), 0, &(opt_aro_buf->eui64), 0,
@ -830,10 +830,10 @@ void recv_nbr_sol(void)
opt_aro_buf->reg_ltime, NULL); opt_aro_buf->reg_ltime, NULL);
} }
else { else {
if(memcmp(&(nbr_entry->addr.uint16[4]), if (memcmp(&(nbr_entry->addr.uint16[4]),
&(opt_aro_buf->eui64.uint16[0]), 8) == 0) { &(opt_aro_buf->eui64.uint16[0]), 8) == 0) {
/* update neighbor cache entry */ /* update neighbor cache entry */
if(opt_aro_buf->reg_ltime == 0) { if (opt_aro_buf->reg_ltime == 0) {
/* delete neighbor cache entry */ /* delete neighbor cache entry */
nbr_cache_rem(&nbr_entry->addr); nbr_cache_rem(&nbr_entry->addr);
} }
@ -870,10 +870,10 @@ void recv_nbr_sol(void)
nbr_sol_buf = get_nbr_sol_buf(ipv6_ext_hdr_len); nbr_sol_buf = get_nbr_sol_buf(ipv6_ext_hdr_len);
alist_targ = ipv6_iface_addr_match(&(nbr_sol_buf->tgtaddr)); alist_targ = ipv6_iface_addr_match(&(nbr_sol_buf->tgtaddr));
if(alist_targ != NULL) { if (alist_targ != NULL) {
alist_dest = ipv6_iface_addr_match(&(ipv6_buf->destaddr)); alist_dest = ipv6_iface_addr_match(&(ipv6_buf->destaddr));
if((memcmp(&(alist_targ->addr), &(alist_dest->addr), 16) == 0) || if ((memcmp(&(alist_targ->addr), &(alist_dest->addr), 16) == 0) ||
ipv6_addr_sol_node_mcast_match(&ipv6_buf->destaddr)) { ipv6_addr_sol_node_mcast_match(&ipv6_buf->destaddr)) {
memcpy(&(ipv6_buf->destaddr.uint8[0]), memcpy(&(ipv6_buf->destaddr.uint8[0]),
&(ipv6_buf->srcaddr.uint8[0]), 16); &(ipv6_buf->srcaddr.uint8[0]), 16);
@ -883,7 +883,7 @@ void recv_nbr_sol(void)
} }
} }
if(send_na) { if (send_na) {
/* solicited na */ /* solicited na */
uint8_t flags = (NBR_ADV_FLAG_O | NBR_ADV_FLAG_S); uint8_t flags = (NBR_ADV_FLAG_O | NBR_ADV_FLAG_S);
init_nbr_adv(&(ipv6_buf->srcaddr), &(ipv6_buf->destaddr), init_nbr_adv(&(ipv6_buf->srcaddr), &(ipv6_buf->destaddr),
@ -922,7 +922,7 @@ void init_nbr_adv(ipv6_addr_t *src, ipv6_addr_t *dst, ipv6_addr_t *tgt,
packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + NBR_ADV_LEN; packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + NBR_ADV_LEN;
if(sllao == OPT_SLLAO) { if (sllao == OPT_SLLAO) {
/* set sllao option */ /* set sllao option */
opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, opt_hdr_len); opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, opt_hdr_len);
set_llao(opt_stllao_buf, OPT_SLLAO_TYPE, 1); set_llao(opt_stllao_buf, OPT_SLLAO_TYPE, 1);
@ -931,7 +931,7 @@ void init_nbr_adv(ipv6_addr_t *src, ipv6_addr_t *dst, ipv6_addr_t *tgt,
packet_length += OPT_STLLAO_MIN_LEN; packet_length += OPT_STLLAO_MIN_LEN;
} }
if(aro == OPT_ARO) { if (aro == OPT_ARO) {
/* set aro option */ /* set aro option */
opt_aro_buf = get_opt_aro_buf(ipv6_ext_hdr_len, opt_hdr_len); opt_aro_buf = get_opt_aro_buf(ipv6_ext_hdr_len, opt_hdr_len);
opt_aro_buf->type = OPT_ARO_TYPE; opt_aro_buf->type = OPT_ARO_TYPE;
@ -960,17 +960,17 @@ void recv_nbr_adv(void)
nbr_adv_buf = get_nbr_adv_buf(ipv6_ext_hdr_len); nbr_adv_buf = get_nbr_adv_buf(ipv6_ext_hdr_len);
/* check if options are present */ /* check if options are present */
while(packet_length > IPV6HDR_ICMPV6HDR_LEN + opt_hdr_len) { while (packet_length > IPV6HDR_ICMPV6HDR_LEN + opt_hdr_len) {
opt_buf = get_opt_buf(ipv6_ext_hdr_len, opt_hdr_len); opt_buf = get_opt_buf(ipv6_ext_hdr_len, opt_hdr_len);
switch(opt_buf->type) { switch(opt_buf->type) {
case(OPT_TLLAO_TYPE): { case (OPT_TLLAO_TYPE): {
llao = (uint8_t *)get_opt_stllao_buf(ipv6_ext_hdr_len, llao = (uint8_t *)get_opt_stllao_buf(ipv6_ext_hdr_len,
opt_hdr_len); opt_hdr_len);
break; break;
} }
case(OPT_ARO_TYPE): { case (OPT_ARO_TYPE): {
break; break;
} }
} }
@ -981,24 +981,24 @@ void recv_nbr_adv(void)
addr_list_t *addr; addr_list_t *addr;
addr = ipv6_iface_addr_match(&nbr_adv_buf->tgtaddr); addr = ipv6_iface_addr_match(&nbr_adv_buf->tgtaddr);
if(addr == NULL) { if (addr == NULL) {
nbr_entry = nbr_cache_search(&nbr_adv_buf->tgtaddr); nbr_entry = nbr_cache_search(&nbr_adv_buf->tgtaddr);
if(nbr_entry != NULL) { if (nbr_entry != NULL) {
if(llao != 0) { if (llao != 0) {
/* TODO: untersheiden zwischen short und long stllao option */ /* TODO: untersheiden zwischen short und long stllao option */
new_ll = memcmp(&llao[2], &(nbr_entry->laddr), 8); new_ll = memcmp(&llao[2], &(nbr_entry->laddr), 8);
} }
if(nbr_entry->state == NBR_STATUS_INCOMPLETE) { if (nbr_entry->state == NBR_STATUS_INCOMPLETE) {
if(llao == NULL) { if (llao == NULL) {
return; return;
} }
/* TODO: untersheiden zwischen short und long stllao option */ /* TODO: untersheiden zwischen short und long stllao option */
memcpy(&nbr_entry->laddr, &llao[2], 8); memcpy(&nbr_entry->laddr, &llao[2], 8);
if(nbr_adv_buf->rso & NBR_ADV_FLAG_S) { if (nbr_adv_buf->rso & NBR_ADV_FLAG_S) {
nbr_entry->state = NBR_STATUS_REACHABLE; nbr_entry->state = NBR_STATUS_REACHABLE;
/* TODO: set rechability */ /* TODO: set rechability */
} }
@ -1009,27 +1009,27 @@ void recv_nbr_adv(void)
nbr_entry->isrouter = nbr_adv_buf->rso & NBR_ADV_FLAG_R; nbr_entry->isrouter = nbr_adv_buf->rso & NBR_ADV_FLAG_R;
} }
else { else {
if(new_ll && !(nbr_adv_buf->rso & NBR_ADV_FLAG_O)) { if (new_ll && !(nbr_adv_buf->rso & NBR_ADV_FLAG_O)) {
if(nbr_entry->state == NBR_STATUS_REACHABLE) { if (nbr_entry->state == NBR_STATUS_REACHABLE) {
nbr_entry->state = NBR_STATUS_STALE; nbr_entry->state = NBR_STATUS_STALE;
} }
return; return;
} }
else { else {
if((nbr_adv_buf->rso & NBR_ADV_FLAG_O) || if ((nbr_adv_buf->rso & NBR_ADV_FLAG_O) ||
(!(nbr_adv_buf->rso & NBR_ADV_FLAG_O) && llao != 0 && (!(nbr_adv_buf->rso & NBR_ADV_FLAG_O) && llao != 0 &&
!new_ll)) { !new_ll)) {
if(llao != 0) { if (llao != 0) {
memcpy(&nbr_entry->laddr, &llao[2], 8); memcpy(&nbr_entry->laddr, &llao[2], 8);
} }
if(nbr_adv_buf->rso & NBR_ADV_FLAG_S) { if (nbr_adv_buf->rso & NBR_ADV_FLAG_S) {
nbr_entry->state = NBR_STATUS_REACHABLE; nbr_entry->state = NBR_STATUS_REACHABLE;
/* TODO: set rechablility */ /* TODO: set rechablility */
} }
else { else {
if(llao != 0 && new_ll) { if (llao != 0 && new_ll) {
nbr_entry->state = NBR_STATUS_STALE; nbr_entry->state = NBR_STATUS_STALE;
} }
} }
@ -1050,13 +1050,13 @@ void set_llao(opt_stllao_t *sllao, uint8_t type, uint8_t length)
/* get link layer address */ /* get link layer address */
switch(length) { switch(length) {
case(1): { case (1): {
memcpy(&llao[2], &(iface.saddr), 2); memcpy(&llao[2], &(iface.saddr), 2);
memset(&llao[4], 0, 4); memset(&llao[4], 0, 4);
break; break;
} }
case(2): { case (2): {
memcpy(&llao[2], &(iface.laddr), 8); memcpy(&llao[2], &(iface.laddr), 8);
memset(&llao[10], 0, 6); memset(&llao[10], 0, 6);
break; break;
@ -1126,8 +1126,8 @@ nbr_cache_t *nbr_cache_search(ipv6_addr_t *ipaddr)
{ {
int i; int i;
for(i = 0; i < NBR_CACHE_SIZE; i++) { for (i = 0; i < NBR_CACHE_SIZE; i++) {
if(memcmp(&(nbr_cache[i].addr.uint8[0]), &(ipaddr->uint8[0]), 16) == 0) { if (memcmp(&(nbr_cache[i].addr.uint8[0]), &(ipaddr->uint8[0]), 16) == 0) {
return &nbr_cache[i]; return &nbr_cache[i];
} }
} }
@ -1139,7 +1139,7 @@ uint8_t nbr_cache_add(ipv6_addr_t *ipaddr, ieee_802154_long_t *laddr,
uint8_t isrouter, uint8_t state, uint8_t type, uint8_t isrouter, uint8_t state, uint8_t type,
uint16_t ltime, ieee_802154_short_t *saddr) uint16_t ltime, ieee_802154_short_t *saddr)
{ {
if(nbr_count == NBR_CACHE_SIZE) { if (nbr_count == NBR_CACHE_SIZE) {
printf("ERROR: neighbor cache full\n"); printf("ERROR: neighbor cache full\n");
return OPT_ARO_STATE_NBR_CACHE_FULL; return OPT_ARO_STATE_NBR_CACHE_FULL;
} }
@ -1162,8 +1162,8 @@ void nbr_cache_auto_rem(void)
{ {
int i; int i;
for(i = 0; i < NBR_CACHE_SIZE; i++) { for (i = 0; i < NBR_CACHE_SIZE; i++) {
if(get_remaining_time(&(nbr_cache[i].ltime)) == 0 && if (get_remaining_time(&(nbr_cache[i].ltime)) == 0 &&
nbr_cache[i].type == NBR_CACHE_TYPE_TEN) { nbr_cache[i].type == NBR_CACHE_TYPE_TEN) {
memmove(&(nbr_cache[i]), &(nbr_cache[nbr_count]), memmove(&(nbr_cache[i]), &(nbr_cache[nbr_count]),
sizeof(nbr_cache_t)); sizeof(nbr_cache_t));
@ -1177,8 +1177,8 @@ void nbr_cache_rem(ipv6_addr_t *addr)
{ {
int i; int i;
for(i = 0; i < NBR_CACHE_SIZE; i++) { for (i = 0; i < NBR_CACHE_SIZE; i++) {
if(memcmp(&(nbr_cache[i].addr.uint8[0]), &(addr->uint8[0]), 16) == 0) { if (memcmp(&(nbr_cache[i].addr.uint8[0]), &(addr->uint8[0]), 16) == 0) {
memmove(&(nbr_cache[i]), &(nbr_cache[nbr_count]), memmove(&(nbr_cache[i]), &(nbr_cache[nbr_count]),
sizeof(nbr_cache_t)); sizeof(nbr_cache_t));
memset(&(nbr_cache[nbr_count]), 0, sizeof(nbr_cache_t)); memset(&(nbr_cache[nbr_count]), 0, sizeof(nbr_cache_t));
@ -1202,8 +1202,8 @@ static abr_cache_t *abr_get_most_current(void)
int i; int i;
int version = abr_cache[0].version; int version = abr_cache[0].version;
for(i = 0; i < abr_count; i++) { for (i = 0; i < abr_count; i++) {
if(serial_comp16(version, abr_cache[i].version) == GREATER) { if (serial_comp16(version, abr_cache[i].version) == GREATER) {
abr = &(abr_cache[i]); abr = &(abr_cache[i]);
version = abr_cache[i].version; version = abr_cache[i].version;
} }
@ -1218,8 +1218,8 @@ static abr_cache_t *abr_get_oldest(void)
int i; int i;
int version = abr_cache[0].version; int version = abr_cache[0].version;
for(i = 0; i < abr_count; i++) { for (i = 0; i < abr_count; i++) {
if(serial_comp16(version, abr_cache[i].version) == LESS) { if (serial_comp16(version, abr_cache[i].version) == LESS) {
abr = &(abr_cache[i]); abr = &(abr_cache[i]);
version = abr_cache[i].version; version = abr_cache[i].version;
} }
@ -1232,8 +1232,8 @@ abr_cache_t *abr_get_version(uint16_t version, ipv6_addr_t *abr_addr)
{ {
int i = 0; int i = 0;
for(i = 0; i < ABR_CACHE_SIZE; i++) { for (i = 0; i < ABR_CACHE_SIZE; i++) {
if(abr_cache[i].version == version && if (abr_cache[i].version == version &&
memcmp(&(abr_cache[i].abr_addr.uint8[0]), memcmp(&(abr_cache[i].abr_addr.uint8[0]),
&(abr_addr->uint8[0]), 16 &(abr_addr->uint8[0]), 16
) == 0) { ) == 0) {
@ -1246,7 +1246,7 @@ abr_cache_t *abr_get_version(uint16_t version, ipv6_addr_t *abr_addr)
lowpan_context_t *abr_get_context(abr_cache_t *abr, uint8_t cid) lowpan_context_t *abr_get_context(abr_cache_t *abr, uint8_t cid)
{ {
if(abr->cids[cid] != cid) { if (abr->cids[cid] != cid) {
return NULL; return NULL;
} }
@ -1258,8 +1258,8 @@ abr_cache_t *abr_add_context(uint16_t version, ipv6_addr_t *abr_addr,
{ {
abr_cache_t *abr = abr_get_version(version, abr_addr); abr_cache_t *abr = abr_get_version(version, abr_addr);
if(abr == NULL) { if (abr == NULL) {
if(abr_count == ABR_CACHE_SIZE) { if (abr_count == ABR_CACHE_SIZE) {
abr = abr_get_oldest(); abr = abr_get_oldest();
} }
else { else {
@ -1280,7 +1280,7 @@ void abr_remove_context(uint8_t cid)
{ {
int i; int i;
for(i = 0; i < abr_count; i++) { for (i = 0; i < abr_count; i++) {
abr_cache[i].cids[cid] = 0xFF; abr_cache[i].cids[cid] = 0xFF;
} }
} }
@ -1292,8 +1292,8 @@ def_rtr_lst_t *def_rtr_lst_search(ipv6_addr_t *ipaddr)
{ {
int i; int i;
for(i = 0; i < DEF_RTR_LST_SIZE; i++) { for (i = 0; i < DEF_RTR_LST_SIZE; i++) {
if(memcmp(&def_rtr_lst[i].addr.uint8[0], if (memcmp(&def_rtr_lst[i].addr.uint8[0],
&(ipaddr->uint8[0]), 16) == 0) { &(ipaddr->uint8[0]), 16) == 0) {
return &def_rtr_lst[i]; return &def_rtr_lst[i];
} }
@ -1304,7 +1304,7 @@ def_rtr_lst_t *def_rtr_lst_search(ipv6_addr_t *ipaddr)
void def_rtr_lst_add(ipv6_addr_t *ipaddr, uint32_t rtr_ltime) void def_rtr_lst_add(ipv6_addr_t *ipaddr, uint32_t rtr_ltime)
{ {
if(def_rtr_count == DEF_RTR_LST_SIZE) { if (def_rtr_count == DEF_RTR_LST_SIZE) {
DEBUG("ERROR: default router list full\n"); DEBUG("ERROR: default router list full\n");
} }
else { else {
@ -1323,8 +1323,8 @@ void def_rtr_lst_rem(def_rtr_lst_t *entry)
{ {
int i; int i;
for(i = 0; i < DEF_RTR_LST_SIZE; i++) { for (i = 0; i < DEF_RTR_LST_SIZE; i++) {
if(&def_rtr_lst[i] == entry) { if (&def_rtr_lst[i] == entry) {
/* search the to deleted item, then memmove the last item to its /* search the to deleted item, then memmove the last item to its
* position, and decrement array count */ * position, and decrement array count */
memmove(entry, &def_rtr_lst[def_rtr_count], sizeof(def_rtr_lst_t)); memmove(entry, &def_rtr_lst[def_rtr_count], sizeof(def_rtr_lst_t));
@ -1340,7 +1340,7 @@ void def_rtr_lst_rem(def_rtr_lst_t *entry)
int8_t plist_add(ipv6_addr_t *addr, uint8_t size, uint32_t val_ltime, int8_t plist_add(ipv6_addr_t *addr, uint8_t size, uint32_t val_ltime,
uint32_t pref_ltime, uint8_t adv_opt, uint8_t l_a_reserved1) uint32_t pref_ltime, uint8_t adv_opt, uint8_t l_a_reserved1)
{ {
if(prefix_count == OPT_PI_LIST_LEN) { if (prefix_count == OPT_PI_LIST_LEN) {
return SIXLOWERROR_ARRAYFULL; return SIXLOWERROR_ARRAYFULL;
} }
else { else {

View File

@ -93,7 +93,7 @@ void lowpan_init(ieee_802154_long_t *addr, uint8_t *data)
memcpy(&laddr.uint8[0], &addr->uint8[0], 8); memcpy(&laddr.uint8[0], &addr->uint8[0], 8);
if(ipv6_prefix_mcast_match(&ipv6_buf->destaddr)) { if (ipv6_prefix_mcast_match(&ipv6_buf->destaddr)) {
/* send broadcast */ /* send broadcast */
mcast = 1; mcast = 1;
} }
@ -103,7 +103,7 @@ void lowpan_init(ieee_802154_long_t *addr, uint8_t *data)
packet_length = comp_len; packet_length = comp_len;
/* check if packet needs to be fragmented */ /* check if packet needs to be fragmented */
if(packet_length + header_size > PAYLOAD_SIZE - IEEE_802154_MAX_HDR_LEN) { if (packet_length + header_size > PAYLOAD_SIZE - IEEE_802154_MAX_HDR_LEN) {
uint8_t fragbuf[packet_length + header_size]; uint8_t fragbuf[packet_length + header_size];
uint8_t remaining; uint8_t remaining;
uint8_t i = 2; uint8_t i = 2;
@ -126,7 +126,7 @@ void lowpan_init(ieee_802154_long_t *addr, uint8_t *data)
data += position; data += position;
while(packet_length - position > max_frame - 5) { while (packet_length - position > max_frame - 5) {
memset(&fragbuf, 0, packet_length + header_size); memset(&fragbuf, 0, packet_length + header_size);
memcpy(fragbuf + 5, data, max_frag); memcpy(fragbuf + 5, data, max_frag);
@ -180,14 +180,14 @@ void printReasBuffers(void)
printf("\n\n--- Reassembly Buffers ---\n"); printf("\n\n--- Reassembly Buffers ---\n");
while(temp_buffer != NULL) { while (temp_buffer != NULL) {
printLongLocalAddr(&temp_buffer->s_laddr); printLongLocalAddr(&temp_buffer->s_laddr);
printf("Ident.: %i, Packet Size: %i/%i, Timestamp: %li\n", printf("Ident.: %i, Packet Size: %i/%i, Timestamp: %li\n",
temp_buffer->ident_no, temp_buffer->current_packet_size, temp_buffer->ident_no, temp_buffer->current_packet_size,
temp_buffer->packet_size, temp_buffer->timestamp); temp_buffer->packet_size, temp_buffer->timestamp);
temp_interval = temp_buffer->interval_list_head; temp_interval = temp_buffer->interval_list_head;
while(temp_interval != NULL) { while (temp_interval != NULL) {
printf("\t%i - %i\n", temp_interval->start, temp_interval->end); printf("\t%i - %i\n", temp_interval->start, temp_interval->end);
temp_interval = temp_interval->next; temp_interval = temp_interval->next;
} }
@ -204,14 +204,14 @@ void printFIFOBuffers(void)
printf("\n\n--- Reassembly Buffers ---\n"); printf("\n\n--- Reassembly Buffers ---\n");
while(temp_buffer != NULL) { while (temp_buffer != NULL) {
printLongLocalAddr(&temp_buffer->s_laddr); printLongLocalAddr(&temp_buffer->s_laddr);
printf("Ident.: %i, Packet Size: %i/%i, Timestamp: %li\n", printf("Ident.: %i, Packet Size: %i/%i, Timestamp: %li\n",
temp_buffer->ident_no, temp_buffer->current_packet_size, temp_buffer->ident_no, temp_buffer->current_packet_size,
temp_buffer->packet_size, temp_buffer->timestamp); temp_buffer->packet_size, temp_buffer->timestamp);
temp_interval = temp_buffer->interval_list_head; temp_interval = temp_buffer->interval_list_head;
while(temp_interval != NULL) { while (temp_interval != NULL) {
printf("\t%i - %i\n", temp_interval->start, temp_interval->end); printf("\t%i - %i\n", temp_interval->start, temp_interval->end);
temp_interval = temp_interval->next; temp_interval = temp_interval->next;
} }
@ -227,23 +227,23 @@ void lowpan_transfer(void)
lowpan_reas_buf_t *current_buf; lowpan_reas_buf_t *current_buf;
uint8_t gotosleep; uint8_t gotosleep;
while(1) { while (1) {
gotosleep = 1; gotosleep = 1;
mutex_lock(&fifo_mutex); mutex_lock(&fifo_mutex);
current_buf = packet_fifo; current_buf = packet_fifo;
if(current_buf != NULL) { if (current_buf != NULL) {
mutex_unlock(&fifo_mutex, 0); mutex_unlock(&fifo_mutex, 0);
if((current_buf->packet)[0] == LOWPAN_IPV6_DISPATCH) { if ((current_buf->packet)[0] == LOWPAN_IPV6_DISPATCH) {
ipv6_buf = get_ipv6_buf(); ipv6_buf = get_ipv6_buf();
memcpy(ipv6_buf, (current_buf->packet) + 1, current_buf->packet_size - 1); memcpy(ipv6_buf, (current_buf->packet) + 1, current_buf->packet_size - 1);
m_send.content.ptr = (char *)ipv6_buf; m_send.content.ptr = (char *)ipv6_buf;
packet_length = current_buf->packet_size - 1; packet_length = current_buf->packet_size - 1;
msg_send_receive(&m_send, &m_recv, ip_process_pid); msg_send_receive(&m_send, &m_recv, ip_process_pid);
} }
else if(((current_buf->packet)[0] & 0xe0) == LOWPAN_IPHC_DISPATCH) { else if (((current_buf->packet)[0] & 0xe0) == LOWPAN_IPHC_DISPATCH) {
lowpan_iphc_decoding(current_buf->packet, lowpan_iphc_decoding(current_buf->packet,
current_buf->packet_size, current_buf->packet_size,
&(current_buf->s_laddr), &(current_buf->s_laddr),
@ -262,7 +262,7 @@ void lowpan_transfer(void)
} }
if(gotosleep == 1) { if (gotosleep == 1) {
mutex_unlock(&fifo_mutex, 0); mutex_unlock(&fifo_mutex, 0);
thread_sleep(); thread_sleep();
} }
@ -273,17 +273,17 @@ uint8_t ll_get_addr_match(ieee_802154_long_t *src, ieee_802154_long_t *dst)
{ {
uint8_t val = 0, xor; uint8_t val = 0, xor;
for(int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
/* if bytes are equal add 8 */ /* if bytes are equal add 8 */
if(src->uint8[i] == dst->uint8[i]) { if (src->uint8[i] == dst->uint8[i]) {
val += 8; val += 8;
} }
else { else {
xor = src->uint8[i] ^ dst->uint8[i]; xor = src->uint8[i] ^ dst->uint8[i];
/* while bits from byte equal add 1 */ /* while bits from byte equal add 1 */
for(int j = 0; j < 8; j++) { for (int j = 0; j < 8; j++) {
if((xor & 0x80) == 0) { if ((xor & 0x80) == 0) {
val++; val++;
xor = xor << 1; xor = xor << 1;
} }
@ -309,12 +309,12 @@ lowpan_reas_buf_t *new_packet_buffer(uint16_t datagram_size,
/* Allocate new memory for a new packet to be reassembled */ /* Allocate new memory for a new packet to be reassembled */
new_buf = malloc(sizeof(lowpan_reas_buf_t)); new_buf = malloc(sizeof(lowpan_reas_buf_t));
if(new_buf != NULL) { if (new_buf != NULL) {
init_reas_bufs(new_buf); init_reas_bufs(new_buf);
new_buf->packet = malloc(datagram_size); new_buf->packet = malloc(datagram_size);
if(new_buf->packet != NULL) { if (new_buf->packet != NULL) {
memcpy(&new_buf->s_laddr, s_laddr, SIXLOWPAN_IPV6_LL_ADDR_LEN); memcpy(&new_buf->s_laddr, s_laddr, SIXLOWPAN_IPV6_LL_ADDR_LEN);
memcpy(&new_buf->d_laddr, d_laddr, SIXLOWPAN_IPV6_LL_ADDR_LEN); memcpy(&new_buf->d_laddr, d_laddr, SIXLOWPAN_IPV6_LL_ADDR_LEN);
@ -325,7 +325,7 @@ lowpan_reas_buf_t *new_packet_buffer(uint16_t datagram_size,
vtimer_now(&now); vtimer_now(&now);
new_buf->timestamp = now.microseconds; new_buf->timestamp = now.microseconds;
if((current_buf == NULL) && (temp_buf == NULL)) { if ((current_buf == NULL) && (temp_buf == NULL)) {
head = new_buf; head = new_buf;
} }
else { else {
@ -351,8 +351,8 @@ lowpan_reas_buf_t *get_packet_frag_buf(uint16_t datagram_size,
lowpan_reas_buf_t *current_buf = NULL, *temp_buf = NULL; lowpan_reas_buf_t *current_buf = NULL, *temp_buf = NULL;
current_buf = head; current_buf = head;
while(current_buf != NULL) { while (current_buf != NULL) {
if(((ll_get_addr_match(&current_buf->s_laddr, s_laddr)) == 64) && if (((ll_get_addr_match(&current_buf->s_laddr, s_laddr)) == 64) &&
((ll_get_addr_match(&current_buf->d_laddr, d_laddr)) == 64) && ((ll_get_addr_match(&current_buf->d_laddr, d_laddr)) == 64) &&
(current_buf->packet_size == datagram_size) && (current_buf->packet_size == datagram_size) &&
(current_buf->ident_no == datagram_tag) && (current_buf->ident_no == datagram_tag) &&
@ -377,7 +377,7 @@ uint8_t isInInterval(uint8_t start1, uint8_t end1, uint8_t start2, uint8_t end2)
/* 1: Interval 1 and 2 are the same or overlapping */ /* 1: Interval 1 and 2 are the same or overlapping */
/* 0: Interval 1 and 2 are not overlapping or the same */ /* 0: Interval 1 and 2 are not overlapping or the same */
if(((start1 < start2) && (start2 <= end1)) || if (((start1 < start2) && (start2 <= end1)) ||
((start2 < start1) && (start1 <= end2)) || ((start2 < start1) && (start1 <= end2)) ||
((start1 == start2) && (end1 == end2))) { ((start1 == start2) && (end1 == end2))) {
return 1; return 1;
@ -395,8 +395,8 @@ uint8_t handle_packet_frag_interval(lowpan_reas_buf_t *current_buf,
lowpan_interval_list_t *temp_interval = NULL, *current_interval = NULL, *new_interval = NULL; lowpan_interval_list_t *temp_interval = NULL, *current_interval = NULL, *new_interval = NULL;
current_interval = current_buf->interval_list_head; current_interval = current_buf->interval_list_head;
while(current_interval != NULL) { while (current_interval != NULL) {
if(isInInterval(current_interval->start, current_interval->end, datagram_offset, datagram_offset + frag_size) == 1) { if (isInInterval(current_interval->start, current_interval->end, datagram_offset, datagram_offset + frag_size) == 1) {
/* Interval is overlapping or the same as one of a previous fragment, discard fragment */ /* Interval is overlapping or the same as one of a previous fragment, discard fragment */
return 0; return 0;
} }
@ -407,12 +407,12 @@ uint8_t handle_packet_frag_interval(lowpan_reas_buf_t *current_buf,
new_interval = malloc(sizeof(lowpan_interval_list_t)); new_interval = malloc(sizeof(lowpan_interval_list_t));
if(new_interval != NULL) { if (new_interval != NULL) {
new_interval->start = datagram_offset; new_interval->start = datagram_offset;
new_interval->end = datagram_offset + frag_size - 1; new_interval->end = datagram_offset + frag_size - 1;
new_interval->next = NULL; new_interval->next = NULL;
if((current_interval == NULL) && (temp_interval == NULL)) { if ((current_interval == NULL) && (temp_interval == NULL)) {
current_buf->interval_list_head = new_interval; current_buf->interval_list_head = new_interval;
} }
else { else {
@ -435,12 +435,12 @@ lowpan_reas_buf_t *collect_garbage_fifo(lowpan_reas_buf_t *current_buf)
temp_buf = packet_fifo; temp_buf = packet_fifo;
my_buf = temp_buf; my_buf = temp_buf;
if(packet_fifo == current_buf) { if (packet_fifo == current_buf) {
packet_fifo = current_buf->next; packet_fifo = current_buf->next;
return_buf = packet_fifo; return_buf = packet_fifo;
} }
else { else {
while(temp_buf != current_buf) { while (temp_buf != current_buf) {
my_buf = temp_buf; my_buf = temp_buf;
temp_buf = temp_buf->next; temp_buf = temp_buf->next;
} }
@ -455,7 +455,7 @@ lowpan_reas_buf_t *collect_garbage_fifo(lowpan_reas_buf_t *current_buf)
current_list = current_buf->interval_list_head; current_list = current_buf->interval_list_head;
temp_list = current_list; temp_list = current_list;
while(current_list != NULL) { while (current_list != NULL) {
temp_list = current_list->next; temp_list = current_list->next;
free(current_list); free(current_list);
current_list = temp_list; current_list = temp_list;
@ -475,12 +475,12 @@ lowpan_reas_buf_t *collect_garbage(lowpan_reas_buf_t *current_buf)
temp_buf = head; temp_buf = head;
my_buf = temp_buf; my_buf = temp_buf;
if(head == current_buf) { if (head == current_buf) {
head = current_buf->next; head = current_buf->next;
return_buf = head; return_buf = head;
} }
else { else {
while(temp_buf != current_buf) { while (temp_buf != current_buf) {
my_buf = temp_buf; my_buf = temp_buf;
temp_buf = temp_buf->next; temp_buf = temp_buf->next;
} }
@ -493,7 +493,7 @@ lowpan_reas_buf_t *collect_garbage(lowpan_reas_buf_t *current_buf)
current_list = current_buf->interval_list_head; current_list = current_buf->interval_list_head;
temp_list = current_list; temp_list = current_list;
while(current_list != NULL) { while (current_list != NULL) {
temp_list = current_list->next; temp_list = current_list->next;
free(current_list); free(current_list);
current_list = temp_list; current_list = temp_list;
@ -515,24 +515,24 @@ void handle_packet_fragment(uint8_t *data, uint8_t datagram_offset,
/* Is there already a reassembly buffer for this packet fragment? */ /* Is there already a reassembly buffer for this packet fragment? */
current_buf = get_packet_frag_buf(datagram_size, datagram_tag, s_laddr, d_laddr); current_buf = get_packet_frag_buf(datagram_size, datagram_tag, s_laddr, d_laddr);
if((current_buf != NULL) && (handle_packet_frag_interval(current_buf, if ((current_buf != NULL) && (handle_packet_frag_interval(current_buf,
datagram_offset, datagram_offset,
frag_size) == 1)) { frag_size) == 1)) {
/* Copy fragment bytes into corresponding packet space area */ /* Copy fragment bytes into corresponding packet space area */
memcpy(current_buf->packet + datagram_offset, data + hdr_length, frag_size); memcpy(current_buf->packet + datagram_offset, data + hdr_length, frag_size);
current_buf->current_packet_size += frag_size; current_buf->current_packet_size += frag_size;
if(current_buf->current_packet_size == current_buf->packet_size) { if (current_buf->current_packet_size == current_buf->packet_size) {
add_fifo_packet(current_buf); add_fifo_packet(current_buf);
if(thread_getstatus(transfer_pid) == STATUS_SLEEPING) { if (thread_getstatus(transfer_pid) == STATUS_SLEEPING) {
thread_wakeup(transfer_pid); thread_wakeup(transfer_pid);
} }
} }
} }
else { else {
/* No memory left or duplicate */ /* No memory left or duplicate */
if(current_buf == NULL) { if (current_buf == NULL) {
printf("ERROR: no memory left!\n"); printf("ERROR: no memory left!\n");
} }
else { else {
@ -552,17 +552,17 @@ void check_timeout(void)
cur_time = now.microseconds; cur_time = now.microseconds;
temp_buf = head; temp_buf = head;
while(temp_buf != NULL) { while (temp_buf != NULL) {
if((cur_time - temp_buf->timestamp) >= LOWPAN_REAS_BUF_TIMEOUT) { if ((cur_time - temp_buf->timestamp) >= LOWPAN_REAS_BUF_TIMEOUT) {
printf("TIMEOUT! cur_time: %li, temp_buf: %li\n", cur_time, printf("TIMEOUT!cur_time: %li, temp_buf: %li\n", cur_time,
temp_buf->timestamp); temp_buf->timestamp);
temp_buf = collect_garbage(temp_buf); temp_buf = collect_garbage(temp_buf);
} }
else { else {
if(smallest_time == NULL) { if (smallest_time == NULL) {
smallest_time = temp_buf; smallest_time = temp_buf;
} }
else if(temp_buf->timestamp < smallest_time->timestamp) { else if (temp_buf->timestamp < smallest_time->timestamp) {
smallest_time = temp_buf; smallest_time = temp_buf;
} }
@ -571,7 +571,7 @@ void check_timeout(void)
} }
} }
if((count > 10) && (smallest_time != NULL)) { if ((count > 10) && (smallest_time != NULL)) {
collect_garbage(smallest_time); collect_garbage(smallest_time);
} }
} }
@ -580,13 +580,13 @@ void add_fifo_packet(lowpan_reas_buf_t *current_packet)
{ {
lowpan_reas_buf_t *temp_buf, *my_buf; lowpan_reas_buf_t *temp_buf, *my_buf;
if(head == current_packet) { if (head == current_packet) {
head = current_packet->next; head = current_packet->next;
} }
else { else {
temp_buf = head; temp_buf = head;
while(temp_buf != current_packet) { while (temp_buf != current_packet) {
my_buf = temp_buf; my_buf = temp_buf;
temp_buf = temp_buf->next; temp_buf = temp_buf->next;
} }
@ -596,13 +596,13 @@ void add_fifo_packet(lowpan_reas_buf_t *current_packet)
mutex_lock(&fifo_mutex); mutex_lock(&fifo_mutex);
if(packet_fifo == NULL) { if (packet_fifo == NULL) {
packet_fifo = current_packet; packet_fifo = current_packet;
} }
else { else {
temp_buf = packet_fifo; temp_buf = packet_fifo;
while(temp_buf != NULL) { while (temp_buf != NULL) {
my_buf = temp_buf; my_buf = temp_buf;
temp_buf = temp_buf->next; temp_buf = temp_buf->next;
} }
@ -626,7 +626,7 @@ void lowpan_read(uint8_t *data, uint8_t length, ieee_802154_long_t *s_laddr,
check_timeout(); check_timeout();
/* Fragmented Packet */ /* Fragmented Packet */
if(((data[0] & 0xf8) == (0xc0)) || ((data[0] & 0xf8) == (0xe0))) { if (((data[0] & 0xf8) == (0xc0)) || ((data[0] & 0xf8) == (0xe0))) {
/* get 11-bit from first 2 byte*/ /* get 11-bit from first 2 byte*/
datagram_size = (((uint16_t)(data[0] << 8)) | data[1]) & 0x07ff; datagram_size = (((uint16_t)(data[0] << 8)) | data[1]) & 0x07ff;
@ -635,14 +635,14 @@ void lowpan_read(uint8_t *data, uint8_t length, ieee_802154_long_t *s_laddr,
switch(data[0] & 0xf8) { switch(data[0] & 0xf8) {
/* First Fragment */ /* First Fragment */
case(0xc0): { case (0xc0): {
datagram_offset = 0; datagram_offset = 0;
hdr_length += 4; hdr_length += 4;
break; break;
} }
/* Subsequent Fragment */ /* Subsequent Fragment */
case(0xe0): { case (0xe0): {
datagram_offset = data[4]; datagram_offset = data[4];
hdr_length += 5; hdr_length += 5;
break; break;
@ -652,8 +652,8 @@ void lowpan_read(uint8_t *data, uint8_t length, ieee_802154_long_t *s_laddr,
frag_size = length - hdr_length; frag_size = length - hdr_length;
byte_offset = datagram_offset * 8; byte_offset = datagram_offset * 8;
if((frag_size % 8) != 0) { if ((frag_size % 8) != 0) {
if((byte_offset + frag_size) != datagram_size) { if ((byte_offset + frag_size) != datagram_size) {
printf("ERROR: received invalid fragment\n"); printf("ERROR: received invalid fragment\n");
return; return;
} }
@ -671,7 +671,7 @@ void lowpan_read(uint8_t *data, uint8_t length, ieee_802154_long_t *s_laddr,
current_buf->current_packet_size += length; current_buf->current_packet_size += length;
add_fifo_packet(current_buf); add_fifo_packet(current_buf);
if(thread_getstatus(transfer_pid) == STATUS_SLEEPING) { if (thread_getstatus(transfer_pid) == STATUS_SLEEPING) {
thread_wakeup(transfer_pid); thread_wakeup(transfer_pid);
} }
} }
@ -710,12 +710,12 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra,
(ipv6_buf->trafficclass_flowlabel >> 4); (ipv6_buf->trafficclass_flowlabel >> 4);
tc = (tc >> 2) | (tc << 6); tc = (tc >> 2) | (tc << 6);
if((ipv6_buf->flowlabel == 0) && if ((ipv6_buf->flowlabel == 0) &&
(ipv6_buf->trafficclass_flowlabel & 0x0f) == 0) { (ipv6_buf->trafficclass_flowlabel & 0x0f) == 0) {
/* flowlabel is elided */ /* flowlabel is elided */
lowpan_iphc[0] |= LOWPAN_IPHC_FL_C; lowpan_iphc[0] |= LOWPAN_IPHC_FL_C;
if(((ipv6_buf->version_trafficclass & 0x0f) == 0) && if (((ipv6_buf->version_trafficclass & 0x0f) == 0) &&
((ipv6_buf->trafficclass_flowlabel & 0xf0) == 0)) { ((ipv6_buf->trafficclass_flowlabel & 0xf0) == 0)) {
/* traffic class is elided */ /* traffic class is elided */
lowpan_iphc[0] |= LOWPAN_IPHC_TC_C; lowpan_iphc[0] |= LOWPAN_IPHC_TC_C;
@ -728,7 +728,7 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra,
} }
else { else {
/* flowlabel not compressible */ /* flowlabel not compressible */
if(((ipv6_buf->version_trafficclass & 0x0f) == 0) && if (((ipv6_buf->version_trafficclass & 0x0f) == 0) &&
((ipv6_buf->trafficclass_flowlabel & 0xf0) == 0)) { ((ipv6_buf->trafficclass_flowlabel & 0xf0) == 0)) {
/* traffic class is elided */ /* traffic class is elided */
lowpan_iphc[0] |= LOWPAN_IPHC_TC_C; lowpan_iphc[0] |= LOWPAN_IPHC_TC_C;
@ -753,19 +753,19 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra,
/* HLIM: Hop Limit: */ /* HLIM: Hop Limit: */
switch(ipv6_buf->hoplimit) { switch(ipv6_buf->hoplimit) {
case(1): { case (1): {
/* 01: The Hop Limit field is compressed and the hop limit is 1. */ /* 01: The Hop Limit field is compressed and the hop limit is 1. */
lowpan_iphc[0] |= 0x01; lowpan_iphc[0] |= 0x01;
break; break;
} }
case(64): { case (64): {
/* 10: The Hop Limit field is compressed and the hop limit is 64. */ /* 10: The Hop Limit field is compressed and the hop limit is 64. */
lowpan_iphc[0] |= 0x02; lowpan_iphc[0] |= 0x02;
break; break;
} }
case(255): { case (255): {
/* 11: The Hop Limit field is compressed and the hop limit is 255. */ /* 11: The Hop Limit field is compressed and the hop limit is 255. */
lowpan_iphc[0] |= 0x03; lowpan_iphc[0] |= 0x03;
break; break;
@ -781,7 +781,7 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra,
mutex_lock(&lowpan_context_mutex); mutex_lock(&lowpan_context_mutex);
/* CID: Context Identifier Extension: */ /* CID: Context Identifier Extension: */
if((lowpan_context_lookup(&ipv6_buf->srcaddr) != NULL) || if ((lowpan_context_lookup(&ipv6_buf->srcaddr) != NULL) ||
(lowpan_context_lookup(&ipv6_buf->destaddr) != NULL)) { (lowpan_context_lookup(&ipv6_buf->destaddr) != NULL)) {
lowpan_iphc[1] |= LOWPAN_IPHC_CID; lowpan_iphc[1] |= LOWPAN_IPHC_CID;
memmove(&ipv6_hdr_fields[1], &ipv6_hdr_fields[0], hdr_pos); memmove(&ipv6_hdr_fields[1], &ipv6_hdr_fields[0], hdr_pos);
@ -789,22 +789,22 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra,
} }
/* SAC: Source Address Compression */ /* SAC: Source Address Compression */
if(ipv6_addr_unspec_match(&(ipv6_buf->srcaddr))) { if (ipv6_addr_unspec_match(&(ipv6_buf->srcaddr))) {
/* SAC = 1 and SAM = 00 */ /* SAC = 1 and SAM = 00 */
lowpan_iphc[1] |= LOWPAN_IPHC_SAC; lowpan_iphc[1] |= LOWPAN_IPHC_SAC;
} }
else if((con = lowpan_context_lookup(&ipv6_buf->srcaddr)) != NULL) { else if ((con = lowpan_context_lookup(&ipv6_buf->srcaddr)) != NULL) {
/* 1: Source address compression uses stateful, context-based /* 1: Source address compression uses stateful, context-based
* compression. */ * compression. */
lowpan_iphc[1] |= LOWPAN_IPHC_SAC; lowpan_iphc[1] |= LOWPAN_IPHC_SAC;
ipv6_hdr_fields[0] |= (con->num << 4); ipv6_hdr_fields[0] |= (con->num << 4);
if(memcmp(&(ipv6_buf->srcaddr.uint8[8]), &(iface.laddr.uint8[0]), 8) == 0) { if (memcmp(&(ipv6_buf->srcaddr.uint8[8]), &(iface.laddr.uint8[0]), 8) == 0) {
/* 0 bits. The address is derived using context information /* 0 bits. The address is derived using context information
* and possibly the link-layer addresses.*/ * and possibly the link-layer addresses.*/
lowpan_iphc[1] |= 0x30; lowpan_iphc[1] |= 0x30;
} }
else if((ipv6_buf->srcaddr.uint16[4] == 0) && else if ((ipv6_buf->srcaddr.uint16[4] == 0) &&
(ipv6_buf->srcaddr.uint16[5] == 0) && (ipv6_buf->srcaddr.uint16[5] == 0) &&
(ipv6_buf->srcaddr.uint16[6] == 0) && (ipv6_buf->srcaddr.uint16[6] == 0) &&
((ipv6_buf->srcaddr.uint8[14]) & 0x80) == 0) { ((ipv6_buf->srcaddr.uint8[14]) & 0x80) == 0) {
@ -824,14 +824,14 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra,
lowpan_iphc[1] |= 0x10; lowpan_iphc[1] |= 0x10;
} }
} }
else if(ipv6_prefix_ll_match(&ipv6_buf->srcaddr)) { else if (ipv6_prefix_ll_match(&ipv6_buf->srcaddr)) {
/* 0: Source address compression uses stateless compression.*/ /* 0: Source address compression uses stateless compression.*/
if(memcmp(&(ipv6_buf->srcaddr.uint8[8]), &(iface.laddr.uint8[0]), 8) == 0) { if (memcmp(&(ipv6_buf->srcaddr.uint8[8]), &(iface.laddr.uint8[0]), 8) == 0) {
/* 0 bits. The address is derived using context information /* 0 bits. The address is derived using context information
* and possibly the link-layer addresses.*/ * and possibly the link-layer addresses.*/
lowpan_iphc[1] |= 0x30; lowpan_iphc[1] |= 0x30;
} }
else if((ipv6_buf->srcaddr.uint16[4] == 0) && else if ((ipv6_buf->srcaddr.uint16[4] == 0) &&
(ipv6_buf->srcaddr.uint16[5] == 0) && (ipv6_buf->srcaddr.uint16[5] == 0) &&
(ipv6_buf->srcaddr.uint16[6] == 0) && (ipv6_buf->srcaddr.uint16[6] == 0) &&
((ipv6_buf->srcaddr.uint8[14]) & 0x80) == 0) { ((ipv6_buf->srcaddr.uint8[14]) & 0x80) == 0) {
@ -858,12 +858,12 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra,
} }
/* M: Multicast Compression */ /* M: Multicast Compression */
if(ipv6_prefix_mcast_match(&ipv6_buf->destaddr)) { if (ipv6_prefix_mcast_match(&ipv6_buf->destaddr)) {
/* 1: Destination address is a multicast address. */ /* 1: Destination address is a multicast address. */
lowpan_iphc[1] |= LOWPAN_IPHC_M; lowpan_iphc[1] |= LOWPAN_IPHC_M;
/* just another cool if condition */ /* just another cool if condition */
if((ipv6_buf->destaddr.uint8[1] == 2) && if ((ipv6_buf->destaddr.uint8[1] == 2) &&
(ipv6_buf->destaddr.uint16[1] == 0) && (ipv6_buf->destaddr.uint16[1] == 0) &&
(ipv6_buf->destaddr.uint16[2] == 0) && (ipv6_buf->destaddr.uint16[2] == 0) &&
(ipv6_buf->destaddr.uint16[3] == 0) && (ipv6_buf->destaddr.uint16[3] == 0) &&
@ -876,7 +876,7 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra,
ipv6_hdr_fields[hdr_pos] = ipv6_buf->destaddr.uint8[15]; ipv6_hdr_fields[hdr_pos] = ipv6_buf->destaddr.uint8[15];
hdr_pos++; hdr_pos++;
} }
else if((ipv6_buf->destaddr.uint16[1] == 0) && else if ((ipv6_buf->destaddr.uint16[1] == 0) &&
(ipv6_buf->destaddr.uint16[2] == 0) && (ipv6_buf->destaddr.uint16[2] == 0) &&
(ipv6_buf->destaddr.uint16[3] == 0) && (ipv6_buf->destaddr.uint16[3] == 0) &&
(ipv6_buf->destaddr.uint16[4] == 0) && (ipv6_buf->destaddr.uint16[4] == 0) &&
@ -890,7 +890,7 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra,
memcpy(&ipv6_hdr_fields[hdr_pos], &ipv6_buf->destaddr.uint8[13], 3); memcpy(&ipv6_hdr_fields[hdr_pos], &ipv6_buf->destaddr.uint8[13], 3);
hdr_pos += 3; hdr_pos += 3;
} }
else if((ipv6_buf->destaddr.uint16[1] == 0) && else if ((ipv6_buf->destaddr.uint16[1] == 0) &&
(ipv6_buf->destaddr.uint16[2] == 0) && (ipv6_buf->destaddr.uint16[2] == 0) &&
(ipv6_buf->destaddr.uint16[3] == 0) && (ipv6_buf->destaddr.uint16[3] == 0) &&
(ipv6_buf->destaddr.uint16[4] == 0) && (ipv6_buf->destaddr.uint16[4] == 0) &&
@ -910,18 +910,18 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra,
} }
else { else {
/* 0: Destination address is not a multicast address. */ /* 0: Destination address is not a multicast address. */
if((con = lowpan_context_lookup(&ipv6_buf->destaddr)) != NULL) { if ((con = lowpan_context_lookup(&ipv6_buf->destaddr)) != NULL) {
/* 1: Destination address compression uses stateful, context-based /* 1: Destination address compression uses stateful, context-based
* compression. */ * compression. */
lowpan_iphc[1] |= LOWPAN_IPHC_DAC; lowpan_iphc[1] |= LOWPAN_IPHC_DAC;
ipv6_hdr_fields[0] = con->num; ipv6_hdr_fields[0] = con->num;
if(memcmp(&(ipv6_buf->destaddr.uint8[8]), &(dest->uint8[0]), 8) == 0) { if (memcmp(&(ipv6_buf->destaddr.uint8[8]), &(dest->uint8[0]), 8) == 0) {
/* 0 bits. The address is derived using context information /* 0 bits. The address is derived using context information
* and possibly the link-layer addresses.*/ * and possibly the link-layer addresses.*/
lowpan_iphc[1] |= 0x03; lowpan_iphc[1] |= 0x03;
} }
else if((ipv6_buf->destaddr.uint16[4] == 0) && else if ((ipv6_buf->destaddr.uint16[4] == 0) &&
(ipv6_buf->destaddr.uint16[5] == 0) && (ipv6_buf->destaddr.uint16[5] == 0) &&
(ipv6_buf->destaddr.uint16[6] == 0) && (ipv6_buf->destaddr.uint16[6] == 0) &&
((ipv6_buf->destaddr.uint8[14]) & 0x80) == 0) { ((ipv6_buf->destaddr.uint8[14]) & 0x80) == 0) {
@ -941,13 +941,13 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra,
lowpan_iphc[1] |= 0x01; lowpan_iphc[1] |= 0x01;
} }
} }
else if(ipv6_prefix_ll_match(&ipv6_buf->destaddr)) { else if (ipv6_prefix_ll_match(&ipv6_buf->destaddr)) {
if(memcmp(&(ipv6_buf->destaddr.uint8[8]), &(dest->uint8[0]), 8) == 0) { if (memcmp(&(ipv6_buf->destaddr.uint8[8]), &(dest->uint8[0]), 8) == 0) {
/* 0 bits. The address is derived using context information /* 0 bits. The address is derived using context information
* and possibly the link-layer addresses.*/ * and possibly the link-layer addresses.*/
lowpan_iphc[1] |= 0x03; lowpan_iphc[1] |= 0x03;
} }
else if((ipv6_buf->destaddr.uint16[4] == 0) && else if ((ipv6_buf->destaddr.uint16[4] == 0) &&
(ipv6_buf->destaddr.uint16[5] == 0) && (ipv6_buf->destaddr.uint16[5] == 0) &&
(ipv6_buf->destaddr.uint16[6] == 0) && (ipv6_buf->destaddr.uint16[6] == 0) &&
((ipv6_buf->destaddr.uint8[14]) & 0x80) == 0) { ((ipv6_buf->destaddr.uint8[14]) & 0x80) == 0) {
@ -1015,15 +1015,15 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
hdr_pos += 2; hdr_pos += 2;
/* first check if CID flag is set */ /* first check if CID flag is set */
if(lowpan_iphc[1] & LOWPAN_IPHC_CID) { if (lowpan_iphc[1] & LOWPAN_IPHC_CID) {
hdr_pos++; hdr_pos++;
cid = 1; cid = 1;
} }
/* TF: Traffic Class, Flow Label: */ /* TF: Traffic Class, Flow Label: */
if(lowpan_iphc[0] & LOWPAN_IPHC_FL_C) { if (lowpan_iphc[0] & LOWPAN_IPHC_FL_C) {
/* flowlabel is elided */ /* flowlabel is elided */
if(lowpan_iphc[0] & LOWPAN_IPHC_TC_C) { if (lowpan_iphc[0] & LOWPAN_IPHC_TC_C) {
/* traffic class is elided */ /* traffic class is elided */
ipv6_buf->version_trafficclass = 0x60; ipv6_buf->version_trafficclass = 0x60;
ipv6_buf->trafficclass_flowlabel = 0; ipv6_buf->trafficclass_flowlabel = 0;
@ -1041,7 +1041,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
} }
else { else {
/* flowlabel carried inline */ /* flowlabel carried inline */
if(lowpan_iphc[0] & LOWPAN_IPHC_TC_C) { if (lowpan_iphc[0] & LOWPAN_IPHC_TC_C) {
/* traffic class is elided */ /* traffic class is elided */
ipv6_buf->version_trafficclass = 0x60; ipv6_buf->version_trafficclass = 0x60;
/* ecn + 4 bit flowlabel*/ /* ecn + 4 bit flowlabel*/
@ -1066,7 +1066,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
} }
/* NH: Next Header: */ /* NH: Next Header: */
if(lowpan_iphc[0] & LOWPAN_IPHC_NH) { if (lowpan_iphc[0] & LOWPAN_IPHC_NH) {
// TODO: next header decompression // TODO: next header decompression
} }
else { else {
@ -1075,19 +1075,19 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
} }
/* HLIM: Hop Limit: */ /* HLIM: Hop Limit: */
if(lowpan_iphc[0] & 0x03) { if (lowpan_iphc[0] & 0x03) {
switch(lowpan_iphc[0] & 0x03) { switch(lowpan_iphc[0] & 0x03) {
case(0x01): { case (0x01): {
ipv6_buf->hoplimit = 1; ipv6_buf->hoplimit = 1;
break; break;
} }
case(0x02): { case (0x02): {
ipv6_buf->hoplimit = 64; ipv6_buf->hoplimit = 64;
break; break;
} }
case(0x03): { case (0x03): {
ipv6_buf->hoplimit = 255; ipv6_buf->hoplimit = 255;
break; break;
} }
@ -1102,27 +1102,27 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
} }
/* CID: Context Identifier Extension: + SAC: Source Address Compression */ /* CID: Context Identifier Extension: + SAC: Source Address Compression */
if(lowpan_iphc[1] & LOWPAN_IPHC_SAC) { if (lowpan_iphc[1] & LOWPAN_IPHC_SAC) {
/* 1: Source address compression uses stateful, context-based /* 1: Source address compression uses stateful, context-based
* compression.*/ * compression.*/
if(cid) { if (cid) {
sci = ipv6_hdr_fields[3] >> 4; sci = ipv6_hdr_fields[3] >> 4;
} }
mutex_lock(&lowpan_context_mutex); mutex_lock(&lowpan_context_mutex);
/* check context number */ /* check context number */
if(((lowpan_iphc[1] & LOWPAN_IPHC_SAM) >> 4) & 0x03) { if (((lowpan_iphc[1] & LOWPAN_IPHC_SAM) >> 4) & 0x03) {
con = lowpan_context_num_lookup(sci); con = lowpan_context_num_lookup(sci);
} }
if(con == NULL) { if (con == NULL) {
printf("ERROR: context not found\n"); printf("ERROR: context not found\n");
return; return;
} }
switch(((lowpan_iphc[1] & LOWPAN_IPHC_SAM) >> 4) & 0x03) { switch(((lowpan_iphc[1] & LOWPAN_IPHC_SAM) >> 4) & 0x03) {
case(0x01): { case (0x01): {
/* 64-bits */ /* 64-bits */
memcpy(&(ipv6_buf->srcaddr.uint8[8]), &ipv6_hdr_fields[hdr_pos], 8); memcpy(&(ipv6_buf->srcaddr.uint8[8]), &ipv6_hdr_fields[hdr_pos], 8);
/* By draft-ietf-6lowpan-hc-15 3.1.1. Bits covered by context /* By draft-ietf-6lowpan-hc-15 3.1.1. Bits covered by context
@ -1132,7 +1132,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
break; break;
} }
case(0x02): { case (0x02): {
/* 16-bits */ /* 16-bits */
memset(&(ipv6_buf->srcaddr.uint8[8]), 0, 6); memset(&(ipv6_buf->srcaddr.uint8[8]), 0, 6);
memcpy(&(ipv6_buf->srcaddr.uint8[14]), &ipv6_hdr_fields[hdr_pos], 2); memcpy(&(ipv6_buf->srcaddr.uint8[14]), &ipv6_hdr_fields[hdr_pos], 2);
@ -1143,7 +1143,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
break; break;
} }
case(0x03): { case (0x03): {
/* 0-bits */ /* 0-bits */
memset(&(ipv6_buf->srcaddr.uint8[8]), 0, 8); memset(&(ipv6_buf->srcaddr.uint8[8]), 0, 8);
memcpy(&(ipv6_buf->srcaddr.uint8[8]), &s_laddr->uint8[0], 8); memcpy(&(ipv6_buf->srcaddr.uint8[8]), &s_laddr->uint8[0], 8);
@ -1164,7 +1164,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
} }
else { else {
switch(((lowpan_iphc[1] & LOWPAN_IPHC_SAM) >> 4) & 0x03) { switch(((lowpan_iphc[1] & LOWPAN_IPHC_SAM) >> 4) & 0x03) {
case(0x01): { case (0x01): {
/* 64-bits */ /* 64-bits */
memcpy(&(ipv6_buf->srcaddr.uint8[0]), &ll_prefix[0], 2); memcpy(&(ipv6_buf->srcaddr.uint8[0]), &ll_prefix[0], 2);
memset(&(ipv6_buf->srcaddr.uint8[2]), 0, 6); memset(&(ipv6_buf->srcaddr.uint8[2]), 0, 6);
@ -1173,7 +1173,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
break; break;
} }
case(0x02): { case (0x02): {
/* 16-bits */ /* 16-bits */
memcpy(&(ipv6_buf->srcaddr.uint8[0]), &ll_prefix[0], 2); memcpy(&(ipv6_buf->srcaddr.uint8[0]), &ll_prefix[0], 2);
memset(&(ipv6_buf->srcaddr.uint8[2]), 0, 12); memset(&(ipv6_buf->srcaddr.uint8[2]), 0, 12);
@ -1182,7 +1182,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
break; break;
} }
case(0x03): { case (0x03): {
/* 0-bits */ /* 0-bits */
memcpy(&(ipv6_buf->srcaddr.uint8[0]), &ll_prefix[0], 2); memcpy(&(ipv6_buf->srcaddr.uint8[0]), &ll_prefix[0], 2);
memset(&(ipv6_buf->srcaddr.uint8[8]), 0, 14); memset(&(ipv6_buf->srcaddr.uint8[8]), 0, 14);
@ -1201,23 +1201,23 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
} }
/* M: Multicast Compression + DAC: Destination Address Compression */ /* M: Multicast Compression + DAC: Destination Address Compression */
if(lowpan_iphc[1] & LOWPAN_IPHC_M) { if (lowpan_iphc[1] & LOWPAN_IPHC_M) {
/* 1: Destination address is a multicast address. */ /* 1: Destination address is a multicast address. */
if(lowpan_iphc[1] & LOWPAN_IPHC_DAC) { if (lowpan_iphc[1] & LOWPAN_IPHC_DAC) {
/* 1: Destination address compression uses stateful, context-based /* 1: Destination address compression uses stateful, context-based
* compression. * compression.
* If M=1 and DAC=1: */ * If M=1 and DAC=1: */
if(cid) { if (cid) {
dci = ipv6_hdr_fields[3] & 0x0f; dci = ipv6_hdr_fields[3] & 0x0f;
} }
mutex_lock(&lowpan_context_mutex); mutex_lock(&lowpan_context_mutex);
if((lowpan_iphc[1] & LOWPAN_IPHC_DAM) & 0x03) { if ((lowpan_iphc[1] & LOWPAN_IPHC_DAM) & 0x03) {
con = lowpan_context_num_lookup(dci); con = lowpan_context_num_lookup(dci);
} }
if(con == NULL) { if (con == NULL) {
printf("ERROR: context not found\n"); printf("ERROR: context not found\n");
return; return;
} }
@ -1228,13 +1228,13 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
else { else {
/* If M=1 and DAC=0: */ /* If M=1 and DAC=0: */
switch(lowpan_iphc[1] & 0x03) { switch(lowpan_iphc[1] & 0x03) {
case(0x01): { case (0x01): {
m_prefix[1] = ipv6_hdr_fields[hdr_pos]; m_prefix[1] = ipv6_hdr_fields[hdr_pos];
hdr_pos++; hdr_pos++;
break; break;
} }
case(0x02): { case (0x02): {
m_prefix[1] = ipv6_hdr_fields[hdr_pos]; m_prefix[1] = ipv6_hdr_fields[hdr_pos];
hdr_pos++; hdr_pos++;
break; break;
@ -1245,7 +1245,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
} }
switch(lowpan_iphc[1] & 0x03) { switch(lowpan_iphc[1] & 0x03) {
case(0x01): { case (0x01): {
memcpy(&(ipv6_buf->destaddr.uint8[0]), &m_prefix[0], 2); memcpy(&(ipv6_buf->destaddr.uint8[0]), &m_prefix[0], 2);
memset(&(ipv6_buf->destaddr.uint8[2]), 0, 9); memset(&(ipv6_buf->destaddr.uint8[2]), 0, 9);
memcpy(&(ipv6_buf->destaddr.uint8[11]), &ipv6_hdr_fields[hdr_pos], 5); memcpy(&(ipv6_buf->destaddr.uint8[11]), &ipv6_hdr_fields[hdr_pos], 5);
@ -1253,7 +1253,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
break; break;
} }
case(0x02): { case (0x02): {
memcpy(&(ipv6_buf->destaddr.uint8[0]), &m_prefix[0], 2); memcpy(&(ipv6_buf->destaddr.uint8[0]), &m_prefix[0], 2);
memset(&(ipv6_buf->destaddr.uint8[2]), 0, 11); memset(&(ipv6_buf->destaddr.uint8[2]), 0, 11);
memcpy(&(ipv6_buf->destaddr.uint8[13]), &ipv6_hdr_fields[hdr_pos], 3); memcpy(&(ipv6_buf->destaddr.uint8[13]), &ipv6_hdr_fields[hdr_pos], 3);
@ -1261,7 +1261,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
break; break;
} }
case(0x03): { case (0x03): {
memcpy(&(ipv6_buf->destaddr.uint8[0]), &m_prefix[0], 2); memcpy(&(ipv6_buf->destaddr.uint8[0]), &m_prefix[0], 2);
memset(&(ipv6_buf->destaddr.uint8[2]), 0, 13); memset(&(ipv6_buf->destaddr.uint8[2]), 0, 13);
memcpy(&(ipv6_buf->destaddr.uint8[15]), &ipv6_hdr_fields[hdr_pos], 1); memcpy(&(ipv6_buf->destaddr.uint8[15]), &ipv6_hdr_fields[hdr_pos], 1);
@ -1277,27 +1277,27 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
} }
} }
else { else {
if(lowpan_iphc[1] & LOWPAN_IPHC_DAC) { if (lowpan_iphc[1] & LOWPAN_IPHC_DAC) {
/* 1: Destination address compression uses stateful, context-based /* 1: Destination address compression uses stateful, context-based
* compression. * compression.
* If M=1 and DAC=1: */ * If M=1 and DAC=1: */
if(cid) { if (cid) {
dci = ipv6_hdr_fields[3] & 0x0f; dci = ipv6_hdr_fields[3] & 0x0f;
} }
mutex_lock(&lowpan_context_mutex); mutex_lock(&lowpan_context_mutex);
if((lowpan_iphc[1] & LOWPAN_IPHC_DAM) & 0x03) { if ((lowpan_iphc[1] & LOWPAN_IPHC_DAM) & 0x03) {
con = lowpan_context_num_lookup(dci); con = lowpan_context_num_lookup(dci);
} }
if(con == NULL) { if (con == NULL) {
printf("ERROR: context not found\n"); printf("ERROR: context not found\n");
return; return;
} }
switch((lowpan_iphc[1] & LOWPAN_IPHC_DAM) & 0x03) { switch((lowpan_iphc[1] & LOWPAN_IPHC_DAM) & 0x03) {
case(0x01): { case (0x01): {
memcpy(&(ipv6_buf->destaddr.uint8[8]), &ipv6_hdr_fields[hdr_pos], 8); memcpy(&(ipv6_buf->destaddr.uint8[8]), &ipv6_hdr_fields[hdr_pos], 8);
/* By draft-ietf-6lowpan-hc-15 3.1.1. Bits covered by context information are always used. */ /* By draft-ietf-6lowpan-hc-15 3.1.1. Bits covered by context information are always used. */
memcpy(&(ipv6_buf->srcaddr.uint8[0]), &con->prefix, con->length); memcpy(&(ipv6_buf->srcaddr.uint8[0]), &con->prefix, con->length);
@ -1305,7 +1305,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
break; break;
} }
case(0x02): { case (0x02): {
memset(&(ipv6_buf->destaddr.uint8[8]), 0, 6); memset(&(ipv6_buf->destaddr.uint8[8]), 0, 6);
memcpy(&(ipv6_buf->destaddr.uint8[14]), &ipv6_hdr_fields[hdr_pos], 2); memcpy(&(ipv6_buf->destaddr.uint8[14]), &ipv6_hdr_fields[hdr_pos], 2);
/* By draft-ietf-6lowpan-hc-15 3.1.1. Bits covered by context information are always used. */ /* By draft-ietf-6lowpan-hc-15 3.1.1. Bits covered by context information are always used. */
@ -1314,7 +1314,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
break; break;
} }
case(0x03): { case (0x03): {
memset(&(ipv6_buf->destaddr.uint8[0]), 0, 8); memset(&(ipv6_buf->destaddr.uint8[0]), 0, 8);
memcpy(&(ipv6_buf->destaddr.uint8[8]), &d_laddr->uint8[0], 8); memcpy(&(ipv6_buf->destaddr.uint8[8]), &d_laddr->uint8[0], 8);
/* By draft-ietf-6lowpan-hc-15 3.1.1. Bits covered by context information are always used. */ /* By draft-ietf-6lowpan-hc-15 3.1.1. Bits covered by context information are always used. */
@ -1330,7 +1330,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
} }
else { else {
switch((lowpan_iphc[1] & LOWPAN_IPHC_DAM) & 0x03) { switch((lowpan_iphc[1] & LOWPAN_IPHC_DAM) & 0x03) {
case(0x01): { case (0x01): {
memcpy(&(ipv6_buf->destaddr.uint8[0]), &ll_prefix[0], 2); memcpy(&(ipv6_buf->destaddr.uint8[0]), &ll_prefix[0], 2);
memset(&(ipv6_buf->destaddr.uint8[2]), 0, 6); memset(&(ipv6_buf->destaddr.uint8[2]), 0, 6);
memcpy(&(ipv6_buf->destaddr.uint8[8]), memcpy(&(ipv6_buf->destaddr.uint8[8]),
@ -1339,7 +1339,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
break; break;
} }
case(0x02): { case (0x02): {
memcpy(&(ipv6_buf->destaddr.uint8[0]), &ll_prefix[0], 2); memcpy(&(ipv6_buf->destaddr.uint8[0]), &ll_prefix[0], 2);
memset(&(ipv6_buf->destaddr.uint8[2]), 0, 12); memset(&(ipv6_buf->destaddr.uint8[2]), 0, 12);
memcpy(&(ipv6_buf->destaddr.uint8[14]), memcpy(&(ipv6_buf->destaddr.uint8[14]),
@ -1348,7 +1348,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
break; break;
} }
case(0x03): { case (0x03): {
memcpy(&(ipv6_buf->destaddr.uint8[0]), &ll_prefix, 2); memcpy(&(ipv6_buf->destaddr.uint8[0]), &ll_prefix, 2);
memset(&(ipv6_buf->destaddr.uint8[2]), 0, 14); memset(&(ipv6_buf->destaddr.uint8[2]), 0, 14);
memcpy(&(ipv6_buf->destaddr.uint8[8]), &d_laddr->uint8[0], 8); memcpy(&(ipv6_buf->destaddr.uint8[8]), &d_laddr->uint8[0], 8);
@ -1383,8 +1383,8 @@ void lowpan_context_remove(uint8_t num)
{ {
int i, j; int i, j;
for(i = 0; i < LOWPAN_CONTEXT_MAX; i++) { for (i = 0; i < LOWPAN_CONTEXT_MAX; i++) {
if(contexts[i].num == num) { if (contexts[i].num == num) {
context_len--; context_len--;
break; break;
} }
@ -1392,7 +1392,7 @@ void lowpan_context_remove(uint8_t num)
abr_remove_context(num); abr_remove_context(num);
for(j = i; j < LOWPAN_CONTEXT_MAX; j++) { for (j = i; j < LOWPAN_CONTEXT_MAX; j++) {
contexts[j] = contexts[j + 1]; contexts[j] = contexts[j + 1];
} }
} }
@ -1403,18 +1403,18 @@ lowpan_context_t *lowpan_context_update(uint8_t num, const ipv6_addr_t *prefix,
{ {
lowpan_context_t *context; lowpan_context_t *context;
if(lifetime == 0) { if (lifetime == 0) {
lowpan_context_remove(num); lowpan_context_remove(num);
return NULL; return NULL;
} }
if(context_len == LOWPAN_CONTEXT_MAX) { if (context_len == LOWPAN_CONTEXT_MAX) {
return NULL; return NULL;
} }
context = lowpan_context_num_lookup(num); context = lowpan_context_num_lookup(num);
if(context == NULL) { if (context == NULL) {
context = &(contexts[context_len++]); context = &(contexts[context_len++]);
} }
@ -1439,11 +1439,11 @@ lowpan_context_t *lowpan_context_lookup(ipv6_addr_t *addr)
lowpan_context_t *context = NULL; lowpan_context_t *context = NULL;
for(i = 0; i < lowpan_context_len(); i++) { for (i = 0; i < lowpan_context_len(); i++) {
if(contexts[i].length > 0 && memcmp((void *)addr, &(contexts[i].prefix), if (contexts[i].length > 0 && memcmp((void *)addr, &(contexts[i].prefix),
contexts[i].length) == 0) { contexts[i].length) == 0) {
/* longer prefixes are always prefered */ /* longer prefixes are always prefered */
if(context == NULL || context->length < contexts[i].length) { if (context == NULL || context->length < contexts[i].length) {
context = &contexts[i]; context = &contexts[i];
} }
} }
@ -1456,8 +1456,8 @@ lowpan_context_t *lowpan_context_num_lookup(uint8_t num)
{ {
int i; int i;
for(i = 0; i < lowpan_context_len(); i++) { for (i = 0; i < lowpan_context_len(); i++) {
if(contexts[i].num == num) { if (contexts[i].num == num) {
return &contexts[i]; return &contexts[i];
} }
} }
@ -1472,18 +1472,18 @@ void lowpan_context_auto_remove(void)
int8_t to_remove[LOWPAN_CONTEXT_MAX]; int8_t to_remove[LOWPAN_CONTEXT_MAX];
int8_t to_remove_size; int8_t to_remove_size;
while(1) { while (1) {
vtimer_sleep(minute); vtimer_sleep(minute);
to_remove_size = 0; to_remove_size = 0;
mutex_lock(&lowpan_context_mutex); mutex_lock(&lowpan_context_mutex);
for(i = 0; i < lowpan_context_len(); i++) { for (i = 0; i < lowpan_context_len(); i++) {
if(--(contexts[i].lifetime) == 0) { if (--(contexts[i].lifetime) == 0) {
to_remove[to_remove_size++] = contexts[i].num; to_remove[to_remove_size++] = contexts[i].num;
} }
} }
for(i = 0; i < to_remove_size; i++) { for (i = 0; i < to_remove_size; i++) {
lowpan_context_remove(to_remove[i]); lowpan_context_remove(to_remove[i]);
} }
@ -1542,7 +1542,7 @@ void sixlowpan_init(transceiver_type_t trans, uint8_t r_addr, int as_border)
ipv6_iface_add_addr(&lladdr, ADDR_STATE_PREFERRED, 0, 0, ipv6_iface_add_addr(&lladdr, ADDR_STATE_PREFERRED, 0, 0,
ADDR_CONFIGURED_AUTO); ADDR_CONFIGURED_AUTO);
if(as_border) { if (as_border) {
ip_process_pid = thread_create(ip_process_buf, IP_PROCESS_STACKSIZE, ip_process_pid = thread_create(ip_process_buf, IP_PROCESS_STACKSIZE,
PRIORITY_MAIN - 1, CREATE_STACKTEST, PRIORITY_MAIN - 1, CREATE_STACKTEST,
border_process_lowpan, border_process_lowpan,

View File

@ -35,7 +35,7 @@ void pong(uint16_t src)
int trans_ok = cc1100_send_csmaca(src, protocol_id, 2, pipa->payload, int trans_ok = cc1100_send_csmaca(src, protocol_id, 2, pipa->payload,
sizeof(pipa->payload)); sizeof(pipa->payload));
if(trans_ok < 0) { if (trans_ok < 0) {
print_failed(); print_failed();
} }
} }
@ -56,12 +56,12 @@ void ping(radio_address_t addr, uint8_t channr)
cc1100_set_channel(channr); cc1100_set_channel(channr);
cc1100_set_address(r_address); cc1100_set_address(r_address);
while(1) { while (1) {
vtimer_now(&start); vtimer_now(&start);
int trans_ok = cc1100_send_csmaca(addr, int trans_ok = cc1100_send_csmaca(addr,
protocol_id, 2, pipa->payload, sizeof(pipa->payload)); protocol_id, 2, pipa->payload, sizeof(pipa->payload));
if(trans_ok < 0) { if (trans_ok < 0) {
print_failed(); print_failed();
} }

View File

@ -45,10 +45,10 @@ void thread_print_all(void)
printf("\tpid | %-21s| %-9sQ | pri | stack ( used) location | runtime | switches \n", "name", "state"); printf("\tpid | %-21s| %-9sQ | pri | stack ( used) location | runtime | switches \n", "name", "state");
for(i = 0; i < MAXTHREADS; i++) { for (i = 0; i < MAXTHREADS; i++) {
tcb_t *p = (tcb_t *)sched_threads[i]; tcb_t *p = (tcb_t *)sched_threads[i];
if(p != NULL) { if (p != NULL) {
int state = p->status; // copy state int state = p->status; // copy state
int statebit = number_of_highest_bit(state >> 1); // get state index int statebit = number_of_highest_bit(state >> 1); // get state index
const char *sname = state_names[statebit]; // get state name const char *sname = state_names[statebit]; // get state name

View File

@ -40,7 +40,7 @@ void _cc1100_get_set_address_handler(char *addr)
mesg.content.ptr = (char *) &tcmd; mesg.content.ptr = (char *) &tcmd;
a = atoi(addr + 5); a = atoi(addr + 5);
if(strlen(addr) > 5) { if (strlen(addr) > 5) {
printf("[cc110x] Trying to set address %i\n", a); printf("[cc110x] Trying to set address %i\n", a);
mesg.type = SET_ADDRESS; mesg.type = SET_ADDRESS;
} }
@ -61,7 +61,7 @@ void _cc1100_get_set_channel_handler(char *chan)
mesg.content.ptr = (char *) &tcmd; mesg.content.ptr = (char *) &tcmd;
c = atoi(chan + 5); c = atoi(chan + 5);
if(strlen(chan) > 5) { if (strlen(chan) > 5) {
printf("[cc110x] Trying to set channel %i\n", c); printf("[cc110x] Trying to set channel %i\n", c);
mesg.type = SET_CHANNEL; mesg.type = SET_CHANNEL;
} }
@ -85,11 +85,11 @@ void _cc1100_send_handler(char *pkt)
tok = strtok(pkt + 7, " "); tok = strtok(pkt + 7, " ");
if(tok) { if (tok) {
addr = atoi(tok); addr = atoi(tok);
tok = strtok(NULL, " "); tok = strtok(NULL, " ");
if(tok) { if (tok) {
memset(text_msg, 0, TEXT_SIZE); memset(text_msg, 0, TEXT_SIZE);
memcpy(text_msg, tok, strlen(tok)); memcpy(text_msg, tok, strlen(tok));
/* if (sscanf(pkt, "txtsnd %hu %s", &(addr), text_msg) == 2) {*/ /* if (sscanf(pkt, "txtsnd %hu %s", &(addr), text_msg) == 2) {*/
@ -116,11 +116,11 @@ void _cc110x_get_set_address_handler(char *addr)
a = atoi(addr + 5); a = atoi(addr + 5);
if(strlen(addr) > 5) { if (strlen(addr) > 5) {
printf("[cc110x] Setting address %i ... ", a); printf("[cc110x] Setting address %i ... ", a);
cc1100_set_address((radio_address_t)a); cc1100_set_address((radio_address_t)a);
if(cc1100_get_address() == (radio_address_t)a) { if (cc1100_get_address() == (radio_address_t)a) {
puts("[OK]"); puts("[OK]");
} }
else { else {
@ -138,11 +138,11 @@ void _cc110x_get_set_channel_handler(char *addr)
a = atoi(addr + 5); a = atoi(addr + 5);
if(strlen(addr) > 5) { if (strlen(addr) > 5) {
printf("[cc110x] Setting channel %i...", a); printf("[cc110x] Setting channel %i...", a);
cc1100_set_channel(a); cc1100_set_channel(a);
if(cc1100_get_channel() == a) { if (cc1100_get_channel() == a) {
puts("OK"); puts("OK");
} }
else { else {

Some files were not shown because too many files have changed in this diff Show More