Blame view

RIOT/examples/network_app/main.c 4.85 KB
a752c7ab   elopes   add first test an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
  /*
   * Copyright (C) 2015 Freie Universitรคt Berlin
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @ingroup     examples
   * @{
   *
   * @file
   * @brief       Example application for demonstrating the RIOT network stack
   *
   * @author      Hauke Petersen <hauke.petersen@fu-berlin.de>
   *
   * @}
   */
  
  #include <stdbool.h>
  #include <stdint.h>
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
  #include <inttypes.h>
  #include <arpa/inet.h>
  
  #include "net/gnrc/ipv6.h"
  #include "shell.h"
  #include "shell_commands.h"
  #include "msg.h"
  #include "thread.h"
  #include "sched.h"
  #include "thread.h"
  #include "kernel_types.h"
  #include "net/netstats.h"
  #include "net/ipv6/addr.h"
  #include "net/gnrc/ipv6/netif.h"
  #include "net/gnrc/netif.h"
  #include "net/gnrc/netapi.h"
  #include "net/netopt.h"
  #include "net/gnrc/pkt.h"
  #include "net/gnrc/pktbuf.h"
  #include "net/gnrc/netif/hdr.h"
  #include "net/gnrc/sixlowpan/netif.h"
  #include "net/fib.h"
  #include "net/gnrc.h"
  #include "net/gnrc/udp.h"
  #include "net/gnrc/pktdump.h"
  #include "xtimer.h"
  
  
  #define MAIN_QUEUE_SIZE	(8)
  #define MAX_ADDR_LEN	(8U)
  
  // addr ipv6 link local node 1: fe80::1210:642c:1432:1702
  uint8_t node1[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x10,0x64,0x2c,0x14,0x32,0x17,0x02};
  // addr ipv6 link local node 2: fe80::1210:6432:140f:1732
  uint8_t node2[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x10,0x64,0x32,0x14,0x0f,0x17,0x32};
  //addr ipv6 link local node 3: fe80::1210:642d:1439:1736
  uint8_t node3[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x10,0x64,0x2d,0x14,0x39,0x17,0x36};
  
  static void _init_interface(void)
  {
      kernel_pid_t ifs[GNRC_NETIF_NUMOF];
      ipv6_addr_t addr = IPV6_ADDR_UNSPECIFIED;
      ipv6_addr_t tmp_addr= IPV6_ADDR_UNSPECIFIED;
      uint8_t hwaddr[MAX_ADDR_LEN];
      int res;
      //msg_t message;
      
      gnrc_netif_get(ifs);
  
      //addresses gobales
      addr.u8[0] = 0xba;
      addr.u8[1] = 0xad;
      addr.u8[2] = 0xa5;
      addr.u8[3] = 0x55;
  
      res = gnrc_netapi_get(ifs[0], NETOPT_ADDRESS, 0, hwaddr, sizeof(hwaddr));
  
      if (res >= 0) {
          addr.u8[14] = *hwaddr;
          addr.u8[15] = *(hwaddr+1);
      }
      memcpy(tmp_addr.u8,addr.u8,IPV6_ADDR_BIT_LEN);
    
      gnrc_ipv6_netif_add_addr(ifs[0], &addr, 64, GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST);
  
      /* model ipv6 addr: baad:a555::Hwaddr */
      if((addr.u8[14]==0x17)&&(addr.u8[15]==0x02)){  
  
  	tmp_addr.u8[14] = 0x17;
          tmp_addr.u8[15] = 0x36;
          //fibroute dest: baad:a555::1736 via fe80::1210:6432:140f:1732
          fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE);
          tmp_addr.u8[14] = 0x17;
          tmp_addr.u8[15] = 0x32;
          //fibroute dest: baad:a555::1732 via fe80::1210:6432:140f:1732
          fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE);    
  
      }else if((addr.u8[14]==0x17)&&(addr.u8[15]==0x32)){
  
  	tmp_addr.u8[14] = 0x17;
          tmp_addr.u8[15] = 0x36;
          //fibroute dest: baad:a555::1732 via fe80::1210:642d:1439:1736
          fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node3, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE);
          tmp_addr.u8[14] = 0x17;
          tmp_addr.u8[15] = 0x02;
          //fibroute dest: baad:a555::1702 via fe80::1210:642c:1432:1702
          fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node1, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE);
  
      }else if((addr.u8[14]==0x17)&&(addr.u8[15]==0x36)){
  
  	tmp_addr.u8[14] = 0x17;
          tmp_addr.u8[15] = 0x02;
          //fibroute dest: baad:a555::1702 via fe80::1210:6432:140f:1732
          fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); 
  	tmp_addr.u8[14] = 0x17;
          tmp_addr.u8[15] = 0x32;
          //fibroute dest: baad:a555::1732 via fe80::1210:6432:140f:1732
          fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE);
  
      }else{
          puts("new node?");
      }
  }
  
  static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];
  
  extern int udp_cmd(int argc, char **argv);
  
  static const shell_command_t shell_commands[] = {
      { "udp", "send data over UDP and listen on UDP ports", udp_cmd },
      { NULL, NULL, NULL }
  };
  
  int main(void)
  {
      /* we need a message queue for the thread running the shell in order to
       * receive potentially fast incoming networking packets */
      msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE);
      puts("RIOT network stack example application");
  
      /* init network interfaces */
       _init_interface();
  
      /* start shell */
      puts("All up, running the shell now");
      char line_buf[SHELL_DEFAULT_BUFSIZE];
      shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
  
      /* should be never reached */
      return 0;
  }