From 5d8349298fd8f559ee9cbc88564be5d647636e0d Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 6 Aug 2015 12:12:47 +0200 Subject: [PATCH] remove bulk of legacy network stack and drivers --- Makefile.dep | 99 +- Makefile.pseudomodules | 1 - boards/native/Makefile.dep | 6 +- boards/native/board_config.c | 8 - cpu/native/Makefile | 4 +- cpu/native/include/nativenet.h | 182 -- cpu/native/include/nativenet_internal.h | 109 - cpu/native/include/tap.h | 70 - cpu/native/native_cpu.c | 8 +- cpu/native/net/Makefile | 5 - cpu/native/net/interface.c | 618 ------ cpu/native/net/tap.c | 370 ---- cpu/native/startup.c | 11 +- drivers/Makefile | 6 - drivers/Makefile.include | 15 - drivers/at86rf231/Makefile | 1 - drivers/at86rf231/at86rf231_rx.c | 112 - drivers/at86rf231/at86rf231_spi.c | 94 - drivers/at86rf231/at86rf231_tx.c | 295 --- drivers/at86rf231/include/at86rf231_spi.h | 44 - drivers/cc110x/Makefile | 1 - drivers/cc110x/cc110x-defaultsettings.c | 133 -- drivers/cc110x/cc110x-internal.h | 207 -- drivers/cc110x/cc110x-netdev.c | 253 --- drivers/cc110x/cc110x-rxtx.c | 247 --- drivers/cc110x_legacy/Makefile | 6 - .../cc110x_legacy/cc110x-defaultSettings.c | 119 -- drivers/cc110x_legacy/cc110x-internal.h | 203 -- drivers/cc110x_legacy/cc110x-rx.c | 228 -- drivers/cc110x_legacy/cc110x-tx.c | 94 - drivers/cc110x_legacy/cc110x.c | 424 ---- drivers/cc110x_legacy/spi/Makefile | 5 - drivers/cc110x_legacy/spi/cc110x_spi.c | 113 - drivers/cc110x_legacy_csma/Makefile | 1 - drivers/cc110x_legacy_csma/arch_cc1100.h | 44 - .../cc110x_legacy_csma/cc1100-csmaca-mac.c | 236 --- .../cc110x_legacy_csma/cc1100-csmaca-mac.h | 63 - .../cc1100-defaultSettings.c | 105 - .../cc1100-defaultSettings.h | 98 - drivers/cc110x_legacy_csma/cc1100-internal.h | 208 -- drivers/cc110x_legacy_csma/cc1100.c | 935 -------- drivers/cc110x_legacy_csma/cc1100.h | 330 --- drivers/cc110x_legacy_csma/cc1100_phy.c | 880 -------- drivers/cc110x_legacy_csma/cc1100_phy.h | 143 -- drivers/cc110x_legacy_csma/cc1100_spi.c | 119 -- drivers/cc110x_legacy_csma/cc1100_spi.h | 54 - drivers/cc2420/Makefile | 1 - drivers/cc2420/cc2420.c | 298 --- drivers/cc2420/cc2420_rx.c | 102 - drivers/cc2420/cc2420_spi.c | 105 - drivers/cc2420/cc2420_tx.c | 314 --- drivers/cc2420/include/cc2420_arch.h | 132 -- drivers/cc2420/include/cc2420_settings.h | 319 --- drivers/cc2420/include/cc2420_spi.h | 100 - drivers/include/at86rf231.h | 402 ---- .../include/at86rf231/at86rf231_settings.h | 255 --- drivers/include/cc110x.h | 26 - drivers/include/cc110x/cc110x-config.h | 106 - .../include/cc110x/cc110x-defaultsettings.h | 58 - drivers/include/cc110x/cc110x-interface.h | 160 -- drivers/include/cc110x/cc110x-netdev.h | 42 - drivers/include/cc110x/cc110x-reg.h | 93 - drivers/include/cc110x_legacy.h | 27 - drivers/include/cc110x_legacy/cc110x-arch.h | 44 - drivers/include/cc110x_legacy/cc110x-config.h | 122 -- .../cc110x_legacy/cc110x-defaultSettings.h | 90 - .../include/cc110x_legacy/cc110x-interface.h | 184 -- drivers/include/cc110x_legacy/cc110x-reg.h | 100 - drivers/include/cc110x_legacy/cc110x_spi.h | 41 - drivers/include/cc110x_legacy_csma.h | 22 - .../cc110x_legacy_csma/cc1100-interface.h | 205 -- drivers/include/cc2420.h | 409 ---- drivers/include/netdev/802154.h | 431 ---- drivers/include/netdev/base.h | 408 ---- drivers/include/netdev/default.h | 65 - drivers/include/netdev/doc.txt | 16 - drivers/include/radio_driver.h | 364 ---- drivers/netdev/802154/802154.c | 119 -- drivers/netdev/802154/Makefile | 5 - drivers/netdev/base/Makefile | 5 - drivers/netdev/base/base.c | 42 - examples/ccn-lite-client/HOWTO | 55 - examples/ccn-lite-client/Makefile | 45 - examples/ccn-lite-client/README.md | 16 - examples/ccn-lite-client/main.c | 366 ---- examples/ccn-lite-relay/Makefile | 40 - examples/ccn-lite-relay/README.md | 9 - examples/ccn-lite-relay/main.c | 85 - examples/default/Makefile | 1 - examples/default/main.c | 100 - examples/rpl_udp/Makefile | 46 - examples/rpl_udp/README.md | 126 -- examples/rpl_udp/helper.c | 158 -- examples/rpl_udp/main.c | 56 - examples/rpl_udp/rpl_udp.h | 108 - examples/rpl_udp/udp.c | 159 -- sys/Makefile.include | 47 - sys/auto_init/Makefile | 8 - sys/auto_init/auto_init.c | 176 -- sys/include/radio/radio.h | 58 - sys/include/radio/types.h | 108 - sys/include/transceiver.h | 304 --- sys/net/ccn_lite/Makefile | 1 - sys/net/ccn_lite/README.md | 52 - sys/net/ccn_lite/ccn-lite-relay.c | 485 ----- sys/net/ccn_lite/ccnl-core.c | 1498 ------------- sys/net/ccn_lite/ccnl-core.h | 302 --- sys/net/ccn_lite/ccnl-ext-debug.c | 67 - sys/net/ccn_lite/ccnl-ext-frag.c | 715 ------- sys/net/ccn_lite/ccnl-ext-mgmt.c | 627 ------ sys/net/ccn_lite/ccnl-ext.h | 106 - sys/net/ccn_lite/ccnl-includes.h | 45 - sys/net/ccn_lite/ccnl-pdu.c | 231 -- sys/net/ccn_lite/ccnl-pdu.h | 36 - sys/net/ccn_lite/ccnl-platform.c | 163 -- sys/net/ccn_lite/ccnl-platform.h | 57 - sys/net/ccn_lite/ccnl-riot-compat.c | 148 -- sys/net/ccn_lite/ccnl-riot-compat.h | 42 - sys/net/ccn_lite/ccnl.h | 150 -- sys/net/ccn_lite/ccnx.h | 80 - sys/net/ccn_lite/util/Makefile | 3 - sys/net/ccn_lite/util/ccn-lite-ctrl.c | 180 -- sys/net/ccn_lite/util/ccn-lite-ctrl.h | 30 - sys/net/ccn_lite/util/ccnl-riot-client.c | 184 -- sys/net/include/ccn_lite/ccnl-riot.h | 99 - .../ccn_lite/test_data/text.txt.ccnb.h | 367 ---- .../include/ccn_lite/util/ccnl-riot-client.h | 117 -- sys/net/include/etx_beaconing.h | 121 -- sys/net/include/ieee802154_frame.h | 127 -- sys/net/include/ipv6.h | 42 - sys/net/include/l2_ping.h | 143 -- sys/net/include/net_if.h | 511 ----- sys/net/include/protocol-multiplex.h | 54 - sys/net/include/rpl.h | 307 --- sys/net/include/rpl/rpl_config.h | 179 -- sys/net/include/rpl/rpl_dodag.h | 55 - sys/net/include/rpl/rpl_of_manager.h | 46 - sys/net/include/rpl/rpl_structs.h | 231 -- sys/net/include/sixlowpan.h | 59 - sys/net/include/sixlowpan/error.h | 107 - sys/net/include/sixlowpan/icmp.h | 259 --- sys/net/include/sixlowpan/ip.h | 590 ------ sys/net/include/sixlowpan/lowpan.h | 315 --- sys/net/include/sixlowpan/mac.h | 70 - sys/net/include/sixlowpan/ndp.h | 239 --- sys/net/include/sixlowpan/types.h | 408 ---- sys/net/include/socket_base.h | 51 - sys/net/include/socket_base/in.h | 160 -- sys/net/include/socket_base/socket.h | 341 --- sys/net/include/socket_base/types.h | 84 - sys/net/include/tcp.h | 49 - sys/net/include/udp.h | 49 - sys/net/link_layer/ieee802154/Makefile | 1 - .../link_layer/ieee802154/ieee802154_frame.c | 304 --- sys/net/link_layer/net_if/Makefile | 4 - sys/net/link_layer/net_if/net_if.c | 545 ----- sys/net/link_layer/ping/Makefile | 3 - sys/net/link_layer/ping/ping.c | 279 --- .../link_layer/protocol-multiplex/Makefile | 3 - .../protocol-multiplex/protocol-multiplex.c | 132 -- sys/net/network_layer/sixlowpan/Makefile | 1 - .../network_layer/sixlowpan/border/border.c | 195 -- .../network_layer/sixlowpan/border/border.h | 49 - .../sixlowpan/border/bordermultiplex.c | 211 -- .../sixlowpan/border/bordermultiplex.h | 100 - .../sixlowpan/border/flowcontrol.c | 199 -- .../sixlowpan/border/flowcontrol.h | 85 - sys/net/network_layer/sixlowpan/icmp.c | 1871 ----------------- sys/net/network_layer/sixlowpan/icmp.h | 70 - sys/net/network_layer/sixlowpan/ip.c | 943 --------- sys/net/network_layer/sixlowpan/ip.h | 121 -- sys/net/network_layer/sixlowpan/lowpan.c | 1789 ---------------- sys/net/network_layer/sixlowpan/lowpan.h | 59 - sys/net/network_layer/sixlowpan/mac.c | 340 --- .../network_layer/sixlowpan/serialnumber.c | 101 - .../network_layer/sixlowpan/serialnumber.h | 98 - sys/net/routing/etx_beaconing.c | 566 ----- sys/net/routing/rpl/Makefile | 41 - sys/net/routing/rpl/of0.c | 93 - sys/net/routing/rpl/of0.h | 37 - sys/net/routing/rpl/of_mrhof.c | 202 -- sys/net/routing/rpl/of_mrhof.h | 69 - sys/net/routing/rpl/rpl.c | 632 ------ sys/net/routing/rpl/rpl_control_messages.c | 990 --------- sys/net/routing/rpl/rpl_dodag.c | 450 ---- sys/net/routing/rpl/rpl_of_manager.c | 60 - sys/net/transport_layer/socket_base/Makefile | 1 - .../transport_layer/socket_base/msg_help.c | 61 - .../transport_layer/socket_base/msg_help.h | 54 - sys/net/transport_layer/socket_base/socket.c | 425 ---- sys/net/transport_layer/socket_base/socket.h | 107 - sys/net/transport_layer/tcp/Makefile | 2 - sys/net/transport_layer/tcp/tcp.c | 1422 ------------- sys/net/transport_layer/tcp/tcp.h | 123 -- sys/net/transport_layer/tcp/tcp_hc.c | 637 ------ sys/net/transport_layer/tcp/tcp_hc.h | 45 - sys/net/transport_layer/tcp/tcp_timer.c | 156 -- sys/net/transport_layer/tcp/tcp_timer.h | 49 - sys/net/transport_layer/udp/Makefile | 2 - sys/net/transport_layer/udp/udp.c | 217 -- sys/net/transport_layer/udp/udp.h | 104 - sys/shell/commands/Makefile | 17 - sys/shell/commands/sc_cc110x_legacy_csma.c | 79 - sys/shell/commands/sc_l2_ping.c | 154 -- sys/shell/commands/sc_net_if.c | 676 ------ sys/shell/commands/sc_rpl.c | 62 - sys/shell/commands/sc_transceiver.c | 404 ---- sys/shell/commands/shell_commands.c | 107 - sys/transceiver/Makefile | 13 - sys/transceiver/transceiver.c | 1276 ----------- tests/nativenet/Makefile | 19 - tests/nativenet/README.md | 9 - tests/nativenet/main.c | 178 -- tests/nativenet/tests/01-tests.py | 38 - tests/net_if/Makefile | 12 - tests/net_if/main.c | 442 ---- tests/netdev/Makefile | 48 - tests/netdev/README.md | 21 - tests/netdev/main.c | 1085 ---------- tests/netdev/tests/01-interaction.py | 142 -- tests/pnet/Makefile | 11 - tests/pnet/main.c | 121 -- tests/unittests/Makefile | 6 - tests/unittests/netdev_dummy/Makefile | 1 - .../netdev_dummy/include/netdev_dummy.h | 160 -- tests/unittests/netdev_dummy/netdev_dummy.c | 699 ------ tests/unittests/tests-netdev_dummy/Makefile | 1 - .../tests-netdev_dummy/Makefile.include | 1 - .../tests-netdev_dummy/tests-netdev_dummy.c | 989 --------- .../tests-netdev_dummy/tests-netdev_dummy.h | 37 - 230 files changed, 11 insertions(+), 45817 deletions(-) delete mode 100644 cpu/native/include/nativenet.h delete mode 100644 cpu/native/include/nativenet_internal.h delete mode 100644 cpu/native/include/tap.h delete mode 100644 cpu/native/net/Makefile delete mode 100644 cpu/native/net/interface.c delete mode 100644 cpu/native/net/tap.c delete mode 100644 drivers/at86rf231/Makefile delete mode 100644 drivers/at86rf231/at86rf231_rx.c delete mode 100644 drivers/at86rf231/at86rf231_spi.c delete mode 100644 drivers/at86rf231/at86rf231_tx.c delete mode 100644 drivers/at86rf231/include/at86rf231_spi.h delete mode 100644 drivers/cc110x/Makefile delete mode 100644 drivers/cc110x/cc110x-defaultsettings.c delete mode 100644 drivers/cc110x/cc110x-internal.h delete mode 100644 drivers/cc110x/cc110x-netdev.c delete mode 100644 drivers/cc110x/cc110x-rxtx.c delete mode 100644 drivers/cc110x_legacy/Makefile delete mode 100644 drivers/cc110x_legacy/cc110x-defaultSettings.c delete mode 100644 drivers/cc110x_legacy/cc110x-internal.h delete mode 100644 drivers/cc110x_legacy/cc110x-rx.c delete mode 100644 drivers/cc110x_legacy/cc110x-tx.c delete mode 100644 drivers/cc110x_legacy/cc110x.c delete mode 100644 drivers/cc110x_legacy/spi/Makefile delete mode 100644 drivers/cc110x_legacy/spi/cc110x_spi.c delete mode 100644 drivers/cc110x_legacy_csma/Makefile delete mode 100644 drivers/cc110x_legacy_csma/arch_cc1100.h delete mode 100644 drivers/cc110x_legacy_csma/cc1100-csmaca-mac.c delete mode 100644 drivers/cc110x_legacy_csma/cc1100-csmaca-mac.h delete mode 100644 drivers/cc110x_legacy_csma/cc1100-defaultSettings.c delete mode 100644 drivers/cc110x_legacy_csma/cc1100-defaultSettings.h delete mode 100644 drivers/cc110x_legacy_csma/cc1100-internal.h delete mode 100644 drivers/cc110x_legacy_csma/cc1100.c delete mode 100644 drivers/cc110x_legacy_csma/cc1100.h delete mode 100644 drivers/cc110x_legacy_csma/cc1100_phy.c delete mode 100644 drivers/cc110x_legacy_csma/cc1100_phy.h delete mode 100644 drivers/cc110x_legacy_csma/cc1100_spi.c delete mode 100644 drivers/cc110x_legacy_csma/cc1100_spi.h delete mode 100644 drivers/cc2420/Makefile delete mode 100644 drivers/cc2420/cc2420.c delete mode 100644 drivers/cc2420/cc2420_rx.c delete mode 100644 drivers/cc2420/cc2420_spi.c delete mode 100644 drivers/cc2420/cc2420_tx.c delete mode 100644 drivers/cc2420/include/cc2420_arch.h delete mode 100644 drivers/cc2420/include/cc2420_settings.h delete mode 100644 drivers/cc2420/include/cc2420_spi.h delete mode 100644 drivers/include/at86rf231.h delete mode 100644 drivers/include/at86rf231/at86rf231_settings.h delete mode 100644 drivers/include/cc110x.h delete mode 100644 drivers/include/cc110x/cc110x-config.h delete mode 100644 drivers/include/cc110x/cc110x-defaultsettings.h delete mode 100644 drivers/include/cc110x/cc110x-interface.h delete mode 100644 drivers/include/cc110x/cc110x-netdev.h delete mode 100644 drivers/include/cc110x/cc110x-reg.h delete mode 100644 drivers/include/cc110x_legacy.h delete mode 100644 drivers/include/cc110x_legacy/cc110x-arch.h delete mode 100644 drivers/include/cc110x_legacy/cc110x-config.h delete mode 100644 drivers/include/cc110x_legacy/cc110x-defaultSettings.h delete mode 100644 drivers/include/cc110x_legacy/cc110x-interface.h delete mode 100644 drivers/include/cc110x_legacy/cc110x-reg.h delete mode 100644 drivers/include/cc110x_legacy/cc110x_spi.h delete mode 100644 drivers/include/cc110x_legacy_csma.h delete mode 100644 drivers/include/cc110x_legacy_csma/cc1100-interface.h delete mode 100644 drivers/include/cc2420.h delete mode 100644 drivers/include/netdev/802154.h delete mode 100644 drivers/include/netdev/base.h delete mode 100644 drivers/include/netdev/default.h delete mode 100644 drivers/include/netdev/doc.txt delete mode 100644 drivers/include/radio_driver.h delete mode 100644 drivers/netdev/802154/802154.c delete mode 100644 drivers/netdev/802154/Makefile delete mode 100644 drivers/netdev/base/Makefile delete mode 100644 drivers/netdev/base/base.c delete mode 100644 examples/ccn-lite-client/HOWTO delete mode 100644 examples/ccn-lite-client/Makefile delete mode 100644 examples/ccn-lite-client/README.md delete mode 100644 examples/ccn-lite-client/main.c delete mode 100644 examples/ccn-lite-relay/Makefile delete mode 100644 examples/ccn-lite-relay/README.md delete mode 100644 examples/ccn-lite-relay/main.c delete mode 100644 examples/rpl_udp/Makefile delete mode 100644 examples/rpl_udp/README.md delete mode 100644 examples/rpl_udp/helper.c delete mode 100644 examples/rpl_udp/main.c delete mode 100644 examples/rpl_udp/rpl_udp.h delete mode 100644 examples/rpl_udp/udp.c delete mode 100644 sys/include/radio/radio.h delete mode 100644 sys/include/radio/types.h delete mode 100644 sys/include/transceiver.h delete mode 100644 sys/net/ccn_lite/Makefile delete mode 100644 sys/net/ccn_lite/README.md delete mode 100644 sys/net/ccn_lite/ccn-lite-relay.c delete mode 100644 sys/net/ccn_lite/ccnl-core.c delete mode 100644 sys/net/ccn_lite/ccnl-core.h delete mode 100644 sys/net/ccn_lite/ccnl-ext-debug.c delete mode 100644 sys/net/ccn_lite/ccnl-ext-frag.c delete mode 100644 sys/net/ccn_lite/ccnl-ext-mgmt.c delete mode 100644 sys/net/ccn_lite/ccnl-ext.h delete mode 100644 sys/net/ccn_lite/ccnl-includes.h delete mode 100644 sys/net/ccn_lite/ccnl-pdu.c delete mode 100644 sys/net/ccn_lite/ccnl-pdu.h delete mode 100644 sys/net/ccn_lite/ccnl-platform.c delete mode 100644 sys/net/ccn_lite/ccnl-platform.h delete mode 100644 sys/net/ccn_lite/ccnl-riot-compat.c delete mode 100644 sys/net/ccn_lite/ccnl-riot-compat.h delete mode 100644 sys/net/ccn_lite/ccnl.h delete mode 100644 sys/net/ccn_lite/ccnx.h delete mode 100644 sys/net/ccn_lite/util/Makefile delete mode 100644 sys/net/ccn_lite/util/ccn-lite-ctrl.c delete mode 100644 sys/net/ccn_lite/util/ccn-lite-ctrl.h delete mode 100644 sys/net/ccn_lite/util/ccnl-riot-client.c delete mode 100644 sys/net/include/ccn_lite/ccnl-riot.h delete mode 100644 sys/net/include/ccn_lite/test_data/text.txt.ccnb.h delete mode 100644 sys/net/include/ccn_lite/util/ccnl-riot-client.h delete mode 100644 sys/net/include/etx_beaconing.h delete mode 100644 sys/net/include/ieee802154_frame.h delete mode 100644 sys/net/include/ipv6.h delete mode 100644 sys/net/include/l2_ping.h delete mode 100644 sys/net/include/net_if.h delete mode 100644 sys/net/include/protocol-multiplex.h delete mode 100644 sys/net/include/rpl.h delete mode 100644 sys/net/include/rpl/rpl_config.h delete mode 100644 sys/net/include/rpl/rpl_dodag.h delete mode 100644 sys/net/include/rpl/rpl_of_manager.h delete mode 100644 sys/net/include/rpl/rpl_structs.h delete mode 100644 sys/net/include/sixlowpan.h delete mode 100644 sys/net/include/sixlowpan/error.h delete mode 100644 sys/net/include/sixlowpan/icmp.h delete mode 100644 sys/net/include/sixlowpan/ip.h delete mode 100644 sys/net/include/sixlowpan/lowpan.h delete mode 100644 sys/net/include/sixlowpan/mac.h delete mode 100644 sys/net/include/sixlowpan/ndp.h delete mode 100644 sys/net/include/sixlowpan/types.h delete mode 100644 sys/net/include/socket_base.h delete mode 100644 sys/net/include/socket_base/in.h delete mode 100644 sys/net/include/socket_base/socket.h delete mode 100644 sys/net/include/socket_base/types.h delete mode 100644 sys/net/include/tcp.h delete mode 100644 sys/net/include/udp.h delete mode 100644 sys/net/link_layer/ieee802154/Makefile delete mode 100644 sys/net/link_layer/ieee802154/ieee802154_frame.c delete mode 100644 sys/net/link_layer/net_if/Makefile delete mode 100644 sys/net/link_layer/net_if/net_if.c delete mode 100644 sys/net/link_layer/ping/Makefile delete mode 100644 sys/net/link_layer/ping/ping.c delete mode 100644 sys/net/link_layer/protocol-multiplex/Makefile delete mode 100644 sys/net/link_layer/protocol-multiplex/protocol-multiplex.c delete mode 100644 sys/net/network_layer/sixlowpan/Makefile delete mode 100644 sys/net/network_layer/sixlowpan/border/border.c delete mode 100644 sys/net/network_layer/sixlowpan/border/border.h delete mode 100644 sys/net/network_layer/sixlowpan/border/bordermultiplex.c delete mode 100644 sys/net/network_layer/sixlowpan/border/bordermultiplex.h delete mode 100644 sys/net/network_layer/sixlowpan/border/flowcontrol.c delete mode 100644 sys/net/network_layer/sixlowpan/border/flowcontrol.h delete mode 100644 sys/net/network_layer/sixlowpan/icmp.c delete mode 100644 sys/net/network_layer/sixlowpan/icmp.h delete mode 100644 sys/net/network_layer/sixlowpan/ip.c delete mode 100644 sys/net/network_layer/sixlowpan/ip.h delete mode 100644 sys/net/network_layer/sixlowpan/lowpan.c delete mode 100644 sys/net/network_layer/sixlowpan/lowpan.h delete mode 100644 sys/net/network_layer/sixlowpan/mac.c delete mode 100644 sys/net/network_layer/sixlowpan/serialnumber.c delete mode 100644 sys/net/network_layer/sixlowpan/serialnumber.h delete mode 100644 sys/net/routing/etx_beaconing.c delete mode 100644 sys/net/routing/rpl/Makefile delete mode 100644 sys/net/routing/rpl/of0.c delete mode 100644 sys/net/routing/rpl/of0.h delete mode 100644 sys/net/routing/rpl/of_mrhof.c delete mode 100644 sys/net/routing/rpl/of_mrhof.h delete mode 100644 sys/net/routing/rpl/rpl.c delete mode 100644 sys/net/routing/rpl/rpl_control_messages.c delete mode 100644 sys/net/routing/rpl/rpl_dodag.c delete mode 100644 sys/net/routing/rpl/rpl_of_manager.c delete mode 100644 sys/net/transport_layer/socket_base/Makefile delete mode 100644 sys/net/transport_layer/socket_base/msg_help.c delete mode 100644 sys/net/transport_layer/socket_base/msg_help.h delete mode 100644 sys/net/transport_layer/socket_base/socket.c delete mode 100644 sys/net/transport_layer/socket_base/socket.h delete mode 100644 sys/net/transport_layer/tcp/Makefile delete mode 100644 sys/net/transport_layer/tcp/tcp.c delete mode 100644 sys/net/transport_layer/tcp/tcp.h delete mode 100644 sys/net/transport_layer/tcp/tcp_hc.c delete mode 100644 sys/net/transport_layer/tcp/tcp_hc.h delete mode 100644 sys/net/transport_layer/tcp/tcp_timer.c delete mode 100644 sys/net/transport_layer/tcp/tcp_timer.h delete mode 100644 sys/net/transport_layer/udp/Makefile delete mode 100644 sys/net/transport_layer/udp/udp.c delete mode 100644 sys/net/transport_layer/udp/udp.h delete mode 100644 sys/shell/commands/sc_cc110x_legacy_csma.c delete mode 100644 sys/shell/commands/sc_l2_ping.c delete mode 100644 sys/shell/commands/sc_net_if.c delete mode 100644 sys/shell/commands/sc_rpl.c delete mode 100644 sys/shell/commands/sc_transceiver.c delete mode 100644 sys/transceiver/Makefile delete mode 100644 sys/transceiver/transceiver.c delete mode 100644 tests/nativenet/Makefile delete mode 100644 tests/nativenet/README.md delete mode 100644 tests/nativenet/main.c delete mode 100755 tests/nativenet/tests/01-tests.py delete mode 100644 tests/net_if/Makefile delete mode 100644 tests/net_if/main.c delete mode 100644 tests/netdev/Makefile delete mode 100644 tests/netdev/README.md delete mode 100644 tests/netdev/main.c delete mode 100755 tests/netdev/tests/01-interaction.py delete mode 100644 tests/pnet/Makefile delete mode 100644 tests/pnet/main.c delete mode 100644 tests/unittests/netdev_dummy/Makefile delete mode 100644 tests/unittests/netdev_dummy/include/netdev_dummy.h delete mode 100644 tests/unittests/netdev_dummy/netdev_dummy.c delete mode 100644 tests/unittests/tests-netdev_dummy/Makefile delete mode 100644 tests/unittests/tests-netdev_dummy/Makefile.include delete mode 100644 tests/unittests/tests-netdev_dummy/tests-netdev_dummy.c delete mode 100644 tests/unittests/tests-netdev_dummy/tests-netdev_dummy.h diff --git a/Makefile.dep b/Makefile.dep index 2c12c27b7d..fe21dc940b 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -1,53 +1,3 @@ -ifneq (,$(filter libcoap,$(USEPKG))) - USEMODULE += pnet -endif - -ifneq (,$(filter pnet,$(USEMODULE))) - USEMODULE += posix - USEMODULE += socket_base - USEMODULE += net_help -endif - -ifneq (,$(filter transport_layer,$(USEMODULE))) - USEMODULE += tcp - USEMODULE += udp -endif - -ifneq (,$(filter udp,$(USEMODULE))) - USEMODULE += socket_base -endif - -ifneq (,$(filter tcp,$(USEMODULE))) - USEMODULE += socket_base -endif - -ifneq (,$(filter socket_base,$(USEMODULE))) - USEMODULE += sixlowpan - USEMODULE += net_help - USEMODULE += vtimer -endif - -ifneq (,$(filter sixlowborder,$(USEMODULE))) - USEMODULE += sixlowpan -endif - -ifneq (,$(filter rpl,$(USEMODULE))) - USEMODULE += trickle - USEMODULE += routing -endif - -ifneq (,$(filter routing,$(USEMODULE))) - USEMODULE += sixlowpan -endif - -ifneq (,$(filter sixlowpan,$(USEMODULE))) - USEMODULE += ieee802154 - USEMODULE += net_help - USEMODULE += net_if - USEMODULE += posix - USEMODULE += vtimer -endif - ifneq (,$(filter ng_netif_default,$(USEMODULE))) USEMODULE += ng_netif endif @@ -232,14 +182,6 @@ ifneq (,$(filter ng_slip,$(USEMODULE))) USEMODULE += ng_netbase endif -ifneq (,$(filter aodvv2,$(USEMODULE))) - USEMODULE += vtimer - USEMODULE += sixlowpan - USEMODULE += oonf_common - USEMODULE += oonf_rfc5444 - USEMODULE += fib -endif - ifneq (,$(filter uart0,$(USEMODULE))) USEMODULE += posix endif @@ -253,29 +195,6 @@ ifneq (,$(filter cbor,$(USEMODULE))) USEMODULE += net_help endif -ifneq (,$(filter cc110x%,$(USEMODULE))) - USEMODULE += protocol_multiplex - USEMODULE += vtimer -endif - -ifneq (,$(filter cc110x,$(USEMODULE))) - USEMODULE += transceiver -endif - -ifneq (,$(filter cc110x_legacy,$(USEMODULE))) - USEMODULE += transceiver -endif - -ifneq (,$(filter cc2420,$(USEMODULE))) - USEMODULE += transceiver - USEMODULE += ieee802154 -endif - -ifneq (,$(filter at86rf231,$(USEMODULE))) - USEMODULE += netdev_802154 - USEMODULE += ieee802154 -endif - ifneq (,$(filter l2_ping,$(USEMODULE))) USEMODULE += vtimer endif @@ -284,20 +203,10 @@ ifneq (,$(filter vtimer,$(USEMODULE))) USEMODULE += timex endif -ifneq (,$(filter net_if,$(USEMODULE))) - USEMODULE += transceiver - USEMODULE += net_help - USEMODULE += hashes -endif - ifneq (,$(filter ccn_lite,$(USEMODULE))) USEMODULE += crypto endif -ifneq (,$(filter netdev_802154,$(USEMODULE))) - USEMODULE += netdev_base -endif - ifneq (,$(filter rgbled,$(USEMODULE))) USEMODULE += color endif @@ -306,10 +215,6 @@ ifneq (,$(filter libfixmath-unittests,$(USEMODULE))) USEPKG += libfixmath endif -ifneq (,$(filter defaulttransceiver,$(USEMODULE))) - FEATURES_REQUIRED += transceiver -endif - ifneq (,$(filter nhdp,$(USEMODULE))) USEMODULE += vtimer USEMODULE += oonf_common @@ -343,6 +248,10 @@ ifneq (,$(filter newlib,$(USEMODULE))) USEMODULE += uart_stdio endif +ifneq (,$(filter ng_netdev_eth,$(USEMODULE))) + USEMODULE += ng_pktbuf +endif + ifneq (,$(filter hih6130,$(USEMODULE))) USEMODULE += vtimer endif diff --git a/Makefile.pseudomodules b/Makefile.pseudomodules index 2b1d2700fb..58f271b603 100644 --- a/Makefile.pseudomodules +++ b/Makefile.pseudomodules @@ -1,5 +1,4 @@ PSEUDOMODULES += defaulttransceiver -PSEUDOMODULES += transport_layer PSEUDOMODULES += ng_netif_default PSEUDOMODULES += ng_ieee802154 PSEUDOMODULES += ng_ipv6_default diff --git a/boards/native/Makefile.dep b/boards/native/Makefile.dep index c0d7dd651f..bba8440a32 100644 --- a/boards/native/Makefile.dep +++ b/boards/native/Makefile.dep @@ -1,8 +1,6 @@ ifneq (,$(filter defaulttransceiver,$(USEMODULE))) - USEMODULE += nativenet - ifeq (,$(filter netdev_base,$(USEMODULE))) - USEMODULE += transceiver - endif + USEMODULE += ng_nativenet + USEMODULE += ng_netdev_eth endif ifneq (,$(filter ng_netif_default,$(USEMODULE))) diff --git a/boards/native/board_config.c b/boards/native/board_config.c index 1444728f33..176a300bc7 100644 --- a/boards/native/board_config.c +++ b/boards/native/board_config.c @@ -22,10 +22,6 @@ #include "config.h" -#ifdef MODULE_NATIVENET -#include "nativenet.h" -#include "nativenet_internal.h" -#endif #include "native_internal.h" #define ENABLE_DEBUG (0) @@ -40,10 +36,6 @@ void config_load(void) sysconfig.id = _native_id; -#ifdef MODULE_NATIVENET - _nativenet_default_dev_more._radio_addr = _native_id; -#endif - return; } diff --git a/cpu/native/Makefile b/cpu/native/Makefile index 4b5daca45a..cc430d5cee 100644 --- a/cpu/native/Makefile +++ b/cpu/native/Makefile @@ -1,9 +1,7 @@ MODULE = cpu DIRS += periph -ifneq (,$(filter nativenet,$(USEMODULE))) - DIRS += net -endif + ifneq (,$(filter ng_nativenet,$(USEMODULE))) DIRS += ng_net endif diff --git a/cpu/native/include/nativenet.h b/cpu/native/include/nativenet.h deleted file mode 100644 index b1e93cbb45..0000000000 --- a/cpu/native/include/nativenet.h +++ /dev/null @@ -1,182 +0,0 @@ -/* - * nativenet transceiver interface - * - * A configurable transceiver for the native port. - * - * At the moment only the tap interface is supported, but more network - * layers are intended. So the "configurable" part is a lie for now ;-) - * The effect of calls like nativenet_set_channel depend on the - * network layer. - * - * Copyright (C) 2013, 2014 Ludwig Ortmann - * - * 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. - */ - -/** - * @defgroup native_net Native network interface - * @ingroup native_cpu - * @{ - * @author Ludwig Ortmann - */ - -#ifndef NATIVENET_H -#define NATIVENET_H - -#if defined(__FreeBSD__) -#include -#endif - -#include - -#include "radio/types.h" -#include "kernel_types.h" -#include "netdev/base.h" - -#ifndef RX_BUF_SIZE -#define RX_BUF_SIZE (10) -#endif -#ifndef TRANSCEIVER_BUFFER_SIZE -#define TRANSCEIVER_BUFFER_SIZE (10) -#endif - -/** - * @brief Number of registrable netdev_rcv_data_cb_t callbacks per nativenet - * device - */ -#define NATIVENET_DEV_CB_MAX (128) - -/** - * @brief Broadcast address - */ -#define NATIVE_BROADCAST_ADDRESS (0) - -#ifndef NATIVE_MAX_DATA_LENGTH -#include "tap.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef MODULE_SIXLOWPAN -#define NATIVE_MAX_DATA_LENGTH (127) -#else -#define NATIVE_MAX_DATA_LENGTH (TAP_MAX_DATA) -#endif -#else -#warning be careful not to exceed (TAP_MAX_DATA) with NATIVE_MAX_DATA_LENGTH -#endif /* NATIVE_MAX_DATA_LENGTH */ - -/** - * @brief Implementation of netdev_driver_t for nativenet - */ -extern const netdev_driver_t nativenet_driver; - -/** - * @brief Default @ref netdev API device - */ -extern netdev_t nativenet_default_dev; - -/** - * Initialize @ref sys_transceiver and @ref nativenet_default_dev - * - * @param transceiver_pid the pid of the transceiver thread - */ -void nativenet_init(kernel_pid_t transceiver_pid); - -/** - * Shutdown transceiver - */ -void nativenet_powerdown(void); - -/** - * Enable/disable monitor mode - * - * @param mode 0 off, 1 on - */ -void nativenet_set_monitor(uint8_t mode); - -/** - * Send a packet - * - * @param packet a radio packet - * @return -1 if the operation failed, the number of transmitted bytes - * up to INT8_MAX otherwise - */ -int8_t nativenet_send(radio_packet_t *packet); - -/** - * Set transceiver address - * - * @param address the address - * @return the address - */ -radio_address_t nativenet_set_address(radio_address_t address); - -/** - * Get transceiver address - * - * @return the address - */ -radio_address_t nativenet_get_address(void); - -/** - * @brief Sets the IEEE long address of the nativenet transceiver. - * - * @param[in] addr The desired address. - * - * @return The set address after calling. - */ -uint64_t nativenet_set_address_long(uint64_t addr); - -/** - * @brief Gets the current IEEE long address of the nativenet - * transceiver. - * - * @return The current IEEE long address. - */ -uint64_t nativenet_get_address_long(void); - -/** - * Set transceiver channel - * - * @param channel the channel - * @return the channel - */ -int16_t nativenet_set_channel(uint8_t channel); - -/** - * Get transceiver channel - * - * @return the channel - */ -int16_t nativenet_get_channel(void); - -/** - * Set transceiver pan - * - * @param pan the pan - * @return the pan - */ -uint16_t nativenet_set_pan(uint16_t pan); - -/** - * Get transceiver pan - * - * @return the pan - */ -uint16_t nativenet_get_pan(void); - -/** - * Enable transceiver rx mode - */ -void nativenet_switch_to_rx(void); - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif /* NATIVENET_H */ diff --git a/cpu/native/include/nativenet_internal.h b/cpu/native/include/nativenet_internal.h deleted file mode 100644 index 04a072d5cb..0000000000 --- a/cpu/native/include/nativenet_internal.h +++ /dev/null @@ -1,109 +0,0 @@ -/** - * internal nativenet transceiver interface - * - * Copyright (C) 2013 Ludwig Ortmann - * - * 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. - */ - -/** - * @{ - * @author Ludwig Ortmann - * @} - */ - -#ifndef NATIVENET_INTERNAL_H -#define NATIVENET_INTERNAL_H - -#include "tap.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define NNEV_PWRDWN 0x01 -#define NNEV_PWRUP 0x02 -#define NNEV_MONITOR 0x03 -#define NNEV_GETCHAN 0x04 -#define NNEV_SETCHAN 0x05 -#define NNEV_GETADDR 0x06 -#define NNEV_SETADDR 0x07 -#define NNEV_GETPAN 0x08 -#define NNEV_SETPAN 0x09 -#define NNEV_SEND 0x0a -#define NNEV_SWTRX 0x0b -#define NNEV_MAXEV 0x0b - -#define _NATIVENET_DEV_MORE(dev) ((_nativenet_netdev_more_t *)dev->more) - -struct rx_buffer_s { - radio_packet_t packet; - char data[NATIVE_MAX_DATA_LENGTH]; -}; - -extern struct rx_buffer_s _nativenet_rx_buffer[RX_BUF_SIZE]; - -/** - * @brief Definition of network device data. - */ -typedef struct { - /** - * @brief The channel assigned to this device - * - * @note For internal use only, do not change externally! - * - * @internal - */ - uint8_t _channel; - - /** - * @brief The PAN ID assigned to this device - * - * @note For internal use only, do not change externally! - * @internal - */ - uint16_t _pan_id; - - /** - * @brief The short address assigned to this device - * - * @note For internal use only, do not change externally! - * @internal - */ - radio_address_t _radio_addr; - - /** - * @brief The long address assigned to this device - * - * @note For internal use only, do not change externally! - * @internal - */ - uint64_t _long_addr; - - /** - * @brief Flag to determine if device is in promiscuous mode - * - * @note For internal use only, do not change externally! - * @internal - */ - uint8_t _is_monitoring; - - /** - * @brief Receive data callbacks for this device - */ - netdev_rcv_data_cb_t _callbacks[NATIVENET_DEV_CB_MAX]; -} _nativenet_netdev_more_t; - -/* internal counterpart to nativenet_default_dev */ -extern _nativenet_netdev_more_t _nativenet_default_dev_more; - -void _nativenet_handle_packet(radio_packet_t *packet); -int8_t send_buf(radio_packet_t *packet); - -#ifdef __cplusplus -} -#endif - -#endif /* NATIVENET_INTERNAL_H */ diff --git a/cpu/native/include/tap.h b/cpu/native/include/tap.h deleted file mode 100644 index 105f8f7c8b..0000000000 --- a/cpu/native/include/tap.h +++ /dev/null @@ -1,70 +0,0 @@ -/** - * internal nativenet tap network layer interface - * - * Copyright (C) 2013 Ludwig Ortmann - * - * 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. - */ - -/** - * @{ - * @author Ludwig Ortmann - * @} - */ -#ifndef _TAP_H -#define _TAP_H - -#include - -#include "board.h" -#include "radio/types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * create and/or open tap device "name" - * - * if "name" is an empty string, the kernel chooses a name - * if "name" is an existing device, that device is used - * otherwise a device named "name" is created - * - * On OSX a name has to be provided. - */ -int tap_init(char *name); - -/** - * Close tap device - */ -void tap_cleanup(void); - -extern unsigned char _native_tap_mac[ETHER_ADDR_LEN]; - -struct nativenet_header { - radio_packet_length_t length; - radio_address_t dst; - radio_address_t src; -} __attribute__((packed)); -#define TAP_MAX_DATA ((ETHERMTU) - 6) /* XXX: this is suboptimal */ - -struct nativenet_packet { - struct nativenet_header nn_header; - uint8_t data[ETHERMTU - sizeof(struct nativenet_header)]; -} __attribute__((packed)); - -union eth_frame { - struct { - struct ether_header header; - struct nativenet_packet payload; - } field; - unsigned char buffer[ETHER_MAX_LEN]; -} __attribute__((packed)); - -#ifdef __cplusplus -} -#endif - -#endif /* _TAP_H */ diff --git a/cpu/native/native_cpu.c b/cpu/native/native_cpu.c index f0bb54bc53..b637932460 100644 --- a/cpu/native/native_cpu.c +++ b/cpu/native/native_cpu.c @@ -48,9 +48,7 @@ #include "cpu.h" #include "cpu_conf.h" -#ifdef MODULE_NATIVENET -#include "tap.h" -#endif + #ifdef MODULE_NG_NATIVENET #include "dev_eth_tap.h" extern dev_eth_tap_t dev_eth_tap; @@ -76,9 +74,7 @@ int reboot_arch(int mode) #ifdef MODULE_UART0 /* TODO: close stdio fds */ #endif -#ifdef MODULE_NATIVENET - tap_cleanup(); -#endif + #ifdef MODULE_NG_NATIVENET dev_eth_tap_cleanup(&dev_eth_tap); #endif diff --git a/cpu/native/net/Makefile b/cpu/native/net/Makefile deleted file mode 100644 index f4740d816d..0000000000 --- a/cpu/native/net/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -MODULE = nativenet - -include $(RIOTBASE)/Makefile.base - -INCLUDES = $(NATIVEINCLUDES) diff --git a/cpu/native/net/interface.c b/cpu/native/net/interface.c deleted file mode 100644 index 1ca8706c6a..0000000000 --- a/cpu/native/net/interface.c +++ /dev/null @@ -1,618 +0,0 @@ -/** - * nativenet.h implementation - * - * Copyright (C) 2013 Ludwig Ortmann - * - * 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 native_cpu - * @ingroup net - * @{ - * @file - * @author Ludwig Ortmann - */ - -#include -#include -#include -#include -#include -#include -#include - -#include - -#define ENABLE_DEBUG (0) -#include "debug.h" -#include "transceiver.h" -#include "msg.h" - -#include "native_internal.h" -#include "tap.h" -#include "nativenet.h" -#include "nativenet_internal.h" -#include "cpu.h" - -static _native_callback_t _nativenet_callbacks[255]; - -struct rx_buffer_s _nativenet_rx_buffer[RX_BUF_SIZE]; -static volatile uint8_t rx_buffer_next; - -static kernel_pid_t _native_net_tpid = KERNEL_PID_UNDEF; - -/************************************************************************/ -/* nativenet.h **********************************************************/ -/************************************************************************/ - -int _nativenet_init(netdev_t *dev) -{ - if ((dev->type != NETDEV_TYPE_BASE) || (dev->more == NULL)) { - return -ENODEV; - } - - _NATIVENET_DEV_MORE(dev)->_channel = 0; - _NATIVENET_DEV_MORE(dev)->_pan_id = 0; - _NATIVENET_DEV_MORE(dev)->_is_monitoring = 0; - memset(_NATIVENET_DEV_MORE(dev)->_callbacks, 0, - sizeof((_NATIVENET_DEV_MORE(dev)->_callbacks))); - - return 0; -} - -void nativenet_init(kernel_pid_t transceiver_pid) -{ - DEBUG("nativenet_init(transceiver_pid=%" PRIkernel_pid ")\n", transceiver_pid); - rx_buffer_next = 0; - _nativenet_init((netdev_t *)(&nativenet_default_dev)); - _native_net_tpid = transceiver_pid; -} - -void nativenet_powerdown(void) -{ - return; -} - -void nativenet_set_monitor(uint8_t mode) -{ - DEBUG("nativenet_set_monitor(mode=%d)\n", mode); - _nativenet_default_dev_more._is_monitoring = mode; -} - -int16_t nativenet_set_channel(uint8_t channel) -{ - _nativenet_default_dev_more._channel = channel; - return _nativenet_default_dev_more._channel; -} - -int16_t nativenet_get_channel(void) -{ - return _nativenet_default_dev_more._channel; -} - -uint16_t nativenet_set_pan(uint16_t pan) -{ - _nativenet_default_dev_more._pan_id = pan; - return _nativenet_default_dev_more._pan_id; -} - -uint16_t nativenet_get_pan(void) -{ - return _nativenet_default_dev_more._pan_id; -} - -radio_address_t nativenet_set_address(radio_address_t address) -{ - DEBUG("nativenet_set_address(address=%d)\n", address); - _nativenet_default_dev_more._radio_addr = address; - return _nativenet_default_dev_more._radio_addr; -} - -radio_address_t nativenet_get_address(void) -{ - DEBUG("nativenet_get_address -> address = %d\n", - _nativenet_default_dev_more._radio_addr); - return _nativenet_default_dev_more._radio_addr; -} - -uint64_t nativenet_get_address_long(void) -{ - DEBUG("nativenet_get_address_long -> address = %" PRIx64 "\n", - _nativenet_default_dev_more._long_addr); - return _nativenet_default_dev_more._long_addr; -} - -uint64_t nativenet_set_address_long(uint64_t address) -{ - DEBUG("nativenet_set_address_long(address=%" PRIx64 ")\n", address); - warnx("nativenet_set_address_long: this does not actually change the interfaces address"); - _nativenet_default_dev_more._long_addr = address; - return _nativenet_default_dev_more._long_addr; -} - -int8_t nativenet_send(radio_packet_t *packet) -{ - packet->src = _nativenet_default_dev_more._radio_addr; - DEBUG("nativenet_send: Sending packet of length %" PRIu16 " from %" PRIu16 " to %" PRIu16 "\n", - packet->length, packet->src, packet->dst); - - return send_buf(packet); -} - -void nativenet_switch_to_rx(void) -{ - return; -} - -/************************************************************************/ -/* nativenet_internal.h *************************************************/ -/************************************************************************/ - -int _nativenet_register_cb(int event, _native_callback_t func) -{ - if (event > NNEV_MAXEV) { - DEBUG("_nativenet_register_cb: event > NNEV_MAXEV\n"); - return -1; - } - - _nativenet_callbacks[event] = func; - return 0; -} - -int _nativenet_unregister_cb(int event) -{ - if (event > NNEV_MAXEV) { - DEBUG("_nativenet_unregister_cb: event > NNEV_MAXEV\n"); - return -1; - } - - _nativenet_callbacks[event] = NULL; - return 0; -} - -void do_cb(int event) -{ - if (event > NNEV_MAXEV) { - DEBUG("do_cb: event > NNEV_MAXEV\n"); - return; - } - - if (_nativenet_callbacks[event] != NULL) { - _nativenet_callbacks[event](); - } -} - -void _nativenet_handle_packet(radio_packet_t *packet) -{ - radio_address_t dst_addr = packet->dst; - int notified = 0; - - /* TODO: find way to demultiplex reception from several taps and map them - * to devices. */ - netdev_t *dev = &nativenet_default_dev; - - /* address filter / monitor mode */ - if (_nativenet_default_dev_more._is_monitoring == 1) { - DEBUG("_nativenet_handle_packet: monitoring, not filtering address \n"); - } - else { - /* own addr check */ - if (dst_addr == _nativenet_default_dev_more._radio_addr) { - DEBUG("_nativenet_handle_packet: accept packet, addressed to us\n"); - } - else if (dst_addr == NATIVE_BROADCAST_ADDRESS) { - DEBUG("_nativenet_handle_packet: accept packet, broadcast\n"); - } - else { - DEBUG("_nativenet_handle_packet: discard packet addressed to someone else\n"); - return; - } - } - - /* copy packet to rx buffer */ - DEBUG("\n\t\trx_buffer_next: %i\n\n", rx_buffer_next); - memcpy(&_nativenet_rx_buffer[rx_buffer_next].data, packet->data, packet->length); - memcpy(&_nativenet_rx_buffer[rx_buffer_next].packet, packet, sizeof(radio_packet_t)); - _nativenet_rx_buffer[rx_buffer_next].packet.data = (uint8_t *) - &_nativenet_rx_buffer[rx_buffer_next].data; - - /* notify transceiver thread if any */ - if (_native_net_tpid != KERNEL_PID_UNDEF) { - DEBUG("_nativenet_handle_packet: notifying transceiver thread!\n"); - msg_t m; - m.type = (uint16_t) RCV_PKT_NATIVE; - m.content.value = rx_buffer_next; - msg_send_int(&m, _native_net_tpid); - notified = 1; - } - - for (int i = 0; i < NATIVENET_DEV_CB_MAX; i++) { - if (_NATIVENET_DEV_MORE(dev)->_callbacks[i]) { - _NATIVENET_DEV_MORE(dev)->_callbacks[i]((netdev_t *)dev, - &(_nativenet_rx_buffer[rx_buffer_next].packet.src), - sizeof(uint16_t), - &(_nativenet_rx_buffer[rx_buffer_next].packet.dst), - sizeof(uint16_t), - &(_nativenet_rx_buffer[rx_buffer_next].data), - (size_t)_nativenet_rx_buffer[rx_buffer_next].packet.length); - notified = 1; - } - } - - if (!notified) { - DEBUG("_nativenet_handle_packet: no one to notify =(\n"); - } - - /* shift to next buffer element */ - if (++rx_buffer_next == RX_BUF_SIZE) { - rx_buffer_next = 0; - } -} - -/*************************************************************** - * netdev_base wrapper - ***************************************************************/ - -#ifdef MODULE_NETDEV_BASE -int _nativenet_send_data(netdev_t *dev, void *dest, size_t dest_len, - netdev_hlist_t *upper_layer_hdrs, void *data, - size_t data_len) -{ - netdev_hlist_t *ptr = upper_layer_hdrs; - uint8_t tx_buffer[data_len + netdev_get_hlist_len(upper_layer_hdrs)]; - size_t tx_ptr = 0; - radio_packet_t pkt = {0, 0, 0, 0, 0, {0, 0}, sizeof(tx_buffer), tx_buffer}; - - if (dev->type != NETDEV_TYPE_BASE) { - return -ENODEV; - } - - if (dest_len > sizeof(uint16_t)) { - return -EAFNOSUPPORT; - } - - if (sizeof(tx_buffer) > NATIVE_MAX_DATA_LENGTH) { - return -EMSGSIZE; - } - - if (upper_layer_hdrs) { - do { - memcpy(&(tx_buffer[tx_ptr]), ptr->header, ptr->header_len); - tx_ptr += ptr->header_len; - netdev_hlist_advance(&ptr); - } while (ptr != upper_layer_hdrs); - } - - memcpy(&(tx_buffer[tx_ptr]), data, data_len); - - if (dest_len == sizeof(uint16_t)) { - pkt.dst = *((uint16_t *)dest); - } - else { - pkt.dst = (uint16_t)(*((uint8_t *)dest)); - } - - return nativenet_send(&pkt); -} - -int _nativenet_add_rcv_data_cb(netdev_t *dev, netdev_rcv_data_cb_t cb) -{ - int i = 0; - - if (dev->type != NETDEV_TYPE_BASE) { - return -ENODEV; - } - - for (i = 0; i < NATIVENET_DEV_CB_MAX; i++) { - if (_NATIVENET_DEV_MORE(dev)->_callbacks[i] == NULL || - _NATIVENET_DEV_MORE(dev)->_callbacks[i] == cb) { - break; - } - } - - if (i >= NATIVENET_DEV_CB_MAX) { - return -ENOBUFS; - } - - _NATIVENET_DEV_MORE(dev)->_callbacks[i] = cb; - - return 0; -} - -int _nativenet_rem_rcv_data_cb(netdev_t *dev, netdev_rcv_data_cb_t cb) -{ - int i = 0; - - if (dev->type != NETDEV_TYPE_BASE) { - return -ENODEV; - } - - for (i = 0; i < NATIVENET_DEV_CB_MAX; i++) { - if (_NATIVENET_DEV_MORE(dev)->_callbacks[i] == cb) { - _NATIVENET_DEV_MORE(dev)->_callbacks[i] = NULL; - } - } - - return 0; -} - -int _nativenet_get_option(netdev_t *dev, netdev_opt_t opt, void *value, - size_t *value_len) -{ - if (dev->type != NETDEV_TYPE_BASE) { - return -ENODEV; - } - - switch (opt) { - case NETDEV_OPT_CHANNEL: - if (*value_len == 0) { - return -EOVERFLOW; - } - - if (*value_len > sizeof(uint8_t)) { - *value_len = sizeof(uint8_t); - } - - *((uint8_t *)value) = _NATIVENET_DEV_MORE(dev)->_channel; - break; - - case NETDEV_OPT_ADDRESS: - if (*value_len < sizeof(radio_address_t)) { - return -EOVERFLOW; - } - - if (*value_len > sizeof(radio_address_t)) { - *value_len = sizeof(radio_address_t); - } - - *((radio_address_t *)value) = _NATIVENET_DEV_MORE(dev)->_radio_addr; - break; - - case NETDEV_OPT_NID: - if (*value_len < sizeof(uint16_t)) { - return -EOVERFLOW; - } - - if (*value_len > sizeof(uint16_t)) { - *value_len = sizeof(uint16_t); - } - - *((uint16_t *)value) = _NATIVENET_DEV_MORE(dev)->_pan_id; - break; - - case NETDEV_OPT_ADDRESS_LONG: - if (*value_len < sizeof(uint64_t)) { - return -EOVERFLOW; - } - - if (*value_len > sizeof(uint64_t)) { - *value_len = sizeof(uint64_t); - } - - *((uint64_t *)value) = _NATIVENET_DEV_MORE(dev)->_long_addr; - break; - - case NETDEV_OPT_MAX_PACKET_SIZE: - if (*value_len < sizeof(NATIVE_MAX_DATA_LENGTH)) { - return -EOVERFLOW; - } - - if (*value_len > sizeof(NATIVE_MAX_DATA_LENGTH)) { - *value_len = sizeof(NATIVE_MAX_DATA_LENGTH); - } - - *((netdev_proto_t *)value) = NATIVE_MAX_DATA_LENGTH; - break; - - case NETDEV_OPT_PROTO: - if (*value_len < sizeof(netdev_proto_t)) { - return -EOVERFLOW; - } - - if (*value_len > sizeof(netdev_proto_t)) { - *value_len = sizeof(netdev_proto_t); - } - - *((netdev_proto_t *)value) = NETDEV_PROTO_RADIO; - break; - - default: - return -ENOTSUP; - } - - return 0; -} - -static int _type_pun_up(void *value_out, size_t desired_len, - void *value_in, size_t given_len) -{ - if (given_len > desired_len) { - return -EOVERFLOW; - } - - /* XXX this is ugly, but bear with me */ - switch (given_len) { - case 8: - switch (desired_len) { - case 8: - *((uint64_t *)value_out) = (*((uint64_t *)value_in)); - return 0; - - default: - return -EINVAL; - } - - case 4: - switch (desired_len) { - case 8: - *((uint64_t *)value_out) = (uint64_t)(*((uint32_t *)value_in)); - return 0; - - case 4: - *((uint32_t *)value_out) = (*((uint32_t *)value_in)); - return 0; - - default: - return -EINVAL; - } - - case 2: - switch (desired_len) { - case 8: - *((uint64_t *)value_out) = (uint64_t)(*((uint16_t *)value_in)); - return 0; - - case 4: - *((uint32_t *)value_out) = (uint32_t)(*((uint16_t *)value_in)); - return 0; - - case 2: - *((uint16_t *)value_out) = (*((uint16_t *)value_in)); - return 0; - - default: - return -EINVAL; - } - - case 1: - switch (desired_len) { - case 8: - *((uint64_t *)value_out) = (uint64_t)(*((uint8_t *)value_in)); - return 0; - - case 4: - *((uint32_t *)value_out) = (uint32_t)(*((uint8_t *)value_in)); - return 0; - - case 2: - *((uint16_t *)value_out) = (uint16_t)(*((uint8_t *)value_in)); - return 0; - - case 1: - *((uint8_t *)value_out) = (*((uint8_t *)value_in)); - return 0; - - default: - return -EINVAL; - } - - default: - return -EINVAL; - } -} - -int _nativenet_set_option(netdev_t *dev, netdev_opt_t opt, void *value, - size_t value_len) -{ - uint8_t set_value[sizeof(uint64_t)]; - int res = 0; - - if (dev->type != NETDEV_TYPE_BASE) { - return -ENODEV; - } - - switch (opt) { - case NETDEV_OPT_CHANNEL: - if ((res = _type_pun_up(set_value, sizeof(uint8_t), - value, value_len)) == 0) { - _NATIVENET_DEV_MORE(dev)->_channel = *((uint8_t *)set_value); - } - - break; - - case NETDEV_OPT_ADDRESS: - if ((res = _type_pun_up(set_value, sizeof(radio_address_t), - value, value_len)) == 0) { - _NATIVENET_DEV_MORE(dev)->_radio_addr = *((radio_address_t *)set_value); - } - - break; - - case NETDEV_OPT_NID: - if ((res = _type_pun_up(set_value, sizeof(uint16_t), - value, value_len)) == 0) { - _NATIVENET_DEV_MORE(dev)->_pan_id = *((uint16_t *)set_value); - } - - break; - - case NETDEV_OPT_PROTO: - /* TODO: wouldn't this be awesome */ - return -ENOTSUP; - - default: - return -ENOTSUP; - } - - return res; -} - -int _nativenet_get_state(netdev_t *dev, netdev_state_t *state) -{ - if (dev->type != NETDEV_TYPE_BASE) { - return -ENODEV; - } - - if (_NATIVENET_DEV_MORE(dev)->_is_monitoring) { - *state = NETDEV_STATE_PROMISCUOUS_MODE; - } - else { - *state = NETDEV_STATE_RX_MODE; - } - - return 0; -} - -int _nativenet_set_state(netdev_t *dev, netdev_state_t state) -{ - if (state != NETDEV_STATE_PROMISCUOUS_MODE && _NATIVENET_DEV_MORE(dev)->_is_monitoring) { - _NATIVENET_DEV_MORE(dev)->_is_monitoring = 0; - } - - switch (state) { - case NETDEV_STATE_RX_MODE: - nativenet_switch_to_rx(); - break; - - case NETDEV_STATE_PROMISCUOUS_MODE: - _NATIVENET_DEV_MORE(dev)->_is_monitoring = 1; - break; - - default: - return -ENOTSUP; - } - - return 0; -} - -void _nativenet_event(netdev_t *dev, uint32_t event_type) -{ - (void)dev; - (void)event_type; -} - -const netdev_driver_t nativenet_driver = { - _nativenet_init, - _nativenet_send_data, - _nativenet_add_rcv_data_cb, - _nativenet_rem_rcv_data_cb, - _nativenet_get_option, - _nativenet_set_option, - _nativenet_get_state, - _nativenet_set_state, - _nativenet_event, -}; - -_nativenet_netdev_more_t _nativenet_default_dev_more; -netdev_t nativenet_default_dev = {NETDEV_TYPE_BASE, &nativenet_driver, - &_nativenet_default_dev_more - }; -#else -_nativenet_netdev_more_t _nativenet_default_dev_more; -netdev_t nativenet_default_dev = {NETDEV_TYPE_BASE, NULL, - &_nativenet_default_dev_more - }; -#endif /* MODULE_NETDEV_BASE */ - -/** @} */ diff --git a/cpu/native/net/tap.c b/cpu/native/net/tap.c deleted file mode 100644 index c5590b907c..0000000000 --- a/cpu/native/net/tap.c +++ /dev/null @@ -1,370 +0,0 @@ -/** - * tap.h implementation - * - * Copyright (C) 2013 Ludwig Ortmann - * - * 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 native_cpu - * @{ - * @file - * @author Ludwig Ortmann - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __MACH__ -#define _POSIX_C_SOURCE -#include -#undef _POSIX_C_SOURCE -#include -#include - -#elif defined(__FreeBSD__) -#include -#include -#include -#include - -#else -#include -#include -#include -#endif - -#define ENABLE_DEBUG (0) -#include "debug.h" - -#include "cpu.h" -#include "cpu_conf.h" -#include "tap.h" -#include "nativenet.h" -#include "nativenet_internal.h" -#include "native_internal.h" - -#include "hwtimer.h" -#include "timex.h" - -#define TAP_BUFFER_LENGTH (ETHER_MAX_LEN) -int _native_marshall_ethernet(uint8_t *framebuf, radio_packet_t *packet); - -int _native_tap_fd = -1; -unsigned char _native_tap_mac[ETHER_ADDR_LEN]; - -#ifdef __MACH__ -pid_t sigio_child_pid; -#endif - -void _native_handle_tap_input(void) -{ - int nread; - union eth_frame frame; - radio_packet_t p; - - DEBUG("_native_handle_tap_input\n"); - - /* TODO: check whether this is an input or an output event - TODO: refactor this into general io-signal multiplexer */ - - nread = real_read(_native_tap_fd, &frame, sizeof(union eth_frame)); - DEBUG("_native_handle_tap_input - read %d bytes\n", nread); - - if (nread > 0) { - if (ntohs(frame.field.header.ether_type) == NATIVE_ETH_PROTO) { - nread = nread - ETHER_HDR_LEN; - - if ((nread - 1) <= 0) { - DEBUG("_native_handle_tap_input: no payload\n"); - } - else { - unsigned long t = hwtimer_now(); - p.processing = 0; - p.src = ntohs(frame.field.payload.nn_header.src); - p.dst = ntohs(frame.field.payload.nn_header.dst); - p.rssi = 0; - p.lqi = 0; - p.toa.seconds = HWTIMER_TICKS_TO_US(t) / 1000000; - p.toa.microseconds = HWTIMER_TICKS_TO_US(t) % 1000000; - /* XXX: check overflow */ - p.length = ntohs(frame.field.payload.nn_header.length); - p.data = frame.field.payload.data; - - if (p.length > (nread - sizeof(struct nativenet_header))) { - warnx("_native_handle_tap_input: packet with malicious length field received, discarding"); - } - else { - DEBUG("_native_handle_tap_input: received packet of length %" PRIu16 " for %" PRIu16 " from %" - PRIu16 "\n", p.length, p.dst, p.src); - _nativenet_handle_packet(&p); - } - } - } - else { - DEBUG("ignoring non-native frame\n"); - } - - /* work around lost signals */ - fd_set rfds; - struct timeval t; - memset(&t, 0, sizeof(t)); - FD_ZERO(&rfds); - FD_SET(_native_tap_fd, &rfds); - - _native_in_syscall++; // no switching here - - if (real_select(_native_tap_fd + 1, &rfds, NULL, NULL, &t) == 1) { - int sig = SIGIO; - extern int _sig_pipefd[2]; - extern ssize_t (*real_write)(int fd, const void *buf, size_t count); - real_write(_sig_pipefd[1], &sig, sizeof(int)); - _native_sigpend++; - DEBUG("_native_handle_tap_input: sigpend++\n"); - } - else { - DEBUG("_native_handle_tap_input: no more pending tap data\n"); -#ifdef __MACH__ - kill(sigio_child_pid, SIGCONT); -#endif - } - - _native_in_syscall--; - } - else if (nread == -1) { - if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) { - //warn("read"); - } - else { - err(EXIT_FAILURE, "_native_handle_tap_input: read"); - } - } - else if (nread == 0) { - DEBUG("_native_handle_tap_input: ignoring null-event\n"); - } - else { - errx(EXIT_FAILURE, "internal error _native_handle_tap_input"); - } -} - -#ifdef __MACH__ -void sigio_child(void) -{ - pid_t parent = _native_pid; - - if ((sigio_child_pid = real_fork()) == -1) { - err(EXIT_FAILURE, "sigio_child: fork"); - } - - if (sigio_child_pid > 0) { - /* return in parent process */ - return; - } - - /* watch tap interface and signal parent process if data is - * available */ - - fd_set rfds; - - while (1) { - FD_ZERO(&rfds); - FD_SET(_native_tap_fd, &rfds); - - if (real_select(_native_tap_fd + 1, &rfds, NULL, NULL, NULL) == 1) { - kill(parent, SIGIO); - } - else { - kill(parent, SIGKILL); - err(EXIT_FAILURE, "osx_sigio_child: select"); - } - - pause(); - } -} -#endif - -int _native_marshall_ethernet(uint8_t *framebuf, radio_packet_t *packet) -{ - int data_len; - union eth_frame *f; - unsigned char addr[ETHER_ADDR_LEN]; - - f = (union eth_frame *)framebuf; - addr[0] = addr[1] = addr[2] = addr[3] = addr[4] = addr[5] = 0xFF; - - memcpy(f->field.header.ether_dhost, addr, ETHER_ADDR_LEN); - memcpy(f->field.header.ether_shost, _native_tap_mac, ETHER_ADDR_LEN); - f->field.header.ether_type = htons(NATIVE_ETH_PROTO); - - /* XXX: check overflow */ - memcpy(f->field.payload.data, packet->data, packet->length); - f->field.payload.nn_header.length = htons(packet->length); - f->field.payload.nn_header.dst = htons(packet->dst); - f->field.payload.nn_header.src = htons(packet->src); - - data_len = packet->length + sizeof(struct nativenet_header); - - /* Pad to minimum payload size. - * Linux does this on its own, but it doesn't hurt to do it here. - * As of now only tuntaposx needs this. */ - if (data_len < ETHERMIN) { - DEBUG("padding data! (%d -> ", data_len); - data_len = ETHERMIN; - DEBUG("%d)\n", data_len); - } - - return data_len + ETHER_HDR_LEN; -} - -int8_t send_buf(radio_packet_t *packet) -{ - uint8_t buf[TAP_BUFFER_LENGTH]; - int nsent, to_send; - - memset(buf, 0, sizeof(buf)); - - DEBUG("send_buf: Sending packet of length %" PRIu16 " from %" PRIu16 " to %" PRIu16 "\n", - packet->length, packet->src, packet->dst); - to_send = _native_marshall_ethernet(buf, packet); - - DEBUG("send_buf: trying to send %d bytes\n", to_send); - - if ((nsent = _native_write(_native_tap_fd, buf, to_send)) == -1) { - warn("write"); - return -1; - } - - return (nsent > INT8_MAX ? INT8_MAX : nsent); -} - -int tap_init(char *name) -{ - -#ifdef __MACH__ /* OSX */ - char clonedev[255] = "/dev/"; /* XXX bad size */ - strncpy(clonedev + 5, name, 250); -#elif defined(__FreeBSD__) - char clonedev[255] = "/dev/"; /* XXX bad size */ - strncpy(clonedev + 5, name, 250); -#else /* Linux */ - struct ifreq ifr; - const char *clonedev = "/dev/net/tun"; -#endif - - /* implicitly create the tap interface */ - if ((_native_tap_fd = real_open(clonedev , O_RDWR)) == -1) { - err(EXIT_FAILURE, "open(%s)", clonedev); - } - -#if (defined(__MACH__) || defined(__FreeBSD__)) /* OSX/FreeBSD */ - struct ifaddrs *iflist; - - if (real_getifaddrs(&iflist) == 0) { - for (struct ifaddrs *cur = iflist; cur; cur = cur->ifa_next) { - if ((cur->ifa_addr->sa_family == AF_LINK) && (strcmp(cur->ifa_name, name) == 0) && cur->ifa_addr) { - struct sockaddr_dl *sdl = (struct sockaddr_dl *)cur->ifa_addr; - memcpy(_native_tap_mac, LLADDR(sdl), sdl->sdl_alen); - break; - } - } - - real_freeifaddrs(iflist); - } - -#else /* Linux */ - memset(&ifr, 0, sizeof(ifr)); - ifr.ifr_flags = IFF_TAP | IFF_NO_PI; - strncpy(ifr.ifr_name, name, IFNAMSIZ); - - if (real_ioctl(_native_tap_fd, TUNSETIFF, (void *)&ifr) == -1) { - _native_in_syscall++; - warn("ioctl TUNSETIFF"); - warnx("probably the tap interface (%s) does not exist or is already in use", name); - real_exit(EXIT_FAILURE); - } - - /* TODO: use strncpy */ - strcpy(name, ifr.ifr_name); - - - /* get MAC address */ - memset(&ifr, 0, sizeof(ifr)); - snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", name); - - if (real_ioctl(_native_tap_fd, SIOCGIFHWADDR, &ifr) == -1) { - _native_in_syscall++; - warn("ioctl SIOCGIFHWADDR"); - - if (real_close(_native_tap_fd) == -1) { - warn("close"); - } - - real_exit(EXIT_FAILURE); - } - - memcpy(_native_tap_mac, ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN); -#endif - DEBUG("_native_tap_mac: %02x:%02x:%02x:%02x:%02x:%02x\n", _native_tap_mac[0], _native_tap_mac[1], - _native_tap_mac[2], _native_tap_mac[3], _native_tap_mac[4], _native_tap_mac[5]); - - unsigned char *eui_64 = (unsigned char *)(&(_nativenet_default_dev_more._long_addr)); - eui_64[0] = _native_tap_mac[0]; - eui_64[1] = _native_tap_mac[1]; - eui_64[2] = _native_tap_mac[2]; - eui_64[3] = 0xff; - eui_64[4] = 0xfe; - eui_64[5] = _native_tap_mac[3]; - eui_64[6] = _native_tap_mac[4]; - eui_64[7] = _native_tap_mac[5]; - - /* configure signal handler for fds */ - register_interrupt(SIGIO, _native_handle_tap_input); - -#ifdef __MACH__ - /* tuntap signalled IO is not working in OSX, - * check http://sourceforge.net/p/tuntaposx/bugs/17/ */ - sigio_child(); -#else - - /* configure fds to send signals on io */ - if (fcntl(_native_tap_fd, F_SETOWN, _native_pid) == -1) { - err(EXIT_FAILURE, "tap_init(): fcntl(F_SETOWN)"); - } - - /* set file access mode to non-blocking */ - if (fcntl(_native_tap_fd, F_SETFL, O_NONBLOCK | O_ASYNC) == -1) { - err(EXIT_FAILURE, "tap_init(): fcntl(F_SETFL)"); - } - -#endif /* not OSX */ - - DEBUG("RIOT native tap initialized.\n"); - return _native_tap_fd; -} - -void tap_cleanup(void) -{ - unregister_interrupt(SIGIO); -#ifdef __MACH__ - kill(sigio_child_pid, SIGKILL); -#endif - - if (_native_tap_fd == -1) { - return; - } - - real_close(_native_tap_fd); - _native_tap_fd = -1; - -} -/** @} */ diff --git a/cpu/native/startup.c b/cpu/native/startup.c index a6c9f6752a..e8d3aa9b9a 100644 --- a/cpu/native/startup.c +++ b/cpu/native/startup.c @@ -35,7 +35,6 @@ #include "board_internal.h" #include "native_internal.h" -#include "tap.h" int _native_null_in_pipe[2]; int _native_null_out_file; @@ -197,7 +196,7 @@ void usage_exit(void) { real_printf("usage: %s", _progname); -#if defined(MODULE_NATIVENET) || defined(MODULE_NG_NATIVENET) +#if defined(MODULE_NG_NATIVENET) real_printf(" "); #endif @@ -257,7 +256,7 @@ __attribute__((constructor)) static void startup(int argc, char **argv) int replay = 0; #endif -#if defined(MODULE_NATIVENET) || defined(MODULE_NG_NATIVENET) +#if defined(MODULE_NG_NATIVENET) if ( (argc < 2) || ( @@ -368,13 +367,7 @@ __attribute__((constructor)) static void startup(int argc, char **argv) native_cpu_init(); native_interrupt_init(); -#ifdef MODULE_NATIVENET - tap_init(argv[1]); -#endif #ifdef MODULE_NG_NATIVENET -# ifdef MODULE_NATIVENET -# error "Modules nativenet and ng_nativenet are mutually exclusive." -# endif dev_eth_tap_setup(&dev_eth_tap, argv[1]); #endif diff --git a/drivers/Makefile b/drivers/Makefile index f26f528a09..44a8fa2a7b 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -1,9 +1,3 @@ -ifneq (,$(filter netdev_base,$(USEMODULE))) - DIRS += netdev/base -endif -ifneq (,$(filter netdev_802154,$(USEMODULE))) - DIRS += netdev/802154 -endif ifneq (,$(filter nrf24l01p,$(USEMODULE))) DIRS += nrf24l01p endif diff --git a/drivers/Makefile.include b/drivers/Makefile.include index c2374e6b5b..6125961bde 100644 --- a/drivers/Makefile.include +++ b/drivers/Makefile.include @@ -1,21 +1,6 @@ -ifneq (,$(filter cc2420,$(USEMODULE))) - USEMODULE_INCLUDES += $(RIOTBASE)/drivers/cc2420/include -endif -ifneq (,$(filter cc110x,$(USEMODULE))) - USEMODULE_INCLUDES += $(RIOTBASE)/drivers/cc110x/include -endif -ifneq (,$(filter cc110x_legacy_csma,$(USEMODULE))) - USEMODULE_INCLUDES += $(RIOTBASE)/drivers/cc110x_legacy_csma/include -endif -ifneq (,$(filter cc110x_legacy,$(USEMODULE))) - USEMODULE_INCLUDES += $(RIOTBASE)/drivers/cc110x_legacy/include -endif ifneq (,$(filter dht,$(USEMODULE))) USEMODULE_INCLUDES += $(RIOTBASE)/drivers/dht/include endif -ifneq (,$(filter at86rf231,$(USEMODULE))) - USEMODULE_INCLUDES += $(RIOTBASE)/drivers/at86rf231/include -endif ifneq (,$(filter ng_at86rf2xx,$(USEMODULE))) USEMODULE_INCLUDES += $(RIOTBASE)/drivers/ng_at86rf2xx/include endif diff --git a/drivers/at86rf231/Makefile b/drivers/at86rf231/Makefile deleted file mode 100644 index 48422e909a..0000000000 --- a/drivers/at86rf231/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(RIOTBASE)/Makefile.base diff --git a/drivers/at86rf231/at86rf231_rx.c b/drivers/at86rf231/at86rf231_rx.c deleted file mode 100644 index 1821e1971a..0000000000 --- a/drivers/at86rf231/at86rf231_rx.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (C) 2014 INRIA - * - * 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 drivers_at86rf231 - * @{ - * - * @file - * @brief RX related functionality for the AT86RF231 device driver - * - * @author Alaeddine Weslati - * @author Thomas Eichinger - * - * @} - */ - -#include "at86rf231.h" -#include "at86rf231_spi.h" - -#include "kernel_types.h" -#include "transceiver.h" -#include "msg.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -at86rf231_packet_t at86rf231_rx_buffer[AT86RF231_RX_BUF_SIZE]; -static uint8_t buffer[AT86RF231_RX_BUF_SIZE][AT86RF231_MAX_PKT_LENGTH]; -volatile uint8_t rx_buffer_next; -extern netdev_802154_raw_packet_cb_t at86rf231_raw_packet_cb; - -void at86rf231_rx_handler(void) -{ - uint8_t lqi, fcs_rssi; - /* read packet length */ - at86rf231_read_fifo(&at86rf231_rx_buffer[rx_buffer_next].length, 1); - - /* read psdu, read packet with length as first byte and lqi as last byte. */ - uint8_t *buf = buffer[rx_buffer_next]; - at86rf231_read_fifo(buf, at86rf231_rx_buffer[rx_buffer_next].length); - - /* read lqi which is appended after the psdu */ - lqi = buf[at86rf231_rx_buffer[rx_buffer_next].length - 1]; - - /* read fcs and rssi, from a register */ - fcs_rssi = at86rf231_reg_read(AT86RF231_REG__PHY_RSSI); - - /* build package */ - at86rf231_rx_buffer[rx_buffer_next].lqi = lqi; - /* RSSI has no meaning here, it should be read during packet reception. */ - at86rf231_rx_buffer[rx_buffer_next].rssi = fcs_rssi & 0x1F; /* bit[4:0] */ - /* bit7, boolean, 1 FCS valid, 0 FCS not valid */ - at86rf231_rx_buffer[rx_buffer_next].crc = (fcs_rssi >> 7) & 0x01; - - if (at86rf231_rx_buffer[rx_buffer_next].crc == 0) { - DEBUG("at86rf231: Got packet with invalid crc.\n"); - return; - } - -#if ENABLE_DEBUG - DEBUG("pkg: "); - for (int i = 1; i < at86rf231_rx_buffer[rx_buffer_next].length; i++) { - DEBUG("%x ", buf[i]); - } - DEBUG("\n"); -#endif - - /* read buffer into ieee802154_frame */ - ieee802154_frame_read(&buf[1], &at86rf231_rx_buffer[rx_buffer_next].frame, - at86rf231_rx_buffer[rx_buffer_next].length); - - /* if packet is no ACK */ - if (at86rf231_rx_buffer[rx_buffer_next].frame.fcf.frame_type != IEEE_802154_ACK_FRAME) { -#if ENABLE_DEBUG - ieee802154_frame_print_fcf_frame(&at86rf231_rx_buffer[rx_buffer_next].frame); -#endif - if (at86rf231_raw_packet_cb != NULL) { - at86rf231_raw_packet_cb(&at86rf231_netdev, (void*)buf, - at86rf231_rx_buffer[rx_buffer_next].length, - fcs_rssi, lqi, (fcs_rssi >> 7)); - } -#ifdef MODULE_TRANSCEIVER - /* notify transceiver thread if any */ - if (transceiver_pid != KERNEL_PID_UNDEF) { - msg_t m; - m.type = (uint16_t) RCV_PKT_AT86RF231; - m.content.value = rx_buffer_next; - msg_send_int(&m, transceiver_pid); - } -#endif - } - else { - /* This should not happen, ACKs are consumed by hardware */ -#if ENABLE_DEBUG - DEBUG("GOT ACK for SEQ %u\n", at86rf231_rx_buffer[rx_buffer_next].frame.seq_nr); - ieee802154_frame_print_fcf_frame(&at86rf231_rx_buffer[rx_buffer_next].frame); -#endif - } - - /* shift to next buffer element */ - if (++rx_buffer_next == AT86RF231_RX_BUF_SIZE) { - rx_buffer_next = 0; - } - - /* Read IRQ to clear it */ - at86rf231_reg_read(AT86RF231_REG__IRQ_STATUS); -} diff --git a/drivers/at86rf231/at86rf231_spi.c b/drivers/at86rf231/at86rf231_spi.c deleted file mode 100644 index 8dc7b9d413..0000000000 --- a/drivers/at86rf231/at86rf231_spi.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2014 INRIA - * - * 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 drivers_at86rf231 - * @{ - * - * @file - * @brief Register access functions for the AT86RF231 device driver - * - * @author Alaeddine Weslati - * @author Thomas Eichinger - * @author Joakim Gebart - * - * @} - */ - -#include "at86rf231_spi.h" -#include "at86rf231.h" -#include "board.h" -#include "periph/spi.h" -#include "periph/gpio.h" - -void at86rf231_reg_write(uint8_t addr, uint8_t value) -{ - /* Acquire exclusive access to the bus. */ - spi_acquire(AT86RF231_SPI); - /* Start the SPI transfer */ - gpio_clear(AT86RF231_CS); - /* write to register */ - spi_transfer_reg(AT86RF231_SPI, AT86RF231_ACCESS_REG | AT86RF231_ACCESS_WRITE | addr, value, 0); - /* End the SPI transfer */ - gpio_set(AT86RF231_CS); - /* Release the bus for other threads. */ - spi_release(AT86RF231_SPI); -} - -uint8_t at86rf231_reg_read(uint8_t addr) -{ - char value; - - /* Acquire exclusive access to the bus. */ - spi_acquire(AT86RF231_SPI); - /* Start the SPI transfer */ - gpio_clear(AT86RF231_CS); - /* read from register */ - spi_transfer_reg(AT86RF231_SPI, AT86RF231_ACCESS_REG | AT86RF231_ACCESS_READ | addr, 0, &value); - /* End the SPI transfer */ - gpio_set(AT86RF231_CS); - /* Release the bus for other threads. */ - spi_release(AT86RF231_SPI); - return (uint8_t)value; -} - -void at86rf231_read_fifo(uint8_t *data, radio_packet_length_t length) -{ - /* Acquire exclusive access to the bus. */ - spi_acquire(AT86RF231_SPI); - /* Start the SPI transfer */ - gpio_clear(AT86RF231_CS); - /* Read a number of bytes from the devices frame buffer */ - spi_transfer_regs(AT86RF231_SPI, AT86RF231_ACCESS_FRAMEBUFFER | AT86RF231_ACCESS_READ, - 0, (char*)data, length); - /* End the SPI transfer */ - gpio_set(AT86RF231_CS); - /* Release the bus for other threads. */ - spi_release(AT86RF231_SPI); -} - -void at86rf231_write_fifo(const uint8_t *data, radio_packet_length_t length) -{ - /* Acquire exclusive access to the bus. */ - spi_acquire(AT86RF231_SPI); - /* Start the SPI transfer */ - gpio_clear(AT86RF231_CS); - /* Send Frame Buffer Write access */ - spi_transfer_regs(AT86RF231_SPI, AT86RF231_ACCESS_FRAMEBUFFER | AT86RF231_ACCESS_WRITE, - (char*)data, 0, length); - /* End the SPI transfer */ - gpio_set(AT86RF231_CS); - /* Release the bus for other threads. */ - spi_release(AT86RF231_SPI); -} - -uint8_t at86rf231_get_status(void) -{ - return (at86rf231_reg_read(AT86RF231_REG__TRX_STATUS) - & AT86RF231_TRX_STATUS_MASK__TRX_STATUS); -} diff --git a/drivers/at86rf231/at86rf231_tx.c b/drivers/at86rf231/at86rf231_tx.c deleted file mode 100644 index ada7553ce7..0000000000 --- a/drivers/at86rf231/at86rf231_tx.c +++ /dev/null @@ -1,295 +0,0 @@ -/* - * Copyright (C) 2014 INRIA - * - * 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 drivers_at86rf231 - * @{ - * - * @file - * @brief TX related functionality for the AT86RF231 device driver - * - * @author Alaeddine Weslati - * @author Thomas Eichinger - * - * @} - */ - -#include "at86rf231.h" -#include "at86rf231_spi.h" -#include "hwtimer.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -#define _MAX_RETRIES (100) - -static int16_t at86rf231_load(at86rf231_packet_t *packet); -static void at86rf231_gen_pkt(uint8_t *buf, at86rf231_packet_t *packet); - -static uint8_t sequence_nr; -static uint8_t wait_for_ack; - -int16_t at86rf231_send(at86rf231_packet_t *packet) -{ - int16_t result; - result = at86rf231_load(packet); - if (result < 0) { - return result; - } - at86rf231_transmit_tx_buf(NULL); - return result; -} - -netdev_802154_tx_status_t at86rf231_load_tx_buf(netdev_t *dev, - netdev_802154_pkt_kind_t kind, - netdev_802154_node_addr_t *dest, - int use_long_addr, - int wants_ack, - netdev_hlist_t *upper_layer_hdrs, - void *buf, - unsigned int len) -{ - (void)dev; - - uint8_t mhr[24]; - uint8_t index = 3; - - /* frame type */ - switch (kind) { - case NETDEV_802154_PKT_KIND_BEACON: - mhr[0] = 0x00; - break; - case NETDEV_802154_PKT_KIND_DATA: - mhr[0] = 0x01; - break; - case NETDEV_802154_PKT_KIND_ACK: - mhr[0] = 0x02; - break; - default: - return NETDEV_802154_TX_STATUS_INVALID_PARAM; - } - - if (wants_ack) { - mhr[0] |= 0x20; - } - - wait_for_ack = wants_ack; - - uint16_t src_pan = at86rf231_get_pan(); - uint8_t compress_pan = 0; - - if (use_long_addr) { - mhr[1] = 0xcc; - } - else { - mhr[1] = 0x88; - if (dest->pan.id == src_pan) { - compress_pan = 1; - mhr[0] |= 0x40; - } - } - - mhr[2] = sequence_nr++; - - /* First 3 bytes are fixed with FCS and SEQ, resume with index=3 */ - if (use_long_addr) { - mhr[index++] = (uint8_t)(dest->long_addr & 0xFF); - mhr[index++] = (uint8_t)(dest->long_addr >> 8); - mhr[index++] = (uint8_t)(dest->long_addr >> 16); - mhr[index++] = (uint8_t)(dest->long_addr >> 24); - mhr[index++] = (uint8_t)(dest->long_addr >> 32); - mhr[index++] = (uint8_t)(dest->long_addr >> 40); - mhr[index++] = (uint8_t)(dest->long_addr >> 48); - mhr[index++] = (uint8_t)(dest->long_addr >> 56); - - uint64_t src_long_addr = at86rf231_get_address_long(); - mhr[index++] = (uint8_t)(src_long_addr & 0xFF); - mhr[index++] = (uint8_t)(src_long_addr >> 8); - mhr[index++] = (uint8_t)(src_long_addr >> 16); - mhr[index++] = (uint8_t)(src_long_addr >> 24); - mhr[index++] = (uint8_t)(src_long_addr >> 32); - mhr[index++] = (uint8_t)(src_long_addr >> 40); - mhr[index++] = (uint8_t)(src_long_addr >> 48); - mhr[index++] = (uint8_t)(src_long_addr >> 56); - } - else { - mhr[index++] = (uint8_t)(dest->pan.id & 0xFF); - mhr[index++] = (uint8_t)(dest->pan.id >> 8); - - mhr[index++] = (uint8_t)(dest->pan.addr & 0xFF); - mhr[index++] = (uint8_t)(dest->pan.addr >> 8); - - if (!compress_pan) { - mhr[index++] = (uint8_t)(src_pan & 0xFF); - mhr[index++] = (uint8_t)(src_pan >> 8); - } - - uint16_t src_addr = at86rf231_get_address(); - mhr[index++] = (uint8_t)(src_addr & 0xFF); - mhr[index++] = (uint8_t)(src_addr >> 8); - } - - /* total frame size: - * index -> MAC header - * len -> payload length - * 2 -> CRC bytes - * + lengths of upper layers' headers */ - size_t size = index + len + 2 + netdev_get_hlist_len(upper_layer_hdrs); - - if (size > AT86RF231_MAX_PKT_LENGTH) { - DEBUG("at86rf231: packet too long, dropped it.\n"); - return NETDEV_802154_TX_STATUS_PACKET_TOO_LONG; - } - - uint8_t size_byte = (uint8_t)size; - netdev_hlist_t *ptr = upper_layer_hdrs; - - at86rf231_write_fifo(&size_byte, 1); - at86rf231_write_fifo(mhr, (radio_packet_length_t)index); - if (upper_layer_hdrs) { - do { - at86rf231_write_fifo(ptr->header, - (radio_packet_length_t)(ptr->header_len)); - netdev_hlist_advance(&ptr); - } while (ptr != upper_layer_hdrs); - } - at86rf231_write_fifo((uint8_t*)buf, len); - return NETDEV_802154_TX_STATUS_OK; -} - -netdev_802154_tx_status_t at86rf231_transmit_tx_buf(netdev_t *dev) -{ - (void)dev; - /* radio driver state: sending */ - /* will be freed in at86rf231_rx_irq when TRX_END interrupt occurs */ - driver_state = AT_DRIVER_STATE_SENDING; - - /* Start TX */ - at86rf231_reg_write(AT86RF231_REG__TRX_STATE, AT86RF231_TRX_STATE__TX_START); - DEBUG("at86rf231: Started TX\n"); - - if (!wait_for_ack) { - DEBUG("at86rf231: Don't wait for ACK, TX done.\n"); - return NETDEV_802154_TX_STATUS_OK; - } - - uint8_t trac_status; - do { - trac_status = at86rf231_reg_read(AT86RF231_REG__TRX_STATE); - trac_status &= AT86RF231_TRX_STATE_MASK__TRAC; - } - while (trac_status == AT86RF231_TRX_STATE__TRAC_INVALID); - - switch (trac_status) { - case AT86RF231_TRX_STATE__TRAC_CHANNEL_ACCESS_FAILURE: - return NETDEV_802154_TX_STATUS_MEDIUM_BUSY; - - case AT86RF231_TRX_STATE__TRAC_NO_ACK: - return NETDEV_802154_TX_STATUS_NOACK; - - default: - return NETDEV_802154_TX_STATUS_OK; - } -} - -int16_t at86rf231_load(at86rf231_packet_t *packet) -{ - // Set missing frame information - packet->frame.fcf.frame_ver = 0; - - packet->frame.src_pan_id = at86rf231_get_pan(); - - if (packet->frame.src_pan_id == packet->frame.dest_pan_id) { - packet->frame.fcf.panid_comp = 1; - } - else { - packet->frame.fcf.panid_comp = 0; - } - - if (packet->frame.fcf.src_addr_m == 2) { - packet->frame.src_addr[0] = (uint8_t)(at86rf231_get_address() >> 8); - packet->frame.src_addr[1] = (uint8_t)(at86rf231_get_address() & 0xFF); - } - else if (packet->frame.fcf.src_addr_m == 3) { - packet->frame.src_addr[0] = (uint8_t)(at86rf231_get_address_long() >> 56); - packet->frame.src_addr[1] = (uint8_t)(at86rf231_get_address_long() >> 48); - packet->frame.src_addr[2] = (uint8_t)(at86rf231_get_address_long() >> 40); - packet->frame.src_addr[3] = (uint8_t)(at86rf231_get_address_long() >> 32); - packet->frame.src_addr[4] = (uint8_t)(at86rf231_get_address_long() >> 24); - packet->frame.src_addr[5] = (uint8_t)(at86rf231_get_address_long() >> 16); - packet->frame.src_addr[6] = (uint8_t)(at86rf231_get_address_long() >> 8); - packet->frame.src_addr[7] = (uint8_t)(at86rf231_get_address_long() & 0xFF); - } - - packet->frame.seq_nr = sequence_nr++; - - /* calculate size of the frame (payload + FCS) */ - packet->length = ieee802154_frame_get_hdr_len(&packet->frame) + - packet->frame.payload_len + 1; - - if (packet->length > AT86RF231_MAX_PKT_LENGTH) { - DEBUG("at86rf231: ERROR: packet too long, dropped it.\n"); - return -1; - } - - /* FCS is added in hardware */ - uint8_t pkt[packet->length]; - - /* generate pkt */ - at86rf231_gen_pkt(pkt, packet); - - /* Go to state PLL_ON */ - at86rf231_reg_write(AT86RF231_REG__TRX_STATE, AT86RF231_TRX_STATE__PLL_ON); - - /* wait until it is on PLL_ON state */ - do { - int max_wait = _MAX_RETRIES; - if (!--max_wait) { - DEBUG("at86rf231 : ERROR : could not enter PLL_ON mode\n"); - break; - } - } while ((at86rf231_get_status() & AT86RF231_TRX_STATUS_MASK__TRX_STATUS) - != AT86RF231_TRX_STATUS__PLL_ON); - - /* change into TX_ARET_ON state */ - at86rf231_reg_write(AT86RF231_REG__TRX_STATE, AT86RF231_TRX_STATE__TX_ARET_ON); - - do { - int max_wait = _MAX_RETRIES; - if (!--max_wait) { - DEBUG("at86rf231 : ERROR : could not enter TX_ARET_ON mode\n"); - break; - } - } while (at86rf231_get_status() != AT86RF231_TRX_STATUS__TX_ARET_ON); - - /* load packet into fifo */ - at86rf231_write_fifo(pkt, packet->length); - DEBUG("at86rf231: Wrote to FIFO\n"); - - return packet->length; -} - -/** - * @brief Static function to generate byte array from at86rf231 packet. - */ -static void at86rf231_gen_pkt(uint8_t *buf, at86rf231_packet_t *packet) -{ - uint8_t index, offset; - index = ieee802154_frame_init(&packet->frame, &buf[1]); - - // add length for at86rf231 - buf[0] = packet->length + 1; - index++; - - offset = index; - - while (index < packet->length) { - buf[index] = packet->frame.payload[index - offset]; - index += 1; - } -} diff --git a/drivers/at86rf231/include/at86rf231_spi.h b/drivers/at86rf231/include/at86rf231_spi.h deleted file mode 100644 index 236892d1b5..0000000000 --- a/drivers/at86rf231/include/at86rf231_spi.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2014 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 drivers_at86rf231 - * @{ - * - * @file - * @brief Register access function definitions for the AT86RF231 device driver - * - * @author Alaeddine Weslati - * @author Thomas Eichinger - */ - -#ifndef AT86RF231_SPI_H_ -#define AT86RF231_SPI_H_ - -#include - -#include "board.h" - -#ifdef __cplusplus -extern "C" { -#endif - -uint8_t at86rf231_reg_read(uint8_t addr); -void at86rf231_reg_write(uint8_t addr, uint8_t value); - -void at86rf231_read_fifo(uint8_t *data, radio_packet_length_t length); -void at86rf231_write_fifo(const uint8_t *data, radio_packet_length_t length); - -uint8_t at86rf231_get_status(void); - -#ifdef __cplusplus -} -#endif - -#endif /* AT86RF231_SPI_H_ */ -/** @} */ diff --git a/drivers/cc110x/Makefile b/drivers/cc110x/Makefile deleted file mode 100644 index 48422e909a..0000000000 --- a/drivers/cc110x/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(RIOTBASE)/Makefile.base diff --git a/drivers/cc110x/cc110x-defaultsettings.c b/drivers/cc110x/cc110x-defaultsettings.c deleted file mode 100644 index cc0a1b2c2c..0000000000 --- a/drivers/cc110x/cc110x-defaultsettings.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (C) 2013 INRIA - * - * 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 drivers_cc110x - * @{ - * - * @file - * @brief TI Chipcon CC110x default settings - * - * @author Thomas Hillebrandt - * @author Heiko Will - * @author Oliver Hahm - * @} - */ - -#include "cc110x.h" - -/** - * @brief Default PA table index (output power) - */ -#define PATABLE (11) - -/** - * @brief Current PATABLE Index - */ -uint8_t pa_table_index = PATABLE; - -/** - * @brief PATABLE with available output powers - * @note If changed in size, adjust MAX_OUTPUT_POWER definition - * in CC110x interface - */ -uint8_t pa_table[] = { - 0x00, ///< -52 dBm - 0x03, ///< -30 dBm - 0x0D, ///< -20 dBm - 0x1C, ///< -15 dBm - 0x34, ///< -10 dBm - 0x57, ///< - 5 dBm - 0x3F, ///< - 1 dBm - 0x8E, ///< 0 dBm - 0x85, ///< + 5 dBm - 0xCC, ///< + 7 dBm - 0xC6, ///< + 9 dBm - 0xC3 ///< +10 dBm -}; - -/** - * Usable, non overlapping channels and corresponding frequencies - * for use with CC110x. CHANNR is the register for selecting a channel. - * - * channel number | CHANNR | frequency [MHz] - * ----------------------------------------- - * 0 | 0 | 869.525 - * 1 | 10 | 871.61 - * 2 | 20 | 873.58 ~ seems to be bad (hang-ups with this channel) - * 3 | 30 | 875.61 - * 4 | 40 | 877.58 - * 5 | 50 | 879.61 - * 6 | 60 | 881.58 - * 7 | 70 | 883.61 - * 8 | 80 | 885.58 - * 9 | 90 | 887.61 - * 10 | 100 | 889.58 - * 11 | 110 | 891.57 - * 12 | 120 | 893.58 - * 13 | 130 | 895.61 - * 14 | 140 | 897.58 - * 15 | 150 | 899.57 - * 16 | 160 | 901.57 - * 17 | 170 | 903.61 - * 18 | 180 | 905.57 - * 19 | 190 | 907.57 - * 20 | 200 | 909.57 - * 21 | 210 | 911.57 - * 22 | 220 | 913.57 - * 23 | 230 | 915.61 - * 24 | 240 | 917.61 - */ - -/** - * @brief Initial CC110x configuration - * - * 400 kbps, MSK, X-tal: 26 MHz (Chip Revision F) - */ -char cc110x_conf[] = { - 0x06, /* IOCFG2 */ - 0x2E, /* IOCFG1 */ - 0x0E, /* IOCFG0 */ - 0x0F, /* FIFOTHR */ - 0x9B, /* SYNC1 */ - 0xAD, /* SYNC0 */ - 0x3D, /* PKTLEN (maximum value of packet length byte = 61) */ - 0x06, /* PKTCTRL1 */ - 0x45, /* PKTCTRL0 (variable packet length) */ - 0xFF, /* ADDR */ - CC1100_DEFAULT_CHANNR * 10, /* CHANNR */ - 0x0B, /* FSCTRL1 */ - 0x00, /* FSCTRL0 */ - 0x21, /* FREQ2 */ - 0x71, /* FREQ1 */ - 0x7A, /* FREQ0 */ - 0x2D, /* MDMCFG4 */ - 0xF8, /* MDMCFG3 */ - 0x73, /* MDMCFG2 */ - 0x42, /* MDMCFG1 */ - 0xF8, /* MDMCFG0 */ - 0x00, /* DEVIATN */ - 0x07, /* MCSM2 */ - 0x03, /* MCSM1 */ - 0x18, /* MCSM0 */ - 0x1D, /* FOCCFG */ - 0x1C, /* BSCFG */ - 0xC0, /* AGCCTRL2 */ - 0x49, /* AGCCTRL1 */ - 0xB2, /* AGCCTRL0 */ - 0x87, /* WOREVT1 */ - 0x6B, /* WOREVT0 */ - 0xF8, /* WORCTRL */ - 0xB6, /* FREND1 */ - 0x10, /* FREND0 */ - 0xEA, /* FSCAL3 */ - 0x2A, /* FSCAL2 */ - 0x00, /* FSCAL1 */ - 0x1F, /* FSCAL0 */ - 0x00 /* padding to 4 bytes */ -}; diff --git a/drivers/cc110x/cc110x-internal.h b/drivers/cc110x/cc110x-internal.h deleted file mode 100644 index b4d8d2c2f4..0000000000 --- a/drivers/cc110x/cc110x-internal.h +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (C) 2008 Freie Universität Berlin - * Copyright (C) 2013 INRIA - * - * 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 drivers_cc110x - * @{ - * - * @file - * @brief Driver internal constants for CC110x chip configuration - * - * @author Thomas Hillebrandt - * @author Heiko Will - * @author Oliver Hahm - */ - -#ifndef CC110X_INTERNAL_H -#define CC110X_INTERNAL_H - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Variable packet length PKTCTRL0 bit configuration - * - * If variable packet length is configured in PKTCTRL0 the - * first byte after the synch word determines the packet length. - */ -#define VARIABLE_PKTLEN (0x01) - -/** - * @name Bitmasks for reading out status register values - * @{ - */ - -/** - * @brief Bitmask (=10000000) for reading CRC_OK. - * - * If CRC_OK == 1: CRC for received data OK (or CRC disabled). - * If CRC_OK == 0: CRC error in received data. - */ -#define CRC_OK (0x80) -/** - * @brief Bitmask (=01111111) for reading LQI_EST. - * - * The Link Quality Indicator estimates how easily a received signal can be demodulated. - */ -#define LQI_EST (0x7F) -#define I_RSSI (0x00) ///< Index 0 contains RSSI information (from optionally appended packet status bytes). -#define I_LQI (0x01) ///< Index 1 contains LQI & CRC_OK information (from optionally appended packet status bytes). -#define MARC_STATE (0x1F) ///< Bitmask (=00011111) for reading MARC_STATE in MARCSTATE status register. -#define CS (0x40) ///< Bitmask (=01000000) for reading CS (Carrier Sense) in PKTSTATUS status register. -#define PQT_REACHED (0x20) ///< Bitmask (=00100000) for reading PQT_REACHED (Preamble Quality reached) in PKTSTATUS status register. -#define CCA (0x10) ///< Bitmask (=00010000) for reading CCA (clear channel assessment) in PKTSTATUS status register. -#define SFD (0x08) ///< Bitmask (=00001000) for reading SFD (Sync word found) in PKTSTATUS status register. -#define GDO2 (0x04) ///< Bitmask (=00000100) for reading GDO2 (current value on GDO2 pin) in PKTSTATUS status register. -#define GDO1 (0x02) ///< Bitmask (=00000010) for reading GDO1 (current value on GDO1 pin) in PKTSTATUS status register. -#define GDO0 (0x01) ///< Bitmask (=00000001) for reading GDO0 (current value on GDO0 pin) in PKTSTATUS status register. -#define TXFIFO_UNDERFLOW (0x80) ///< Bitmask (=10000000) for reading TXFIFO_UNDERFLOW in TXBYTES status register. -#define BYTES_IN_TXFIFO (0x7F) ///< Bitmask (=01111111) for reading NUM_TXBYTES in TXBYTES status register. -#define RXFIFO_OVERFLOW (0xBF) ///< Bitmask (=10000000) for reading RXFIFO_OVERFLOW in RXBYTES status register. -#define BYTES_IN_RXFIFO (0xFF) ///< Bitmask (=01111111) for reading NUM_RXBYTES in RXBYTES status register. -/** @} */ - -/** - * @name Bitmasks for reading out configuration register values - * @{ - */ -#define PKT_LENGTH_CONFIG (0x03) ///< Bitmask (=00000011) for reading LENGTH_CONFIG in PKTCTRL0 configuration register. -/** @} */ - -/** - * @name Definitions to support burst/single access - * @{ - */ -#define CC1100_WRITE_BURST (0x40) ///< Offset for burst write. -#define CC1100_READ_SINGLE (0x80) ///< Offset for read single byte. -#define CC1100_READ_BURST (0xC0) ///< Offset for read burst. -#define CC1100_NOBYTE (0xFF) ///< No command (for reading). -/** @} */ - -/** - * @name Configuration Registers (47x) - * @{ - */ -#define CC1100_IOCFG2 (0x00) ///< GDO2 output pin configuration -#define CC1100_IOCFG1 (0x01) ///< GDO1 output pin configuration -#define CC1100_IOCFG0 (0x02) ///< GDO0 output pin configuration -#define CC1100_FIFOTHR (0x03) ///< RX FIFO and TX FIFO thresholds -#define CC1100_SYNC1 (0x04) ///< Sync word, high byte -#define CC1100_SYNC0 (0x05) ///< Sync word, low byte -#define CC1100_PKTLEN (0x06) ///< Packet length -#define CC1100_PKTCTRL1 (0x07) ///< Packet automation control -#define CC1100_PKTCTRL0 (0x08) ///< Packet automation control -#define CC1100_ADDR (0x09) ///< Device address -#define CC1100_CHANNR (0x0A) ///< Channel number -#define CC1100_FSCTRL1 (0x0B) ///< Frequency synthesizer control -#define CC1100_FSCTRL0 (0x0C) ///< Frequency synthesizer control -#define CC1100_FREQ2 (0x0D) ///< Frequency control word, high byte -#define CC1100_FREQ1 (0x0E) ///< Frequency control word, middle byte -#define CC1100_FREQ0 (0x0F) ///< Frequency control word, low byte -#define CC1100_MDMCFG4 (0x10) ///< Modem configuration -#define CC1100_MDMCFG3 (0x11) ///< Modem configuration -#define CC1100_MDMCFG2 (0x12) ///< Modem configuration -#define CC1100_MDMCFG1 (0x13) ///< Modem configuration -#define CC1100_MDMCFG0 (0x14) ///< Modem configuration -#define CC1100_DEVIATN (0x15) ///< Modem deviation setting -#define CC1100_MCSM2 (0x16) ///< Main Radio Control State Machine configuration -#define CC1100_MCSM1 (0x17) ///< Main Radio Control State Machine configuration -#define CC1100_MCSM0 (0x18) ///< Main Radio Control State Machine configuration -#define CC1100_FOCCFG (0x19) ///< Frequency Offset Compensation configuration -#define CC1100_BSCFG (0x1A) ///< Bit Synchronization configuration -#define CC1100_AGCCTRL2 (0x1B) ///< AGC control -#define CC1100_AGCCTRL1 (0x1C) ///< AGC control -#define CC1100_AGCCTRL0 (0x1D) ///< AGC control -#define CC1100_WOREVT1 (0x1E) ///< High byte Event 0 timeout -#define CC1100_WOREVT0 (0x1F) ///< Low byte Event 0 timeout -#define CC1100_WORCTRL (0x20) ///< Wake On Radio control -#define CC1100_FREND1 (0x21) ///< Front end RX configuration -#define CC1100_FREND0 (0x22) ///< Front end TX configuration -#define CC1100_FSCAL3 (0x23) ///< Frequency synthesizer calibration -#define CC1100_FSCAL2 (0x24) ///< Frequency synthesizer calibration -#define CC1100_FSCAL1 (0x25) ///< Frequency synthesizer calibration -#define CC1100_FSCAL0 (0x26) ///< Frequency synthesizer calibration -#define CC1100_RCCTRL1 (0x27) ///< RC oscillator configuration -#define CC1100_RCCTRL0 (0x28) ///< RC oscillator configuration -#define CC1100_FSTEST (0x29) ///< Frequency synthesizer calibration control -#define CC1100_PTEST (0x2A) ///< Production test -#define CC1100_AGCTEST (0x2B) ///< AGC test -#define CC1100_TEST2 (0x2C) ///< Various test settings -#define CC1100_TEST1 (0x2D) ///< Various test settings -#define CC1100_TEST0 (0x2E) ///< Various test settings -/** @} */ - -/** - * @name Strobe commands (14x) - * @{ - */ -#define CC1100_SRES (0x30) ///< Reset chip. -/** - * @brief Enable and calibrate frequency synthesizer (if MCSM0.FS_AUTOCAL=1). - * - * If in RX/TX: Go to a wait state where only the synthesizer is running (for quick RX / TX turnaround). - */ -#define CC1100_SFSTXON (0x31) -#define CC1100_SXOFF (0x32) ///< Turn off crystal oscillator. -#define CC1100_SCAL (0x33) ///< Calibrate frequency synthesizer and turn it off (enables quick start). -#define CC1100_SRX (0x34) ///< Enable RX. Perform calibration first if coming from IDLE and MCSM0.FS_AUTOCAL=1. -/** - * In IDLE state: Enable TX. Perform calibration first if MCSM0.FS_AUTOCAL=1. - * If in RX state and CCA is enabled: Only go to TX if channel is clear. - */ -#define CC1100_STX (0x35) -#define CC1100_SIDLE (0x36) ///< Exit RX / TX, turn off frequency synthesizer and exit WOR mode if applicable. -#define CC1100_SAFC (0x37) ///< Perform AFC adjustment of the frequency synthesizer -#define CC1100_SWOR (0x38) ///< Start automatic RX polling sequence (Wake-on-Radio) -#define CC1100_SPWD (0x39) ///< Enter power down mode when CSn goes high. -#define CC1100_SFRX (0x3A) ///< Flush the RX FIFO buffer (CC1100 should be in IDLE state). -#define CC1100_SFTX (0x3B) ///< Flush the TX FIFO buffer (CC1100 should be in IDLE state). -#define CC1100_SWORRST (0x3C) ///< Reset real time clock. -#define CC1100_SNOP (0x3D) ///< No operation. May be used to pad strobe commands to two bytes for simpler software. -/** @} */ - -/** - * @name Status registers (12x) - * @{ - */ -#define CC1100_PARTNUM (0x30) ///< Part number of CC1100. -#define CC1100_VERSION (0x31) ///< Current version number. -#define CC1100_FREQEST (0x32) ///< Frequency Offset Estimate. -#define CC1100_LQI (0x33) ///< Demodulator estimate for Link Quality. -#define CC1100_RSSI (0x34) ///< Received signal strength indication. -#define CC1100_MARCSTATE (0x35) ///< Control state machine state. -#define CC1100_WORTIME1 (0x36) ///< High byte of WOR timer. -#define CC1100_WORTIME0 (0x37) ///< Low byte of WOR timer. -#define CC1100_PKTSTATUS (0x38) ///< Current GDOx status and packet status. -#define CC1100_VCO_VC_DAC (0x39) ///< Current setting from PLL calibration module. -#define CC1100_TXBYTES (0x3A) ///< Underflow and number of bytes in the TX FIFO. -#define CC1100_RXBYTES (0x3B) ///< Overflow and number of bytes in the RX FIFO. -/** @} */ - -/** - * @name Multi byte registers - * @{ - */ -/** - * @brief Register for eight user selected output power settings. - * - * 3-bit FREND0.PA_POWER value selects the PATABLE entry to use. - */ -#define CC1100_PATABLE (0x3E) -#define CC1100_TXFIFO (0x3F) ///< TX FIFO: Write operations write to the TX FIFO (SB: +0x00; BURST: +0x40) -#define CC1100_RXFIFO (0x3F) ///< RX FIFO: Read operations read from the RX FIFO (SB: +0x80; BURST: +0xC0) -/** @} */ - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif diff --git a/drivers/cc110x/cc110x-netdev.c b/drivers/cc110x/cc110x-netdev.c deleted file mode 100644 index 152545fab8..0000000000 --- a/drivers/cc110x/cc110x-netdev.c +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (C) 2014 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 drivers_cc110x - * @{ - * @file - * @brief Functionality for netdev base interface - * - * @author Fabian Nack - * @} - */ -#include -#include -#include - -#include "cc110x.h" -#include "cc110x-internal.h" - -#include "periph/gpio.h" -#include "netdev/base.h" - -#ifdef MODULE_NETDEV_BASE -extern netdev_rcv_data_cb_t cc110x_recv_cb; - -int _cc110x_send_data(netdev_t *dev, void *dest, size_t dest_len, - netdev_hlist_t *upper_layer_hdrs, void *data, size_t data_len) -{ - netdev_hlist_t *ptr = upper_layer_hdrs; - uint8_t tx_buffer[data_len + netdev_get_hlist_len(upper_layer_hdrs)]; - size_t tx_ptr = 0; - cc110x_packet_t cc110x_pkt; - - if (dev != &cc110x_dev) { - return -ENODEV; - } - if (dest_len > sizeof(uint8_t)) { - return -EAFNOSUPPORT; - } - if ((sizeof(tx_buffer) + CC1100_HEADER_LENGTH + 1) > PACKET_LENGTH) { - return -EMSGSIZE; - } - - /* append possible upper layer headers */ - if (upper_layer_hdrs) { - do { - memcpy(&(tx_buffer[tx_ptr]), ptr->header, ptr->header_len); - tx_ptr += ptr->header_len; - netdev_hlist_advance(&ptr); - } while (ptr != upper_layer_hdrs); - } - - /* append data */ - memcpy(&(tx_buffer[tx_ptr]), data, data_len); - - cc110x_pkt.length = sizeof(tx_buffer) + CC1100_HEADER_LENGTH; - cc110x_pkt.address = *((uint8_t *)dest); - cc110x_pkt.flags = 0; - memcpy(cc110x_pkt.data, &tx_buffer[0], sizeof(tx_buffer)); - - return cc110x_send(&cc110x_pkt); -} - -int _cc110x_add_rcv_data_cb(netdev_t *dev, netdev_rcv_data_cb_t cb) -{ - if (dev != &cc110x_dev) { - return -ENODEV; - } - else if (cc110x_recv_cb != NULL) { - return -ENOBUFS; - } - - cc110x_recv_cb = cb; - - return 0; -} - -int _cc110x_rem_rcv_data_cb(netdev_t *dev, netdev_rcv_data_cb_t cb) -{ - if (dev != &cc110x_dev) { - return -ENODEV; - } - - if (cc110x_recv_cb == cb) { - cc110x_recv_cb = NULL; - } - - return 0; -} - -int _cc110x_get_option(netdev_t *dev, netdev_opt_t opt, void *value, size_t *value_len) -{ - if (dev != &cc110x_dev) { - return -ENODEV; - } - - switch (opt) { - case NETDEV_OPT_CHANNEL: - if (*value_len == 0) { - return -EOVERFLOW; - } - if (*value_len > sizeof(uint8_t)) { - *value_len = sizeof(uint8_t); - } - *((uint8_t *)value) = cc110x_get_channel(); - break; - case NETDEV_OPT_ADDRESS: - if (*value_len < sizeof(radio_address_t)) { - return -EOVERFLOW; - } - if (*value_len > sizeof(uint8_t)) { - *value_len = sizeof(uint8_t); - } - *((uint8_t *)value) = (uint8_t) cc110x_get_address(); - break; - case NETDEV_OPT_PROTO: - if (*value_len < sizeof(netdev_proto_t)) { - return -EOVERFLOW; - } - if (*value_len > sizeof(netdev_proto_t)) { - *value_len = sizeof(netdev_proto_t); - } - *((netdev_proto_t *)value) = NETDEV_PROTO_CC110X; - break; - case NETDEV_OPT_MAX_PACKET_SIZE: - if (*value_len == 0) { - return -EOVERFLOW; - } - if (*value_len > sizeof(uint8_t)) { - *value_len = sizeof(uint8_t); - } - *((uint8_t *)value) = PACKET_LENGTH; - break; - default: - return -ENOTSUP; - } - - return 0; -} - -int _cc110x_set_option(netdev_t *dev, netdev_opt_t opt, void *value, size_t value_len) -{ - if (dev != &cc110x_dev) { - return -ENODEV; - } - - switch (opt) { - case NETDEV_OPT_CHANNEL: - if (value_len != sizeof(uint8_t)) { - return -EOVERFLOW; - } - if (cc110x_set_channel(*((uint8_t *)value)) == -1) { - return -EINVAL; - } - break; - case NETDEV_OPT_ADDRESS: - /* leaves room for optimization */ - if (value_len > sizeof(radio_address_t)) { - return -EOVERFLOW; - } - radio_address_t temp_address; - if (value_len == sizeof(uint8_t)) { - temp_address = ((radio_address_t)(*((uint8_t *)value))); - } - else { - temp_address = *((radio_address_t *)value); - } - if (!cc110x_set_address(temp_address)) { - return -EINVAL; - } - break; - default: - return -ENOTSUP; - } - - return 0; -} - -int _cc110x_get_state(netdev_t *dev, netdev_state_t *state) -{ - if (dev != &cc110x_dev) { - return -ENODEV; - } - - switch(radio_state) { - case RADIO_IDLE: - *state = NETDEV_STATE_POWER_IDLE; - break; - case RADIO_SEND_BURST: - *state = NETDEV_STATE_TX_BURST; - break; - case RADIO_RX: - *state = NETDEV_STATE_RX_MODE; - break; - case RADIO_UNKNOWN: - case RADIO_PWD: - default: - *state = NETDEV_STATE_POWER_OFF; - break; - } - - return 0; -} - -int _cc110x_set_state(netdev_t *dev, netdev_state_t state) -{ - if (dev != &cc110x_dev) { - return -ENODEV; - } - - switch (state) { - case NETDEV_STATE_POWER_OFF: - gpio_irq_disable(CC110X_GDO2); - cc110x_switch_to_pwd(); - break; - case NETDEV_STATE_RX_MODE: - gpio_irq_enable(CC110X_GDO2); - cc110x_setup_rx_mode(); - break; - default: - return -ENOTSUP; - } - - return 0; -} - -void _cc110x_event(netdev_t *dev, uint32_t event_type) -{ - (void)dev; - (void)event_type; -} - -const netdev_driver_t cc110x_net_driver = { - cc110x_initialize, - _cc110x_send_data, - _cc110x_add_rcv_data_cb, - _cc110x_rem_rcv_data_cb, - _cc110x_get_option, - _cc110x_set_option, - _cc110x_get_state, - _cc110x_set_state, - _cc110x_event, -}; - -netdev_t cc110x_dev = {NETDEV_TYPE_BASE, &cc110x_net_driver, 0}; -#else -netdev_t cc110x_dev = {NETDEV_TYPE_BASE, 0, 0}; -#endif /* MODULE_NETDEV_BASE */ diff --git a/drivers/cc110x/cc110x-rxtx.c b/drivers/cc110x/cc110x-rxtx.c deleted file mode 100644 index 1b31c863b8..0000000000 --- a/drivers/cc110x/cc110x-rxtx.c +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright (C) 2014 Freie Universität Berlin - * Copyright (C) 2013 INRIA - * - * 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 drivers_cc110x - * @{ - * @file - * @brief Functions for packet reception and transmission on cc110x devices - * - * @author Oliver Hahm - * @author Fabian Nack - * @} - */ -#include - -#include "cc110x.h" -#include "cc110x-internal.h" - -#include "periph/gpio.h" -#include "irq.h" - -#include "kernel_types.h" -#include "hwtimer.h" -#include "msg.h" -#include "transceiver.h" - -#include "cpu_conf.h" -#include "cpu.h" - -#ifdef MODULE_NETDEV_BASE -#include "netdev/base.h" - -netdev_rcv_data_cb_t cc110x_recv_cb = NULL; -#endif - -/* Internal function prototypes */ -static uint8_t receive_packet_variable(uint8_t *rxBuffer, radio_packet_length_t length); -static uint8_t receive_packet(uint8_t *rxBuffer, radio_packet_length_t length); - -/* Global variables */ -rx_buffer_t cc110x_rx_buffer[RX_BUF_SIZE]; /* RX buffer */ -volatile uint8_t rx_buffer_next; /* Next packet in RX queue */ - -void cc110x_rx_handler(void *args) -{ - uint8_t res = 0; - - /* Possible packet received, RX -> IDLE (0.1 us) */ - cc110x_statistic.packets_in++; - - res = receive_packet((uint8_t *)&(cc110x_rx_buffer[rx_buffer_next].packet), - sizeof(cc110x_packet_t)); - - if (res) { - /* If we are sending a burst, don't accept packets. - * Only ACKs are processed (for stopping the burst). - * Same if state machine is in TX lock. */ - if (radio_state == RADIO_SEND_BURST) { - cc110x_statistic.packets_in_while_tx++; - return; - } - - cc110x_rx_buffer[rx_buffer_next].rssi = rflags._RSSI; - cc110x_rx_buffer[rx_buffer_next].lqi = rflags._LQI; - cc110x_strobe(CC1100_SFRX); /* ...for flushing the RX FIFO */ - - /* Valid packet. After a wake-up, the radio should be in IDLE. - * So put CC110x to RX for WOR_TIMEOUT (have to manually put - * the radio back to sleep/WOR). */ - cc110x_write_reg(CC1100_MCSM2, 0x07); /* Configure RX_TIME (until end of packet) */ - cc110x_strobe(CC1100_SRX); - hwtimer_wait(IDLE_TO_RX_TIME); - radio_state = RADIO_RX; - -#ifdef MODULE_TRANSCEIVER - /* notify transceiver thread if any */ - if (transceiver_pid != KERNEL_PID_UNDEF) { - msg_t m; - m.type = (uint16_t) RCV_PKT_CC1100; - m.content.value = rx_buffer_next; - msg_send_int(&m, transceiver_pid); - } -#endif - -#ifdef MODULE_NETDEV_BASE - if (cc110x_recv_cb != NULL) { - cc110x_packet_t p = cc110x_rx_buffer[rx_buffer_next].packet; - cc110x_recv_cb(&cc110x_dev, &p.phy_src, sizeof(uint8_t), &p.address, - sizeof(uint8_t), p.data, p.length - CC1100_HEADER_LENGTH); - } -#endif - - /* shift to next buffer element */ - if (++rx_buffer_next == RX_BUF_SIZE) { - rx_buffer_next = 0; - } - - return; - } - else { - /* CRC false or RX buffer full -> clear RX FIFO in both cases */ - cc110x_strobe(CC1100_SIDLE); /* Switch to IDLE (should already be)... */ - cc110x_strobe(CC1100_SFRX); /* ...for flushing the RX FIFO */ - - /* If currently sending, exit here (don't go to RX/WOR) */ - if (radio_state == RADIO_SEND_BURST) { - cc110x_statistic.packets_in_while_tx++; - return; - } - - /* No valid packet, so go back to RX/WOR as soon as possible */ - cc110x_switch_to_rx(); - } -} - -static uint8_t receive_packet_variable(uint8_t *rxBuffer, radio_packet_length_t length) -{ - uint8_t status[2]; - - /* Any bytes available in RX FIFO? */ - if ((cc110x_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) { - uint8_t packetLength = 0; - - /* Read length byte (first byte in RX FIFO) */ - packetLength = cc110x_read_reg(CC1100_RXFIFO); - - /* Read data from RX FIFO and store in rxBuffer */ - if (packetLength <= length) { - uint8_t crc_ok = 0; - - /* Put length byte at first position in RX Buffer */ - rxBuffer[0] = packetLength; - - /* Read the rest of the packet */ - cc110x_readburst_reg(CC1100_RXFIFO, (char *) rxBuffer + 1, packetLength); - - /* Read the 2 appended status bytes (status[0] = RSSI, status[1] = LQI) */ - cc110x_readburst_reg(CC1100_RXFIFO, (char *)status, 2); - - /* Store RSSI value of packet */ - rflags._RSSI = status[I_RSSI]; - - /* MSB of LQI is the CRC_OK bit */ - crc_ok = (status[I_LQI] & CRC_OK) >> 7; - - if (!crc_ok) { - cc110x_statistic.packets_in_crc_fail++; - } - - /* Bit 0-6 of LQI indicates the link quality (LQI) */ - rflags._LQI = status[I_LQI] & LQI_EST; - - return crc_ok; - } - /* too many bytes in FIFO */ - else { - /* RX FIFO gets automatically flushed if return value is false */ - return 0; - } - } - /* no bytes in RX FIFO */ - else { - /* RX FIFO gets automatically flushed if return value is false */ - return 0; - } -} - -static uint8_t receive_packet(uint8_t *rxBuffer, radio_packet_length_t length) -{ - uint8_t pkt_len_cfg = cc110x_read_reg(CC1100_PKTCTRL0) & PKT_LENGTH_CONFIG; - - if (pkt_len_cfg == VARIABLE_PKTLEN) { - return receive_packet_variable(rxBuffer, length); - } - - /* Fixed packet length not supported. */ - /* RX FIFO get automatically flushed if return value is false */ - return 0; -} - -int8_t cc110x_send(cc110x_packet_t *packet) -{ - volatile uint32_t abort_count; - uint8_t size; - - radio_state = RADIO_SEND_BURST; - - /* - * Number of bytes to send is: - * length of phy payload (packet->length) - * + size of length field (1 byte) - */ - size = packet->length + 1; - - /* The number of bytes to be transmitted must be smaller - * or equal to PACKET_LENGTH (62 bytes). So the receiver - * can put the whole packet in its RX-FIFO (with appended - * packet status bytes).*/ - if (size > PACKET_LENGTH) { - return 0; - } - - packet->phy_src = cc110x_get_address(); - - /* Disable RX interrupt */ - gpio_irq_disable(CC110X_GDO2); - - /* Put CC110x in IDLE mode to flush the FIFO */ - cc110x_strobe(CC1100_SIDLE); - /* Flush TX FIFO to be sure it is empty */ - cc110x_strobe(CC1100_SFTX); - /* Write packet into TX FIFO */ - cc110x_writeburst_reg(CC1100_TXFIFO, (char *) packet, size); - /* Switch to TX mode */ - abort_count = 0; - unsigned int cpsr = disableIRQ(); - cc110x_strobe(CC1100_STX); - - /* Wait for GDO2 to be set -> sync word transmitted */ - while (gpio_read(CC110X_GDO2) == 0) { - abort_count++; - - if (abort_count > CC1100_SYNC_WORD_TX_TIME) { - /* Abort waiting. CC110x maybe in wrong mode */ - break; - } - } - - restoreIRQ(cpsr); - - /* Wait for GDO2 to be cleared -> end of packet */ - while (gpio_read(CC110X_GDO2) != 0); - - gpio_irq_enable(CC110X_GDO2); - cc110x_statistic.raw_packets_out++; - - /* Go to RX mode after TX */ - cc110x_switch_to_rx(); - - return size; -} diff --git a/drivers/cc110x_legacy/Makefile b/drivers/cc110x_legacy/Makefile deleted file mode 100644 index 22cd1d8282..0000000000 --- a/drivers/cc110x_legacy/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -DIRS = spi -ifneq (,$(filter chronos,$(BOARD))) - DIRS = -endif - -include $(RIOTBASE)/Makefile.base diff --git a/drivers/cc110x_legacy/cc110x-defaultSettings.c b/drivers/cc110x_legacy/cc110x-defaultSettings.c deleted file mode 100644 index 535ef1ea6b..0000000000 --- a/drivers/cc110x_legacy/cc110x-defaultSettings.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (C) 2013 INRIA - * - * 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 drivers_cc110x_legacy - * @{ - * - * @file - * @brief TI Chipcon CC110x default settings - * - * @author Thomas Hillebrandt - * @author Heiko Will - * @author Oliver Hahm - * @} - */ - -#include "cc110x_legacy.h" - -// Default PA table index (output power) -#define PATABLE (11) - -/** - * Usable, non overlapping channels and corresponding frequencies - * for use with CC1100. CHANNR is the register for selecting a channel. - * - * channel number | CHANNR | frequency [MHz] - * ----------------------------------------- - * 0 | 0 | 869.525 - * 1 | 10 | 871.61 - * 2 | 20 | 873.58 ~ seems to be bad (hang-ups with this channel) - * 3 | 30 | 875.61 - * 4 | 40 | 877.58 - * 5 | 50 | 879.61 - * 6 | 60 | 881.58 - * 7 | 70 | 883.61 - * 8 | 80 | 885.58 - * 9 | 90 | 887.61 - * 10 | 100 | 889.58 - * 11 | 110 | 891.57 - * 12 | 120 | 893.58 - * 13 | 130 | 895.61 - * 14 | 140 | 897.58 - * 15 | 150 | 899.57 - * 16 | 160 | 901.57 - * 17 | 170 | 903.61 - * 18 | 180 | 905.57 - * 19 | 190 | 907.57 - * 20 | 200 | 909.57 - * 21 | 210 | 911.57 - * 22 | 220 | 913.57 - * 23 | 230 | 915.61 - * 24 | 240 | 917.61 - */ - -// 400 kbps, MSK, X-tal: 26 MHz (Chip Revision F) -char cc110x_conf[] = { - 0x06, // IOCFG2 - 0x2E, // IOCFG1 - 0x0E, // IOCFG0 - 0x0F, // FIFOTHR - 0x9B, // SYNC1 - 0xAD, // SYNC0 - 0x3D, // PKTLEN (maximum value of packet length byte = 61) - 0x06, // PKTCTRL1 - 0x45, // PKTCTRL0 (variable packet length) - 0xFF, // ADDR - CC1100_DEFAULT_CHANNR * 10, // CHANNR - 0x0B, // FSCTRL1 - 0x00, // FSCTRL0 - 0x21, // FREQ2 - 0x71, // FREQ1 - 0x7A, // FREQ0 - 0x2D, // MDMCFG4 - 0xF8, // MDMCFG3 - 0x73, // MDMCFG2 - 0x42, // MDMCFG1 - 0xF8, // MDMCFG0 - 0x00, // DEVIATN - 0x07, // MCSM2 - 0x03, // MCSM1 - 0x18, // MCSM0 - 0x1D, // FOCCFG - 0x1C, // BSCFG - 0xC0, // AGCCTRL2 - 0x49, // AGCCTRL1, (old value was 0x49 -> made carrier sense less sensitive!) - // 0x47 - 7 dB above MAGN_TARGET setting - 0xB2, // AGCCTRL0 - 0x87, // WOREVT1 - 0x6B, // WOREVT0 - 0xF8, // WORCTRL - 0xB6, // FREND1 - 0x10, // FREND0 - 0xEA, // FSCAL3 - 0x2A, // FSCAL2 - 0x00, // FSCAL1 - 0x1F, // FSCAL0 - 0x00 // padding to 4 bytes -}; - -uint8_t pa_table_index = PATABLE; ///< Current PATABLE Index -uint8_t pa_table[] = { ///< PATABLE with available output powers - 0x00, ///< -52 dBm - 0x03, ///< -30 dBm - 0x0D, ///< -20 dBm - 0x1C, ///< -15 dBm - 0x34, ///< -10 dBm - 0x57, ///< - 5 dBm - 0x3F, ///< - 1 dBm - 0x8E, ///< 0 dBm - 0x85, ///< + 5 dBm - 0xCC, ///< + 7 dBm - 0xC6, ///< + 9 dBm - 0xC3 ///< +10 dBm -}; // If PATABLE is changed in size, adjust MAX_OUTPUT_POWER definition in CC1100 interface! diff --git a/drivers/cc110x_legacy/cc110x-internal.h b/drivers/cc110x_legacy/cc110x-internal.h deleted file mode 100644 index 70f92943e9..0000000000 --- a/drivers/cc110x_legacy/cc110x-internal.h +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (C) 2008 Freie Universität Berlin - * Copyright (C) 2013 INRIA - * - * 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 drivers_cc110x_legacy - * @{ - * - * @file - * @brief Driver internal constants for 110x chip configuration - * - * @author Thomas Hillebrandt - * @author Heiko Will - * @author Oliver Hahm - */ - -#ifndef CC1100_INTERNAL_H -#define CC1100_INTERNAL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define FIXED_PKTLEN (0x00) ///< Fixed length packets, length configured in PKTLEN register. -#define VARIABLE_PKTLEN (0x01) ///< Variable length packets, packet length configured by the first - ///< byte after synch word. - -/** - * @name Bitmasks for reading out status register values - * @{ - */ - -/** - * @brief Bitmask (=10000000) for reading CRC_OK. - * - * If CRC_OK == 1: CRC for received data OK (or CRC disabled). - * If CRC_OK == 0: CRC error in received data. - */ -#define CRC_OK (0x80) -/** - * @brief Bitmask (=01111111) for reading LQI_EST. - * - * The Link Quality Indicator estimates how easily a received signal can be demodulated. - */ -#define LQI_EST (0x7F) -#define I_RSSI (0x00) ///< Index 0 contains RSSI information (from optionally appended packet status bytes). -#define I_LQI (0x01) ///< Index 1 contains LQI & CRC_OK information (from optionally appended packet status bytes). -#define MARC_STATE (0x1F) ///< Bitmask (=00011111) for reading MARC_STATE in MARCSTATE status register. -#define CS (0x40) ///< Bitmask (=01000000) for reading CS (Carrier Sense) in PKTSTATUS status register. -#define PQT_REACHED (0x20) ///< Bitmask (=00100000) for reading PQT_REACHED (Preamble Quality reached) in PKTSTATUS status register. -#define CCA (0x10) ///< Bitmask (=00010000) for reading CCA (clear channel assessment) in PKTSTATUS status register. -#define SFD (0x08) ///< Bitmask (=00001000) for reading SFD (Sync word found) in PKTSTATUS status register. -#define GDO2 (0x04) ///< Bitmask (=00000100) for reading GDO2 (current value on GDO2 pin) in PKTSTATUS status register. -#define GDO1 (0x02) ///< Bitmask (=00000010) for reading GDO1 (current value on GDO1 pin) in PKTSTATUS status register. -#define GDO0 (0x01) ///< Bitmask (=00000001) for reading GDO0 (current value on GDO0 pin) in PKTSTATUS status register. -#define TXFIFO_UNDERFLOW (0x80) ///< Bitmask (=10000000) for reading TXFIFO_UNDERFLOW in TXBYTES status register. -#define BYTES_IN_TXFIFO (0x7F) ///< Bitmask (=01111111) for reading NUM_TXBYTES in TXBYTES status register. -#define RXFIFO_OVERFLOW (0xBF) ///< Bitmask (=10000000) for reading RXFIFO_OVERFLOW in RXBYTES status register. -#define BYTES_IN_RXFIFO (0xFF) ///< Bitmask (=01111111) for reading NUM_RXBYTES in RXBYTES status register. -/** @} */ - -/** - * @name Bitmasks for reading out configuration register values - * @{ - */ -#define PKT_LENGTH_CONFIG (0x03) ///< Bitmask (=00000011) for reading LENGTH_CONFIG in PKTCTRL0 configuration register. -/** @} */ - -/** - * @name Definitions to support burst/single access - * @{ - */ -#define CC1100_WRITE_BURST (0x40) ///< Offset for burst write. -#define CC1100_READ_SINGLE (0x80) ///< Offset for read single byte. -#define CC1100_READ_BURST (0xC0) ///< Offset for read burst. -#define CC1100_NOBYTE (0xFF) ///< No command (for reading). -/** @} */ - -/** - * @name Configuration Registers (47x) - * @{ - */ -#define CC1100_IOCFG2 (0x00) ///< GDO2 output pin configuration -#define CC1100_IOCFG1 (0x01) ///< GDO1 output pin configuration -#define CC1100_IOCFG0 (0x02) ///< GDO0 output pin configuration -#define CC1100_FIFOTHR (0x03) ///< RX FIFO and TX FIFO thresholds -#define CC1100_SYNC1 (0x04) ///< Sync word, high byte -#define CC1100_SYNC0 (0x05) ///< Sync word, low byte -#define CC1100_PKTLEN (0x06) ///< Packet length -#define CC1100_PKTCTRL1 (0x07) ///< Packet automation control -#define CC1100_PKTCTRL0 (0x08) ///< Packet automation control -#define CC1100_ADDR (0x09) ///< Device address -#define CC1100_CHANNR (0x0A) ///< Channel number -#define CC1100_FSCTRL1 (0x0B) ///< Frequency synthesizer control -#define CC1100_FSCTRL0 (0x0C) ///< Frequency synthesizer control -#define CC1100_FREQ2 (0x0D) ///< Frequency control word, high byte -#define CC1100_FREQ1 (0x0E) ///< Frequency control word, middle byte -#define CC1100_FREQ0 (0x0F) ///< Frequency control word, low byte -#define CC1100_MDMCFG4 (0x10) ///< Modem configuration -#define CC1100_MDMCFG3 (0x11) ///< Modem configuration -#define CC1100_MDMCFG2 (0x12) ///< Modem configuration -#define CC1100_MDMCFG1 (0x13) ///< Modem configuration -#define CC1100_MDMCFG0 (0x14) ///< Modem configuration -#define CC1100_DEVIATN (0x15) ///< Modem deviation setting -#define CC1100_MCSM2 (0x16) ///< Main Radio Control State Machine configuration -#define CC1100_MCSM1 (0x17) ///< Main Radio Control State Machine configuration -#define CC1100_MCSM0 (0x18) ///< Main Radio Control State Machine configuration -#define CC1100_FOCCFG (0x19) ///< Frequency Offset Compensation configuration -#define CC1100_BSCFG (0x1A) ///< Bit Synchronization configuration -#define CC1100_AGCCTRL2 (0x1B) ///< AGC control -#define CC1100_AGCCTRL1 (0x1C) ///< AGC control -#define CC1100_AGCCTRL0 (0x1D) ///< AGC control -#define CC1100_WOREVT1 (0x1E) ///< High byte Event 0 timeout -#define CC1100_WOREVT0 (0x1F) ///< Low byte Event 0 timeout -#define CC1100_WORCTRL (0x20) ///< Wake On Radio control -#define CC1100_FREND1 (0x21) ///< Front end RX configuration -#define CC1100_FREND0 (0x22) ///< Front end TX configuration -#define CC1100_FSCAL3 (0x23) ///< Frequency synthesizer calibration -#define CC1100_FSCAL2 (0x24) ///< Frequency synthesizer calibration -#define CC1100_FSCAL1 (0x25) ///< Frequency synthesizer calibration -#define CC1100_FSCAL0 (0x26) ///< Frequency synthesizer calibration -#define CC1100_RCCTRL1 (0x27) ///< RC oscillator configuration -#define CC1100_RCCTRL0 (0x28) ///< RC oscillator configuration -#define CC1100_FSTEST (0x29) ///< Frequency synthesizer calibration control -#define CC1100_PTEST (0x2A) ///< Production test -#define CC1100_AGCTEST (0x2B) ///< AGC test -#define CC1100_TEST2 (0x2C) ///< Various test settings -#define CC1100_TEST1 (0x2D) ///< Various test settings -#define CC1100_TEST0 (0x2E) ///< Various test settings -/** @} */ - -/** - * @name Strobe commands (14x) - * @{ - */ -#define CC1100_SRES (0x30) ///< Reset chip. -/** - * @brief Enable and calibrate frequency synthesizer (if MCSM0.FS_AUTOCAL=1). - * - * If in RX/TX: Go to a wait state where only the synthesizer is running (for quick RX / TX turnaround). - */ -#define CC1100_SFSTXON (0x31) -#define CC1100_SXOFF (0x32) ///< Turn off crystal oscillator. -#define CC1100_SCAL (0x33) ///< Calibrate frequency synthesizer and turn it off (enables quick start). -#define CC1100_SRX (0x34) ///< Enable RX. Perform calibration first if coming from IDLE and MCSM0.FS_AUTOCAL=1. -/** - * In IDLE state: Enable TX. Perform calibration first if MCSM0.FS_AUTOCAL=1. - * If in RX state and CCA is enabled: Only go to TX if channel is clear. - */ -#define CC1100_STX (0x35) -#define CC1100_SIDLE (0x36) ///< Exit RX / TX, turn off frequency synthesizer and exit WOR mode if applicable. -#define CC1100_SAFC (0x37) ///< Perform AFC adjustment of the frequency synthesizer -#define CC1100_SWOR (0x38) ///< Start automatic RX polling sequence (Wake-on-Radio) -#define CC1100_SPWD (0x39) ///< Enter power down mode when CSn goes high. -#define CC1100_SFRX (0x3A) ///< Flush the RX FIFO buffer (CC1100 should be in IDLE state). -#define CC1100_SFTX (0x3B) ///< Flush the TX FIFO buffer (CC1100 should be in IDLE state). -#define CC1100_SWORRST (0x3C) ///< Reset real time clock. -#define CC1100_SNOP (0x3D) ///< No operation. May be used to pad strobe commands to two bytes for simpler software. -/** @} */ - -/** - * @name Status registers (12x) - * @{ - */ -#define CC1100_PARTNUM (0x30) ///< Part number of CC1100. -#define CC1100_VERSION (0x31) ///< Current version number. -#define CC1100_FREQEST (0x32) ///< Frequency Offset Estimate. -#define CC1100_LQI (0x33) ///< Demodulator estimate for Link Quality. -#define CC1100_RSSI (0x34) ///< Received signal strength indication. -#define CC1100_MARCSTATE (0x35) ///< Control state machine state. -#define CC1100_WORTIME1 (0x36) ///< High byte of WOR timer. -#define CC1100_WORTIME0 (0x37) ///< Low byte of WOR timer. -#define CC1100_PKTSTATUS (0x38) ///< Current GDOx status and packet status. -#define CC1100_VCO_VC_DAC (0x39) ///< Current setting from PLL calibration module. -#define CC1100_TXBYTES (0x3A) ///< Underflow and number of bytes in the TX FIFO. -#define CC1100_RXBYTES (0x3B) ///< Overflow and number of bytes in the RX FIFO. -/** @} */ - -/** - * @name Multi byte registers - * @{ - */ -/** - * @brief Register for eight user selected output power settings. - * - * 3-bit FREND0.PA_POWER value selects the PATABLE entry to use. - */ -#define CC1100_PATABLE (0x3E) -#define CC1100_TXFIFO (0x3F) ///< TX FIFO: Write operations write to the TX FIFO (SB: +0x00; BURST: +0x40) -#define CC1100_RXFIFO (0x3F) ///< RX FIFO: Read operations read from the RX FIFO (SB: +0x80; BURST: +0xC0) -/** @} */ - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif diff --git a/drivers/cc110x_legacy/cc110x-rx.c b/drivers/cc110x_legacy/cc110x-rx.c deleted file mode 100644 index c8e92cfe95..0000000000 --- a/drivers/cc110x_legacy/cc110x-rx.c +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (C) 2009 Freie Universität Berlin - * Copyright (C) 2013 INRIA - * - * 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 drivers_cc110x_legacy - * @{ - * @file - * @brief Functions for packet reception on cc110x - * - * @author Oliver Hahm - * @} - */ - -#include "cc110x_legacy.h" -#include "cc110x-internal.h" - -#include "kernel_types.h" -#include "hwtimer.h" -#include "msg.h" -#include "transceiver.h" - -#include "cpu_conf.h" -#include "cpu.h" - -#ifdef DBG_IGNORE -#include -#include -#define IGN_MAX (10) - -radio_address_t ignored_addr[IGN_MAX]; -static uint8_t is_ignored(radio_address_t addr); -#endif - -static uint8_t receive_packet_variable(uint8_t *rxBuffer, radio_packet_length_t length); -static uint8_t receive_packet(uint8_t *rxBuffer, radio_packet_length_t length); - -rx_buffer_t cc110x_rx_buffer[RX_BUF_SIZE]; ///< RX buffer -volatile uint8_t rx_buffer_next; ///< Next packet in RX queue - -void cc110x_rx_handler(void) -{ - uint8_t res = 0; - - /* Possible packet received, RX -> IDLE (0.1 us) */ - rflags.CAA = 0; - rflags.MAN_WOR = 0; - cc110x_statistic.packets_in++; - - res = receive_packet((uint8_t *)&(cc110x_rx_buffer[rx_buffer_next].packet), sizeof(cc110x_packet_t)); - - if (res) { - /* If we are sending a burst, don't accept packets. - * Only ACKs are processed (for stopping the burst). - * Same if state machine is in TX lock. */ - if (radio_state == RADIO_SEND_BURST || rflags.TX) { - cc110x_statistic.packets_in_while_tx++; - return; - } - - cc110x_rx_buffer[rx_buffer_next].rssi = rflags._RSSI; - cc110x_rx_buffer[rx_buffer_next].lqi = rflags._LQI; - cc110x_strobe(CC1100_SFRX); /* ...for flushing the RX FIFO */ - - /* Valid packet. After a wake-up, the radio should be in IDLE. - * So put CC1100 to RX for WOR_TIMEOUT (have to manually put - * the radio back to sleep/WOR). */ - //cc110x_spi_write_reg(CC1100_MCSM0, 0x08); /* Turn off FS-Autocal */ - cc110x_write_reg(CC1100_MCSM2, 0x07); /* Configure RX_TIME (until end of packet) */ - cc110x_strobe(CC1100_SRX); - hwtimer_wait(IDLE_TO_RX_TIME); - radio_state = RADIO_RX; - -#ifdef DBG_IGNORE - - if (is_ignored(cc110x_rx_buffer[rx_buffer_next].packet.phy_src)) { - LED_RED_TOGGLE; - return; - } - -#endif - - /* notify transceiver thread if any */ - if (transceiver_pid != KERNEL_PID_UNDEF) { - msg_t m; - m.type = (uint16_t) RCV_PKT_CC1100; - m.content.value = rx_buffer_next; - msg_send_int(&m, transceiver_pid); - } - - /* shift to next buffer element */ - if (++rx_buffer_next == RX_BUF_SIZE) { - rx_buffer_next = 0; - } - - return; - } - else { - /* No ACK received so TOF is unpredictable */ - rflags.TOF = 0; - - /* CRC false or RX buffer full -> clear RX FIFO in both cases */ - cc110x_strobe(CC1100_SIDLE); /* Switch to IDLE (should already be)... */ - cc110x_strobe(CC1100_SFRX); /* ...for flushing the RX FIFO */ - - /* If packet interrupted this nodes send call, - * don't change anything after this point. */ - if (radio_state == RADIO_AIR_FREE_WAITING) { - cc110x_strobe(CC1100_SRX); - hwtimer_wait(IDLE_TO_RX_TIME); - return; - } - - /* If currently sending, exit here (don't go to RX/WOR) */ - if (radio_state == RADIO_SEND_BURST) { - cc110x_statistic.packets_in_while_tx++; - return; - } - - /* No valid packet, so go back to RX/WOR as soon as possible */ - cc110x_switch_to_rx(); - } -} - - -static uint8_t receive_packet_variable(uint8_t *rxBuffer, radio_packet_length_t length) -{ - uint8_t status[2]; - uint8_t packetLength = 0; - - /* Any bytes available in RX FIFO? */ - if ((cc110x_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) { - /* Read length byte (first byte in RX FIFO) */ - cc110x_read_fifo((char *) &packetLength, 1); - - /* Read data from RX FIFO and store in rxBuffer */ - if (packetLength <= length) { - /* Put length byte at first position in RX Buffer */ - rxBuffer[0] = packetLength; - - /* Read the rest of the packet */ - //cc110x_readburst_reg(CC1100_RXFIFO, (char*)rxBuffer+1, packetLength); - cc110x_read_fifo((char *) rxBuffer + 1, packetLength); - - /* Read the 2 appended status bytes (status[0] = RSSI, status[1] = LQI) */ - cc110x_readburst_reg(CC1100_RXFIFO, (char *)status, 2); - - /* Store RSSI value of packet */ - rflags._RSSI = status[I_RSSI]; - - /* MSB of LQI is the CRC_OK bit */ - rflags.CRC_STATE = (status[I_LQI] & CRC_OK) >> 7; - - if (!rflags.CRC_STATE) { - cc110x_statistic.packets_in_crc_fail++; - } - - /* Bit 0-6 of LQI indicates the link quality (LQI) */ - rflags._LQI = status[I_LQI] & LQI_EST; - - return rflags.CRC_STATE; - } - /* too many bytes in FIFO */ - else { - /* RX FIFO get automatically flushed if return value is false */ - return 0; - } - } - /* no bytes in RX FIFO */ - else { - /* RX FIFO get automatically flushed if return value is false */ - return 0; - } -} - -static uint8_t receive_packet(uint8_t *rxBuffer, radio_packet_length_t length) -{ - uint8_t pkt_len_cfg = cc110x_read_reg(CC1100_PKTCTRL0) & PKT_LENGTH_CONFIG; - - if (pkt_len_cfg == VARIABLE_PKTLEN) { - return receive_packet_variable(rxBuffer, length); - } - - /* Fixed packet length not supported. */ - /* RX FIFO get automatically flushed if return value is false */ - return 0; -} - -#ifdef DBG_IGNORE -void cc110x_init_ignore(void) -{ - memset(ignored_addr, 0, IGN_MAX * sizeof(radio_address_t)); -} - -uint8_t cc110x_add_ignored(radio_address_t addr) -{ - uint8_t i = 0; - - while ((i < IGN_MAX) && ignored_addr[i++]) { - printf("i: %hu\n", i); - } - - if (i > IGN_MAX) { - return 0; - } - - ignored_addr[i - 1] = addr; - return 1; -} - -static uint8_t is_ignored(radio_address_t addr) -{ - uint8_t i; - - for (i = 0; i < IGN_MAX; i++) { - if (ignored_addr[i] == addr) { - return 1; - } - } - - return 0; -} -#endif diff --git a/drivers/cc110x_legacy/cc110x-tx.c b/drivers/cc110x_legacy/cc110x-tx.c deleted file mode 100644 index 482378ba71..0000000000 --- a/drivers/cc110x_legacy/cc110x-tx.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2009 Freie Universität Berlin - * Copyright (C) 2013 INRIA - * - * 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 drivers_cc110x_legacy - * @{ - * @file - * @brief Functions for packet transmission on cc110x - * - * @author Oliver Hahm - * @} - */ -#include - -#include "cc110x_legacy.h" -#include "cc110x-internal.h" - -#include "irq.h" - -int8_t cc110x_send(cc110x_packet_t *packet) -{ - volatile uint32_t abort_count; - uint8_t size; - /* TODO: burst sending */ - radio_state = RADIO_SEND_BURST; - rflags.LL_ACK = 0; - - /* - * Number of bytes to send is: - * length of phy payload (packet->length) - * + size of length field (1 byte) - */ - size = packet->length + 1; - - /* The number of bytes to be transmitted must be smaller - * or equal to PACKET_LENGTH (62 bytes). So the receiver - * can put the whole packet in its RX-FIFO (with appended - * packet status bytes).*/ - if (size > PACKET_LENGTH) { - return 0; - } - - packet->phy_src = cc110x_get_address(); - - /* Disables RX interrupt etc. */ - cc110x_before_send(); - - /* But CC1100 in IDLE mode to flush the FIFO */ - cc110x_strobe(CC1100_SIDLE); - /* Flush TX FIFO to be sure it is empty */ - cc110x_strobe(CC1100_SFTX); - /* Write packet into TX FIFO */ - cc110x_writeburst_reg(CC1100_TXFIFO, (char *) packet, size); - /* Switch to TX mode */ - abort_count = 0; - unsigned int cpsr = disableIRQ(); - cc110x_strobe(CC1100_STX); - - /* Wait for GDO2 to be set -> sync word transmitted */ - while (cc110x_get_gdo2() == 0) { - abort_count++; - - if (abort_count > CC1100_SYNC_WORD_TX_TIME) { - /* Abort waiting. CC1100 maybe in wrong mode */ - /* e.g. sending preambles for always */ - puts("[CC1100 TX] fatal error\n"); - break; - } - } - - restoreIRQ(cpsr); - - /* Wait for GDO2 to be cleared -> end of packet */ - while (cc110x_get_gdo2() != 0); - - - /* Experimental - TOF Measurement */ - cc110x_after_send(); - cc110x_statistic.raw_packets_out++; - - /* Store number of transmission retries */ - rflags.TX = 0; - - /* Go to mode after TX (CONST_RX -> RX, WOR -> WOR) */ - cc110x_switch_to_rx(); - - return size; -} diff --git a/drivers/cc110x_legacy/cc110x.c b/drivers/cc110x_legacy/cc110x.c deleted file mode 100644 index e22d852777..0000000000 --- a/drivers/cc110x_legacy/cc110x.c +++ /dev/null @@ -1,424 +0,0 @@ -/* - * Copyright (C) 2013 Freie Universität Berlin - * Copyright (C) 2013 INRIA - * - * 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 drivers_cc110x_legacy - * @{ - * @file - * @brief Basic functionality of cc110x driver - * - * @author Oliver Hahm - * @} - */ -#include "cc110x_legacy.h" -#include "cc110x-internal.h" - -#include "hwtimer.h" -#include "config.h" -#include "cpu.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -/* some externals */ -extern uint8_t pa_table[]; ///< PATABLE with available output powers -extern uint8_t pa_table_index; ///< Current PATABLE Index - -/* global variables */ - -cc110x_statistic_t cc110x_statistic; - -volatile cc110x_flags rflags; ///< Radio control flags -volatile uint8_t radio_state = RADIO_UNKNOWN; ///< Radio state - -static radio_address_t radio_address; ///< Radio address -static uint8_t radio_channel; ///< Radio channel - -/* internal function prototypes */ -static int rd_set_mode(int mode); -static void reset(void); -static void power_up_reset(void); -static void write_register(uint8_t r, uint8_t value); - -/*---------------------------------------------------------------------------* - * Radio Driver API * - *---------------------------------------------------------------------------*/ -void cc110x_init(kernel_pid_t tpid) -{ - transceiver_pid = tpid; - DEBUG("Transceiver PID: %" PRIkernel_pid "\n", transceiver_pid); - - rx_buffer_next = 0; - -#ifdef MODULE_CC110X_SPI - /* Initialize SPI */ - cc110x_spi_init(); -#endif - - /* Load driver & reset */ - power_up_reset(); - - /* Write configuration to configuration registers */ - cc110x_writeburst_reg(0x00, cc110x_conf, CC1100_CONF_SIZE); - - /* Write PATABLE (power settings) */ - cc110x_write_reg(CC1100_PATABLE, pa_table[pa_table_index]); - - /* Initialize Radio Flags */ - rflags._RSSI = 0x00; - rflags.LL_ACK = 0; - rflags.CAA = 0; - rflags.CRC_STATE = 0; - rflags.SEQ = 0; - rflags.MAN_WOR = 0; - rflags.KT_RES_ERR = 0; - rflags.TX = 0; - rflags.WOR_RST = 0; - - /* Set default channel number */ -#ifdef MODULE_CONFIG - cc110x_set_config_channel(sysconfig.radio_channel); -#else - cc110x_set_channel(CC1100_DEFAULT_CHANNR); -#endif - DEBUG("CC1100 initialized and set to channel %i\n", radio_channel); - - /* Switch to desired mode (WOR or RX) */ - rd_set_mode(RADIO_MODE_ON); - -#ifdef DBG_IGNORE - cc110x_init_ignore(); -#endif -} - -void cc110x_disable_interrupts(void) -{ - cc110x_gdo2_disable(); - cc110x_gdo0_disable(); -} - -void cc110x_gdo0_irq(void) -{ - /* Air was not free -> Clear CCA flag */ - rflags.CAA = false; - /* Disable carrier sense detection (GDO0 interrupt) */ - cc110x_gdo0_disable(); -} - -void cc110x_gdo2_irq(void) -{ - cc110x_rx_handler(); -} - -uint8_t cc110x_get_buffer_pos(void) -{ - return (rx_buffer_next - 1); -} - -radio_address_t cc110x_get_address(void) -{ - return radio_address; -} - -radio_address_t cc110x_set_address(radio_address_t address) -{ - if ((address < MIN_UID) || (address > MAX_UID)) { - return 0; - } - - uint8_t id = (uint8_t) address; - - if (radio_state != RADIO_UNKNOWN) { - write_register(CC1100_ADDR, id); - } - - radio_address = id; - return radio_address; -} - -#ifdef MODULE_CONFIG -radio_address_t cc110x_set_config_address(radio_address_t address) -{ - radio_address_t a = cc110x_set_address(address); - - if (a) { - sysconfig.radio_address = a; - } - - config_save(); - return a; -} -#endif - -void cc110x_set_monitor(uint8_t mode) -{ - if (mode) { - write_register(CC1100_PKTCTRL1, (0x04)); - } - else { - write_register(CC1100_PKTCTRL1, (0x06)); - } -} - -void cc110x_setup_rx_mode(void) -{ - /* Stay in RX mode until end of packet */ - cc110x_write_reg(CC1100_MCSM2, 0x07); - cc110x_switch_to_rx(); -} - -void cc110x_switch_to_rx(void) -{ - radio_state = RADIO_RX; - cc110x_strobe(CC1100_SRX); -} - -void cc110x_wakeup_from_rx(void) -{ - if (radio_state != RADIO_RX) { - return; - } - - DEBUG("CC1100 going to idle\n"); - cc110x_strobe(CC1100_SIDLE); - radio_state = RADIO_IDLE; -} - -char *cc110x_get_marc_state(void) -{ - uint8_t state; - - /* Save old radio state */ - uint8_t old_state = radio_state; - - /* Read content of status register */ - state = cc110x_read_status(CC1100_MARCSTATE) & MARC_STATE; - - /* Make sure in IDLE state. - * Only goes to IDLE if state was RX/WOR */ - cc110x_wakeup_from_rx(); - - /* Have to put radio back to WOR/RX if old radio state - * was WOR/RX, otherwise no action is necessary */ - if (old_state == RADIO_WOR || old_state == RADIO_RX) { - cc110x_switch_to_rx(); - } - - switch(state) { - /* Note: it is not possible to read back the SLEEP or XOFF state numbers - * because setting CSn low will make the chip enter the IDLE mode from the - * SLEEP (0) or XOFF (2) states. */ - case 1: - return "IDLE"; - - case 3: - case 4: - case 5: - return "MANCAL"; - - case 6: - case 7: - return "FS_WAKEUP"; - - case 8: - case 12: - return "CALIBRATE"; - - case 9: - case 10: - case 11: - return "SETTLING"; - - case 13: - case 14: - case 15: - return "RX"; - - case 16: - return "TXRX_SETTLING"; - - case 17: - return "RXFIFO_OVERFLOW"; - - case 18: - return "FSTXON"; - - case 19: - case 20: - return "TX"; - - case 21: - return "RXTX_SETTLING"; - - case 22: - return "TXFIFO_UNDERFLOW"; - - default: - return "UNKNOWN"; - } -} - -char *cc110x_state_to_text(uint8_t state) -{ - switch(state) { - case RADIO_UNKNOWN: - return "Unknown"; - - case RADIO_AIR_FREE_WAITING: - return "CS"; - - case RADIO_WOR: - return "WOR"; - - case RADIO_IDLE: - return "IDLE"; - - case RADIO_SEND_BURST: - return "TX BURST"; - - case RADIO_RX: - return "RX"; - - case RADIO_SEND_ACK: - return "TX ACK"; - - case RADIO_PWD: - return "PWD"; - - default: - return "unknown"; - } -} - -void cc110x_print_config(void) -{ - printf("Current radio state: %s\r\n", cc110x_state_to_text(radio_state)); - printf("Current MARC state: %s\r\n", cc110x_get_marc_state()); - printf("Current channel number: %u\r\n", radio_channel); -} - -void cc110x_switch_to_pwd(void) -{ - DEBUG("[cc110x_legacy] switching to powerdown\n"); - cc110x_wakeup_from_rx(); - cc110x_strobe(CC1100_SPWD); - radio_state = RADIO_PWD; -} - -/*---------------------------------------------------------------------------*/ -int16_t cc110x_set_channel(uint8_t channr) -{ - uint8_t state = cc110x_read_status(CC1100_MARCSTATE) & MARC_STATE; - - if ((state != 1) && (channr > MAX_CHANNR)) { - return -1; - } - - write_register(CC1100_CHANNR, channr * 10); - radio_channel = channr; - return radio_channel; -} - -#ifdef MODULE_CONFIG -int16_t cc110x_set_config_channel(uint8_t channr) -{ - int16_t c = cc110x_set_channel(channr); - - if (c) { - sysconfig.radio_channel = c; - } - - config_save(); - return c; -} -#endif - -int16_t cc110x_get_channel(void) -{ - return radio_channel; -} - - -/*--------------------------------------------------------------------------- - * CC1100 reset functionality - *---------------------------------------------------------------------------*/ - -static void reset(void) -{ - cc110x_wakeup_from_rx(); -#ifdef MODULE_CC110x_SPI - cc110x_spi_select(); -#endif - cc110x_strobe(CC1100_SRES); - hwtimer_wait(RTIMER_TICKS(100)); -} - -static void power_up_reset(void) -{ -#ifdef MODULE_CC110x_SPI - cc110x_spi_unselect(); - cc110x_spi_cs(); - cc110x_spi_unselect(); -#endif - hwtimer_wait(RESET_WAIT_TIME); - reset(); - radio_state = RADIO_IDLE; -} - -static void write_register(uint8_t r, uint8_t value) -{ - /* Save old radio state */ - uint8_t old_state = radio_state; - - /* Wake up from WOR/RX (if in WOR/RX, else no effect) */ - cc110x_wakeup_from_rx(); - cc110x_write_reg(r, value); - - /* Have to put radio back to WOR/RX if old radio state - * was WOR/RX, otherwise no action is necessary */ - if ((old_state == RADIO_WOR) || (old_state == RADIO_RX)) { - cc110x_switch_to_rx(); - } -} - -static int rd_set_mode(int mode) -{ - int result; - - /* Get current radio mode */ - if ((radio_state == RADIO_UNKNOWN) || (radio_state == RADIO_PWD)) { - result = RADIO_MODE_OFF; - } - else { - result = RADIO_MODE_ON; - } - - switch(mode) { - case RADIO_MODE_ON: - DEBUG("Enabling rx mode\n"); - cc110x_init_interrupts(); /* Enable interrupts */ - cc110x_setup_rx_mode(); /* Set chip to desired mode */ - break; - - case RADIO_MODE_OFF: - cc110x_disable_interrupts(); /* Disable interrupts */ - cc110x_switch_to_pwd(); /* Set chip to power down mode */ - break; - - case RADIO_MODE_GET: - - /* do nothing, just return current mode */ - default: - /* do nothing */ - break; - } - - /* Return previous mode */ - return result; -} diff --git a/drivers/cc110x_legacy/spi/Makefile b/drivers/cc110x_legacy/spi/Makefile deleted file mode 100644 index d6ca73f655..0000000000 --- a/drivers/cc110x_legacy/spi/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -MODULE =cc110x_spi - -INCLUDES += -I$(RIOTBASE)/drivers/cc110x_legacy - -include $(RIOTBASE)/Makefile.base diff --git a/drivers/cc110x_legacy/spi/cc110x_spi.c b/drivers/cc110x_legacy/spi/cc110x_spi.c deleted file mode 100644 index 58619c0468..0000000000 --- a/drivers/cc110x_legacy/spi/cc110x_spi.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. - * - * 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 drivers_cc110x_legacy - * @{ - * - * @file - * @brief TI Chipcon CC1100 SPI driver - * - * @author Thomas Hillebrandt - * @author Heiko Will - * @} - */ - -#include - -#include "cc110x_legacy.h" -#include "cc110x-internal.h" - -#include "irq.h" - -/*---------------------------------------------------------------------------*/ -// CC1100 SPI access -/*---------------------------------------------------------------------------*/ - -uint8_t cc110x_writeburst_reg(uint8_t addr, char *src, uint8_t count) -{ - int i = 0; - unsigned int cpsr = disableIRQ(); - cc110x_spi_select(); - cc110x_txrx(addr | CC1100_WRITE_BURST); - - while (i < count) { - cc110x_txrx(src[i]); - i++; - } - - cc110x_spi_unselect(); - restoreIRQ(cpsr); - return count; -} - -void cc110x_readburst_reg(uint8_t addr, char *buffer, uint8_t count) -{ - int i = 0; - unsigned int cpsr = disableIRQ(); - cc110x_spi_select(); - cc110x_txrx(addr | CC1100_READ_BURST); - - while (i < count) { - buffer[i] = cc110x_txrx(CC1100_NOBYTE); - i++; - } - - cc110x_spi_unselect(); - restoreIRQ(cpsr); -} - -void cc110x_read_fifo(char *buffer, uint8_t count) -{ - cc110x_readburst_reg(CC1100_RXFIFO, buffer, count); -} - -void cc110x_write_reg(uint8_t addr, uint8_t value) -{ - unsigned int cpsr = disableIRQ(); - cc110x_spi_select(); - cc110x_txrx(addr); - cc110x_txrx(value); - cc110x_spi_unselect(); - restoreIRQ(cpsr); -} - -uint8_t cc110x_read_reg(uint8_t addr) -{ - uint8_t result; - unsigned int cpsr = disableIRQ(); - cc110x_spi_select(); - cc110x_txrx(addr | CC1100_READ_SINGLE); - result = cc110x_txrx(CC1100_NOBYTE); - cc110x_spi_unselect(); - restoreIRQ(cpsr); - return result; -} - -uint8_t cc110x_read_status(uint8_t addr) -{ - uint8_t result; - unsigned int cpsr = disableIRQ(); - cc110x_spi_select(); - cc110x_txrx(addr | CC1100_READ_BURST); - result = cc110x_txrx(CC1100_NOBYTE); - cc110x_spi_unselect(); - restoreIRQ(cpsr); - return result; -} - -uint8_t cc110x_strobe(uint8_t c) -{ - uint8_t result; - unsigned int cpsr = disableIRQ(); - cc110x_spi_select(); - result = cc110x_txrx(c); - cc110x_spi_unselect(); - restoreIRQ(cpsr); - return result; -} diff --git a/drivers/cc110x_legacy_csma/Makefile b/drivers/cc110x_legacy_csma/Makefile deleted file mode 100644 index 48422e909a..0000000000 --- a/drivers/cc110x_legacy_csma/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(RIOTBASE)/Makefile.base diff --git a/drivers/cc110x_legacy_csma/arch_cc1100.h b/drivers/cc110x_legacy_csma/arch_cc1100.h deleted file mode 100644 index da88e0ec31..0000000000 --- a/drivers/cc110x_legacy_csma/arch_cc1100.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. - * - * 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. - */ - -/** - * @file - * @ingroup LPC2387 - * @brief CC1100 LPC2387 dependend functions - * - * @author Heiko Will - * @version $Revision: 1775 $ - * - * @note $Id: arch_cc1100.h 1775 2010-01-26 09:37:03Z hillebra $ - */ - -#ifndef ARCH_CC1100_H -#define ARCH_CC1100_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -uint8_t cc110x_txrx(uint8_t c); - -void cc110x_gdo0_enable(void); -void cc110x_gdo0_disable(void); -void cc110x_gdo2_enable(void); -void cc110x_gdo2_disable(void); -void cc110x_init_interrupts(void); - -void cc110x_before_send(void); -void cc110x_after_send(void); - -#ifdef __cplusplus -} -#endif - -#endif /* ARCH_CC1100_H */ diff --git a/drivers/cc110x_legacy_csma/cc1100-csmaca-mac.c b/drivers/cc110x_legacy_csma/cc1100-csmaca-mac.c deleted file mode 100644 index 753ff6dd4c..0000000000 --- a/drivers/cc110x_legacy_csma/cc1100-csmaca-mac.c +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. - * - * 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. - */ - -/** - * @file - * @ingroup dev_cc110x_legacy_csma - * @brief ScatterWeb MSB-A2 mac-layer - * - * @author Thomas Hillebrandt - * @author Heiko Will - * @version $Revision: 2128 $ - * - * @note $Id: cc1100-csmaca-mac.c 2128 2010-05-12 12:07:59Z hillebra $ - */ - -#include -#include -#include - -#include "cc1100.h" -#include "cc1100_phy.h" -#include "cc1100-csmaca-mac.h" -#include "protocol-multiplex.h" - -#include "hwtimer.h" -#include "vtimer.h" - -/*---------------------------------------------------------------------------*/ - -#define COLLISION_STATE_INITIAL 1 -#define COLLISION_STATE_MEASURE 2 -#define COLLISION_STATE_KEEP 3 - -static uint32_t send_csmaca_calls = 0; -static uint32_t send_csmaca_calls_cs_timeout = 0; -static int collision_count; -static double collisions_per_sec = 0; -static int collision_state = COLLISION_STATE_INITIAL; -static timex_t collision_measurement_start; - -static volatile int cs_hwtimer_id = -1; -static volatile int cs_timeout_flag = 0; - -/*---------------------------------------------------------------------------*/ -static void cs_timeout_cb(void *ptr) -{ - (void) ptr; - cs_timeout_flag = 1; -} - -/*---------------------------------------------------------------------------*/ -int cc1100_send_csmaca(radio_address_t address, protocol_t protocol, int priority, char *payload, radio_packet_length_t payload_len) -{ - uint16_t min_window_size; - uint16_t max_window_size; - uint16_t difs; - uint16_t slottime; - - switch(priority) { - case PRIORITY_ALARM: - min_window_size = PRIO_ALARM_MIN_WINDOW_SIZE; - max_window_size = PRIO_ALARM_MAX_WINDOW_SIZE; - difs = PRIO_ALARM_DIFS; - slottime = PRIO_ALARM_SLOTTIME; - break; - - case PRIORITY_WARNING: - min_window_size = PRIO_WARN_MIN_WINDOW_SIZE; - max_window_size = PRIO_WARN_MAX_WINDOW_SIZE; - difs = PRIO_WARN_DIFS; - slottime = PRIO_WARN_SLOTTIME; - break; - - default: - min_window_size = PRIO_DATA_MIN_WINDOW_SIZE; - max_window_size = PRIO_DATA_MAX_WINDOW_SIZE; - difs = PRIO_DATA_DIFS; - slottime = PRIO_DATA_SLOTTIME; - } - - /* Calculate collisions per second */ - if (collision_state == COLLISION_STATE_INITIAL) { - vtimer_now(&collision_measurement_start); - collision_count = 0; - collisions_per_sec = 0; - collision_state = COLLISION_STATE_MEASURE; - } - else if (collision_state == COLLISION_STATE_MEASURE) { - timex_t now; - vtimer_now(&now); - timex_t timespan = timex_sub(now, collision_measurement_start); - - if (timex_cmp(timespan, timex_set(1, 0)) > 0) { - collisions_per_sec = (collision_count * 1000000) / (double) timex_uint64(timespan); - - if (collisions_per_sec > 0.5 && collisions_per_sec <= 2.2) { - timex_t now; - vtimer_now(&now); - collision_measurement_start = now; - collision_state = COLLISION_STATE_KEEP; - } - else if (collisions_per_sec > 2.2) { - timex_t now; - vtimer_now(&now); - collision_measurement_start = now; - collision_state = COLLISION_STATE_KEEP; - } - else { - collision_state = COLLISION_STATE_INITIAL; - } - } - } - else if (collision_state == COLLISION_STATE_KEEP) { - timex_t now; - vtimer_now(&now); - timex_t timespan = timex_sub(now, collision_measurement_start); - - if (timex_cmp(timespan, timex_set(5, 0)) > 0) { - collision_state = COLLISION_STATE_INITIAL; - } - } - - /* Adjust initial window size according to collision rate */ - if (collisions_per_sec > 0.5 && collisions_per_sec <= 2.2) { - min_window_size *= 2; - } - else if (collisions_per_sec > 2.2) { - min_window_size *= 4; - } - - uint16_t windowSize = min_window_size; /* Start with window size of PRIO_XXX_MIN_WINDOW_SIZE */ - uint16_t backoff = 0; /* Backoff between 1 and windowSize */ - uint32_t total; /* Holds the total wait time before send try */ - uint32_t cs_timeout; /* Current carrier sense timeout value */ - - if (protocol == 0) { - return RADIO_INVALID_PARAM; /* Not allowed, protocol id must be greater zero */ - } - - cc1100_phy_mutex_lock(); /* Lock radio for exclusive access */ - - /* Get carrier sense timeout based on overall error rate till now */ - send_csmaca_calls++; - int fail_percentage = (send_csmaca_calls_cs_timeout * 100) / send_csmaca_calls; - - if (fail_percentage == 0) { - fail_percentage = 1; - } - - cs_timeout = CARRIER_SENSE_TIMEOUT / fail_percentage; - - if (cs_timeout < CARRIER_SENSE_TIMEOUT_MIN) { - cs_timeout = CARRIER_SENSE_TIMEOUT_MIN; - } - - cc1100_cs_init(); /* Initialize carrier sensing */ - -window: - - if (backoff != 0) { - goto cycle; /* If backoff was 0 */ - } - - windowSize *= 2; /* ...double the current window size */ - - if (windowSize > max_window_size) { - windowSize = max_window_size; /* This is the maximum size allowed */ - } - - backoff = rand() % windowSize; /* ...and choose new backoff */ - - backoff += (uint16_t) 1; -cycle: - cs_timeout_flag = 0; /* Carrier sense timeout flag */ - cs_hwtimer_id = hwtimer_set(cs_timeout, /* Set hwtimer to set CS timeout flag */ - cs_timeout_cb, NULL); - - while (cc1100_cs_read()) { /* Wait until air is free */ - if (cs_timeout_flag) { - send_csmaca_calls_cs_timeout++; -#ifndef CSMACA_MAC_AGGRESSIVE_MODE - cc1100_phy_mutex_unlock(); - cc1100_go_after_tx(); /* Go from RX to default mode */ - return RADIO_CS_TIMEOUT; /* Return immediately */ -#endif -#ifdef CSMACA_MAC_AGGRESSIVE_MODE - goto send; /* Send anyway */ -#endif - } - } - - hwtimer_remove(cs_hwtimer_id); /* Remove hwtimer */ - cc1100_cs_write_cca(1); /* Air is free now */ - cc1100_cs_set_enabled(true); - - if (cc1100_cs_read()) { - goto window; /* GDO0 triggers on rising edge, so */ - } - - /* test once after interrupt is enabled */ - if (backoff > 0) { - backoff--; /* Decrement backoff counter */ - } - - total = slottime; /* Calculate total wait time */ - total *= (uint32_t)backoff; /* Slot vector set */ - total += difs; /* ...and standard DIFS wait time */ - cs_timeout_flag = 0; /* Carrier sense timeout flag */ - cs_hwtimer_id = hwtimer_set(total, /* Set hwtimer to set CS timeout flag */ - cs_timeout_cb, NULL); - - while (!cs_timeout_flag - || !cc1100_cs_read_cca()) { /* Wait until timeout is finished */ - if (cc1100_cs_read_cca() == 0) { /* Is the air still free? */ - hwtimer_remove(cs_hwtimer_id); - goto window; /* No. Go back to new wait period. */ - } - } - - cc1100_cs_set_enabled(false); -#ifdef CSMACA_MAC_AGGRESSIVE_MODE -send: -#endif - int res = cc1100_send(address, protocol, priority, payload, payload_len); - - if (res < 0) { - collision_count++; - } - - return res; -} diff --git a/drivers/cc110x_legacy_csma/cc1100-csmaca-mac.h b/drivers/cc110x_legacy_csma/cc1100-csmaca-mac.h deleted file mode 100644 index dfe525054b..0000000000 --- a/drivers/cc110x_legacy_csma/cc1100-csmaca-mac.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. - * - * 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. - */ - -/** - * @file - * @ingroup dev_cc110x_legacy_csma - * @brief ScatterWeb MSB-A2 mac-layer - * - * @author Thomas Hillebrandt - * @author Heiko Will - * @version $Revision: 1999 $ - * - * @note $Id: cc1100-csmaca-mac.h 1999 2010-03-16 15:48:18Z hillebra $ - */ - -#ifndef CC1100_CSMACA_MAC_ -#define CC1100_CSMACA_MAC_ - -#include "cc1100-defaultSettings.h" - -#ifdef __cplusplus -extern "C" { -#endif - -//#define CSMACA_MAC_AGGRESSIVE_MODE // MAC aggressive mode on/off switch - -#define CARRIER_SENSE_TIMEOUT (200000) /**< Carrier Sense timeout ~ 2 seconds */ -#define CARRIER_SENSE_TIMEOUT_MIN (2000) /**< Minimum Carrier Sense timeout ~ 20 milliseconds */ -#define CS_TX_SWITCH_TIME (80) /**< Carrier Sense to TX switch time (measured ~ 350 us) */ - -/** - * @name CSMA backoff and wait times - * @brief All values are in ticks (x10 us) - * @{ - */ -#define PRIO_ALARM_DIFS (200) /**< DIFS for ALARM packets, the default wait time */ -#define PRIO_ALARM_SLOTTIME (CS_TX_SWITCH_TIME) /**< Time of one additional wait slot */ -#define PRIO_ALARM_MIN_WINDOW_SIZE (2) /**< Minimum window size of backoff algorithm */ -#define PRIO_ALARM_MAX_WINDOW_SIZE (8) /**< Maximum window size of backoff algorithm */ - -#define PRIO_WARN_DIFS (1000) /**< DIFS for WARN packets, the default wait time */ -#define PRIO_WARN_SLOTTIME (CS_TX_SWITCH_TIME) /**< Time of one additional wait slot */ -#define PRIO_WARN_MIN_WINDOW_SIZE (2) /**< Minimum window size of backoff algorithm */ -#define PRIO_WARN_MAX_WINDOW_SIZE (16) /**< Maximum window size of backoff algorithm */ - -#define PRIO_DATA_DIFS (2500) /**< DIFS for normal data packets, the default wait time */ -#define PRIO_DATA_SLOTTIME (CS_TX_SWITCH_TIME) /**< Time of one additional wait slot */ -#define PRIO_DATA_MIN_WINDOW_SIZE (4) /**< Minimum window size of backoff algorithm */ -#define PRIO_DATA_MAX_WINDOW_SIZE (32) /**< Maximum window size of backoff algorithm */ -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /*CC1100_CSMACA_MAC_*/ diff --git a/drivers/cc110x_legacy_csma/cc1100-defaultSettings.c b/drivers/cc110x_legacy_csma/cc1100-defaultSettings.c deleted file mode 100644 index 18893a8068..0000000000 --- a/drivers/cc110x_legacy_csma/cc1100-defaultSettings.c +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. - * - * 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 dev_cc110x_legacy_csma - * @{ - */ - -/** - * @file - * @brief TI Chipcon CC110x default settings - * - * @author Thomas Hillebrandt - * @author Heiko Will - * @version $Revision: 2058 $ - * - * @note $Id: cc1100-defaultSettings.c 2058 2010-03-31 08:59:31Z hillebra $ - */ - -#include "cc1100-defaultSettings.h" - -/** - * Usable, non overlapping channels and corresponding frequencies - * for use with CC1100. CHANNR is the register for selecting a channel. - * - * channel number | CHANNR | frequency [MHz] - * ----------------------------------------- - * 0 | 0 | 869.525 - * 1 | 10 | 871.61 - * 2 | 20 | 873.58 ~ seems to be bad (hang-ups with this channel) - * 3 | 30 | 875.61 - * 4 | 40 | 877.58 - * 5 | 50 | 879.61 - * 6 | 60 | 881.58 - * 7 | 70 | 883.61 - * 8 | 80 | 885.58 - * 9 | 90 | 887.61 - * 10 | 100 | 889.58 - * 11 | 110 | 891.57 - * 12 | 120 | 893.58 - * 13 | 130 | 895.61 - * 14 | 140 | 897.58 - * 15 | 150 | 899.57 - * 16 | 160 | 901.57 - * 17 | 170 | 903.61 - * 18 | 180 | 905.57 - * 19 | 190 | 907.57 - * 20 | 200 | 909.57 - * 21 | 210 | 911.57 - * 22 | 220 | 913.57 - * 23 | 230 | 915.61 - * 24 | 240 | 917.61 - */ - -/* 400 kbps, MSK, X-tal: 26 MHz (Chip Revision F) */ -char cc1100_conf[] = { - 0x06, /* IOCFG2 */ - 0x2E, /* IOCFG1 */ - 0x0E, /* IOCFG0 */ - 0x0F, /* FIFOTHR */ - 0x9B, /* SYNC1 */ - 0xAD, /* SYNC0 */ - 0x3D, /* PKTLEN (maximum value of packet length byte = 61) */ - 0x06, /* PKTCTRL1 */ - 0x45, /* PKTCTRL0 (variable packet length) */ - 0xFF, /* ADDR */ - CC1100_DEFAULT_CHANNR * 10, /* CHANNR */ - 0x0B, /* FSCTRL1 */ - 0x00, /* FSCTRL0 */ - 0x21, /* FREQ2 */ - 0x71, /* FREQ1 */ - 0x7A, /* FREQ0 */ - 0x2D, /* MDMCFG4 */ - 0xF8, /* MDMCFG3 */ - 0x73, /* MDMCFG2 */ - 0x42, /* MDMCFG1 */ - 0xF8, /* MDMCFG0 */ - 0x00, /* DEVIATN */ - 0x07, /* MCSM2 */ - 0x03, /* MCSM1 */ - 0x18, /* MCSM0 */ - 0x1D, /* FOCCFG */ - 0x1C, /* BSCFG */ - 0xC0, /* AGCCTRL2 */ - 0x49, /* AGCCTRL1, (old value was 0x49 -> made carrier sense less sensitive!) - * 0x47 - 7 dB above MAGN_TARGET setting */ - 0xB2, /* AGCCTRL0 */ - 0x87, /* WOREVT1 */ - 0x6B, /* WOREVT0 */ - 0xF8, /* WORCTRL */ - 0xB6, /* FREND1 */ - 0x10, /* FREND0 */ - 0xEA, /* FSCAL3 */ - 0x2A, /* FSCAL2 */ - 0x00, /* FSCAL1 */ - 0x1F, /* FSCAL0 */ - 0x00 /* padding to 4 bytes */ -}; - -/** @} */ diff --git a/drivers/cc110x_legacy_csma/cc1100-defaultSettings.h b/drivers/cc110x_legacy_csma/cc1100-defaultSettings.h deleted file mode 100644 index 4d3c817398..0000000000 --- a/drivers/cc110x_legacy_csma/cc1100-defaultSettings.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. - * - * 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. - */ - -#ifndef CC1100_DEFAULTSETTINGS_H -#define CC1100_DEFAULTSETTINGS_H - -/** - * @ingroup dev_cc110x_legacy_csma - * @{ - */ - -/** - * @file - * @brief TI Chipcon CC110x default settings - * - * @author Thomas Hillebrandt - * @author Heiko Will - * @version $Revision: 2139 $ - * - * @note $Id: cc1100-defaultSettings.h 2139 2010-05-26 08:04:04Z hillebra $ - */ - -#include "hwtimer.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// returns hwtimer ticks per us -#define RTIMER_TICKS(us) HWTIMER_TICKS(us) - -#define TIMER_TICK_USEC_RES (122) - -// Default PA table index (output power) -#define PATABLE (11) - -// Watchdog cycle time in seconds, set 0 to disable watchdog -#define CC1100_WATCHDOG_PERIOD (5) - -// Number of transmission retries for unicast packets (constant RX mode) -#define TRANSMISSION_RETRIES_CRX_UC (5) - -// Number of transmission retries for unicast packets (WOR mode) -#define TRANSMISSION_RETRIES_WOR_UC (1) - -// Number of transmission retries for broadcast packets (constant RX mode) -#define TRANSMISSION_RETRIES_CRX_BC (0) - -// Number of transmission retries for broadcast packets (WOR mode) -#define TRANSMISSION_RETRIES_WOR_BC (0) - -// Time before chip goes back to RX (= stays in PWD after incoming packet) -#define WOR_TIMEOUT_1 (3200) // ~ 32 milliseconds - -// Time before chip goes back to WOR (= stays in RX after elapsed WOR_TIMEOUT_1) -#define WOR_TIMEOUT_2 (800) // ~ 8 milliseconds - -// XOSC startup + FS calibration (300 + 809 us ~ 1.38 ms) -#define FS_CAL_TIME RTIMER_TICKS(12 * TIMER_TICK_USEC_RES) - -// Manual FS calibration (721 us) -#define MANUAL_FS_CAL_TIME RTIMER_TICKS(7 * TIMER_TICK_USEC_RES) - -// Reset wait time (in reset procedure) -#define RESET_WAIT_TIME RTIMER_TICKS(4 * TIMER_TICK_USEC_RES) - -// Time chip needs to go to RX -#define IDLE_TO_RX_TIME RTIMER_TICKS(1 * TIMER_TICK_USEC_RES) - -// Time chip needs to go to RX and CS signal is ready -#define CS_READY_TIME RTIMER_TICKS(3 * TIMER_TICK_USEC_RES) - -// Default RX interval for WOR in milliseconds -#define T_RX_INTERVAL (542) - -// Time of packet interval in microseconds (at 400 kbps) -#define T_PACKET_INTERVAL (3800) - -// The size of the configuration array for CC1100 in bytes -#define CC1100_CONF_SIZE (39) - -// The default channel number (0-24) for CC1100 -#define CC1100_DEFAULT_CHANNR (0) - -// Burst retry to TX switch time (measured ~ 230 us) -#define BURST_RETRY_TX_SWITCH_TIME (23) - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif diff --git a/drivers/cc110x_legacy_csma/cc1100-internal.h b/drivers/cc110x_legacy_csma/cc1100-internal.h deleted file mode 100644 index 8de14c02bc..0000000000 --- a/drivers/cc110x_legacy_csma/cc1100-internal.h +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. - * - * 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. - */ - -#ifndef CC1100_INTERNAL_H -#define CC1100_INTERNAL_H - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @ingroup dev_cc110x_legacy_csma - * @{ - */ - -/** - * @file - * @internal - * @brief TI Chipcon CC110x internal hardware constants - * - * @author Thomas Hillebrandt - * @author Heiko Will - * @version $Revision: 1231 $ - * - * @note $Id: cc1100-internal.h 1231 2009-08-20 08:31:32Z baar $ - */ - -#define FIXED_PKTLEN (0x00) ///< Fixed length packets, length configured in PKTLEN register. -#define VARIABLE_PKTLEN (0x01) ///< Variable length packets, packet length configured by the first - ///< byte after synch word. - -/** - * @name Bitmasks for reading out status register values - * @{ - */ - -/** - * @brief Bitmask (=10000000) for reading CRC_OK. - * - * If CRC_OK == 1: CRC for received data OK (or CRC disabled). - * If CRC_OK == 0: CRC error in received data. - */ -#define CRC_OK (0x80) -/** - * @brief Bitmask (=01111111) for reading LQI_EST. - * - * The Link Quality Indicator estimates how easily a received signal can be demodulated. - */ -#define LQI_EST (0x7F) -#define I_RSSI (0x00) ///< Index 0 contains RSSI information (from optionally appended packet status bytes). -#define I_LQI (0x01) ///< Index 1 contains LQI & CRC_OK information (from optionally appended packet status bytes). -#define MARC_STATE (0x1F) ///< Bitmask (=00011111) for reading MARC_STATE in MARCSTATE status register. -#define CS (0x40) ///< Bitmask (=01000000) for reading CS (Carrier Sense) in PKTSTATUS status register. -#define PQT_REACHED (0x20) ///< Bitmask (=00100000) for reading PQT_REACHED (Preamble Quality reached) in PKTSTATUS status register. -#define CCA (0x10) ///< Bitmask (=00010000) for reading CCA (clear channel assessment) in PKTSTATUS status register. -#define SFD (0x08) ///< Bitmask (=00001000) for reading SFD (Sync word found) in PKTSTATUS status register. -#define GDO2 (0x04) ///< Bitmask (=00000100) for reading GDO2 (current value on GDO2 pin) in PKTSTATUS status register. -#define GDO1 (0x02) ///< Bitmask (=00000010) for reading GDO1 (current value on GDO1 pin) in PKTSTATUS status register. -#define GDO0 (0x01) ///< Bitmask (=00000001) for reading GDO0 (current value on GDO0 pin) in PKTSTATUS status register. -#define TXFIFO_UNDERFLOW (0x80) ///< Bitmask (=10000000) for reading TXFIFO_UNDERFLOW in TXBYTES status register. -#define BYTES_IN_TXFIFO (0x7F) ///< Bitmask (=01111111) for reading NUM_TXBYTES in TXBYTES status register. -#define RXFIFO_OVERFLOW (0x80) ///< Bitmask (=10000000) for reading RXFIFO_OVERFLOW in RXBYTES status register. -#define BYTES_IN_RXFIFO (0x7F) ///< Bitmask (=01111111) for reading NUM_RXBYTES in RXBYTES status register. -/** @} */ - -/** - * @name Bitmasks for reading out configuration register values - * @{ - */ -#define PKT_LENGTH_CONFIG (0x03) ///< Bitmask (=00000011) for reading LENGTH_CONFIG in PKTCTRL0 configuration register. -/** @} */ - -/** - * @name Definitions to support burst/single access - * @{ - */ -#define CC1100_WRITE_BURST (0x40) ///< Offset for burst write. -#define CC1100_READ_SINGLE (0x80) ///< Offset for read single byte. -#define CC1100_READ_BURST (0xC0) ///< Offset for read burst. -#define CC1100_NOBYTE (0x00) ///< No command (for reading). -/** @} */ - -/** - * @name Configuration Registers (47x) - * @{ - */ -#define CC1100_IOCFG2 (0x00) ///< GDO2 output pin configuration -#define CC1100_IOCFG1 (0x01) ///< GDO1 output pin configuration -#define CC1100_IOCFG0 (0x02) ///< GDO0 output pin configuration -#define CC1100_FIFOTHR (0x03) ///< RX FIFO and TX FIFO thresholds -#define CC1100_SYNC1 (0x04) ///< Sync word, high byte -#define CC1100_SYNC0 (0x05) ///< Sync word, low byte -#define CC1100_PKTLEN (0x06) ///< Packet length -#define CC1100_PKTCTRL1 (0x07) ///< Packet automation control -#define CC1100_PKTCTRL0 (0x08) ///< Packet automation control -#define CC1100_ADDR (0x09) ///< Device address -#define CC1100_CHANNR (0x0A) ///< Channel number -#define CC1100_FSCTRL1 (0x0B) ///< Frequency synthesizer control -#define CC1100_FSCTRL0 (0x0C) ///< Frequency synthesizer control -#define CC1100_FREQ2 (0x0D) ///< Frequency control word, high byte -#define CC1100_FREQ1 (0x0E) ///< Frequency control word, middle byte -#define CC1100_FREQ0 (0x0F) ///< Frequency control word, low byte -#define CC1100_MDMCFG4 (0x10) ///< Modem configuration -#define CC1100_MDMCFG3 (0x11) ///< Modem configuration -#define CC1100_MDMCFG2 (0x12) ///< Modem configuration -#define CC1100_MDMCFG1 (0x13) ///< Modem configuration -#define CC1100_MDMCFG0 (0x14) ///< Modem configuration -#define CC1100_DEVIATN (0x15) ///< Modem deviation setting -#define CC1100_MCSM2 (0x16) ///< Main Radio Control State Machine configuration -#define CC1100_MCSM1 (0x17) ///< Main Radio Control State Machine configuration -#define CC1100_MCSM0 (0x18) ///< Main Radio Control State Machine configuration -#define CC1100_FOCCFG (0x19) ///< Frequency Offset Compensation configuration -#define CC1100_BSCFG (0x1A) ///< Bit Synchronization configuration -#define CC1100_AGCCTRL2 (0x1B) ///< AGC control -#define CC1100_AGCCTRL1 (0x1C) ///< AGC control -#define CC1100_AGCCTRL0 (0x1D) ///< AGC control -#define CC1100_WOREVT1 (0x1E) ///< High byte Event 0 timeout -#define CC1100_WOREVT0 (0x1F) ///< Low byte Event 0 timeout -#define CC1100_WORCTRL (0x20) ///< Wake On Radio control -#define CC1100_FREND1 (0x21) ///< Front end RX configuration -#define CC1100_FREND0 (0x22) ///< Front end TX configuration -#define CC1100_FSCAL3 (0x23) ///< Frequency synthesizer calibration -#define CC1100_FSCAL2 (0x24) ///< Frequency synthesizer calibration -#define CC1100_FSCAL1 (0x25) ///< Frequency synthesizer calibration -#define CC1100_FSCAL0 (0x26) ///< Frequency synthesizer calibration -#define CC1100_RCCTRL1 (0x27) ///< RC oscillator configuration -#define CC1100_RCCTRL0 (0x28) ///< RC oscillator configuration -#define CC1100_FSTEST (0x29) ///< Frequency synthesizer calibration control -#define CC1100_PTEST (0x2A) ///< Production test -#define CC1100_AGCTEST (0x2B) ///< AGC test -#define CC1100_TEST2 (0x2C) ///< Various test settings -#define CC1100_TEST1 (0x2D) ///< Various test settings -#define CC1100_TEST0 (0x2E) ///< Various test settings -/** @} */ - -/** - * @name Strobe commands (14x) - * @{ - */ -#define CC1100_SRES (0x30) ///< Reset chip. -/** - * @brief Enable and calibrate frequency synthesizer (if MCSM0.FS_AUTOCAL=1). - * - * If in RX/TX: Go to a wait state where only the synthesizer is running (for quick RX / TX turnaround). - */ -#define CC1100_SFSTXON (0x31) -#define CC1100_SXOFF (0x32) ///< Turn off crystal oscillator. -#define CC1100_SCAL (0x33) ///< Calibrate frequency synthesizer and turn it off (enables quick start). -#define CC1100_SRX (0x34) ///< Enable RX. Perform calibration first if coming from IDLE and MCSM0.FS_AUTOCAL=1. -/** - * In IDLE state: Enable TX. Perform calibration first if MCSM0.FS_AUTOCAL=1. - * If in RX state and CCA is enabled: Only go to TX if channel is clear. - */ -#define CC1100_STX (0x35) -#define CC1100_SIDLE (0x36) ///< Exit RX / TX, turn off frequency synthesizer and exit WOR mode if applicable. -#define CC1100_SAFC (0x37) ///< Perform AFC adjustment of the frequency synthesizer -#define CC1100_SWOR (0x38) ///< Start automatic RX polling sequence (Wake-on-Radio) -#define CC1100_SPWD (0x39) ///< Enter power down mode when CSn goes high. -#define CC1100_SFRX (0x3A) ///< Flush the RX FIFO buffer (CC1100 should be in IDLE state). -#define CC1100_SFTX (0x3B) ///< Flush the TX FIFO buffer (CC1100 should be in IDLE state). -#define CC1100_SWORRST (0x3C) ///< Reset real time clock. -#define CC1100_SNOP (0x3D) ///< No operation. May be used to pad strobe commands to two bytes for simpler software. -/** @} */ - -/** - * @name Status registers (12x) - * @{ - */ -#define CC1100_PARTNUM (0x30) ///< Part number of CC1100. -#define CC1100_VERSION (0x31) ///< Current version number. -#define CC1100_FREQEST (0x32) ///< Frequency Offset Estimate. -#define CC1100_LQI (0x33) ///< Demodulator estimate for Link Quality. -#define CC1100_RSSI (0x34) ///< Received signal strength indication. -#define CC1100_MARCSTATE (0x35) ///< Control state machine state. -#define CC1100_WORTIME1 (0x36) ///< High byte of WOR timer. -#define CC1100_WORTIME0 (0x37) ///< Low byte of WOR timer. -#define CC1100_PKTSTATUS (0x38) ///< Current GDOx status and packet status. -#define CC1100_VCO_VC_DAC (0x39) ///< Current setting from PLL calibration module. -#define CC1100_TXBYTES (0x3A) ///< Underflow and number of bytes in the TX FIFO. -#define CC1100_RXBYTES (0x3B) ///< Overflow and number of bytes in the RX FIFO. -/** @} */ - -/** - * @name Multi byte registers - * @{ - */ -/** - * @brief Register for eight user selected output power settings. - * - * 3-bit FREND0.PA_POWER value selects the PATABLE entry to use. - */ -#define CC1100_PATABLE (0x3E) -#define CC1100_TXFIFO (0x3F) ///< TX FIFO: Write operations write to the TX FIFO (SB: +0x00; BURST: +0x40) -#define CC1100_RXFIFO (0x3F) ///< RX FIFO: Read operations read from the RX FIFO (SB: +0x80; BURST: +0xC0) - - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/drivers/cc110x_legacy_csma/cc1100.c b/drivers/cc110x_legacy_csma/cc1100.c deleted file mode 100644 index 6c4df25ede..0000000000 --- a/drivers/cc110x_legacy_csma/cc1100.c +++ /dev/null @@ -1,935 +0,0 @@ -/** - * TI Chipcon CC110x radio driver - * - * Copyright (C) 2009-2013 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 dev_cc110x_legacy_csma - * @{ - */ - -/** - * @file - * @internal - * @brief TI Chipcon CC110x Radio driver - * - * @author Thomas Hillebrandt - * @author Heiko Will - * @version $Revision: 2283 $ - * - * @note $Id: cc1100.c 2283 2010-06-15 14:02:27Z hillebra $ - */ - -#include -#include -#include -#include - -#include "irq.h" -#include "arch_cc1100.h" -#include "cc1100.h" -#include "cc1100_phy.h" -#include "cc1100_spi.h" -#include "cc1100-internal.h" -#include "cc1100-defaultSettings.h" - -#include "hwtimer.h" -#include "bitarithm.h" - -#define PACKET_LENGTH (0x3E) ///< Packet length = 62 Bytes. -#define CC1100_SYNC_WORD_TX_TIME (90000) /* loop count (max. timeout ~ 15 ms) to wait for */ - /* sync word to be transmitted (GDO2 from low to high) */ - -/** - * @name Virtual Radio Device methods (see vdevice_radio_methods) - * @{ - */ -static int rd_set_mode(int mode); -/** @} */ - -static void switch_to_wor(void); - -/*---------------------------------------------------------------------------*/ -// Power control data structures -/*---------------------------------------------------------------------------*/ - -static uint8_t pa_table_index = PATABLE; ///< Current PATABLE Index -static uint8_t pa_table[] = { ///< PATABLE with available output powers - 0x00, ///< -52 dBm - 0x03, ///< -30 dBm - 0x0D, ///< -20 dBm - 0x1C, ///< -15 dBm - 0x34, ///< -10 dBm - 0x57, ///< - 5 dBm - 0x3F, ///< - 1 dBm - 0x8E, ///< 0 dBm - 0x85, ///< + 5 dBm - 0xCC, ///< + 7 dBm - 0xC6, ///< + 9 dBm - 0xC3 ///< +10 dBm -}; /* 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 - -52, - -30, - -20, - -15, - -10, - -5, - -1, - 0, - 5, - 7, - 9, - 10 -}; - -/*---------------------------------------------------------------------------*/ -// Main radio data structures -/*---------------------------------------------------------------------------*/ - -volatile cc1100_flags rflags; ///< Radio control flags -static uint8_t radio_address; ///< Radio address -static uint8_t radio_channel; ///< Radio channel number - -/*---------------------------------------------------------------------------*/ -// Data structures for mode control -/*---------------------------------------------------------------------------*/ - -volatile uint8_t radio_mode; ///< Radio mode -volatile uint8_t radio_state = RADIO_UNKNOWN; ///< Radio state - -volatile cc1100_mode_callback_t cc1100_go_idle; ///< Function for going IDLE -volatile cc1100_mode_callback_t cc1100_go_receive; ///< Function for going RX -volatile cc1100_mode_callback_t cc1100_go_after_tx; ///< Function to call after TX (burst send) -volatile cc1100_mode_callback_t cc1100_setup_mode; ///< Function to set up selected mode (RX or WOR) - -volatile int wor_hwtimer_id = -1; - -/*---------------------------------------------------------------------------*/ -/* Low-level hardware access */ -/*---------------------------------------------------------------------------*/ - -void cc1100_disable_interrupts(void) -{ - cc110x_gdo2_disable(); - cc110x_gdo0_disable(); -} - -void cc110x_gdo0_irq(void) -{ - /* Air was not free -> Clear CCA flag */ - rflags.CAA = false; - /* Disable carrier sense detection (GDO0 interrupt) */ - cc110x_gdo0_disable(); -} - -void cc110x_gdo2_irq(void) -{ - cc1100_phy_rx_handler(); -} - -/*---------------------------------------------------------------------------*/ -/* High level CC1100 SPI functions for transferring packet out */ -// of RX FIFO (don't call when in WOR mode) -/*---------------------------------------------------------------------------*/ - -static bool spi_receive_packet_variable(uint8_t *rxBuffer, radio_packet_length_t length) -{ - /* Needed here for statistics */ - extern cc1100_statistic_t cc1100_statistic; - - /* Any bytes available in RX FIFO? */ - if ((cc1100_spi_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) { - uint8_t status[2]; - - /* Read length byte (first byte in RX FIFO) */ - uint8_t packetLength = cc1100_spi_read_reg(CC1100_RXFIFO); - - /* Read data from RX FIFO and store in rxBuffer */ - if (packetLength <= length) { - /* Put length byte at first position in RX Buffer */ - rxBuffer[0] = packetLength; - - /* Read the rest of the packet */ - cc1100_spi_readburst_reg(CC1100_RXFIFO, (char *)rxBuffer + 1, packetLength); - - /* Read the 2 appended status bytes (status[0] = RSSI, status[1] = LQI) */ - cc1100_spi_readburst_reg(CC1100_RXFIFO, (char *)status, 2); - - /* Store RSSI value of packet */ - rflags.RSSI = status[I_RSSI]; - - /* MSB of LQI is the CRC_OK bit */ - rflags.CRC_STATE = (status[I_LQI] & CRC_OK) >> 7; - - if (!rflags.CRC_STATE) { - cc1100_statistic.packets_in_crc_fail++; - } - - /* Bit 0-6 of LQI indicates the link quality (LQI) */ - rflags.LQI = status[I_LQI] & LQI_EST; - - return rflags.CRC_STATE; - } - else { - /* RX FIFO get automatically flushed if return value is false */ - return false; - } - } - else { - /* RX FIFO get automatically flushed if return value is false */ - return false; - } -} - -bool cc1100_spi_receive_packet(uint8_t *rxBuffer, radio_packet_length_t length) -{ - uint8_t pkt_len_cfg = cc1100_spi_read_reg(CC1100_PKTCTRL0) & PKT_LENGTH_CONFIG; - - if (pkt_len_cfg == VARIABLE_PKTLEN) { - return spi_receive_packet_variable(rxBuffer, length); - } - - /* Fixed packet length not supported. */ - /* RX FIFO get automatically flushed if return value is false */ - return false; -} - -/*---------------------------------------------------------------------------*/ -/* CC1100 mode functionality */ -/*---------------------------------------------------------------------------*/ - -void cc1100_set_idle(void) -{ - if (radio_state == RADIO_WOR) { - /* Wake up the chip from WOR/sleep */ - cc110x_spi_select(); - hwtimer_wait(RTIMER_TICKS(122)); - cc110x_spi_unselect(); - radio_state = RADIO_IDLE; - /* XOSC startup + FS calibration (300 + 809 us ~ 1.38 ms) */ - hwtimer_wait(FS_CAL_TIME); - return; - } - - cc1100_spi_strobe(CC1100_SIDLE); - radio_state = RADIO_IDLE; -} - -static void wakeup_from_rx(void) -{ - if (radio_state != RADIO_RX) { - return; - } - - cc1100_spi_strobe(CC1100_SIDLE); - radio_state = RADIO_IDLE; -} - -static void switch_to_rx(void) -{ - radio_state = RADIO_RX; - cc1100_spi_strobe(CC1100_SRX); -} - -static void setup_rx_mode(void) -{ - /* Stay in RX mode until end of packet */ - cc1100_spi_write_reg(CC1100_MCSM2, 0x07); - switch_to_rx(); -} - -/** - * Note: It is possible that this code is executed in an ISR! - */ -static void wakeup_from_wor(void) -{ - if (radio_state != RADIO_WOR) { - return; - } - - /* Wake up the chip from WOR/sleep */ - cc110x_spi_select(); - hwtimer_wait(RTIMER_TICKS(122)); - cc110x_spi_unselect(); - radio_state = RADIO_IDLE; - /* XOSC startup + FS calibration (300 + 809 us ~ 1.38 ms) */ - hwtimer_wait(FS_CAL_TIME); -} - -/** - * Note: This code is executed in the hwtimer ISR! - */ -void switch_to_wor2(void) -{ - // if (cc110x_get_gdo2()) return; /* If incoming packet, then don't go to WOR now */ - cc1100_spi_strobe(CC1100_SIDLE); /* Put CC1100 to IDLE */ - radio_state = RADIO_IDLE; /* Radio state now IDLE */ - cc1100_spi_write_reg(CC1100_MCSM2, - cc1100_wor_config.rx_time_reg); /* Configure RX_TIME (for use in WOR) */ - cc1100_spi_write_reg(CC1100_MCSM0, 0x18); /* Turn on FS-Autocal */ - - if (rflags.WOR_RST) { - cc1100_spi_strobe(CC1100_SWORRST); /* Resets the real time clock */ - rflags.WOR_RST = false; - } - - cc1100_spi_strobe(CC1100_SWOR); /* Put radio back to sleep/WOR (must be in IDLE when this is done) */ - radio_state = RADIO_WOR; /* Radio state now WOR */ -} - -/** - * Note: This code is executed in the hwtimer ISR! - */ -static void hwtimer_switch_to_wor2_wrapper(void *ptr) -{ - (void) ptr; - wor_hwtimer_id = -1; /* kernel timer handler function called, clear timer id */ - - if (rflags.TX) { - return; /* Stability: don't allow WOR timers at this point */ - } - - rflags.WOR_RST = true; - switch_to_wor2(); -} - -/** - * Note: This code is executed in the hwtimer ISR! - */ -static void switch_to_wor(void) -{ - /* Any incoming packet? */ - if (cc110x_get_gdo2()) { - /* Then don't go to WOR now */ - return; - } - - /* Step 1: Set chip for random interval (1..RX_INTERVAL) to power down mode */ - if (!rflags.MAN_WOR) { - rflags.MAN_WOR = true; - radio_state = RADIO_WOR; - /* Go to power down mode */ - cc1100_spi_strobe(CC1100_SIDLE); - cc1100_spi_strobe(CC1100_SPWD); - - /* Set timer to do second step of manual WOR */ - 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); - - if (wor_hwtimer_id == -1) { - rflags.KT_RES_ERR = true; - /* No hwtimer available, go immediately to WOR mode. */ - /* Else never receiving packets again... */ - rflags.MAN_WOR = false; - switch_to_wor2(); - } - } - /* Step 2: Go to RX and then to WOR mode again */ - else { - rflags.MAN_WOR = false; - wakeup_from_wor(); - cc1100_spi_strobe(CC1100_SRX); - hwtimer_wait(IDLE_TO_RX_TIME); - radio_state = RADIO_RX; - /* Register timer to go to WOR after RX timeout */ - 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 */ - - if (wor_hwtimer_id == -1) { - rflags.KT_RES_ERR = true; - } - } -} - -static void setup_wor_mode(void) -{ - /* Wake up from WOR (if in WOR, else no effect) */ - cc1100_go_idle(); - - /* Make sure CC1100 is in IDLE state */ - cc1100_spi_strobe(CC1100_SIDLE); - - /* Enable automatic initial calibration of RCosc. */ - /* Set T_event1 ~ 1.4 ms, enough for XOSC stabilize and FS calibration before RX. */ - /* Enable RC oscillator before starting with WOR (or else it will not wake up). */ - /* Not using AUTO_SYNC function. */ - cc1100_spi_write_reg(CC1100_WORCTRL, cc1100_wor_config.wor_ctrl); - - /* Set Event0 timeout (RX polling interval) */ - cc1100_spi_write_reg(CC1100_WOREVT1, cc1100_wor_config.wor_evt_1); - cc1100_spi_write_reg(CC1100_WOREVT0, cc1100_wor_config.wor_evt_0); - - /* Set RX time in WOR mode */ - cc1100_spi_write_reg(CC1100_MCSM2, cc1100_wor_config.rx_time_reg); - - /* Enable automatic FS calibration when going from IDLE to RX/TX/FSTXON (in between EVENT0 and EVENT1) */ - cc1100_spi_write_reg(CC1100_MCSM0, 0x18); - - /* Put the radio to SLEEP by starting Wake-on-Radio. */ - cc1100_spi_strobe(CC1100_SWORRST); /* Resets the real time clock */ - cc1100_spi_strobe(CC1100_SWOR); /* Starts Wake-on-Radio */ - radio_state = RADIO_WOR; -} - -static void switch_to_pwd(void) -{ - cc1100_go_idle(); - cc1100_spi_strobe(CC1100_SPWD); - radio_state = RADIO_PWD; -} - -uint8_t cc1100_get_mode(void) -{ - return radio_mode; -} - -static bool cc1100_set_mode0(uint8_t mode, uint16_t opt_mode_data) -{ - int result; - - switch(mode) { - case CC1100_MODE_WOR: - /* Calculate WOR settings, store result (new burst count) */ - result = cc1100_phy_calc_wor_settings(opt_mode_data); - - /* If settings can be applied, set new mode and burst count */ - if (result != -1) { - radio_mode = mode; - cc1100_go_idle = wakeup_from_wor; - cc1100_go_receive = switch_to_wor; - cc1100_go_after_tx = switch_to_wor2; - cc1100_setup_mode = setup_wor_mode; - cc1100_burst_count = result; - cc1100_retransmission_count_uc = TRANSMISSION_RETRIES_WOR_UC; - cc1100_retransmission_count_bc = TRANSMISSION_RETRIES_WOR_BC; - return true; - } - - break; - - case CC1100_MODE_CONSTANT_RX: - radio_mode = mode; - cc1100_go_idle = wakeup_from_rx; - cc1100_go_receive = switch_to_rx; - cc1100_go_after_tx = switch_to_rx; - cc1100_setup_mode = setup_rx_mode; - cc1100_burst_count = 1; - cc1100_retransmission_count_uc = TRANSMISSION_RETRIES_CRX_UC; - cc1100_retransmission_count_bc = TRANSMISSION_RETRIES_CRX_BC; - return true; - } - - return false; -} - -bool cc1100_set_mode(uint8_t mode, uint16_t opt_mode_data) -{ - /* Wake up from WOR/RX (if in WOR/RX, else no effect) */ - cc1100_go_idle(); - - /* Make sure CC1100 is in IDLE state */ - cc1100_spi_strobe(CC1100_SIDLE); - - /* Set the new mode */ - bool result = cc1100_set_mode0(mode, opt_mode_data); - - /* If mode change was successful (mode is valid) */ - if (result) { - /* Setup new mode configuration */ - cc1100_setup_mode(); - /* Reset statistics */ - cc1100_reset_statistic(); - return true; - } - else { - /* Still in old mode, go to receive mode again */ - cc1100_go_receive(); - return false; - } -} - -char *cc1100_mode_to_text(uint8_t mode) -{ - switch(mode) { - case CC1100_MODE_WOR: - return "Wake-On-Radio"; - - case CC1100_MODE_CONSTANT_RX: - return "Constant RX"; - - default: - return "unknown"; - } -} - -char *cc1100_state_to_text(uint8_t state) -{ - switch(state) { - case RADIO_UNKNOWN: - return "Unknown"; - - case RADIO_AIR_FREE_WAITING: - return "CS"; - - case RADIO_WOR: - return "WOR"; - - case RADIO_IDLE: - return "IDLE"; - - case RADIO_SEND_BURST: - return "TX BURST"; - - case RADIO_RX: - return "RX"; - - case RADIO_SEND_ACK: - return "TX ACK"; - - case RADIO_PWD: - return "PWD"; - - default: - return "unknown"; - } -} - -void cc1100_hwtimer_go_receive_wrapper(void *ptr) -{ - (void) ptr; - - /* kernel timer handler function called, clear timer id */ - wor_hwtimer_id = -1; - - /* Stability: don't allow WOR timers at this point */ - if (rflags.TX) { - return; - } - - if (radio_state == RADIO_PWD) { - /* Go to RX state, listen for packets as long as WOR_TIMEOUT_2 */ - cc1100_spi_strobe(CC1100_SRX); - hwtimer_wait(IDLE_TO_RX_TIME); - radio_state = RADIO_RX; - /* 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); - - if (wor_hwtimer_id == -1) { - rflags.KT_RES_ERR = true; - /* No hwtimer available, go immediately to WOR mode. */ - /* Else never receiving packets again... */ - rflags.MAN_WOR = false; - switch_to_wor2(); - } - } - else { - cc1100_go_receive(); - } -} - -/*---------------------------------------------------------------------------*/ -/* CC1100 reset functionality */ -/*---------------------------------------------------------------------------*/ - -static void reset(void) -{ - cc1100_go_idle(); - cc110x_spi_select(); - cc1100_spi_strobe(CC1100_SRES); - hwtimer_wait(RTIMER_TICKS(10)); -} - -static void power_up_reset(void) -{ - cc110x_spi_unselect(); - cc110x_spi_cs(); - cc110x_spi_unselect(); - hwtimer_wait(RESET_WAIT_TIME); - reset(); - radio_state = RADIO_IDLE; -} - -/*---------------------------------------------------------------------------*/ -/* CC1100 low level send function */ -/*---------------------------------------------------------------------------*/ - -void cc1100_send_raw(uint8_t *tx_buffer, uint8_t size) -{ - volatile uint32_t abort_count; - - /* The number of bytes to be transmitted must be smaller */ - /* or equal to PACKET_LENGTH (62 bytes). So the receiver */ - /* can put the whole packet in its RX-FIFO (with appended */ - /* packet status bytes). */ - if (size > PACKET_LENGTH) { - return; - } - - /* Disables RX interrupt etc. */ - cc110x_before_send(); - - /* But CC1100 in IDLE mode to flush the FIFO */ - cc1100_spi_strobe(CC1100_SIDLE); - /* Flush TX FIFO to be sure it is empty */ - cc1100_spi_strobe(CC1100_SFTX); - /* Write packet into TX FIFO */ - cc1100_spi_writeburst_reg(CC1100_TXFIFO, (char *) tx_buffer, size); - /* Switch to TX mode */ - abort_count = 0; - unsigned int cpsr = disableIRQ(); - cc1100_spi_strobe(CC1100_STX); - - /* Wait for GDO2 to be set -> sync word transmitted */ - while (cc110x_get_gdo2() == 0) { - abort_count++; - - if (abort_count > CC1100_SYNC_WORD_TX_TIME) { - /* Abort waiting. CC1100 maybe in wrong mode */ - /* e.g. sending preambles for always */ - puts("[CC1100 TX] fatal error\n"); - break; - } - } - - restoreIRQ(cpsr); - - /* Wait for GDO2 to be cleared -> end of packet */ - while (cc110x_get_gdo2() != 0); - - /* Experimental - TOF Measurement */ - cc110x_after_send(); -} - -/*---------------------------------------------------------------------------*/ -/* Various functions (mode safe - they can be called in any radio mode) */ -/*---------------------------------------------------------------------------*/ -uint8_t -read_register(uint8_t r) -{ - uint8_t result; - - /* Save old radio state */ - uint8_t old_state = radio_state; - - /* Wake up from WOR/RX (if in WOR/RX, else no effect) */ - cc1100_go_idle(); - result = cc1100_spi_read_reg(r); - - /* Have to put radio back to WOR/RX if old radio state */ - /* was WOR/RX, otherwise no action is necessary */ - if (old_state == RADIO_WOR || old_state == RADIO_RX) { - cc1100_go_receive(); - } - - return result; -} - -static void -write_register(uint8_t r, uint8_t value) -{ - /* Save old radio state */ - uint8_t old_state = radio_state; - - /* Wake up from WOR/RX (if in WOR/RX, else no effect) */ - cc1100_go_idle(); - cc1100_spi_write_reg(r, value); - - /* Have to put radio back to WOR/RX if old radio state */ - /* was WOR/RX, otherwise no action is necessary */ - if (old_state == RADIO_WOR || old_state == RADIO_RX) { - cc1100_go_receive(); - } -} - -char *cc1100_get_output_power(char *buf) -{ - sprintf(buf, "%+i dBm", pa_table_dBm[pa_table_index]); - return buf; -} - -uint8_t cc1100_get_channel(void) -{ - return radio_channel; -} - -bool -cc1100_set_channel(uint8_t channr) -{ - if (channr > MAX_CHANNR) { - return false; - } - - write_register(CC1100_CHANNR, channr * 10); - radio_channel = channr; - return true; -} - -bool -cc1100_set_output_power(uint8_t pa_idx) -{ - if (pa_idx >= sizeof(pa_table)) { - return false; - } - - write_register(CC1100_PATABLE, pa_table[pa_idx]); - pa_table_index = pa_idx; - return true; -} - -char *cc1100_get_marc_state(void) -{ - uint8_t state; - - /* Save old radio state */ - uint8_t old_state = radio_state; - - /* Read content of status register */ - state = cc1100_spi_read_status(CC1100_MARCSTATE) & MARC_STATE; - - /* Make sure in IDLE state. */ - /* Only goes to IDLE if state was RX/WOR */ - cc1100_go_idle(); - - /* Have to put radio back to WOR/RX if old radio state */ - /* was WOR/RX, otherwise no action is necessary */ - if (old_state == RADIO_WOR || old_state == RADIO_RX) { - cc1100_go_receive(); - } - - switch(state) { - /* Note: it is not possible to read back the SLEEP or XOFF state numbers */ - /* because setting CSn low will make the chip enter the IDLE mode from the */ - /* SLEEP (0) or XOFF (2) states. */ - case 1: - return "IDLE"; - - case 3: - case 4: - case 5: - return "MANCAL"; - - case 6: - case 7: - return "FS_WAKEUP"; - - case 8: - case 12: - return "CALIBRATE"; - - case 9: - case 10: - case 11: - return "SETTLING"; - - case 13: - case 14: - case 15: - return "RX"; - - case 16: - return "TXRX_SETTLING"; - - case 17: - return "RXFIFO_OVERFLOW"; - - case 18: - return "FSTXON"; - - case 19: - case 20: - return "TX"; - - case 21: - return "RXTX_SETTLING"; - - case 22: - return "TXFIFO_UNDERFLOW"; - - default: - return "UNKNOWN"; - } -} - -/* -static int8_t -rssi_2_dbm(uint8_t rssi) -{ - if (rssi >= 128) rssi -= 256; - rssi /= 2; - rssi -= 78; - return rssi; -}*/ - -/*---------------------------------------------------------------------------*/ -/* Radio Driver API */ -/*---------------------------------------------------------------------------*/ -void cc1100_init(void) -{ - /* Initialize SPI */ - cc110x_spi_init(); - - /* Set default mode (with default (energy optimized) RX interval) */ - cc1100_set_mode0(CC1100_RADIO_MODE, T_RX_INTERVAL); - - /* Load driver & reset */ - power_up_reset(); - - /* Write configuration to configuration registers */ - extern char cc1100_conf[]; - cc1100_spi_writeburst_reg(0x00, cc1100_conf, CC1100_CONF_SIZE); - - /* Write PATABLE (power settings) */ - cc1100_spi_write_reg(CC1100_PATABLE, pa_table[pa_table_index]); - - /* Initialize Radio Flags */ - rflags.RSSI = 0x00; - rflags.LL_ACK = false; - rflags.CAA = false; - rflags.CRC_STATE = false; - rflags.SEQ = false; - rflags.MAN_WOR = false; - rflags.KT_RES_ERR = false; - rflags.TX = false; - rflags.WOR_RST = false; - - /* Initialize physical layer */ - cc1100_phy_init(); - - /* Set radio address of CC1100 */ - cc1100_set_address(radio_address); - - /* Set default channel number */ - radio_channel = CC1100_DEFAULT_CHANNR; - - /* Switch to desired mode (WOR or RX) */ - rd_set_mode(RADIO_MODE_ON); -} - -int cc1100_get_avg_transmission_duration(void) -{ - if (radio_mode == CC1100_MODE_WOR) { - /* Transmission duration ~ RX interval */ - /* Double value because of MAC delay. */ - return 2 * cc1100_wor_config.rx_interval; - } - else { - /* Transmission duration ~ 32 ms */ - /* Double value because of MAC delay. */ - return 2 * 32; - } -} - -radio_address_t cc1100_get_address(void) -{ - return radio_address; -} - -bool cc1100_set_address(radio_address_t address) -{ - if (address < MIN_UID || address > MAX_UID) { - return false; - } - - uint8_t id = (uint8_t) address; - - if (radio_state != RADIO_UNKNOWN) { - write_register(CC1100_ADDR, id); - } - - radio_address = id; - return true; -} - -static int -rd_set_mode(int mode) -{ - int result; - - /* Get current radio mode */ - if (radio_state == RADIO_UNKNOWN || radio_state == RADIO_PWD) { - result = RADIO_MODE_OFF; - } - else { - result = RADIO_MODE_ON; - } - - switch(mode) { - case RADIO_MODE_ON: - cc110x_init_interrupts(); /* Enable interrupts */ - cc1100_setup_mode(); /* Set chip to desired mode */ - break; - - case RADIO_MODE_OFF: - cc1100_disable_interrupts(); /* Disable interrupts */ - switch_to_pwd(); /* Set chip to power down mode */ - break; - - case RADIO_MODE_GET: - - /* do nothing, just return current mode */ - default: - /* do nothing */ - break; - } - - /* Return previous mode */ - return result; -} - -/*---------------------------------------------------------------------------*/ -/* Carrier sense interface functions */ -/*---------------------------------------------------------------------------*/ - -void cc1100_cs_init(void) -{ - cc1100_go_idle(); /* Wake CC1100 up from Wake-On-Radio mode */ - - if (radio_state == RADIO_RX) { /* If radio in RX mode */ - cc1100_spi_strobe(CC1100_SIDLE); /* Go back to IDLE for calibration */ - } - - cc1100_spi_write_reg(CC1100_MCSM0, 0x08); /* Turn off FS-Autocal */ - cc1100_spi_strobe(CC1100_SCAL); /* Calibrate manually (721 us) */ - hwtimer_wait(MANUAL_FS_CAL_TIME); /* Wait for calibration to finish before packet burst can start */ - radio_state = RADIO_AIR_FREE_WAITING; /* Set status "waiting for air free" */ - cc1100_spi_write_reg(CC1100_MCSM2, 0x07); /* Configure RX_TIME = Until end of packet (no timeout) */ - cc1100_spi_strobe(CC1100_SRX); /* Switch to RX (88.4 us) (Carrier Sense) */ - hwtimer_wait(CS_READY_TIME); /* Wait until CC1100 is in RX + carrier sense ready (GDO0 ready for readout -> data rate dependent!!!) */ -} - -void cc1100_cs_set_enabled(bool enabled) -{ - if (enabled) { - /* Enable carrier sense detection (GDO0 interrupt) */ - cc110x_gdo0_enable(); - } - else { - /* Disable carrier sense detection (GDO0 interrupt) */ - cc110x_gdo0_disable(); - } -} - -int cc1100_cs_read(void) -{ - /* GDO0 reflects CS (high: air not free, low: air free) */ - return cc110x_get_gdo0(); -} - -int cc1100_cs_read_cca(void) -{ - return rflags.CAA; -} - -void cc1100_cs_write_cca(const int cca) -{ - rflags.CAA = cca; -} -/*---------------------------------------------------------------------------*/ -/** @} */ diff --git a/drivers/cc110x_legacy_csma/cc1100.h b/drivers/cc110x_legacy_csma/cc1100.h deleted file mode 100644 index 706960fbd8..0000000000 --- a/drivers/cc110x_legacy_csma/cc1100.h +++ /dev/null @@ -1,330 +0,0 @@ -/* - * Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. - * - * 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. - */ - -/** - * @defgroup drivers_cc110x_legacy_csma CC110X_LEGACY_CSMA - * @ingroup drivers - * @brief Driver for Texas Instruments CC110x (including CMSA/CA MAC) - * - *

Quick links

- * \li \ref cc1100_packet_layer0_t MAC packet format - * - * @{ - * - * @file - * @brief TI Chipcon CC110x radio driver - * - * @author Thomas Hillebrandt - * @author Heiko Will - */ - -#ifndef CC1100_H -#define CC1100_H - -#include -#include "cc110x_legacy_csma.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @name Defines used as state values for state machine - * @{ - */ -#define RADIO_UNKNOWN (0) -#define RADIO_AIR_FREE_WAITING (1) -#define RADIO_WOR (2) -#define RADIO_IDLE (3) -#define RADIO_SEND_BURST (4) -#define RADIO_RX (5) -#define RADIO_SEND_ACK (6) -#define RADIO_PWD (7) - -/** @} */ - -/** @brief CC1100 register configuration */ -typedef struct cc1100_reg { - uint8_t IOCFG2; /**< GDO2 output pin configuration */ - uint8_t IOCFG1; /**< GDO1 output pin configuration */ - uint8_t IOCFG0; /**< GDO0 output pin configuration */ - uint8_t FIFOTHR; /**< RX FIFO and TX FIFO thresholds */ - uint8_t SYNC1; /**< Sync word, high byte */ - uint8_t SYNC0; /**< Sync word, low byte */ - uint8_t PKTLEN; /**< Packet length */ - uint8_t PKTCTRL1; /**< Packet automation control */ - uint8_t PKTCTRL0; /**< Packet automation control */ - uint8_t ADDR; /**< Device address */ - uint8_t CHANNR; /**< Channel number */ - uint8_t FSCTRL1; /**< Frequency synthesizer control */ - uint8_t FSCTRL0; /**< Frequency synthesizer control */ - uint8_t FREQ2; /**< Frequency control word, high byte */ - uint8_t FREQ1; /**< Frequency control word, middle byte */ - uint8_t FREQ0; /**< Frequency control word, low byte */ - uint8_t MDMCFG4; /**< Modem configuration */ - uint8_t MDMCFG3; /**< Modem configuration */ - uint8_t MDMCFG2; /**< Modem configuration */ - uint8_t MDMCFG1; /**< Modem configuration */ - uint8_t MDMCFG0; /**< Modem configuration */ - uint8_t DEVIATN; /**< Modem deviation setting */ - uint8_t MCSM2; /**< Main Radio Control State Machine configuration */ - uint8_t MCSM1; /**< Main Radio Control State Machine configuration */ - uint8_t MCSM0; /**< Main Radio Control State Machine configuration */ - uint8_t FOCCFG; /**< Frequency Offset Compensation configuration */ - uint8_t BSCFG; /**< Bit Synchronization configuration */ - uint8_t AGCCTRL2; /**< AGC control */ - uint8_t AGCCTRL1; /**< AGC control */ - uint8_t AGCCTRL0; /**< AGC control */ - uint8_t WOREVT1; /**< High byte Event 0 timeout */ - uint8_t WOREVT0; /**< Low byte Event 0 timeout */ - uint8_t WORCTRL; /**< Wake On Radio control */ - uint8_t FREND1; /**< Front end RX configuration */ - uint8_t FREND0; /**< Front end TX configuration */ - uint8_t FSCAL3; /**< Frequency synthesizer calibration */ - uint8_t FSCAL2; /**< Frequency synthesizer calibration */ - uint8_t FSCAL1; /**< Frequency synthesizer calibration */ - uint8_t FSCAL0; /**< Frequency synthesizer calibration */ -} cc1100_reg_t; - -/** CC1100 radio configuration */ -typedef struct cc1100_cfg_t { - cc1100_reg_t reg_cfg; /**< CC1100 register configuration */ - uint8_t pa_power; /**< Output power setting */ -} cc1100_cfg_t; - -/** - * @brief Radio Control Flags - */ -typedef struct cc1100_flags { - uint32_t TOF; /**< Time of flight of the last packet and last ACK */ - uint32_t TCP; /**< Time to compute packet */ - unsigned RPS : 16; /**< Raw packets sent to transmit last packet */ - unsigned RETC : 8; /**< Retransmission count of last send packet */ - unsigned RSSI : 8; /**< The RSSI value of last received packet */ - unsigned RSSI_SEND : 8; /**< The RSSI value of the last send unicast packet of this node */ - unsigned LQI : 8; /**< The LQI value of the last received packet */ - unsigned LL_ACK : 1; /**< Is set if Link-Level ACK is received, otherwise 0 (reset on new burst) */ - unsigned CAA : 1; /**< The status of the air (1 = air free, 0 = air not free) */ - unsigned CRC_STATE : 1; /**< The CRC status of last received packet (1 = OK, 0 = not OK) */ - unsigned SEQ : 1; /**< Sequence number (toggles between 0 and 1) */ - unsigned MAN_WOR : 1; /**< Manual WOR set (for randomized WOR times => no synch) */ - unsigned KT_RES_ERR : 1; /**< A hwtimer resource error has occurred (no free timers available) */ - unsigned TX : 1; /**< State machine TX lock, only ACKs will be received */ - unsigned WOR_RST : 1; /**< Reset CC1100 real time clock (WOR) on next WOR strobe */ -} cc1100_flags; - -/** - * @brief Statistic interface for debugging - */ -typedef struct cc1100_statistic { - uint32_t packets_in; - uint32_t packets_in_crc_fail; - uint32_t packets_in_while_tx; - uint32_t packets_in_dups; - uint32_t packets_in_up; - uint32_t packets_out; - uint32_t packets_out_acked; - uint32_t packets_out_broadcast; - uint32_t raw_packets_out; - uint32_t raw_packets_out_acked; - uint32_t acks_send; - uint32_t rx_buffer_max; - uint32_t watch_dog_resets; -} cc1100_statistic_t; - -enum radio_mode { - RADIO_MODE_GET = -1, /**< leave mode unchanged */ - RADIO_MODE_OFF = 0, /**< turn radio off */ - RADIO_MODE_ON = 1 /**< turn radio on */ -}; - -enum radio_result { - RADIO_PAYLOAD_TOO_LONG = -1, /**< payload too long */ - RADIO_WRONG_MODE = -2, /**< operation not supported in current mode */ - RADIO_ADDR_OUT_OF_RANGE = -3, /**< address out of range */ - RADIO_OP_FAILED = -4, /**< operation failed */ - RADIO_CS_TIMEOUT = -5, /**< Carrier Sense timeout: air was never free */ - RADIO_INVALID_PARAM = -6 /**< Invalid parameters passed to radio */ -}; - -/* ------------------------------------------------------------------------- */ -// Variable declarations (also used in other files) -/* ------------------------------------------------------------------------- */ - -extern volatile cc1100_flags rflags; ///< Radio flags - -extern volatile uint8_t radio_mode; ///< Radio mode -extern volatile uint8_t radio_state; ///< Radio state - -/** Mode callback functions */ -typedef void (*cc1100_mode_callback_t)(void); -extern volatile cc1100_mode_callback_t cc1100_go_idle; -extern volatile cc1100_mode_callback_t cc1100_go_receive; -extern volatile cc1100_mode_callback_t cc1100_go_after_tx; -extern volatile cc1100_mode_callback_t cc1100_setup_mode; - -extern volatile int wor_hwtimer_id; ///< WOR hwtimer identifier - -/* ------------------------------------------------------------------------- */ -// CC1100 radio driver API -/* ------------------------------------------------------------------------- */ - -/** - * @brief Set chip and state machine to IDLE mode. - */ -void cc1100_set_idle(void); - -/** - * @brief Convert radio mode to textual representation. - * - * @param mode The radio mode to convert. - * - * @return Textual representation of radio mode. - */ -char *cc1100_mode_to_text(uint8_t mode); - -/** - * @brief Convert radio state to textual representation. - * - * @param state The radio state to convert. - * - * @return Textual representation of radio state. - */ -char *cc1100_state_to_text(uint8_t state); - -/** - * @brief Convert current output power to textual representation. - * - * @return Textual representation of current output power in dBm. - */ -char *cc1100_get_output_power(char *buf); - -/** - * @brief Read out main radio control FSM state. - * - * @return Textual representation of current main radio control FSM state. - */ -char *cc1100_get_marc_state(void); - -/** - * @brief hwtimer wrapper function. - * - * This wrapper function puts the radio to receive mode. - * - * @param ptr Optional data (only to match hwtimer interface). - */ -void cc1100_hwtimer_go_receive_wrapper(void *ptr); - -/** - * @brief GDO0 interrupt handler. - */ -void cc1100_gdo0_irq(void); - -/** - * @brief GDO2 interrupt handler. - * - * @note Wakes up MCU on packet reception. - */ -void cc1100_gdo2_irq(void); - -/** - * @brief Transfer packet from CC1100 RX FIFO. - * - * Transfers a packet from CC1100 RX FIFO into a buffer. - * - * @param rxBuffer The buffer in which to transfer the packet. - * @param length The size of the buffer in which to transfer the packet. - * - * @return true if operation succeeded; false otherwise (e.g. no data - * available, buffer to small or CRC check failed). - */ -bool cc1100_spi_receive_packet(uint8_t *rxBuffer, radio_packet_length_t length); - -/** - * @brief Sends raw data. - * - * Sends the data of the given buffer. The first two bytes of the - * buffer must match the CC1100 packet format (so address interpretation - * succeeds). - *

- * This function is not mode safe!The radio must be woke up before - * sending and has to be put back manually to receive mode. - * - * @param tx_buffer Data source buffer. - * @param size The size of the data source buffer (maximum: 62 bytes). - */ -void cc1100_send_raw(uint8_t *tx_buffer, uint8_t size); - -/** - * @name Carrier Sense interface - * @{ - */ - -/** - * @brief Initialize radio for carrier sense detection. - */ -void cc1100_cs_init(void); - -/** - * @brief Enable or disable carrier sense detections. - * - * Turns interrupts for carrier sense on or off. - * - * @param enabled true if carrier sense detection should - * be enabled; false otherwise. - */ -void cc1100_cs_set_enabled(bool enabled); - -/** - * @brief Read carrier sense signal. - * - * @return High (1) if air is not free; low (0) if air is - * currently free. - */ -int cc1100_cs_read(void); - -/** - * @brief Reads the CCA (Clear Channel Assessment) flag. - * - * The CCA flag is set by an interrupt service routine, after - * carrier sense detection is enabled. So the status of the - * carrier sense signal can be evaluated in a non blocking - * manner. - * - * @return The current value of the CCA flag (High: air is free, - * low: air is not free). - */ -int cc1100_cs_read_cca(void); - -/** - * @brief Sets the CCA flag. - * - * @param cca The new value for the CCA flag. - */ -void cc1100_cs_write_cca(const int cca); - -/** @} */ - -/** - * @name Statistic interface - * @{ - */ - -/** - * @brief Reset radio statistics. - */ -void cc1100_reset_statistic(void); - -/** @} */ - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif diff --git a/drivers/cc110x_legacy_csma/cc1100_phy.c b/drivers/cc110x_legacy_csma/cc1100_phy.c deleted file mode 100644 index b3d3419d05..0000000000 --- a/drivers/cc110x_legacy_csma/cc1100_phy.c +++ /dev/null @@ -1,880 +0,0 @@ -/* - * Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. - * - * 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 dev_cc110x_legacy_csma - * @{ - */ - -/** - * @file - * @internal - * @brief TI Chipcon CC110x physical radio driver - * - * @author Thomas Hillebrandt - * @author Heiko Will - * @author Oliver Hahm - * @version $Revision: 2130 $ - * - * @note $Id: cc1100_phy.c 2130 2010-05-12 13:19:07Z hillebra $ - */ -#include -#include - -#include "hwtimer.h" -#include "vtimer.h" - -#include "cc1100.h" -#include "cc1100_spi.h" -#include "cc1100_phy.h" -#include "cc1100-defaultSettings.h" - -#include "protocol-multiplex.h" - -#include "kernel.h" -#include "thread.h" -#include "mutex.h" -#include "msg.h" -#include "debug.h" - -#define PRIORITY_CC1100 THREAD_PRIORITY_MAIN-1 - -#define MSG_POLL 12346 - -#define FLAGS_IDENTIFICATION (0x01) ///< Bit mask for reading the identification out of the flags field -#define R_FLAGS_PROTOCOL(x) ((x & 0x0E)>>1) ///< Macro for reading the protocol out of the flags field -#define W_FLAGS_PROTOCOL(x) ((x<<1) & 0x0E) ///< Macro for writing the protocol in the flags field - -/*---------------------------------------------------------------------------*/ -/* RX/TX buffer data structures */ -/*---------------------------------------------------------------------------*/ - -typedef struct { - cc1100_packet_layer0_t packet; - packet_info_t info; -} rx_buffer_t; - -#define RX_BUFF_SIZE (10) ///< Size of RX queue -static volatile uint8_t rx_buffer_head; ///< RX queue head -static volatile uint8_t rx_buffer_tail; ///< RX queue tail -static volatile uint8_t rx_buffer_size; ///< RX queue size -static rx_buffer_t rx_buffer[RX_BUFF_SIZE]; ///< RX buffer -static cc1100_packet_layer0_t tx_buffer; ///< TX buffer (for one packet) - -/*---------------------------------------------------------------------------*/ -/* Process/Event management data structures */ -/*---------------------------------------------------------------------------*/ - -#define MAX_PACKET_HANDLERS (5) -static packet_monitor_t packet_monitor; -static handler_entry_t handlers[MAX_PACKET_HANDLERS]; -static const pm_table_t handler_table; -static const char *cc1100_event_handler_name = "cc1100_event_handler"; -static mutex_t cc1100_mutex = MUTEX_INIT; -volatile kernel_pid_t cc1100_mutex_pid; -static vtimer_t cc1100_watch_dog; -static timex_t cc1100_watch_dog_period; - -static kernel_pid_t cc1100_event_handler_pid; -static void *cc1100_event_handler_function(void *); - -static char event_handler_stack[THREAD_STACKSIZE_MAIN]; - -/*---------------------------------------------------------------------------*/ -/* Sequence number buffer management data structures */ -/*---------------------------------------------------------------------------*/ - -/** - * @name Sequence Buffer - * @{ - */ -#define MAX_SEQ_BUFFER_SIZE (20) ///< Maximum size of the sequence number buffer - -typedef struct { - uint64_t m_ticks; ///< 64-bit timestamp - uint8_t source; ///< Source address - uint8_t identification; ///< Identification (1-bit) -} seq_buffer_entry_t; - -//* Sequence number buffer for this layer */ -static seq_buffer_entry_t seq_buffer[MAX_SEQ_BUFFER_SIZE]; - -//* Next position to enter a new value into ::seqBuffer */ -static uint8_t seq_buffer_pos = 0; - -/** - * @brief Last sequence number this node has seen - * - * @note (phySrc + flags.identification) - for speedup in ISR. - */ -static volatile uint16_t last_seq_num = 0; - -/** @} */ - -/*---------------------------------------------------------------------------*/ -// WOR configuration data structures -/*---------------------------------------------------------------------------*/ - -#define EVENT0_MAX (60493) ///< Maximum RX polling interval in milliseconds -#define WOR_RES_SWITCH (1891) ///< Switching point value in milliseconds between - ///< WOR_RES = 0 and WOR_RES = 1 -#define DUTY_CYCLE_SIZE (7) ///< Length of duty cycle array - -cc1100_wor_config_t cc1100_wor_config; ///< CC1100 WOR configuration - -uint16_t cc1100_burst_count; ///< Burst count, number of packets in a burst transfer -uint8_t cc1100_retransmission_count_uc; ///< Number of retransmissions for unicast -uint8_t cc1100_retransmission_count_bc; ///< Number of retransmissions for broadcast - -static const double duty_cycle[2][DUTY_CYCLE_SIZE] = { ///< Duty cycle values from AN047 - {12.5, 6.25, 3.125, 1.563, 0.781, 0.391, 0.195}, - {1.95, 0.9765, 0.4883, 0.2441, 0.1221, 0.061035, 0.030518} -}; - -/*---------------------------------------------------------------------------*/ -// Data structures for statistic -/*---------------------------------------------------------------------------*/ - -cc1100_statistic_t cc1100_statistic; - -/*---------------------------------------------------------------------------*/ -// Initialization of physical layer -/*---------------------------------------------------------------------------*/ - -void cc1100_phy_init(void) -{ - int i; - - rx_buffer_head = 0; - rx_buffer_tail = 0; - rx_buffer_size = 0; - - /* Initialize RX-Buffer (clear content) */ - for (i = 0; i < RX_BUFF_SIZE; i++) { - rx_buffer->packet.length = 0; - } - - /* Initialize handler table & packet monitor */ - packet_monitor = NULL; - pm_init_table((pm_table_t *)&handler_table, MAX_PACKET_HANDLERS, handlers); - - /* Clear sequence number buffer */ - memset(seq_buffer, 0, sizeof(seq_buffer_entry_t) * MAX_SEQ_BUFFER_SIZE); - - /* Initialize mutex */ - cc1100_mutex_pid = KERNEL_PID_UNDEF; - - /* Allocate event numbers and start cc1100 event process */ - cc1100_event_handler_pid = thread_create(event_handler_stack, sizeof(event_handler_stack), PRIORITY_CC1100, CREATE_STACKTEST, - cc1100_event_handler_function, NULL, cc1100_event_handler_name); - - /* Active watchdog for the first time */ - if (radio_mode == CC1100_MODE_CONSTANT_RX) { - cc1100_watch_dog_period = timex_set(CC1100_WATCHDOG_PERIOD, 0); - - if (timex_cmp(cc1100_watch_dog_period, timex_set(0, 0)) != 0) { - vtimer_set_msg(&cc1100_watch_dog, cc1100_watch_dog_period, cc1100_event_handler_pid, MSG_TIMER, NULL); - } - } -} - -/*---------------------------------------------------------------------------*/ -/* CC1100 mutual exclusion */ -/*---------------------------------------------------------------------------*/ - -void cc1100_phy_mutex_lock(void) -{ - if (sched_active_pid != cc1100_mutex_pid) { - mutex_lock(&cc1100_mutex); - cc1100_mutex_pid = sched_active_pid; - } -} - -void cc1100_phy_mutex_unlock(void) -{ - cc1100_mutex_pid = KERNEL_PID_UNDEF; - mutex_unlock(&cc1100_mutex); -} - -/*---------------------------------------------------------------------------*/ -// Statistical functions -/*---------------------------------------------------------------------------*/ - -void cc1100_reset_statistic(void) -{ - cc1100_statistic.packets_in_up = 0; - cc1100_statistic.acks_send = 0; - cc1100_statistic.packets_out_acked = 0; - cc1100_statistic.packets_in = 0; - cc1100_statistic.packets_out = 0; - cc1100_statistic.packets_out_broadcast = 0; - cc1100_statistic.raw_packets_out_acked = 0; - cc1100_statistic.raw_packets_out = 0; - cc1100_statistic.packets_in_dups = 0; - cc1100_statistic.packets_in_crc_fail = 0; - cc1100_statistic.packets_in_while_tx = 0; - cc1100_statistic.rx_buffer_max = 0; - cc1100_statistic.watch_dog_resets = 0; -} - -void cc1100_print_statistic(void) -{ - printf("\nStatistic on CC1100 interface\n\n"); - printf("Total packets send on layer 0.5 (broadcast): %lu\n", cc1100_statistic.packets_out_broadcast); - printf("Total packets send on layer 0.5 (unicast): %lu\n", cc1100_statistic.packets_out); - printf("Total packets Acked on layer 0.5: %lu (%.2f%%)\n", cc1100_statistic.packets_out_acked, cc1100_statistic.packets_out_acked * (100.0f / (float)cc1100_statistic.packets_out)); - printf("Total packets send on layer 0: %lu\n", cc1100_statistic.raw_packets_out); - printf("Total packets send on layer 0 w. Ack on Layer 0.5: %lu (Avg. Ack after: %lu packets)\n", cc1100_statistic.raw_packets_out_acked, cc1100_statistic.raw_packets_out_acked / cc1100_statistic.packets_out_acked); - printf("Burst count on this node: %i (%.2f%%)\n", cc1100_burst_count, (100 / (float)cc1100_burst_count) * (cc1100_statistic.raw_packets_out_acked / (float) cc1100_statistic.packets_out_acked)); - printf("Total packets In on layer 0: %lu\n", cc1100_statistic.packets_in); - printf("Duped packets In on layer 0: %lu\n", cc1100_statistic.packets_in_dups); - printf("Corrupted packets In on layer 0: %lu\n", cc1100_statistic.packets_in_crc_fail); - printf("Packets In on layer 0 while in TX: %lu\n", cc1100_statistic.packets_in_while_tx); - printf("Total packets In and up to layer 1: %lu (%.2f%%)\n", cc1100_statistic.packets_in_up, cc1100_statistic.packets_in_up * (100.0f / (float)cc1100_statistic.packets_in)); - printf("Total Acks send on layer 0.5: %lu\n", cc1100_statistic.acks_send); - printf("RX Buffer max: %lu (now: %u)\n", cc1100_statistic.rx_buffer_max, rx_buffer_size); - printf("State machine resets by cc1100 watchdog: %lu\n", cc1100_statistic.watch_dog_resets); -} - -void cc1100_print_config(void) -{ - char buf[8]; - printf("Current radio mode: %s\r\n", cc1100_mode_to_text(radio_mode)); - printf("Current radio state: %s\r\n", cc1100_state_to_text(radio_state)); - printf("Current MARC state: %s\r\n", cc1100_get_marc_state()); - printf("Current channel number: %u\r\n", cc1100_get_channel()); - printf("Burst count: %u packet(s)\r\n", cc1100_burst_count); - printf("Retransmissions (unicast): %u - if no ACK\r\n", cc1100_retransmission_count_uc); - printf("Retransmissions (broadcast): %u - always\r\n", cc1100_retransmission_count_bc); - printf("Output power setting: %s\r\n", cc1100_get_output_power(buf)); - - if (radio_mode == CC1100_MODE_WOR) { - 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, - cc1100_wor_config.rx_time_ms); - printf("CC1100 WOREVT0 register: 0x%.2X\r\n", cc1100_wor_config.wor_evt_0); - printf("CC1100 WOREVT1 register: 0x%.2X\r\n", cc1100_wor_config.wor_evt_1); - printf("CC1100 WOR_CTRL register: 0x%.2X\r\n", cc1100_wor_config.wor_ctrl); - printf("CC1100 MAN_WOR flag: %u\r\n", rflags.MAN_WOR); - } -} - -/*---------------------------------------------------------------------------*/ -// Change of RX polling interval (T_EVENT0) -/*---------------------------------------------------------------------------*/ - -inline uint16_t iround(double d) -{ - return (uint16_t) (d + 0.5); -} - -int cc1100_phy_calc_wor_settings(uint16_t millis) -{ - /* Get packet interval as milliseconds */ - double t_packet_interval = (double)((T_PACKET_INTERVAL) / 1000.0); - - /* Calculate minimal T_EVENT0: - - (1) t_rx_time > t_packet_interval - (2) t_rx_time = T_EVENT0 / 2 ^ (RX_TIME + 3 + WOR_RES) - ------------------------------------------------------ - with RX_TIME = 0 && WOR_RES = 0 => event0_min > t_packet_interval * 8 - - t_packet_interval = 3.8 ms (@400kbit/s) - - => event0_min = Math.ceil(3.8 * 8) + 10 */ - uint16_t event0_min = (uint16_t)(t_packet_interval * 8) + 1 + 10; - - /* Check if given value is in allowed range */ - if (millis < event0_min || millis > EVENT0_MAX) { - return -1; - } - - /* Time resolution for EVENT0 and other WOR parameters, */ - /* possible values are 0 and 1 if WOR is used */ - uint8_t wor_res = millis < WOR_RES_SWITCH ? 0 : 1; - - /* Calculate new value for EVENT0 */ - double tmp = (millis * 26) / (double) 750; - - if (wor_res == 1) { - tmp /= 32; - } - - tmp *= 1000; - uint16_t event0 = (uint16_t) iround(tmp); - - /* Calculate all possible RX timeouts */ - int i; - double rx_timeouts[DUTY_CYCLE_SIZE]; - - for (i = 0; i < DUTY_CYCLE_SIZE; i++) { - rx_timeouts[i] = (millis * duty_cycle[wor_res][i]) / 100; - } - - /* Calculate index for optimal rx_timeout (MCSM2.RX_TIME) (if possible) */ - int idx = -1; - - for (i = DUTY_CYCLE_SIZE - 1; i >= 0; i--) { - if (rx_timeouts[i] > t_packet_interval) { - idx = i; - break; - } - } - - /* If no index found, exit here (configuration with given value is not possible) */ - if (idx == -1) { - return -1; - } - - /* Calculate burst count (secure burst calculation with 8 extra packets) */ - int burst_count = (int) iround(millis / t_packet_interval) + 8; - - /* All calculations successful, now its safe to store */ - /* final configuration values in global WOR configuration */ - cc1100_wor_config.rx_interval = millis; - cc1100_wor_config.wor_ctrl = (wor_res == 0) ? 0x78 : 0x79; - cc1100_wor_config.wor_evt_0 = (uint8_t) event0; - cc1100_wor_config.wor_evt_1 = (uint8_t)(event0 >> 8); - cc1100_wor_config.rx_time_reg = idx; - cc1100_wor_config.rx_time_ms = rx_timeouts[idx]; - - /* If successful, return number of packets in a burst transfer */ - return burst_count; -} - -/*---------------------------------------------------------------------------*/ -// Sequence number buffer management -/*---------------------------------------------------------------------------*/ - -static bool contains_seq_entry(uint8_t src, uint8_t id) -{ - int i; - uint32_t cmp; - timex_t now_timex; - vtimer_now(&now_timex); - - for (i = 0; i < MAX_SEQ_BUFFER_SIZE; i++) { - if ((seq_buffer[i].source == src) && (seq_buffer[i].identification == id)) { - /* Check if time stamp is OK */ - cmp = (radio_mode == CC1100_MODE_WOR) ? cc1100_wor_config.rx_interval : 16000; /* constant RX ~16ms */ - - if ((timex_uint64(now_timex) - seq_buffer[i].m_ticks < cmp)) { - return true; - } - else { - seq_buffer[i].source = 0; /* Reset */ - } - } - } - - return false; -} - -static void add_seq_entry(uint8_t src, uint8_t id) -{ - /* Remove all entries with given source to avoid short time overflow - * of one bit counter (of the source node). So a valid packet would get - * lost (especially important in constant RX mode). */ - int i; - - for (i = 0; i < MAX_SEQ_BUFFER_SIZE; i++) { - if (seq_buffer[i].source == src) { - seq_buffer[i].source = 0; /* Reset */ - } - } - - /* Add new entry */ - seq_buffer[seq_buffer_pos].source = src; - seq_buffer[seq_buffer_pos].identification = id; - timex_t now; - vtimer_now(&now); - seq_buffer[seq_buffer_pos].m_ticks = timex_uint64(now); - - /* Store 16 bit sequence number of layer 0 for speedup */ - last_seq_num = src; - last_seq_num <<= 8; - last_seq_num += id; - - seq_buffer_pos++; - - if (seq_buffer_pos == MAX_SEQ_BUFFER_SIZE) { - seq_buffer_pos = 0; - } -} - -/*---------------------------------------------------------------------------*/ -/* CC1100 physical layer send functions */ -/*---------------------------------------------------------------------------*/ - -static void send_link_level_ack(uint8_t dest) -{ - uint8_t oldState = radio_state; /* Save old state */ - cc1100_packet_layer0_t ack; /* Local packet, don't overwrite */ - - 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_MCSM1, 0x00); /* TX_OFFMODE = IDLE */ - ack.length = 3; /* possible packet in txBuffer!*/ - ack.address = dest; - ack.phy_src = rflags.RSSI; - ack.flags = (LAYER_1_PROTOCOL_LL_ACK << 1); - cc1100_send_raw((uint8_t *)&ack, /* IDLE -> TX (88.4 us) */ - ack.length + 1); - cc1100_spi_write_reg(CC1100_MCSM0, 0x18); /* Turn on FS-Autocal */ - cc1100_spi_write_reg(CC1100_MCSM1, 0x03); /* TX_OFFMODE = RX */ - radio_state = oldState; /* Restore state */ - cc1100_statistic.acks_send++; -} - -static bool send_burst(cc1100_packet_layer0_t *packet, uint8_t retries, uint8_t rtc) -{ - int i; - radio_state = RADIO_SEND_BURST; - rflags.LL_ACK = false; - - for (i = 1; i <= cc1100_burst_count; i++) { - /* - * Number of bytes to send is: - * length of phy payload (packet->length) - * + size of length field (1 byte) - */ - extern unsigned long hwtimer_now(void); - timer_tick_t t = hwtimer_now() + RTIMER_TICKS(T_PACKET_INTERVAL); - cc1100_send_raw((uint8_t *)packet, packet->length + 1); /* RX -> TX (9.6 us) */ - - cc1100_statistic.raw_packets_out++; - - /* Delay until predefined "send" interval has passed */ - timer_tick_t now = hwtimer_now(); - - if (t > now) { - hwtimer_wait(t - now); - } - - /** - * After sending the packet the CC1100 goes automatically - * into RX mode (21.5 us) (listening for an ACK). - * Do not interrupt burst if send to broadcast address (a node may - * have the broadcast address at startup and would stop the burst - * by sending an ACK). - */ - if (rflags.LL_ACK && packet->address != CC1100_BROADCAST_ADDRESS) { - cc1100_statistic.raw_packets_out_acked += i; - break; - } - } - - /* No link level ACK -> do retry if retry counter greater zero - * Note: Event broadcast packets can be sent repeatedly if in - * constant RX mode. In WOR mode it is not necessary, so - * set retry count to zero.*/ - if (!rflags.LL_ACK && retries > 0) { - return send_burst(packet, retries - 1, rtc + 1); - } - - /* Store number of transmission retries */ - rflags.RETC = rtc; - rflags.RPS = rtc * cc1100_burst_count + i; - - if (i > cc1100_burst_count) { - rflags.RPS--; - } - - rflags.TX = false; - - /* Go to mode after TX (CONST_RX -> RX, WOR -> WOR) */ - cc1100_go_after_tx(); - - /* Burst from any other node is definitely over */ - last_seq_num = 0; - - if (packet->address != CC1100_BROADCAST_ADDRESS && !rflags.LL_ACK) { - return false; - } - - return true; -} - -int cc1100_send(radio_address_t addr, protocol_t protocol, int priority, char *payload, radio_packet_length_t payload_len) -{ - (void) priority; - - bool result; - int return_code; - uint8_t address; - uint8_t retries; - - /* Lock mutex, nobody else should send now */ - cc1100_phy_mutex_lock(); - - /* TX state machine lock -> no timers (WOR), no packets (only ACKs) */ - rflags.TX = true; - - /* Set chip to idle state */ - cc1100_set_idle(); - - /* CC1100 radio layer only supports 8-bit addresses */ - address = addr; - - /* Loopback not supported */ - if (address == cc1100_get_address()) { - return_code = RADIO_ADDR_OUT_OF_RANGE; - goto mode_before_final; - } - - /* Check address */ - if (address > MAX_UID) { - return_code = RADIO_ADDR_OUT_OF_RANGE; - goto mode_before_final; - } - - /* Packet too long */ - if (payload_len > MAX_DATA_LENGTH) { - return_code = RADIO_PAYLOAD_TOO_LONG; - goto mode_before_final; - } - - if (radio_state == RADIO_PWD) { - return_code = RADIO_WRONG_MODE; - goto mode_before_final; - } - - /* Set number of transmission retries */ - retries = (address == CC1100_BROADCAST_ADDRESS) ? - cc1100_retransmission_count_bc : cc1100_retransmission_count_uc; - - memset(tx_buffer.data, 0, MAX_DATA_LENGTH); /* Clean data */ - - /* TODO: If packets are shorter than max packet size, WOR interval is too long. - * This must be solved in some way. */ - tx_buffer.length = 3 + payload_len; /* 3 bytes (A&PS&F) + data length */ - tx_buffer.address = address; /* Copy destination address */ - tx_buffer.flags = 0x00; /* Set clean state */ - tx_buffer.flags = W_FLAGS_PROTOCOL(protocol); /* Copy protocol identifier */ - tx_buffer.phy_src = (uint8_t) cc1100_get_address(); /* Copy sender address */ - - /* Set identification number of packet */ - tx_buffer.flags |= rflags.SEQ; /* Set flags.identification (bit 0) */ - rflags.SEQ = !rflags.SEQ; /* Toggle value of layer 0 sequence number bit */ - - memcpy(tx_buffer.data, payload, payload_len); /* Copy data */ - - /* Send the packet */ - cc1100_spi_write_reg(CC1100_MCSM0, 0x08); /* Turn off FS-Autocal */ - result = send_burst(&tx_buffer, retries, 0); /* Send raw burst */ - return_code = result ? payload_len : RADIO_OP_FAILED; - - /* Collect statistics */ - if (address != CC1100_BROADCAST_ADDRESS) { - cc1100_statistic.packets_out++; - - if (result) { - cc1100_statistic.packets_out_acked++; - } - } - else { - cc1100_statistic.packets_out_broadcast++; - } - - goto final; - -mode_before_final: - rflags.TX = false; - /* Definitely set secure mode (CONST_RX -> RX, WOR -> WOR) */ - cc1100_go_after_tx(); - -final: - /* Release mutex and return */ - cc1100_phy_mutex_unlock(); - return return_code; -} - -/*---------------------------------------------------------------------------*/ -/* RX Event Handler */ -/*---------------------------------------------------------------------------*/ - -bool cc1100_set_packet_monitor(packet_monitor_t monitor) -{ - packet_monitor = monitor; - return true; -} - -int cc1100_set_packet_handler(protocol_t protocol, packet_handler_t handler) -{ - if (protocol > 7) { - return -1; /* Only 3-bit value allowed */ - } - - return pm_set_handler(&handler_table, protocol, handler); -} - -static void *cc1100_event_handler_function(void *arg) -{ - (void) arg; - - msg_t m; - - while (1) { - if (timex_uint64(cc1100_watch_dog_period) != 0) { - vtimer_remove(&cc1100_watch_dog); - } - - /* Test if any resource error has occurred */ - if (rflags.KT_RES_ERR) { - rflags.KT_RES_ERR = false; - /* possibly do something, e.g. log error condition */ - } - - if (m.type == MSG_TIMER) { - if (radio_mode == CC1100_MODE_CONSTANT_RX) { - uint8_t state = cc1100_spi_read_status(CC1100_MARCSTATE) & MARC_STATE; - - if ((state < 13 || state > 15) && radio_state == RADIO_RX && !rflags.TX) { - cc1100_statistic.watch_dog_resets++; - - if (state != 1) { - cc1100_spi_strobe(CC1100_SIDLE); - } - - cc1100_spi_strobe(CC1100_SFRX); - cc1100_go_receive(); - } - } - else { - /* Radio mode is WOR, cannot read current MARC state, will */ - /* always be IDLE. So do nothing here, e.g. disable watchdog. */ - } - } - - while (rx_buffer_size > 0) { - rx_buffer_t *packet = &rx_buffer[rx_buffer_head]; - protocol_t p = R_FLAGS_PROTOCOL(packet->packet.flags); - - if (packet_monitor != NULL) { - packet_monitor((void *)&packet->packet.data, packet->packet.length, p, &packet->info); - } - - pm_invoke(&handler_table, p, (void *)&packet->packet.data, MAX_DATA_LENGTH, &packet->info); - dINT(); - rx_buffer_size--; - rx_buffer_head++; - - if (rx_buffer_head == RX_BUFF_SIZE) { - rx_buffer_head = 0; - } - - eINT(); - } - - dINT(); - - if (rx_buffer_size == 0) { - if (timex_uint64(cc1100_watch_dog_period) != 0) { - vtimer_set_msg(&cc1100_watch_dog, cc1100_watch_dog_period, - cc1100_event_handler_pid, MSG_TIMER, NULL); - } - - msg_receive(&m); - } - - eINT(); - } - - return NULL; -} - -/*---------------------------------------------------------------------------*/ -/* CC1100 packet (RX) ISR */ -/*---------------------------------------------------------------------------*/ - -void cc1100_phy_rx_handler(void) -{ - msg_t m; - m.type = MSG_POLL; - bool dup = false; - bool res = false; - - /* Possible packet received, RX -> IDLE (0.1 us) */ - rflags.CAA = false; - rflags.MAN_WOR = false; - cc1100_statistic.packets_in++; - - /* If WOR timer set, delete it now (new one will be set at end of ISR) */ - if (wor_hwtimer_id != -1) { - hwtimer_remove(wor_hwtimer_id); - wor_hwtimer_id = -1; - } - - /* Transfer packet into temporary buffer position */ - res = cc1100_spi_receive_packet((uint8_t *) & (rx_buffer[rx_buffer_tail].packet), sizeof(cc1100_packet_layer0_t)); - - if (res) { - /* Get packet pointer and store additional data in packet info structure */ - 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.source = p->phy_src; - rx_buffer[rx_buffer_tail].info.destination = p->address; - rx_buffer[rx_buffer_tail].info.rssi = rflags.RSSI; - rx_buffer[rx_buffer_tail].info.lqi = rflags.LQI; - rx_buffer[rx_buffer_tail].info.promiscuous = false; - - /* Get protocol and id field out of flags field */ - uint8_t protocol = R_FLAGS_PROTOCOL(p->flags); - uint8_t identification = (p->flags & FLAGS_IDENTIFICATION); - - /* If received packet was an ACK (here we must be in - * TX lock state, otherwise we don't expect an ACK) */ - if (protocol == LAYER_1_PROTOCOL_LL_ACK && rflags.TX) { - /* And packet was for us */ - if (p->address == cc1100_get_address()) { - /* Stop the burst */ - rflags.LL_ACK = true; - rflags.RSSI_SEND = p->phy_src; - rflags.TCP = (uint32_t)((uint16_t *)p->data); - } - - return; - } - else { - /* No ACK received so TOF is unpredictable */ - rflags.TOF = 0; - } - - /* If we are sending a burst, don't accept packets. - * Only ACKs are processed (for stopping the burst). - * Same if state machine is in TX lock. */ - if (radio_state == RADIO_SEND_BURST || rflags.TX) { - cc1100_statistic.packets_in_while_tx++; - return; - } - - /* If buffer is currently full -> don't check sequence numbers, send - * ACK and restore state (keep always one position free for temporary packets) */ - if (rx_buffer_size >= RX_BUFF_SIZE - 1) { - goto send_ack; - } - - /* Build 16 bit sequence number of layer 0 for fast check */ - uint16_t new_seq_num = p->phy_src; - new_seq_num <<= 8; - new_seq_num += identification; - - /* Duplicate packet detection */ - dup = true; - - /* If new and last sequence number are the same, then discard packet */ - if (last_seq_num != new_seq_num) { - /* Do a more precise check (takes more time) with larger buffer */ - if (!contains_seq_entry(p->phy_src, identification)) { - /* Sequence number is new, no duplicate packet */ - dup = false; - - /* Store sequence number */ - add_seq_entry(p->phy_src, identification); - - /* Make temporary packet in RX buffer to a "real" packet which is processed */ - rx_buffer_size++; - - if (rx_buffer_size > cc1100_statistic.rx_buffer_max) { - cc1100_statistic.rx_buffer_max = rx_buffer_size; - } - - rx_buffer_tail++; - - if (rx_buffer_tail == RX_BUFF_SIZE) { - rx_buffer_tail = 0; - } - - /* Send empty message to wake up receiver process. - * Receiver process could already be running (triggered by previous message), - * so function would return 0 and assume the receiver is not waiting but indeed - * all is working fine.*/ - msg_send_int(&m, cc1100_event_handler_pid); - cc1100_statistic.packets_in_up++; - } - } - - send_ack: - - /* 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!*/ - if (p->address == cc1100_get_address() && protocol != LAYER_1_PROTOCOL_LL_ACK) { - send_link_level_ack(p->phy_src); - - /* After LL-ACK burst is over, reset number */ - last_seq_num = 0; - } - - /* If duplicate packet detected, clear rxBuffer position */ - if (dup) { - cc1100_statistic.packets_in_dups++; - } - - /* If packet interrupted this nodes send call, - * don't change anything after this point. */ - if (radio_state == RADIO_AIR_FREE_WAITING) { - cc1100_spi_strobe(CC1100_SRX); - hwtimer_wait(IDLE_TO_RX_TIME); - return; - } - - /* Valid packet. After a wake-up, the radio should be in IDLE. - * So put CC1100 to RX for WOR_TIMEOUT (have to manually put - * the radio back to sleep/WOR).*/ - 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) */ - - if (radio_mode == CC1100_MODE_CONSTANT_RX) { - cc1100_spi_strobe(CC1100_SRX); - hwtimer_wait(IDLE_TO_RX_TIME); - radio_state = RADIO_RX; - /* Return here if mode is CONSTANT_RX_MODE */ - return; - } - else { - cc1100_spi_strobe(CC1100_SPWD); - radio_state = RADIO_PWD; - } - - /* 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); - - if (wor_hwtimer_id == -1) { - /* Signal hwtimer resource error, radio stays in RX, - * so no big problem, only energy is wasted. */ - rflags.KT_RES_ERR = true; - } - } - else { - /* No ACK received so TOF is unpredictable */ - rflags.TOF = 0; - - /* CRC false or RX buffer full -> clear RX FIFO in both cases */ - last_seq_num = 0; /* Reset for correct burst detection */ - cc1100_spi_strobe(CC1100_SIDLE); /* Switch to IDLE (should already be)... */ - cc1100_spi_strobe(CC1100_SFRX); /* ...for flushing the RX FIFO */ - - /* If packet interrupted this nodes send call, - * don't change anything after this point. */ - if (radio_state == RADIO_AIR_FREE_WAITING) { - cc1100_spi_strobe(CC1100_SRX); - hwtimer_wait(IDLE_TO_RX_TIME); - return; - } - - /* If currently sending, exit here (don't go to RX/WOR) */ - if (radio_state == RADIO_SEND_BURST) { - cc1100_statistic.packets_in_while_tx++; - return; - } - - /* No valid packet, so go back to RX/WOR as soon as possible */ - cc1100_go_receive(); - } -} diff --git a/drivers/cc110x_legacy_csma/cc1100_phy.h b/drivers/cc110x_legacy_csma/cc1100_phy.h deleted file mode 100644 index e118796597..0000000000 --- a/drivers/cc110x_legacy_csma/cc1100_phy.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. - * - * 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 dev_cc110x_legacy_csma - * @{ - */ - -/** - * @file - * @internal - * @brief TI Chipcon CC110x physical radio driver - * - * @author Thomas Hillebrandt - * @author Heiko Will - * @version $Revision: 1285 $ - * - * @note $Id: cc1100_phy.h 1285 2009-08-27 13:22:42Z hillebra $ - */ -#ifndef CC1100_PHY_H_ -#define CC1100_PHY_H_ - -#include -#include -//#include "cc1100.h" -#include "cc1100-internal.h" -#include "cc110x_legacy_csma.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MAX_DATA_LENGTH (0x3A) ///< Maximum data length of layer 0 = 58 Bytes. - -/** - * @brief CC1100 layer 0 protocol - * - *

----------------------------------------------------
-|        |         |         |       |            |
-| Length | Address | PhySrc  | Flags |    Data    |
-|        |         |         |       |            |
----------------------------------------------------
-  1 byte   1 byte    1 byte   1 byte   <= 58 bytes
-
-Flags:
-        Bit | Meaning
-        --------------------
-        7:4 | -
-        3:1 | Protocol
-          0 | Identification
-
-Notes: -\li length & address are given by CC1100 -\li Identification is increased is used to scan duplicates. It must be increased - for each new packet and kept for packet retransmissions. - */ -typedef struct __attribute__((packed)) cc1100_packet_layer0_t { - radio_packet_length_t length; ///< Length of the packet (without length byte) - uint8_t address; ///< Destination address - uint8_t phy_src; ///< Source address (physical source) - uint8_t flags; ///< Flags - uint8_t data[MAX_DATA_LENGTH]; ///< Data (high layer protocol) -} cc1100_packet_layer0_t; - -typedef struct cc1100_wor_config_t { - uint16_t rx_interval; ///< RX polling interval in milliseconds - float rx_time_ms; ///< WOR_RX_TIME in milliseconds - uint8_t rx_time_reg; ///< WOR_RX_TIME (CC1100 "MCSM2.RX_TIME" register value) - uint8_t wor_evt_0; ///< CC1100 WOREVT0 register value - uint8_t wor_evt_1; ///< CC1100 WOREVT1 register value - uint8_t wor_ctrl; ///< CC1100 WORCTRL register value -} cc1100_wor_config_t; - -/*---------------------------------------------------------------------------*/ -// CC1100 Wake-On-Radio configuration -/*---------------------------------------------------------------------------*/ - -extern uint16_t cc1100_burst_count; -extern uint8_t cc1100_retransmission_count_uc; -extern uint8_t cc1100_retransmission_count_bc; -extern cc1100_wor_config_t cc1100_wor_config; - -/*---------------------------------------------------------------------------*/ -// CC1100 physical radio driver API -/*---------------------------------------------------------------------------*/ - -/** - * @brief Initialize the physical radio layer. - */ -void cc1100_phy_init(void); - -/** - * Lock radio for exclusive access. If no lock could be gained, - * the current process is blocked and waits for release of lock. - * - * This function can be used by MAC for locking the radio, the - * ::cc1100_send function will automatically lock the radio. - */ -void cc1100_phy_mutex_lock(void); - -/** - * Unlock radio. Must always be called after ::cc1100_phy_mutex_lock. - * If ::cc1100_send is called, it will automatically unlock the radio - * at the end of transmission. - */ -void cc1100_phy_mutex_unlock(void); - -/** - * @brief Calculate and store Wake-On-Radio settings. - * - * Calculates WOR settings for a given RX interval in - * milliseconds and stores the values in global configuration. - *

- * Does not change settings if not applicable. - * - * @param millis Desired RX interval in milliseconds [50..60000]. - * - * @return The burst count (number of packets in a burst transfer) - * or -1 if an error occurred (e.g. RX interval invalid). - */ -int cc1100_phy_calc_wor_settings(uint16_t millis); - -/** - * @brief Handler function for incoming packets. - * - * This handler function must be called in the receive - * interrupt service routine. - */ -void cc1100_phy_rx_handler(void); - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif /* CC1100_PHY_H_ */ diff --git a/drivers/cc110x_legacy_csma/cc1100_spi.c b/drivers/cc110x_legacy_csma/cc1100_spi.c deleted file mode 100644 index 4611688d95..0000000000 --- a/drivers/cc110x_legacy_csma/cc1100_spi.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. - * - * 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 dev_cc110x_legacy_csma - * @{ - */ - -/** - * @file - * @internal - * @brief TI Chipcon CC1100 SPI driver - * - * @author Thomas Hillebrandt - * @author Heiko Will - * @version $Revision: 1775 $ - * - * @note $Id: cc1100_spi.c 1775 2010-01-26 09:37:03Z hillebra $ - */ - -#include - -#include "irq.h" -#include "arch_cc1100.h" -#include "cc1100.h" -#include "cc1100_spi.h" -#include "cc1100-internal.h" - -/*---------------------------------------------------------------------------*/ -// CC1100 SPI access -/*---------------------------------------------------------------------------*/ - -uint8_t -cc1100_spi_writeburst_reg(uint8_t addr, char *src, uint8_t count) -{ - int i = 0; - unsigned int cpsr = disableIRQ(); - cc110x_spi_select(); - cc110x_txrx(addr | CC1100_WRITE_BURST); - - while (i < count) { - cc110x_txrx(src[i]); - i++; - } - - cc110x_spi_unselect(); - restoreIRQ(cpsr); - return count; -} - -void -cc1100_spi_readburst_reg(uint8_t addr, char *buffer, uint8_t count) -{ - int i = 0; - unsigned int cpsr = disableIRQ(); - cc110x_spi_select(); - cc110x_txrx(addr | CC1100_READ_BURST); - - while (i < count) { - buffer[i] = cc110x_txrx(CC1100_NOBYTE); - i++; - } - - cc110x_spi_unselect(); - restoreIRQ(cpsr); -} - -void -cc1100_spi_write_reg(uint8_t addr, uint8_t value) -{ - unsigned int cpsr = disableIRQ(); - cc110x_spi_select(); - cc110x_txrx(addr); - cc110x_txrx(value); - cc110x_spi_unselect(); - restoreIRQ(cpsr); -} - -uint8_t cc1100_spi_read_reg(uint8_t addr) -{ - uint8_t result; - unsigned int cpsr = disableIRQ(); - cc110x_spi_select(); - cc110x_txrx(addr | CC1100_READ_SINGLE); - result = cc110x_txrx(CC1100_NOBYTE); - cc110x_spi_unselect(); - restoreIRQ(cpsr); - return result; -} - -uint8_t cc1100_spi_read_status(uint8_t addr) -{ - uint8_t result; - unsigned int cpsr = disableIRQ(); - cc110x_spi_select(); - cc110x_txrx(addr | CC1100_READ_BURST); - result = cc110x_txrx(CC1100_NOBYTE); - cc110x_spi_unselect(); - restoreIRQ(cpsr); - return result; -} - -uint8_t cc1100_spi_strobe(uint8_t c) -{ - uint8_t result; - unsigned int cpsr = disableIRQ(); - cc110x_spi_select(); - result = cc110x_txrx(c); - cc110x_spi_unselect(); - restoreIRQ(cpsr); - return result; -} - -/** @} */ diff --git a/drivers/cc110x_legacy_csma/cc1100_spi.h b/drivers/cc110x_legacy_csma/cc1100_spi.h deleted file mode 100644 index 38485ca328..0000000000 --- a/drivers/cc110x_legacy_csma/cc1100_spi.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. - * - * 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 dev_cc110x_legacy_csma - * @{ - */ - -/** - * @file - * @internal - * @brief TI Chipcon CC1100 SPI driver - * - * @author Thomas Hillebrandt - * @author Heiko Will - * @version $Revision: 1775 $ - * - * @note $Id: cc1100_spi.h 1775 2010-01-26 09:37:03Z hillebra $ - */ - -#ifndef CC1100_SPI_H_ -#define CC1100_SPI_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -int cc110x_get_gdo0(void); -int cc110x_get_gdo1(void); -int cc110x_get_gdo2(void); - -void cc110x_spi_init(void); -void cc110x_spi_cs(void); -void cc110x_spi_select(void); -void cc110x_spi_unselect(void); - -uint8_t cc1100_spi_writeburst_reg(uint8_t addr, char *buffer, uint8_t count); -void cc1100_spi_readburst_reg(uint8_t addr, char *buffer, uint8_t count); -void cc1100_spi_write_reg(uint8_t addr, uint8_t value); -uint8_t cc1100_spi_read_reg(uint8_t addr); -uint8_t cc1100_spi_read_status(uint8_t addr); -uint8_t cc1100_spi_strobe(uint8_t c); - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif /* CC1100_SPI_H_ */ diff --git a/drivers/cc2420/Makefile b/drivers/cc2420/Makefile deleted file mode 100644 index 48422e909a..0000000000 --- a/drivers/cc2420/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(RIOTBASE)/Makefile.base diff --git a/drivers/cc2420/cc2420.c b/drivers/cc2420/cc2420.c deleted file mode 100644 index cc2dc1edaa..0000000000 --- a/drivers/cc2420/cc2420.c +++ /dev/null @@ -1,298 +0,0 @@ -/** - * cc2420.c - Implementation of cc2420 functions. - * Copyright (C) 2013 Milan Babel - * Copyright (C) 2014 Kévin Roussel - * - * 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. - */ - -#include "panic.h" -#include "cc2420.h" -#include "cc2420_spi.h" -#include "cc2420_settings.h" -#include "cc2420_arch.h" -#include "hwtimer.h" -#include "transceiver.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - - -/* number of attempts to turn on transceiver at startup, before panicking */ -#define CC2420_STARTUP_ATTEMPTS 3 - -/* startup timeout (2 ms) in 16MHz-clock cycles */ -#define CC2420_STARTUP_TIMEOUT 32000U - - -/* implementation of driver's functions */ - -void cc2420_initialize(void) -{ - cc2420_spi_init(); - hwtimer_wait(CC2420_WAIT_TIME); - cc2420_reset(); - - bool ok = false; - for (int i = 0; i < CC2420_STARTUP_ATTEMPTS; i++) { - ok = cc2420_on(); - if (ok) break; - } - if (!ok) { - core_panic(0x2420, "Could not start CC2420 radio transceiver"); - } - - hwtimer_wait(CC2420_WAIT_TIME); - - uint16_t reg = cc2420_read_reg(CC2420_REG_MDMCTRL0); - reg |= CC2420_ADR_DECODE; /* enable auto adress decoding */ - reg |= CC2420_AUTOACK; /* enable auto ACK */ - reg |= CC2420_AUTOCRC; /* enable auto CRC */ - reg &= ~(CC2420_RES_FRM_MODE); /* disable reserved frames */ - cc2420_write_reg(CC2420_REG_MDMCTRL0, reg); - - /* Change default values as recomended in the data sheet, */ - /* RX bandpass filter = 1.3uA. */ - reg = cc2420_read_reg(CC2420_REG_RXCTRL1); - reg |= CC2420_RXBPF_LOCUR; - cc2420_write_reg(CC2420_REG_RXCTRL1, reg); - - /* Set the FIFOP threshold to maximum. */ - cc2420_write_reg(CC2420_REG_IOCFG0, 127); - - /* Turn off "Security enable" (page 32). */ - reg = cc2420_read_reg(CC2420_REG_SECCTRL0); - reg &= ~CC2420_RXFIFO_PROTECTION; - cc2420_write_reg(CC2420_REG_SECCTRL0, reg); - - cc2420_set_tx_power(0); - cc2420_set_channel(CC2420_DEFAULT_CHANNR); - cc2420_set_pan(0x1111); - DEBUG("CC2420 initialized and set to channel %i and pan 0x1111\n", CC2420_DEFAULT_CHANNR); - cc2420_init_interrupts(); - cc2420_switch_to_rx(); -} - -void cc2420_init(kernel_pid_t tpid) -{ - transceiver_pid = tpid; - cc2420_initialize(); -} - -bool cc2420_on(void) -{ - /* enable transceiver's crystal oscillator */ - cc2420_strobe(CC2420_STROBE_XOSCON); - /* wait for the oscillator to be stable */ - unsigned int delay_on = 0; - do { - delay_on++; - if (delay_on >= CC2420_STARTUP_TIMEOUT) { - /* could not start up radio transceiver! */ - return false; - } - } while ((cc2420_status_byte() & CC2420_STATUS_XOSC16M_STABLE) == 0); - hwtimer_wait(CC2420_WAIT_TIME); - /* discard any potential garbage in TX buffer */ - cc2420_strobe(CC2420_STROBE_FLUSHTX); - /* switch to RX mode */ - cc2420_switch_to_rx(); - /* OK, radio is on */ - return true; -} - -void cc2420_off(void) -{ - /* halt any pending communication... */ - cc2420_strobe(CC2420_STROBE_RFOFF); - /* ... and put the transceiver in power-down mode */ - cc2420_strobe(CC2420_STROBE_XOSCOFF); -} - -bool cc2420_is_on(void) -{ - return ((cc2420_status_byte() & CC2420_STATUS_XOSC16M_STABLE) != 0); -} - -void cc2420_switch_to_rx(void) -{ - cc2420_strobe(CC2420_STROBE_RFOFF); - cc2420_strobe(CC2420_STROBE_FLUSHRX); - cc2420_strobe(CC2420_STROBE_FLUSHRX); - cc2420_strobe(CC2420_STROBE_RXON); -} - -void cc2420_rxoverflow_irq(void) -{ - cc2420_strobe(CC2420_STROBE_FLUSHRX); - /* CC2420 datasheet says to do this twice... */ - cc2420_strobe(CC2420_STROBE_FLUSHRX); -} - -void cc2420_rx_irq(void) -{ - cc2420_rx_handler(); -} - -void cc2420_set_monitor(bool mode) -{ - uint16_t reg = cc2420_read_reg(CC2420_REG_MDMCTRL0); - if (mode) { - reg &= ~CC2420_ADR_DECODE; - } else { - reg |= CC2420_ADR_DECODE; - } - cc2420_write_reg(CC2420_REG_MDMCTRL0, reg); -} - -bool cc2420_get_monitor(void) -{ - uint16_t reg = cc2420_read_reg(CC2420_REG_MDMCTRL0); - return ((reg & CC2420_ADR_DECODE) == 0); -} - -int cc2420_set_channel(unsigned int chan) -{ - if (chan < 11 || chan > 26) { - DEBUG("Invalid channel %i set. Valid channels are 11 through 26\n", chan); - return -1; - } - /* - * calculation from http://www.ti.com/lit/ds/symlink/cc2420.pdf p.50 - */ - uint16_t freq= cc2420_read_reg(CC2420_REG_FSCTRL); - freq &= ~CC2420_FREQ_MASK; - freq |= (357 + (5 * (chan - 11))); - cc2420_write_reg(CC2420_REG_FSCTRL, freq); - return ((unsigned int) chan); -} - -unsigned int cc2420_get_channel(void) -{ - /* undo calculation from cc2420_set_channel() */ - return (((cc2420_read_reg(CC2420_REG_FSCTRL) & CC2420_FREQ_MASK) - 357) / 5) + 11; -} - -uint16_t cc2420_set_address(uint16_t addr) -{ - uint8_t buf[2]; - buf[0] = (uint8_t)(addr & 0xFF); - buf[1] = (uint8_t)(addr >> 8); - cc2420_write_ram(CC2420_RAM_SHORTADR, buf, 2); - cc2420_set_address_long(0xFFFF & addr); - return addr; -} - -uint64_t cc2420_set_address_long(uint64_t addr) -{ - uint8_t buf[8]; - buf[0] = (uint8_t)(addr & 0xFF); - buf[1] = (uint8_t)(addr >> 8); - buf[2] = (uint8_t)(addr >> 16); - buf[3] = (uint8_t)(addr >> 24); - buf[4] = (uint8_t)(addr >> 32); - buf[5] = (uint8_t)(addr >> 40); - buf[6] = (uint8_t)(addr >> 48); - buf[7] = (uint8_t)(addr >> 56); - cc2420_write_ram(CC2420_RAM_IEEEADR, buf, 8); - return addr; -} - -uint16_t cc2420_get_address(void) -{ - uint16_t addr; - cc2420_read_ram(CC2420_RAM_SHORTADR, (uint8_t *)&addr, sizeof(addr)); - return addr; -} - -uint64_t cc2420_get_address_long(void) -{ - uint64_t addr; - cc2420_read_ram(CC2420_RAM_IEEEADR, (uint8_t *)&addr, sizeof(addr)); - return addr; -} - -uint16_t cc2420_set_pan(uint16_t pan) -{ - uint8_t buf[2]; - buf[0] = (uint8_t)(pan & 0xFF); - buf[1] = (uint8_t)(pan >> 8); - cc2420_write_ram(CC2420_RAM_PANID, buf, 2); - return pan; -} - -uint16_t cc2420_get_pan(void) -{ - uint16_t pan; - cc2420_read_ram(CC2420_RAM_PANID, (uint8_t *)&pan, sizeof(pan)); - return pan; -} - -static const uint8_t DBM_TO_LEVEL[32] = { - 31, 27, 25, 23, 21, 19, 17, 15, 13, 12, 11, 10, 9, 8, 7, 7, - 6, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3 -}; - -int cc2420_set_tx_power(int pow) -{ - uint16_t txctrl_reg = cc2420_read_reg(CC2420_REG_TXCTRL); - /* reset PA_LEVEL bits */ - txctrl_reg &= 0xFFE0; - /* constrain power in transceiver's acceptable set of values */ - if (pow > 0) pow = 0; - if (pow < -25) pow = -25; - /* determine TX level from power in dBm */ - uint8_t level = DBM_TO_LEVEL[-pow]; - /* put wanted value in PA_LEVEL bits, and write back register */ - txctrl_reg |= level; - cc2420_write_reg(CC2420_REG_TXCTRL, txctrl_reg); - return pow; -} - -static const int LEVEL_TO_DBM[32] = { - -25, -25, -25, -24, -21, -19, -17, -15, -13, -12, -11, -10, -9, -8, -7, -7, - -6, -6, -5, -5, -4, -4, -3, -3, -2, -2, -1, -1, 0, 0, 0, 0 -}; - -int cc2420_get_tx_power(void) -{ - uint16_t txctrl_reg = cc2420_read_reg(CC2420_REG_TXCTRL); - /* PA_LEVEL is in the 5 least-significant bits of TXCTRL register */ - uint8_t level = txctrl_reg & 0x001F; - /* determine output power in dBm from TX level */ - int pow = LEVEL_TO_DBM[level]; - return pow; -} - -inline bool cc2420_channel_clear(void) -{ - return (cc2420_get_cca() != 0); -} - -/* CC2420 low-level radio driver definition */ -const ieee802154_radio_driver_t cc2420_radio_driver = { - .init = cc2420_initialize, - .on = cc2420_on, - .off = cc2420_off, - .is_on = cc2420_is_on, - .load_tx = cc2420_load_tx_buf, - .transmit = cc2420_transmit_tx_buf, - .send = cc2420_do_send, - .set_receive_callback = cc2420_set_recv_callback, - .switch_to_rx = cc2420_switch_to_rx, - .set_channel = do_set_channel, - .get_channel = cc2420_get_channel, - .set_address = do_set_address, - .get_address = cc2420_get_address, - .set_long_address = do_set_long_address, - .get_long_address = cc2420_get_address_long, - .set_pan_id = do_set_pan_id, - .get_pan_id = cc2420_get_pan, - .set_tx_power = do_set_tx_power, - .get_tx_power = cc2420_get_tx_power, - .channel_is_clear = cc2420_channel_clear, - .set_promiscuous_mode = cc2420_set_monitor, - .in_promiscuous_mode = cc2420_get_monitor -}; diff --git a/drivers/cc2420/cc2420_rx.c b/drivers/cc2420/cc2420_rx.c deleted file mode 100644 index 41217d7c2e..0000000000 --- a/drivers/cc2420/cc2420_rx.c +++ /dev/null @@ -1,102 +0,0 @@ -/** - * cc2420_rx.c - Implementation of receiving cc2420 functions. - * Copyright (C) 2013 Milan Babel - * Copyright (C) 2014 Kévin Roussel - * - * 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. - */ - -#include - -#include "cc2420.h" -#include "cc2420_settings.h" -#include "cc2420_arch.h" -#include "cc2420_spi.h" -#include "ieee802154_frame.h" - -#include "kernel_types.h" -#include "transceiver.h" -#include "msg.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -/* circular buffer for incoming 802.15.4 packets */ -cc2420_packet_t cc2420_rx_buffer[CC2420_RX_BUF_SIZE]; -volatile uint8_t rx_buffer_next; /* index of next free cell in RX buffer */ - -/* pointer to the callback low-level function for packet reception */ -static receive_802154_packet_callback_t recv_func = NULL; - - -void cc2420_set_recv_callback(receive_802154_packet_callback_t recv_cb) -{ - recv_func = recv_cb; -} - -void cc2420_rx_handler(void) -{ - uint8_t pkt_len, pkt_lqi; - int8_t pkt_rssi; - bool crc_ok; - - /* read length */ - cc2420_read_fifo(&pkt_len, 1); - - /* read packet's raw payload */ - uint8_t buf[pkt_len - 2]; - cc2420_read_fifo(buf, pkt_len - 2); - - /* read rssi, lqi and crc */ - cc2420_read_fifo((uint8_t *) &pkt_rssi, 1); - cc2420_read_fifo(&pkt_lqi, 1); - crc_ok = ((pkt_lqi & 0x80) != 0); - pkt_lqi &= 0x7F; - if (!crc_ok) { - DEBUG("Got packet with invalid crc.\n"); - return; - } - - /* low-level reception mechanism (for MAC layer, among others) */ - if (recv_func != NULL) { - recv_func(buf, pkt_len - 2, pkt_rssi, pkt_lqi, crc_ok); - } - - /* decode received packet */ - cc2420_rx_buffer[rx_buffer_next].length = pkt_len; - cc2420_rx_buffer[rx_buffer_next].rssi = pkt_rssi; - cc2420_rx_buffer[rx_buffer_next].lqi = pkt_lqi; - cc2420_rx_buffer[rx_buffer_next].crc = (crc_ok ? 1 : 0); - ieee802154_frame_read(buf, - &cc2420_rx_buffer[rx_buffer_next].frame, - cc2420_rx_buffer[rx_buffer_next].length); - - /* follow-up to transceiver module if adequate */ - if (cc2420_rx_buffer[rx_buffer_next].frame.fcf.frame_type != IEEE_802154_ACK_FRAME) { -#if ENABLE_DEBUG - ieee802154_frame_print_fcf_frame(&cc2420_rx_buffer[rx_buffer_next].frame); -#endif - - /* notify transceiver thread if any */ - if (transceiver_pid != KERNEL_PID_UNDEF) { - msg_t m; - m.type = (uint16_t) RCV_PKT_CC2420; - m.content.value = rx_buffer_next; - msg_send_int(&m, transceiver_pid); - } - } - -#if ENABLE_DEBUG - else { - DEBUG("GOT ACK for SEQ %u\n", cc2420_rx_buffer[rx_buffer_next].frame.seq_nr); - ieee802154_frame_print_fcf_frame(&cc2420_rx_buffer[rx_buffer_next].frame); - } -#endif - - /* shift to next buffer element */ - if (++rx_buffer_next == CC2420_RX_BUF_SIZE) { - rx_buffer_next = 0; - } -} diff --git a/drivers/cc2420/cc2420_spi.c b/drivers/cc2420/cc2420_spi.c deleted file mode 100644 index 52c9d5a53a..0000000000 --- a/drivers/cc2420/cc2420_spi.c +++ /dev/null @@ -1,105 +0,0 @@ -/** - * cc2420_spi.c - Implementation of SPI cc2420 functions. - * Copyright (C) 2013 Milan Babel - * - * 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. - */ - -#include "cc2420_spi.h" -#include "cc2420_arch.h" - -#include "cc2420_settings.h" -#include "irq.h" - -/* reg */ -void cc2420_write_reg(uint8_t addr, uint16_t value) { - unsigned int cpsr = disableIRQ(); - cc2420_spi_select(); - cc2420_txrx(addr | CC2420_WRITE_ACCESS); - cc2420_txrx((uint8_t) (value >> 8)); - cc2420_txrx((uint8_t) (value & 0xFF)); - cc2420_spi_unselect(); - restoreIRQ(cpsr); -} - -uint16_t cc2420_read_reg(uint8_t addr) { - uint16_t result; - unsigned int cpsr = disableIRQ(); - cc2420_spi_select(); - cc2420_txrx(addr | CC2420_READ_ACCESS); - result = cc2420_txrx(NOBYTE); - result <<= 8; - result |= cc2420_txrx(NOBYTE); - cc2420_spi_unselect(); - restoreIRQ(cpsr); - return result; -} - -uint8_t cc2420_strobe(uint8_t c) { - uint8_t result; - unsigned int cpsr = disableIRQ(); - cc2420_spi_select(); - result = cc2420_txrx(c); - cc2420_spi_unselect(); - restoreIRQ(cpsr); - return result; -} - -/* ram */ -radio_packet_length_t cc2420_read_ram(uint16_t addr, uint8_t* buffer, radio_packet_length_t len) { - radio_packet_length_t i; - unsigned int cpsr = disableIRQ(); - cc2420_spi_select(); - cc2420_txrx(CC2420_RAM_ACCESS | (addr & 0x7F)); - cc2420_txrx(((addr >> 1) & 0xC0) | CC2420_RAM_READ_ACCESS); - for (i = 0; i < len; i++) { - buffer[i] = cc2420_txrx(NOBYTE); - } - cc2420_spi_unselect(); - restoreIRQ(cpsr); - return i; -} - -radio_packet_length_t cc2420_write_ram(uint16_t addr, uint8_t* buffer, radio_packet_length_t len) { - radio_packet_length_t i; - unsigned int cpsr = disableIRQ(); - cc2420_spi_select(); - cc2420_txrx(CC2420_RAM_ACCESS | (addr & 0x7F)); - cc2420_txrx(((addr >> 1) & 0xC0) | CC2420_RAM_WRITE_ACCESS); - for (i = 0; i < len; i++) { - cc2420_txrx(buffer[i]); - } - cc2420_spi_unselect(); - restoreIRQ(cpsr); - return i; -} - -/* fifo */ - -radio_packet_length_t cc2420_write_fifo(uint8_t* data, radio_packet_length_t data_length) { - radio_packet_length_t i; - unsigned int cpsr = disableIRQ(); - cc2420_spi_select(); - cc2420_txrx(CC2420_REG_TXFIFO | CC2420_WRITE_ACCESS); - for (i = 0; i < data_length; i++) { - cc2420_txrx(data[i]); - } - cc2420_spi_unselect(); - restoreIRQ(cpsr); - return i; -} - -radio_packet_length_t cc2420_read_fifo(uint8_t* data, radio_packet_length_t data_length) { - radio_packet_length_t i; - unsigned int cpsr = disableIRQ(); - cc2420_spi_select(); - cc2420_txrx(CC2420_REG_RXFIFO | CC2420_READ_ACCESS); - for (i = 0; i < data_length; i++) { - data[i] = cc2420_txrx(NOBYTE); - } - cc2420_spi_unselect(); - restoreIRQ(cpsr); - return i; -} diff --git a/drivers/cc2420/cc2420_tx.c b/drivers/cc2420/cc2420_tx.c deleted file mode 100644 index e55cb3a1cc..0000000000 --- a/drivers/cc2420/cc2420_tx.c +++ /dev/null @@ -1,314 +0,0 @@ -/** - * cc2420_rx.c - Implementation of transmitting cc2420 functions. - * Copyright (C) 2013 Milan Babel - * - * 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. - */ - -#include - -#include "cc2420.h" -#include "cc2420_spi.h" -#include "cc2420_settings.h" -#include "cc2420_arch.h" -#include "ieee802154_frame.h" - -#include "irq.h" -#include "hwtimer.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -static void cc2420_gen_pkt(uint8_t *buf, cc2420_packet_t *packet); -static uint8_t sequence_nr; -static bool wait_for_ack; - -radio_tx_status_t cc2420_load_tx_buf(ieee802154_packet_kind_t kind, - ieee802154_node_addr_t dest, - bool use_long_addr, - bool wants_ack, - void *buf, - unsigned int len) -{ - uint8_t hdr[24]; - - /* FCS : frame version 0, we don't manage security, - nor batchs of packets */ - switch (kind) { - case PACKET_KIND_BEACON: - hdr[0] = 0x00; - break; - case PACKET_KIND_DATA: - hdr[0] = 0x01; - break; - case PACKET_KIND_ACK: - hdr[0] = 0x02; - break; - default: - return RADIO_TX_INVALID_PARAM; - } - - if (wants_ack) { - hdr[0] |= 0x20; - } - wait_for_ack = wants_ack; - - uint16_t src_pan = cc2420_get_pan(); - bool compress_pan = false; - - if (use_long_addr) { - hdr[1] = 0xcc; - } else { - hdr[1] = 0x88; - /* short address mode, use PAN ID compression - for intra-PAN communication */ - if (dest.pan.id == src_pan) { - compress_pan = true; - hdr[0] |= 0x40; - } - } - - /* sequence number */ - hdr[2] = sequence_nr++; - - /* variable-length fields */ - int idx = 3; - - if (use_long_addr) { - /* dest long addr */ - hdr[idx++] = (uint8_t)(dest.long_addr & 0xFF); - hdr[idx++] = (uint8_t)(dest.long_addr >> 8); - hdr[idx++] = (uint8_t)(dest.long_addr >> 16); - hdr[idx++] = (uint8_t)(dest.long_addr >> 24); - hdr[idx++] = (uint8_t)(dest.long_addr >> 32); - hdr[idx++] = (uint8_t)(dest.long_addr >> 40); - hdr[idx++] = (uint8_t)(dest.long_addr >> 48); - hdr[idx++] = (uint8_t)(dest.long_addr >> 56); - /* src long addr */ - uint64_t src_long_addr = cc2420_get_address_long(); - hdr[idx++] = (uint8_t)(src_long_addr & 0xFF); - hdr[idx++] = (uint8_t)(src_long_addr >> 8); - hdr[idx++] = (uint8_t)(src_long_addr >> 16); - hdr[idx++] = (uint8_t)(src_long_addr >> 24); - hdr[idx++] = (uint8_t)(src_long_addr >> 32); - hdr[idx++] = (uint8_t)(src_long_addr >> 40); - hdr[idx++] = (uint8_t)(src_long_addr >> 48); - hdr[idx++] = (uint8_t)(src_long_addr >> 56); - } else { - /* dest PAN ID */ - hdr[idx++] = (uint8_t)(dest.pan.id & 0xFF); - hdr[idx++] = (uint8_t)(dest.pan.id >> 8); - /* dest short addr */ - hdr[idx++] = (uint8_t)(dest.pan.addr & 0xFF); - hdr[idx++] = (uint8_t)(dest.pan.addr >> 8); - /* src PAN ID */ - if (!compress_pan) { - uint16_t src_pan = cc2420_get_pan(); - hdr[idx++] = (uint8_t)(src_pan & 0xFF); - hdr[idx++] = (uint8_t)(src_pan >> 8); - } - /* src short addr */ - uint16_t src_addr = cc2420_get_address(); - hdr[idx++] = (uint8_t)(src_addr & 0xFF); - hdr[idx++] = (uint8_t)(src_addr >> 8); - } - - /* total frame size */ - uint8_t size = idx + len + 2; - if (size > CC2420_MAX_PKT_LENGTH) { - return RADIO_TX_PACKET_TOO_LONG; - } - - /* flush TX buffer */ - cc2420_strobe(CC2420_STROBE_FLUSHTX); - - /* write length, header and payload to TX FIFO */ - cc2420_write_fifo(&size, 1); - cc2420_write_fifo(hdr, idx); - cc2420_write_fifo(buf, len); - - return RADIO_TX_OK; -} - -#define CC2420_ACK_WAIT_DELAY_uS 1000 -#define ACK_LENGTH 5 - -radio_tx_status_t cc2420_transmit_tx_buf(void) -{ - /* check if channel clear */ - if (!cc2420_channel_clear()) { - return RADIO_TX_MEDIUM_BUSY; - } - - /* put tranceiver in idle mode */ - cc2420_strobe(CC2420_STROBE_RFOFF); - - /* begin transmission: wait for preamble to be sent */ - unsigned int cpsr = disableIRQ(); - cc2420_strobe(CC2420_STROBE_TXON); - - int abort_count = 0; - while (cc2420_get_sfd() == 0) { - /* Wait for SFD signal to be set -> sync word transmitted */ - abort_count++; - - if (abort_count > CC2420_SYNC_WORD_TX_TIME) { - /* Abort waiting. CC2420 maybe in wrong mode - e.g. sending preambles for always */ - puts("[CC2420 TX] fatal error: could not send packet\n"); - return RADIO_TX_ERROR; - } - } - - restoreIRQ(cpsr); - - /* wait for packet to be sent, i.e.: SFD to go down */ - uint8_t st; - do { - st = cc2420_status_byte(); - } while (cc2420_get_sfd() != 0); - cc2420_switch_to_rx(); - - /* check for underflow error flag */ - if (st & CC2420_STATUS_TX_UNDERFLOW) { - return RADIO_TX_UNDERFLOW; - } - - /* wait for ACK only if needed */ - if (!wait_for_ack) { - return RADIO_TX_OK; - } - - /* delay for the peer to answer our packet */ - //TODO design a more robust method? - hwtimer_wait(HWTIMER_TICKS(CC2420_ACK_WAIT_DELAY_uS)); - /* try to read a returning ACK packet */ - if (cc2420_get_fifop()) { - uint8_t ackbuf[ACK_LENGTH]; - /* a packet has arrived, read the arrived data */ - cc2420_read_fifo(ackbuf, ACK_LENGTH); - if (ackbuf[0] == 0x02 /* ack packet in buffer */ - && (ackbuf[2] == sequence_nr - 1)) /* correct sequence number */ - return RADIO_TX_OK; - } - return RADIO_TX_NOACK; -} - -radio_tx_status_t cc2420_do_send(ieee802154_packet_kind_t kind, - ieee802154_node_addr_t dest, - bool use_long_addr, - bool wants_ack, - void *buf, - unsigned int len) -{ - radio_tx_status_t st = cc2420_load_tx_buf(kind, dest, - use_long_addr, - wants_ack, - buf, len); - if (st != RADIO_TX_OK) { - return st; - } - return cc2420_transmit_tx_buf(); -} - -int16_t cc2420_send(cc2420_packet_t *packet) -{ - volatile uint32_t abort_count = 0; - - /* Set missing frame information */ - packet->frame.fcf.frame_ver = 0; - - if (packet->frame.src_pan_id == packet->frame.dest_pan_id) { - packet->frame.fcf.panid_comp = 1; - } - else { - packet->frame.fcf.panid_comp = 0; - } - - if (packet->frame.fcf.src_addr_m == 2) { - packet->frame.src_addr[0] = (uint8_t)(cc2420_get_address() >> 8); - packet->frame.src_addr[1] = (uint8_t)(cc2420_get_address() & 0xFF); - } - else if (packet->frame.fcf.src_addr_m == 3) { - packet->frame.src_addr[0] = (uint8_t)(cc2420_get_address_long() >> 56); - packet->frame.src_addr[1] = (uint8_t)(cc2420_get_address_long() >> 48); - packet->frame.src_addr[2] = (uint8_t)(cc2420_get_address_long() >> 40); - packet->frame.src_addr[3] = (uint8_t)(cc2420_get_address_long() >> 32); - packet->frame.src_addr[4] = (uint8_t)(cc2420_get_address_long() >> 24); - packet->frame.src_addr[5] = (uint8_t)(cc2420_get_address_long() >> 16); - packet->frame.src_addr[6] = (uint8_t)(cc2420_get_address_long() >> 8); - packet->frame.src_addr[7] = (uint8_t)(cc2420_get_address_long() & 0xFF); - } - - packet->frame.src_pan_id = cc2420_get_pan(); - packet->frame.seq_nr = sequence_nr; - - sequence_nr += 1; - - /* calculate size of the package (header + payload + fcs) */ - packet->length = ieee802154_frame_get_hdr_len(&packet->frame) + - packet->frame.payload_len + 2; - - if (packet->length > CC2420_MAX_PKT_LENGTH) { - return -1; - } - - /* FCS is added in hardware */ - uint8_t pkt[packet->length - 2]; - - /* generate pkt */ - cc2420_gen_pkt(pkt, packet); - - /* idle & flush tx */ - cc2420_strobe(CC2420_STROBE_RFOFF); - cc2420_strobe(CC2420_STROBE_FLUSHTX); - - /* write length and packet to fifo */ - cc2420_write_fifo(&packet->length, 1); - cc2420_write_fifo(pkt, packet->length - 2); - - unsigned int cpsr = disableIRQ(); - cc2420_strobe(CC2420_STROBE_TXON); - - // Wait for SFD to be set -> sync word transmitted - while (cc2420_get_sfd() == 0) { - abort_count++; - - if (abort_count > CC2420_SYNC_WORD_TX_TIME) { - // Abort waiting. CC2420 maybe in wrong mode - // e.g. sending preambles for always - puts("[CC2420 TX] fatal error\n"); - /* TODO: error handling */ - packet->length = 0; - break; - } - } - - DEBUG("SEQ: %u\n", packet->frame.seq_nr); - restoreIRQ(cpsr); - - /* wait for packet to be send */ - while (cc2420_get_sfd() != 0); - - cc2420_switch_to_rx(); - return packet->length; -} - -/** - * @brief Static function to generate byte array from cc2420 packet. - * - */ - -static void cc2420_gen_pkt(uint8_t *buf, cc2420_packet_t *packet) -{ - uint8_t index, offset; - index = ieee802154_frame_init(&packet->frame, buf); - offset = index; - - while (index < packet->length - 2) { - buf[index] = packet->frame.payload[index - offset]; - index += 1; - } -} diff --git a/drivers/cc2420/include/cc2420_arch.h b/drivers/cc2420/include/cc2420_arch.h deleted file mode 100644 index ee9fb463ea..0000000000 --- a/drivers/cc2420/include/cc2420_arch.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2014, Freie Universitaet Berlin (FUB). All rights reserved. - * - * 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. - */ - -/** - * @file - * @ingroup CC2420 - * @brief CC2420 dependend functions - * - * @author Heiko Will - * @author Milan Babel - * @author Kévin Roussel - */ - -#ifndef CC2420_ARCH_H -#define CC2420_ARCH_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief SPI tx and rx function. - * - * @param[in] c byte which should be transmitted. - * - * @return Byte which was received after transmitting. - * - */ -uint8_t cc2420_txrx(uint8_t c); - -/** - * @brief Gets the status of the FIFOP pin. - * - * @return Status of the FIFOP pin. - * - */ -uint8_t cc2420_get_fifop(void); - -/** - * @brief Gets the status of the SFD pin. - * - * @return Status of the SFD pin. - * - */ -uint8_t cc2420_get_sfd(void); - -/** - * @brief Gets the status of the CCA pin - * - * @return Status of the CCA pin. - * - */ -uint8_t cc2420_get_cca(void); - -/** - * @brief Does a hardware reset of the CC2420. - * - */ -void cc2420_reset(void); - -/** - * @brief Init the SPI interface. - * - */ -void cc2420_spi_init(void); - -/** - * @brief Selects the CC2420 on the spi bus. - * - */ -void cc2420_spi_select(void); - -/** - * @brief Unselects the CC2420 on the spi bus. - * - */ -void cc2420_spi_unselect(void); - -/** - * @brief Enable interrupts on the GDO0 pin. - * - */ -void cc2420_gdo0_enable(void); - -/** - * @brief Disable interrupts on the GDO0 pin. - * - */ -void cc2420_gdo0_disable(void); - -/** - * @brief Enable interrupts on the GDO2 pin. - * - */ -void cc2420_gdo2_enable(void); - -/** - * @brief Disable interrupts on the GDO2 pin. - * - */ -void cc2420_gdo2_disable(void); - -/** - * @brief Init interrupts. - * - */ -void cc2420_init_interrupts(void); - -/** - * @brief Function called before send to disable interrupts. - * - */ -void cc2420_before_send(void); - -/** - * @brief Function called after send to reenable interrupts. - * - */ -void cc2420_after_send(void); - -#ifdef __cplusplus -} -#endif - -#endif /* CC2420_ARCH_H */ diff --git a/drivers/cc2420/include/cc2420_settings.h b/drivers/cc2420/include/cc2420_settings.h deleted file mode 100644 index 7351b870b5..0000000000 --- a/drivers/cc2420/include/cc2420_settings.h +++ /dev/null @@ -1,319 +0,0 @@ -/* - * Copyright (C) 2014 Milan Babel and INRIA - * - * 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 CC2420 - * @{ - * @file - * @brief Definitions and settings for the CC2420 - * @author Milan Babel - * @author Kévin Roussel - * - */ -#ifndef CC2420_SETTINGS_H -#define CC2420_SETTINGS_H - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @name CC2420 access mode values. - * @brief Values defining the command you want to give to the CC2420: - * read or write access to registers or RAM. - * These values are to be OR-ed to the address you want to access. - * @see CC2420 datasheet section 13.2 page 31. - * @{ - */ -/** @brief Read-Register Mode */ -#define CC2420_READ_ACCESS 0x40 -/** @brief Write Register Mode */ -#define CC2420_WRITE_ACCESS 0x00 -/** - * @brief RAM Access Modifier (to use with @c CC2420_RAM_READ_ACCESS - * or @c CC2420_RAM_WRITE_ACCESS) - */ -#define CC2420_RAM_ACCESS 0x80 -/** @brief Read-Memory Mode (to use with @c CC2420_RAM_ACCESS) */ -#define CC2420_RAM_READ_ACCESS 0x20 -/** @brief Write-Memory Mode (to use with @c CC2420_RAM_ACCESS) */ -#define CC2420_RAM_WRITE_ACCESS 0x00 - -/** - * @} - */ - - -/** - * @name Strobe command addresses - * @brief Addresses of "strobe" commands in CC2420 address space. - * @see CC2420 datasheet section 37 pages 61--62. - * @{ - */ -/** @brief NO Operation @see NOBYTE */ -#define CC2420_STROBE_NOP 0x00 -/** @brief Turn transceiver (internal oscillator) on */ -#define CC2420_STROBE_XOSCON 0x01 -/** @brief Calibrate TX frequency, then put transceiver in wait (inactive) mode */ -#define CC2420_STROBE_TXCAL 0x02 -/** @brief Put transceiver in RX mode */ -#define CC2420_STROBE_RXON 0x03 -/** @brief Put transceiver in TX mode */ -#define CC2420_STROBE_TXON 0x04 -/** @brief Put transceiver in TX mode after checking media availability */ -#define CC2420_STROBE_TXONCCA 0x05 -/** @brief Put transceiver in idle mode */ -#define CC2420_STROBE_RFOFF 0x06 -/** @brief Turn transceiver (internal oscillator) off -> power-down mode */ -#define CC2420_STROBE_XOSCOFF 0x07 -/** @brief Flush transceiver's RX buffer */ -#define CC2420_STROBE_FLUSHRX 0x08 -/** @brief Flush transceiver's TX buffer */ -#define CC2420_STROBE_FLUSHTX 0x09 -/** @brief Send an ACK frame with pending field cleared */ -#define CC2420_STROBE_ACK 0x0A -/** @brief Send an ACK frame with pending field set */ -#define CC2420_STROBE_ACKPEND 0x0B -/** @brief Start RXFIFO in-line decryption/verification */ -#define CC2420_STROBE_RXDEC 0x0C -/** @brief Start TXFIFO in-line encryption/authentication */ -#define CC2420_STROBE_TXENC 0x0D -/** @brief Start standalone AES encryption */ -#define CC2420_STROBE_AES 0x0E - -/** - * @} - */ - - - -/** - * @name CC2420 Configuration Register addresses. - * @brief Addresses of configuration registers in CC2420 address space. - * @see CC2420 datasheet section 37 pages 61 to 80. - * @{ - */ -/** @brief Main Control Register */ -#define CC2420_REG_MAIN 0x10 -/** - * @brief Modem Control Register 0 - * @{ - */ -#define CC2420_REG_MDMCTRL0 0x11 - /** @brief Address Decode enable flag */ - #define CC2420_ADR_DECODE 0x800 - /** @brief Reserved Frame accept enable flag */ - #define CC2420_RES_FRM_MODE 0x2000 - /** @brief PAN Coordinator mode enable flag */ - #define CC2420_PAN_COORD 0x1000 - /** @brief Automatic CRC computation/verification enable flag */ - #define CC2420_AUTOCRC 0x20 - /** @brief Automatic ACK response enable flag */ - #define CC2420_AUTOACK 0x10 -/** @} */ -/** @brief Modem Control Register 1 */ -#define CC2420_REG_MDMCTRL1 0x12 -/** - * @brief RSSI and CCA Status and Control Register - * @{ - */ -#define CC2420_REG_RSSI 0x13 - /** @brief CCA Threshold value mask */ - #define CC2420_CCATHR_MASK 0xFF00 - /** @brief RSSI estimate value mask */ - #define CC2420_RSSI_MASK 0xFF -/** @} */ -/** @brief Sync Word */ -#define CC2420_REG_SYNCWORD 0x14 -/** - * @brief Transmit Control Register - * @{ - */ -#define CC2420_REG_TXCTRL 0x15 - /** @brief Output PA Level value mask */ - #define CC2420_PALEVEL_MASK 0x1F -/** @} */ -/** @brief Receive Control Register 0 */ -#define CC2420_REG_RXCTRL0 0x16 -/** - * @brief Receive Control Register 1 - * @{ - */ -#define CC2420_REG_RXCTRL1 0x17 - /** @brief RX BandPass Filter Bias Current mode flag */ - #define CC2420_RXBPF_LOCUR 0x2000 -/** @} */ -/** - * @brief Frequency Synthesizer Control and Status Register - * @{ - */ -#define CC2420_REG_FSCTRL 0x18 - /** @brief RF Operating Frequency mask */ - #define CC2420_FREQ_MASK 0x3FF -/** @} */ -/** - * @brief Security Control Register 0 - * @{ - */ -#define CC2420_REG_SECCTRL0 0x19 - /** @brief RXFIFO Protection enable flag */ - #define CC2420_RXFIFO_PROTECTION 0x200 -/** @} */ -/** @brief Security Control Register 1 */ -#define CC2420_REG_SECCTRL1 0x1A -/** @brief Battery Monitor Control Register */ -#define CC2420_REG_BATTMON 0x1B -/** - * @brief I/O Configuration Register 0 - * @{ - */ -#define CC2420_REG_IOCFG0 0x1C - /** @brief FIFOP Activation Threshold mask */ - #define CC2420_FIFOPTHR_MASK 0x7F -/** @} */ -/** @brief I/O Configuration Register 1 */ -#define CC2420_REG_IOCFG1 0x1D -/** @brief Manufacturer ID (low word) */ -#define CC2420_REG_MANFIDL 0x1E -/** @brief Manufacturer ID (high word) */ -#define CC2420_REG_MANFIDH 0x1F -/** @brief Finite State Machine Time Constants */ -#define CC2420_REG_FSMTC 0x20 -/** @brief Manual signal AND override Register */ -#define CC2420_REG_MANAND 0x21 -/** @brief Manual signal OR override Register */ -#define CC2420_REG_MANOR 0x22 -/** @brief AGC Control Register */ -#define CC2420_REG_AGCCTRL 0x23 -/** @brief AGC Test Register 0 */ -#define CC2420_REG_AGCTST0 0x24 -/** @brief AGC Test Register 1 */ -#define CC2420_REG_AGCTST1 0x25 -/** @brief AGC Test Register 2 */ -#define CC2420_REG_AGCTST2 0x26 -/** @brief Frequency Synthesizer Test Register 0 */ -#define CC2420_REG_FSTST0 0x27 -/** @brief Frequency Synthesizer Test Register 1 */ -#define CC2420_REG_FSTST1 0x28 -/** @brief Frequency Synthesizer Test Register 2 */ -#define CC2420_REG_FSTST2 0x29 -/** @brief Frequency Synthesizer Test Register 3 */ -#define CC2420_REG_FSTST3 0x2A -/** @brief Receiver Bandpass Filters Test Register */ -#define CC2420_REG_RXBPFTST 0x2B -/** @brief Finite State Machine Information Register */ -#define CC2420_REG_FSMSTATE 0x2C -/** @brief ADC Test Register */ -#define CC2420_REG_ADCTST 0x2D -/** @brief DAC Test Register */ -#define CC2420_REG_DACTST 0x2E -/** @brief Top-level Test Register */ -#define CC2420_REG_TOPTST 0x2F - -/** @brief Transmit FIFO Byte Register */ -#define CC2420_REG_TXFIFO 0x3E -/** @brief Receive FIFO Byte Register */ -#define CC2420_REG_RXFIFO 0x3F - -/** - * @} - */ - - - -/** - * @name CC2420 Configuration RAM addresses. - * @brief Addresses of configuration zones in CC2420 RAM address space. - * @see CC2420 datasheet section 13.5 page 31. - * @{ - */ -/** @brief Short (16-bit) address of the system into its current PAN. */ -#define CC2420_RAM_SHORTADR 0x16A -/** @brief 16-bit ID of the PAN into which the system is associated. */ -#define CC2420_RAM_PANID 0x168 -/** @brief IEEE long (64-bit) address of the system. */ -#define CC2420_RAM_IEEEADR 0x160 - -/** - * @} - */ - - -/** - * @name Status byte flags - * @brief Bits of the status byte returned by CC2420 adter each command. - * @see CC2420 datasheet section 13.3 page 29. - * @{ - */ - -/** - * @brief Bit XOSC16M_STABLE of the status register. - * @details This bit indicates whether the 16-MHz oscillator - * is running (value 1), or if the transceiver - * is in power-down mode (value 0). - */ -#define CC2420_STATUS_XOSC16M_STABLE 0x40 -/** - * @brief Bit TX_UNDERFLOW of the status register. - * @details This bit indicates whether the latest transmission has failed - * because the TX buffer didn't contain enough data (error bit). - */ -#define CC2420_STATUS_TX_UNDERFLOW 0x20 -/** - * @brief Bit ENC_BUSY of the status register. - * @details This bit indicates whether the encryption module - * is currently busy (value 1), or not (value 0). - */ -#define CC2420_STATUS_ENC_BUSY 0x10 -/** - * @brief Bit TX_ACTIVE of the status register. - * @details This bit indicates whether a RF transmission - * is currently in progress (value 1), or not (value 0). - */ -#define CC2420_STATUS_TX_ACTIVE 0x08 -/** - * @brief Bit PLL_LOCK of the status register. - * @details This bit indicates whether the frequency synthesizer PLL - * is currently locked (value 1), or not (value 0). - */ -#define CC2420_STATUS_PLL_LOCK 0x04 -/** - * @brief Bit RSSI_VALID of the status register. - * @details This bit indicates whether the RSSI value - * is valid (value 1), or not (value 0). - * The RSSI is always valid when the CC2420 - * has been in RX mode for at least 128 µs), - */ -#define CC2420_STATUS_RSSI_VALID 0x02 - -/** - * @} - */ - - - -/** - * @brief Null command strobe/parameter. - * @details Basically a strobe address used to perform a NOP on CC2420; - * This is useful to just query the status byte, or more generally - * passively receive bytes from the transceiver on its SPI link. - */ -#define NOBYTE 0x0 - - -/* Various configuration settings for the CC2420 drivers */ -#define CC2420_DEFAULT_CHANNR (26U) -#define CC2420_SYNC_WORD_TX_TIME 900000 -#define CC2420_RX_BUF_SIZE 3 -#define CC2420_WAIT_TIME 500 - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/drivers/cc2420/include/cc2420_spi.h b/drivers/cc2420/include/cc2420_spi.h deleted file mode 100644 index e20c3d269f..0000000000 --- a/drivers/cc2420/include/cc2420_spi.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2013 Milan Babel - * - * 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 CC2420 - * @{ - * @file - * @brief Definition of CC2420 SPI functions - * @author Milan Babel - * - */ -#ifndef CC2420_SPI_H -#define CC2420_SPI_H - -#include -#include "board.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Writes a byte to the cc2420 register. - * - * @param[in] addr The address of the register to write. - * @param[in] value The value to write in the register. - */ -void cc2420_write_reg(uint8_t addr, uint16_t value); - -/** - * @brief Reads a byte from the cc2420 register. - * - * @param[in] addr The address of the register to read. - * - * @return The value in the register. - */ -uint16_t cc2420_read_reg(uint8_t addr); - -/** - * @brief Sends a strobe command to the cc2420. - * - * @param[in] c The strobe command to send. - * - * @return The result of the strobe command. - */ -uint8_t cc2420_strobe(uint8_t c); - - -/** - * @brief Reads multiple bytes from the cc2420 ram. - * - * @param[in] addr The ram address to read. - * @param[out] buffer A buffer to store the value of the ram. - * @param[in] len The count of bytes which should be read. - * - * @return The number of bytes read. - */ -radio_packet_length_t cc2420_read_ram(uint16_t addr, uint8_t* buffer, radio_packet_length_t len); - -/** - * @brief Writes multiple bytes to the cc2420 ram. - * - * @param[in] addr The ram address to write. - * @param[in] buffer A buffer with the value to write to the ram. - * @param[in] len The count of bytes which should be written. - * - * @return The number of bytes written. - */ -radio_packet_length_t cc2420_write_ram(uint16_t addr, uint8_t* buffer, radio_packet_length_t len); - -/** - * @brief Writes multiple bytes to the cc2420 fifo. - * - * @param[in] data A buffer with the value to write to the fifo. - * @param[in] data_length The count of bytes which should be written. - * - * @return The number of bytes written. - */ -radio_packet_length_t cc2420_write_fifo(uint8_t* data, radio_packet_length_t data_length); - -/** - * @brief Reads multiple bytes from the cc2420 fifo. - * - * @param[out] data A buffer to store the value of the fifo. - * @param[in] data_length The count of bytes which should be read. - * - * @return The number of bytes read. - */ -radio_packet_length_t cc2420_read_fifo(uint8_t* data, radio_packet_length_t data_length); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/drivers/include/at86rf231.h b/drivers/include/at86rf231.h deleted file mode 100644 index 376c804a3a..0000000000 --- a/drivers/include/at86rf231.h +++ /dev/null @@ -1,402 +0,0 @@ -/* - * Copyright (C) 2014 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. - */ - -/** - * @defgroup drivers_at86rf231 at86rf231 - * @ingroup drivers - * @brief Device driver for the Atmel AT86RF231 radio - * @{ - * - * @file - * @brief Interface definition for the AT86RF231 device driver - * - * @author Alaeddine Weslati - * @author Thomas Eichinger - */ - -#ifndef AT86RF231_H_ -#define AT86RF231_H_ - -#include -#include - -#include "kernel_types.h" -#include "board.h" -#include "radio/types.h" -#include "ieee802154_frame.h" -#include "at86rf231/at86rf231_settings.h" -#include "periph/gpio.h" -#include "netdev/802154.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Maximum length of a frame on at86rf231 - */ -#define AT86RF231_MAX_PKT_LENGTH (127) - -/** - * @brief Maximum payload length - * @details Assuming intra PAN short address mode - * results in 2 bytes FCF - * + 1 bytes SEQNr - * + 2 bytes PAN Id - * + 2 bytes destination address - * + 2 bytes source address - */ -#define AT86RF231_MAX_DATA_LENGTH (118) - -/** - * @brief Broadcast address - */ -#define AT86RF231_BROADCAST_ADDRESS (0xFFFF) - -/** - * @brief at86rf231's lowest supported channel - */ -#define AT86RF231_MIN_CHANNEL (0) - -/** - * @brief at86rf231's highest supported channel - */ -#define AT86RF231_MAX_CHANNEL (26) - -/** - * @brief Structure to represent a at86rf231 packet. - */ -typedef struct __attribute__((packed)) -{ - /** @{ */ - uint8_t length; /**< the length of the frame of the frame including fcs*/ - ieee802154_frame_t frame; /**< the ieee802154 frame */ - uint8_t rssi; /**< the rssi value */ - uint8_t crc; /**< 1 if crc was successfull, 0 otherwise */ - uint8_t lqi; /**< the link quality indicator */ - /** @} */ -} at86rf231_packet_t; - -extern netdev_t at86rf231_netdev; /**< netdev representation of this driver */ - -/** - * @brief States to be assigned to `driver_state` - * @{ - */ -#define AT_DRIVER_STATE_DEFAULT (0) -#define AT_DRIVER_STATE_SENDING (1) -/** @} */ - -/** - * @brief To keep state inside of at86rf231 driver - * @details This variable is used to determine if a TRX_END IRQ from - * the radio transceiver has to be interpreted as end of - * sending or reception. - */ -extern uint8_t driver_state; - -/** - * @brief Initialize the at86rf231 transceiver - */ -int at86rf231_initialize(netdev_t *dev); - -#ifdef MODULE_TRANSCEIVER -/** - * @brief Init the at86rf231 for use with RIOT's transceiver module. - * - * @param[in] tpid The PID of the transceiver thread. - */ - -void at86rf231_init(kernel_pid_t tpid); -#endif - -/** - * @brief Turn at86rf231 on. - * - * @return 1 if the radio was correctly turned on; 0 otherwise. - */ -int at86rf231_on(void); - -/** - * @brief Turn at86rf231 off. - */ -void at86rf231_off(void); - -/** - * @brief Indicate if the at86rf231 is on. - * - * @return 1 if the radio transceiver is on (active); 0 otherwise. - */ -int at86rf231_is_on(void); - -/** - * @brief Switches the at86rf231 into receive mode. - */ -void at86rf231_switch_to_rx(void); - -/** - * @brief Turns monitor (promiscuous) mode on or off. - * - * @param[in] mode The desired mode: - * 1 for monitor (promiscuous) mode; - * 0 for normal (auto address-decoding) mode. - */ -void at86rf231_set_monitor(int mode); - -/** - * @brief Indicate if the at86rf231 is in monitor (promiscuous) mode. - * - * @return 1 if the transceiver is in monitor (promiscuous) mode; - * 0 if it is in normal (auto address-decoding) mode. - */ -int at86rf231_get_monitor(void); - -/** - * @brief Set the channel of the at86rf231. - * - * @param[in] chan The desired channel, valid channels are from 11 to 26. - * - * @return The tuned channel after calling, or -1 on error. - */ -int at86rf231_set_channel(unsigned int chan); - -/** - * @brief Get the channel of the at86rf231. - * - * @return The tuned channel. - */ -unsigned int at86rf231_get_channel(void); - -/** - * @brief Sets the short address of the at86rf231. - * - * @param[in] addr The desired address. - * - * @return The set address after calling. - */ -uint16_t at86rf231_set_address(uint16_t addr); - -/** - * @brief Gets the current short address of the at86rf231. - * - * @return The current short address. - */ -uint16_t at86rf231_get_address(void); - -/** - * @brief Sets the IEEE long address of the at86rf231. - * - * @param[in] addr The desired address. - * - * @return The set address after calling. - */ -uint64_t at86rf231_set_address_long(uint64_t addr); - -/** - * @brief Gets the current IEEE long address of the at86rf231. - * - * @return The current IEEE long address. - */ -uint64_t at86rf231_get_address_long(void); - -/** - * @brief Sets the pan ID of the at86rf231. - * - * @param[in] pan The desired pan ID. - * - * @return The set pan ID after calling. - */ -uint16_t at86rf231_set_pan(uint16_t pan); - -/** - * @brief Gets the current IEEE long address of the at86rf231. - * - * @return The current IEEE long address. - */ -uint16_t at86rf231_get_pan(void); - -/** - * @brief Sets the output (TX) power of the at86rf231. - * - * @param[in] pow The desired TX (output) power in dBm, - * valid values are -25 to 0; other values - * will be "saturated" into this range. - * - * @return The set TX (output) power after calling. - */ -int at86rf231_set_tx_power(int pow); - -/** - * @brief Gets the current output (TX) power of the at86rf231. - * - * @return The current TX (output) power. - */ -int at86rf231_get_tx_power(void); - -/** - * @brief Checks if the radio medium is available/clear to send - * ("Clear Channel Assessment" a.k.a. CCA). - * - * @return a 1 value if radio medium is clear (available), - * a 0 value otherwise. - * - */ -int at86rf231_channel_is_clear(netdev_t *dev); - -/** - * @brief Interrupt handler, gets fired when a RX overflow happens. - * - */ -void at86rf231_rxoverflow_irq(void); - -/** - * @brief Interrupt handler, gets fired when bytes in the RX FIFO are present. - * - */ -void at86rf231_rx_irq(void); - -/** - * @brief Sets the function called back when a packet is received. - * (Low-level mechanism, parallel to the `transceiver` module). - * - * @param[in] dev The network device to operate on. (Currently not used) - * @param[in] recv_cb callback function for 802.15.4 packet arrival - * - * @return 0 on success - * @return -ENODEV if *dev* is not recognized - * @return -ENOBUFS, if maximum number of registable callbacks is exceeded - */ -int at86rf231_add_raw_recv_callback(netdev_t *dev, - netdev_802154_raw_packet_cb_t recv_cb); - -/** - * @brief Unsets the function called back when a packet is received. - * (Low-level mechanism, parallel to the `transceiver` module). - * - * @param[in] dev The network device to operate on. (Currently not used) - * @param[in] recv_cb callback function to unset - * - * @return 0 on success - * @return -ENODEV if *dev* is not recognized - * @return -ENOBUFS, if maximum number of registable callbacks is exceeded - */ -int at86rf231_rem_raw_recv_callback(netdev_t *dev, - netdev_802154_raw_packet_cb_t recv_cb); - -/** - * @brief Sets a function called back when a data packet is received. - * - * @param[in] dev The network device to operate on. (Currently not used) - * @param[in] recv_cb callback function for 802.15.4 data packet arrival - * - * @return 0 on success - * @return -ENODEV if *dev* is not recognized - * @return -ENOBUFS, if maximum number of registable callbacks is exceeded - */ -int at86rf231_add_data_recv_callback(netdev_t *dev, - netdev_rcv_data_cb_t recv_cb); - -/** - * @brief Unsets a function called back when a data packet is received. - * - * @param[in] dev The network device to operate on. (Currently not used) - * @param[in] recv_cb callback function to unset - * - * @return 0 on success - * @return -ENODEV if *dev* is not recognized - * @return -ENOBUFS, if maximum number of registable callbacks is exceeded - */ -int at86rf231_rem_data_recv_callback(netdev_t *dev, - netdev_rcv_data_cb_t recv_cb); - -/** - * @brief RX handler, process data from the RX FIFO. - * - */ -void at86rf231_rx_handler(void); - -/** - * @brief Prepare the at86rf231 TX buffer to send with the given packet. - * - * @param[in] dev The network device to operate on. (Currently not used) - * @param[in] kind Kind of packet to transmit. - * @param[in] dest Address of the node to which the packet is sent. - * @param[in] use_long_addr 1 to use the 64-bit address mode - * with *dest* param; 0 to use - * "short" PAN-centric mode. - * @param[in] wants_ack 1 to request an acknowledgement - * from the receiving node for this packet; - * 0 otherwise. - * @param[in] upper_layer_hdrs header data from higher network layers from - * highest to lowest layer. Must be prepended to - * the data stream by the network device. May be - * NULL if there are none. - * @param[in] buf Pointer to the buffer containing the payload - * of the 802.15.4 packet to transmit. - * The frame header (i.e.: FCS, sequence number, - * src and dest PAN and addresses) is inserted - * using values in accord with *kind* parameter - * and transceiver configuration. - * @param[in] len Length (in bytes) of the outgoing packet payload. - * - * @return @ref netdev_802154_tx_status_t - */ -netdev_802154_tx_status_t at86rf231_load_tx_buf(netdev_t *dev, - netdev_802154_pkt_kind_t kind, - netdev_802154_node_addr_t *dest, - int use_long_addr, - int wants_ack, - netdev_hlist_t *upper_layer_hdrs, - void *buf, - unsigned int len); - -/** - * @brief Transmit the data loaded into the at86rf231 TX buffer. - * - * @param[in] dev The network device to operate on. (Currently not used) - * - * @return @ref netdev_802154_tx_status_t - */ -netdev_802154_tx_status_t at86rf231_transmit_tx_buf(netdev_t *dev); - -/** - * @brief Send function, sends a at86rf231_packet_t over the air. - * - * @param[in] *packet The Packet which will be send. - * - * @return The count of bytes which are send or -1 on error - * - */ -int16_t at86rf231_send(at86rf231_packet_t *packet); - -/** - * RX Packet Buffer, read from the transceiver, filled by the at86rf231_rx_handler. - */ -extern at86rf231_packet_t at86rf231_rx_buffer[AT86RF231_RX_BUF_SIZE]; - -/** - * Get at86rf231's status byte - */ -uint8_t at86rf231_get_status(void); - -/** - * Get at86rf231's TRAC status byte - */ -uint8_t at86rf231_get_trac_status(void); - -/** - * at86rf231 low-level radio driver definition. - */ -extern const netdev_802154_driver_t at86rf231_driver; - -#ifdef __cplusplus -} -#endif - -#endif /* AT86RF231_H_ */ -/** @} */ diff --git a/drivers/include/at86rf231/at86rf231_settings.h b/drivers/include/at86rf231/at86rf231_settings.h deleted file mode 100644 index 274202e82a..0000000000 --- a/drivers/include/at86rf231/at86rf231_settings.h +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright (C) 2014 INRIA - * - * 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 drivers_at86rf231 - * @{ - * - * @file - * @brief Register and command definitions for the AT86RF231 radio - * - * @author Alaeddine Weslati - */ - -#ifndef AT86AT86RF231_SETTINGS_H -#define AT86AT86RF231_SETTINGS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define AT86RF231_RX_BUF_SIZE 3 - -enum at86rf231_access { - AT86RF231_ACCESS_REG = 0x80, - AT86RF231_ACCESS_FRAMEBUFFER = 0x20, - AT86RF231_ACCESS_SRAM = 0x00, - - AT86RF231_ACCESS_READ = 0x00, - AT86RF231_ACCESS_WRITE = 0x40, -}; - -enum at86rf231_register { - AT86RF231_REG__TRX_STATUS = 0x01, - AT86RF231_REG__TRX_STATE = 0x02, - AT86RF231_REG__TRX_CTRL_0 = 0x03, - AT86RF231_REG__TRX_CTRL_1 = 0x04, - AT86RF231_REG__PHY_TX_PWR = 0x05, - AT86RF231_REG__PHY_RSSI = 0x06, - AT86RF231_REG__PHY_ED_LEVEL = 0x07, - AT86RF231_REG__PHY_CC_CCA = 0x08, - AT86RF231_REG__CCA_THRES = 0x09, - AT86RF231_REG__RX_CTRL = 0x0A, - AT86RF231_REG__SFD_VALUE = 0x0B, - AT86RF231_REG__TRX_CTRL_2 = 0x0C, - AT86RF231_REG__ANT_DIV = 0x0D, - AT86RF231_REG__IRQ_MASK = 0x0E, - AT86RF231_REG__IRQ_STATUS = 0x0F, - AT86RF231_REG__VREG_CTRL = 0x10, - AT86RF231_REG__BATMON = 0x11, - AT86RF231_REG__XOSC_CTRL = 0x12, - - AT86RF231_REG__RX_SYN = 0x15, - - AT86RF231_REG__XAH_CTRL_1 = 0x17, - AT86RF231_REG__FTN_CTRL = 0x18, - - AT86RF231_REG__PLL_CF = 0x1A, - AT86RF231_REG__PLL_DCU = 0x1B, - AT86RF231_REG__PART_NUM = 0x1C, - AT86RF231_REG__VERSION_NUM = 0x1D, - AT86RF231_REG__MAN_ID_0 = 0x1E, - AT86RF231_REG__MAN_ID_1 = 0x1F, - AT86RF231_REG__SHORT_ADDR_0 = 0x20, - AT86RF231_REG__SHORT_ADDR_1 = 0x21, - AT86RF231_REG__PAN_ID_0 = 0x22, - AT86RF231_REG__PAN_ID_1 = 0x23, - - AT86RF231_REG__IEEE_ADDR_0 = 0x24, - AT86RF231_REG__IEEE_ADDR_1 = 0x25, - AT86RF231_REG__IEEE_ADDR_2 = 0x26, - AT86RF231_REG__IEEE_ADDR_3 = 0x27, - AT86RF231_REG__IEEE_ADDR_4 = 0x28, - AT86RF231_REG__IEEE_ADDR_5 = 0x29, - AT86RF231_REG__IEEE_ADDR_6 = 0x2A, - AT86RF231_REG__IEEE_ADDR_7 = 0x2B, - - AT86RF231_REG__XAH_CTRL_0 = 0x2C, - AT86RF231_REG__CSMA_SEED_0 = 0x2D, - AT86RF231_REG__CSMA_SEED_1 = 0x2E, - AT86RF231_REG__CSMA_BE = 0x2F, - - - AT86RF231_REG__TST_CTRL_DIGI = 0x36, -}; - -enum { - AT86RF231_TRX_CTRL_0_MASK__PAD_IO = 0xC0, - AT86RF231_TRX_CTRL_0_MASK__PAD_IO_CLKM = 0x30, - AT86RF231_TRX_CTRL_0_MASK__CLKM_SHA_SEL = 0x08, - AT86RF231_TRX_CTRL_0_MASK__CLKM_CTRL = 0x07, - - AT86RF231_TRX_CTRL_0_DEFAULT__PAD_IO = 0x00, - AT86RF231_TRX_CTRL_0_DEFAULT__PAD_IO_CLKM = 0x10, - AT86RF231_TRX_CTRL_0_DEFAULT__CLKM_SHA_SEL = 0x08, - AT86RF231_TRX_CTRL_0_DEFAULT__CLKM_CTRL = 0x01, - - AT86RF231_TRX_CTRL_0_CLKM_CTRL__OFF = 0x00, - AT86RF231_TRX_CTRL_0_CLKM_CTRL__1MHz = 0x01, - AT86RF231_TRX_CTRL_0_CLKM_CTRL__2MHz = 0x02, - AT86RF231_TRX_CTRL_0_CLKM_CTRL__4MHz = 0x03, - AT86RF231_TRX_CTRL_0_CLKM_CTRL__8MHz = 0x04, - AT86RF231_TRX_CTRL_0_CLKM_CTRL__16MHz = 0x05, - AT86RF231_TRX_CTRL_0_CLKM_CTRL__250kHz = 0x06, - AT86RF231_TRX_CTRL_0_CLKM_CTRL__62_5kHz = 0x07, -}; - -enum { - AT86RF231_TRX_CTRL_1_MASK__PA_EXT_EN = 0x80, - AT86RF231_TRX_CTRL_1_MASK__IRQ_2_EXT_EN = 0x40, - AT86RF231_TRX_CTRL_1_MASK__TX_AUTO_CRC_ON = 0x20, - AT86RF231_TRX_CTRL_1_MASK__RX_BL_CTRL = 0x10, - AT86RF231_TRX_CTRL_1_MASK__SPI_CMD_MODE = 0x0C, - AT86RF231_TRX_CTRL_1_MASK__IRQ_MASK_MODE = 0x02, - AT86RF231_TRX_CTRL_1_MASK__IRQ_POLARITY = 0x01, -}; - -enum { - AT86RF231_TRX_CTRL_2_MASK__RX_SAFE_MODE = 0x80, - AT86RF231_TRX_CTRL_2_MASK__OQPSK_DATA_RATE = 0x03, -}; - -enum { - AT86RF231_IRQ_STATUS_MASK__BAT_LOW = 0x80, - AT86RF231_IRQ_STATUS_MASK__TRX_UR = 0x40, - AT86RF231_IRQ_STATUS_MASK__AMI = 0x20, - AT86RF231_IRQ_STATUS_MASK__CCA_ED_DONE = 0x10, - AT86RF231_IRQ_STATUS_MASK__TRX_END = 0x08, - AT86RF231_IRQ_STATUS_MASK__RX_START = 0x04, - AT86RF231_IRQ_STATUS_MASK__PLL_UNLOCK = 0x02, - AT86RF231_IRQ_STATUS_MASK__PLL_LOCK = 0x01, -}; - -enum at86rf231_trx_status { - AT86RF231_TRX_STATUS_MASK__CCA_DONE = 0x80, - AT86RF231_TRX_STATUS_MASK__CCA_STATUS = 0x40, - AT86RF231_TRX_STATUS_MASK__TRX_STATUS = 0x1F, - - AT86RF231_TRX_STATUS__P_ON = 0x00, - AT86RF231_TRX_STATUS__BUSY_RX = 0x01, - AT86RF231_TRX_STATUS__BUSY_TX = 0x02, - AT86RF231_TRX_STATUS__RX_ON = 0x06, - AT86RF231_TRX_STATUS__TRX_OFF = 0x08, - AT86RF231_TRX_STATUS__PLL_ON = 0x09, - AT86RF231_TRX_STATUS__SLEEP = 0x0F, - AT86RF231_TRX_STATUS__BUSY_RX_AACK = 0x11, - AT86RF231_TRX_STATUS__BUSY_TX_ARET = 0x12, - AT86RF231_TRX_STATUS__RX_AACK_ON = 0x16, - AT86RF231_TRX_STATUS__TX_ARET_ON = 0x19, - AT86RF231_TRX_STATUS__RX_ON_NOCLK = 0x1C, - AT86RF231_TRX_STATUS__RX_AACK_ON_NOCLK = 0x1D, - AT86RF231_TRX_STATUS__BUSY_RX_AACK_NOCLK = 0x1E, - AT86RF231_TRX_STATUS__STATE_TRANSITION_IN_PROGRESS = 0x1F, -}; - -enum at86rf231_trx_state { - AT86RF231_TRX_STATE_MASK__TRAC = 0xe0, - - AT86RF231_TRX_STATE__NOP = 0x00, - AT86RF231_TRX_STATE__TX_START = 0x02, - AT86RF231_TRX_STATE__FORCE_TRX_OFF = 0x03, - AT86RF231_TRX_STATE__FORCE_PLL_ON = 0x04, - AT86RF231_TRX_STATE__RX_ON = 0x06, - AT86RF231_TRX_STATE__TRX_OFF = 0x08, - AT86RF231_TRX_STATE__PLL_ON = 0x09, - AT86RF231_TRX_STATE__RX_AACK_ON = 0x16, - AT86RF231_TRX_STATE__TX_ARET_ON = 0x19, - - AT86RF231_TRX_STATE__TRAC_SUCCESS = 0x00, - AT86RF231_TRX_STATE__TRAC_SUCCESS_DATA_PENDING = 0x20, - AT86RF231_TRX_STATE__TRAC_SUCCESS_WAIT_FOR_ACK = 0x40, - AT86RF231_TRX_STATE__TRAC_CHANNEL_ACCESS_FAILURE = 0x60, - AT86RF231_TRX_STATE__TRAC_NO_ACK = 0xa0, - AT86RF231_TRX_STATE__TRAC_INVALID = 0xe0, -}; - -enum at86rf231_phy_cc_cca { - AT86RF231_PHY_CC_CCA_MASK__CCA_REQUEST = 0x80, - AT86RF231_PHY_CC_CCA_MASK__CCA_MODE = 0x60, - AT86RF231_PHY_CC_CCA_MASK__CHANNEL = 0x1F, - - AT86RF231_PHY_CC_CCA_DEFAULT__CCA_MODE = 0x20, -}; - -enum at86rf231_phy_tx_pwr { - AT86RF231_PHY_TX_PWR_MASK__PA_BUF_LT = 0xC0, - AT86RF231_PHY_TX_PWR_MASK__PA_LT = 0x30, - AT86RF231_PHY_TX_PWR_MASK__TX_PWR = 0x0F, - - AT86RF231_PHY_TX_PWR_DEFAULT__PA_BUF_LT = 0xC0, - AT86RF231_PHY_TX_PWR_DEFAULT__PA_LT = 0x00, - AT86RF231_PHY_TX_PWR_DEFAULT__TX_PWR = 0x00, - - AT86RF231_PHY_TX_PWR_TX_PWR_VALUE__3dBm = 0x00, - AT86RF231_PHY_TX_PWR_TX_PWR_VALUE__2_8dBm = 0x01, - AT86RF231_PHY_TX_PWR_TX_PWR_VALUE__2_3dBm = 0x02, - AT86RF231_PHY_TX_PWR_TX_PWR_VALUE__1_8dBm = 0x03, - AT86RF231_PHY_TX_PWR_TX_PWR_VALUE__1_3dBm = 0x04, - AT86RF231_PHY_TX_PWR_TX_PWR_VALUE__0_7dBm = 0x05, - AT86RF231_PHY_TX_PWR_TX_PWR_VALUE__0dBm = 0x06, - AT86RF231_PHY_TX_PWR_TX_PWR_VALUE__m1dBm = 0x07, - AT86RF231_PHY_TX_PWR_TX_PWR_VALUE__m2dBm = 0x08, - AT86RF231_PHY_TX_PWR_TX_PWR_VALUE__m3dBm = 0x09, - AT86RF231_PHY_TX_PWR_TX_PWR_VALUE__m4dBm = 0x0A, - AT86RF231_PHY_TX_PWR_TX_PWR_VALUE__m5dBm = 0x0B, - AT86RF231_PHY_TX_PWR_TX_PWR_VALUE__m7dBm = 0x0C, - AT86RF231_PHY_TX_PWR_TX_PWR_VALUE__m9dBm = 0x0D, - AT86RF231_PHY_TX_PWR_TX_PWR_VALUE__m12dBm = 0x0E, - AT86RF231_PHY_TX_PWR_TX_PWR_VALUE__m17dBm = 0x0F, - -}; - -enum at86rf231_phy_rssi { - AT86RF231_PHY_RSSI_MASK__RX_CRC_VALID = 0x80, - AT86RF231_PHY_RSSI_MASK__RND_VALUE = 0x60, - AT86RF231_PHY_RSSI_MASK__RSSI = 0x1F, -}; - -enum at86rf231_xosc_ctrl { - AT86RF231_XOSC_CTRL__XTAL_MODE_CRYSTAL = 0xF0, - AT86RF231_XOSC_CTRL__XTAL_MODE_EXTERNAL = 0xF0, -}; - -enum at86rf231_timing { - AT86RF231_TIMING__VCC_TO_P_ON = 330, - AT86RF231_TIMING__SLEEP_TO_TRX_OFF = 380, - AT86RF231_TIMING__TRX_OFF_TO_PLL_ON = 110, - AT86RF231_TIMING__TRX_OFF_TO_RX_ON = 110, - AT86RF231_TIMING__PLL_ON_TO_BUSY_TX = 16, - - AT86RF231_TIMING__RESET = 100, - AT86RF231_TIMING__RESET_TO_TRX_OFF = 37, -}; - -enum at86rf231_xah_ctrl_1 { - AT86RF231_XAH_CTRL_1__AACK_FLTR_RES_FT = 0x20, - AT86RF231_XAH_CTRL_1__AACK_UPLD_RES_FT = 0x10, - AT86RF231_XAH_CTRL_1__AACK_ACK_TIME = 0x04, - AT86RF231_XAH_CTRL_1__AACK_PROM_MODE = 0x02, -}; - -enum at86rf231_csma_seed_1 { - AT86RF231_CSMA_SEED_1__AACK_SET_PD = 0x20, - AT86RF231_CSMA_SEED_1__AACK_DIS_ACK = 0x10, - AT86RF231_CSMA_SEED_1__AACK_I_AM_COORD = 0x08, -}; - -#ifdef __cplusplus -} -#endif -#endif /* AT86AT86RF231_SETTINGS_H */ diff --git a/drivers/include/cc110x.h b/drivers/include/cc110x.h deleted file mode 100644 index 9843c5d2cf..0000000000 --- a/drivers/include/cc110x.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2014 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. - */ - -#ifndef CC110X_H -#define CC110X_H - -#include "cc110x/cc110x-interface.h" -#include "cc110x/cc110x-defaultsettings.h" -#include "cc110x/cc110x-config.h" -#include "cc110x/cc110x-reg.h" -#include "cc110x/cc110x-netdev.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* CC110X_H */ diff --git a/drivers/include/cc110x/cc110x-config.h b/drivers/include/cc110x/cc110x-config.h deleted file mode 100644 index f76a9ccb9b..0000000000 --- a/drivers/include/cc110x/cc110x-config.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (C) 2014 Freie Universität Berlin - * Copyright (C) 2013 INRIA - * - * 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 drivers_cc110x - * @{ - * - * @file - * @brief Configuration parameters for the cc110x radio chip - * - * @author Oliver Hahm - * @author Fabian Nack - */ - -#ifndef CC110X_CONFIG_H -#define CC110X_CONFIG_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief CC110x register configuration - */ -typedef struct { - uint8_t _IOCFG2; /**< GDO2 output pin configuration */ - uint8_t _IOCFG1; /**< GDO1 output pin configuration */ - uint8_t _IOCFG0; /**< GDO0 output pin configuration */ - uint8_t _FIFOTHR; /**< RX FIFO and TX FIFO thresholds */ - uint8_t _SYNC1; /**< Sync word, high byte */ - uint8_t _SYNC0; /**< Sync word, low byte */ - uint8_t _PKTLEN; /**< Packet length */ - uint8_t _PKTCTRL1; /**< Packet automation control */ - uint8_t _PKTCTRL0; /**< Packet automation control */ - uint8_t _ADDR; /**< Device address */ - uint8_t _CHANNR; /**< Channel number */ - uint8_t _FSCTRL1; /**< Frequency synthesizer control */ - uint8_t _FSCTRL0; /**< Frequency synthesizer control */ - uint8_t _FREQ2; /**< Frequency control word, high byte */ - uint8_t _FREQ1; /**< Frequency control word, middle byte */ - uint8_t _FREQ0; /**< Frequency control word, low byte */ - uint8_t _MDMCFG4; /**< Modem configuration */ - uint8_t _MDMCFG3; /**< Modem configuration */ - uint8_t _MDMCFG2; /**< Modem configuration */ - uint8_t _MDMCFG1; /**< Modem configuration */ - uint8_t _MDMCFG0; /**< Modem configuration */ - uint8_t _DEVIATN; /**< Modem deviation setting */ - uint8_t _MCSM2; /**< Main Radio Control State Machine configuration */ - uint8_t _MCSM1; /**< Main Radio Control State Machine configuration */ - uint8_t _MCSM0; /**< Main Radio Control State Machine configuration */ - uint8_t _FOCCFG; /**< Frequency Offset Compensation configuration */ - uint8_t _BSCFG; /**< Bit Synchronization configuration */ - uint8_t _AGCCTRL2; /**< AGC control */ - uint8_t _AGCCTRL1; /**< AGC control */ - uint8_t _AGCCTRL0; /**< AGC control */ - uint8_t _WOREVT1; /**< High byte Event 0 timeout */ - uint8_t _WOREVT0; /**< Low byte Event 0 timeout */ - uint8_t _WORCTRL; /**< Wake On Radio control */ - uint8_t _FREND1; /**< Front end RX configuration */ - uint8_t _FREND0; /**< Front end TX configuration */ - uint8_t _FSCAL3; /**< Frequency synthesizer calibration */ - uint8_t _FSCAL2; /**< Frequency synthesizer calibration */ - uint8_t _FSCAL1; /**< Frequency synthesizer calibration */ - uint8_t _FSCAL0; /**< Frequency synthesizer calibration */ -} cc110x_reg_t; - -/** - * @brief CC110x radio configuration - */ -typedef struct { - cc110x_reg_t reg_cfg; ///< CC1100 register configuration - uint8_t pa_power; ///< Output power setting -} cc110x_cfg_t; - -/** - * @brief Radio Control Flags - */ -typedef struct { - uint8_t _RSSI; ///< The RSSI value of last received packet - uint8_t _LQI; ///< The LQI value of the last received packet -} cc110x_flags; - -/** - * @brief Statistic interface for debugging - */ -typedef struct cc110x_statistic { - uint32_t packets_in; - uint32_t packets_in_crc_fail; - uint32_t packets_in_while_tx; - uint32_t raw_packets_out; -} cc110x_statistic_t; - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif /* CC110X_CONFIG_H */ diff --git a/drivers/include/cc110x/cc110x-defaultsettings.h b/drivers/include/cc110x/cc110x-defaultsettings.h deleted file mode 100644 index 2533bbbc36..0000000000 --- a/drivers/include/cc110x/cc110x-defaultsettings.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2014 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 drivers_cc110x - * @{ - * - * @file - * @brief TI Chipcon CC110x default settings - * - * @author Thomas Hillebrandt - * @author Heiko Will - * @author Fabian Nack - */ - -#ifndef CC110X_DEFAULTSETTINGS_H -#define CC110X_DEFAULTSETTINGS_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Returns hwtimer ticks per us */ -#define RTIMER_TICKS(us) HWTIMER_TICKS(us) - -#define TIMER_TICK_USEC_RES (122) - -/* Reset wait time (in reset procedure) */ -#define RESET_WAIT_TIME RTIMER_TICKS(4 * TIMER_TICK_USEC_RES) - -/* Time chip needs to go to RX */ -#define IDLE_TO_RX_TIME RTIMER_TICKS(1 * TIMER_TICK_USEC_RES) - -/* Time to wait for SO to go low after CS */ -#define CS_SO_WAIT_TIME RTIMER_TICKS(4 * TIMER_TICK_USEC_RES) - -/* Max. retries for SO to go low after CS */ -#define CC1100_GDO1_LOW_RETRY (100) - -/* The size of the configuration array for CC1100 in bytes */ -#define CC1100_CONF_SIZE (39) - -/* The default channel number (0-24) for CC1100 */ -#define CC1100_DEFAULT_CHANNR (0) - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif /* CC110X_DEFAULTSETTINGS_H */ diff --git a/drivers/include/cc110x/cc110x-interface.h b/drivers/include/cc110x/cc110x-interface.h deleted file mode 100644 index 82e20a60c7..0000000000 --- a/drivers/include/cc110x/cc110x-interface.h +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (C) 2014 Freie Universität Berlin - * Copyright (C) 2013 INRIA - * - * 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. - */ - -/** - * @defgroup drivers_cc110x CC110X - * @brief Driver for Texas Instruments CC110x (without MAC protocol) - * @ingroup drivers - * @{ - * - * @file - * @brief Data structures and variables for the cc110x driver interface - * - * @author Oliver Hahm - */ - -#ifndef CC110X_INTERFACE_H -#define CC110X_INTERFACE_H - -#include -#include "radio/radio.h" -#include "radio/types.h" -#include "cc110x-config.h" -#include "kernel_types.h" -#include "transceiver.h" -#include "netdev/base.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define CC1100_MAX_DATA_LENGTH (58) - -#define CC1100_HEADER_LENGTH (3) ///< Header covers SRC, DST and FLAGS - -#define CC1100_BROADCAST_ADDRESS (0x00) ///< CC1100 broadcast address - -#define MAX_UID (0xFF) ///< Maximum UID of a node is 255 -#define MIN_UID (0x01) ///< Minimum UID of a node is 1 - -#define MIN_CHANNR (0) ///< Minimum channel number -#define MAX_CHANNR (24) ///< Maximum channel number - -#define MIN_OUTPUT_POWER (0) ///< Minimum output power value -#define MAX_OUTPUT_POWER (11) ///< Maximum output power value - -#define PACKET_LENGTH (0x3E) ///< Packet length = 62 Bytes. -#define CC1100_SYNC_WORD_TX_TIME (90000) // loop count (max. timeout ~ 15 ms) to wait for - // sync word to be transmitted (GDO2 from low to high) -/** - * @name Defines used as state values for state machine - * @{ - */ -#define RADIO_UNKNOWN (0) -#define RADIO_IDLE (1) -#define RADIO_SEND_BURST (2) -#define RADIO_RX (3) -#define RADIO_PWD (4) - -/** @} */ - -extern volatile cc110x_flags rflags; ///< Radio flags -extern char cc110x_conf[]; - -/** - * @brief CC1100 layer 0 protocol - * - *

----------------------------------------------------
-|        |         |         |       |            |
-| Length | Address | PhySrc  | Flags |    Data    |
-|        |         |         |       |            |
----------------------------------------------------
-  1 byte   1 byte    1 byte   1 byte   <= 58 bytes
-
-Flags:
-        Bit | Meaning
-        --------------------
-        7:4 | -
-        3:1 | Protocol
-          0 | Identification
-
-Notes: -\li length & address are given by CC1100 -\li Identification is increased is used to scan duplicates. It must be increased - for each new packet and kept for packet retransmissions. - */ -typedef struct __attribute__((packed)) -{ - uint8_t length; ///< Length of the packet (without length byte) - uint8_t address; ///< Destination address - uint8_t phy_src; ///< Source address (physical source) - uint8_t flags; ///< Flags - uint8_t data[CC1100_MAX_DATA_LENGTH]; ///< Data (high layer protocol) -} -cc110x_packet_t; - -typedef struct { - uint8_t rssi; - uint8_t lqi; - cc110x_packet_t packet; -} rx_buffer_t; - -enum radio_mode { - RADIO_MODE_GET = -1, ///< leave mode unchanged - RADIO_MODE_OFF = 0, ///< turn radio off - RADIO_MODE_ON = 1 ///< turn radio on -}; - -extern rx_buffer_t cc110x_rx_buffer[]; - -extern volatile uint8_t rx_buffer_next; ///< Next packet in RX queue - -extern volatile uint8_t radio_state; ///< Radio state -extern cc110x_statistic_t cc110x_statistic; - -#ifdef MODULE_TRANSCEIVER -void cc110x_init(kernel_pid_t transceiver_pid); -#endif - -int cc110x_initialize(netdev_t *dev); - -int8_t cc110x_send(cc110x_packet_t *pkt); - -uint8_t cc110x_get_buffer_pos(void); - -void cc110x_setup_rx_mode(void); -void cc110x_switch_to_rx(void); -void cc110x_wakeup_from_rx(void); -void cc110x_switch_to_pwd(void); - -int16_t cc110x_set_config_channel(uint8_t channr); -int16_t cc110x_set_channel(uint8_t channr); -int16_t cc110x_get_channel(void); - -radio_address_t cc110x_set_address(radio_address_t addr); -radio_address_t cc110x_set_config_address(radio_address_t addr); -radio_address_t cc110x_get_address(void); -void cc110x_set_monitor(uint8_t mode); - -void cc110x_print_config(void); - -/** - * @brief GDO2 interrupt handler. - * - * @note Wakes up MCU on packet reception. - */ -void cc110x_rx_handler(void *args); - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif /* CC110X_INTERFACE_H */ diff --git a/drivers/include/cc110x/cc110x-netdev.h b/drivers/include/cc110x/cc110x-netdev.h deleted file mode 100644 index d9573495fd..0000000000 --- a/drivers/include/cc110x/cc110x-netdev.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2014 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 drivers_cc110x - * @{ - * - * @file - * @brief Variables for the cc110x netdev base interface - * - * @author Fabian Nack - */ - -#ifndef CC110X_NETDEV_H -#define CC110X_NETDEV_H - -#include "netdev/base.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Implementation of netdev_driver_t for CC110X device - */ -extern const netdev_driver_t cc110x_net_driver; - -/** - * @brief CC110X default device - */ -extern netdev_t cc110x_dev; - -#ifdef __cplusplus -} -#endif - -#endif /* CC110X_NETDEV_H */ diff --git a/drivers/include/cc110x/cc110x-reg.h b/drivers/include/cc110x/cc110x-reg.h deleted file mode 100644 index fc2b6ddf18..0000000000 --- a/drivers/include/cc110x/cc110x-reg.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2014 Freie Universität Berlin - * Copyright (C) 2013 INRIA - * - * 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 drivers_cc110x - * @{ - * - * @file - * @brief Access to CC110X registers - * - * @author Oliver Hahm - * @author Fabian Nack - */ - -#ifndef CC110X_REG_H -#define CC110X_REG_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Write a set of bytes using burst mode (if available) - * - * @param addr Destination register - * @param buffer Data to be written - * @param count Size of data - */ -void cc110x_writeburst_reg(uint8_t addr, char *buffer, uint8_t count); - -/** - * @brief Read a set of bytes using burst mode (if available) - * - * @param addr Source register - * @param buffer Buffer to store read data - * @param count Size of data to be read - */ -void cc110x_readburst_reg(uint8_t addr, char *buffer, uint8_t count); - -/** - * @brief Write one byte to a register - * - * @param addr Destinatoin register - * @param value New value - */ -void cc110x_write_reg(uint8_t addr, uint8_t value); - -/** - * @brief Read a byte from register - * - * @param addr Source register - * - * @return Read state and value of register - */ -uint8_t cc110x_read_reg(uint8_t addr); - -/** - * @brief Read state of a register - * - * @param addr Source register - * - * @return State of register - */ -uint8_t cc110x_read_status(uint8_t addr); - -/** - * @brief Sends a command strobe - * - * @param c Command code - * - * @return Command response - */ -uint8_t cc110x_strobe(uint8_t c); - -/** - * @brief Pull CS to low and wait for CC110x stabilization - */ -void cc110x_cs(void); - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif /* CC110X_REG_H */ diff --git a/drivers/include/cc110x_legacy.h b/drivers/include/cc110x_legacy.h deleted file mode 100644 index 8c7afe144c..0000000000 --- a/drivers/include/cc110x_legacy.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2014 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. - */ - -#ifndef CC110X_LEGACY_H -#define CC110X_LEGACY_H - -#include "cc110x_legacy/cc110x-interface.h" -#include "cc110x_legacy/cc110x-defaultSettings.h" -#include "cc110x_legacy/cc110x-config.h" -#include "cc110x_legacy/cc110x-reg.h" -#include "cc110x_legacy/cc110x-arch.h" -#include "cc110x_legacy/cc110x_spi.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* CC110X_LEGACY_H */ diff --git a/drivers/include/cc110x_legacy/cc110x-arch.h b/drivers/include/cc110x_legacy/cc110x-arch.h deleted file mode 100644 index 8a4eedccb1..0000000000 --- a/drivers/include/cc110x_legacy/cc110x-arch.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. - * - * 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 drivers_cc110x_legacy - * @{ - * - * @file - * @brief CC1100 architecture dependent functions - * - * @author Heiko Will - */ - -#ifndef CC1100_ARCH_H -#define CC1100_ARCH_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -uint8_t cc110x_txrx(uint8_t c); - -void cc110x_gdo0_enable(void); -void cc110x_gdo0_disable(void); -void cc110x_gdo2_enable(void); -void cc110x_gdo2_disable(void); -void cc110x_init_interrupts(void); - -void cc110x_before_send(void); -void cc110x_after_send(void); - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif /* CC1100_ARCH_H */ diff --git a/drivers/include/cc110x_legacy/cc110x-config.h b/drivers/include/cc110x_legacy/cc110x-config.h deleted file mode 100644 index 520f63c434..0000000000 --- a/drivers/include/cc110x_legacy/cc110x-config.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2009 Freie Universität Berlin - * Copyright (C) 2013 INRIA - * - * 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 drivers_cc110x_legacy - * @{ - * - * @file - * @brief Configuration parameters for the cc110x radio chip - * - * @author Oliver Hahm - */ -#ifndef CC1100_CONFIG_H -#define CC1100_CONFIG_H - -#include -#include "timex.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** CC1100 register configuration */ -typedef struct { - uint8_t _IOCFG2; - uint8_t _IOCFG1; - uint8_t _IOCFG0; - uint8_t _FIFOTHR; - uint8_t _SYNC1; - uint8_t _SYNC0; - uint8_t _PKTLEN; - uint8_t _PKTCTRL1; - uint8_t _PKTCTRL0; - uint8_t _ADDR; - uint8_t _CHANNR; - uint8_t _FSCTRL1; - uint8_t _FSCTRL0; - uint8_t _FREQ2; - uint8_t _FREQ1; - uint8_t _FREQ0; - uint8_t _MDMCFG4; - uint8_t _MDMCFG3; - uint8_t _MDMCFG2; - uint8_t _MDMCFG1; - uint8_t _MDMCFG0; - uint8_t _DEVIATN; - uint8_t _MCSM2; - uint8_t _MCSM1; - uint8_t _MCSM0; - uint8_t _FOCCFG; - uint8_t _BSCFG; - uint8_t _AGCCTRL2; - uint8_t _AGCCTRL1; - uint8_t _AGCCTRL0; - uint8_t _WOREVT1; - uint8_t _WOREVT0; - uint8_t _WORCTRL; - uint8_t _FREND1; - uint8_t _FREND0; - uint8_t _FSCAL3; - uint8_t _FSCAL2; - uint8_t _FSCAL1; - uint8_t _FSCAL0; -} cc110x_reg_t; - -/** CC1100 radio configuration */ -typedef struct { - cc110x_reg_t reg_cfg; /**< CC1100 register configuration */ - uint8_t pa_power; /**< Output power setting */ -} cc110x_cfg_t; - -/** - * @brief Radio Control Flags - */ -typedef struct { - uint32_t TOF; /**< Time of flight of the last packet and last ACK */ - timex_t TOA; /**< Time of packet arrival */ - uint32_t TCP; /**< Time to compute packet */ - unsigned RPS : 16; /**< Raw packets sent to transmit last packet */ - unsigned RETC : 8; /**< Retransmission count of last sent packet */ - unsigned _RSSI : 8; /**< The RSSI value of last received packet */ - unsigned RSSI_SEND : 8; /**< The RSSI value of the last sent unicast packet of this node */ - unsigned _LQI : 8; /**< The LQI value of the last received packet */ - unsigned LL_ACK : 1; /**< Is set if Link-Level ACK is received, otherwise 0 (reset on new burst) */ - unsigned CAA : 1; /**< The status of the air (1 = air free, 0 = air not free) */ - unsigned CRC_STATE : 1; /**< The CRC status of last received packet (1 = OK, 0 = not OK) */ - unsigned SEQ : 1; /**< Sequence number (toggles between 0 and 1) */ - unsigned MAN_WOR : 1; /**< Manual WOR set (for randomized WOR times => no synch) */ - unsigned KT_RES_ERR : 1; /**< A hwtimer resource error has occurred (no free timers available) */ - unsigned TX : 1; /**< State machine TX lock, only ACKs will be received */ - unsigned WOR_RST : 1; /**< Reset CC1100 real time clock (WOR) on next WOR strobe */ -} cc110x_flags; - -/** - * @brief Statistic interface for debugging - */ -typedef struct cc110x_statistic { - uint32_t packets_in; - uint32_t packets_in_crc_fail; - uint32_t packets_in_while_tx; - uint32_t packets_in_dups; - uint32_t packets_in_up; - uint32_t packets_out; - uint32_t packets_out_broadcast; - uint32_t raw_packets_out; - uint32_t acks_send; - uint32_t rx_buffer_max; - uint32_t watch_dog_resets; -} cc110x_statistic_t; - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif /* CC110X_CONFIG_H */ diff --git a/drivers/include/cc110x_legacy/cc110x-defaultSettings.h b/drivers/include/cc110x_legacy/cc110x-defaultSettings.h deleted file mode 100644 index 1a3f64aecb..0000000000 --- a/drivers/include/cc110x_legacy/cc110x-defaultSettings.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. - * - * 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. - */ - -#ifndef CC1100_DEFAULTSETTINGS_H -#define CC1100_DEFAULTSETTINGS_H - -/** - * @ingroup drivers_cc110x_legacy - * @{ - * - * @file - * @brief TI Chipcon CC110x default settings - * - * @author Thomas Hillebrandt - * @author Heiko Will - */ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* returns hwtimer ticks per us */ -#define RTIMER_TICKS(us) HWTIMER_TICKS(us) - -#define TIMER_TICK_USEC_RES (122) - -/* Watchdog cycle time in seconds, set 0 to disable watchdog */ -#define CC1100_WATCHDOG_PERIOD (5) - -/* Number of transmission retries for unicast packets (constant RX mode) */ -#define TRANSMISSION_RETRIES_CRX_UC (5) - -/* Number of transmission retries for unicast packets (WOR mode) */ -#define TRANSMISSION_RETRIES_WOR_UC (1) - -/* Number of transmission retries for broadcast packets (constant RX mode) */ -#define TRANSMISSION_RETRIES_CRX_BC (0) - -/* Number of transmission retries for broadcast packets (WOR mode) */ -#define TRANSMISSION_RETRIES_WOR_BC (0) - -/* Time before chip goes back to RX (= stays in PWD after incoming packet) */ -#define WOR_TIMEOUT_1 (3200) /* ~ 32 milliseconds */ - -/* Time before chip goes back to WOR (= stays in RX after elapsed WOR_TIMEOUT_1) */ -#define WOR_TIMEOUT_2 (800) /* ~ 8 milliseconds */ - -/* XOSC startup + FS calibration (300 + 809 us ~ 1.38 ms) */ -#define FS_CAL_TIME RTIMER_TICKS(12 * TIMER_TICK_USEC_RES) - -/* Manual FS calibration (721 us) */ -#define MANUAL_FS_CAL_TIME RTIMER_TICKS(7 * TIMER_TICK_USEC_RES) - -/* Reset wait time (in reset procedure) */ -#define RESET_WAIT_TIME RTIMER_TICKS(4 * TIMER_TICK_USEC_RES) - -/* Time chip needs to go to RX */ -#define IDLE_TO_RX_TIME RTIMER_TICKS(1 * TIMER_TICK_USEC_RES) - -/* Time chip needs to go to RX and CS signal is ready */ -#define CS_READY_TIME RTIMER_TICKS(3 * TIMER_TICK_USEC_RES) - -/* Default RX interval for WOR in milliseconds */ -#define T_RX_INTERVAL (542) - -/* Time of packet interval in microseconds (at 400 kbps) */ -#define T_PACKET_INTERVAL (3800) - -/* The size of the configuration array for CC1100 in bytes */ -#define CC1100_CONF_SIZE (39) - -/* The default channel number (0-24) for CC1100 */ -#define CC1100_DEFAULT_CHANNR (0) - -/* Burst retry to TX switch time (measured ~ 230 us) */ -#define BURST_RETRY_TX_SWITCH_TIME (23) - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif /* CC110X_DEFAULTSETTINGS_H */ diff --git a/drivers/include/cc110x_legacy/cc110x-interface.h b/drivers/include/cc110x_legacy/cc110x-interface.h deleted file mode 100644 index 9c3291de3d..0000000000 --- a/drivers/include/cc110x_legacy/cc110x-interface.h +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (C) 2009 Freie Universität Berlin - * Copyright (C) 2013 INRIA - * - * 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. - */ - -/** - * @defgroup drivers_cc110x_legacy CC110x_legacy - * @brief Driver for Texas Instruments CC110x (without MAC protocol) - * @ingroup drivers - * @{ - * - * @file - * @brief Data structures and variables for the cc110x driver interface - * - * @author Oliver Hahm - */ - -#ifndef CC110X_LEGACY_INTERFACE_H -#define CC110X_LEGACY_INTERFACE_H - -#include -#include "radio/radio.h" -#include "radio/types.h" -#include "cc110x-config.h" -#include "kernel_types.h" -#include "transceiver.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define CC1100_MAX_DATA_LENGTH (58) - -#define CC1100_HEADER_LENGTH (3) /**< Header covers SRC, DST and FLAGS */ - -#define CC1100_BROADCAST_ADDRESS (0x00) /**< CC1100 broadcast address */ - -#define MAX_UID (0xFF) /**< Maximum UID of a node is 255 */ -#define MIN_UID (0x01) /**< Minimum UID of a node is 1 */ - -#define MIN_CHANNR (0) /**< Minimum channel number */ -#define MAX_CHANNR (24) /**< Maximum channel number */ - -#define MIN_OUTPUT_POWER (0) /**< Minimum output power value */ -#define MAX_OUTPUT_POWER (11) /**< Maximum output power value */ - -#define PACKET_LENGTH (0x3E) /**< Packet length = 62 Bytes. */ -#define CC1100_SYNC_WORD_TX_TIME (90000) /**< loop count (max. timeout ~15 ms) - * to wait for sync word to be - * transmitted (GDO2 from low to high) */ -/** - * @name Defines used as state values for state machine - * @{ - */ -#define RADIO_UNKNOWN (0) -#define RADIO_AIR_FREE_WAITING (1) -#define RADIO_WOR (2) -#define RADIO_IDLE (3) -#define RADIO_SEND_BURST (4) -#define RADIO_RX (5) -#define RADIO_SEND_ACK (6) -#define RADIO_PWD (7) - -/** @} */ - -extern volatile cc110x_flags rflags; /**< Radio flags */ -extern char cc110x_conf[]; - -/** - * @brief CC1100 layer 0 protocol - * - *
----------------------------------------------------
-|        |         |         |       |            |
-| Length | Address | PhySrc  | Flags |    Data    |
-|        |         |         |       |            |
----------------------------------------------------
-  1 byte   1 byte    1 byte   1 byte   <= 58 bytes
-
-Flags:
-        Bit | Meaning
-        --------------------
-        7:4 | -
-        3:1 | Protocol
-          0 | Identification
-
-Notes: -\li length & address are given by CC1100 -\li Identification is increased is used to scan duplicates. It must be increased - for each new packet and kept for packet retransmissions. - */ -typedef struct __attribute__((packed)) -{ - uint8_t length; /**< Length of the packet (without length byte) */ - uint8_t address; /**< Destination address */ - uint8_t phy_src; /**< Source address (physical source) */ - uint8_t flags; /**< Flags */ - uint8_t data[CC1100_MAX_DATA_LENGTH]; /**< Data (high layer protocol) */ -} -cc110x_packet_t; - -typedef struct { - uint8_t rssi; - uint8_t lqi; - cc110x_packet_t packet; -} rx_buffer_t; - -enum radio_mode { - RADIO_MODE_GET = -1, /**< leave mode unchanged */ - RADIO_MODE_OFF = 0, /**< turn radio off */ - RADIO_MODE_ON = 1 /**< turn radio on */ -}; - -extern rx_buffer_t cc110x_rx_buffer[]; - -extern volatile uint8_t rx_buffer_next; /**< Next packet in RX queue */ - -extern volatile uint8_t radio_state; /**< Radio state */ -extern cc110x_statistic_t cc110x_statistic; - -void cc110x_init(kernel_pid_t transceiver_pid); - -void cc110x_rx_handler(void); - -int8_t cc110x_send(cc110x_packet_t *pkt); - -uint8_t cc110x_get_buffer_pos(void); - -void cc110x_setup_rx_mode(void); -void cc110x_switch_to_rx(void); -void cc110x_wakeup_from_rx(void); -void cc110x_switch_to_pwd(void); - -void cc110x_disable_interrupts(void); -int16_t cc110x_set_config_channel(uint8_t channr); -int16_t cc110x_set_channel(uint8_t channr); -int16_t cc110x_get_channel(void); - -radio_address_t cc110x_set_address(radio_address_t addr); -radio_address_t cc110x_set_config_address(radio_address_t addr); -radio_address_t cc110x_get_address(void); -void cc110x_set_monitor(uint8_t mode); - -void cc110x_print_config(void); - -/** - * @brief GDO0 interrupt handler. - */ -void cc110x_gdo0_irq(void); - -/** - * @brief GDO2 interrupt handler. - * - * @note Wakes up MCU on packet reception. - */ -void cc110x_gdo2_irq(void); - -#ifdef DBG_IGNORE -/** - * @brief Initialize ignore function - */ -void cc110x_init_ignore(void); - -/** - * @brief Adds a address to the ignore list - * - * @param addr The physical address to be ignored - * - * @return 0 if list is full, 1 otherwise - * - */ -uint8_t cc110x_add_ignored(radio_address_t addr); -#endif - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif /* CC110X_LEGACY_INTERFACE_H */ diff --git a/drivers/include/cc110x_legacy/cc110x-reg.h b/drivers/include/cc110x_legacy/cc110x-reg.h deleted file mode 100644 index 3b4b71557a..0000000000 --- a/drivers/include/cc110x_legacy/cc110x-reg.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2008 Freie Universität Berlin - * Copyright (C) 2013 INRIA - * - * 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 drivers_cc110x_legacy - * @{ - * - * @file - * @brief Access to CC110X registers - * - * @author Oliver Hahm - */ - -#ifndef CC110X_REG_H -#define CC110X_REG_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Write a set of bytes using burst mode (if available) - * - * @param addr Destination register - * @param buffer Data to be written - * @param count Size of data - * - * @return Written bytes - */ -uint8_t cc110x_writeburst_reg(uint8_t addr, char *buffer, uint8_t count); - -/** - * @brief Read a set of bytes using burst mode (if available) - * - * @param addr Source register - * @param buffer Buffer to store read data - * @param count Size of data to be read - */ -void cc110x_readburst_reg(uint8_t addr, char *buffer, uint8_t count); - -/** - * @brief Read bytes from RXFIFO - * - * @param buffer Buffer to store read data - * @param count Size of data to be read - * - * @note: Calls cc110x_readburst_reg if not dedicated fifo read command - * available - */ -void cc110x_read_fifo(char *buffer, uint8_t count); - -/** - * @brief Write one byte to a register - * - * @param addr Destinatoin register - * @param value New value - */ -void cc110x_write_reg(uint8_t addr, uint8_t value); - -/** - * @brief Read a byte from register - * - * @param addr Source register - * - * @return Read state and value of register - */ -uint8_t cc110x_read_reg(uint8_t addr); - -/** - * @brief Read state of a register - * - * @param addr Source register - * - * @return State of register - */ -uint8_t cc110x_read_status(uint8_t addr); - -/** - * @brief Sends a command strobe - * - * @param c Command code - * - * @return Command response - */ -uint8_t cc110x_strobe(uint8_t c); - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif /* CC110X_REG_H */ diff --git a/drivers/include/cc110x_legacy/cc110x_spi.h b/drivers/include/cc110x_legacy/cc110x_spi.h deleted file mode 100644 index 0163677d9c..0000000000 --- a/drivers/include/cc110x_legacy/cc110x_spi.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. - * - * 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 drivers_cc110x_legacy - * @{ - * - * @file - * @brief TI Chipcon CC1100 SPI driver - * - * @author Thomas Hillebrandt - * @author Heiko Will - */ - -#ifndef CC1100_SPI_H_ -#define CC1100_SPI_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -int cc110x_get_gdo0(void); -int cc110x_get_gdo1(void); -int cc110x_get_gdo2(void); - -void cc110x_spi_init(void); -void cc110x_spi_cs(void); -void cc110x_spi_select(void); -void cc110x_spi_unselect(void); - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif /* CC1100_SPI_H_ */ diff --git a/drivers/include/cc110x_legacy_csma.h b/drivers/include/cc110x_legacy_csma.h deleted file mode 100644 index a62066049e..0000000000 --- a/drivers/include/cc110x_legacy_csma.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2014 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. - */ - -#ifndef CC110X_LEGACY_CSMA_H -#define CC110X_LEGACY_CSMA_H - -#include "cc110x_legacy_csma/cc1100-interface.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* CC110X_LEGACY_CSMA_H */ diff --git a/drivers/include/cc110x_legacy_csma/cc1100-interface.h b/drivers/include/cc110x_legacy_csma/cc1100-interface.h deleted file mode 100644 index 979973d640..0000000000 --- a/drivers/include/cc110x_legacy_csma/cc1100-interface.h +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. - * - * 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 dev_cc110x_legacy_csma - * @{ - */ - -/** - * @file - * @brief TI Chipcon CC110x public interface - * - * @author Thomas Hillebrandt - * @version $Revision: 2283 $ - * - * @note $Id: cc1100-interface.h 2283 2010-06-15 14:02:27Z hillebra $ - */ - -#ifndef CC1100INTERFACE_H_ -#define CC1100INTERFACE_H_ - -#include -#include "radio/radio.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define CC1100_BROADCAST_ADDRESS (0x00) /**< CC1100 broadcast address */ - -#define MAX_UID (0xFF) /**< Maximum UID of a node is 255 */ -#define MIN_UID (0x01) /**< Minimum UID of a node is 1 */ - -#define MIN_CHANNR (0) /**< Minimum channel number */ -#define MAX_CHANNR (24) /**< Maximum channel number */ - -#define MIN_OUTPUT_POWER (0) /**< Minimum output power value */ -#define MAX_OUTPUT_POWER (11) /**< Maximum output power value */ - -#define CC1100_MODE_WOR (0) /**< Usable radio mode: Wake-On-Radio */ -#define CC1100_MODE_CONSTANT_RX (1) /**< Usable radio mode: Constant receive */ - -#define CC1100_MAX_DATA_LENGTH (58) - -/* Define default radio mode to constant RX if no application specific setting - * is available. */ -#ifndef CC1100_RADIO_MODE -#define CC1100_RADIO_MODE CC1100_MODE_CONSTANT_RX -#endif - - -/** - * @brief Initialize radio layer. - * - * Initialize the radio layer, must be called before radio can be used. - */ -void cc1100_init(void); - -/** - * @brief Get the radio mode. - * - * @return Either CC1100_MODE_CONSTANT_RX or CC1100_MODE_WOR. - */ -uint8_t cc1100_get_mode(void); - -/** - * @brief Set the radio mode. - * - * Sets the radio mode with optional mode data. If the radio mode is WOR, - * the optional mode data is the RX interval in milliseconds. Must be called - * only after CC1100 is initialized. - * - * @param mode New radio mode (one of the constants defined in this file). - * @param opt_mode_data Desired RX interval in milliseconds [50..60000]. - * - * @return true if mode could be applied; false otherwise (stays in previous mode). - */ -bool cc1100_set_mode(uint8_t mode, uint16_t opt_mode_data); - -/** - * @brief Get the average transmission duration (till ACK received). - * - * @return The average transmission duration of one packet in milliseconds. - */ -int cc1100_get_avg_transmission_duration(void); - -/** - * @brief Get the radio address. - * - * @return The current address of the radio. - */ -radio_address_t cc1100_get_address(void); - -/** - * @brief Set the radio address. - * - * @param address The new radio address. - * - * @return true if address could be set; false otherwise. - */ -bool cc1100_set_address(radio_address_t address); - -/** - * @brief Get the current channel number. - * - * @return The current channel number used. - */ -uint8_t cc1100_get_channel(void); - -/** - * @brief Set the channel to use. - * - * @param channr The new channel number (between MIN_CHANNR and MAX_CHANNR) to use. - * - * @return true if channel could be set; false otherwise. - */ -bool cc1100_set_channel(uint8_t channr); - -/** - * @brief Set current output power in dBm. - * - * @param pa_idx New output power setting, valid values - * are from MIN_OUTPUT_POWER (lowest output power, -52 dBm) - * to MAX_OUTPUT_POWER (highest output power, +10 dBm). - * - * @return true if output power could be set; false otherwise. - */ -bool cc1100_set_output_power(uint8_t pa_idx); - -/** - * @brief Set a packet monitor at this layer. - * - * All incoming packets will be passed to this packet monitor before - * packet gets processed by a specific handler. The work in the monitor - * should take as less time as possible (no waiting or intense I/O). - * - * @param monitor The packet monitor or NULL if the current packet - * monitor should be removed. - * - * @return true if this layer supports packet monitoring; false otherwise. - */ -bool cc1100_set_packet_monitor(packet_monitor_t monitor); - -/** - * @brief Set a packet handler for a given protocol. - * - * @param protocol The protocol identifier (3-bit value > 0, 1 reserved for LL-ACK). - * @param handler The packet handler called if a packet of given protocol is received. - * - * @return -1 if an error occurs (e.g. handler table full) else >= 0. - */ -int cc1100_set_packet_handler(protocol_t protocol, packet_handler_t handler); - -/** - * @brief Send data to given destination address with acknowledgment. - * - * The maximum payload length are 58 bytes! - * - * @param addr The destination address. - * @param protocol The protocol identifier of the transmitted data. - * @param priority Ignored (always highest). - * @param payload The data to be send. - * @param payload_len The length of the data in bytes. - * - * @return A negative value if operation failed; if operation succeeded (ACK received) the number of transmitted bytes. - */ -int cc1100_send(radio_address_t addr, protocol_t protocol, int priority, char *payload, radio_packet_length_t payload_len); - -/** - * @brief Send data to given destination address with acknowledgment and CSMA/CA. - * - * The maximum payload length are 58 bytes! - * - * @param address The destination address. - * @param protocol The protocol identifier of the transmitted data. - * @param priority The MAC priority to send with. One of {PRIORITY_ALARM, PRIORITY_WARNING, PRIORITY_DATA}. - * @param payload The data to be send. - * @param payload_len The length of the data in bytes. - * - * @return A negative value if operation failed; if operation succeeded (ACK received) else the number of transmitted bytes. - */ -int cc1100_send_csmaca(radio_address_t address, protocol_t protocol, int priority, char *payload, radio_packet_length_t payload_len); - -/** - * @brief Print current radio configuration. - */ -void cc1100_print_config(void); - -/** - * @brief Print radio statistics. - */ -void cc1100_print_statistic(void); - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif /* CC1100INTERFACE_H_ */ diff --git a/drivers/include/cc2420.h b/drivers/include/cc2420.h deleted file mode 100644 index bf78d5904f..0000000000 --- a/drivers/include/cc2420.h +++ /dev/null @@ -1,409 +0,0 @@ -/** - * cc2420.h - Definitions for CC2420 functions. - * Copyright (C) 2013 Milan Babel - * Copyright (C) 2014 Kévin Roussel - * - * 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 CC2420 - * @{ - * @file - * @brief Definitions for CC2420 functions - * @author Milan Babel - * - */ - -/** - * @brief Definition of the cc2420 layer 0 protocol - *
----------------------------------------------------------------------------
-|        |         |          |         |         |            |          |
-| Length |   FCF   |  Seq No. |Address  | PhySrc  |    Data    |    FCS   |
-|        |         |          |         |         |            |          |
----------------------------------------------------------------------------
- 1 byte    2 bytes     1 byte  2/8 bytes  2/8 bytes  <=118 bytes  2 bytes
-
-A 5 byte SHR will be generated and added in hardware.
-SHR contains a preable sequence and a start of delimiter,
-
-Length does not contain SHR and Length,
-first bit of length has to be 0 (length has only 7bit)
-
-Address fields can be in total between 4 and 20 bytes
-FCS contain a hardware generated CRC sum with the polynom x^16+x^12+x^5+1
-When receiving a package FCS will be checked by hardware, the first FCS byte will be replaced by RSSI,
-followed by a CRC OK bit and the unsigned 7 bit correlation value.
-FCF:
-        Bit | Meaning
-        --------------------
-        0-2 | Frame Type
-          3 | Security Enabled
-          4 | Frame Pending
-          5 | Acknowledge request
-          6 | PAN ID Compression Field
-        7-9 | Reserved
-      10-11 | Destination addressing mode
-      12-13 | Reserved
-      14-15 | Source addressing mode
-
-For the cc2420 bit 0 is the most right bit and bit 15 is the most left bit.
-But the 2 FCF bytes have to be transmitted littel endian (byte 15 to 8 first than 7 to 0)
-
-Addressing mode value:
-
-       Bit | Meaning
-       ---------------------
-        00 | PAN identifier and address field are not present.
-        01 | Reserved.
-        10 | Address field contains a 16 bit short address.
-        11 | Address field contains a 64 bit extended address.
-
-Frame type value:
-
-       Bit | Meaning
-       ---------------------
-       000 | Beacon
-       001 | Data
-       010 | Acknowledgment
-       011 | MAC command
-       1xx | Reserved
-  
- - * This corresponds to IEEE 802.15.4 frame format. - */ - -#ifndef CC2420_H -#define CC2420_H - -#include - -#include "kernel_types.h" -#include "ieee802154_frame.h" -#include "cc2420_settings.h" - -#include "radio_driver.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define CC2420_MAX_PKT_LENGTH 127 -#define CC2420_MAX_DATA_LENGTH (118) - -#define CC2420_BROADCAST_ADDRESS (0xFFFF) - -#define CC2420_MAX_UID (0xFFFE) -#define CC2420_MIN_UID (0x0000) - -/** - * Structure to represent a cc2420 packet. - */ -typedef struct __attribute__ ((packed)) { - /* @{ */ - uint8_t length; /** < the length of the frame of the frame including fcs*/ - ieee802154_frame_t frame; /** < the ieee802154 frame */ - int8_t rssi; /** < the rssi value */ - uint8_t lqi; /** < the link quality indicator */ - bool crc; /** < 1 if crc was successfull, 0 otherwise */ - /* @} */ -} cc2420_packet_t; - -/** - * @brief Initialize the CC2420 transceiver. - */ -void cc2420_initialize(void); - -/** - * @brief Init the CC2420 for use with RIOT's transceiver module. - * - * @param[in] tpid The PID of the transceiver thread. - */ - -void cc2420_init(kernel_pid_t tpid); - -/** - * @brief Turn CC2420 on. - * - * @return true if the radio was correctly turned on; false otherwise. - */ -bool cc2420_on(void); - -/** - * @brief Turn CC2420 off. - */ -void cc2420_off(void); - -/** - * @brief Indicate if the CC2420 is on. - * - * @return true if the radio transceiver is on (active); false otherwise. - */ -bool cc2420_is_on(void); - -/** - * @brief Switches the CC2420 into receive mode. - */ -void cc2420_switch_to_rx(void); - -/** - * @brief Turns monitor (promiscuous) mode on or off. - * - * @param[in] mode The desired mode: - * true for monitor (promiscuous) mode; - * false for normal (auto address-decoding) mode. - */ -void cc2420_set_monitor(bool mode); - -/** - * @brief Indicate if the CC2420 is in monitor (promiscuous) mode. - * - * @return true if the transceiver is in monitor (promiscuous) mode; - * false if it is in normal (auto address-decoding) mode. - */ -bool cc2420_get_monitor(void); - -/** - * @brief Set the channel of the CC2420. - * - * @param[in] chan The desired channel, valid channels are from 11 to 26. - * - * @return The tuned channel after calling, or -1 on error. - */ -int cc2420_set_channel(unsigned int chan); - -/** - * @brief Get the channel of the CC2420. - * - * @return The tuned channel. - */ -unsigned int cc2420_get_channel(void); - -/** - * @brief Sets the short address of the CC2420. - * - * @param[in] addr The desired address. - * - * @return The set address after calling. - */ -uint16_t cc2420_set_address(uint16_t addr); - -/** - * @brief Gets the current short address of the CC2420. - * - * @return The current short address. - */ -uint16_t cc2420_get_address(void); - -/** - * @brief Sets the IEEE long address of the CC2420. - * - * @param[in] addr The desired address. - * - * @return The set address after calling. - */ -uint64_t cc2420_set_address_long(uint64_t addr); - -/** - * @brief Gets the current IEEE long address of the CC2420. - * - * @return The current IEEE long address. - */ -uint64_t cc2420_get_address_long(void); - -/** - * @brief Sets the pan ID of the CC2420. - * - * @param[in] pan The desired pan ID. - * - * @return The set pan ID after calling. - */ -uint16_t cc2420_set_pan(uint16_t pan); - -/** - * @brief Gets the current IEEE long address of the CC2420. - * - * @return The current IEEE long address. - */ -uint16_t cc2420_get_pan(void); - -/** - * @brief Sets the output (TX) power of the CC2420. - * - * @param[in] pow The desired TX (output) power in dBm, - * valid values are -25 to 0; other values - * will be "saturated" into this range. - * - * @return The set TX (output) power after calling. - */ -int cc2420_set_tx_power(int pow); - -/** - * @brief Gets the current output (TX) power of the CC2420. - * - * @return The current TX (output) power. - */ -int cc2420_get_tx_power(void); - -/** - * @brief Checks if the radio medium is available/clear to send - * ("Clear Channel Assessment" a.k.a. CCA). - * - * @return a `true` value if radio medium is clear (available), - * a `false` value otherwise. - * - */ -bool cc2420_channel_clear(void); - -/** - * @brief Interrupt handler, gets fired when a RX overflow happens. - * - */ -void cc2420_rxoverflow_irq(void); - -/** - * @brief Interrupt handler, gets fired when bytes in the RX FIFO are present. - * - */ -void cc2420_rx_irq(void); - -/** - * @brief Sets the function called back when a packet is received. - * (Low-level mechanism, parallel to the `transceiver` module). - * - * @param[in] recv_cb callback function for 802.15.4 packet arrival; - * pass `NULL` to deactivate packet reception. - */ -void cc2420_set_recv_callback(receive_802154_packet_callback_t recv_cb); - -/** - * @brief RX handler, process data from the RX FIFO. - * - */ -void cc2420_rx_handler(void); - -/** - * @brief Prepare the CC2420 TX buffer to send with the given packet. - * - * @param[in] kind Kind of packet to transmit. - * @param[in] dest Address of the node to which the packet is sent. - * @param[in] use_long_addr `true` to use the 64-bit address mode - * with `dest` param; `false` to use - * "short" PAN-centric mode. - * @param[in] wants_ack `true` to request an acknowledgement - * from the receiving node for this packet; - * `false` otherwise. - * @param[in] buf Pointer to the buffer containing the payload - * of the 802.15.4 packet to transmit. - * The frame header (i.e.: FCS, sequence number, - * src and dest PAN and addresses) is inserted - * using values in accord with `kind` parameter - * and transceiver configuration. - * @param[in] len Length (in bytes) of the outgoing packet payload. - * - * @return `true` if the transceiver TX buffer was loaded correctly; - * `false` otherwise (transceiver error). - */ -radio_tx_status_t cc2420_load_tx_buf(ieee802154_packet_kind_t kind, - ieee802154_node_addr_t dest, - bool use_long_addr, - bool wants_ack, - void *buf, - unsigned int len); - -/** - * @brief Transmit the data loaded into the CC2420 TX buffer. - * - * @return The outcome of this packet's transmission. - * @see radio_tx_status_t - */ -radio_tx_status_t cc2420_transmit_tx_buf(void); - -/** - * @brief Transmit the given IEEE 802.15.4 packet, - * by calling successively functions`load_tx()` - * and `transmit()`. - * - * @param[in] kind Kind of packet to transmit. - * @param[in] dest Address of the node to which the packet is sent. - * @param[in] use_long_addr `true` to use the 64-bit address mode - * with `dest` param; `false` to use - * "short" PAN-centric mode. - * @param[in] wants_ack `true` to request an acknowledgement - * from the receiving node for this packet; - * `false` otherwise. - * @param[in] buf Pointer to the buffer containing the payload - * of the 802.15.4 packet to transmit. - * The frame header (i.e.: FCS, sequence number, - * src and dest PAN and addresses) is inserted - * using values in accord with `kind` parameter - * and transceiver configuration. - * @param[in] len Length (in bytes) of the outgoing packet payload. - * - * @return The outcome of this packet's transmission. - * @see radio_tx_status_t - */ -radio_tx_status_t cc2420_do_send(ieee802154_packet_kind_t kind, - ieee802154_node_addr_t dest, - bool use_long_addr, - bool wants_ack, - void *buf, - unsigned int len); - -/** - * @brief Send function, sends a cc2420_packet_t over the air. - * - * @param[in] *packet The Packet which will be send. - * - * @return The count of bytes which are send or -1 on error - * - */ -int16_t cc2420_send(cc2420_packet_t *packet); - -/* - * RX Packet Buffer, read from the transceiver, filled by the cc2420_rx_handler. - */ -extern cc2420_packet_t cc2420_rx_buffer[CC2420_RX_BUF_SIZE]; - - -/** Utility macro: get CC2420's status byte */ -#define cc2420_status_byte() cc2420_strobe(NOBYTE) - - -/* setter functions wrappers, to maintain compatibility with both - ieee802154_radio_driver_t and transceiver module */ - -static inline void do_set_channel(unsigned int chan) { - cc2420_set_channel(chan); -} - -static inline void do_set_address(uint16_t addr) { - cc2420_set_address(addr); -} - -static inline void do_set_long_address(uint64_t addr) { - cc2420_set_address_long(addr); -} - -static inline void do_set_pan_id(uint16_t pan) { - cc2420_set_pan(pan); -} - -static inline void do_set_tx_power(int pow) { - cc2420_set_tx_power(pow); -} - -/** - * CC2420 low-level radio driver definition. - */ -extern const ieee802154_radio_driver_t cc2420_radio_driver; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/drivers/include/netdev/802154.h b/drivers/include/netdev/802154.h deleted file mode 100644 index b69a37e170..0000000000 --- a/drivers/include/netdev/802154.h +++ /dev/null @@ -1,431 +0,0 @@ -/* - * Copyright (C) 2014 INRIA - * - * 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. - */ - -/** - * @defgroup netdev_802154 Network device interface for IEEE 802.15.4 transceivers - * @ingroup netdev - * @brief Network device driver API for IEEE 802.15.4 radio transceivers - * - * @{ - * @file - * @brief API definitions for 802.15.4 radio transceivers' drivers - * @author Kévin Roussel - * @author Martine Lenders - * - */ - -#ifndef NETDEV_802154_H_ -#define NETDEV_802154_H_ - -#include - -#include "netdev/base.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Callback function type for receiving incoming packets - * from 802.15.4 radio transceiver. - * - * @param[in] buf Pointer to the buffer containing the incoming - * 802.15.4 packet's raw data. - * @param[in] len Length (in bytes) of the incoming packet's raw data. - * @param[in] rssi Value of the Receive Signal Strength Indicator (RSSI) - * for the incoming packet. - * @param[in] lqi Value of the Link Quality Indicator (LQI) - * for the incoming packet. - * @param[in] crc_ok 1 if incoming packet's checksum (CRC) is valid; - * 0 otherwise (corrupted packet). - */ -typedef void (* netdev_802154_raw_packet_cb_t)(netdev_t *dev, - void *buf, - size_t len, - int8_t rssi, - uint8_t lqi, - int crc_ok); - -/** - * @brief Kind of packet to prepare/configure for transmission. - * - */ -typedef enum { - /** Beacon packet */ - NETDEV_802154_PKT_KIND_BEACON, - - /** Standard data packet */ - NETDEV_802154_PKT_KIND_DATA, - - /** Acknowledgement packet */ - NETDEV_802154_PKT_KIND_ACK, - - /** MAC command */ - NETDEV_802154_PKT_KIND_MAC_CMD, - - /** invalid packet kind */ - NETDEV_802154_PKT_KIND_INVALID = -1 - -} netdev_802154_pkt_kind_t; - -/** - * @brief Return values for packet emission function of 802.15.4 radio driver. - * - */ -typedef enum { - /** Transmission completed successfully */ - NETDEV_802154_TX_STATUS_OK, - - /** Device not found or not an IEEE 802.15.4 device */ - NETDEV_802154_TX_STATUS_NO_DEV, - - /** Transmission buffer underflow (forgot to call netdev_802154_driver_t::load_tx() - before netdev_802154_driver_t::transmit() ) */ - NETDEV_802154_TX_STATUS_UNDERFLOW, - - /** Transmission cannot start because radio medium is already busy */ - NETDEV_802154_TX_STATUS_MEDIUM_BUSY, - - /** Transmission failed because of collision on radio medium */ - NETDEV_802154_TX_STATUS_COLLISION, - - /** Wrong parameter given to TX-related functions */ - NETDEV_802154_TX_STATUS_INVALID_PARAM, - - /** Too much given data to be included in a single packet */ - NETDEV_802154_TX_STATUS_PACKET_TOO_LONG, - - /** Transmission supposedly failed since no ACK packet - has been received as response */ - NETDEV_802154_TX_STATUS_NOACK, - - /** Transmission failed because of an unexpected (fatal?) error */ - NETDEV_802154_TX_STATUS_ERROR, - -} netdev_802154_tx_status_t; - -/** - * @brief Definition of an IEEE 802.15.4 node address. - * - * @details The `union` allows to choose between PAN-centric addressing - * ("volatile" 16-bit address and 16-bit PAN ID), or canonical - * IEEE 64-bit ("long") addressing. - * - */ -typedef union { - /** @brief PAN-centric ("short") addressing mode */ - struct { - /** @brief Address assigned to the node within its current PAN */ - uint16_t addr; - /** @brief ID of the PAN to which the node is currently associated */ - uint16_t id; - } pan; - /** @brief 64-bit ("long") addressing mode */ - uint64_t long_addr; -} netdev_802154_node_addr_t; - -/** - * @brief IEEE 802.15.4 radio driver API definition. - * - * @details This is the set of functions that must be implemented - * by any driver for a 802.15.4 radio transceiver. - * - * @extends netdev_driver_t - */ -typedef struct { - /** - * @see netdev_driver_t::init - */ - int (*init)(netdev_t *dev); - - /** - * @details wraps netdev_802154_driver_t::send with - * - * @see netdev_driver_t::send_data - */ - int (*send_data)(netdev_t *dev, void *dest, size_t dest_len, - netdev_hlist_t *upper_layer_hdrs, void *data, - size_t data_len); - - /** - * @see netdev_driver_t::add_receive_data_callback - */ - int (*add_receive_data_callback)(netdev_t *dev, netdev_rcv_data_cb_t cb); - - /** - * @see netdev_driver_t::rem_receive_data_callback - */ - int (*rem_receive_data_callback)(netdev_t *dev, netdev_rcv_data_cb_t cb); - - /** - * @see netdev_driver_t::get_option - * - * @details The options are constrained as follows: - * - * *opt* | type | *value_len* - * --------------------------- | ----------- | ----------- - * NETDEV_OPT_CHANNEL | uint8_t | >= 1 - * NETDEV_OPT_ADDRESS | uint16_t | >= 2 - * NETDEV_OPT_NID | uint16_t | >= 2 - * NETDEV_OPT_ADDRESS_LONG | uint64_t | >= 8 - * NETDEV_OPT_TX_POWER | int | >= 4 - * NETDEV_OPT_MAX_PACKET_SIZE | uint8_t | >= 1 - */ - int (*get_option)(netdev_t *dev, netdev_opt_t opt, void *value, - size_t *value_len); - - /** - * @see netdev_driver_t::set_option - * - * @details The options are constrained as follows: - * - * *opt* | type | *value_len* | *value* - * --------------------------- | ----------- | ----------- | -------- - * NETDEV_OPT_CHANNEL | uint8_t | >= 1 | <= 26 - * NETDEV_OPT_ADDRESS | uint16_t | >= 2 | - * NETDEV_OPT_NID | uint16_t | >= 2 | - * NETDEV_OPT_ADDRESS_LONG | uint64_t | >= 8 | - * NETDEV_OPT_TX_POWER | int | >= 4 | - * - * NETDEV_OPT_MAX_PACKET_SIZE can not be set. - */ - int (*set_option)(netdev_t *dev, netdev_opt_t opt, void *value, - size_t value_len); - - /** - * @see netdev_driver_t::get_state - */ - int (*get_state)(netdev_t *dev, netdev_state_t *state); - - /** - * @see netdev_driver_t::set_state - */ - int (*set_state)(netdev_t *dev, netdev_state_t state); - - /** - * @see netdev_driver_t::event - */ - void (*event)(netdev_t *dev, uint32_t event_type); - - /** - * @brief Load the transceiver TX buffer with the given - * IEEE 802.15.4 packet. - * - * @param[in] dev the network device - * @param[in] kind Kind of packet to transmit. - * @param[in] dest Address of the node to which the packet is sent. - * @param[in] use_long_addr 1 to use the 64-bit address mode - * with *dest* param; 0 to use - * "short" PAN-centric mode. - * @param[in] wants_ack 1 to request an acknowledgement - * from the receiving node for this packet; - * 0 otherwise. - * @param[in] upper_layer_hdrs header data from higher network layers from - * highest to lowest layer. Must be prepended to - * the data stream by the network device. May be - * NULL if there are none. - * @param[in] buf Pointer to the buffer containing the payload - * of the 802.15.4 packet to transmit. - * The frame header (i.e.: FCS, sequence number, - * src and dest PAN and addresses) is inserted - * using values in accord with *kind* parameter - * and transceiver configuration. - * @param[in] len Length (in bytes) of the outgoing packet payload. - * - * @return The outcome of this packet's transmission. - * @see netdev_802154_tx_status_t - */ - netdev_802154_tx_status_t (* load_tx)(netdev_t *dev, - netdev_802154_pkt_kind_t kind, - netdev_802154_node_addr_t *dest, - int use_long_addr, - int wants_ack, - netdev_hlist_t *upper_layer_hdrs, - void *buf, - unsigned int len); - - /** - * @brief Transmit the data loaded into the transceiver TX buffer. - * - * @param[in] dev the network device - * - * @return The outcome of this packet's transmission. - * @see netdev_802154_tx_status_t - */ - netdev_802154_tx_status_t (* transmit)(netdev_t *dev); - - /** - * @brief Transmit the given IEEE 802.15.4 packet, - * by calling successively functions netdev_802154_driver_t::load_tx() - * and netdev_802154_driver_t::transmit(). - * - * @param[in] dev the network device - * @param[in] kind Kind of packet to transmit. - * @param[in] dest Address of the node to which the packet is sent. - * @param[in] use_long_addr 1 to use the 64-bit address mode - * with *dest* param; 0 to use - * "short" PAN-centric mode. - * @param[in] wants_ack 1 to request an acknowledgement - * from the receiving node for this packet; - * 0 otherwise. - * @param[in] upper_layer_hdrs header data from higher network layers from - * highest to lowest layer. Must be prepended to - * the data stream by the network device. May be - * NULL if there are none. - * @param[in] buf Pointer to the buffer containing the payload - * of the 802.15.4 packet to transmit. - * The frame header (i.e.: FCS, sequence number, - * src and dest PAN and addresses) is inserted - * using values in accord with *kind* parameter - * and transceiver configuration. - * @param[in] len Length (in bytes) of the outgoing packet payload. - * - * @return The outcome of this packet's transmission. - * @see netdev_802154_tx_status_t - */ - netdev_802154_tx_status_t (* send)(netdev_t *dev, - netdev_802154_pkt_kind_t kind, - netdev_802154_node_addr_t *dest, - int use_long_addr, - int wants_ack, - netdev_hlist_t *upper_layer_hdrs, - void *buf, - unsigned int len); - - /** - * @brief Add a function to be called back when the radio transceiver - * has received a incoming packet. - * - * @details This function differentiates from - * netdev_driver_t::add_receive_data_callback() as it expects - * a callback that excepts the raw frame format of IEEE 802.15.4, - * rather than just the source and destination addresses and the - * payload. - * - * @param[in] dev the network device - * @param[in] recv_func the callback function to invoke for each - * packet received by the radio transceiver. - * @see netdev_802153_raw_packet_cb_t - * - * @return 0, on success - * @return -ENOBUFS, if maximum number of registrable callbacks is exceeded - * @return -ENODEV, if *dev* is not recognized - */ - int (* add_receive_raw_callback)(netdev_t *dev, netdev_802154_raw_packet_cb_t recv_func); - - /** - * @brief Remove a callback set by netdev_802154_driver_t::add_receive_raw_callback() - * - * @param[in] dev the network device - * @param[in] recv_func the callback function to invoke for each - * packet received by the radio transceiver. - * @see netdev_802153_raw_packet_cb_t - * - * @return 0, on success - * @return -ENODEV, if *dev* is not recognized - */ - int (* rem_receive_raw_callback)(netdev_t *dev, netdev_802154_raw_packet_cb_t recv_func); - - /** - * @brief Indicates if the radio medium is available for transmission - * ("Clear Channel Assessment"). - * - * @param[in] dev the network device - * - * @return 1 if radio medium is "clear" (available); - * @return 0 if another transmission is already running. - * @return -ENODEV, if *dev* is not recognized - */ - int (* channel_is_clear)(netdev_t *dev); -} netdev_802154_driver_t; - -/* define to implement yourself and omit compilation of this function */ -#ifndef NETDEV_802154_SEND_DATA_OVERLOAD -/** - * @brief wraps netdev_802154_driver_t::send(), default value for - * netdev_802154_driver_t::send_data(). - * - * @param[in] dev the network device - * @param[in] dest the (hardware) destination address for the data - * in host byte order. - * @param[in] dest_len the length of *dest* in byte - * @param[in] upper_layer_hdrs header data from higher network layers from - * highest to lowest layer. Must be prepended to - * the data stream by the network device. May be - * NULL if there are none. - * @param[in] data the data to send - * @param[in] data_len the length of *data* in byte - * - * @return the number of byte actually (data_len + total length of upper layer - * headers) send on success - * @return -EAFNOSUPPORT if address of length dest_len is not supported - * by the device *dev* - * @return -EBUSY if transmission cannot start because radio medium is already - * busy or collision on radio medium occured. - * @return -EINVAL if wrong parameter was given - * @return -ENODEV if *dev* is not recognized as IEEE 802.15.4 device - * @return -EMSGSIZE if the total frame size is too long to fit in a frame - * of the device *dev* - * @return -EIO if any other occured (netdev_802154_driver_t::send() returned - * NETDEV_802154_TX_STATUS_ERROR) - */ -int netdev_802154_send_data(netdev_t *dev, void *dest, size_t dest_len, - netdev_hlist_t *upper_layer_hdrs, void *data, - size_t data_len); -#endif /* NETDEV_802154_SEND_DATA_OVERLOAD */ - -/* define to implement yourself and omit compilation of this function */ -#ifndef NETDEV_802154_SEND_OVERLOAD -/** - * @brief Transmit the given IEEE 802.15.4 packet, by calling - * functions netdev_802154_driver_t::load_tx() and - * netdev_802154_driver_t::transmit() successfully. Default value for - * netdev_802154_driver_t::send() - * - * @param[in] dev the network device - * @param[in] kind Kind of packet to transmit. - * @param[in] dest Address of the node to which the packet is sent. - * @param[in] use_long_addr 1 to use the 64-bit address mode - * with *dest* param; 0 to use - * "short" PAN-centric mode. - * @param[in] wants_ack 1 to request an acknowledgement - * from the receiving node for this packet; - * 0 otherwise. - * @param[in] upper_layer_hdrs header data from higher network layers from - * highest to lowest layer. Must be prepended to - * the data stream by the network device. May be - * NULL if there are none. - * @param[in] buf Pointer to the buffer containing the payload - * of the 802.15.4 packet to transmit. - * The frame header (i.e.: FCS, sequence number, - * src and dest PAN and addresses) is inserted - * using values in accord with *kind* parameter - * and transceiver configuration. - * @param[in] len Length (in bytes) of the outgoing packet payload. - * - * @return @ref netdev_802154_tx_status_t - */ -netdev_802154_tx_status_t netdev_802154_send(netdev_t *dev, - netdev_802154_pkt_kind_t kind, - netdev_802154_node_addr_t *dest, - int use_long_addr, - int wants_ack, - netdev_hlist_t *upper_layer_hdrs, - void *buf, - unsigned int len); -#endif /* NETDEV_802154_SEND_OVERLOAD */ - -#ifdef __cplusplus -} -#endif - -#endif /* NETDEV_802154_H_ */ - -/** - * @} - */ diff --git a/drivers/include/netdev/base.h b/drivers/include/netdev/base.h deleted file mode 100644 index a1868c8071..0000000000 --- a/drivers/include/netdev/base.h +++ /dev/null @@ -1,408 +0,0 @@ -/* - * Copyright (C) 2014 Martine Lenders - * - * 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. - */ - -/** - * @addtogroup netdev - * @{ - * - * @file - * @brief Basic network device driver interface definitions. - * - * @author Martine Lenders - */ - -#ifndef NETDEV_BASE_H_ -#define NETDEV_BASE_H_ - -#include -#include -#include - -#include "clist.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Type for @ref msg_t if device fired an event. - */ -#define NETDEV_MSG_EVENT_TYPE (0x0100) - -/** - * @brief Definition of device families. - */ -typedef enum { - NETDEV_TYPE_UNKNOWN = 0, /**< Type was not specified and may not - understand this API */ - NETDEV_TYPE_BASE, /**< Device understands this API */ - NETDEV_TYPE_802154, /**< Device understands this API and the API - defined in @ref netdev_802154 */ -} netdev_type_t; - -/** - * @brief Definition of protocol families to determine which frame types a - * device or protocol layer (see @ref netapi) can handle - * - * @note XXX: The concrete definition of the values is necessary to work - * with super-flexible devices as e.g. @ref native_net. It was also - * decided not to use ethertype since protocols not supplied by it - * might be supported - */ -typedef enum { - NETDEV_PROTO_UNKNOWN = 0x0000, /**< Type was not specified */ - - /** - * @brief Radio frame protocol - * - * @details Sends frames as defined by radio_packet_t. - */ - NETDEV_PROTO_RADIO = 0x0001, - - /** - * @brief IEEE 802.15.4 - * - * @details Sends frames as defined by ieee802154_frame_t - */ - NETDEV_PROTO_802154 = 0x0002, - NETDEV_PROTO_6LOWPAN = 0x0003, /**< 6LoWPAN. */ - NETDEV_PROTO_IPV6 = 0x0004, /**< IPv6. */ - NETDEV_PROTO_UDP = 0x0005, /**< UDP. */ - NETDEV_PROTO_TCP = 0x0006, /**< TCP. */ - NETDEV_PROTO_CCNL = 0x0007, /**< CCN lite. */ - - /** - * @brief CC110x frame format protocol - * - * @detail Sends frames as defined by cc110x_packet_t. - */ - NETDEV_PROTO_CC110X = 0x0008, -} netdev_proto_t; - -/** - * @brief Definition of basic network device options. - * @note Feel free to expand if your device needs/supports more. - */ -typedef enum { - /** - * @brief Communication type for the device as defined by @ref netdev_proto_t - * - * @details If a driver does not support the type (but the setting of the - * option is supported) it @ref netdev_driver_t::set_option() shall result - * with -EPROTONOSUPPORT. - * - * *value_len* for @ref netdev_driver_t::get_option() must always be at - * least `sizeof(netdev_proto_t)`. - */ - NETDEV_OPT_PROTO = 0, - NETDEV_OPT_CHANNEL, /**< Channel for the device as unsigned value - in host byte order */ - NETDEV_OPT_ADDRESS, /**< Hardware address for the device as - unsigned value in host byte order */ - NETDEV_OPT_NID, /**< Network ID (e.g. PAN ID in IEEE 802.15.4) - for the device as unsigned value in - host byte order */ - NETDEV_OPT_ADDRESS_LONG, /**< Longer hardware address for the device - (e.g. EUI-64) for the device as - unsigned value in host byte order */ - NETDEV_OPT_TX_POWER, /**< The output of the device in dB as - signed value in host byte order */ - NETDEV_OPT_MAX_PACKET_SIZE, /**< Maximum packet size the device supports - unsigned value in host byte order */ - NETDEV_OPT_SRC_LEN, /**< Default mode the source address is - set to as value of `size_t`. (e.g. - either PAN-centric 16-bit address or - EUI-64 in IEEE 802.15.4) */ - - /** - * @brief Last value for @ref netdev_opt_t defined here - * - * @details Specific devices or modules like @ref netapi that utilize these - * values to may define higher values, but they must be greater - * or equal to @ref NETDEV_OPT_LAST. - */ - NETDEV_OPT_LAST, -} netdev_opt_t; - -/** - * @brief Definition of basic network device. - * @note Feel free to expand if your device needs/supports more - */ -typedef enum { - NETDEV_STATE_POWER_OFF = 0, /**< Device is powered off */ - NETDEV_STATE_POWER_SLEEP, /**< Device is sleeping */ - NETDEV_STATE_POWER_IDLE, /**< Device is idle */ - NETDEV_STATE_RX_MODE, /**< Device is in receive mode */ - NETDEV_STATE_PROMISCUOUS_MODE, /**< Device is in receive mode and - accepts all packets without regard - for their destination */ - NETDEV_STATE_TX_BURST, /**< Device is burst sending and - does not accept packets */ -} netdev_state_t; - -/** - * @brief Circular list type to store a number of protocol headers of - * unspecified type to work with @ref clist.h. - * - * @extends clist_node_t - */ -typedef struct __attribute__((packed)) netdev_hlist_t { - struct netdev_hlist_t *next; /**< next element in list */ - struct netdev_hlist_t *prev; /**< previous element in list */ - netdev_proto_t protocol; /**< protocol of the header */ - void *header; /**< the header stored in here */ - size_t header_len; /**< the length of the header in byte */ -} netdev_hlist_t; - -/** - * @brief Definition of the network device type - * - * @see struct netdev_t - * - * @note Forward definition to use in @ref netdev_driver_t - */ -typedef struct netdev_t netdev_t; - -/** - * Receive data callback for data frames from given network device. - * - * @param[in] dev the network device the frame came from. - * @param[in] src the (hardware) source address of the frame in host - * byte order. - * @param[in] src_len the length of *src* in byte - * @param[in] dest the (hardware) destination address of the frame in - * host byte order. - * @param[in] dest_len the length of *dest* in byte - * @param[in] payload the payload of the frame. - * @param[in] payload_len the length of *payload* in byte - * - * @return the number of bytes in payload actually processed by the callback, - * on success - * @return a fitting negative errno on failure - */ -typedef int (*netdev_rcv_data_cb_t)(netdev_t *dev, void *src, size_t src_len, - void *dest, size_t dest_len, void *payload, - size_t payload_len); - -/** - * @brief Network device API definition. - * - * @details This is a set of functions that must be implemented by any driver - * for a network device. - */ -typedef struct { - /** - * @brief Initialize a given network device. - * - * @param[in] dev the device to initialize - * - * @return 0 on success - * @return -ENODEV if *dev* can not be initialized - */ - int (*init)(netdev_t *dev); - - /** - * @brief Send data via a given network device - * - * @param[in] dev the network device - * @param[in] dest the (hardware) destination address for the data - * in host byte order. - * @param[in] dest_len the length of *dest* in byte - * @param[in] upper_layer_hdrs header data from higher network layers from - * highest to lowest layer. Must be prepended to - * the data stream by the network device. May be - * NULL if there are none. - * @param[in] data the data to send - * @param[in] data_len the length of *data* in byte - * - * @return the number of byte actually send on success - * @return -EAFNOSUPPORT if address of length dest_len is not supported - * by the device *dev* - * @return -ENODEV if *dev* is not recognized - * @return -EMSGSIZE if the total frame size is too long to fit in a frame - * of the device *dev* - * @return a fitting negative other errno on other failure - */ - int (*send_data)(netdev_t *dev, void *dest, size_t dest_len, - netdev_hlist_t *upper_layer_hdrs, void *data, - size_t data_len); - - /** - * @brief Registers a receive data callback to a given network device. - * - * @param[in] dev the network device. - * @param[in] cb the callback. - * - * @return 0, on success - * @return -ENODEV, if *dev* is not recognized - * @return -ENOBUFS, if maximum number of registrable callbacks is exceeded - */ - int (*add_receive_data_callback)(netdev_t *dev, netdev_rcv_data_cb_t cb); - - /** - * @brief Unregisters a receive data callback to a given network device. - * - * @param[in] dev the network device. - * @param[in] cb the callback. - * - * @return 0, on success - * @return -ENODEV, if *dev* is not recognized - */ - int (*rem_receive_data_callback)(netdev_t *dev, netdev_rcv_data_cb_t cb); - - /** - * @brief Get an option value from a given network device. - * - * @param[in] dev the network device - * @param[in] opt the option type - * @param[out] value pointer to store the gotten value in - * @param[in,out] value_len the length of *value*. Must be initialized to the - * available space in *value* on call. - * @return 0, on success - * @return -ENODEV, if *dev* is not recognized - * @return -ENOTSUP, if *opt* is not supported for the device with this - * operation - * @return -EOVERFLOW, if available space in *value* given in *value_len* - * is not big enough to store the option value. - * @return any other fitting negative errno if the ones stated above - * are not sufficient - */ - int (*get_option)(netdev_t *dev, netdev_opt_t opt, void *value, - size_t *value_len); - - /** - * @brief Set an option value for a given network device. - * - * @param[in] dev the network device - * @param[in] opt the option type - * @param[in] value the value to set - * @param[in] value_len the length of *value* - * - * @return 0, on success - * @return -EINVAL, if *value* is not in a required format - * @return -ENODEV, if *dev* is not recognized - * @return -ENOTSUP, if *opt* is not supported for the device with this - * operation - * @return -EOVERFLOW, if *value_len* is larger then the device expects. - * @return -EPROTONOSUPPORT, if *opt* was NETDEV_OPT_PROTO and type is - * not supported. - * @return any other fitting negative errno if the ones stated above - * are not sufficient - */ - int (*set_option)(netdev_t *dev, netdev_opt_t opt, void *value, - size_t value_len); - - /** - * @brief Get state from a given network device. - * - * @param[in] dev the network device - * @param[out] state the network device - * - * @return 0, on success - * @return -ENODEV, if *dev* is not recognized - * @return -ETIME, if device timed out on trying to acquire state - */ - int (*get_state)(netdev_t *dev, netdev_state_t *state); - - /** - * @brief Set state from a given network device. - * - * @param[in] dev the network device - * @param[in] state the network device - * - * @return 0, on success - * @return -ENODEV, if *dev* is not recognized - * @return -ENOTSUP, if *state* is not supported - * @return -ETIME, if device timed out on trying to change state - */ - int (*set_state)(netdev_t *dev, netdev_state_t state); - - /** - * @brief Must be called by a controlling thread if a message of type - * NETDEV_MSG_EVENT_TYPE was received - * - * @param[in] dev the network device that fired the event. - * @param[in] event_type Event type. Values are free to choose for the - * driver. Must be given in the @ref msg_t::value - * of the received message - */ - void (*event)(netdev_t *dev, uint32_t event_type); -} netdev_driver_t; - -/** - * @brief Definition of the network device type - * - * @note Your driver may overload this with additional information (e.g. - * how the device is connected) - */ -struct netdev_t { - netdev_type_t type; /**< The type of this device */ - const netdev_driver_t *driver; /**< The driver for this device */ - void *more; /**< Pointer to device dependent - additional information. E.g. the - low-level device(s) to - communiticate with this device. */ -}; - -/** - * @brief Helper function to calculate the total length of the headers in - * *hlist*. - * - * @param[in] hlist The header list. - * - * @return Length in number of bytes of all headers in *hlist*. - */ -size_t netdev_get_hlist_len(const netdev_hlist_t *hlist); - -/** - * @brief Advance the header list - * - * @see clist_advance - * - * @param[in,out] list The list to work upon. - */ -static inline void netdev_hlist_advance(netdev_hlist_t **list) -{ - clist_advance((clist_node_t **)list); -} - -/** - * @brief Add *node* to list start of *list* - * - * @param[in,out] list The list to add *node* to - * @param[in] node The node to add to the list - */ -static inline void netdev_hlist_add(netdev_hlist_t **list, - netdev_hlist_t *node) -{ - clist_add((clist_node_t **)list, (clist_node_t *)node); - *list = node; -} - -/** - * @brief Removes *node* from list *list* - * - * @see clist_remove - * - * @param[in,out] list The list to remove *node* from - * @param[in] node The node to remove from the list - */ -static inline void netdev_hlist_remove(netdev_hlist_t **list, - netdev_hlist_t *node) -{ - clist_remove((clist_node_t **)list, (clist_node_t *)node); -} - -#ifdef __cplusplus -} -#endif - -#endif /* NETDEV_BASE_H_ */ -/** - * @} - */ diff --git a/drivers/include/netdev/default.h b/drivers/include/netdev/default.h deleted file mode 100644 index 0916973f2d..0000000000 --- a/drivers/include/netdev/default.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2014 Martine Lenders - * - * 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. - */ - -/** - * @addtogroup netdev - * @{ - * - * @file - * @brief Supplies the users with default values for the use of - * @ref netdev - * - * @author Martine Lenders - */ - -#ifndef NETDEV_DEFAULT_H_ -#define NETDEV_DEFAULT_H_ - -#include "netdev/base.h" - -#ifdef DOXYGEN -/** - * @brief Default device as a pointer of netdev_t. - */ -#define NETDEV_DEFAULT -#endif - -#ifdef MODULE_AT86RF231 -#include "at86rf231.h" - -#ifndef NETDEV_DEFAULT -#define NETDEV_DEFAULT ((netdev_t *)(&at86rf231_netdev)) -#endif /* NETDEV_DEFAULT */ -#endif /* MODULE_AT86RF231 */ - -#ifdef MODULE_CC110X -#include "cc110x.h" - -#ifndef NETDEV_DEFAULT -#define NETDEV_DEFAULT ((netdev_t *)(&cc110x_dev)) -#endif /* NETDEV_DEFAULT */ -#endif /* MODULE_CC110X */ - -#ifdef MODULE_NATIVENET -#include "nativenet.h" - -#ifndef NETDEV_DEFAULT -#define NETDEV_DEFAULT (&nativenet_default_dev) -#endif /* NETDEV_DEFAULT */ -#endif /* MODULE_NATIVENET */ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* NETDEV_DEFAULT_H_ */ -/** @} */ diff --git a/drivers/include/netdev/doc.txt b/drivers/include/netdev/doc.txt deleted file mode 100644 index 6780804300..0000000000 --- a/drivers/include/netdev/doc.txt +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (C) 2014 Freie Universität Berlin - * - * This file is subject to the terms and conditions of the LGPLv2 License. - * See the file LICENSE in the top level directory for more details. - */ - -/** - * @defgroup netdev Network device interface - * @ingroup drivers - * @brief Network device drivers - * - * The module the network device drivers. It consists of a set of device - * independent interface definitions and specific implementations for every - * device. - */ diff --git a/drivers/include/radio_driver.h b/drivers/include/radio_driver.h deleted file mode 100644 index c8e05bc10b..0000000000 --- a/drivers/include/radio_driver.h +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Copyright (C) 2014 INRIA - * - * 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. - */ - -/** - * @defgroup radio_driver IEEE 802.15.4 radio driver interface - * @ingroup drivers - * - * @brief API definitions for 802.15.4 radio transceivers' drivers - * - * @deprecated THIS INTERFACE IS DEPRECATED. PLEASE USE netdev/802154.h - * - * @{ - * @file - * @author Kévin Roussel - * - */ - -#ifndef IEEE802154_RADIO_DRIVER_API_ -#define IEEE802154_RADIO_DRIVER_API_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Callback function type for receiving incoming packets - * from 802.15.4 radio transceiver. - * - * @param[in] buf Pointer to the buffer containing the incoming - * 802.15.4 packet's raw data. - * @param[in] len Length (in bytes) of the incoming packet's raw data. - * @param[in] rssi Value of the Receive Signal Strength Indicator (RSSI) - * for the incoming packet. - * @param[in] lqi Value of the Link Quality Indicator (LQI) - * for the incoming packet. - * @param[in] crc_ok @c true if incoming packet's checksum (CRC) is valid; - * @c false otherwise (corrupted packet). - */ -typedef void (* receive_802154_packet_callback_t)(void *buf, - unsigned int len, - int8_t rssi, - uint8_t lqi, - bool crc_ok); - -/** - * @brief Kind of packet to prepare/configure for transmission. - * - */ -typedef enum { - /** Beacon packet */ - PACKET_KIND_BEACON, - - /** Standard data packet */ - PACKET_KIND_DATA, - - /** Acknowledgement packet */ - PACKET_KIND_ACK, - - /** MAC command */ - PACKET_KIND_MAC_CMD, - - /** invalid packet kind */ - PACKET_KIND_INVALID = -1 - -} ieee802154_packet_kind_t; - -/** - * @brief Return values for packet emission function of 802.15.4 radio driver. - * - */ -typedef enum { - /** Transmission completed successfully */ - RADIO_TX_OK, - - /** Transmission buffer underflow (forgot to call @c load_tx() - before @c transmit() ) */ - RADIO_TX_UNDERFLOW, - - /** Transmission cannot start because radio medium is already busy */ - RADIO_TX_MEDIUM_BUSY, - - /** Transmission failed because of collision on radio medium */ - RADIO_TX_COLLISION, - - /** Wrong parameter given to TX-related functions */ - RADIO_TX_INVALID_PARAM, - - /** Too much given data to be included in a single packet */ - RADIO_TX_PACKET_TOO_LONG, - - /** Transmission supposedly failed since no ACK packet - has been received as response */ - RADIO_TX_NOACK, - - /** Transmission failed because of an unexpected (fatal?) error */ - RADIO_TX_ERROR, - -} radio_tx_status_t; - - -/** - * @brief Definition of an IEEE 802.15.4 node address. - * - * @details The @c union allows to choose between PAN-centric addressing - * ("volatile" 16-bit address and 16-bit PAN ID), or canonical - * IEEE 64-bit ("long") addressing. - * - */ -typedef union { - /** @brief PAN-centric ("short") addressing mode */ - struct { - /** @brief Address assigned to the node within its current PAN */ - uint16_t addr; - /** @brief ID of the PAN to which the node is currently associated */ - uint16_t id; - } pan; - /** @brief 64-bit ("long") addressing mode */ - uint64_t long_addr; -} ieee802154_node_addr_t; - - -/** - * @brief IEEE 802.15.4 radio driver API definition. - * - * @details This is the set of functions that must be implemented - * by any driver for a 802.15.4 radio transceiver. - * - */ -typedef struct { - /** - * @brief Initialize the radio transceiver (call before first use). - */ - void (* init)(void); - - /** - * @brief Turn radio transceiver on. - * - * @return @c true if radio transceiver was actually started; - * @c false if an error prevented transceiver to start. - */ - bool (* on)(void); - - /** - * @brief Turn radio transceiver off. - */ - void (* off)(void); - - /** - * @brief Indicate whether the radio transceiver is up and running. - * - * @return @c true if radio transceiver is on; - * @c false if it is off. - */ - bool (* is_on)(void); - - /** - * @brief Load the tranceiver TX buffer with the given - * IEEE 802.15.4 packet. - * - * @param[in] kind Kind of packet to transmit. - * @param[in] dest Address of the node to which the packet is sent. - * @param[in] use_long_addr @c true to use the 64-bit address mode - * with @c dest param; @c false to use - * "short" PAN-centric mode. - * @param[in] wants_ack @c true to request an acknowledgement - * from the receiving node for this packet; - * @c false otherwise. - * @param[in] buf Pointer to the buffer containing the payload - * of the 802.15.4 packet to transmit. - * The frame header (i.e.: FCS, sequence number, - * src and dest PAN and addresses) is inserted - * using values in accord with @c kind parameter - * and transceiver configuration. - * @param[in] len Length (in bytes) of the outgoing packet payload. - * - * @return The outcome of this packet's transmission. - * @see radio_tx_status_t - */ - radio_tx_status_t (* load_tx)(ieee802154_packet_kind_t kind, - ieee802154_node_addr_t dest, - bool use_long_addr, - bool wants_ack, - void *buf, - unsigned int len); - - /** - * @brief Transmit the data loaded into the transceiver TX buffer. - * - * @return The outcome of this packet's transmission. - * @see radio_tx_status_t - */ - radio_tx_status_t (* transmit)(void); - - /** - * @brief Transmit the given IEEE 802.15.4 packet, - * by calling successively functions @c load_tx() - * and @c transmit(). - * - * @param[in] kind Kind of packet to transmit. - * @param[in] dest Address of the node to which the packet is sent. - * @param[in] use_long_addr @c true to use the 64-bit address mode - * with @c dest param; @c false to use - * "short" PAN-centric mode. - * @param[in] wants_ack @c true to request an acknowledgement - * from the receiving node for this packet; - * @c false otherwise. - * @param[in] buf Pointer to the buffer containing the payload - * of the 802.15.4 packet to transmit. - * The frame header (i.e.: FCS, sequence number, - * src and dest PAN and addresses) is inserted - * using values in accord with @c kind parameter - * and transceiver configuration. - * @param[in] len Length (in bytes) of the outgoing packet payload. - * - * @return The outcome of this packet's transmission. - * @see radio_tx_status_t - */ - radio_tx_status_t (* send)(ieee802154_packet_kind_t kind, - ieee802154_node_addr_t dest, - bool use_long_addr, - bool wants_ack, - void *buf, - unsigned int len); - - /** - * @brief Define the function to be called back the radio transceiver - * has received a incoming packet. - * - * @param[in] recv_func the callback function to invoke for each - * packet received by the radio transceiver. - * @see receive_802154_packet_callback_t - */ - void (* set_receive_callback)(receive_802154_packet_callback_t recv_func); - - /** - * @brief Switch the radio transceiver to receive mode. - */ - void (* switch_to_rx)(void); - - /** - * @brief Set the 802.15.4 channel to be used - * by the radio transceiver as medium. - * - * @param[in] chan Channel to switch to. - * Usual values are 0 (868 MHz band), - * 1 to 10 (915 MHz band), and - * 11 to 26 (2.4 GHz band). - */ - void (* set_channel)(unsigned int chan); - - /** - * @brief Get the 802.15.4 channel currently used - * by the radio transceiver as medium. - */ - unsigned int (* get_channel)(void); - - /** - * @brief Set the 16-bit short address to be used by - * the radio transceiver within the current PAN. - * - * @param[in] addr Address to use. - */ - void (* set_address)(uint16_t addr); - - /** - * @brief Get the 16-bit short address currently used by - * the radio transceiver within the current PAN. - */ - uint16_t (* get_address)(void); - - /** - * @brief Set the 64-bit long ("extended") address - * to be used by the radio transceiver. - * - * @param[in] addr Address to use. - */ - void (* set_long_address)(uint64_t addr); - - /** - * @brief Get the 64-bit long ("extended") address - * currently used by the radio transceiver. - */ - uint64_t (* get_long_address)(void); - - /** - * @brief Set the 16-bit PAN ID within which the radio - * transceiver shall operate. - * - * @param[in] pan PAN ID to use. - */ - void (* set_pan_id)(uint16_t pan); - - /** - * @brief Get the 16-bit PAN ID within which the radio - * transceiver currently operates. - */ - uint16_t (* get_pan_id)(void); - - /** - * @brief Set the transmission power of the radio transceiver. - * - * @param[in] pow Output power to use (in dB). - */ - void (* set_tx_power)(int pow); - - /** - * @brief Get the transmission (output) power currently used - * by the radio transceiver (in dB). - */ - int (* get_tx_power)(void); - - /** - * @brief Indicates if the radio medium is available for transmission - * ("Clear Channel Assessment"). - * - * @return @c true if radio medium is "clear" (available); - * @c false if another transmission is already running. - */ - bool (* channel_is_clear)(void); - - /** - * @brief Set the radio transceiver in or out of "promiscuous mode" - * (i.e. reception of all packets without regard for their - * intended destination). - * - * @param[in] monitor Set to @c true to put the transceiver in - * "promiscuous mode" (a.k.a. monitor mode); - * @c false to only receive packets actually - * destined to the currently used address (i.e.: - * to activate hardware address-decoding). - */ - void (* set_promiscuous_mode)(bool monitor); - - /** - * @brief Indicates if the radio medium is currently in "promiscuous - * mode" (i.e. receiving all packets without regard for their - * intended destination). - * - * @return @c true if the transceiver is in "promiscuous mode"; - * @c false if only packets actually destined to the - * current transceiver are received (i.e. hardware - * address-decoding is active). - */ - bool (* in_promiscuous_mode)(void); - -} ieee802154_radio_driver_t; - -#ifdef __cplusplus -} -#endif - -#endif /* IEEE802154_RADIO_DRIVER_API_ */ - -/** - * @} - */ diff --git a/drivers/netdev/802154/802154.c b/drivers/netdev/802154/802154.c deleted file mode 100644 index 389b33ca5c..0000000000 --- a/drivers/netdev/802154/802154.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (C) 2014 Martine Lenders - * - * 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. - */ - -/** - * @addtogroup netdev - * @{ - * - * @file - * @brief Provides wrappers of @ref netdev/base.h functions to - * netdev/802154.h functions. - * - * @author Martine Lenders - */ - -#include -#include -#include - -#include "netdev/802154.h" - -static inline netdev_802154_driver_t *_get_driver(netdev_t *dev) -{ - return (netdev_802154_driver_t *)dev->driver; -} - -/* define to implement yourself and omit compilation of this function */ -#ifndef NETDEV_802154_SEND_DATA_OVERLOAD -static size_t _get_src_len(netdev_t *dev) -{ - size_t src_len, src_len_len = sizeof(size_t); - - if (_get_driver(dev)->get_option(dev, NETDEV_OPT_SRC_LEN, &src_len, &src_len_len) < 0) { - return 2; - } - - return src_len; -} - -int netdev_802154_send_data(netdev_t *dev, void *dest, size_t dest_len, - netdev_hlist_t *upper_layer_hdrs, void *data, - size_t data_len) -{ - int use_long_addr; - - if (dev == NULL || dev->type != NETDEV_TYPE_802154) { - return -ENODEV; - } - - use_long_addr = _get_src_len(dev) == 8; - - if (dest_len != 8 && dest_len != 4) { /* 8 for EUI-64, 4 for short address + PAN ID*/ - return -EAFNOSUPPORT; - } - - switch (_get_driver(dev)->send(dev, NETDEV_802154_PKT_KIND_DATA, - (netdev_802154_node_addr_t *)dest, - use_long_addr, 0, upper_layer_hdrs, - data, data_len)) { - case NETDEV_802154_TX_STATUS_OK: - return (int)(data_len + netdev_get_hlist_len(upper_layer_hdrs)); - - case NETDEV_802154_TX_STATUS_MEDIUM_BUSY: - case NETDEV_802154_TX_STATUS_COLLISION: - return -EBUSY; - - case NETDEV_802154_TX_STATUS_INVALID_PARAM: - return -EINVAL; - - case NETDEV_802154_TX_STATUS_PACKET_TOO_LONG: - return -EMSGSIZE; - - case NETDEV_802154_TX_STATUS_ERROR: - default: - return -EIO; - /* NETDEV_802154_TX_STATUS_UNDERFLOW can not happen since - * netdev_802154_driver_t::send always calls - * netdev_802154_driver_t::load_tx */ - /* NETDEV_802154_TX_STATUS_NOACK can not happen since - * wants_ack == 0 */ - } -} -#endif /* NETDEV_802154_SEND_DATA_OVERLOAD */ - -/* define to implement yourself and omit compilation of this function */ -#ifndef NETDEV_802154_SEND_OVERLOAD -netdev_802154_tx_status_t netdev_802154_send(netdev_t *dev, - netdev_802154_pkt_kind_t kind, - netdev_802154_node_addr_t *dest, - int use_long_addr, - int wants_ack, - netdev_hlist_t *upper_layer_hdrs, - void *buf, - unsigned int len) -{ - netdev_802154_tx_status_t status; - - if (dev == NULL || dev->type != NETDEV_TYPE_802154) { - return NETDEV_802154_TX_STATUS_NO_DEV; - } - - status = _get_driver(dev)->load_tx(dev, kind, dest, use_long_addr, wants_ack, - upper_layer_hdrs, buf, len); - - if (status != NETDEV_802154_TX_STATUS_OK) { - return status; - } - - return _get_driver(dev)->transmit(dev); -} -#endif /* NETDEV_802154_SEND_OVERLOAD */ - -/** - * @} - */ diff --git a/drivers/netdev/802154/Makefile b/drivers/netdev/802154/Makefile deleted file mode 100644 index 18db41909a..0000000000 --- a/drivers/netdev/802154/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -MODULE := netdev_802154 - -INCLUDES += -I$(RIOTBASE)/drivers/include - -include $(RIOTBASE)/Makefile.base diff --git a/drivers/netdev/base/Makefile b/drivers/netdev/base/Makefile deleted file mode 100644 index 84416c03d5..0000000000 --- a/drivers/netdev/base/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -MODULE := netdev_base - -INCLUDES += -I$(RIOTBASE)/drivers/include - -include $(RIOTBASE)/Makefile.base diff --git a/drivers/netdev/base/base.c b/drivers/netdev/base/base.c deleted file mode 100644 index f96d63567a..0000000000 --- a/drivers/netdev/base/base.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2014 Martine Lenders - * - * 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. - */ - -/** - * @addtogroup netdev - * @{ - * - * @file - * @brief Provides helper functions to the API in @ref netdev/base.h. - * - * @author Martine Lenders - */ - -#include "clist.h" - -#include "netdev/base.h" - -size_t netdev_get_hlist_len(const netdev_hlist_t *hlist) -{ - netdev_hlist_t *ptr = (netdev_hlist_t *)hlist; - size_t length = 0; - - if (ptr == NULL) { - return 0; - } - - do { - length += ptr->header_len; - netdev_hlist_advance(&ptr); - } while (ptr != hlist); - - return length; -} - -/** - * @} - */ diff --git a/examples/ccn-lite-client/HOWTO b/examples/ccn-lite-client/HOWTO deleted file mode 100644 index 010ac451bb..0000000000 --- a/examples/ccn-lite-client/HOWTO +++ /dev/null @@ -1,55 +0,0 @@ -simple appserver (all in one shell) -==================================================== - -0. create tap devices: *./cpu/native/tapsetup.sh create 3* -1. build ccn-lite-client: *make -B clean all-valgrind* -2. start: *./bin/native/ccn-lite-client.elf tap0* (valgrind support included) -3. optional: *config 20* [enter] (this sets the content store size) -4. start appserver thread: *appserver* [enter] (this starts the userland appserver, which registers for "/riot/appserver/" -5. request content: *interest /riot/appserver/test* [enter] (ask the relay for this "file", userland code splits this up in -chunks and requests them from the relay. In the relay the name "/riot/appserver" is registered to the RIOT MSG face with -thread of the appserver. Interest is forwarded to appserver which replies with content.... -6. tear down ccn network stack: *haltccn* [enter] -7. now you can hit *ctrl+c* to stop the RIOT process [in valgrind you can notice that there is no leak] - -simple forward (needs two shells) -==================================================== - -SHELL 1 | SHELL 2 --------------------------------------------------------------------------------------------------------------- -0. create tap devices: *./cpu/native/tapsetup.sh create 3* | -1. build ccn-lite-client: *make -B clean all* | build ccn-lite: *make clean all* -2. start: *./bin/native/ccn-lite-client.elf tap0* | start: *./bin/ccn-lite-relay.elf tap1* -3. set content store size: *config 20* [enter] | [stack starts automaticly] -4. set address: *addr 1* [enter] | [it picks address 42 automaticly] -5. register prefix the ccn-lite stack: *prefix /riot/ newTRANSface 42* [enter] | [it populates the cache automaticly] -6. request content: *interest /riot/text* [enter] | -7. tear down ccn network stack: *haltccn* [enter] - -advanced forward (needs three shells) -==================================================== - -SHELL 1 | SHELL 2 | SHELL 3 ----------------------------------------------------------------------------------------------------------------------------------------------------------------- -0. create tap devices: *./cpu/native/tapsetup.sh create 3* | | -1. build ccn-lite-client: *make -B clean all* | | build ccn-lite: make clean all -2. start: *./bin/native/ccn-lite-client.elf tap0* | start: *./bin/native/ccn-lite-client.elf tap1* | start: ./bin/ccn-lite-relay.elf tap2 -3. set content store size: *cconfig 20* [enter] | set content store size: *cconfig 20* [enter] | [it starts ccn automaticly] -4. set address: *addr 1* [enter] | set address: *addr 2* [enter] | [it picks address 42 automaticly] -5. *prefix /riot/ newTRANSface 2* [enter] | *prefix /riot/ newTRANSface 42* [enter] | [it populates the cache automaticly] -6. request content: *interest /riot/text* [enter] | | - - -overdosed forward (needs three shells) -==================================================== - -SHELL 1 | SHELL 2 | SHELL 3 ----------------------------------------------------------------------------------------------------------------------------------------------------------------- -0. create tap devices: *./cpu/native/tapsetup.sh create 3* | | -1. build ccn-lite-client: *make -B clean all* | | -2. start: *./bin/native/ccn-lite-client.elf tap0* | start: *./bin/native/ccn-lite-client.elf tap1* | start: *./bin/native/ccn-lite-client.elf tap2* -3. set content store size: *cconfig 20* [enter] | sset content store size: *cconfig 20* [enter] | sset content store size: *cconfig 20* [enter] -4. set address: *addr 1* [enter] | set address: *addr 2* [enter] | set address: *addr 3* [enter] -5. | | start appserver: *appserver* [enter] -6. *prefix /riot/ newTRANSface 2* [enter] | *prefix /riot/ newTRANSface 3* [enter] | -7. request content: *interest /riot/appserver/test* [enter] | | diff --git a/examples/ccn-lite-client/Makefile b/examples/ccn-lite-client/Makefile deleted file mode 100644 index 494da4bebe..0000000000 --- a/examples/ccn-lite-client/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -# name of your application -APPLICATION = ccn-lite-client - -# If no BOARD is found in the environment, use this default: -BOARD ?= native - -# This has to be the absolute path to the RIOT base directory: -RIOTBASE ?= $(CURDIR)/../.. - -# Uncomment these lines if you want to use platform support from external -# repositories: -#RIOTCPU ?= $(CURDIR)/../../RIOT/thirdparty_cpu -#RIOTBOARD ?= $(CURDIR)/../../RIOT/thirdparty_boards - -# Uncomment this to enable scheduler statistics for ps: -#CFLAGS += -DSCHEDSTATISTICS - -# If you want to use native with valgrind, you should recompile native -# with the target all-valgrind instead of all: -# make -B clean all-valgrind - -# Comment this out to disable code in RIOT that does safety checking -# which is not needed in a production environment but helps in the -# development process: -CFLAGS += -DDEVELHELP - -# Change this to 0 show compiler invocation lines by default: -QUIET ?= 1 - -# The CCN-lite API is currently expecting unsigned int to be at least 32 bits wide. -BOARD_BLACKLIST := chronos msb-430h telosb wsn430-v1_3b wsn430-v1_4 z1 redbee-econotag - -# Modules to include: - -USEMODULE += shell -USEMODULE += shell_commands -USEMODULE += uart0 -USEMODULE += ps -USEMODULE += random -USEMODULE += defaulttransceiver -USEMODULE += vtimer -USEMODULE += ccn_lite -USEMODULE += ccn_lite_client - -include $(RIOTBASE)/Makefile.include diff --git a/examples/ccn-lite-client/README.md b/examples/ccn-lite-client/README.md deleted file mode 100644 index c01758b467..0000000000 --- a/examples/ccn-lite-client/README.md +++ /dev/null @@ -1,16 +0,0 @@ -This application is a showcase of the Content Centric Networking (CCN) capabilities in RIOT. - -The example consists in two parts: clients and relays. - -This file documents the client functionalities. - -A client opens a shell to enable the following: - -* **start the CCN stack**: The command `ccn X` starts the CCN stack and sets the content store size to X chunks. Chunk size is by default set to 802.15.4 packet payload (set it differently if needed). Note that X must be bigger or equal to 15 if you plan to publish content using Way 1 described below. - -* **publishing content locally**: Two alternative ways are defined to do that. - - * *Way 1*: pre-provision the local CCN stack cache with X dummy chunks, with the command `populate`. Chunk size is by default set to 802.15.4 packet payload (set it differently if needed). The default name of the content is `/riot/text`. - * *Way 2*: start a application in a different thread with the command `appserver`. This application will register a prefix `/riot/appserver/test` in the CCN network stack Forwarding Information Base (FIB). Note that from the view of the CCN network stack, there is no difference between local faces connecting to local appplications and network faces connecting to real network interfaces. When the application recieves an interest it replies with chunck `/riot/appserver/test/0`. Note that actual interest parsing is not implemented in the application. - -* **subscribing to receive content**: the command `interest` fetches a remote file through the CCN network stack. This starts an application executed by the shell thread, which creates an interest message and routes this message hop by hop towards the publisher of the content (or a cache containing a copy) using the CCN stack. By default the content being fetched is `/riot/text`. One can also specify a name of content to fetch with the command `interest valid-name`. By valid, it is meant that the name should have structure like `/a/b/c` and the application will then request chunks with syntax `/a/b/c/0` etc. diff --git a/examples/ccn-lite-client/main.c b/examples/ccn-lite-client/main.c deleted file mode 100644 index b03a864e71..0000000000 --- a/examples/ccn-lite-client/main.c +++ /dev/null @@ -1,366 +0,0 @@ -/* - * Copyright (C) 2013 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 CCN Lite interactive shell example application - * - * @author Christian Mehlis - * - * @} - */ - -#include -#include -#include -#include - -#include "msg.h" -#include "thread.h" -#include "posix_io.h" -#include "shell.h" -#include "board_uart0.h" -#include "transceiver.h" -#include "vtimer.h" -#include "ps.h" -#include "ltc4150.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -#include "ccn_lite/ccnl-riot.h" -#include "ccn_lite/util/ccnl-riot-client.h" - -#define RIOT_CCN_APPSERVER (1) -#define RIOT_CCN_TESTS (0) - -static const char DEFAULT_INTEREST[] = "/ccnx/0.7.1/doc/technical/CanonicalOrder.txt"; - -char relay_stack[THREAD_STACKSIZE_MAIN]; - -#if RIOT_CCN_APPSERVER -char appserver_stack[THREAD_STACKSIZE_MAIN]; -#endif -static volatile kernel_pid_t _relay_pid = KERNEL_PID_UNDEF, _appserver_pid = KERNEL_PID_UNDEF; - -#define SHELL_MSG_BUFFER_SIZE (64) -msg_t msg_buffer_shell[SHELL_MSG_BUFFER_SIZE]; - -shell_t shell; - -unsigned char big_buf[3 * 1024]; -char small_buf[PAYLOAD_SIZE]; - -#if RIOT_CCN_APPSERVER -static int riot_ccn_appserver(int argc, char **argv) -{ - (void) argc; /* the function takes no arguments */ - (void) argv; - - if (_appserver_pid != KERNEL_PID_UNDEF) { - /* already running */ - return 1; - } - - _appserver_pid = thread_create( - appserver_stack, sizeof(appserver_stack), - THREAD_PRIORITY_MAIN - 1, CREATE_STACKTEST, - ccnl_riot_appserver_start, (void *) &_relay_pid, "appserver"); - DEBUG("ccn-lite appserver on thread_id %" PRIkernel_pid "...\n", _appserver_pid); - - return 0; -} -#endif - -static int riot_ccn_express_interest(int argc, char **argv) -{ - if (argc < 2) { - strncpy(small_buf, DEFAULT_INTEREST, sizeof(small_buf)); - } - else { - strncpy(small_buf, argv[1], sizeof(small_buf)); - } - - DEBUG("in='%s'\n", small_buf); - - int content_len = ccnl_riot_client_get(_relay_pid, small_buf, (char *) big_buf); // small_buf=name to request - - if (content_len == 0) { - puts("riot_get returned 0 bytes...aborting!"); - return 1; - } - - puts("####################################################"); - big_buf[content_len] = '\0'; - printf("data='%s'\n", big_buf); - puts("####################################################"); - puts("done"); - - return 0; -} - -static int riot_ccn_register_prefix(int argc, char **argv) -{ - if (argc < 4) { - puts("enter: prefix "); - return 1; - } - - strncpy(small_buf, argv[1], 100); - DEBUG("prefix='%s'\n", small_buf); - - char *type = argv[2]; - char *faceid = argv[3]; // 0=trans;1=msg - - int content_len = ccnl_riot_client_publish(_relay_pid, small_buf, faceid, type, big_buf); -#if !ENABLE_DEBUG - (void) content_len; -#endif - - DEBUG("shell received: '%s'\n", big_buf); - DEBUG("received %d bytes.\n", content_len); - puts("done"); - - return 0; -} - -static int riot_ccn_relay_config(int argc, char **argv) -{ - if (_relay_pid == KERNEL_PID_UNDEF) { - puts("ccnl stack not running"); - return 1; - } - - if (argc < 2) { - printf("%s: \n", argv[0]); - return 1; - } - - msg_t m; - m.content.value = atoi(argv[1]); - m.type = CCNL_RIOT_CONFIG_CACHE; - msg_send(&m, _relay_pid); - - return 0; -} - -static void riot_ccn_transceiver_start(kernel_pid_t _relay_pid) -{ - transceiver_init(TRANSCEIVER); - int transceiver_pid = transceiver_start(); - DEBUG("transceiver on thread_id %d...\n", transceiver_pid); - - /* register for transceiver events */ - uint8_t reg = transceiver_register(TRANSCEIVER, _relay_pid); - if (reg != 1) { - DEBUG("transceiver register failed\n"); - } - - /* set channel to CCNL_CHAN */ - msg_t mesg; - transceiver_command_t tcmd; - int32_t c = CCNL_DEFAULT_CHANNEL; - tcmd.transceivers = TRANSCEIVER; - tcmd.data = &c; - mesg.content.ptr = (char *) &tcmd; - mesg.type = SET_CHANNEL; - msg_send_receive(&mesg, &mesg, transceiver_pid); - if (c == -1) { - puts("[transceiver] Error setting/getting channel"); - } - else { - printf("[transceiver] Got channel: %" PRIi32 "\n", c); - } -} - -static int riot_ccn_relay_start(void) -{ - if (_relay_pid != KERNEL_PID_UNDEF) { - DEBUG("ccn-lite relay on thread_id %d...please stop it first!\n", _relay_pid); - /* already running */ - return 1; - } - - _relay_pid = thread_create( - relay_stack, sizeof(relay_stack), - THREAD_PRIORITY_MAIN - 2, CREATE_STACKTEST, - ccnl_riot_relay_start, NULL, "relay"); - DEBUG("ccn-lite relay on thread_id %" PRIkernel_pid "...\n", _relay_pid); - - riot_ccn_transceiver_start(_relay_pid); - - return 0; -} - -static int riot_ccn_relay_stop(int argc, char **argv) -{ - (void) argc; /* the function takes no arguments */ - (void) argv; - - msg_t m; - m.content.value = 0; - m.type = CCNL_RIOT_HALT; - msg_send(&m, _relay_pid); - - /* mark relay as not running */ - _relay_pid = 0; - - return 0; -} - -#if RIOT_CCN_TESTS -static int riot_ccn_pit_test(int argc, char **argv) -{ - (void) argc; /* the function takes no arguments */ - (void) argv; - - char name[] = "/riot/test"; - - char *prefix[CCNL_MAX_NAME_COMP]; - char *cp = strtok(name, "/"); - int i = 0; - - while (i < (CCNL_MAX_NAME_COMP - 1) && cp) { - prefix[i++] = cp; - cp = strtok(NULL, "/"); - } - - //prefix[i] = 0; //segment to request - prefix[i + 1] = 0; - - msg_t m; - riot_ccnl_msg_t rmsg; - char segment_string[16]; //max=999\0 - timex_t now; - - int segment; - - for (segment = 0; segment < 200; segment++) { - memset(segment_string, 0, 16); - snprintf(segment_string, 16, "%d", segment); - prefix[i] = segment_string; - unsigned int interest_nonce = genrand_uint32(); - int interest_len = mkInterest(prefix, &interest_nonce, (unsigned char *) small_buf); - - rmsg.payload = &small_buf; - rmsg.size = interest_len; - m.content.ptr = (char *) &rmsg; - m.type = CCNL_RIOT_MSG; - - msg_send(&m, _relay_pid); - - if ((segment % 50) == 0) { - vtimer_now(&now); - printf("done: %d - %ld.%ld\n", segment, now.tv_sec, now.tv_usec); - } - } - - printf("done: tried to send %d interests\n", segment); - - return 0; -} - -static int riot_ccn_fib_test(int argc, char **argv) -{ - (void) argc; /* the function takes no arguments */ - (void) argv; - - char type[] = "newTRANSface"; - char faceid[] = "42"; - - riot_new_face(_relay_pid, type, faceid, big_buf); - - timex_t now; - int i = -1; - - do { - i++; - snprintf(small_buf, sizeof(small_buf), "/riot/test/fib/%d/", i); - riot_register_prefix(_relay_pid, small_buf, faceid, big_buf); - - if (i % 50 == 0) { - vtimer_now(&now); - printf("done: %d - %ld.%ld\n", i, now.tv_sec, now.tv_usec); - } - } - while (0 == strcmp((const char *) big_buf, "prefixreg cmd worked")); - - DEBUG("%d: '%s'\n", i, big_buf); - printf("done: %d\n", i - 1); - - return 0; -} -#endif - -static int riot_ccn_populate(int argc, char **argv) -{ - (void) argc; /* the function takes no arguments */ - (void) argv; - - msg_t m; - m.content.value = 0; - m.type = CCNL_RIOT_POPULATE; - msg_send(&m, _relay_pid); - - return 0; -} - -static int riot_ccn_stat(int argc, char **argv) -{ - (void) argc; /* the function takes no arguments */ - (void) argv; - - msg_t m; - m.content.value = 0; - m.type = CCNL_RIOT_PRINT_STAT; - msg_send(&m, _relay_pid); - - return 0; -} - -static const shell_command_t sc[] = { - { "haltccn", "stops ccn relay", riot_ccn_relay_stop }, - { "interest", "express an interest", riot_ccn_express_interest }, - { "populate", "populate the cache of the relay with data", riot_ccn_populate }, - { "prefix", "registers a prefix to a face", riot_ccn_register_prefix }, - { "stat", "prints out forwarding statistics", riot_ccn_stat }, - { "config", "changes the runtime config of the ccn lite relay", riot_ccn_relay_config }, -#if RIOT_CCN_APPSERVER - { "appserver", "starts an application server to reply to interests", riot_ccn_appserver }, -#endif -#if RIOT_CCN_TESTS - { "pittest", "starts a test for the size and speed of pit operations", riot_ccn_pit_test }, - { "fibtest", "starts a test for the size and speed of fib operations", riot_ccn_fib_test }, -#endif - { NULL, NULL, NULL } -}; - -int main(void) -{ - puts("CCN!"); - - if (msg_init_queue(msg_buffer_shell, SHELL_MSG_BUFFER_SIZE) != 0) { - DEBUG("msg init queue failed...abording\n"); - return -1; - } - - riot_ccn_relay_start(); - - puts("starting shell..."); - puts(" posix open"); - posix_open(uart0_handler_pid, 0); - puts(" shell init"); - shell_init(&shell, sc, UART0_BUFSIZE, uart0_readc, uart0_putc); - puts(" shell run"); - shell_run(&shell); - - return 0; -} diff --git a/examples/ccn-lite-relay/Makefile b/examples/ccn-lite-relay/Makefile deleted file mode 100644 index ea26e8da27..0000000000 --- a/examples/ccn-lite-relay/Makefile +++ /dev/null @@ -1,40 +0,0 @@ -# name of your application -APPLICATION = ccn-lite-relay - -# If no BOARD is found in the environment, use this default: -BOARD ?= native - -# This has to be the absolute path to the RIOT base directory: -RIOTBASE ?= $(CURDIR)/../.. - -# Uncomment these lines if you want to use platform support from external -# repositories: -#RIOTCPU ?= $(CURDIR)/../../RIOT/thirdparty_cpu -#RIOTBOARD ?= $(CURDIR)/../../RIOT/thirdparty_boards - -# Uncomment this to enable scheduler statistics for ps: -#CFLAGS += -DSCHEDSTATISTICS - -# If you want to use native with valgrind, you should recompile native -# with the target all-valgrind instead of all: -# make -B clean all-valgrind - -# Comment this out to disable code in RIOT that does safety checking -# which is not needed in a production environment but helps in the -# development process: -CFLAGS += -DDEVELHELP - -# Change this to 0 show compiler invocation lines by default: -QUIET ?= 1 - -# The CCN-lite API is currently expecting unsigned int to be at least 32 bits wide. -BOARD_BLACKLIST := chronos msb-430h telosb wsn430-v1_3b wsn430-v1_4 z1 redbee-econotag - -# Modules to include: - -USEMODULE += posix - -USEMODULE += defaulttransceiver -USEMODULE += ccn_lite - -include $(RIOTBASE)/Makefile.include diff --git a/examples/ccn-lite-relay/README.md b/examples/ccn-lite-relay/README.md deleted file mode 100644 index f0489f5fa1..0000000000 --- a/examples/ccn-lite-relay/README.md +++ /dev/null @@ -1,9 +0,0 @@ -This application is a showcase of the Content Centric Networking (CCN) capabilities in RIOT. - -The example consists in two parts: clients and relays. - -This file documents the relay functionalities. - -A relay implements CCN capabilities for third party content caching, forwarding and subscription. - -Upon booting up, the CCN stack is automatically started, which enables the processing of incoming CCN messages (and relaying them if necessary). diff --git a/examples/ccn-lite-relay/main.c b/examples/ccn-lite-relay/main.c deleted file mode 100644 index e7dc9b62d8..0000000000 --- a/examples/ccn-lite-relay/main.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2013 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 CCN Lite relay example application - * - * @author Christian Mehlis - * - * @} - */ - -// system -#include -#include -#include -#include - -// riot -#include "thread.h" -#include "periph/rtc.h" - -// ccn -#include "ccn_lite/ccnl-riot.h" - -static kernel_pid_t _relay_pid = KERNEL_PID_UNDEF; - -char t2_stack[THREAD_STACKSIZE_MAIN]; - -void set_address_handler(uint16_t a) -{ - msg_t mesg; - transceiver_command_t tcmd; - - tcmd.transceivers = TRANSCEIVER; - tcmd.data = &a; - mesg.content.ptr = (char *) &tcmd; - - printf("trying to set address %" PRIu16 "\n", a); - mesg.type = SET_ADDRESS; - - printf("transceiver_pid=%" PRIkernel_pid"\n", transceiver_pid); - - msg_send_receive(&mesg, &mesg, transceiver_pid); - printf("got address: %" PRIu16 "\n", a); -} - -void populate_cache(void) -{ - msg_t m; - m.content.value = 0; - m.type = CCNL_RIOT_POPULATE; - msg_send(&m, _relay_pid); -} - -void *second_thread(void *arg) -{ - (void) arg; - set_address_handler(42); - populate_cache(); - return NULL; -} - -int main(void) -{ - printf("CCN!\n"); - - _relay_pid = thread_getpid(); - - thread_create(t2_stack, sizeof(t2_stack), THREAD_PRIORITY_MAIN + 1, - CREATE_STACKTEST, second_thread, NULL, "helper thread"); - - printf("starting ccn-lite relay...\n"); - ccnl_riot_relay_start(NULL); - - return 0; -} diff --git a/examples/default/Makefile b/examples/default/Makefile index a4db05ddd4..5b41e2404c 100644 --- a/examples/default/Makefile +++ b/examples/default/Makefile @@ -37,7 +37,6 @@ USEMODULE += vtimer USEMODULE += defaulttransceiver USEMODULE += config -FEATURES_OPTIONAL += transceiver FEATURES_OPTIONAL += config FEATURES_OPTIONAL += periph_rtc diff --git a/examples/default/main.c b/examples/default/main.c index 3411325352..df24568dce 100644 --- a/examples/default/main.c +++ b/examples/default/main.c @@ -39,102 +39,6 @@ #include "ltc4150.h" #endif -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X -#include "ieee802154_frame.h" -#endif - -#ifdef MODULE_TRANSCEIVER -#include "transceiver.h" -#endif - -#define SND_BUFFER_SIZE (100) -#define RCV_BUFFER_SIZE (64) -#define RADIO_STACK_SIZE (THREAD_STACKSIZE_MAIN) - -#ifdef MODULE_TRANSCEIVER - -static char radio_stack_buffer[RADIO_STACK_SIZE]; -static msg_t msg_q[RCV_BUFFER_SIZE]; - -void *radio(void *arg) -{ - (void) arg; - - msg_t m; - -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X - ieee802154_packet_t *p; -#else - radio_packet_t *p; - radio_packet_length_t i; -#endif - - msg_init_queue(msg_q, RCV_BUFFER_SIZE); - - while (1) { - msg_receive(&m); - - if (m.type == PKT_PENDING) { -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X - p = (ieee802154_packet_t*) m.content.ptr; - printf("Got radio packet:\n"); - printf("\tLength:\t%u\n", p->length); - printf("\tSrc:\t%u\n", (p->frame.src_addr[0])|(p->frame.src_addr[1]<<8)); - printf("\tDst:\t%u\n", (p->frame.dest_addr[0])|(p->frame.dest_addr[1]<<8)); - printf("\tLQI:\t%u\n", p->lqi); - printf("\tRSSI:\t%u\n", p->rssi); - - printf("Payload Length:%u\n", p->frame.payload_len); - printf("Payload:%s\n", p->frame.payload); - - p->processing--; -#else - p = (radio_packet_t *) m.content.ptr; - - printf("Got radio packet:\n"); - printf("\tLength:\t%u\n", p->length); - printf("\tSrc:\t%u\n", p->src); - printf("\tDst:\t%u\n", p->dst); - printf("\tLQI:\t%u\n", p->lqi); - printf("\tRSSI:\t%u\n", p->rssi); - - for (i = 0; i < p->length; i++) { - printf("%02X ", p->data[i]); - } - - p->processing--; - puts("\n"); -#endif - - } - else if (m.type == ENOBUFFER) { - puts("Transceiver buffer full"); - } - else { - puts("Unknown message received"); - } - } -} - -void init_transceiver(void) -{ - kernel_pid_t radio_pid = thread_create( - radio_stack_buffer, - sizeof(radio_stack_buffer), - THREAD_PRIORITY_MAIN - 2, - CREATE_STACKTEST, - radio, - NULL, - "radio"); - - uint16_t transceivers = TRANSCEIVER_DEFAULT; - - transceiver_init(transceivers); - (void) transceiver_start(); - transceiver_register(transceivers, radio_pid); -} -#endif /* MODULE_TRANSCEIVER */ - int main(void) { shell_t shell; @@ -144,10 +48,6 @@ int main(void) ltc4150_start(); #endif -#ifdef MODULE_TRANSCEIVER - init_transceiver(); -#endif - #ifdef FEATURE_PERIPH_RTC rtc_init(); #endif diff --git a/examples/rpl_udp/Makefile b/examples/rpl_udp/Makefile deleted file mode 100644 index 9270b6ac75..0000000000 --- a/examples/rpl_udp/Makefile +++ /dev/null @@ -1,46 +0,0 @@ -# name of your application -APPLICATION = rpl_udp - -# If no BOARD is found in the environment, use this default: -BOARD ?= native - -# This has to be the absolute path to the RIOT base directory: -RIOTBASE ?= $(CURDIR)/../.. - -# Uncomment these lines if you want to use platform support from external -# repositories: -#RIOTCPU ?= $(CURDIR)/../../RIOT/thirdparty_cpu -#RIOTBOARD ?= $(CURDIR)/../../RIOT/thirdparty_boards - -# Uncomment this to enable scheduler statistics for ps: -#CFLAGS += -DSCHEDSTATISTICS - -# If you want to use native with valgrind, you should recompile native -# with the target all-valgrind instead of all: -# make -B clean all-valgrind - -# Comment this out to disable code in RIOT that does safety checking -# which is not needed in a production environment but helps in the -# development process: -CFLAGS += -DDEVELHELP - -# Change this to 0 show compiler invocation lines by default: -QUIET ?= 1 - -BOARD_INSUFFICIENT_RAM := chronos msb-430h redbee-econotag telosb wsn430-v1_3b wsn430-v1_4 z1 samr21-xpro - -# arduino-mega2560: time.h missing from avr-libc -BOARD_BLACKLIST := arduino-mega2560 - -# Modules to include: - -USEMODULE += shell -USEMODULE += shell_commands -USEMODULE += uart0 -USEMODULE += ps -USEMODULE += vtimer -USEMODULE += defaulttransceiver -USEMODULE += rpl -USEMODULE += udp - -include $(RIOTBASE)/Makefile.include diff --git a/examples/rpl_udp/README.md b/examples/rpl_udp/README.md deleted file mode 100644 index b2190406a4..0000000000 --- a/examples/rpl_udp/README.md +++ /dev/null @@ -1,126 +0,0 @@ -# Setup the build -First switch to this application directory: - - cd RIOT/examples/rpl_udp - -The build system provides three specific parameters for the RPL module. -These parameters are: - * `RPL_MOP` sets the _mode of operation_ (MOP) of RPL. _The default value (`0x02`) is used if this variable is not set._ - * `RPL_MAX_ROUTING_ENTRIES` sets the desired maximum number of entries for the RPL routing table. _If this parameter is not provided, a default value (`128`) is used._ - * `RPL_NODE_IS_ROOT` indicating the build is specifically for a root node. This parameter is **only required** for using `RPL_MOP_NON_STORING_MODE` MOP to initialize a RPL routing table. The parameter is ignored in all other cases. _For non-storing MOP a node does not require to provide a routing table._ - -These RPL build parameters and their according _default_ values are used in the [`rpl_config.h`](https://github.com/RIOT-OS/RIOT/blob/master/sys/net/include/rpl/rpl_config.h). - -#### Compiling the executable -**example for `RPL_MOP_STORING_MODE_MC`:** - - make RPL_MOP=RPL_MOP_STORING_MODE_MC - -builds the project and creates `128` entries for the RPL routing table by default. - - make RPL_MOP=RPL_MOP_STORING_MODE_MC RPL_MAX_ROUTING_ENTRIES=103 - -builds the project and creates `103` entries for the RPL routing table **overwriting** the default value. - -**example for `RPL_MOP_NON_STORING_MODE`:** - - make RPL_MOP=RPL_MOP_NON_STORING_MODE RPL_MAX_ROUTING_ENTRIES=103 RPL_NODE_IS_ROOT=1 - -builds the project and creates `103` entries for the RPL routing table for the root node. - -#### _[native only]_ Set up a bridge for *two* tap devices for communication - - ../../cpu/native/tapsetup.sh create 2 - -The `2` corresponds to the number of _virtual_ nodes to be started. -The tap devices are bound to the _virtual_ native node on starting the created executable `rpl_udp.elf`. - -#### _[native only]_ Starting _virtual_ nodes -Run the first node - - make term - -This starts the executable binding a _virtual_ node to the first tap device `tap0`. - -**Further nodes must be bound to tap devices manually.** -For the second node it would be: - - make term PORT=tap1 - - -# RPL init -Type ``help`` to see the commands available. - -#### Command order: - - init (r|n|h) - server - send - - -Init your RPL node either as root (`r`), as node router (`n`), or as non-routing node (host-mode) (`h`) - - > init r - init r - INFO: Initialize as root on address 1 - 6LoWPAN and RPL initialized. - Channel set to 10 - Transport layer initialized - -or - - > init n - init n - INFO: Initialize as node on address 2 - 6LoWPAN and RPL initialized. - Channel set to 10 - Transport layer initialized - -or - - > init h - init h - INFO: Initialize as non-routing node on address 3 - 6LoWPAN initialized. - Channel set to 10 - Transport layer initialized - -(It is advised to start all nodes before running the root node, because the interval for sending DIOs from the root increases over time) -A few seconds withing running, setting and initializing your second node, the nodes will automatically start to exchange control traffic. You should be seeing output similar to the following: - - 41 CC FC 34 12 36 12 00 FF FE 00 00 02 36 12 00 FF FE 00 00 01 7A 33 3A 9B 03 F9 90 00 00 04 00 00 80 - IPv6 datagram received (next header: 3A) from fe80:0000:0000:0000:3612:00ff:fe00:0001 ICMP type: 5A ICMP code: 08 - Received packet from ID 1 - Length: 34 - Src: 1 - Dst: 2 - LQI: 0 - RSSI: 0 - -You can now use the ``dodag`` command to obtain information on the node's rank in the rpl dodag as well as their preferred parent - - > dodag - dodag - --------------------------- - Part of Dodag: - fe80:0000:0000:0000:3612:00ff:fe00:0001 - my rank: 512 - my preferred parent: - fe80:0000:0000:0000:3612:00ff:fe00:0001 - --------------------------- - -#Sending via UDP - -In order to be able to receive UDP messages from other nodes, we have to start `rpl_udp`'s UDP server: - - > server - server - UDP SERVER ON PORT 511 (THREAD PID: 17) - -When rpl is running, you can send a message from any participating node to the node initialized as a server (in our case, node 1) using the ``send`` command - - > send 1 hi - send 1 hi - Successful deliverd 11 bytes over UDP to abcd:0000:0000:0000:3612:00ff:fe00:0001 to 6LoWPAN - -In case of an error message, make sure that rpl is running and you've started the UDP server on the receiving node by running the ``server`` command. diff --git a/examples/rpl_udp/helper.c b/examples/rpl_udp/helper.c deleted file mode 100644 index f4ffdd23c6..0000000000 --- a/examples/rpl_udp/helper.c +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (C) 2013, 2014 INRIA - * - * 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 UDP RPL example application - * - * @author Oliver Hahm - * - * @} - */ - -#include -#include -#include -#include "msg.h" -#include "sixlowpan/ip.h" -#include "transceiver.h" -#include "ieee802154_frame.h" -#include "rpl/rpl_structs.h" - -#include "rpl_udp.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -#define LL_HDR_LEN (0x4) -#define IPV6_HDR_LEN (0x28) - -extern uint8_t ipv6_ext_hdr_len; - -static msg_t msg_q[RCV_BUFFER_SIZE]; - -int rpl_udp_set_id(int argc, char **argv) -{ - if (argc != 2) { - printf("Usage: %s address\n", argv[0]); -#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY) || defined(MODULE_CC110X_LEGACY_CSMA)) - printf("\taddress must be an 8 bit integer\n"); -#else - printf("\taddress must be an 16 bit integer\n"); -#endif - printf("\n\t(Current address is %u)\n", id); - return 1; - } - - id = atoi(argv[1]); - - printf("Set node ID to %u\n", id); - - return 0; -} - -void *rpl_udp_monitor(void *arg) -{ - (void) arg; - - msg_t m; - radio_packet_t *p; - ipv6_hdr_t *ipv6_buf; - uint8_t icmp_type, icmp_code; - icmpv6_hdr_t *icmpv6_buf = NULL; - - msg_init_queue(msg_q, RCV_BUFFER_SIZE); - - while (1) { - msg_receive(&m); - - if (m.type == PKT_PENDING) { - p = (radio_packet_t *) m.content.ptr; - - DEBUGF("Received packet from ID %u\n", p->src); - DEBUG("\tLength:\t%u\n", p->length); - DEBUG("\tSrc:\t%u\n", p->src); - DEBUG("\tDst:\t%u\n", p->dst); - DEBUG("\tLQI:\t%u\n", p->lqi); - DEBUG("\tRSSI:\t%i\n", (int8_t) p->rssi); - - for (uint8_t i = 0; i < p->length; i++) { - DEBUG("%02X ", p->data[i]); - } - - p->processing--; - DEBUG("\n"); - } - else if (m.type == IPV6_PACKET_RECEIVED) { - ipv6_buf = (ipv6_hdr_t *) m.content.ptr; - printf("IPv6 datagram received (next header: %02X)", ipv6_buf->nextheader); - printf(" from %s ", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - &ipv6_buf->srcaddr)); - - if (ipv6_buf->nextheader == IPV6_PROTO_NUM_ICMPV6) { - icmpv6_buf = (icmpv6_hdr_t *) &ipv6_buf[(LL_HDR_LEN + IPV6_HDR_LEN) + ipv6_ext_hdr_len]; - icmp_type = icmpv6_buf->type; - icmp_code = icmpv6_buf->code; - } - - if (ipv6_buf->nextheader == IPV6_PROTO_NUM_ICMPV6) { - DEBUG("\t ICMP type: %02X ", icmp_type); - DEBUG("\t ICMP code: %02X ", icmp_code); - (void) icmp_type; - (void) icmp_code; - } - - printf("\n"); - } - else if (m.type == ENOBUFFER) { - puts("Transceiver buffer full"); - } - else { - printf("Unknown packet received, type %04X\n", m.type); - } - } - - return NULL; -} - -static transceiver_command_t tcmd; - -int rpl_udp_ignore(int argc, char **argv) -{ - uint16_t a; - - if (argc < 2) { - printf("Usage: %s \n", argv[0]); - return 1; - } - - if (transceiver_pid == KERNEL_PID_UNDEF) { - puts("Transceiver not runnning."); - return 1; - } - - /* cppcheck: a is actually read via tcmd.data */ - /* cppcheck-suppress unreadVariable */ - a = atoi(argv[1]); - - msg_t mesg; - mesg.type = DBG_IGN; - mesg.content.ptr = (char *) &tcmd; - - tcmd.transceivers = TRANSCEIVER_CC1100; - tcmd.data = &a; - - printf("sending to transceiver (%" PRIkernel_pid "): %u\n", transceiver_pid, - (*(uint8_t *)tcmd.data)); - msg_send(&mesg, transceiver_pid); - - return 0; -} diff --git a/examples/rpl_udp/main.c b/examples/rpl_udp/main.c deleted file mode 100644 index 4c88c9938b..0000000000 --- a/examples/rpl_udp/main.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2013, 2014 INRIA - * - * 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 UDP RPL example application - * - * @author Oliver Hahm - * - * @} - */ - -#include - -#include "net_if.h" -#include "posix_io.h" -#include "shell.h" -#include "shell_commands.h" -#include "board_uart0.h" -#include "udp.h" - -#include "rpl_udp.h" - -static const shell_command_t shell_commands[] = { - {"init", "Initialize network", rpl_udp_init}, - {"set", "Set ID", rpl_udp_set_id}, - {"dodag", "Shows the dodag", rpl_udp_dodag}, - {"server", "Starts a UDP server", udp_server}, - {"send", "Send a UDP datagram", udp_send}, - {"ign", "Ignore a node", rpl_udp_ignore}, - {NULL, NULL, NULL} -}; - -int main(void) -{ - puts("RPL router v"APP_VERSION); - - /* start shell */ - posix_open(uart0_handler_pid, 0); - net_if_set_src_address_mode(0, NET_IF_TRANS_ADDR_M_SHORT); - id = net_if_get_hardware_address(0); - - shell_t shell; - shell_init(&shell, shell_commands, UART0_BUFSIZE, uart0_readc, uart0_putc); - - shell_run(&shell); - return 0; -} diff --git a/examples/rpl_udp/rpl_udp.h b/examples/rpl_udp/rpl_udp.h deleted file mode 100644 index a650b659f5..0000000000 --- a/examples/rpl_udp/rpl_udp.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (C) 2014 Oliver Hahm - * - * 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. - */ - -#ifndef RPL_UDP_H -#define RPL_UDP_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define APP_VERSION "1.2" - -#define RADIO_CHANNEL (10) - -#define MONITOR_STACK_SIZE (THREAD_STACKSIZE_MAIN) -#define RCV_BUFFER_SIZE (32) - -/* RPL shell command handlers */ -/** - * @brief Shell command to initializes RPL and UDP - * - * @details Usage: init - * `init r` will initialize the node as a RPL root node, - * `init n` as a RPL node. - * - * @param[in] argc Argument count - * @param[in] argv Arguments - */ -int rpl_udp_init(int argc, char **argv); - -/** - * @brief Shell command to set node's ID - * - * @details Usage: set - * Set the node address - * - * @param[in] argc Argument count - * @param[in] argv Arguments - */ -int rpl_udp_set_id(int argc, char **argv); - -/** - * @brief Shows the dodag - * - * @details No parameters required - * - * @param[in] argc Argument count - * @param[in] argv Arguments - */ -int rpl_udp_dodag(int argc, char **argv); - -/** - * @brief Command handler to start a UDP server - * - * @details No parameters required - * - * @param[in] argc Argument count - * @param[in] argv Arguments - */ -int udp_server(int argc, char **argv); - -/** - * @brief Sends a UDP datagram - * - * @details Usage: send - * Sends TEXT to the node with IP address: - * fe80::ff:fe00: - * - * @param[in] argc Argument count - * @param[in] argv Arguments - */ -int udp_send(int argc, char **argv); - -/** - * @brief Ignore a certain node - * - * @details Usage: ignore - * Ignore the node with IP address: - * fe80::ff:fe00: - * - * @param[in] argc Argument count - * @param[in] argv Arguments - */ -int rpl_udp_ignore(int argc, char **argv); - -/** - * @brief monitoring thread start function - * - * @param arg Unused - */ -void *rpl_udp_monitor(void *arg); - -/** @brief The nodes radio address */ -extern radio_address_t id; - -/** @brief Char array for IP address printing */ -extern char addr_str[IPV6_MAX_ADDR_STR_LEN]; - -#ifdef __cplusplus -} -#endif - -#endif /* RPL_UDP_H */ diff --git a/examples/rpl_udp/udp.c b/examples/rpl_udp/udp.c deleted file mode 100644 index a58e2a629e..0000000000 --- a/examples/rpl_udp/udp.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (C) 2013, 2014 INRIA - * - * 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 UDP RPL example application - * - * @author Oliver Hahm - * - * @} - */ - -#include -#include -#include -#include -#include - -#include "thread.h" - -#include "socket_base/socket.h" - -#include "net_help.h" - -#include "rpl_udp.h" - -#define UDP_BUFFER_SIZE (128) -#define SERVER_PORT (0xFF01) - -static char udp_server_stack_buffer[THREAD_STACKSIZE_MAIN]; -char addr_str[IPV6_MAX_ADDR_STR_LEN]; - -static void *init_udp_server(void *); - -/* UDP server thread */ -int udp_server(int argc, char **argv) -{ - (void) argc; - (void) argv; - - kernel_pid_t udp_server_thread_pid = thread_create(udp_server_stack_buffer, - sizeof(udp_server_stack_buffer), - THREAD_PRIORITY_MAIN, CREATE_STACKTEST, - init_udp_server, - NULL, - "init_udp_server"); - printf("UDP SERVER ON PORT %d (THREAD PID: %" PRIkernel_pid ")\n", HTONS(SERVER_PORT), udp_server_thread_pid); - - return 0; -} - -static void *init_udp_server(void *arg) -{ - (void) arg; - - sockaddr6_t sa; - char buffer_main[UDP_BUFFER_SIZE]; - uint32_t fromlen; - int sock = socket_base_socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP); - - memset(&sa, 0, sizeof(sa)); - - sa.sin6_family = AF_INET; - sa.sin6_port = HTONS(SERVER_PORT); - - fromlen = sizeof(sa); - - if (-1 == socket_base_bind(sock, &sa, sizeof(sa))) { - printf("Error bind failed!\n"); - socket_base_close(sock); - return NULL; - } - - while (1) { - int32_t recsize = socket_base_recvfrom(sock, (void *)buffer_main, UDP_BUFFER_SIZE, 0, &sa, &fromlen); - - if (recsize < 0) { - printf("ERROR: recsize < 0!\n"); - } - - printf("UDP packet received, payload: %s\n", buffer_main); - } - - socket_base_close(sock); - - return NULL; -} - -/* UDP send command */ -int udp_send(int argc, char **argv) -{ - int sock, res; - sockaddr6_t sa; - ipv6_addr_t ipaddr; - int bytes_sent; - int address; - - if (argc != 3) { - printf("usage: send \n"); - return 1; - } - - /* max payload size = MTU - MAC - AES - IPV6_HDR_LEN - UDP_HDR_LEN - * 33 = 127 - 25 - 21 - 40 - 8 - */ - if (strlen(argv[2]) > 32) { - puts(" is too large to be sent (max. 33 characters)."); - return 1; - } - - address = atoi(argv[1]); - - sock = socket_base_socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP); - - if (-1 == sock) { - printf("Error Creating Socket!"); - return 1; - } - - memset(&sa, 0, sizeof(sa)); - - if (address) { - ipv6_addr_init(&ipaddr, 0xabcd, 0x0, 0x0, 0x0, 0x0, 0x00ff, 0xfe00, (uint16_t)address); - } - else { - ipv6_addr_set_all_nodes_addr(&ipaddr); - } - - sa.sin6_family = AF_INET; - memcpy(&sa.sin6_addr, &ipaddr, 16); - sa.sin6_port = HTONS(SERVER_PORT); - - bytes_sent = socket_base_sendto(sock, argv[2], - strlen(argv[2]), 0, &sa, - sizeof(sa)); - - if (bytes_sent < 0) { - printf("Error sending packet!\n"); - res = 1; - } - else { - printf("Successful deliverd %i bytes over UDP to %s to 6LoWPAN\n", - bytes_sent, ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - &ipaddr)); - res = 0; - } - - socket_base_close(sock); - - return res; -} diff --git a/sys/Makefile.include b/sys/Makefile.include index 874000d87f..c828922119 100644 --- a/sys/Makefile.include +++ b/sys/Makefile.include @@ -1,40 +1,3 @@ -ifneq (,$(filter nomac,$(USEMODULE))) - USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include -endif -ifneq (,$(filter transport_layer,$(USEMODULE))) - USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include -endif -ifneq (,$(filter socket_base,$(USEMODULE))) - USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include -endif -ifneq (,$(filter tcp,$(USEMODULE))) - USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include -endif -ifneq (,$(filter udp,$(USEMODULE))) - USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include -endif -ifneq (,$(filter net_help,$(USEMODULE))) - USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include - USEMODULE_INCLUDES += $(RIOTBASE)/drivers/cc110x - USEMODULE_INCLUDES += $(RIOTBASE)/drivers/cc110x_legacy_csma - USEMODULE_INCLUDES += $(RIOTBASE)/drivers/cc110x_legacy/include -endif -ifneq (,$(filter net_if,$(USEMODULE))) - USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include -endif -ifneq (,$(filter pktqueue,$(USEMODULE))) - USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include -endif -ifneq (,$(filter protocol_multiplex,$(USEMODULE))) - USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include -endif -ifneq (,$(filter sixlowpan,$(USEMODULE))) - USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include -endif -ifneq (,$(filter rpl,$(USEMODULE))) - USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include - USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/routing/rpl -endif ifneq (,$(filter nhdp,$(USEMODULE))) USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/routing/nhdp @@ -42,16 +5,6 @@ endif ifneq (,$(filter ieee802154,$(USEMODULE))) USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include endif -ifneq (,$(filter l2_ping,$(USEMODULE))) - USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include -endif -ifneq (,$(filter ccn_lite,$(USEMODULE))) - USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include - USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/ccn_lite -endif -ifneq (,$(filter ccn_lite_client,$(USEMODULE))) - USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include -endif ifneq (,$(filter crypto,$(USEMODULE))) USEMODULE_INCLUDES += $(RIOTBASE)/include/crypto diff --git a/sys/auto_init/Makefile b/sys/auto_init/Makefile index c913303873..500728af1f 100644 --- a/sys/auto_init/Makefile +++ b/sys/auto_init/Makefile @@ -1,11 +1,3 @@ -ifneq (,$(filter net_if,$(USEMODULE))) - INCLUDES += -I$(RIOTBASE)/sys/net/include/ -endif - -ifneq (,$(filter nomac,$(USEMODULE))) - INCLUDES += -I$(RIOTBASE)/sys/net/include/ -endif - DIRS += $(AUTO_INIT_MODULES) ifneq (,$(filter auto_init_ng_netif,$(USEMODULE))) diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index 91e94152e3..e9c17eceef 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -32,10 +32,6 @@ #include "gpioint.h" #endif -#ifdef MODULE_CC110X_LEGACY_CSMA -#include "cc110x_legacy_csma.h" -#endif - #ifdef MODULE_LTC4150 #include "ltc4150.h" #endif @@ -56,33 +52,6 @@ #include "periph/rtc.h" #endif -#ifdef MODULE_SIXLOWPAN -#include "sixlowpan.h" -#endif - -#ifdef MODULE_UDP -#include "udp.h" -#endif - -#ifdef MODULE_TCP -#include "tcp.h" -#endif - -#ifdef MODULE_NOMAC -#include "nomac.h" -#endif - -#ifdef MODULE_NET_IF -#include "cpu_conf.h" -#include "cpu.h" -#include "kernel.h" -#include "net_if.h" -#include "transceiver.h" -#include "net_help.h" -#include "hashes.h" -#include "periph/cpuid.h" -#endif - #ifdef MODULE_NG_SIXLOWPAN #include "net/ng_sixlowpan.h" #endif @@ -123,120 +92,6 @@ #define ENABLE_DEBUG (0) #include "debug.h" -#ifndef CONF_RADIO_ADDR -#define CONF_RADIO_ADDR (1) -#endif - -#ifndef CONF_PAN_ID -#define CONF_PAN_ID (0xabcd) -#endif - -#ifdef MODULE_NET_IF -void auto_init_net_if(void) -{ - transceiver_type_t transceivers = 0; -#ifdef MODULE_AT86RF231 - transceivers |= TRANSCEIVER_AT86RF231; -#endif -#ifdef MODULE_CC1020 - transceivers |= TRANSCEIVER_CC1020; -#endif -#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY) || defined(MODULE_CC110X_LEGACY_CSMA)) - transceivers |= TRANSCEIVER_CC1100; -#endif -#ifdef MODULE_CC2420 - transceivers |= TRANSCEIVER_CC2420; -#endif -#ifdef MODULE_MC1322X - transceivers |= TRANSCEIVER_MC1322X; -#endif -#ifdef MODULE_NATIVENET - transceivers |= TRANSCEIVER_NATIVE; -#endif - net_if_init(); - - if (transceivers != 0) { -#if CPUID_ID_LEN && defined(MODULE_HASHES) - uint8_t cpuid[CPUID_ID_LEN]; - - cpuid_get(cpuid); -#endif - transceiver_init(transceivers); - transceiver_start(); - int iface = net_if_init_interface(0, transceivers); - -#if CPUID_ID_LEN && defined(MODULE_HASHES) - net_if_eui64_t eui64; - uint32_t hash_h = djb2_hash(cpuid, CPUID_ID_LEN / 2); -#if CPUID_ID_LEN % 2 == 0 - uint32_t hash_l = djb2_hash(&(cpuid[CPUID_ID_LEN / 2]), - CPUID_ID_LEN / 2); -#else /* CPUID_ID_LEN % 2 == 0 */ - uint32_t hash_l = djb2_hash(&(cpuid[CPUID_ID_LEN / 2]), - CPUID_ID_LEN / 2 + 1); -#endif /* CPUID_ID_LEN % 2 == 0 */ - - eui64.uint32[1] = hash_l; - eui64.uint32[0] = hash_h; - - /* Set Local/Universal bit to Local since this EUI64 is made up. */ - eui64.uint8[0] |= 0x02; - net_if_set_eui64(iface, &eui64); - -#if ENABLE_DEBUG - DEBUG("Auto init radio long address on interface %d to ", iface); - - for (size_t i = 0; i < 8; i++) { - printf("%02x ", eui64.uint8[i]); - } - - DEBUG("\n"); -#endif /* ENABLE_DEBUG */ - -#undef CONF_RADIO_ADDR -#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY) || defined(MODULE_CC110X_LEGACY_CSMA)) - uint8_t hwaddr = (uint8_t)((hash_l ^ hash_h) ^ ((hash_l ^ hash_h) >> 24)); - /* do not combine more parts to keep the propability low that it just - * becomes 0xff */ -#else - uint16_t hwaddr = HTONS((uint16_t)((hash_l ^ hash_h) ^ ((hash_l ^ hash_h) >> 16))); -#endif - net_if_set_hardware_address(iface, hwaddr); - DEBUG("Auto init radio address on interface %d to 0x%04x\n", iface, hwaddr); -#else /* CPUID_ID_LEN && defined(MODULE_HASHES) */ - - if (!net_if_get_hardware_address(iface)) { - DEBUG("Auto init radio address on interface %d to 0x%04x\n", iface, CONF_RADIO_ADDR); - DEBUG("Change this value at compile time with macro CONF_RADIO_ADDR\n"); - net_if_set_hardware_address(iface, CONF_RADIO_ADDR); - } - -#endif /* CPUID_ID_LEN && defined(MODULE_HASHES) */ - - if (net_if_set_src_address_mode(iface, NET_IF_TRANS_ADDR_M_SHORT)) { - DEBUG("Auto init source address mode to short on interface %d\n", - iface); - } - else { - net_if_set_src_address_mode(iface, NET_IF_TRANS_ADDR_M_LONG); - DEBUG("Auto init source address mode to long on interface %d\n", - iface); - } - - - if (net_if_get_pan_id(iface) <= 0) { - DEBUG("Auto init PAN ID on interface %d to 0x%04x\n", iface, CONF_PAN_ID); - DEBUG("Change this value at compile time with macro CONF_PAN_ID\n"); - net_if_set_pan_id(iface, CONF_PAN_ID); - } - - if (iface >= 0) { - DEBUG("Auto init interface %d\n", iface); - } - } -} -#endif /* MODULE_NET_IF */ - void auto_init(void) { #ifdef MODULE_CONFIG @@ -266,12 +121,6 @@ void auto_init(void) DEBUG("Auto init gpioint module.\n"); gpioint_init(); #endif -#ifdef MODULE_CC110X_LEGACY_CSMA - DEBUG("Auto init CC1100 module.\n"); -#ifndef MODULE_TRANSCEIVER - cc1100_init(); -#endif -#endif #ifdef MODULE_LTC4150 DEBUG("Auto init ltc4150 module.\n"); ltc4150_init(); @@ -280,35 +129,10 @@ void auto_init(void) DEBUG("Auto init mci module.\n"); MCI_initialize(); #endif -#ifdef MODULE_L2_PING - DEBUG("Auto init net_if module.\n"); - l2_ping_init(); -#endif -#ifdef MODULE_NOMAC - DEBUG("Auto init nomac module.\n"); - nomac_init_module(); -#endif -#ifdef MODULE_NET_IF - DEBUG("Auto init net_if module.\n"); - auto_init_net_if(); -#endif -#ifdef MODULE_SIXLOWPAN - DEBUG("Auto init 6LoWPAN module.\n"); - sixlowpan_lowpan_init(); -#endif #ifdef MODULE_PROFILING extern void profiling_init(void); profiling_init(); #endif -#ifdef MODULE_UDP - DEBUG("Auto init transport layer module: [udp].\n"); - udp_init_transport_layer(); -#endif - -#ifdef MODULE_TCP - DEBUG("Auto init transport layer module: [tcp].\n"); - tcp_init_transport_layer(); -#endif #ifdef MODULE_NG_PKTBUF DEBUG("Auto init ng_pktbuf module\n"); ng_pktbuf_init(); diff --git a/sys/include/radio/radio.h b/sys/include/radio/radio.h deleted file mode 100644 index 9f6cd6d372..0000000000 --- a/sys/include/radio/radio.h +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Generic radio driver interface - * - * Copyright (C) 2008-2009 Freie Universitaet Berlin (FUB). - * Copyright (C) 2013 INRIA. - * - * 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. - * - */ - -#ifndef RADIO_H_ -#define RADIO_H_ - -/** - * @defgroup net_datalink Data link layer - * @ingroup net - * - * @brief Defines interface of data link layers for use with micro mesh stack. - * - * @{ - */ - -/** - * @file - * @brief - * - * @author baar - * @author Thomas Hillebrandt - * - */ - -#include -#include -#include "radio/types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define L1_PROTOCOL_CATCH_ALL (0xff) /**< Catch all protocol ID */ - -/** - * @brief Link layer protocols (sic!) for proprietary cc110x protocol stack - */ -enum layer_1_protocols { - LAYER_1_PROTOCOL_LL_ACK = 1, /**< Link-Level Acknowledgement (LL-ACK) */ - LAYER_1_PROTOCOL_MM = 2, /**< Micro Mesh network packet (MM) */ -}; - -#ifdef __cplusplus -} -#endif - -/** @} */ - -#endif /* RADIO_H_ */ diff --git a/sys/include/radio/types.h b/sys/include/radio/types.h deleted file mode 100644 index 463c92b939..0000000000 --- a/sys/include/radio/types.h +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Generic radio driver interface data structures and prototypes - * - * Copyright (C) 2009 Freie Universitaet Berlin (FUB). - * Copyright (C) 2013 INRIA. - * - * 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. - * - */ - -#ifndef COMMONTYPES_H_ -#define COMMONTYPES_H_ - -/** - * @file - * @brief Common network stack types (of all layers). - * - * @author Thomas Hillebrandt - * @author Oliver Hahm - * @version $Revision: 2061 $ - * - * @note $Id: common-types.h 2061 2010-04-01 12:13:22Z hillebra $ - */ - -#include -#include - -#include "board.h" -#include "timex.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef uint8_t protocol_t; ///< Packet protocol type -typedef uint16_t radio_address_t; ///< Radio layer address type - -#define NUM_PRIORITY_LEVELS 3 ///< Number of packet transmission priorities - -/** - * @brief Packet transmission priorities of various layers. - */ -enum transmission_priorities { - PRIORITY_ALARM = 0, - PRIORITY_WARNING = 1, - PRIORITY_DATA = 2 -}; - -/** - * Additional packet information on a received packet. - * This struct is passed along all receive functions of - * all layers. Each layers fills in additional information. - */ -typedef struct __attribute__((packed)) packet_info_t { - uint16_t source; ///< Net layer: source - uint16_t destination; ///< Net layer: destination - radio_address_t phy_src; ///< Radio layer: source - uint8_t rssi; ///< Radio layer: RSSI - uint8_t lqi; ///< Radio layer: LQI - uint8_t ttl; ///< Net layer: TTL - uint8_t tos; ///< Net layer: TOS - bool promiscuous; ///< Radio layer: whether network interface is in promiscuous mode -} packet_info_t; - - -/** - * @brief General link layer packet format - */ -typedef struct __attribute__((packed)) -{ - uint8_t processing; ///< internal processing state - uint16_t src; ///< Radio source address - uint16_t dst; ///< Radio destination address - uint8_t rssi; ///< Radio Signal Strength Indication - uint8_t lqi; ///< Link Quality Indicator - timex_t toa; ///< Time of Arrival - radio_packet_length_t length; ///< Length of payload - uint8_t *data; ///< Payload -} -radio_packet_t; - - -/** - * Packet handler (receive function) of all layers. - * @param [in/out] payload Pointer to packet payload data - * @param [in] payload_size Size of the packet payload data in bytes - * @param [in/out] packet_info Cross-layer meta data - */ -typedef void (*packet_handler_t)(void *payload, int payload_size, packet_info_t *packet_info); - -/** - * Packet monitor of all layers. Normally there can be one packet - * monitor per layer (if any). The payload must not be changed! - * - * @param payload Pointer to packet payload data - * @param payload_size Size of the packet payload data in bytes - * @param protocol Protocol type of the packet payload data - * @param packet_info Cross-layer meta data - */ -typedef void (*packet_monitor_t)(void *payload, int payload_size, protocol_t protocol, packet_info_t *packet_info); - -#ifdef __cplusplus -} -#endif - -#endif /* COMMONTYPES_H_ */ diff --git a/sys/include/transceiver.h b/sys/include/transceiver.h deleted file mode 100644 index b06918deb3..0000000000 --- a/sys/include/transceiver.h +++ /dev/null @@ -1,304 +0,0 @@ -/* - * Copyright (C) 2010 - 2014 Oliver Hahm - * - * 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. - */ - -/** - * @defgroup sys_transceiver Transceiver - * @ingroup sys - * - * @brief The transceiver module implements a generic link abstraction to - * any radio interface. - * - * @{ - * - * @file - * @author Oliver Hahm - */ - -#ifndef TRANSCEIVER_H -#define TRANSCEIVER_H - -#include "kernel_types.h" -#include "radio/types.h" - -/* supported transceivers * - * NOTE: necessary to include here again due to - * https://github.com/RIOT-OS/RIOT/issues/117 */ -#ifdef MODULE_CC110X -#include "cc110x.h" -#ifndef TRANSCEIVER_DEFAULT -#define TRANSCEIVER_DEFAULT TRANSCEIVER_CC1100 -#endif -#endif - -#ifdef MODULE_CC110X_LEGACY_CSMA -#include "cc110x_legacy_csma.h" -#ifndef TRANSCEIVER_DEFAULT -#define TRANSCEIVER_DEFAULT TRANSCEIVER_CC1100 -#endif -#endif - -#ifdef MODULE_CC110X_LEGACY -#include "cc110x_legacy.h" -#ifndef TRANSCEIVER_DEFAULT -#define TRANSCEIVER_DEFAULT TRANSCEIVER_CC1100 -#endif -#endif - -#ifdef MODULE_CC11020 -#include "cc1020.h" -#ifndef TRANSCEIVER_DEFAULT -#define TRANSCEIVER_DEFAULT TRANSCEIVER_CC1020 -#endif -#endif - -#ifdef MODULE_CC2420 -#include "cc2420.h" -#ifndef TRANSCEIVER_DEFAULT -#define TRANSCEIVER_DEFAULT TRANSCEIVER_CC2420 -#endif -#endif - -#ifdef MODULE_MC1322X -#include "mc1322x.h" -#include "maca.h" -#include "maca_packet.h" -#ifndef TRANSCEIVER_DEFAULT -#define TRANSCEIVER_DEFAULT TRANSCEIVER_MC1322X -#endif -#endif - -#ifdef MODULE_NATIVENET -#include "nativenet.h" -#include "nativenet_internal.h" -#ifndef TRANSCEIVER_DEFAULT -#define TRANSCEIVER_DEFAULT TRANSCEIVER_NATIVE -#endif -#endif - -#ifdef MODULE_AT86RF231 -#include "at86rf231.h" -#ifndef TRANSCEIVER_DEFAULT -#define TRANSCEIVER_DEFAULT TRANSCEIVER_AT86RF231 -#endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Stack size for transceiver thread - */ -#ifndef TRANSCEIVER_STACK_SIZE -#define TRANSCEIVER_STACK_SIZE (THREAD_STACKSIZE_DEFAULT) -#endif - -/** - * @name Defines the upper payload limit for all available transceivers - * @{ - */ -#ifndef PAYLOAD_SIZE -#define PAYLOAD_SIZE (0) -#endif -#ifdef MODULE_CC110X_LEGACY_CSMA -#if (CC1100_MAX_DATA_LENGTH > PAYLOAD_SIZE) -#undef PAYLOAD_SIZE -#define PAYLOAD_SIZE (CC1100_MAX_DATA_LENGTH) -#define TRANSCEIVER_BROADCAST CC1100_BROADCAST_ADDRESS -#endif -#endif -#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY)) -#if (CC1100_MAX_DATA_LENGTH > PAYLOAD_SIZE) -#undef PAYLOAD_SIZE -#define PAYLOAD_SIZE (CC1100_MAX_DATA_LENGTH) -#define TRANSCEIVER_BROADCAST CC1100_BROADCAST_ADDRESS -#endif -#endif -#ifdef MODULE_CC2420 -#if (CC2420_MAX_DATA_LENGTH > PAYLOAD_SIZE) -#undef PAYLOAD_SIZE -#define PAYLOAD_SIZE (CC2420_MAX_DATA_LENGTH) -#define TRANSCEIVER_BROADCAST CC2420_BROADCAST_ADDRESS -#endif -#endif -#ifdef MODULE_AT86RF231 -#if (AT86RF231_MAX_DATA_LENGTH > PAYLOAD_SIZE) -#undef PAYLOAD_SIZE -#define PAYLOAD_SIZE (AT86RF231_MAX_DATA_LENGTH) -#define TRANSCEIVER_BROADCAST AT86RF231_BROADCAST_ADDRESS -#endif -#endif -#ifdef MODULE_MC1322X -#if (MACA_MAX_PAYLOAD_SIZE > PAYLOAD_SIZE) -#undef PAYLOAD_SIZE -#define PAYLOAD_SIZE (MACA_MAX_PAYLOAD_SIZE) -#define TRANSCEIVER_BROADCAST MC1322X_BROADCAST_ADDRESS -#endif -#endif -#ifdef MODULE_NATIVENET -#if (NATIVE_MAX_DATA_LENGTH > PAYLOAD_SIZE) -#undef PAYLOAD_SIZE -#define PAYLOAD_SIZE (NATIVE_MAX_DATA_LENGTH) -#define TRANSCEIVER_BROADCAST NATIVE_BROADCAST_ADDRESS -#endif -#endif -/** - * @} - */ - -/** - * @brief The maximum of threads to register - */ -#define TRANSCEIVER_MAX_REGISTERED (4) - -/** - * @brief The size of the message queue between driver and transceiver (must be - * power of two - */ -#define TRANSCEIVER_MSG_BUFFER_SIZE (32) - -/** - * @brief The maximum number of ignored addresses - */ -#define TRANSCEIVER_MAX_IGNORED_ADDR (10) - -/** - * @name All supported transceivers - * @{ - */ -#define TRANSCEIVER_NONE (0x0) /**< Invalid */ -#define TRANSCEIVER_CC1100 (0x01) /**< CC110X transceivers */ -#define TRANSCEIVER_CC1020 (0x02) /**< CC1020 transceivers */ -#define TRANSCEIVER_CC2420 (0x04) /**< CC2420 transceivers */ -#define TRANSCEIVER_MC1322X (0x08) /**< MC1322X transceivers */ -#define TRANSCEIVER_NATIVE (0x10) /**< NATIVE transceivers */ -#define TRANSCEIVER_AT86RF231 (0x20) /**< AT86RF231 transceivers */ -/** - * @} - */ - -/** - * @brief Data type for transceiver specification - */ -typedef uint16_t transceiver_type_t; - -/** - * @brief Data type to represent the transceiver's EUI-64. - */ -typedef uint64_t transceiver_eui64_t; - -/** - * @brief Message types for transceiver interface - */ -enum transceiver_msg_type_t { - /* Message types for driver <-> transceiver communication */ - RCV_PKT_CC1020, /**< packet was received by CC1020 transceiver */ - RCV_PKT_CC1100, /**< packet was received by CC1100 transceiver */ - RCV_PKT_CC2420, /**< packet was received by CC2420 transceiver */ - RCV_PKT_MC1322X, /**< packet was received by mc1322x transceiver */ - RCV_PKT_NATIVE, /**< packet was received by native transceiver */ - RCV_PKT_AT86RF231, /**< packet was received by AT86RF231 transceiver */ - - /* Message types for transceiver <-> upper layer communication */ - PKT_PENDING, /**< packet pending in transceiver buffer */ - SND_PKT, /**< request for sending a packet */ - SND_ACK, /**< request for sending an acknowledgement */ - SWITCH_RX, /**< switch transceiver to RX sate */ - POWERDOWN, /**< power down transceiver */ - GET_CHANNEL, /**< Get current channel */ - SET_CHANNEL, /**< Set a new channel */ - GET_ADDRESS, /**< Get the radio address */ - SET_ADDRESS, /**< Set the radio address */ - GET_LONG_ADDR, /**< Get the long radio address, if existing */ - SET_LONG_ADDR, /**< Set the long radio address, if supported by hardware */ - SET_MONITOR, /**< Set transceiver to monitor mode (disable address - checking) */ - GET_PAN, /**< Get current pan */ - SET_PAN, /**< Set a new pan */ - - /* debug message types */ - DBG_IGN, /**< add a physical address to the ignore list */ - - /* Error messages */ - ENOBUFFER, /**< No buffer left */ - - /* reserve message types for higher layer notifications */ - UPPER_LAYER_1, /**< reserved */ - UPPER_LAYER_2, /**< reserved */ - UPPER_LAYER_3, /**< reserved */ - UPPER_LAYER_4, /**< reserved */ - UPPER_LAYER_5, /**< reserved */ -}; - -/** - * @brief Manage registered threads per transceiver - */ -typedef struct { - transceiver_type_t transceivers; /**< the tranceivers the thread is - registered for */ - kernel_pid_t pid; /**< the thread's pid */ -} registered_t; - -/** - * @brief Transceiver command struct - */ -typedef struct { - transceiver_type_t transceivers; /**< Bitfield of targeted transceivers */ - void *data; /**< The payload of the command */ -} transceiver_command_t; - -/** - * @brief The transceiver thread's pid - */ -extern volatile kernel_pid_t transceiver_pid; - -/** - * @brief An array of ignored link layer addresses - */ -extern radio_address_t transceiver_ignored_addr[TRANSCEIVER_MAX_IGNORED_ADDR]; - -/** - * @brief Initializes the transceiver module for certain transceiver types - * - * @param transceivers Specifies all transceivers to init - **/ -void transceiver_init(transceiver_type_t transceivers); - -/** - * @brief Runs the transceiver thread - * - * @return The transceiver thread's pid - */ -kernel_pid_t transceiver_start(void); - -/** - * @brief register a thread for events from certain transceivers - * - * @param transceivers The transceiver types to register for - * @param pid The pid of the thread to register - * - * @return 1 on success, 0 otherwise - */ -uint8_t transceiver_register(transceiver_type_t transceivers, kernel_pid_t pid); - -/** - * @brief unregister a thread for events from certain transceivers - * - * @param transceivers The transceiver types to register for - * @param pid The pid of the thread to register - * - * @return 1 on success, 0 otherwise - */ -uint8_t transceiver_unregister(transceiver_type_t transceivers, kernel_pid_t pid); - -#ifdef __cplusplus -} -#endif - -#endif /* TRANSCEIVER_H */ -/** @} */ diff --git a/sys/net/ccn_lite/Makefile b/sys/net/ccn_lite/Makefile deleted file mode 100644 index 48422e909a..0000000000 --- a/sys/net/ccn_lite/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(RIOTBASE)/Makefile.base diff --git a/sys/net/ccn_lite/README.md b/sys/net/ccn_lite/README.md deleted file mode 100644 index d97a4291eb..0000000000 --- a/sys/net/ccn_lite/README.md +++ /dev/null @@ -1,52 +0,0 @@ -CCN lite port of RIOT -===================== - -RIOT's support for CCN messages is based on the work of [Christian Tschudin from University of Basel](http://cn.cs.unibas.ch/people/cft/) [(CCN-lite code available here)](https://github.com/cn-uofbasel/ccn-lite). - -The network stack can handle multiple faces based on the transceiver or from the local device via RIOT's message system. -To communicate with the stack, one can send messages via the RIOT message system to the CCN-lite relay thread or via a physical network transceiver. - -All incoming messages are processed in the main IO loop, which you can find [here](ccn-lite-relay.c#L302). - -The public API of the ccn network stack is defined in `sys/net/include/ccn_lite/ccnl-riot.h`. -Client related functions are defined in `sys/net/include/ccn_lite/util/ccn-riot-client.h`. - -To work with the CCN-lite network stack, only these two API declarations need to be considered. - - -Running Test Application ------------------------- - -Test applications are provided in the example directory. - -### ccn-lite-client - -The CCN-lite client uses the RIOT shell for user interaction. -The network stack is started on demand in its own thread. You have to enter `ccn ` in the shell. -Further details are explained in `examples/ccn-lite-client/README.md`. - -### ccn-lite-relay - -The CCN-lite relay is an application without interactive user control. -Further details are explained in `examples/ccn-lite-relay/README.md`. - -Hardware support ----------------- - -The CCN-lite stack is currently tested and proved to run on the native port of RIOT and the MSBA2 embedded hardware. -On the MSBA2 platform (32 Bit) CCN-lite only needs a stack of 800 bytes. -It uses the heap for the CS, FIB, and PIT. - -Reference ---------- - -If you are using this implementation in a scientific context, please cite the implementation as follows: - -* Emmanuel Baccelli, Christian Mehlis, Oliver Hahm, Thomas C. Schmidt, and Matthias Wählisch, "Information Centric Networking in the IoT: Experiments with NDN in the Wild," in Proc. of 1st ACM Conference on Information-Centric Networking (ICN). New York: ACM, pp. 77-86. - -The paper is publicly [available](http://conferences.sigcomm.org/acm-icn/2014/papers/p77.pdf). - -More ----- - -This README is still under construction. diff --git a/sys/net/ccn_lite/ccn-lite-relay.c b/sys/net/ccn_lite/ccn-lite-relay.c deleted file mode 100644 index b721156840..0000000000 --- a/sys/net/ccn_lite/ccn-lite-relay.c +++ /dev/null @@ -1,485 +0,0 @@ -/* - * @f ccn-lite-relay.c - * @b CCN relay - * - * Copyright (C) 2011-13, Christian Tschudin, University of Basel - * Copyright (C) 2013, Christian Mehlis, Freie Universität Berlin - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * File history: - * 2011-11-22 created - */ - -#include - -#define RIOT_CCNL_POPULATE (1) - -#include "ccnl-includes.h" - -#include "ccnx.h" -#include "ccnl.h" -#include "ccnl-core.h" - -#include "ccnl-ext.h" -#include "ccnl-platform.h" - -#include "ccnl-core.h" - -#include "ccnl-pdu.h" - -#include "msg.h" -#include "thread.h" -#include "transceiver.h" -#include "vtimer.h" - -#include "ccnl-riot-compat.h" -#include "ccn_lite/test_data/text.txt.ccnb.h" - -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X -#include "ieee802154_frame.h" -#endif - -/** The size of the message queue between router daemon and transceiver AND clients */ -#define RELAY_MSG_BUFFER_SIZE (64) - -/** message buffer */ -msg_t msg_buffer_relay[RELAY_MSG_BUFFER_SIZE]; - -struct ccnl_relay_s *theRelay = NULL; - -struct timeval * -ccnl_run_events(void) -{ - static struct timeval now; - ccnl_get_timeval(&now); - //DEBUGMSG(1, "ccnl_run_events now: %ld:%ld\n", now.tv_sec, now.tv_usec); - - while (eventqueue) { - struct ccnl_timer_s *t = eventqueue; - long usec = timevaldelta(&(t->timeout), &now); - - if (usec >= 0) { - //DEBUGMSG(1, "ccnl_run_events nothing to do: %ld:%ld\n", now.tv_sec, now.tv_usec); - now.tv_sec = usec / 1000000; - now.tv_usec = usec % 1000000; - return &now; - } - - //DEBUGMSG(1, "ccnl_run_events run event handler: %ld:%ld\n", now.tv_sec, now.tv_usec); - if (t->fct) { - (t->fct)(t->node, t->intarg); - } - else if (t->fct2) { - (t->fct2)(t->aux1, t->aux2); - } - - eventqueue = t->next; - ccnl_free(t); - } - - return NULL; -} - -/* ---------------------------------------------------------------------- */ - -int ccnl_open_riotmsgdev(void) -{ - return RIOT_MSG_DEV; -} - -int ccnl_open_riottransdev(void) -{ - return RIOT_TRANS_DEV; -} - -void ccnl_ll_TX(struct ccnl_relay_s *ccnl, struct ccnl_if_s *ifc, - sockunion *dest, struct ccnl_buf_s *buf) -{ - (void) ccnl; /* unused */ - - ifc->sendfunc(buf->data, (uint16_t) buf->datalen, (uint16_t) dest->id); -} - -/* ---------------------------------------------------------------------- */ - -void ccnl_ageing(void *relay, void *aux) -{ - ccnl_do_ageing(relay, aux); - ccnl_set_timer(TIMEOUT_TO_US(CCNL_CHECK_TIMEOUT_SEC, CCNL_CHECK_TIMEOUT_USEC), - ccnl_ageing, relay, 0); -} - -void ccnl_retransmit(void *relay, void *aux) -{ - ccnl_do_retransmit(relay, aux); - ccnl_set_timer(TIMEOUT_TO_US(CCNL_CHECK_RETRANSMIT_SEC, - CCNL_CHECK_RETRANSMIT_USEC), ccnl_retransmit, relay, 0); -} - -void ccnl_nonce_timeout(void *relay, void *aux) -{ - ccnl_do_nonce_timeout(relay, aux); - ccnl_set_timer(TIMEOUT_TO_US(CCNL_NONCE_TIMEOUT_SEC, - CCNL_NONCE_TIMEOUT_USEC), ccnl_nonce_timeout, relay, 0); -} - -/* ---------------------------------------------------------------------- */ - -void ccnl_relay_config(struct ccnl_relay_s *relay, int max_cache_entries, - int fib_threshold_prefix, int fib_threshold_aggregate) -{ - struct ccnl_if_s *i; - - DEBUGMSG(99, "ccnl_relay_config\n"); - - relay->max_cache_entries = max_cache_entries; - relay->fib_threshold_prefix = fib_threshold_prefix; - relay->fib_threshold_aggregate = fib_threshold_aggregate; - - if (RIOT_MSG_IDX != relay->ifcount) { - DEBUGMSG(1, "sorry, idx did not match: riot msg device\n"); - } - - i = &relay->ifs[relay->ifcount]; - i->sock = ccnl_open_riotmsgdev(); - i->sendfunc = &riot_send_msg; - i->mtu = 4000; - i->reflect = 0; - i->fwdalli = 0; - - if (i->sock >= 0) { - relay->ifcount++; - - if (relay->defaultInterfaceScheduler) { - i->sched = relay->defaultInterfaceScheduler(relay, - ccnl_interface_CTS); - } - } - else { - DEBUGMSG(1, "sorry, could not open riot msg device\n"); - } - - if (RIOT_TRANS_IDX != relay->ifcount) { - DEBUGMSG(1, "sorry, idx did not match: riot trans device\n"); - } - - i = &relay->ifs[relay->ifcount]; - i->sock = ccnl_open_riottransdev(); - i->sendfunc = &riot_send_transceiver; -#ifdef USE_FRAG - i->mtu = 120; -#else - i->mtu = 1500; -#endif - i->reflect = 0; - i->fwdalli = 0; - - if (i->sock >= 0) { - relay->ifcount++; - - if (relay->defaultInterfaceScheduler) { - i->sched = relay->defaultInterfaceScheduler(relay, - ccnl_interface_CTS); - } - } - else { - DEBUGMSG(1, "sorry, could not open riot trans device\n"); - } - - /* create default boardcast face on transceiver interface */ - struct ccnl_face_s * f = ccnl_get_face_or_create(relay, RIOT_TRANS_IDX, RIOT_BROADCAST); - f->flags |= CCNL_FACE_FLAGS_STATIC; - i->broadcast_face = f; - - ccnl_set_timer(TIMEOUT_TO_US(CCNL_CHECK_TIMEOUT_SEC, CCNL_CHECK_TIMEOUT_USEC), - ccnl_ageing, relay, 0); - ccnl_set_timer(TIMEOUT_TO_US(CCNL_CHECK_RETRANSMIT_SEC, CCNL_CHECK_RETRANSMIT_USEC), - ccnl_retransmit, relay, 0); - ccnl_set_timer(TIMEOUT_TO_US(CCNL_NONCE_TIMEOUT_SEC, CCNL_NONCE_TIMEOUT_USEC), - ccnl_nonce_timeout, relay, 0); -} - -#if RIOT_CCNL_POPULATE - -void ccnl_populate_cache(struct ccnl_relay_s *ccnl, unsigned char *buf, int datalen) -{ - if (buf[0] == 0x04 && buf[1] == 0x82) { - struct ccnl_prefix_s *prefix = 0; - struct ccnl_content_s *c = 0; - struct ccnl_buf_s *nonce = 0, *ppkd = 0, *pkt = 0; - unsigned char *content, *data = buf + 2; - int contlen; - - datalen -= 2; - - pkt = ccnl_extract_prefix_nonce_ppkd(&data, &datalen, 0, 0, - 0, 0, &prefix, &nonce, &ppkd, - &content, &contlen); - - if (!pkt) { - DEBUGMSG(6, " parsing error\n"); - goto Done; - } - - if (!prefix) { - DEBUGMSG(6, " no prefix error\n"); - goto Done; - } - - printf("populating: %s\n", ccnl_prefix_to_path(prefix)); - - c = ccnl_content_new(ccnl, &pkt, &prefix, &ppkd, content, - contlen); - - if (!c) { - goto Done; - } - - c->flags |= CCNL_CONTENT_FLAGS_STATIC; - if (!ccnl_content_add2cache(ccnl, c)) { - /* content store error */ - free_content(c); - } - - Done: - free_prefix(prefix); - ccnl_free(pkt); - ccnl_free(nonce); - ccnl_free(ppkd); - } - else { - DEBUGMSG(6, " not a content object\n"); - } -} - -void handle_populate_cache(struct ccnl_relay_s *ccnl) -{ - DEBUGMSG(1, "ccnl_populate_cache with: text_txt_ccnb\n"); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_0, (int) text_txt_ccnb_0_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_1, (int) text_txt_ccnb_1_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_2, (int) text_txt_ccnb_2_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_3, (int) text_txt_ccnb_3_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_4, (int) text_txt_ccnb_4_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_5, (int) text_txt_ccnb_5_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_6, (int) text_txt_ccnb_6_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_7, (int) text_txt_ccnb_7_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_8, (int) text_txt_ccnb_8_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_9, (int) text_txt_ccnb_9_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_10, (int) text_txt_ccnb_10_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_11, (int) text_txt_ccnb_11_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_12, (int) text_txt_ccnb_12_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_13, (int) text_txt_ccnb_13_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_14, (int) text_txt_ccnb_14_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_15, (int) text_txt_ccnb_15_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_16, (int) text_txt_ccnb_16_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_17, (int) text_txt_ccnb_17_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_18, (int) text_txt_ccnb_18_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_19, (int) text_txt_ccnb_19_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_20, (int) text_txt_ccnb_20_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_21, (int) text_txt_ccnb_21_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_22, (int) text_txt_ccnb_22_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_23, (int) text_txt_ccnb_23_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_24, (int) text_txt_ccnb_24_len); - ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_25, (int) text_txt_ccnb_25_len); -} - -#endif - -/* ---------------------------------------------------------------------- */ - -int ccnl_io_loop(struct ccnl_relay_s *ccnl) -{ - if (ccnl->ifcount == 0) { - DEBUGMSG(1, "no socket to work with, not good, quitting\n"); - return -1; - } - - DEBUGMSG(1, "starting main event and IO loop\n"); - - if (msg_init_queue(msg_buffer_relay, RELAY_MSG_BUFFER_SIZE) != 0) { - DEBUGMSG(1, "msg init queue failed...abording\n"); - return -1; - } - - msg_t in; -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X - ieee802154_packet_t *p; -#else - radio_packet_t *p; -#endif - riot_ccnl_msg_t *m; - - while (!ccnl->halt_flag) { - - msg_receive(&in); - - mutex_lock(&ccnl->global_lock); - switch (in.type) { - case PKT_PENDING: - /* msg from transceiver */ -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X - p = (ieee802154_packet_t*) in.content.ptr; - DEBUGMSG(1, "\tLength:\t%u\n", p->length); - DEBUGMSG(1, "\tSrc:\t%u\n", - (p->frame.src_addr[0]) | (p->frame.src_addr[1] << 8)); - DEBUGMSG(1, "\tDst:\t%u\n", - (p->frame.dest_addr[0]) | (p->frame.dest_addr[1] << 8)); -#else - p = (radio_packet_t *) in.content.ptr; - DEBUGMSG(1, "\tLength:\t%u\n", p->length); - DEBUGMSG(1, "\tSrc:\t%u\n", p->src); - DEBUGMSG(1, "\tDst:\t%u\n", p->dst); -#endif - - /* p->src must be > 0 */ -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X - if ((!(p->frame.src_addr[0])) | (p->frame.src_addr[1] << 8)) { - p->frame.src_addr[0] = RIOT_BROADCAST >> 8; - p->frame.src_addr[1] = RIOT_BROADCAST && 0xFF; - } -#else - if (!p->src) { - p->src = RIOT_BROADCAST; - } -#endif - -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X - uint16_t src_addr = ((p->frame.src_addr[1] << 8) | p->frame.src_addr[0]); - ccnl_core_RX(ccnl, RIOT_TRANS_IDX, - (unsigned char *) p->frame.payload, - (int) p->frame.payload_len, - src_addr); -#else - ccnl_core_RX(ccnl, RIOT_TRANS_IDX, - (unsigned char *) p->data, - (int) p->length, p->src); -#endif - p->processing--; - break; - - case (CCNL_RIOT_MSG): - /* msg from device local client */ - m = (riot_ccnl_msg_t *) in.content.ptr; - DEBUGMSG(1, "\tLength:\t%u\n", m->size); - DEBUGMSG(1, "\tSrc:\t%u\n", in.sender_pid); - - ccnl_core_RX(ccnl, RIOT_MSG_IDX, (unsigned char *) m->payload, m->size, - in.sender_pid); - break; - - case (CCNL_RIOT_HALT): - /* cmd to stop the relay */ - DEBUGMSG(1, "\tSrc:\t%" PRIkernel_pid "\n", in.sender_pid); - DEBUGMSG(1, "\tNumb:\t%" PRIu32 "\n", in.content.value); - - ccnl->halt_flag = 1; - break; - -#if RIOT_CCNL_POPULATE - case (CCNL_RIOT_POPULATE): - /* cmd to polulate the cache */ - DEBUGMSG(1, "\tSrc:\t%" PRIkernel_pid "\n", in.sender_pid); - DEBUGMSG(1, "\tNumb:\t%" PRIu32 "\n", in.content.value); - - handle_populate_cache(ccnl); - break; -#endif -#if ENABLE_DEBUG - case (CCNL_RIOT_PRINT_STAT): - /* cmd to print face statistics */ - for (struct ccnl_face_s *f = ccnl->faces; f; f = f->next) { - ccnl_face_print_stat(f); - } - break; -#endif - case (CCNL_RIOT_CONFIG_CACHE): - /* cmd to configure the size of the cache at runtime */ - ccnl->max_cache_entries = in.content.value; - DEBUGMSG(1, "max_cache_entries set to %d\n", ccnl->max_cache_entries); - break; - case (ENOBUFFER): - /* transceiver has not enough buffer to store incoming packets, - * one packet is dropped */ - DEBUGMSG(1, "transceiver: one packet is dropped because buffers are full\n"); - break; - default: - DEBUGMSG(1, "%s Packet waiting\n", riot_ccnl_event_to_string(in.type)); - DEBUGMSG(1, "\tSrc:\t%" PRIkernel_pid "\n", in.sender_pid); - DEBUGMSG(1, "\tdropping it...\n"); - break; - } - mutex_unlock(&ccnl->global_lock); - } - - return 0; -} - -/** - * @brief initializing routing system - * @param pointer to count transceiver pids - * - */ -void *ccnl_riot_relay_start(void *arg) -{ - (void) arg; - - theRelay = calloc(1, sizeof(struct ccnl_relay_s)); - ccnl_get_timeval(&theRelay->startup_time); - theRelay->riot_pid = sched_active_pid; - mutex_init(&theRelay->global_lock); - - DEBUGMSG(1, "This is ccn-lite-relay, starting at %lu:%lu\n", - theRelay->startup_time.tv_sec, theRelay->startup_time.tv_usec); - DEBUGMSG(1, " compile time: %s %s\n", __DATE__, __TIME__); - DEBUGMSG(1, " max_cache_entries: %d\n", CCNL_DEFAULT_MAX_CACHE_ENTRIES); - DEBUGMSG(1, " threshold_prefix: %d\n", CCNL_DEFAULT_THRESHOLD_PREFIX); - DEBUGMSG(1, " threshold_aggregate: %d\n", CCNL_DEFAULT_THRESHOLD_AGGREGATE); - - ccnl_relay_config(theRelay, - CCNL_DEFAULT_MAX_CACHE_ENTRIES, - CCNL_DEFAULT_THRESHOLD_PREFIX, - CCNL_DEFAULT_THRESHOLD_AGGREGATE); - - theRelay->riot_helper_pid = riot_start_helper_thread(); - - ccnl_io_loop(theRelay); - DEBUGMSG(1, "ioloop stopped\n"); - - while (eventqueue) { - ccnl_rem_timer(eventqueue); - } - - ccnl_core_cleanup(theRelay); - - mutex_lock(&theRelay->stop_lock); - ccnl_free(theRelay); - return NULL; -} - -void *ccnl_riot_relay_helper_start(void *arg) -{ - (void) arg; - unsigned long us = CCNL_CHECK_RETRANSMIT_USEC; - mutex_lock(&theRelay->stop_lock); - while (!theRelay->halt_flag) { - mutex_lock(&theRelay->global_lock); - ccnl_run_events(); - mutex_unlock(&theRelay->global_lock); - - vtimer_usleep(us); - } - - mutex_unlock(&theRelay->stop_lock); - return NULL; -} diff --git a/sys/net/ccn_lite/ccnl-core.c b/sys/net/ccn_lite/ccnl-core.c deleted file mode 100644 index eb9e309282..0000000000 --- a/sys/net/ccn_lite/ccnl-core.c +++ /dev/null @@ -1,1498 +0,0 @@ -/* - * @f ccnl-core.c - * @b CCN lite, core CCNx protocol logic - * - * Copyright (C) 2011-13, Christian Tschudin, University of Basel - * Copyright (C) 2013, Christian Mehlis, Freie Universität Berlin - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * File history: - * 2011-04-09 created - */ - -#define CCNL_VERSION "2013-07-27" - -#include -#include - -#include "ccnl.h" -#include "ccnl-core.h" -#include "ccnl-pdu.h" -#include "ccnx.h" -#include "ccnl-ext.h" -#include "ccnl-platform.h" - -#include "ccnl-includes.h" - -#include "ccnl-riot-compat.h" - -#define CCNL_DYNAMIC_FIB (0) - -static struct ccnl_interest_s *ccnl_interest_remove(struct ccnl_relay_s *ccnl, - struct ccnl_interest_s *i); - -void ccnl_ll_TX(struct ccnl_relay_s *ccnl, struct ccnl_if_s *ifc, - sockunion *dest, struct ccnl_buf_s *buf); - -void free_2ptr_list(void *a, void *b) -{ - ccnl_free(a); - ccnl_free(b); -} - -void free_3ptr_list(void *a, void *b, void *c) -{ - ccnl_free(a); - ccnl_free(b); - ccnl_free(c); -} - -void free_4ptr_list(void *a, void *b, void *c, void *d) -{ - ccnl_free(a); - ccnl_free(b); - ccnl_free(c); - ccnl_free(d); -} - -void free_prefix(struct ccnl_prefix_s *p) -{ - if (p) { - free_4ptr_list(p->path, p->comp, p->complen, p); - } -} - -void free_content(struct ccnl_content_s *c) -{ - free_prefix(c->name); - free_2ptr_list(c->pkt, c); -} - -void free_forward(struct ccnl_forward_s *fwd) -{ - free_prefix(fwd->prefix); - ccnl_free(fwd); -} - -// ---------------------------------------------------------------------- -// datastructure support functions - -struct ccnl_buf_s * -ccnl_buf_new(void *data, int len) -{ - struct ccnl_buf_s *b = (struct ccnl_buf_s *) ccnl_malloc(sizeof(*b) + len); - - if (!b) { - return NULL; - } - - b->next = NULL; - b->datalen = len; - - if (data) { - memcpy(b->data, data, len); - } - - return b; -} - -struct ccnl_buf_s *buf_dup(struct ccnl_buf_s *B) -{ - return (B) ? ccnl_buf_new(B->data, B->datalen) : NULL; -} - -int buf_equal(struct ccnl_buf_s *X, struct ccnl_buf_s *Y) -{ - return ((X) && (Y) && (X->datalen == Y->datalen) && !memcmp(X->data, Y->data, X->datalen)); -} - -int ccnl_prefix_cmp(struct ccnl_prefix_s *name, unsigned char *md, - struct ccnl_prefix_s *p, int mode) -/* returns -1 if no match at all (all modes) or exact match failed - returns 0 if full match (CMP_EXACT) - returns n>0 for matched components (CMP_MATCH, CMP_LONGEST) */ -{ - int i, clen, nlen = name->compcnt + (md ? 1 : 0), rc = -1; - unsigned char *comp; - - if (mode == CMP_EXACT && nlen != p->compcnt) { - goto done; - } - - for (i = 0; i < nlen && i < p->compcnt; i++) { - comp = i < name->compcnt ? name->comp[i] : md; - clen = i < name->compcnt ? name->complen[i] : 32; // SHA256_DIGEST_LEN - - if (clen != p->complen[i] || memcmp(comp, p->comp[i], p->complen[i])) { - rc = mode == CMP_EXACT ? -1 : i; - goto done; - } - } - - rc = (mode == CMP_EXACT) ? 0 : i; -done: - DEBUGMSG(49, - "ccnl_prefix_cmp (mode=%d, nlen=%d, plen=%d, %d), name=%s: %d (%p)\n", - mode, nlen, p->compcnt, name->compcnt, ccnl_prefix_to_path(name), - rc, md); - return rc; -} - -// ---------------------------------------------------------------------- -// ccnb parsing support - -static int hunt_for_end(unsigned char **buf, int *len, unsigned char **valptr, - int *vallen) -{ - int typ, num; - - while (dehead(buf, len, &num, &typ) == 0) { - if (num == 0 && typ == 0) { - return 0; - } - - if (consume(typ, num, buf, len, valptr, vallen) < 0) { - return -1; - } - } - - return -1; -} - -int consume(int typ, int num, unsigned char **buf, int *len, - unsigned char **valptr, int *vallen) -{ - if (typ == CCN_TT_BLOB || typ == CCN_TT_UDATA) { - if (valptr) { - *valptr = *buf; - } - - if (vallen) { - *vallen = num; - } - - *buf += num, *len -= num; - return 0; - } - - if (typ == CCN_TT_DTAG || typ == CCN_TT_DATTR) { - return hunt_for_end(buf, len, valptr, vallen); - } - - // case CCN_TT_TAG, CCN_TT_ATTR: - // case DTAG, DATTR: - return -1; -} - -static int data2uint(unsigned char *cp, int len) -{ - int i, val; - - for (i = 0, val = 0; i < len; i++) - if (isdigit(cp[i])) { - val = 10 * val + cp[i] - '0'; - } - else { - return -1; - } - - return val; -} - -struct ccnl_nonce_s *ccnl_nonce_new(struct ccnl_buf_s *that) -{ - struct ccnl_nonce_s *n = (struct ccnl_nonce_s *) ccnl_malloc(sizeof(struct ccnl_nonce_s)); - - n->buf = buf_dup(that); - ccnl_get_timeval(&n->created); - - n->next = NULL; - n->prev = NULL; - - return n; -} - -struct ccnl_nonce_s *ccnl_nonce_remove(struct ccnl_relay_s *ccnl, struct ccnl_nonce_s *nonce) -{ - DEBUGMSG(99, "ccnl_nonce_remove: %u:%u:%u:%u\n", - nonce->buf->data[0], nonce->buf->data[1], nonce->buf->data[2], nonce->buf->data[3]); - - struct ccnl_nonce_s *next = nonce->next; - DBL_LINKED_LIST_REMOVE(ccnl->nonces, nonce); - - free(nonce->buf); - free(nonce); - - return next; -} - -struct ccnl_buf_s * -ccnl_extract_prefix_nonce_ppkd(unsigned char **data, int *datalen, int *scope, - int *aok, int *min, int *max, struct ccnl_prefix_s **prefix, - struct ccnl_buf_s **nonce, struct ccnl_buf_s **ppkd, - unsigned char **content, int *contlen) -{ - unsigned char *start = *data - 2, *cp; - int num, typ, len; - struct ccnl_prefix_s *p; - struct ccnl_buf_s *buf, *n = 0, *pub = 0; - DEBUGMSG(99, "ccnl_extract_prefix\n"); - - p = (struct ccnl_prefix_s *) ccnl_calloc(1, sizeof(struct ccnl_prefix_s)); - - if (!p) { - puts("can't get more memory from malloc, dropping ccn msg..."); - return NULL; - } - - p->comp = (unsigned char **) ccnl_malloc( - CCNL_MAX_NAME_COMP * sizeof(unsigned char **)); - p->complen = (int *) ccnl_malloc(CCNL_MAX_NAME_COMP * sizeof(int)); - - if (!p->comp || !p->complen) { - puts("can't get more memory from malloc, dropping ccn msg..."); - goto Bail; - } - - while (dehead(data, datalen, &num, &typ) == 0) { - if (num == 0 && typ == 0) { - break; // end - } - - if (typ == CCN_TT_DTAG) { - if (num == CCN_DTAG_NAME) { - while (1) { - if (dehead(data, datalen, &num, &typ) != 0) { - goto Bail; - } - - if (num == 0 && typ == 0) { - break; - } - - if (typ == CCN_TT_DTAG && num == CCN_DTAG_COMPONENT - && p->compcnt < CCNL_MAX_NAME_COMP) { - if (hunt_for_end(data, datalen, p->comp + p->compcnt, - p->complen + p->compcnt) < 0) { - goto Bail; - } - - p->compcnt++; - } - else { - if (consume(typ, num, data, datalen, 0, 0) < 0) { - goto Bail; - } - } - } - - continue; - } - - if (num == CCN_DTAG_SCOPE || num == CCN_DTAG_NONCE - || num == CCN_DTAG_MINSUFFCOMP - || num == CCN_DTAG_MAXSUFFCOMP - || num == CCN_DTAG_PUBPUBKDIGEST) { - if (hunt_for_end(data, datalen, &cp, &len) < 0) { - goto Bail; - } - - if (num == CCN_DTAG_SCOPE && len == 1 && scope) { - *scope = isdigit(*cp) && (*cp < '3') ? *cp - '0' : -1; - } - - if (num == CCN_DTAG_ANSWERORIGKIND && aok) { - *aok = data2uint(cp, len); - } - - if (num == CCN_DTAG_MINSUFFCOMP && min) { - *min = data2uint(cp, len); - } - - if (num == CCN_DTAG_MAXSUFFCOMP && max) { - *max = data2uint(cp, len); - } - - if (num == CCN_DTAG_NONCE && !n) { - n = ccnl_buf_new(cp, len); - } - - if (num == CCN_DTAG_PUBPUBKDIGEST && !pub) { - pub = ccnl_buf_new(cp, len); - } - - if (num == CCN_DTAG_EXCLUDE) { - DEBUGMSG(49, "warning: 'exclude' field ignored\n"); - } - else { - continue; - } - } - - if (num == CCN_DTAG_CONTENT || num == CCN_DTAG_CONTENTOBJ) { - if (consume(typ, num, data, datalen, content, contlen) < 0) { - goto Bail; - } - - continue; - } - } - - if (consume(typ, num, data, datalen, 0, 0) < 0) { - goto Bail; - } - } - - if (prefix) { - p->comp[p->compcnt] = NULL; - *prefix = p; - } - else { - free_prefix(p); - } - - if (nonce) { - *nonce = n; - } - else { - ccnl_free(n); - } - - if (ppkd) { - *ppkd = pub; - } - else { - ccnl_free(pub); - } - - buf = ccnl_buf_new(start, *data - start); - - if (!buf) { - puts("can't get more memory from malloc, dropping ccn msg..."); - goto Bail; - } - - // carefully rebase ptrs to new buf because of 64bit pointers: - if (content) { - *content = buf->data + (*content - start); - } - - for (num = 0; num < p->compcnt; num++) { - p->comp[num] = buf->data + (p->comp[num] - start); - } - - return buf; -Bail: - free_prefix(p); - free_2ptr_list(n, pub); - return NULL; -} - -// ---------------------------------------------------------------------- -// addresses, interfaces and faces - -static void ccnl_face_CTS(struct ccnl_relay_s *ccnl, struct ccnl_face_s *f); - -int ccnl_addr_cmp(sockunion *s1, sockunion *s2) -{ - return (s1->id == s2->id); -} - -struct ccnl_face_s * -ccnl_get_face_or_create(struct ccnl_relay_s *ccnl, int ifndx, uint16_t sender_id) -{ - struct ccnl_face_s *f; - - for (f = ccnl->faces; f; f = f->next) { - if (ifndx == f->ifndx && (f->faceid == sender_id)) { - DEBUGMSG(1, "face found! ifidx=%d sender_id=%d faceid=%d\n", ifndx, sender_id, f->faceid); - ccnl_get_timeval(&f->last_used); - return f; - } - } - - f = (struct ccnl_face_s *) ccnl_calloc(1, sizeof(struct ccnl_face_s)); - if (!f) { - return NULL; - } - - f->faceid = sender_id; - f->ifndx = ifndx; - - if (sender_id == RIOT_BROADCAST) { - f->flags |= CCNL_FACE_FLAGS_BROADCAST; - } - - if (ifndx >= 0) { - if (ccnl->defaultFaceScheduler) - f->sched = ccnl->defaultFaceScheduler(ccnl, - (void ( *)(void *, void *)) ccnl_face_CTS); - - if (ccnl->ifs[ifndx].reflect) { - f->flags |= CCNL_FACE_FLAGS_REFLECT; - } - - if (ccnl->ifs[ifndx].fwdalli) { - f->flags |= CCNL_FACE_FLAGS_FWDALLI; - } - } - - f->peer.id = sender_id; - -#ifdef USE_FRAG - - if (ifndx == RIOT_TRANS_IDX) { - // if newly created face, no fragment policy is defined yet - // turning on fragmentation for riot trans dev based faces - int flagval = CCNL_FACE_FLAGS_STATIC; - f->flags = flagval & - (CCNL_FACE_FLAGS_STATIC | CCNL_FACE_FLAGS_REFLECT); - - if (f->frag) { - ccnl_frag_destroy(f->frag); - f->frag = NULL; - } - - int mtu = ccnl->ifs[f->ifndx].mtu; - f->frag = ccnl_frag_new(CCNL_FRAG_CCNx2013, mtu); //TODO - } - -#endif - - ccnl_get_timeval(&f->last_used); - DBL_LINKED_LIST_ADD(ccnl->faces, f); - - return f; -} - -struct ccnl_face_s * -ccnl_face_remove(struct ccnl_relay_s *ccnl, struct ccnl_face_s *f) -{ - struct ccnl_face_s *f2; - struct ccnl_interest_s *pit; - struct ccnl_forward_s **ppfwd; - DEBUGMSG(1, "ccnl_face_remove relay=%p face=%p\n", (void *) ccnl, (void *) f); - - ccnl_sched_destroy(f->sched); - ccnl_frag_destroy(f->frag); - - for (pit = ccnl->pit; pit;) { - struct ccnl_pendint_s **ppend, *pend; - - if (pit->from == f) { - pit->from = NULL; - } - - for (ppend = &pit->pending; *ppend;) { - if ((*ppend)->face == f) { - pend = *ppend; - *ppend = pend->next; - ccnl_free(pend); - } - else { - ppend = &(*ppend)->next; - } - } - - if (pit->pending) { - pit = pit->next; - } - else { - pit = ccnl_interest_remove(ccnl, pit); - } - } - - for (ppfwd = &ccnl->fib; *ppfwd;) { - if ((*ppfwd)->face == f) { - struct ccnl_forward_s *pfwd = *ppfwd; - *ppfwd = pfwd->next; - - ccnl_forward_remove(ccnl, pfwd); - } - else { - ppfwd = &(*ppfwd)->next; - } - } - - while (f->outq) { - struct ccnl_buf_s *tmp = f->outq->next; - ccnl_free(f->outq); - f->outq = tmp; - } - -#if ENABLE_DEBUG - ccnl_face_print_stat(f); -#endif - - f2 = f->next; - DBL_LINKED_LIST_REMOVE(ccnl->faces, f); - ccnl_free(f); - return f2; -} - -#if ENABLE_DEBUG -void ccnl_face_print_stat(struct ccnl_face_s *f) -{ - DEBUGMSG(1, "ccnl_face_print_stat: faceid=%d ifndx=%d\n", f->faceid, f->ifndx); - DEBUGMSG(1, " STAT interest send=%d:%d:%d:%d:%d\n", f->stat.send_interest[0], - f->stat.send_interest[1], f->stat.send_interest[2], - f->stat.send_interest[3], f->stat.send_interest[4]); - - DEBUGMSG(1, " STAT content send=%d:%d:%d:%d:%d\n", f->stat.send_content[0], - f->stat.send_content[1], f->stat.send_content[2], - f->stat.send_content[3], f->stat.send_content[4]); - - DEBUGMSG(1, " STAT interest received=%d\n", f->stat.received_interest); - - DEBUGMSG(1, " STAT content received=%d\n", f->stat.received_content); -} -#endif - -void ccnl_interface_cleanup(struct ccnl_if_s *i) -{ - int j; - DEBUGMSG(99, "ccnl_interface_cleanup\n"); - - ccnl_sched_destroy(i->sched); - - for (j = 0; j < i->qlen; j++) { - struct ccnl_txrequest_s *r = i->queue - + (i->qfront + j) % CCNL_MAX_IF_QLEN; - ccnl_free(r->buf); - } -} - -// ---------------------------------------------------------------------- -// face and interface queues, scheduling - -void ccnl_interface_CTS(void *aux1, void *aux2) -{ - struct ccnl_relay_s *ccnl = (struct ccnl_relay_s *) aux1; - struct ccnl_if_s *ifc = (struct ccnl_if_s *) aux2; - struct ccnl_txrequest_s *r, req; - DEBUGMSG(25, "ccnl_interface_CTS interface=%p, qlen=%d, sched=%p\n", - (void *) ifc, ifc->qlen, (void *) ifc->sched); - - if (ifc->qlen <= 0) { - return; - } - - r = ifc->queue + ifc->qfront; - memcpy(&req, r, sizeof(req)); - ifc->qfront = (ifc->qfront + 1) % CCNL_MAX_IF_QLEN; - ifc->qlen--; - - ccnl_ll_TX(ccnl, ifc, &req.dst, req.buf); - ccnl_free(req.buf); -} - -void ccnl_interface_enqueue(void (tx_done)(void *, int, int), - struct ccnl_face_s *f, struct ccnl_relay_s *ccnl, struct ccnl_if_s *ifc, - struct ccnl_buf_s *buf, sockunion *dest) -{ - struct ccnl_txrequest_s *r; - DEBUGMSG(25, "ccnl_interface_enqueue interface=%p buf=%p (qlen=%d)\n", - (void *) ifc, (void *) buf, ifc->qlen); - - if (ifc->qlen >= CCNL_MAX_IF_QLEN) { - DEBUGMSG(2, " DROPPING buf=%p\n", (void *) buf); - ccnl_free(buf); - return; - } - - r = ifc->queue + ((ifc->qfront + ifc->qlen) % CCNL_MAX_IF_QLEN); - r->buf = buf; - memcpy(&r->dst, dest, sizeof(sockunion)); - r->txdone = tx_done; - r->txdone_face = f; - ifc->qlen++; - - ccnl_interface_CTS(ccnl, ifc); -} - -struct ccnl_buf_s * -ccnl_face_dequeue(struct ccnl_relay_s *ccnl, struct ccnl_face_s *f) -{ - (void) ccnl; /* unused */ - - struct ccnl_buf_s *pkt; - DEBUGMSG(20, "ccnl_face_dequeue face=%p (id=%d.%d)\n", (void *) f, ccnl->id, - f->faceid); - - if (!f->outq) { - return NULL; - } - - pkt = f->outq; - f->outq = pkt->next; - - if (!pkt->next) { - f->outqend = NULL; - } - - pkt->next = NULL; - return pkt; -} - -void ccnl_face_CTS_done(void *ptr, int cnt, int len) -{ - (void) ptr; - (void) cnt; - (void) len; - DEBUGMSG(99, "ccnl_face_CTS_done face=%p cnt=%d len=%d\n", ptr, cnt, len); -} - -void ccnl_face_CTS(struct ccnl_relay_s *ccnl, struct ccnl_face_s *f) -{ - DEBUGMSG(99, "ccnl_face_CTS face=%p sched=%p\n", (void *) f, - (void *) f->sched); - - if (!f->frag || f->frag->protocol == CCNL_FRAG_NONE) { - struct ccnl_buf_s *buf = ccnl_face_dequeue(ccnl, f); - - if (buf) - ccnl_interface_enqueue(ccnl_face_CTS_done, f, ccnl, - ccnl->ifs + f->ifndx, buf, &f->peer); - } - -#ifdef USE_FRAG - else { - sockunion dst; - int ifndx = f->ifndx; - buf = ccnl_frag_getnext(f->frag, &ifndx, &dst); - - if (!buf) { - buf = ccnl_face_dequeue(ccnl, f); - ccnl_frag_reset(f->frag, buf, f->ifndx, &f->peer); - buf = ccnl_frag_getnext(f->frag, &ifndx, &dst); - } - - if (buf) { - ccnl_interface_enqueue(ccnl_face_CTS_done, f, - ccnl, ccnl->ifs + ifndx, buf, &dst); - } - } - -#endif -} - -int ccnl_face_enqueue(struct ccnl_relay_s *ccnl, struct ccnl_face_s *to, - struct ccnl_buf_s *buf) -{ - struct ccnl_buf_s *msg; - DEBUGMSG(20, "ccnl_face_enqueue face=%p (id=%d.%d) buf=%p len=%d\n", - (void *) to, ccnl->id, to->faceid, (void *) buf, buf->datalen); - - for (msg = to->outq; msg; msg = msg->next) // already in the queue? - if (buf_equal(msg, buf)) { - DEBUGMSG(31, " not enqueued because already there\n"); - ccnl_free(buf); - return -1; - } - - buf->next = NULL; - - if (to->outqend) { - to->outqend->next = buf; - } - else { - to->outq = buf; - } - - to->outqend = buf; - ccnl_face_CTS(ccnl, to); - return 0; -} - -// ---------------------------------------------------------------------- -// handling of interest messages - -int ccnl_nonce_find_or_append(struct ccnl_relay_s *ccnl, - struct ccnl_buf_s *nonce) -{ - struct ccnl_nonce_s *n; - struct ccnl_nonce_s *last = NULL; - int i; - DEBUGMSG(99, "ccnl_nonce_find_or_append: %u:%u:%u:%u\n", - nonce->data[0], nonce->data[1], nonce->data[2], nonce->data[3]); - - /* test for noce in nonce cache */ - - for (n = ccnl->nonces, i = 0; n; n = n->next, i++) { - DEBUGMSG(1, "known: %u:%u:%u:%u\n", - n->buf->data[0], n->buf->data[1], n->buf->data[2], n->buf->data[3]); - if (buf_equal(n->buf, nonce)) { - /* nonce in cache -> known */ - return -1; - } - if (n->next) { - last = n->next; - } - } - - /* nonce not in local cache, add it */ - n = ccnl_nonce_new(nonce); - DBL_LINKED_LIST_ADD(ccnl->nonces, n); - - /* nonce chache full? */ - if (i >= CCNL_MAX_NONCES) { - /* cache is full, drop oldest nonce: its the last element in the list */ - ccnl_nonce_remove(ccnl, last); - } - - return 0; -} - -struct ccnl_interest_s * -ccnl_interest_new(struct ccnl_relay_s *ccnl, struct ccnl_face_s *from, - struct ccnl_buf_s **pkt, struct ccnl_prefix_s **prefix, int minsuffix, - int maxsuffix, struct ccnl_buf_s **ppkd) -{ - struct ccnl_interest_s *i = (struct ccnl_interest_s *) ccnl_calloc(1, - sizeof(struct ccnl_interest_s)); - DEBUGMSG(99, "ccnl_new_interest\n"); - - if (!i) { - puts("can't get more memory from malloc, dropping ccn msg..."); - return NULL; - } - - i->from = from; - i->prefix = *prefix; - *prefix = 0; - i->pkt = *pkt; - *pkt = 0; - i->ppkd = *ppkd; - *ppkd = 0; - i->minsuffix = minsuffix; - i->maxsuffix = maxsuffix; - ccnl_get_timeval(&i->last_used); - DBL_LINKED_LIST_ADD(ccnl->pit, i); - return i; -} - -int ccnl_interest_append_pending(struct ccnl_interest_s *i, - struct ccnl_face_s *from) -{ - struct ccnl_pendint_s *pi, *last = NULL; - DEBUGMSG(99, "ccnl_append_pending\n"); - - for (pi = i->pending; pi; pi = pi->next) { // check whether already listed - if (pi->face == from) { - DEBUGMSG(40, " we found a matching interest, updating time\n"); - ccnl_get_timeval(&pi->last_used); - return 0; - } - - last = pi; - } - - pi = (struct ccnl_pendint_s *) ccnl_calloc(1, - sizeof(struct ccnl_pendint_s)); - DEBUGMSG(40, " appending a new pendint entry %p\n", (void *) pi); - - if (!pi) { - return -1; - } - - pi->face = from; - ccnl_get_timeval(&pi->last_used); - - if (last) { - last->next = pi; - } - else { - i->pending = pi; - } - - return 0; -} - -void ccnl_interest_propagate(struct ccnl_relay_s *ccnl, - struct ccnl_interest_s *i) -{ - struct ccnl_forward_s *fwd; - DEBUGMSG(99, "ccnl_interest_propagate\n"); - - // CONFORM: "A node MUST implement some strategy rule, even if it is only to - // transmit an Interest Message on all listed dest faces in sequence." - // CCNL strategy: we forward on all FWD entries with a prefix match - int forward_cnt = 0; - for (fwd = ccnl->fib; fwd; fwd = fwd->next) { - int rc = ccnl_prefix_cmp(fwd->prefix, NULL, i->prefix, CMP_LONGEST); - DEBUGMSG(40, " ccnl_interest_propagate, rc=%d/%d\n", rc, - fwd->prefix->compcnt); - - if (rc < fwd->prefix->compcnt) { - continue; - } - - DEBUGMSG(40, " ccnl_interest_propagate, fwd==%p\n", (void *) fwd); - - // suppress forwarding to origin of interest, except wireless - if (!i->from || fwd->face != i->from - || (i->from->flags & CCNL_FACE_FLAGS_REFLECT)) { - - i->forwarded_over = fwd; - fwd->face->stat.send_interest[i->retries]++; - ccnl_get_timeval(&i->last_used); - ccnl_face_enqueue(ccnl, fwd->face, buf_dup(i->pkt)); - ccnl_get_timeval(&fwd->last_used); - forward_cnt++; - } - } - - if (forward_cnt == 0) { - DEBUGMSG(40, " ccnl_interest_propagate: using broadcast face!\n"); - ccnl->ifs[RIOT_TRANS_IDX].broadcast_face->stat.send_interest[i->retries]++; - ccnl_get_timeval(&i->last_used); - ccnl_face_enqueue(ccnl, ccnl->ifs[RIOT_TRANS_IDX].broadcast_face, buf_dup(i->pkt)); - } - - return; -} - -struct ccnl_interest_s * -ccnl_interest_remove(struct ccnl_relay_s *ccnl, struct ccnl_interest_s *i) -{ - struct ccnl_interest_s *i2; - DEBUGMSG(40, "ccnl_interest_remove %p\n", (void *) i); - - while (i->pending) { - struct ccnl_pendint_s *tmp = i->pending->next; - ccnl_free(i->pending); - i->pending = tmp; - } - - i2 = i->next; - DBL_LINKED_LIST_REMOVE(ccnl->pit, i); - free_prefix(i->prefix); - free_3ptr_list(i->ppkd, i->pkt, i); - return i2; -} - -// ---------------------------------------------------------------------- -// handling of content messages - -int ccnl_i_prefixof_c(struct ccnl_prefix_s *prefix, struct ccnl_buf_s *ppkd, - int minsuffix, int maxsuffix, struct ccnl_content_s *c) -{ - unsigned char *md; - DEBUGMSG(99, "ccnl_i_prefixof_c prefix=%s min=%d max=%d\n", - ccnl_prefix_to_path(prefix), minsuffix, maxsuffix); - - // CONFORM: we do prefix match, honour min. and maxsuffix, - // and check the PublisherPublicKeyDigest if present - - // NON-CONFORM: "Note that to match a ContentObject must satisfy - // all of the specifications given in the Interest Message." - // >> CCNL does not honour the exclusion filtering - - if ((ppkd && !buf_equal(ppkd, c->ppkd)) - || (prefix->compcnt + minsuffix) > (c->name->compcnt + 1) - || (prefix->compcnt + maxsuffix) < (c->name->compcnt + 1)) { - return 0; - } - - md = NULL; - - if ((prefix->compcnt - c->name->compcnt) == 1) { - md = compute_ccnx_digest(c->pkt); - } - - return ccnl_prefix_cmp(c->name, md, prefix, CMP_MATCH) == prefix->compcnt; -} - -struct ccnl_content_s * -ccnl_content_new(struct ccnl_relay_s *ccnl, struct ccnl_buf_s **pkt, - struct ccnl_prefix_s **prefix, struct ccnl_buf_s **ppkd, - unsigned char *content, int contlen) -{ - - (void) ccnl; /* unused */ - - struct ccnl_content_s *c; - // DEBUGMSG(99, "ccnl_content_new <%s>\n", - // prefix == NULL ? NULL : ccnl_prefix_to_path(*prefix)); - - c = (struct ccnl_content_s *) ccnl_calloc(1, sizeof(struct ccnl_content_s)); - - if (!c) { - return NULL; - } - - ccnl_get_timeval(&c->last_used); - c->content = content; - c->contentlen = contlen; - c->pkt = *pkt; - *pkt = NULL; - c->name = *prefix; - *prefix = NULL; - - if (ppkd) { - c->ppkd = *ppkd; - *ppkd = NULL; - } - - return c; -} - -struct ccnl_content_s * -ccnl_content_remove(struct ccnl_relay_s *ccnl, struct ccnl_content_s *c) -{ - struct ccnl_content_s *c2; - DEBUGMSG(99, "ccnl_content_remove: %s\n", ccnl_prefix_to_path(c->name)); - - c2 = c->next; - DBL_LINKED_LIST_REMOVE(ccnl->contents, c); - free_content(c); - ccnl->contentcnt--; - return c2; -} - -struct ccnl_content_s * -ccnl_content_add2cache(struct ccnl_relay_s *ccnl, struct ccnl_content_s *c) -{ - DEBUGMSG(99, "ccnl_content_add2cache (%d/%d)\n", ccnl->contentcnt, - ccnl->max_cache_entries); - - if (ccnl->max_cache_entries <= 0) { - DEBUGMSG(1, " content store disabled...\n"); - return NULL; - } - - while (ccnl->max_cache_entries <= ccnl->contentcnt) { - DEBUGMSG(1, " remove Least Recently Used content...\n"); - struct ccnl_content_s *c2, *lru = NULL; - - for (c2 = ccnl->contents; c2; c2 = c2->next) { - DEBUGMSG(1, " '%s' -> %ld:%ld\n", ccnl_prefix_to_path(c2->name), c2->last_used.tv_sec, c2->last_used.tv_usec); - if (!(c2->flags & CCNL_CONTENT_FLAGS_STATIC) - && ((!lru) || timevaldelta(&c2->last_used, &lru->last_used) < 0)) { - lru = c2; - } - } - - if (lru) { - DEBUGMSG(1, " replaced: '%s'\n", ccnl_prefix_to_path(lru->name)); - ccnl_content_remove(ccnl, lru); - } - else { - DEBUGMSG(1, " no dynamic content to remove...\n"); - break; - } - } - - DEBUGMSG(1, " add new content to store: '%s'\n", ccnl_prefix_to_path(c->name)); - DBL_LINKED_LIST_ADD(ccnl->contents, c); - ccnl->contentcnt++; - return c; -} - -// deliver new content c to all clients with (loosely) matching interest, -// but only one copy per face -// returns: number of forwards -int ccnl_content_serve_pending(struct ccnl_relay_s *ccnl, - struct ccnl_content_s *c, - struct ccnl_face_s *from) -{ - struct ccnl_interest_s *i; - struct ccnl_face_s *f; - int cnt = 0; - DEBUGMSG(99, "ccnl_content_serve_pending\n"); - - for (f = ccnl->faces; f; f = f->next) { - f->flags &= ~CCNL_FACE_FLAGS_SERVED; // reply on a face only once - } - - for (i = ccnl->pit; i;) { - struct ccnl_pendint_s *pi; - - if (!ccnl_i_prefixof_c(i->prefix, i->ppkd, i->minsuffix, i->maxsuffix, - c)) { - i = i->next; - continue; - } - - // CONFORM: "Data MUST only be transmitted in response to - // an Interest that matches the Data." - for (pi = i->pending; pi; pi = pi->next) { - if (pi->face->flags & CCNL_FACE_FLAGS_SERVED) { - continue; - } - - if (pi->face == from) { - // the existing pending interest is from the same face - // as the newly arrived content is...no need to send content back - DEBUGMSG(1, " detected looping content, before loop could happen\n"); - continue; - } - - pi->face->flags |= CCNL_FACE_FLAGS_SERVED; - - DEBUGMSG(6, " forwarding content <%s>\n", - ccnl_prefix_to_path(c->name)); - pi->face->stat.send_content[c->served_cnt % CCNL_MAX_CONTENT_SERVED_STAT]++; - ccnl_face_enqueue(ccnl, pi->face, buf_dup(c->pkt)); - - c->served_cnt++; - ccnl_get_timeval(&c->last_used); - cnt++; - } - - i = ccnl_interest_remove(ccnl, i); - } - - return cnt; -} - -/** - * returns an entry from the fib which has a common prefix with p. - * only returns that entry if it fullfils the aggregate threshold! - */ -struct ccnl_forward_s *ccn_forward_find_common_prefix_to_aggregate(struct ccnl_relay_s *ccnl, struct ccnl_prefix_s *p, int *match_len) -{ - if (!ccnl->fib) { - DEBUGMSG(999, "ccn_forward_find_common_prefix: fib was empty\n"); - return NULL; - } - - /* fib as at least one enty */ - struct ccnl_forward_s *fwd2 = ccnl->fib; - while (fwd2) { - DEBUGMSG(1, "ccn_forward_find_common_prefix: '%s' vs. '%s'\n", ccnl_prefix_to_path(p), ccnl_prefix_to_path(fwd2->prefix)); - *match_len = ccnl_prefix_cmp(fwd2->prefix, 0, p, CMP_LONGEST); - - /* check for threshold and never date up a static enty */ - if ((ccnl->fib_threshold_aggregate <= *match_len) && !(fwd2->flags & CCNL_FORWARD_FLAGS_STATIC)) { - return fwd2; - } - - fwd2 = fwd2->next; - } - - return NULL; -} - -static struct ccnl_forward_s *ccnl_forward_new(struct ccnl_prefix_s *p, struct ccnl_face_s *f, int threshold_prefix, int flags) -{ - struct ccnl_forward_s *fwd = ccnl_calloc(1, sizeof(struct ccnl_forward_s)); - fwd->prefix = ccnl_prefix_clone_strip(p, threshold_prefix); - fwd->face = f; - fwd->flags = flags; - return fwd; -} - -void ccnl_content_learn_name_route(struct ccnl_relay_s *ccnl, struct ccnl_prefix_s *p, struct ccnl_face_s *f, int threshold_prefix, int flags) -{ - /* - * we want to insert a new dynamic route in the fib, let's try to aggregate! - * for aggregation we ask the fib for a prefix match - */ - int match_len; - struct ccnl_forward_s *fwd = ccn_forward_find_common_prefix_to_aggregate(ccnl, p, &match_len); - if (!fwd) { - /* there was no prefix match with the user defined creteria. */ - - /* create a new fib entry */ - fwd = ccnl_forward_new(p, f, threshold_prefix, flags); - DBL_LINKED_LIST_ADD(ccnl->fib, fwd); - DEBUGMSG(999, "ccnl_content_learn_name_route: new route '%s' on face %d learned\n", ccnl_prefix_to_path(fwd->prefix), f->faceid); - } - else { - /* there was a prefix match with the user defined creteria. */ - - /* if the new entry has shorter prefix */ - if (p->compcnt < fwd->prefix->compcnt) { - /* we need to aggregate! */ - DBL_LINKED_LIST_REMOVE(ccnl->fib, fwd); - - /* create a new fib entry */ - fwd = ccnl_forward_new(p, f, (p->compcnt - match_len), flags); - DBL_LINKED_LIST_ADD(ccnl->fib, fwd); - DEBUGMSG(999, "ccnl_content_learn_name_route: route '%s' on face %d replaced\n", ccnl_prefix_to_path(fwd->prefix), f->faceid); - } - else { - /* we don't need to do an update, because we know a shorter prefix already */ - } - } - - /* refresh fwd entry */ - DEBUGMSG(999, "ccnl_content_learn_name_route refresh route '%s' on face %d\n", ccnl_prefix_to_path(fwd->prefix), f->faceid); - ccnl_get_timeval(&fwd->last_used); -} - -struct ccnl_forward_s * -ccnl_forward_remove(struct ccnl_relay_s *ccnl, struct ccnl_forward_s *fwd) -{ - struct ccnl_forward_s *fwd2; - DEBUGMSG(40, "ccnl_forward_remove %p\n", (void *) fwd); - - fwd2 = fwd->next; - DBL_LINKED_LIST_REMOVE(ccnl->fib, fwd); - - for (struct ccnl_interest_s *p = ccnl->pit; p; p = p->next) { - if (p->forwarded_over == fwd) { - p->forwarded_over = NULL; - } - } - DEBUGMSG(40, " ccnl_forward_remove next=%p\n", (void *) fwd2); - - free_forward(fwd); - return fwd2; -} - -bool ccnl_is_timed_out(struct timeval *now, struct timeval *last_used, uint32_t timeout_s, uint32_t timeout_us) -{ - timex_t time = timex_set(timeout_s, timeout_us); - timex_normalize(&time); - struct timeval abs_timeout = { last_used->tv_sec + time.seconds, last_used->tv_usec + time.microseconds }; - return timevaldelta(now, &abs_timeout) > 0; -} - -void ccnl_do_retransmit(void *ptr, void *dummy) -{ - (void) dummy; /* unused */ - - struct ccnl_relay_s *relay = (struct ccnl_relay_s *) ptr; - - for (struct ccnl_interest_s *i = relay->pit; i; i = i->next) { - // CONFORM: "Entries in the PIT MUST timeout rather - // than being held indefinitely." - if(i->retries <= CCNL_MAX_INTEREST_RETRANSMIT) { - // CONFORM: "A node MUST retransmit Interest Messages - // periodically for pending PIT entries." - DEBUGMSG(7, " retransmit %d <%s>\n", i->retries, - ccnl_prefix_to_path(i->prefix)); - - if (i->forwarded_over - && !(i->forwarded_over->flags & CCNL_FORWARD_FLAGS_STATIC) - && (i->retries >= CCNL_MAX_INTEREST_OPTIMISTIC)) { - DEBUGMSG(1, " removed dynamic forward %p\n", (void *) i->forwarded_over); - ccnl_forward_remove(relay, i->forwarded_over); - } - - i->retries++; - ccnl_interest_propagate(relay, i); - } - } -} - -void ccnl_do_nonce_timeout(void *ptr, void *dummy) -{ - (void) dummy; /* unused */ - - struct ccnl_relay_s *relay = (struct ccnl_relay_s *) ptr; - - struct timeval now; - ccnl_get_timeval(&now); - //DEBUGMSG(99, "ccnl_do_nonce_timeout: %lu:%lu\n", now.tv_sec, now.tv_usec); - - for (struct ccnl_nonce_s *n = relay->nonces; n;) { - if (ccnl_is_timed_out(&now, &n->created, CCNL_NONCE_TIMEOUT_SEC, CCNL_NONCE_TIMEOUT_USEC)) { - n = ccnl_nonce_remove(relay, n); - } else { - n = n->next; - } - } -} - -void ccnl_do_ageing(void *ptr, void *dummy) -{ - - (void) dummy; /* unused */ - - struct ccnl_relay_s *relay = (struct ccnl_relay_s *) ptr; - struct ccnl_interest_s *i = relay->pit; - struct ccnl_content_s *c = relay->contents; - - struct ccnl_face_s *f = relay->faces; - struct timeval now; - ccnl_get_timeval(&now); - //DEBUGMSG(999, "ccnl_do_ageing %ld:%ld\n", now.tv_sec, now.tv_usec); - - while (i) { - if (ccnl_is_timed_out(&now, &i->last_used, CCNL_INTEREST_TIMEOUT_SEC, - CCNL_INTEREST_TIMEOUT_USEC)) { - if (i->from->ifndx == RIOT_MSG_IDX) { - /* this interest was requested by an app from this node */ - /* inform this app about this problem */ - riot_send_nack(i->from->faceid); - } - i = ccnl_interest_remove(relay, i); - } - else { - i = i->next; - } - } - - while (c) { - if (ccnl_is_timed_out(&now, &c->last_used, CCNL_CONTENT_TIMEOUT_SEC, CCNL_CONTENT_TIMEOUT_USEC) - && !(c->flags & CCNL_CONTENT_FLAGS_STATIC)) { - c = ccnl_content_remove(relay, c); - } - else { - c = c->next; - } - } - - while (f) { - if (!(f->flags & CCNL_FACE_FLAGS_STATIC) - && ccnl_is_timed_out(&now, &f->last_used, CCNL_FACE_TIMEOUT_SEC, CCNL_FACE_TIMEOUT_USEC)) { - f = ccnl_face_remove(relay, f); - } - else { - f = f->next; - } - } - - struct ccnl_forward_s *fwd = relay->fib; - while (fwd) { - if (!(fwd->flags & CCNL_FORWARD_FLAGS_STATIC) - && ccnl_is_timed_out(&now, &fwd->last_used, CCNL_FWD_TIMEOUT_SEC, CCNL_FWD_TIMEOUT_USEC)) { - fwd = ccnl_forward_remove(relay, fwd); - } - else { - fwd = fwd->next; - } - } -} - -void ccnl_core_cleanup(struct ccnl_relay_s *ccnl) -{ - int k; - DEBUGMSG(99, "ccnl_core_cleanup %p\n", (void *) ccnl); - - while (ccnl->pit) { - ccnl_interest_remove(ccnl, ccnl->pit); - } - - while (ccnl->faces) { - ccnl_face_remove(ccnl, ccnl->faces); // also removes all FWD entries - } - - while (ccnl->contents) { - ccnl_content_remove(ccnl, ccnl->contents); - } - - while (ccnl->nonces) { - ccnl_nonce_remove(ccnl, ccnl->nonces); - } - - for (k = 0; k < ccnl->ifcount; k++) { - ccnl_interface_cleanup(ccnl->ifs + k); - } -} - -// ---------------------------------------------------------------------- -// the core logic of CCN: - -int ccnl_core_RX_i_or_c(struct ccnl_relay_s *relay, struct ccnl_face_s *from, - unsigned char **data, int *datalen) -{ - int rc = -1, scope = 3, aok = 3, minsfx = 0, maxsfx = CCNL_MAX_NAME_COMP, - contlen; - struct ccnl_buf_s *buf = 0, *nonce = 0, *ppkd = 0; - struct ccnl_interest_s *i = 0; - struct ccnl_content_s *c = 0; - struct ccnl_prefix_s *p = 0; - unsigned char *content = 0; - DEBUGMSG(1, "ccnl_core_RX_i_or_c: (%d bytes left)\n", *datalen); - - buf = ccnl_extract_prefix_nonce_ppkd(data, datalen, &scope, &aok, &minsfx, - &maxsfx, &p, &nonce, &ppkd, &content, &contlen); - - if (!buf) { - DEBUGMSG(6, " parsing error or no prefix\n"); - goto Done; - } - - if (nonce && ccnl_nonce_find_or_append(relay, nonce)) { - DEBUGMSG(6, " dropped because of duplicate nonce\n"); - goto Skip; - } - - if (buf->data[0] == 0x01 && buf->data[1] == 0xd2) { // interest - DEBUGMSG(1, "ccnl_core_RX_i_or_c: interest=<%s>\n", ccnl_prefix_to_path(p)); - from->stat.received_interest++; - - if (p->compcnt > 0 && p->comp[0][0] == (unsigned char) 0xc1) { - goto Skip; - } - - if (p->compcnt == 4 && !memcmp(p->comp[0], "ccnx", 4)) { - DEBUGMSG(1, "it's a mgnt msg!\n"); - rc = ccnl_mgmt(relay, buf, p, from); - DEBUGMSG(1, "mgnt processing done!\n"); - goto Done; - } - - // CONFORM: Step 1: - if (aok & 0x01) { // honor "answer-from-existing-content-store" flag - for (c = relay->contents; c; c = c->next) { - if (!ccnl_i_prefixof_c(p, ppkd, minsfx, maxsfx, c)) { - continue; - } - - // FIXME: should check stale bit in aok here - DEBUGMSG(7, " matching content for interest, content %p\n", - (void *) c); - from->stat.send_content[c->served_cnt % CCNL_MAX_CONTENT_SERVED_STAT]++; - c->served_cnt++; - - if (from->ifndx >= 0) { - ccnl_face_enqueue(relay, from, buf_dup(c->pkt)); - } - - goto Skip; - } - } - - // CONFORM: Step 2: check whether interest is already known - for (i = relay->pit; i; i = i->next) { - if (!ccnl_prefix_cmp(i->prefix, NULL, p, CMP_EXACT) - && i->minsuffix == minsfx && i->maxsuffix == maxsfx - && ((!ppkd && !i->ppkd) || buf_equal(ppkd, i->ppkd))) { - break; - } - } - - if (!i) { // this is a new/unknown I request: create and propagate - i = ccnl_interest_new(relay, from, &buf, &p, minsfx, maxsfx, &ppkd); - - if (i) { // CONFORM: Step 3 (and 4) - DEBUGMSG(7, " created new interest entry %p\n", (void *) i); - - if (scope > 2) { - ccnl_interest_propagate(relay, i); - } - } - } - else if (scope > 2 && (from->flags & CCNL_FACE_FLAGS_FWDALLI)) { - DEBUGMSG(7, " old interest, nevertheless propagated %p\n", - (void *) i); - ccnl_interest_propagate(relay, i); - } - - if (i) { // store the I request, for the incoming face (Step 3) - DEBUGMSG(7, " appending interest entry %p\n", (void *) i); - ccnl_interest_append_pending(i, from); - } - } - else { // content - DEBUGMSG(6, " content=<%s>\n", ccnl_prefix_to_path(p)); - from->stat.received_content++; - - // CONFORM: Step 1: - for (c = relay->contents; c; c = c->next) { - if (buf_equal(c->pkt, buf)) { - DEBUGMSG(1, "content is dup: skip\n"); - goto Skip; - } - } - - c = ccnl_content_new(relay, &buf, &p, &ppkd, content, contlen); - - if (c) { // CONFORM: Step 2 (and 3) - if (!ccnl_content_serve_pending(relay, c, from)) { // unsolicited content - // CONFORM: "A node MUST NOT forward unsolicited data [...]" - DEBUGMSG(7, " removed because no matching interest\n"); - free_content(c); - goto Skip; - } -#if CCNL_DYNAMIC_FIB - else { - /* content has matched an interest, we consider this name as available on this face */ - ccnl_content_learn_name_route(relay, c->name, from, relay->fib_threshold_prefix, 0); - } -#endif - - if (relay->max_cache_entries != 0) { // it's set to -1 or a limit - DEBUGMSG(7, " adding content to cache\n"); - ccnl_content_add2cache(relay, c); - } - else { - DEBUGMSG(7, " content not added to cache\n"); - free_content(c); - } - } - } - -Skip: - rc = 0; -Done: - free_prefix(p); - free_3ptr_list(buf, nonce, ppkd); - DEBUGMSG(1, "leaving\n"); - return rc; -} - -int ccnl_core_RX_datagram(struct ccnl_relay_s *relay, struct ccnl_face_s *from, - unsigned char **data, int *datalen) -{ - int rc = 0, num = 0, typ = 0; - DEBUGMSG(1, "ccnl_core_RX_datagram: %d bytes from face=%p (id=%d.%d)\n", - *datalen, (void *) from, relay->id, from ? from->faceid : -1); - - while (rc >= 0 && *datalen > 0) { - if (dehead(data, datalen, &num, &typ) || typ != CCN_TT_DTAG) { - return -1; - } - - switch (num) { - case CCN_DTAG_INTEREST: - /* no break */ - - case CCN_DTAG_CONTENTOBJ: - rc = ccnl_core_RX_i_or_c(relay, from, data, datalen); - continue; -#ifdef USE_FRAG - - case CCNL_DTAG_FRAGMENT2012: - rc = ccnl_frag_RX_frag2012(ccnl_core_RX_datagram, relay, from, data, datalen); - continue; - - case CCNL_DTAG_FRAGMENT: - rc = ccnl_frag_RX_CCNx2013(ccnl_core_RX_datagram, relay, from, data, datalen); - continue; -#endif - - default: - DEBUGMSG(15, " unknown datagram type %d\n", num); - return -1; - } - } - - return rc; -} - -void -ccnl_core_RX(struct ccnl_relay_s *relay, int ifndx, unsigned char *data, - int datalen, uint16_t sender_id) -{ - struct ccnl_face_s *from; - DEBUGMSG(14, "ccnl_core_RX ifndx=%d, %d bytes\n", ifndx, datalen); - - from = ccnl_get_face_or_create(relay, ifndx, sender_id); - - if (!from) { - return; - } - - DEBUGMSG(1, "ccnl_core_RX: faceid=%d frag=%p\n", from->faceid, (void *) from->frag); - - ccnl_core_RX_datagram(relay, from, &data, &datalen); -} - -// eof diff --git a/sys/net/ccn_lite/ccnl-core.h b/sys/net/ccn_lite/ccnl-core.h deleted file mode 100644 index 644768d258..0000000000 --- a/sys/net/ccn_lite/ccnl-core.h +++ /dev/null @@ -1,302 +0,0 @@ -/* - * @f ccnl-core.h - * @b CCN lite (CCNL), core header file (internal data structures) - * - * Copyright (C) 2011-13, Christian Tschudin, University of Basel - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * File history: - * 2011-04-09 created - * 2013-03-19 updated (ms): modified struct ccnl_relay_s for 'aux' field - */ - -#ifndef CCNL_CORE_H__ -#define CCNL_CORE_H__ - -#define EXACT_MATCH 1 -#define PREFIX_MATCH 0 - -#define CMP_EXACT 0 // used to compare interests among themselves -#define CMP_MATCH 1 // used to match interest and content -#define CMP_LONGEST 2 // used to lookup the FIB - -#define CCNL_FACE_FLAGS_STATIC 1 -#define CCNL_FACE_FLAGS_REFLECT 2 -#define CCNL_FACE_FLAGS_SERVED 4 -#define CCNL_FACE_FLAGS_FWDALLI 8 // forward all interests, also known ones -#define CCNL_FACE_FLAGS_BROADCAST 16 - -#define CCNL_FRAG_NONE 0 -#define CCNL_FRAG_SEQUENCED2012 1 -#define CCNL_FRAG_CCNx2013 2 - -#define CCNL_CONTENT_FLAGS_STATIC 0x01 -#define CCNL_CONTENT_FLAGS_STALE 0x02 - -#define CCNL_FORWARD_FLAGS_STATIC 0x01 - -#include -#include -#include - -#include "mutex.h" - -#include "ccnl.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// ---------------------------------------------------------------------- - -typedef union { - uint16_t id; -} sockunion; - -struct ccnl_txrequest_s { - struct ccnl_buf_s *buf; - sockunion dst; - void (*txdone)(void *, int, int); - struct ccnl_face_s *txdone_face; -}; - -struct ccnl_if_s { // interface for packet IO - sockunion addr; - int sock; - int (*sendfunc)(uint8_t *, uint16_t, uint16_t); - int reflect; // whether to reflect I packets on this interface - int fwdalli; // whether to forward all I packets rcvd on this interface - int mtu; - - int qlen; // number of pending sends - int qfront; // index of next packet to send - struct ccnl_txrequest_s queue[CCNL_MAX_IF_QLEN]; - struct ccnl_sched_s *sched; - struct ccnl_face_s *broadcast_face; -}; - -struct ccnl_relay_s { - struct timeval startup_time; - int id; - struct ccnl_face_s *faces; - struct ccnl_forward_s *fib; - struct ccnl_interest_s *pit; - struct ccnl_content_s *contents; //, *contentsend; - struct ccnl_nonce_s *nonces; - int contentcnt; // number of cached items - int max_cache_entries; // -1: unlimited - struct ccnl_if_s ifs[CCNL_MAX_INTERFACES]; - int ifcount; // number of active interfaces - char halt_flag; - struct ccnl_sched_s *(*defaultFaceScheduler)(struct ccnl_relay_s *, - void(*cts_done)(void *, void *)); - struct ccnl_sched_s *(*defaultInterfaceScheduler)(struct ccnl_relay_s *, - void(*cts_done)(void *, void *)); - struct ccnl_http_s *http; - struct ccnl_stats_s *stats; - void *aux; - int fib_threshold_prefix; /* how may name components should be considdered as dynamic */ - int fib_threshold_aggregate; - kernel_pid_t riot_pid; - kernel_pid_t riot_helper_pid; - mutex_t global_lock; - mutex_t stop_lock; -}; - -struct ccnl_buf_s { - struct ccnl_buf_s *next; - unsigned int datalen; - unsigned char data[1]; -}; - -struct ccnl_nonce_s { - struct ccnl_nonce_s *next, *prev; - struct timeval created; - struct ccnl_buf_s *buf; -}; - -struct ccnl_prefix_s { - unsigned char **comp; - int *complen; - int compcnt; - unsigned char *path; // memory for name component copies -}; - -struct ccnl_stat_s { - int send_interest[CCNL_MAX_INTEREST_RETRANSMIT]; - int send_content[CCNL_MAX_CONTENT_SERVED_STAT]; - int received_interest; - int received_content; -}; - -struct ccnl_frag_s { - int protocol; // (0=plain CCNx) - int mtu; - sockunion dest; - struct ccnl_buf_s *bigpkt; - unsigned int sendoffs; - // transport state, if present: - int ifndx; - - struct ccnl_buf_s *defrag; - - unsigned int sendseq; - unsigned int losscount; - unsigned int recvseq; - unsigned char flagwidth; - unsigned char sendseqwidth; - unsigned char losscountwidth; - unsigned char recvseqwidth; -}; - -struct ccnl_face_s { - struct ccnl_face_s *next, *prev; - int faceid; - int ifndx; - sockunion peer; - int flags; - struct timeval last_used; // updated when we receive a packet - struct ccnl_buf_s *outq, *outqend; // queue of packets to send - struct ccnl_frag_s *frag; // which special datagram armoring - struct ccnl_sched_s *sched; - - struct ccnl_stat_s stat; -}; - -struct ccnl_forward_s { - struct ccnl_forward_s *next, *prev; - struct ccnl_prefix_s *prefix; - struct ccnl_face_s *face; - int flags; - struct timeval last_used; // updated when we use this fib entry -}; - -struct ccnl_interest_s { - struct ccnl_interest_s *next, *prev; - struct ccnl_face_s *from; - struct ccnl_pendint_s *pending; // linked list of faces wanting that content - struct ccnl_prefix_s *prefix; - int minsuffix, maxsuffix; - struct ccnl_buf_s *ppkd; // publisher public key digest - struct ccnl_buf_s *pkt; // full datagram - struct timeval last_used; - int retries; - struct ccnl_forward_s *forwarded_over; -}; - -struct ccnl_pendint_s { // pending interest - struct ccnl_pendint_s *next; // , *prev; - struct ccnl_face_s *face; - struct timeval last_used; -}; - -struct ccnl_content_s { - struct ccnl_content_s *next, *prev; - struct ccnl_prefix_s *name; - struct ccnl_buf_s *ppkd; // publisher public key digest - struct ccnl_buf_s *pkt; // full datagram - int flags; - unsigned char *content; // pointer into the data buffer - int contentlen; - // NON-CONFORM: "The [ContentSTore] MUST also implement the Staleness Bit." - // >> CCNL: currently no stale bit, old content is fully removed << - struct timeval last_used; - int served_cnt; -}; - -// ---------------------------------------------------------------------- -// macros for double linked lists (these double linked lists are not rings) - -#define DBL_LINKED_LIST_ADD(l,e) \ - do { if ((l)) (l)->prev = (e); \ - (e)->next = (l); \ - (l) = (e); \ - } while(0) - -#define DBL_LINKED_LIST_REMOVE(l,e) \ - do { if ((l) == (e)) (l) = (e)->next; \ - if ((e)->prev) (e)->prev->next = (e)->next; \ - if ((e)->next) (e)->next->prev = (e)->prev; \ - } while(0) - -// ---------------------------------------------------------------------- -// collect the USE_* macros in a string -const char *compile_string(void); - -int consume(int typ, int num, unsigned char **buf, int *len, - unsigned char **valptr, int *vallen); - -void -ccnl_core_RX(struct ccnl_relay_s *relay, int ifndx, unsigned char *data, - int datalen, uint16_t sender_id); - -void ccnl_core_cleanup(struct ccnl_relay_s *ccnl); - -struct ccnl_buf_s * -ccnl_buf_new(void *data, int len); - -struct ccnl_content_s * -ccnl_content_new(struct ccnl_relay_s *ccnl, struct ccnl_buf_s **pkt, - struct ccnl_prefix_s **prefix, struct ccnl_buf_s **ppkd, - unsigned char *content, int contlen); - -struct ccnl_content_s * -ccnl_content_add2cache(struct ccnl_relay_s *ccnl, struct ccnl_content_s *c); - -void ccnl_content_learn_name_route(struct ccnl_relay_s *ccnl, struct ccnl_prefix_s *p, - struct ccnl_face_s *f, int threshold_prefix, int flags); - -struct ccnl_face_s * -ccnl_get_face_or_create(struct ccnl_relay_s *ccnl, int ifndx, uint16_t sender_id); - -int ccnl_face_enqueue(struct ccnl_relay_s *ccnl, struct ccnl_face_s *to, - struct ccnl_buf_s *buf); - -struct ccnl_face_s * -ccnl_face_remove(struct ccnl_relay_s *ccnl, struct ccnl_face_s *f); - -struct ccnl_forward_s * -ccnl_forward_remove(struct ccnl_relay_s *ccnl, struct ccnl_forward_s *fwd); - -struct ccnl_buf_s * -ccnl_extract_prefix_nonce_ppkd(unsigned char **data, int *datalen, int *scope, - int *aok, int *min, int *max, struct ccnl_prefix_s **prefix, - struct ccnl_buf_s **nonce, struct ccnl_buf_s **ppkd, - unsigned char **content, int *contlen); - -void ccnl_do_retransmit(void *ptr, void *dummy); -void ccnl_do_ageing(void *ptr, void *dummy); -void ccnl_do_nonce_timeout(void *ptr, void *dummy); - -void ccnl_interface_CTS(void *aux1, void *aux2); - -void ccnl_face_print_stat(struct ccnl_face_s *f); - -#define ccnl_malloc(s) malloc(s) -#define ccnl_calloc(n,s) calloc(n,s) -#define ccnl_realloc(p,s) realloc(p,s) -#define ccnl_free(p) free(p) - -void free_2ptr_list(void *a, void *b); -void free_3ptr_list(void *a, void *b, void *c); -void free_4ptr_list(void *a, void *b, void *c, void *d); -void free_prefix(struct ccnl_prefix_s *p); -void free_content(struct ccnl_content_s *c); - -#ifdef __cplusplus -} -#endif - -#endif /*CCNL_CORE_H__*/ -// eof diff --git a/sys/net/ccn_lite/ccnl-ext-debug.c b/sys/net/ccn_lite/ccnl-ext-debug.c deleted file mode 100644 index 646075722e..0000000000 --- a/sys/net/ccn_lite/ccnl-ext-debug.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * @f ccnl-ext-debug.c - * @b CCNL debugging support, dumping routines, memory tracking, stats - * - * Copyright (C) 2011-13, Christian Tschudin, University of Basel - * Copyright (C) 2013, Christian Mehlis, Freie Universität Berlin - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * File history: - * 2011-04-19 created - * 2013-03-18 updated (ms): removed omnet related code - * 2013-03-31 merged with ccnl-debug.h and ccnl-debug-mem.c - */ - -#ifndef CCNL_EXT_DEBUG_H -#define CCNL_EXT_DEBUG_H - -#include -#include -#include -#include - -#include "ccnl-core.h" - -char * -ccnl_prefix_to_path(struct ccnl_prefix_s *pr) -{ - static char prefix_buf[256]; - int len, i, j; - - if (!pr) { - return NULL; - } - - for (len = 0, i = 0; i < pr->compcnt; i++) { - if ((len + 1 + 3 * pr->complen[i]) >= (int) sizeof(prefix_buf)) { - return (char *) "(...prefix...)"; - } - - prefix_buf[len++] = '/'; - - for (j = 0; j < pr->complen[i]; j++) { - unsigned char c = pr->comp[i][j]; - len += sprintf(prefix_buf + len, - !isprint(c) || isspace(c) || c == '/' ? "%%%02x" : "%c", - c); - } - } - - prefix_buf[len] = '\0'; - return prefix_buf; -} - -#endif - -// eof diff --git a/sys/net/ccn_lite/ccnl-ext-frag.c b/sys/net/ccn_lite/ccnl-ext-frag.c deleted file mode 100644 index db09200642..0000000000 --- a/sys/net/ccn_lite/ccnl-ext-frag.c +++ /dev/null @@ -1,715 +0,0 @@ -/* - * @f ccnl-ext-frag.c - * @b CCN lite extension: fragmentation support (including scheduling interface) - * - * Copyright (C) 2011-13, Christian Tschudin, University of Basel - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * File history: - * 2011-10-05 created - * 2013-05-02 prototyped a new fragment format CCNL_FRAG_TYPE_CCNx2013 - */ - -/* ---------------------------------------------------------------------- */ -#ifdef USE_FRAG - -#include "ccnl-includes.h" -#include "ccnl-core.h" -#include "ccnl-ext.h" -#include "ccnx.h" - - - -/* see ccnl-core.h for available fragmentation protocols. - * - * CCNL_FRAG_NONE - * passthrough, i.e. no header is added at all - * - * CCNL_FRAG_SEQUENCED2012 - * - a ccnb encoded header is prepended, - * - the driver is configurable for arbitrary MTU - * - packets have sequence numbers (can detect lost packets) - * - * CCNL_FRAG_CCNx2013 - * - a ccnb encoded wire format as currently discussed with PARC. - * It serves as a container for various wire format types, - * including carrying fragments of bigger CCNX objects - * - all attributes from SEQUENCED2012 are retained - * - */ - -/* ---------------------------------------------------------------------- */ -struct ccnl_frag_s * -ccnl_frag_new(int protocol, int mtu) -{ - struct ccnl_frag_s *e = NULL; - - DEBUGMSG(8, "ccnl_frag_new proto=%d mtu=%d\n", protocol, mtu); - - switch (protocol) { - case CCNL_FRAG_SEQUENCED2012: - case CCNL_FRAG_CCNx2013: - e = (struct ccnl_frag_s *) ccnl_calloc(1, sizeof(struct ccnl_frag_s)); - - if (e) { - e->protocol = protocol; - e->mtu = mtu; - e->flagwidth = 1; - e->sendseqwidth = 4; - e->losscountwidth = 2; - e->recvseqwidth = 4; - } - - break; - - case CCNL_FRAG_NONE: - default: - break; - } - - return e; -} - -void ccnl_frag_reset(struct ccnl_frag_s *e, struct ccnl_buf_s *buf, int ifndx, - sockunion *dst) -{ - DEBUGMSG(99, "ccnl_frag_reset (%d bytes)\n", buf ? buf->datalen : -1); - - if (!e) { - return; - } - - e->ifndx = ifndx; - memcpy(&e->dest, dst, sizeof(*dst)); - ccnl_free(e->bigpkt); - e->bigpkt = buf; - e->sendoffs = 0; -} - -int ccnl_frag_getfragcount(struct ccnl_frag_s *e, int origlen, int *totallen) -{ - int cnt = 0, len = 0; - unsigned char dummy[256]; - int hdrlen, blobtaglen, datalen; - int offs = 0; - - if (!e) { - cnt = 1; - } - else if (e && e->protocol == CCNL_FRAG_SEQUENCED2012) { - while (offs < origlen) { /* we could do better than to simulate this: */ - hdrlen = mkHeader(dummy, CCNL_DTAG_FRAGMENT2012, CCN_TT_DTAG); - hdrlen += mkBinaryInt(dummy, CCNL_DTAG_FRAG_FLAGS, CCN_TT_DTAG, 0, - e->flagwidth); - hdrlen += mkBinaryInt(dummy, CCNL_DTAG_FRAG_SEQNR, CCN_TT_DTAG, 0, - e->sendseqwidth); - hdrlen += mkBinaryInt(dummy, CCNL_DTAG_FRAG_OLOSS, CCN_TT_DTAG, 0, - e->losscountwidth); - hdrlen += mkBinaryInt(dummy, CCNL_DTAG_FRAG_YSEQN, CCN_TT_DTAG, 0, - e->recvseqwidth); - - hdrlen += mkHeader(dummy, CCN_DTAG_CONTENT, CCN_TT_DTAG); - blobtaglen = mkHeader(dummy, e->mtu - hdrlen - 1, CCN_TT_BLOB); - datalen = e->mtu - hdrlen - blobtaglen - 1; - - if (datalen > (origlen - offs)) { - datalen = origlen - offs; - } - - hdrlen += mkHeader(dummy, datalen, CCN_TT_BLOB); - len += hdrlen + datalen + 1; - offs += datalen; - cnt++; - } - } - else if (e && e->protocol == CCNL_FRAG_CCNx2013) { - while (offs < origlen) { /* we could do better than to simulate this: */ - hdrlen = mkHeader(dummy, CCNL_DTAG_FRAGMENT, CCN_TT_DTAG); - hdrlen += mkHeader(dummy, CCNL_DTAG_FRAG_TYPE, CCN_TT_DTAG); - hdrlen += 4; /* three BLOB bytes plus end-of-entry */ - hdrlen += mkBinaryInt(dummy, CCNL_DTAG_FRAG_SEQNR, CCN_TT_DTAG, 0, - e->sendseqwidth); - hdrlen += mkBinaryInt(dummy, CCNL_DTAG_FRAG_FLAGS, CCN_TT_DTAG, 0, - e->flagwidth); - hdrlen += mkBinaryInt(dummy, CCNL_DTAG_FRAG_OLOSS, CCN_TT_DTAG, 0, - e->losscountwidth); - hdrlen += mkBinaryInt(dummy, CCNL_DTAG_FRAG_YSEQN, CCN_TT_DTAG, 0, - e->recvseqwidth); - - hdrlen += mkHeader(dummy, CCN_DTAG_CONTENT, CCN_TT_DTAG); - blobtaglen = mkHeader(dummy, e->mtu - hdrlen - 1, CCN_TT_BLOB); - datalen = e->mtu - hdrlen - blobtaglen - 1; - - if (datalen > (origlen - offs)) { - datalen = origlen - offs; - } - - hdrlen += mkHeader(dummy, datalen, CCN_TT_BLOB); - len += hdrlen + datalen + 1; - offs += datalen; - cnt++; - } - } - - if (totallen) { - *totallen = len; - } - - return cnt; -} - -struct ccnl_buf_s * -ccnl_frag_getnextSEQD2012(struct ccnl_frag_s *e, int *ifndx, sockunion *su) -{ - struct ccnl_buf_s *buf = 0; - unsigned char header[256]; - int hdrlen = 0, blobtaglen, flagoffs; - unsigned int datalen; - - DEBUGMSG(16, "ccnl_frag_getnextSEQD2012 e=%p, mtu=%d\n", (void *) e, e->mtu); - DEBUGMSG(17, " %d bytes to fragment, offset=%d\n", e->bigpkt->datalen, - e->sendoffs); - - hdrlen = mkHeader(header, CCNL_DTAG_FRAGMENT2012, CCN_TT_DTAG); - hdrlen += mkBinaryInt(header + hdrlen, CCNL_DTAG_FRAG_FLAGS, - CCN_TT_DTAG, 0, e->flagwidth); - flagoffs = hdrlen - 2; - hdrlen += mkBinaryInt(header + hdrlen, CCNL_DTAG_FRAG_YSEQN, - CCN_TT_DTAG, e->recvseq, e->recvseqwidth); - hdrlen += mkBinaryInt(header + hdrlen, CCNL_DTAG_FRAG_OLOSS, CCN_TT_DTAG, - e->losscount, e->losscountwidth); - - hdrlen += mkBinaryInt(header + hdrlen, CCNL_DTAG_FRAG_SEQNR, - CCN_TT_DTAG, e->sendseq, e->sendseqwidth); - hdrlen += mkHeader(header + hdrlen, CCN_DTAG_CONTENT, CCN_TT_DTAG); - blobtaglen = mkHeader(header + hdrlen, e->mtu - hdrlen - 2, CCN_TT_BLOB); - - datalen = e->mtu - hdrlen - blobtaglen - 2; - - if (datalen > (e->bigpkt->datalen - e->sendoffs)) { - datalen = e->bigpkt->datalen - e->sendoffs; - } - - hdrlen += mkHeader(header + hdrlen, datalen, CCN_TT_BLOB); - - buf = ccnl_buf_new(NULL, hdrlen + datalen + 2); - - if (!buf) { - return NULL; - } - - memcpy(buf->data, header, hdrlen); - memcpy(buf->data + hdrlen, e->bigpkt->data + e->sendoffs, datalen); - buf->data[hdrlen + datalen] = '\0'; /* end of content/any field */ - buf->data[hdrlen + datalen + 1] = '\0'; /* end of fragment/pdu */ - - if (datalen >= e->bigpkt->datalen) { /* fits in a single fragment */ - buf->data[flagoffs + e->flagwidth - 1] = - CCNL_DTAG_FRAG_FLAG_FIRST | CCNL_DTAG_FRAG_FLAG_LAST; - ccnl_free(e->bigpkt); - e->bigpkt = NULL; - } - else if (e->sendoffs == 0) { /* this is the start fragment */ - buf->data[flagoffs + e->flagwidth - 1] = CCNL_DTAG_FRAG_FLAG_FIRST; - } - else if (datalen >= (e->bigpkt->datalen - e->sendoffs)) { /* the end */ - buf->data[flagoffs + e->flagwidth - 1] = CCNL_DTAG_FRAG_FLAG_LAST; - ccnl_free(e->bigpkt); - e->bigpkt = NULL; - } - else - /* in the middle */ - { - buf->data[flagoffs + e->flagwidth - 1] = 0x00; - } - - e->sendoffs += datalen; - e->sendseq++; - - DEBUGMSG(17, " e->offset now %d\n", e->sendoffs); - - if (ifndx) { - *ifndx = e->ifndx; - } - - if (su) { - memcpy(su, &e->dest, sizeof(*su)); - } - - return buf; -} - -struct ccnl_buf_s * -ccnl_frag_getnextCCNx2013(struct ccnl_frag_s *fr, int *ifndx, sockunion *su) -{ - struct ccnl_buf_s *buf = 0; - unsigned char header[256]; - int hdrlen, blobtaglen, flagoffs; - unsigned int datalen; - - /* switch among encodings of fragments here (ccnb, TLV, etc) */ - - hdrlen = mkHeader(header, CCNL_DTAG_FRAGMENT, CCN_TT_DTAG); /* fragment */ - - hdrlen += mkHeader(header + hdrlen, CCNL_DTAG_FRAG_TYPE, CCN_TT_DTAG); - hdrlen += mkHeader(header + hdrlen, 3, CCN_TT_BLOB); - memcpy(header + hdrlen, CCNL_FRAG_TYPE_CCNx2013_VAL, 3); /* "FHBH" */ - header[hdrlen + 3] = '\0'; - hdrlen += 4; - - hdrlen += mkBinaryInt(header + hdrlen, CCNL_DTAG_FRAG_SEQNR, CCN_TT_DTAG, - fr->sendseq, fr->sendseqwidth); - - hdrlen += mkBinaryInt(header + hdrlen, CCNL_DTAG_FRAG_FLAGS, CCN_TT_DTAG, 0, - fr->flagwidth); - flagoffs = hdrlen - 2; /* most significant byte of flag element */ - - /* other optional fields would go here */ - - hdrlen += mkHeader(header + hdrlen, CCN_DTAG_CONTENT, CCN_TT_DTAG); - - blobtaglen = mkHeader(header + hdrlen, fr->mtu - hdrlen - 2, CCN_TT_BLOB); - datalen = fr->mtu - hdrlen - blobtaglen - 2; - - if (datalen > (fr->bigpkt->datalen - fr->sendoffs)) { - datalen = fr->bigpkt->datalen - fr->sendoffs; - } - - hdrlen += mkHeader(header + hdrlen, datalen, CCN_TT_BLOB); - - buf = ccnl_buf_new(NULL, hdrlen + datalen + 2); - - if (!buf) { - return NULL; - } - - memcpy(buf->data, header, hdrlen); - memcpy(buf->data + hdrlen, fr->bigpkt->data + fr->sendoffs, datalen); - buf->data[hdrlen + datalen] = '\0'; /* end of content field */ - buf->data[hdrlen + datalen + 1] = '\0'; /* end of fragment */ - - /* patch flag field: */ - if (datalen >= fr->bigpkt->datalen) { /* single */ - buf->data[flagoffs] = CCNL_DTAG_FRAG_FLAG_SINGLE; - ccnl_free(fr->bigpkt); - fr->bigpkt = NULL; - } - else if (fr->sendoffs == 0) { /* start */ - buf->data[flagoffs] = CCNL_DTAG_FRAG_FLAG_FIRST; - } - else if (datalen >= (fr->bigpkt->datalen - fr->sendoffs)) { /* end */ - buf->data[flagoffs] = CCNL_DTAG_FRAG_FLAG_LAST; - ccnl_free(fr->bigpkt); - fr->bigpkt = NULL; - } - else { - buf->data[flagoffs] = CCNL_DTAG_FRAG_FLAG_MID; - } - - fr->sendoffs += datalen; - fr->sendseq++; - - if (ifndx) { - *ifndx = fr->ifndx; - } - - if (su) { - memcpy(su, &fr->dest, sizeof(*su)); - } - - return buf; -} - -struct ccnl_buf_s * -ccnl_frag_getnext(struct ccnl_frag_s *fr, int *ifndx, sockunion *su) -{ - if (!fr->bigpkt) { - return NULL; - } - - DEBUGMSG(99, "fragmenting %d bytes (@ %d)\n", fr->bigpkt->datalen, - fr->sendoffs); - - switch (fr->protocol) { - case CCNL_FRAG_SEQUENCED2012: - return ccnl_frag_getnextSEQD2012(fr, ifndx, su); - - case CCNL_FRAG_CCNx2013: - return ccnl_frag_getnextCCNx2013(fr, ifndx, su); - - default: - return NULL; - } -} - -int ccnl_frag_nomorefragments(struct ccnl_frag_s *e) -{ - if (!e || !e->bigpkt) { - return 1; - } - - return e->bigpkt->datalen <= e->sendoffs; -} - -void ccnl_frag_destroy(struct ccnl_frag_s *e) -{ - if (e) { - ccnl_free(e->bigpkt); - ccnl_free(e->defrag); - ccnl_free(e); - } -} - -/* ---------------------------------------------------------------------- */ - -struct serialFragPDU_s { /* collect all fields of a numbered HBH fragment */ - int contlen; - unsigned char *content; - unsigned int flags, ourseq, ourloss, yourseq, HAS; - unsigned char flagwidth, ourseqwidth, ourlosswidth, yourseqwidth; -}; - -void serialFragPDU_init(struct serialFragPDU_s *s) -{ - memset(s, 0, sizeof(*s)); - s->contlen = -1; - s->flagwidth = 1; - s->ourseqwidth = s->ourlosswidth = s->yourseqwidth = sizeof(int); -} - -void ccnl_frag_RX_serialfragment(RX_datagram callback, - struct ccnl_relay_s *relay, struct ccnl_face_s *from, - struct serialFragPDU_s *s) -{ - struct ccnl_buf_s *buf = NULL; - struct ccnl_frag_s *e = from->frag; - DEBUGMSG(8, " frag %p protocol=%d, flags=%04x, seq=%d (%d)\n", (void *) e, - e->protocol, s->flags, s->ourseq, e->recvseq); - - if (e->recvseq != s->ourseq) { - /* should increase error counter here */ - if (e->defrag) { - DEBUGMSG(17, " >> seqnum mismatch (%d/%d), dropped defrag buf\n", - s->ourseq, e->recvseq); - ccnl_free(e->defrag); - e->defrag = NULL; - } - } - - switch (s->flags & (CCNL_DTAG_FRAG_FLAG_FIRST | CCNL_DTAG_FRAG_FLAG_LAST)) { - case CCNL_DTAG_FRAG_FLAG_SINGLE: /* single packet */ - DEBUGMSG(17, " >> single fragment\n"); - - if (e->defrag) { - DEBUGMSG(18, " had to drop defrag buf\n"); - ccnl_free(e->defrag); - e->defrag = NULL; - } - - /* no need to copy the buffer: */ - callback(relay, from, &s->content, &s->contlen); - return; - - case CCNL_DTAG_FRAG_FLAG_FIRST: /* start of fragment sequence */ - DEBUGMSG(17, " >> start of fragment series\n"); - - if (e->defrag) { - DEBUGMSG(18, " had to drop defrag buf\n"); - ccnl_free(e->defrag); - } - - e->defrag = ccnl_buf_new(s->content, s->contlen); - break; - - case CCNL_DTAG_FRAG_FLAG_LAST: /* end of fragment sequence */ - DEBUGMSG(17, " >> last fragment of a series\n"); - - if (!e->defrag) { - break; - } - - buf = ccnl_buf_new(NULL, e->defrag->datalen + s->contlen); - - if (buf) { - memcpy(buf->data, e->defrag->data, e->defrag->datalen); - memcpy(buf->data + e->defrag->datalen, s->content, s->contlen); - } - - ccnl_free(e->defrag); - e->defrag = NULL; - break; - - case CCNL_DTAG_FRAG_FLAG_MID: /* fragment in the middle of a squence */ - default: - DEBUGMSG(17, " >> fragment in the middle of a series\n"); - - if (!e->defrag) { - break; - } - - buf = ccnl_buf_new(NULL, e->defrag->datalen + s->contlen); - - if (buf) { - memcpy(buf->data, e->defrag->data, e->defrag->datalen); - memcpy(buf->data + e->defrag->datalen, s->content, s->contlen); - ccnl_free(e->defrag); - e->defrag = buf; - buf = NULL; - } - else { - ccnl_free(e->defrag); - e->defrag = NULL; - } - - break; - } - - /* FIXME: we should only bump recvseq if s->ourseq is ahead, or 0 */ - e->recvseq = s->ourseq + 1; - DEBUGMSG(1, ">>> seq from %d to %d (w=%d)\n", s->ourseq, e->recvseq, - s->ourseqwidth); - - if (buf) { - unsigned char *frag = buf->data; - int fraglen = buf->datalen; - DEBUGMSG(1, " >> reassembled fragment is %d bytes\n", buf->datalen); - callback(relay, from, &frag, &fraglen); - ccnl_free(buf); - } - - DEBUGMSG(1, "leaving function\n"); -} - -/* ---------------------------------------------------------------------- */ - -#define getNumField(var,len,flag,rem) \ - DEBUGMSG(19, " parsing " rem "\n"); \ - if (unmkBinaryInt(data, datalen, &var, &len) != 0) \ - goto Bail; \ - s.HAS |= flag -#define HAS_FLAGS 0x01 -#define HAS_OSEQ 0x02 -#define HAS_OLOS 0x04 -#define HAS_YSEQ 0x08 - -int ccnl_frag_RX_frag2012(RX_datagram callback, struct ccnl_relay_s *relay, - struct ccnl_face_s *from, unsigned char **data, int *datalen) -{ - int num, typ; - struct serialFragPDU_s s; - DEBUGMSG(99, "ccnl_frag_RX_frag2012 (%d bytes)\n", *datalen); - - serialFragPDU_init(&s); - - while (dehead(data, datalen, &num, &typ) == 0) { - if (num == 0 && typ == 0) { - break; /* end */ - } - - if (typ == CCN_TT_DTAG) { - switch (num) { - case CCN_DTAG_CONTENT: - DEBUGMSG(18, " frag content\n"); - - // if (s.content) /* error: more than one content entry */ - if (consume(typ, num, data, datalen, &s.content, &s.contlen) - < 0) { - goto Bail; - } - - continue; - - case CCNL_DTAG_FRAG_FLAGS: - getNumField(s.flags, s.flagwidth, HAS_FLAGS, "flags") - ; - continue; - - case CCNL_DTAG_FRAG_SEQNR: - getNumField(s.ourseq, s.ourseqwidth, HAS_OSEQ, "ourseq") - ; - continue; - - case CCNL_DTAG_FRAG_OLOSS: - getNumField(s.ourloss, s.ourlosswidth, HAS_OLOS, "ourloss") - ; - continue; - - case CCNL_DTAG_FRAG_YSEQN: - getNumField(s.yourseq, s.yourseqwidth, HAS_YSEQ, "yourseq") - ; - continue; - - default: - break; - } - } - - if (consume(typ, num, data, datalen, 0, 0) < 0) { - goto Bail; - } - } - - if (!s.content || s.HAS != 15) { - DEBUGMSG(1, "* incomplete frag\n"); - return 0; - } - - if (from) { - if (!from->frag) - from->frag = ccnl_frag_new(CCNL_FRAG_SEQUENCED2012, - relay->ifs[from->ifndx].mtu); - - if (from->frag && from->frag->protocol == CCNL_FRAG_SEQUENCED2012) { - ccnl_frag_RX_serialfragment(callback, relay, from, &s); - } - else { - DEBUGMSG(1, "WRONG FRAG PROTOCOL\n"); - } - } - else { - ccnl_frag_RX_serialfragment(callback, relay, from, &s); - } - - return 0; -Bail: - DEBUGMSG(1, "* frag bailing\n"); - return -1; -} - -int ccnl_frag_RX_CCNx2013(RX_datagram callback, struct ccnl_relay_s *relay, - struct ccnl_face_s *from, unsigned char **data, int *datalen) -{ - int rc, num, typ, pdutypelen; - unsigned char *pdutype = 0; - struct serialFragPDU_s s; - - DEBUGMSG(99, "ccnl_frag_RX_CCNx2013 (%d bytes)\n", *datalen); - serialFragPDU_init(&s); - - while (dehead(data, datalen, &num, &typ) == 0) { - if (num == 0 && typ == 0) { - break; /* end */ - } - - if (typ == CCN_TT_DTAG) { - switch (num) { - case CCNL_DTAG_FRAG_TYPE: - if (hunt_for_end(data, datalen, &pdutype, &pdutypelen) - || pdutypelen != 3) { - goto Bail; - } - - continue; - - case CCNL_DTAG_FRAG_SEQNR: - getNumField(s.ourseq, s.ourseqwidth, HAS_OSEQ, "ourseq") - ; - continue; - - case CCNL_DTAG_FRAG_FLAGS: - getNumField(s.flags, s.flagwidth, HAS_FLAGS, "flags") - ; - continue; - - case CCN_DTAG_CONTENT: - - // if (frag) /* error: more than one content entry */ - if (consume(typ, num, data, datalen, &s.content, &s.contlen) - < 0) { - goto Bail; - } - - continue; - - /* CCNL extensions: */ - case CCN_DTAG_INTEREST: - case CCN_DTAG_CONTENTOBJ: - rc = ccnl_core_RX_i_or_c(relay, from, data, datalen); - - if (rc < 0) { - return rc; - } - - continue; - - case CCNL_DTAG_FRAG_OLOSS: - getNumField(s.ourloss, s.ourlosswidth, HAS_OLOS, "ourloss") - ; - continue; - - case CCNL_DTAG_FRAG_YSEQN: - getNumField(s.yourseq, s.yourseqwidth, HAS_YSEQ, "yourseq") - ; - continue; - - default: - break; - } - } - - if (consume(typ, num, data, datalen, 0, 0) < 0) { - goto Bail; - } - } - - if (!pdutype || !s.content) { - /* || - (s.HAS&(HAS_FLAGS|HAS_OSEQ)) != (HAS_FLAGS|HAS_OSEQ) ) { - */ - DEBUGMSG(1, "* incomplete frag\n"); - return 0; - } - - DEBUGMSG(1, "hop-by-hop\n"); - - if (memcmp(pdutype, CCNL_FRAG_TYPE_CCNx2013_VAL, 3) == 0) { /* hop-by-hop */ - if (from) { - if (!from->frag) - from->frag = ccnl_frag_new(CCNL_FRAG_CCNx2013, - relay->ifs[from->ifndx].mtu); - - if (from->frag && from->frag->protocol == CCNL_FRAG_CCNx2013) { - ccnl_frag_RX_serialfragment(callback, relay, from, &s); - } - else { - DEBUGMSG(1, "WRONG FRAG PROTOCOL\n"); - } - } - else { - ccnl_frag_RX_serialfragment(callback, relay, from, &s); - } - } - - /* - * echo "FMTE" | base64 -d | hexdump -v -e '/1 "@x%02x"'| tr @ '\\'; echo - */ - if (memcmp(pdutype, "\x14\xc4\xc4", 3) == 0) { /* mid-to-end fragment */ - /* not implemented yet */ - } - - DEBUGMSG(1, "mid-to-end fragment\n"); - - return 0; -Bail: - DEBUGMSG(1, "* frag bailing\n"); - return -1; -} - -#else /* USE_FRAG */ - -#define CCNL_NO_FRAG_DUMMY - -static int dummy __attribute__((unused)); - -#endif diff --git a/sys/net/ccn_lite/ccnl-ext-mgmt.c b/sys/net/ccn_lite/ccnl-ext-mgmt.c deleted file mode 100644 index 2095ace136..0000000000 --- a/sys/net/ccn_lite/ccnl-ext-mgmt.c +++ /dev/null @@ -1,627 +0,0 @@ -/* - * @f ccnl-ext-mgmt.c - * @b CCN lite extension, management logic (face mgmt and registration) - * - * Copyright (C) 2012-13, Christian Tschudin, University of Basel - * Copyright (C) 2013, Christian Mehlis, Freie Universität Berlin - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * File history: - * 2012-05-06 created - */ - -#include -#include - -#include "ccnx.h" -#include "ccnl-pdu.h" -#include "ccnl.h" -#include "ccnl-includes.h" -#include "ccnl-core.h" -#include "ccnl-ext.h" - -unsigned char contentobj_buf[500]; -unsigned char faceinst_buf[500]; -unsigned char out_buf[500]; -unsigned char fwdentry_buf[500]; - -char * -ccnl_addr2ascii(sockunion *su) -{ - static char buf[10]; - snprintf(buf, sizeof(buf), "%d", su->id); - return buf; -} - -// ---------------------------------------------------------------------- -int -ccnl_is_local_addr(struct ccnl_face_s *f) -{ - return (f->ifndx == RIOT_MSG_IDX); -} - -struct ccnl_prefix_s * -ccnl_prefix_clone_strip(struct ccnl_prefix_s *p, int strip) -{ - int i, len; - struct ccnl_prefix_s *p2; - - p2 = (struct ccnl_prefix_s *) ccnl_calloc(1, sizeof(struct ccnl_prefix_s)); - - if (!p2) { - return NULL; - } - - int stripped_compcnt = p->compcnt; - stripped_compcnt -= (p->compcnt > strip) ? strip : 0; - - for (i = 0, len = 0; i < stripped_compcnt; len += p->complen[i++]); - - p2->path = (unsigned char *) ccnl_malloc(len); - p2->comp = (unsigned char **) ccnl_malloc(stripped_compcnt * sizeof(char *)); - p2->complen = (int *) ccnl_malloc(stripped_compcnt * sizeof(int)); - - if (!p2->comp || !p2->complen || !p2->path) { - goto Bail; - } - - p2->compcnt = stripped_compcnt; - - for (i = 0, len = 0; i < stripped_compcnt; len += p2->complen[i++]) { - p2->complen[i] = p->complen[i]; - p2->comp[i] = p2->path + len; - memcpy(p2->comp[i], p->comp[i], p2->complen[i]); - } - - return p2; -Bail: - free_prefix(p2); - return NULL; -} - -struct ccnl_prefix_s * -ccnl_prefix_clone(struct ccnl_prefix_s *p) -{ - return ccnl_prefix_clone_strip(p, 0U); -} -// ---------------------------------------------------------------------- -// management protocols - -#define extractStr(VAR,DTAG) \ - if (typ == CCN_TT_DTAG && num == DTAG) { \ - char *s; unsigned char *valptr; int vallen; \ - if (consume(typ, num, &buf, &buflen, &valptr, &vallen) < 0) goto Bail; \ - s = ccnl_malloc(vallen+1); if (!s) goto Bail; \ - memcpy(s, valptr, vallen); s[vallen] = '\0'; \ - ccnl_free(VAR); \ - VAR = (unsigned char*) s; \ - continue; \ - } do {} while(0) - -void -ccnl_mgmt_return_msg(struct ccnl_relay_s *ccnl, struct ccnl_buf_s *orig, - struct ccnl_face_s *from, char *msg) -{ - (void) orig; /* unused */ - - struct ccnl_buf_s *buf; - - // this is a temporary non-solution: a CCN-content reply should - // be returned instead of a string message - - buf = ccnl_buf_new(msg, strlen(msg)); - ccnl_face_enqueue(ccnl, from, buf); -} - -int -ccnl_mgmt_newface(struct ccnl_relay_s *ccnl, struct ccnl_buf_s *orig, - struct ccnl_prefix_s *prefix, struct ccnl_face_s *from) -{ - (void) orig; /* unused */ - - unsigned char *buf; - int buflen, num, typ; - unsigned char *action, *macsrc, *ip4src, *proto, *host, *port, - *path, *frag, *flags; - char *cp = "newface cmd failed"; - int rc = -1; - struct ccnl_face_s *f = NULL; - //varibales for answer - struct ccnl_buf_s *retbuf; - // unsigned char out[2000]; - int len = 0, len2, len3; - // unsigned char contentobj[2000]; - // unsigned char faceinst[2000]; - unsigned char faceidstr[100]; - unsigned char retstr[200]; - - DEBUGMSG(99, "ccnl_mgmt_newface from=%p, ifndx=%d\n", - (void *) from, from->ifndx); - action = macsrc = ip4src = proto = host = port = NULL; - path = frag = flags = NULL; - - buf = prefix->comp[3]; - buflen = prefix->complen[3]; - - if (dehead(&buf, &buflen, &num, &typ) < 0) { - goto Bail; - } - - if (typ != CCN_TT_DTAG || num != CCN_DTAG_CONTENTOBJ) { - goto Bail; - } - - if (dehead(&buf, &buflen, &num, &typ) != 0) { - goto Bail; - } - - if (typ != CCN_TT_DTAG || num != CCN_DTAG_CONTENT) { - goto Bail; - } - - if (dehead(&buf, &buflen, &num, &typ) != 0) { - goto Bail; - } - - if (typ != CCN_TT_BLOB) { - goto Bail; - } - - buflen = num; - - if (dehead(&buf, &buflen, &num, &typ) != 0) { - goto Bail; - } - - if (typ != CCN_TT_DTAG || num != CCN_DTAG_FACEINSTANCE) { - goto Bail; - } - - while (dehead(&buf, &buflen, &num, &typ) == 0) { - if (num == 0 && typ == 0) { - break; // end - } - - extractStr(action, CCN_DTAG_ACTION); - extractStr(macsrc, CCNL_DTAG_MACSRC); - extractStr(ip4src, CCNL_DTAG_IP4SRC); - extractStr(path, CCNL_DTAG_UNIXSRC); - extractStr(proto, CCN_DTAG_IPPROTO); - extractStr(host, CCN_DTAG_HOST); - extractStr(port, CCN_DTAG_PORT); - // extractStr(frag, CCNL_DTAG_FRAG); - extractStr(flags, CCNL_DTAG_FACEFLAGS); - - if (consume(typ, num, &buf, &buflen, 0, 0) < 0) { - goto Bail; - } - } - - // should (re)verify that action=="newface" - - /***************************************************************************/ - - int ifndx = 0; - - if (strcmp((const char *) macsrc, "newTRANSface") == 0) { - ifndx = RIOT_TRANS_IDX; - } - else if (strcmp((const char *) macsrc, "newMSGface") == 0) { - ifndx = RIOT_MSG_IDX; - } - else { - goto Bail; - } - - uint16_t faceid = 0; - - if (port) { - faceid = atoi((const char *) port); - } - else { - goto Bail; - } - - // create face ontop of the traceceiver iface - DEBUGMSG(1, "new %s=%d face gets created - faceid==%s==%d!\n", (const char *) macsrc, ifndx, (const char *) port, faceid); - f = ccnl_get_face_or_create( - ccnl, - ifndx, - faceid - ); - - /***************************************************************************/ - if (f) { - int flagval = flags ? - strtol((const char *)flags, NULL, 0) : CCNL_FACE_FLAGS_STATIC; - // DEBUGMSG(1, " flags=%s %d\n", flags, flagval); - DEBUGMSG(99, " adding a new face (id=%d) worked!\n", f->faceid); - f->flags = flagval & - (CCNL_FACE_FLAGS_STATIC | CCNL_FACE_FLAGS_REFLECT); - -#ifdef USE_FRAG - - if (frag) { - int mtu = 1500; - - if (f->frag) { - ccnl_frag_destroy(f->frag); - f->frag = NULL; - } - - if (f->ifndx >= 0 && ccnl->ifs[f->ifndx].mtu > 0) { - mtu = ccnl->ifs[f->ifndx].mtu; - } - - f->frag = ccnl_frag_new(strtol((const char *)frag, NULL, 0), - mtu); - } - -#endif - cp = "newface cmd worked"; - } - else { - DEBUGMSG(99, " newface request for (macsrc=%s ip4src=%s proto=%s host=%s port=%s frag=%s flags=%s) failed or was ignored\n", - macsrc, ip4src, proto, host, port, frag, flags); - } - - rc = 0; - -Bail: - /*ANSWER*/ - - len = mkHeader(out_buf, CCN_DTAG_CONTENT, CCN_TT_DTAG); // content - len += mkHeader(out_buf + len, CCN_DTAG_NAME, CCN_TT_DTAG); // name - - len += mkStrBlob(out_buf + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, "ccnx"); - len += mkStrBlob(out_buf + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, ""); - - len += mkStrBlob(out_buf + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, "newface"); - - // prepare FACEINSTANCE - len3 = mkHeader(faceinst_buf, CCN_DTAG_FACEINSTANCE, CCN_TT_DTAG); - sprintf((char *)retstr, "newface: %s", cp); - len3 += mkStrBlob(faceinst_buf + len3, CCN_DTAG_ACTION, CCN_TT_DTAG, (char *) retstr); - - if (macsrc) { - len3 += mkStrBlob(faceinst_buf + len3, CCNL_DTAG_MACSRC, CCN_TT_DTAG, (char *) macsrc); - } - - if (ip4src) { - len3 += mkStrBlob(faceinst_buf + len3, CCNL_DTAG_IP4SRC, CCN_TT_DTAG, (char *) ip4src); - len3 += mkStrBlob(faceinst_buf + len3, CCN_DTAG_IPPROTO, CCN_TT_DTAG, "17"); - } - - if (host) { - len3 += mkStrBlob(faceinst_buf + len3, CCN_DTAG_HOST, CCN_TT_DTAG, (char *) host); - } - - if (port) { - len3 += mkStrBlob(faceinst_buf + len3, CCN_DTAG_PORT, CCN_TT_DTAG, (char *) port); - } - - /* - if (frag) - len3 += mkStrBlob(faceinst+len3, CCNL_DTAG_FRAG, CCN_TT_DTAG, frag); - */ - if (flags) { - len3 += mkStrBlob(faceinst_buf + len3, CCNL_DTAG_FACEFLAGS, CCN_TT_DTAG, (char *) flags); - } - - if (f) { - sprintf((char *)faceidstr, "%i", f->faceid); - len3 += mkStrBlob(faceinst_buf + len3, CCN_DTAG_FACEID, CCN_TT_DTAG, (char *) faceidstr); - } - - faceinst_buf[len3++] = 0; // end-of-faceinst - - // prepare CONTENTOBJ with CONTENT - len2 = mkHeader(contentobj_buf, CCN_DTAG_CONTENTOBJ, CCN_TT_DTAG);// contentobj - len2 += mkBlob(contentobj_buf + len2, CCN_DTAG_CONTENT, CCN_TT_DTAG, // content - (char *) faceinst_buf, len3); - contentobj_buf[len2++] = 0;// end-of-contentobj - - // add CONTENTOBJ as the final name component - len += mkBlob(out_buf + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, // comp - (char *) contentobj_buf, len2); - - out_buf[len++] = (unsigned char) 0;// end-of-name - out_buf[len++] = (unsigned char) 0;// end-of-interest - - retbuf = ccnl_buf_new((char *)out_buf, len); - ccnl_face_enqueue(ccnl, from, retbuf); - - /*END ANWER*/ - - ccnl_free(action); - ccnl_free(macsrc); - ccnl_free(ip4src); - ccnl_free(proto); - ccnl_free(host); - ccnl_free(port); - ccnl_free(frag); - ccnl_free(flags); - - //ccnl_mgmt_return_msg(ccnl, orig, from, cp); - return rc; -} - -int -ccnl_mgmt_prefixreg(struct ccnl_relay_s *ccnl, struct ccnl_buf_s *orig, - struct ccnl_prefix_s *prefix, struct ccnl_face_s *from) -{ - unsigned char *buf; - int buflen, num, typ; - struct ccnl_prefix_s *p = NULL; - unsigned char *action, *faceid; - char *cp = "prefixreg cmd failed"; - int rc = -1; - //variables for answer - int len = 0, len2, len3; - - DEBUGMSG(1, "ccnl_mgmt_prefixreg\n"); - action = faceid = NULL; - - buf = prefix->comp[3]; - buflen = prefix->complen[3]; - - if (dehead(&buf, &buflen, &num, &typ) < 0) { - goto Bail; - } - - if (typ != CCN_TT_DTAG || num != CCN_DTAG_CONTENTOBJ) { - goto Bail; - } - - if (dehead(&buf, &buflen, &num, &typ) != 0) { - goto Bail; - } - - if (typ != CCN_TT_DTAG || num != CCN_DTAG_CONTENT) { - goto Bail; - } - - if (dehead(&buf, &buflen, &num, &typ) != 0) { - goto Bail; - } - - if (typ != CCN_TT_BLOB) { - goto Bail; - } - - buflen = num; - - if (dehead(&buf, &buflen, &num, &typ) != 0) { - goto Bail; - } - - if (typ != CCN_TT_DTAG || num != CCN_DTAG_FWDINGENTRY) { - goto Bail; - } - - p = (struct ccnl_prefix_s *) ccnl_calloc(1, sizeof(struct ccnl_prefix_s)); - - if (!p) { - goto Bail; - } - - p->comp = (unsigned char **) ccnl_malloc(CCNL_MAX_NAME_COMP * - sizeof(unsigned char *)); - p->complen = (int *) ccnl_malloc(CCNL_MAX_NAME_COMP * sizeof(int)); - - if (!p->comp || !p->complen) { - goto Bail; - } - - while (dehead(&buf, &buflen, &num, &typ) == 0) { - if (num == 0 && typ == 0) { - break; // end - } - - if (typ == CCN_TT_DTAG && num == CCN_DTAG_NAME) { - while (1) { - if (dehead(&buf, &buflen, &num, &typ) != 0) { - goto Bail; - } - - if (num == 0 && typ == 0) { - break; - } - - if (typ == CCN_TT_DTAG && num == CCN_DTAG_COMPONENT && - p->compcnt < CCNL_MAX_NAME_COMP) { - // if (ccnl_grow_prefix(p)) goto Bail; - if (consume(typ, num, &buf, &buflen, - p->comp + p->compcnt, - p->complen + p->compcnt) < 0) { - goto Bail; - } - - p->compcnt++; - } - else { - if (consume(typ, num, &buf, &buflen, 0, 0) < 0) { - goto Bail; - } - } - } - - continue; - } - - extractStr(action, CCN_DTAG_ACTION); - extractStr(faceid, CCN_DTAG_FACEID); - - if (consume(typ, num, &buf, &buflen, 0, 0) < 0) { - goto Bail; - } - } - - // should (re)verify that action=="prefixreg" - if (faceid && p->compcnt > 0) { - struct ccnl_face_s *f; - int fi = strtol((const char *)faceid, NULL, 0); - - DEBUGMSG(1, "mgmt: adding prefix %s to faceid='%s'='%d'\n", - ccnl_prefix_to_path(p), faceid, fi); - - for (f = ccnl->faces; f && f->faceid != fi; f = f->next) { - DEBUGMSG(1, "faceid=%d\n", f->faceid); - } - - if (!f) { - DEBUGMSG(1, "bail!\n"); - goto Bail; - } - - DEBUGMSG(1, "Face %s found! ifndx=%d\n", faceid, f->ifndx); - - ccnl_content_learn_name_route(ccnl, p, f, 0, CCNL_FORWARD_FLAGS_STATIC); - cp = "prefixreg cmd worked"; - } - else { - DEBUGMSG(1, "mgmt: ignored prefixreg faceid=%s\n", faceid); - } - - rc = 0; - -Bail: - /*ANSWER*/ - - len = mkHeader(out_buf, CCN_DTAG_CONTENT, CCN_TT_DTAG); // interest - len += mkHeader(out_buf + len, CCN_DTAG_NAME, CCN_TT_DTAG); // name - - len += mkStrBlob(out_buf + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, "ccnx"); - len += mkStrBlob(out_buf + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, ""); - len += mkStrBlob(out_buf + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, (char *) action); - - // prepare FWDENTRY - len3 = mkHeader(fwdentry_buf, CCNL_DTAG_PREFIX, CCN_TT_DTAG); - len3 += mkStrBlob(fwdentry_buf + len3, CCN_DTAG_ACTION, CCN_TT_DTAG, cp); - len3 += mkStrBlob(fwdentry_buf + len3, CCN_DTAG_NAME, CCN_TT_DTAG, ccnl_prefix_to_path(p)); // prefix - - len3 += mkStrBlob(fwdentry_buf + len3, CCN_DTAG_FACEID, CCN_TT_DTAG, (char *) faceid); - fwdentry_buf[len3++] = 0;// end-of-fwdentry - - // prepare CONTENTOBJ with CONTENT - len2 = mkHeader(contentobj_buf, CCN_DTAG_CONTENTOBJ, CCN_TT_DTAG);// contentobj - len2 += mkBlob(contentobj_buf + len2, CCN_DTAG_CONTENT, CCN_TT_DTAG, // content - (char *) fwdentry_buf, len3); - contentobj_buf[len2++] = 0;// end-of-contentobj - - // add CONTENTOBJ as the final name component - len += mkBlob(out_buf + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, // comp - (char *) contentobj_buf, len2); - - out_buf[len++] = 0;// end-of-name - out_buf[len++] = 0;// end-of-interest - - /*END ANWER*/ - ccnl_free(faceid); - ccnl_free(action); - free_prefix(p); - - DEBUGMSG(1, "data='%s' faceid=%d cp='%s'\n", orig->data, from->faceid, cp); - ccnl_mgmt_return_msg(ccnl, orig, from, cp); - return rc; -} - -static int ccnl_mgmt_handle(struct ccnl_relay_s *ccnl, struct ccnl_buf_s *orig, - struct ccnl_prefix_s *prefix, struct ccnl_face_s *from, char *cmd, - int verified) -{ - DEBUGMSG(99, "ccnl_mgmt_handle \"%s\"\n", cmd); - if (!verified) { - ccnl_mgmt_return_msg(ccnl, orig, from, - "refused: error signature not verified"); - return -1; - } - - if (!strcmp(cmd, "newface")) { - DEBUGMSG(1, "ccnl_mgmt_newface msg\n"); - ccnl_mgmt_newface(ccnl, orig, prefix, from); - } - else if (!strcmp(cmd, "prefixreg")) { - DEBUGMSG(1, "ccnl_mgmt_prefixreg msg\n"); - ccnl_mgmt_prefixreg(ccnl, orig, prefix, from); - } - else { - DEBUGMSG(99, "unknown mgmt command %s\n", cmd); - - ccnl_mgmt_return_msg(ccnl, orig, from, "unknown mgmt command"); - return -1; - } - - return 0; -} - -char cmd[500]; -int ccnl_mgmt(struct ccnl_relay_s *ccnl, struct ccnl_buf_s *orig, - struct ccnl_prefix_s *prefix, struct ccnl_face_s *from) -{ - if (prefix->complen[2] < (int) sizeof(cmd)) { - memcpy(cmd, prefix->comp[2], prefix->complen[2]); - cmd[prefix->complen[2]] = '\0'; - } - else { - strcpy(cmd, "cmd-is-too-long-to-display"); - } - - DEBUGMSG(99, "ccnl_mgmt request \"%s\"\n", cmd); - - if (ccnl_is_local_addr(from)) { - goto MGMT; - } - - DEBUGMSG(99, " rejecting because src is not a local addr\n"); - ccnl_mgmt_return_msg(ccnl, orig, from, - "refused: origin of mgmt cmd is not local"); - return -1; - - MGMT: ccnl_mgmt_handle(ccnl, orig, prefix, from, cmd, 1); - - return 0; -} - -#if 0 - char *cmd = (char *) prefix->comp[2]; - - if (!ccnl_is_local_addr(&from->peer)) { - DEBUGMSG(99, " rejecting because src=%s is not a local addr\n", - ccnl_addr2ascii(&from->peer)); - ccnl_mgmt_return_msg(ccnl, orig, from, - "refused: origin of mgmt cmd is not local"); - return -1; - } - - if (!strcmp(cmd, "newface")) { - DEBUGMSG(1, "ccnl_mgmt_newface msg\n"); - ccnl_mgmt_newface(ccnl, orig, prefix, from); - } - else if (!strcmp(cmd, "prefixreg")) { - DEBUGMSG(1, "ccnl_mgmt_prefixreg msg\n"); - ccnl_mgmt_prefixreg(ccnl, orig, prefix, from); - } - else { - DEBUGMSG(99, "unknown mgmt command %s\n", cmd); - - ccnl_mgmt_return_msg(ccnl, orig, from, "unknown mgmt command"); - return -1; - } - - return 0; -} -#endif - -// eof diff --git a/sys/net/ccn_lite/ccnl-ext.h b/sys/net/ccn_lite/ccnl-ext.h deleted file mode 100644 index ea1f0411dc..0000000000 --- a/sys/net/ccn_lite/ccnl-ext.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * @f ccnl-ext.h - * @b header file for CCN lite extentions (forward declarations) - * - * Copyright (C) 2011-13, Christian Tschudin, University of Basel - * Copyright (C) 2013, Christian Mehlis, Freie Universität Berlin - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * File history: - * 2013-03-30 created - */ - -// ---------------------------------------------------------------------- - -#ifndef CCNL_EXT_H__ -#define CCNL_EXT_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#define compute_ccnx_digest(buf) sha256(buf->data, buf->datalen, NULL) - -#ifdef USE_FRAG - -struct ccnl_frag_s *ccnl_frag_new(int protocol, int mtu); - -void ccnl_frag_reset(struct ccnl_frag_s *e, struct ccnl_buf_s *buf, - int ifndx, sockunion *su); - -int ccnl_frag_getfragcount(struct ccnl_frag_s *e, int origlen, - int *totallen); - -struct ccnl_buf_s *ccnl_frag_getnext(struct ccnl_frag_s *e, - int *ifndx, sockunion *su); - -/* -struct ccnl_buf_s* ccnl_frag_handle_fragment(struct ccnl_relay_s *r, - struct ccnl_face_s *f, unsigned char *data, int datalen); -*/ - -void ccnl_frag_destroy(struct ccnl_frag_s *e); - -/* -struct ccnl_buf_s* ccnl_frag_fragment(struct ccnl_relay_s *ccnl, - struct ccnl_frag_s *frag, - struct ccnl_buf_s *buf); -*/ - -typedef int (RX_datagram)(struct ccnl_relay_s *, struct ccnl_face_s *, - unsigned char **, int *); - -int ccnl_frag_RX_frag2012(RX_datagram callback, struct ccnl_relay_s *relay, - struct ccnl_face_s *from, - unsigned char **data, int *datalen); - -int ccnl_frag_RX_CCNx2013(RX_datagram callback, struct ccnl_relay_s *relay, - struct ccnl_face_s *from, - unsigned char **data, int *datalen); - -int ccnl_is_fragment(unsigned char *data, int datalen); -#else -# define ccnl_frag_new(e,u) NULL -# define ccnl_frag_destroy(e) do{}while(0) -# define ccnl_frag_handle_fragment(r,f,data,len) ccnl_buf_new(data,len) -# define ccnl_is_fragment(d,l) 0 -#endif // USE_FRAG - -// ---------------------------------------------------------------------- - -// ---------------------------------------------------------------------- - -int ccnl_mgmt(struct ccnl_relay_s *ccnl, struct ccnl_buf_s *buf, - struct ccnl_prefix_s *prefix, struct ccnl_face_s *from); - -struct ccnl_prefix_s * -ccnl_prefix_clone(struct ccnl_prefix_s *p); - -struct ccnl_prefix_s * -ccnl_prefix_clone_strip(struct ccnl_prefix_s *p, int strip); - -// ---------------------------------------------------------------------- - -# define ccnl_sched_CTS_done(S,C,L) do{}while(0) -# define ccnl_sched_destroy(S) do{}while(0) - -char *ccnl_prefix_to_path(struct ccnl_prefix_s *pr); - -#ifdef __cplusplus -} -#endif - -#endif /* CCNL_EXT_H__ */ - -// eof diff --git a/sys/net/ccn_lite/ccnl-includes.h b/sys/net/ccn_lite/ccnl-includes.h deleted file mode 100644 index 89e5667349..0000000000 --- a/sys/net/ccn_lite/ccnl-includes.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * @f ccnl-includes.h - * @b does the #include of all (system) header file - * - * Copyright (C) 2011, Christian Tschudin, University of Basel - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * File history: - * 2011-03-30 created - */ - -#include -#include -#include -#include -#include - -#include "crypto/sha256.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define RIOT_MSG_DEV (1) -#define RIOT_TRANS_DEV (2) - -#define RIOT_MSG_IDX (0) -#define RIOT_TRANS_IDX (1) - -#ifdef __cplusplus -} -#endif - -// eof diff --git a/sys/net/ccn_lite/ccnl-pdu.c b/sys/net/ccn_lite/ccnl-pdu.c deleted file mode 100644 index 1f6ea88080..0000000000 --- a/sys/net/ccn_lite/ccnl-pdu.c +++ /dev/null @@ -1,231 +0,0 @@ -/* - * @f ccnl-pdu.c - * @b CCN lite - create and manipulate CCN protocol data units - * - * Copyright (C) 2011-13, Christian Tschudin, University of Basel - * Copyright (C) 2013, Christian Mehlis, Freie Universität Berlin - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * File history: - * 2011-03-13 created (cft): orig name ccnl-parse-ccnb.c - * 2013-04-04 modified (ms): #if defined(CCNL_SIMULATION) || defined(CCNL_OMNET) - */ - -#include - -#include "ccnl-core.h" -#include "ccnx.h" - -int dehead(unsigned char **buf, int *len, int *num, int *typ) -{ - int i; - int val = 0; - - if (*len > 0 && **buf == 0) { // end - *num = *typ = 0; - *buf += 1; - *len -= 1; - return 0; - } - - for (i = 0; (unsigned int) i < sizeof(i) && i < *len; i++) { - unsigned char c = (*buf)[i]; - - if (c & 0x80) { - *num = (val << 4) | ((c >> 3) & 0xf); - *typ = c & 0x7; - *buf += i + 1; - *len -= i + 1; - return 0; - } - - val = (val << 7) | c; - } - - return -1; -} - -int mkHeader(unsigned char *buf, unsigned int num, unsigned int tt) -{ - unsigned char tmp[100]; - int len = 0, i; - - *tmp = 0x80 | ((num & 0x0f) << 3) | tt; - len = 1; - num = num >> 4; - - while (num > 0) { - tmp[len++] = num & 0x7f; - num = num >> 7; - } - - for (i = len - 1; i >= 0; i--) { - *buf++ = tmp[i]; - } - - return len; -} - -static int addBlob(unsigned char *out, char *cp, int cnt) -{ - int len; - - len = mkHeader(out, cnt, CCN_TT_BLOB); - memcpy(out + len, cp, cnt); - len += cnt; - - return len; -} - -int mkBlob(unsigned char *out, unsigned int num, unsigned int tt, char *cp, - int cnt) -{ - int len; - - len = mkHeader(out, num, tt); - len += addBlob(out + len, cp, cnt); - out[len++] = 0; - - return len; -} - -int mkStrBlob(unsigned char *out, unsigned int num, unsigned int tt, char *str) -{ - return mkBlob(out, num, tt, str, strlen(str)); -} - -int mkBinaryInt(unsigned char *out, unsigned int num, unsigned int tt, - unsigned int val, int bytes) -{ - int len = mkHeader(out, num, tt); - - if (!bytes) { - for (bytes = sizeof(val) - 1; bytes > 0; bytes--) - if (val >> (8 * bytes)) { - break; - } - - bytes++; - } - - len += mkHeader(out + len, bytes, CCN_TT_BLOB); - - while (bytes > 0) { // big endian - bytes--; - out[len++] = 0x0ff & (val >> (8 * bytes)); - } - - out[len++] = 0; // end-of-entry - return len; -} - -int unmkBinaryInt(unsigned char **data, int *datalen, unsigned int *result, - unsigned char *width) -{ - unsigned char *cp = *data; - int len = *datalen, typ, num; - unsigned int val = 0; - - if (dehead(&cp, &len, &num, &typ) != 0 || typ != CCN_TT_BLOB) { - return -1; - } - - if (width) { - if (*width < num) { - num = *width; - } - else { - *width = num; - } - } - - // big endian (network order): - while (num-- > 0 && len > 0) { - val = (val << 8) | *cp++; - len--; - } - - *result = val; - - if (len < 1 || *cp != '\0') { // no end-of-entry - return -1; - } - - *data = cp + 1; - *datalen = len - 1; - return 0; -} - -// ---------------------------------------------------------------------- -// (ms): Brought here the following two. I noticed also that some -// of them are replicated elsewhere in the util/ dir. Should we put them -// in one place only ? - -int mkInterest(char **namecomp, unsigned int *nonce, unsigned char *out) -{ - int len = mkHeader(out, CCN_DTAG_INTEREST, CCN_TT_DTAG); // interest - len += mkHeader(out + len, CCN_DTAG_NAME, CCN_TT_DTAG); // name - - while (*namecomp) { - len += mkHeader(out + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG); // comp - int k = strlen(*namecomp); - len += mkHeader(out + len, k, CCN_TT_BLOB); - memcpy(out + len, *namecomp++, k); - len += k; - out[len++] = 0; // end-of-component - } - - out[len++] = 0; // end-of-name - - if (nonce) { - len += mkHeader(out + len, CCN_DTAG_NONCE, CCN_TT_DTAG); - len += mkHeader(out + len, sizeof(unsigned int), CCN_TT_BLOB); - memcpy(out + len, (void *) nonce, sizeof(unsigned int)); - len += sizeof(unsigned int); - } - - out[len++] = 0; // end-of-interest - - return len; -} - -int -mkContent(char **namecomp, char *data, int datalen, unsigned char *out) -{ - int len = mkHeader(out, CCN_DTAG_CONTENTOBJ, CCN_TT_DTAG); // content - len += mkHeader(out + len, CCN_DTAG_NAME, CCN_TT_DTAG); // name - - while (*namecomp) { - len += mkHeader(out + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG); // comp - int k = strlen(*namecomp); - len += mkHeader(out + len, k, CCN_TT_BLOB); - memcpy(out + len, *namecomp++, k); - len += k; - out[len++] = 0;// end-of-component - } - - out[len++] = 0; // end-of-name - - len += mkHeader(out + len, CCN_DTAG_CONTENT, CCN_TT_DTAG); // content obj - len += mkHeader(out + len, datalen, CCN_TT_BLOB); - memcpy(out + len, data, datalen); - len += datalen; - out[len++] = 0;// end-of-content obj - - out[len++] = 0;// end-of-content - - return len; -} - -// eof diff --git a/sys/net/ccn_lite/ccnl-pdu.h b/sys/net/ccn_lite/ccnl-pdu.h deleted file mode 100644 index dd36757fd6..0000000000 --- a/sys/net/ccn_lite/ccnl-pdu.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * @f ccnl-pdu.h - * - * Copyright (C) 2013, Christian Mehlis, Freie University Berlin - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -int dehead(unsigned char **buf, int *len, int *num, int *typ); -int mkHeader(unsigned char *buf, unsigned int num, unsigned int tt); -int mkBlob(unsigned char *out, unsigned int num, unsigned int tt, char *cp, int cnt); -int mkStrBlob(unsigned char *out, unsigned int num, unsigned int tt, char *str); -int mkBinaryInt(unsigned char *out, unsigned int num, unsigned int tt, - unsigned int val, int bytes); -int unmkBinaryInt(unsigned char **data, int *datalen, unsigned int *result, - unsigned char *width); -int mkInterest(char **namecomp, unsigned int *nonce, unsigned char *out); -int mkContent(char **namecomp, char *data, int datalen, unsigned char *out); - -#ifdef __cplusplus -} -#endif diff --git a/sys/net/ccn_lite/ccnl-platform.c b/sys/net/ccn_lite/ccnl-platform.c deleted file mode 100644 index 12fb613e04..0000000000 --- a/sys/net/ccn_lite/ccnl-platform.c +++ /dev/null @@ -1,163 +0,0 @@ -/* - * @f ccnl-platform.c - * @b routines for uniform time handling - * - * Copyright (C) 2011-13, Christian Tschudin, University of Basel - * Copyright (C) 2013, Christian Mehlis, Freie Universität Berlin - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * File history: - * 2012-11 created - * 2013-03-18 updated (ms): removed omnet related code, and moved struct - * ccnl_timer_s to the '#ifndef CCNL_LINUXKERNEL' section - */ - -#include -#include -#include - -#include "ccnl-core.h" -#include "ccnl-platform.h" - -#include "vtimer.h" - -long -timevaldelta(struct timeval *a, struct timeval *b) -{ - return 1000000 * (a->tv_sec - b->tv_sec) + a->tv_usec - b->tv_usec; -} - -// ---------------------------------------------------------------------- - -struct ccnl_timer_s *eventqueue; - -void -ccnl_get_timeval(struct timeval *tv) -{ - timex_t now; - - vtimer_now(&now); - - tv->tv_sec = now.seconds; - tv->tv_usec = now.microseconds; -} - -void * -ccnl_set_timer(int usec, void (*fct)(void *aux1, void *aux2), - void *aux1, void *aux2) -{ - struct ccnl_timer_s *t, **pp; - static int handlercnt; - - t = (struct ccnl_timer_s *) ccnl_calloc(1, sizeof(*t)); - - if (!t) { - return 0; - } - - t->fct2 = fct; - ccnl_get_timeval(&t->timeout); - usec += t->timeout.tv_usec; - t->timeout.tv_sec += usec / 1000000; - t->timeout.tv_usec = usec % 1000000; - t->aux1 = aux1; - t->aux2 = aux2; - - for (pp = &eventqueue; ; pp = &((*pp)->next)) { - if (!*pp || (*pp)->timeout.tv_sec > t->timeout.tv_sec || - ((*pp)->timeout.tv_sec == t->timeout.tv_sec && - (*pp)->timeout.tv_usec > t->timeout.tv_usec)) { - t->next = *pp; - t->handler = handlercnt++; - *pp = t; - return t; - } - } - - return NULL; // ? -} - -void * -ccnl_set_absolute_timer(struct timeval abstime, void (*fct)(void *aux1, void *aux2), - void *aux1, void *aux2) -{ - struct ccnl_timer_s *t, **pp; - static int handlercnt; - - t = (struct ccnl_timer_s *) ccnl_calloc(1, sizeof(*t)); - - if (!t) { - return 0; - } - - t->fct2 = fct; - t->timeout = abstime; - t->aux1 = aux1; - t->aux2 = aux2; - - for (pp = &eventqueue; ; pp = &((*pp)->next)) { - if (!*pp || (*pp)->timeout.tv_sec > t->timeout.tv_sec || - ((*pp)->timeout.tv_sec == t->timeout.tv_sec && - (*pp)->timeout.tv_usec > t->timeout.tv_usec)) { - t->next = *pp; - t->handler = handlercnt++; - *pp = t; - return t; - } - } - - return NULL; // ? -} - -void -ccnl_rem_timer(void *h) -{ - struct ccnl_timer_s **pp; - - DEBUGMSG(99, "removing time handler %p\n", h); - - for (pp = &eventqueue; *pp; pp = &((*pp)->next)) { - if ((void *)*pp == h) { - struct ccnl_timer_s *e = *pp; - *pp = e->next; - ccnl_free(e); - break; - } - } -} - -char * -timestamp(void) -{ - static char ts[30], *cp; - struct timeval now; - ccnl_get_timeval(&now); - - sprintf(ts, "%.4lu", (time_t) 100000 * now.tv_sec + now.tv_usec); - cp = strchr(ts, '.'); - - if (!cp) { - strcat(ts, ".0000"); - } - else if (strlen(cp) > 5) { - cp[5] = '\0'; - } - else while (strlen(cp) < 5) { - strcat(cp, "0"); - } - - return ts; -} - -// eof diff --git a/sys/net/ccn_lite/ccnl-platform.h b/sys/net/ccn_lite/ccnl-platform.h deleted file mode 100644 index 4a17cbce11..0000000000 --- a/sys/net/ccn_lite/ccnl-platform.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * @f ccnl-platform.h - * - * Copyright (C) 2013, Christian Mehlis, Freie University Berlin - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// (ms) I moved the following struct def here because it is used by all -// containers apart from the kernel (this way I don't need to redefine it -// for omnet. -// -struct ccnl_timer_s { - struct ccnl_timer_s *next; - struct timeval timeout; - void (*fct)(char, int); - void (*fct2)(void *, void *); - char node; - int intarg; - void *aux1; - void *aux2; - int handler; -}; - -void ccnl_get_timeval(struct timeval *tv); - -long timevaldelta(struct timeval *a, struct timeval *b); - -void *ccnl_set_timer(int usec, void (*fct)(void *aux1, void *aux2), - void *aux1, void *aux2); - -void -ccnl_rem_timer(void *h); - -extern struct ccnl_timer_s *eventqueue; - -#ifdef __cplusplus -} -#endif diff --git a/sys/net/ccn_lite/ccnl-riot-compat.c b/sys/net/ccn_lite/ccnl-riot-compat.c deleted file mode 100644 index b471e7b944..0000000000 --- a/sys/net/ccn_lite/ccnl-riot-compat.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * @f ccnl-riot-compat.c - * - * Copyright (C) 2013, Christian Mehlis, Freie University Berlin - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include - -#include "msg.h" -#include "thread.h" - -#include "ieee802154_frame.h" - -#include "ccnl.h" -#include "ccnl-core.h" -#include "ccnl-pdu.h" -#include "ccnl-riot-compat.h" - -#if defined (MODULE_AT86RF231) || defined(MODULE_CC2420) || defined(MODULE_MC1322X) -ieee802154_packet_t p; -#else -radio_packet_t p; -#endif - -transceiver_command_t tcmd; -msg_t mesg, rep; - -char relay_helper_stack[THREAD_STACKSIZE_MAIN]; - -int riot_send_transceiver(uint8_t *buf, uint16_t size, uint16_t to) -{ - DEBUGMSG(1, "this is a RIOT TRANSCEIVER based connection\n"); - DEBUGMSG(1, "size=%" PRIu16 " to=%" PRIu16 "\n", size, to); - - if (size > PAYLOAD_SIZE) { - DEBUGMSG(1, "size > PAYLOAD_SIZE: %d > %d\n", size, PAYLOAD_SIZE); - return 0; - } - -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X - memset(&p, 0, sizeof(ieee802154_packet_t)); - p.frame.payload_len = size; - p.frame.fcf.frame_type = IEEE_802154_DATA_FRAME; - p.frame.fcf.dest_addr_m = IEEE_802154_SHORT_ADDR_M; - p.frame.fcf.src_addr_m = IEEE_802154_SHORT_ADDR_M; - p.frame.dest_addr[1] = (to & 0xff); - p.frame.dest_addr[0] = (to >> 8); - p.frame.payload = buf; - p.frame.dest_pan_id = IEEE_802154_DEFAULT_PAN_ID; -#else - p.length = size; - p.dst = (to == RIOT_BROADCAST) ? 0 : to; - p.data = buf; -#endif - - tcmd.transceivers = TRANSCEIVER; - tcmd.data = &p; - - mesg.type = SND_PKT; - mesg.content.ptr = (char *) &tcmd; - msg_send_receive(&mesg, &rep, transceiver_pid); - - return size; -} - -int riot_send_msg(uint8_t *buf, uint16_t size, uint16_t to) -{ - DEBUGMSG(1, "this is a RIOT MSG based connection\n"); - DEBUGMSG(1, "size=%" PRIu16 " to=%" PRIu16 "\n", size, to); - - uint8_t *buf2 = ccnl_malloc(sizeof(riot_ccnl_msg_t) + size); - if (!buf2) { - DEBUGMSG(1, " malloc failed...dorpping msg!\n"); - return 0; - } - - riot_ccnl_msg_t *rmsg = (riot_ccnl_msg_t *) buf2; - rmsg->payload = buf2 + sizeof(riot_ccnl_msg_t); - rmsg->size = size; - - memcpy(rmsg->payload, buf, size); - - msg_t m; - m.type = CCNL_RIOT_MSG; - m.content.ptr = (char *) rmsg; - DEBUGMSG(1, "sending msg to pid=%" PRIkernel_pid "\n", to); - msg_send(&m, to); - - return size; -} - -void riot_send_nack(uint16_t to) -{ - msg_t m; - m.type = CCNL_RIOT_NACK; - DEBUGMSG(1, "sending NACK msg to pid=%" PRIkernel_pid"\n", to); - msg_try_send(&m, to); -} - -void *ccnl_riot_relay_helper_start(void *); - -kernel_pid_t riot_start_helper_thread(void) -{ - return thread_create(relay_helper_stack, sizeof(relay_helper_stack), - THREAD_PRIORITY_MAIN - 2, CREATE_STACKTEST, - ccnl_riot_relay_helper_start, NULL, "relay-helper"); -} - -char *riot_ccnl_event_to_string(int event) -{ - switch (event) { - case PKT_PENDING: - return "PKT_PENDING"; - - case CCNL_RIOT_MSG: - return "RIOT_MSG"; - - case CCNL_RIOT_HALT: - return "RIOT_HALT"; - - case CCNL_RIOT_POPULATE: - return "RIOT_POPULATE"; - - case CCNL_RIOT_PRINT_STAT: - return "CCNL_RIOT_PRINT_STAT"; - - case ENOBUFFER: - return "ENOBUFFER"; - - default: - return "UNKNOWN"; - } -} diff --git a/sys/net/ccn_lite/ccnl-riot-compat.h b/sys/net/ccn_lite/ccnl-riot-compat.h deleted file mode 100644 index af43b0fd1b..0000000000 --- a/sys/net/ccn_lite/ccnl-riot-compat.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * @f ccnl-riot-compat.h - * - * Copyright (C) 2013, Christian Mehlis, Freie University Berlin - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "ccn_lite/ccnl-riot.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define RIOT_CCN_EVENT_NUMBER_OFFSET (1 << 8) - -#define RIOT_BROADCAST TRANSCEIVER_BROADCAST - -typedef struct riot_ccnl_msg { - void *payload; - uint16_t size; -} riot_ccnl_msg_t; - -int riot_send_transceiver(uint8_t *buf, uint16_t size, uint16_t to); -int riot_send_msg(uint8_t *buf, uint16_t size, uint16_t to); -void riot_send_nack(uint16_t to); -kernel_pid_t riot_start_helper_thread(void); -char *riot_ccnl_event_to_string(int event); - -#ifdef __cplusplus -} -#endif diff --git a/sys/net/ccn_lite/ccnl.h b/sys/net/ccn_lite/ccnl.h deleted file mode 100644 index 6864633475..0000000000 --- a/sys/net/ccn_lite/ccnl.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - * @f ccnl.h - * @b header file for CCN lite (CCNL) - * - * Copyright (C) 2011-13, Christian Tschudin, University of Basel - * Copyright (C) 2013, Christian Mehlis, Freie Universität Berlin - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * File history: - * 2011-03-30 created - */ - -#ifdef __cplusplus -extern "C" { -#endif - -#define CCNL_MAX_INTERFACES 2 /* transceiver and msg interfaces */ - -#define CCNL_INTEREST_TIMEOUT_SEC 0 -#define CCNL_INTEREST_TIMEOUT_USEC ((CCNL_CHECK_RETRANSMIT_USEC) * ((CCNL_MAX_INTEREST_RETRANSMIT) + 1)) - -#define CCNL_CONTENT_TIMEOUT_SEC 2 -#define CCNL_CONTENT_TIMEOUT_USEC 0 - -#define CCNL_NONCE_TIMEOUT_SEC 0 -#define CCNL_NONCE_TIMEOUT_USEC (3 * (CCNL_CHECK_RETRANSMIT_USEC)) - -#define CCNL_MAX_CONTENT_SERVED_STAT 10 - -#define CCNL_MAX_INTEREST_RETRANSMIT 5 -#define CCNL_MAX_INTEREST_OPTIMISTIC 2 - -#define CCNL_FACE_TIMEOUT_SEC 10 -#define CCNL_FACE_TIMEOUT_USEC 0 - -#define CCNL_FWD_TIMEOUT_SEC 10 -#define CCNL_FWD_TIMEOUT_USEC 0 - -#define CCNL_CHECK_TIMEOUT_SEC 1 -#define CCNL_CHECK_TIMEOUT_USEC 0 - -#define CCNL_CHECK_RETRANSMIT_SEC 0 -#define CCNL_CHECK_RETRANSMIT_USEC (300 * 1000) - -#define CCNL_MAX_NAME_COMP 16 -#define CCNL_MAX_IF_QLEN 64 - -#define CCNL_MAX_NONCES 256 // for detected dups - -#define TIMEOUT_TO_US(SEC, USEC) ((SEC)*1000*1000 + (USEC)) - -// ---------------------------------------------------------------------- -// our own CCN-lite extensions for the ccnb encoding: - -// management protocol: (ccnl-ext-mgmt.c) -#define CCNL_DTAG_MACSRC 99001 // newface: which L2 interface -#define CCNL_DTAG_IP4SRC 99002 // newface: which L3 interface -#define CCNL_DTAG_UNIXSRC 99003 // newface: which UNIX path -#define CCNL_DTAG_FRAG 99004 // fragmentation protocol, see core.h -#define CCNL_DTAG_FACEFLAGS 99005 // -#define CCNL_DTAG_DEVINSTANCE 99006 // adding/removing a device/interface -#define CCNL_DTAG_DEVNAME 99007 // name of interface (eth0, wlan0) -#define CCNL_DTAG_DEVFLAGS 99008 // -#define CCNL_DTAG_MTU 99009 // - -#define CCNL_DTAG_DEBUGREQUEST 99100 // -#define CCNL_DTAG_DEBUGACTION 99101 // dump, halt, dump+halt - -//FOR THE DEBUG_REPLY MSG -#define CCNL_DTAG_DEBUGREPLY 99201 // dump reply -#define CCNL_DTAG_INTERFACE 99202 // interface list -#define CCNL_DTAG_NEXT 99203 // next pointer e.g. for faceinstance -#define CCNL_DTAG_PREV 99204 // prev pointer e.g. for faceinstance -#define CCNL_DTAG_IFNDX 99205 -#define CCNL_DTAG_IP 99206 -#define CCNL_DTAG_ETH 99207 -#define CCNL_DTAG_UNIX 99208 -#define CCNL_DTAG_PEER 99209 -#define CCNL_DTAG_FWD 99210 -#define CCNL_DTAG_FACE 99211 -#define CCNL_DTAG_ADDRESS 99212 -#define CCNL_DTAG_SOCK 99213 -#define CCNL_DTAG_REFLECT 99214 -#define CCNL_DTAG_PREFIX 99215 -#define CCNL_DTAG_INTERESTPTR 99216 -#define CCNL_DTAG_LAST 99217 -#define CCNL_DTAG_MIN 99218 -#define CCNL_DTAG_MAX 99219 -#define CCNL_DTAG_RETRIES 99220 -#define CCNL_DTAG_PUBLISHER 99221 -#define CCNL_DTAG_CONTENTPTR 99222 -#define CCNL_DTAG_LASTUSE 99223 -#define CCNL_DTAG_SERVEDCTN 99224 - -// fragmentation protocol: (ccnl-ext-frag.c, FRAG_SEQUENCED2012) -#define CCNL_DTAG_FRAGMENT2012 144144 // http://redmine.ccnx.org/issues/100803 -#define CCNL_DTAG_FRAGMENT 144199 // pending request (2013-07-24) - -#define CCNL_DTAG_FRAG_TYPE (CCNL_DTAG_FRAGMENT+1) -#define CCNL_DTAG_FRAG_FLAGS (CCNL_DTAG_FRAGMENT+2) -#define CCNL_DTAG_FRAG_SEQNR (CCNL_DTAG_FRAGMENT+3) // our seq number - -#define CCNL_DTAG_FRAG_OLOSS (CCNL_DTAG_FRAGMENT+5) // our loss count -#define CCNL_DTAG_FRAG_YSEQN (CCNL_DTAG_FRAGMENT+6) // your (highest) seq no -/* -#define CCNL_DTAG_FRAG_YSEQN16 (CCNL_DTAG_FRAGMENT+4) -#define CCNL_DTAG_FRAG_YSEQN32 (CCNL_DTAG_FRAGMENT+5) -*/ -#define CCNL_DTAG_FRAG_FLAG_MASK 0x03 -#define CCNL_DTAG_FRAG_FLAG_FIRST 0x01 -#define CCNL_DTAG_FRAG_FLAG_MID 0x00 -#define CCNL_DTAG_FRAG_FLAG_LAST 0x02 -#define CCNL_DTAG_FRAG_FLAG_SINGLE 0x03 - -#define CCNL_DTAG_FRAG_FLAG_STATUSREQ 0x04 - -// echo "FHBH" | base64 -d | hexdump -v -e '/1 "@x%02x"'| tr @ '\\'; echo -#define CCNL_FRAG_TYPE_CCNx2013_VAL "\x14\x70\x47" - -// fragmentation protocol: (ccnl-ext-frag.c, FRAG_WIRE2013) -#define CCNL_DTAG_WIRE 333333 -#define CCNL_DTAG_WFRAG_FLAGS (CCNL_DTAG_WIRE+1) -#define CCNL_DTAG_WFRAG_OSEQN (CCNL_DTAG_WIRE+2) // our seq number -#define CCNL_DTAG_WFRAG_OLOSS (CCNL_DTAG_WIRE+3) // our loss count -#define CCNL_DTAG_WFRAG_YSEQN (CCNL_DTAG_WIRE+4) // your (highest) seq no -#define CCNL_DTAG_WFRAG_FLAG_FIRST 0x01 -#define CCNL_DTAG_WFRAG_FLAG_LAST 0x02 - -#define ENABLE_DEBUG (0) -#include "debug.h" - -// function alias for RIOTs debug infrastructure -#define DEBUGMSG(LVL, ...) DEBUG(__VA_ARGS__) - -#ifdef __cplusplus -} -#endif - -// eof diff --git a/sys/net/ccn_lite/ccnx.h b/sys/net/ccn_lite/ccnx.h deleted file mode 100644 index 40829d7696..0000000000 --- a/sys/net/ccn_lite/ccnx.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * @f ccnx.h - * @b CCN constants - * - * Copyright (C) 2011, Christian Tschudin, University of Basel - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * File history: - * 2011-03-13 created - */ - -#ifdef __cplusplus -extern "C" { -#endif - -// ---------------------------------------------------------------------- - -#define CCN_DEFAULT_MTU PAYOAD_SIZE - -// ---------------------------------------------------------------------- - -#define CCN_TT_TAG 1 -#define CCN_TT_DTAG 2 -#define CCN_TT_ATTR 3 -#define CCN_TT_DATTR 4 -#define CCN_TT_BLOB 5 -#define CCN_TT_UDATA 6 - -#define CCN_DTAG_ANY 13 -#define CCN_DTAG_NAME 14 -#define CCN_DTAG_COMPONENT 15 -#define CCN_DTAG_CONTENT 19 -#define CCN_DTAG_SIGNEDINFO 20 -#define CCN_DTAG_INTEREST 26 -#define CCN_DTAG_KEY 27 -#define CCN_DTAG_KEYLOCATOR 28 -#define CCN_DTAG_KEYNAME 29 -#define CCN_DTAG_SIGNATURE 37 -#define CCN_DTAG_TIMESTAMP 39 -#define CCN_DTAG_TYPE 40 -#define CCN_DTAG_NONCE 41 -#define CCN_DTAG_SCOPE 42 -#define CCN_DTAG_EXCLUDE 43 -#define CCN_DTAG_ANSWERORIGKIND 47 -#define CCN_DTAG_WITNESS 53 -#define CCN_DTAG_SIGNATUREBITS 54 -#define CCN_DTAG_FRESHNESS 58 -#define CCN_DTAG_FINALBLOCKID 59 -#define CCN_DTAG_PUBPUBKDIGEST 60 -#define CCN_DTAG_PUBCERTDIGEST 61 -#define CCN_DTAG_CONTENTOBJ 64 -#define CCN_DTAG_ACTION 73 -#define CCN_DTAG_FACEID 74 -#define CCN_DTAG_IPPROTO 75 -#define CCN_DTAG_HOST 76 -#define CCN_DTAG_PORT 77 -#define CCN_DTAG_FWDINGFLAGS 79 -#define CCN_DTAG_FACEINSTANCE 80 -#define CCN_DTAG_FWDINGENTRY 81 -#define CCN_DTAG_MINSUFFCOMP 83 -#define CCN_DTAG_MAXSUFFCOMP 84 -#define CCN_DTAG_SEQNO 256 -#define CCN_DTAG_CCNPDU 17702112 - -#ifdef __cplusplus -} -#endif - -// eof diff --git a/sys/net/ccn_lite/util/Makefile b/sys/net/ccn_lite/util/Makefile deleted file mode 100644 index 5cf15fbe9e..0000000000 --- a/sys/net/ccn_lite/util/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -MODULE := ccn_lite_client -INCLUDES += -I$(RIOTBASE)/sys/net/ccn_lite -include $(RIOTBASE)/Makefile.base diff --git a/sys/net/ccn_lite/util/ccn-lite-ctrl.c b/sys/net/ccn_lite/util/ccn-lite-ctrl.c deleted file mode 100644 index 4e4b7eb49d..0000000000 --- a/sys/net/ccn_lite/util/ccn-lite-ctrl.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - * @f util/ccn-lite-ctrl.c - * @b control utility to steer a ccn-lite relay - * - * Copyright (C) 2012-13, Christian Tschudin, University of Basel - * Copyright (C) 2013, Christian Mehlis, Freie Universität Berlin - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * File history: - * 2012-06-01 created - * 2013-07 heavy reworking and parsing - * of return message - */ - -#include -#include -#include - -#include "ccnx.h" -#include "ccnl.h" -#include "ccnl-pdu.h" -#include "ccnl-core.h" - -// ---------------------------------------------------------------------- - -int -mkNewFaceRequest(unsigned char *out, char *macsrc, char *ip4src, - char *host, char *port, char *flags) -{ - int len = 0, len2, len3; - - unsigned char *contentobj = ccnl_malloc(500); - if (!contentobj) { - puts("mkNewFaceRequest: malloc failed"); - return 0; - } - - unsigned char *faceinst = ccnl_malloc(500); - if (!faceinst) { - free(contentobj); - puts("mkNewFaceRequest: malloc failed"); - return 0; - } - - len = mkHeader(out, CCN_DTAG_INTEREST, CCN_TT_DTAG); // interest - len += mkHeader(out + len, CCN_DTAG_NAME, CCN_TT_DTAG); // name - - len += mkStrBlob(out + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, "ccnx"); - len += mkStrBlob(out + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, ""); - len += mkStrBlob(out + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, "newface"); - - // prepare FACEINSTANCE - len3 = mkHeader(faceinst, CCN_DTAG_FACEINSTANCE, CCN_TT_DTAG); - len3 += mkStrBlob(faceinst + len3, CCN_DTAG_ACTION, CCN_TT_DTAG, "newface"); - - if (macsrc) { - len3 += mkStrBlob(faceinst + len3, CCNL_DTAG_MACSRC, CCN_TT_DTAG, macsrc); - } - - if (ip4src) { - len3 += mkStrBlob(faceinst + len3, CCNL_DTAG_IP4SRC, CCN_TT_DTAG, ip4src); - len3 += mkStrBlob(faceinst + len3, CCN_DTAG_IPPROTO, CCN_TT_DTAG, "17"); - } - - if (host) { - len3 += mkStrBlob(faceinst + len3, CCN_DTAG_HOST, CCN_TT_DTAG, host); - } - - if (port) { - len3 += mkStrBlob(faceinst + len3, CCN_DTAG_PORT, CCN_TT_DTAG, port); - } - - /* - if (frag) - len3 += mkStrBlob(faceinst+len3, CCNL_DTAG_FRAG, CCN_TT_DTAG, frag); - */ - if (flags) { - len3 += mkStrBlob(faceinst + len3, CCNL_DTAG_FACEFLAGS, CCN_TT_DTAG, flags); - } - - faceinst[len3++] = 0; // end-of-faceinst - - // prepare CONTENTOBJ with CONTENT - len2 = mkHeader(contentobj, CCN_DTAG_CONTENTOBJ, CCN_TT_DTAG); // contentobj - len2 += mkBlob(contentobj + len2, CCN_DTAG_CONTENT, CCN_TT_DTAG, // content - (char *) faceinst, len3); - contentobj[len2++] = 0; // end-of-contentobj - - // add CONTENTOBJ as the final name component - len += mkBlob(out + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, // comp - (char *) contentobj, len2); - - out[len++] = 0; // end-of-name - out[len++] = 0; // end-of-interest - - free(contentobj); - free(faceinst); - - return len; -} - -// ---------------------------------------------------------------------- - -int -mkPrefixregRequest(unsigned char *out, char reg, char *path, char *faceid) -{ - int len = 0, len2, len3; - char *cp; - - unsigned char *contentobj = ccnl_malloc(500); - if (!contentobj) { - puts("mkNewFaceRequest: malloc failed"); - return 0; - } - - unsigned char *fwdentry = ccnl_malloc(500); - if (!fwdentry) { - free(contentobj); - puts("mkNewFaceRequest: malloc failed"); - return 0; - } - - len = mkHeader(out, CCN_DTAG_INTEREST, CCN_TT_DTAG); // interest - len += mkHeader(out + len, CCN_DTAG_NAME, CCN_TT_DTAG); // name - - len += mkStrBlob(out + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, "ccnx"); - len += mkStrBlob(out + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, ""); - len += mkStrBlob(out + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, - reg ? "prefixreg" : "prefixunreg"); - - // prepare FWDENTRY - len3 = mkHeader(fwdentry, CCN_DTAG_FWDINGENTRY, CCN_TT_DTAG); - len3 += mkStrBlob(fwdentry + len3, CCN_DTAG_ACTION, CCN_TT_DTAG, - reg ? "prefixreg" : "prefixunreg"); - len3 += mkHeader(fwdentry + len3, CCN_DTAG_NAME, CCN_TT_DTAG); // prefix - - cp = strtok(path, "/"); - - while (cp) { - len3 += mkBlob(fwdentry + len3, CCN_DTAG_COMPONENT, CCN_TT_DTAG, - cp, strlen(cp)); - cp = strtok(NULL, "/"); - } - - fwdentry[len3++] = 0; // end-of-prefix - len3 += mkStrBlob(fwdentry + len3, CCN_DTAG_FACEID, CCN_TT_DTAG, faceid); - fwdentry[len3++] = 0; // end-of-fwdentry - - // prepare CONTENTOBJ with CONTENT - len2 = mkHeader(contentobj, CCN_DTAG_CONTENTOBJ, CCN_TT_DTAG); // contentobj - len2 += mkBlob(contentobj + len2, CCN_DTAG_CONTENT, CCN_TT_DTAG, // content - (char *) fwdentry, len3); - contentobj[len2++] = 0; // end-of-contentobj - - // add CONTENTOBJ as the final name component - len += mkBlob(out + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, // comp - (char *) contentobj, len2); - - out[len++] = 0; // end-of-name - out[len++] = 0; // end-of-interest - - free(contentobj); - free(fwdentry); - - // ccnl_prefix_free(p); - return len; -} - -// ---------------------------------------------------------------------- diff --git a/sys/net/ccn_lite/util/ccn-lite-ctrl.h b/sys/net/ccn_lite/util/ccn-lite-ctrl.h deleted file mode 100644 index 4e2c47d992..0000000000 --- a/sys/net/ccn_lite/util/ccn-lite-ctrl.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * @f ccn-lite-ctrl.h - * - * Copyright (C) 2011-13, Christian Tschudin, University of Basel - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -int mkNewFaceRequest(unsigned char *out, char *macsrc, char *ip4src, - char *host, char *port, char *flags); - -int mkPrefixregRequest(unsigned char *out, char reg, char *path, char *faceid); - -#ifdef __cplusplus -} -#endif diff --git a/sys/net/ccn_lite/util/ccnl-riot-client.c b/sys/net/ccn_lite/util/ccnl-riot-client.c deleted file mode 100644 index 6e88162486..0000000000 --- a/sys/net/ccn_lite/util/ccnl-riot-client.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - * @f ccnl-riot-client.c client side api for ccnl on RIOT - * - * Copyright (C) 2013, Christian Mehlis, Freie Universität Berlin - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include - -#include "msg.h" -#include "random.h" - -#include "ccnl.h" -#include "ccnl-core.h" -#include "ccnl-riot-compat.h" -#include "ccn-lite-ctrl.h" -#include "ccnl-pdu.h" - -int ccnl_riot_client_get(kernel_pid_t relay_pid, char *name, char *reply_buf) -{ - char *prefix[CCNL_MAX_NAME_COMP]; - char *cp = strtok(name, "/"); - int i = 0; - - while (i < (CCNL_MAX_NAME_COMP - 1) && cp) { - prefix[i++] = cp; - cp = strtok(NULL, "/"); - } - - //prefix[i] = 0; //segment to request - prefix[i + 1] = 0; - - int content_len = 0; - - for (int segment = 0; ; segment++) { - char segment_string[16]; //max=999\0 - memset(segment_string, 0, 16); - snprintf(segment_string, 16, "%d", segment); - prefix[i] = segment_string; - unsigned char *interest_pkg = ccnl_malloc(PAYLOAD_SIZE); - if (!interest_pkg) { - puts("ccnl_riot_client_get: malloc failed"); - return 0; - } - unsigned int interest_nonce = genrand_uint32(); - int interest_len = mkInterest(prefix, &interest_nonce, interest_pkg); - DEBUGMSG(1, "relay_pid=%" PRIkernel_pid " interest_len=%d\n", relay_pid, interest_len); - - riot_ccnl_msg_t rmsg; - rmsg.payload = interest_pkg; - rmsg.size = interest_len; - - msg_t m, rep; - m.content.ptr = (char *) &rmsg; - m.type = CCNL_RIOT_MSG; - msg_send(&m, relay_pid); - - /* ######################################################################### */ - - msg_receive(&rep); - free(interest_pkg); - if (rep.type == CCNL_RIOT_NACK) { - /* network stack was not able to fetch this chunk */ - return 0; - } - - /* we got a chunk of data from the network stack */ - riot_ccnl_msg_t *rmsg_reply = (riot_ccnl_msg_t *) rep.content.ptr; - - unsigned char *data = rmsg_reply->payload; - int datalen = (int) rmsg_reply->size; - DEBUGMSG(1, "%d bytes left; msg from=%" PRIkernel_pid "\n", datalen, rep.sender_pid); - - int scope = 3, aok = 3, minsfx = 0, maxsfx = CCNL_MAX_NAME_COMP, - contlen = 0; - struct ccnl_buf_s *buf = 0, *nonce = 0, *ppkd = 0; - struct ccnl_prefix_s *p = 0; - unsigned char *content = 0; - - buf = ccnl_extract_prefix_nonce_ppkd(&data, &datalen, &scope, &aok, &minsfx, - &maxsfx, &p, &nonce, &ppkd, &content, &contlen); - - if (!buf) { - DEBUGMSG(6, " parsing error or no prefix\n"); - return 0; - } - - DEBUGMSG(1, "content_len=%d contlen=%d\n", content_len, contlen); - memcpy(reply_buf + content_len, content, contlen); - content_len += contlen; - - free_prefix(p); - free_3ptr_list(buf, nonce, ppkd); - ccnl_free(rmsg_reply); - - DEBUGMSG(1, "contentlen=%d CCNL_RIOT_CHUNK_SIZE=%d\n", contlen, CCNL_RIOT_CHUNK_SIZE); - if (contlen < CCNL_RIOT_CHUNK_SIZE || CCNL_RIOT_CHUNK_SIZE < contlen) { - /* last chunk */ - break; - } - } - - return content_len; -} - -int ccnl_riot_client_new_face(kernel_pid_t relay_pid, char *type, char *faceid, - unsigned char *reply_buf) -{ - DEBUGMSG(1, "riot_new_face: mkNewFaceRquest\n"); - int len = mkNewFaceRequest(reply_buf, type, NULL, NULL, faceid, NULL); - - riot_ccnl_msg_t rmsg; - rmsg.payload = reply_buf; - rmsg.size = len; - - msg_t m, rep; - m.content.ptr = (char *) &rmsg; - m.type = CCNL_RIOT_MSG; - DEBUGMSG(1, " sending face req to relay\n"); - msg_send(&m, relay_pid); - - /* ######################################################################### */ - - msg_receive(&rep); - DEBUGMSG(1, " received reply from relay\n"); - riot_ccnl_msg_t *rmsg_reply = (riot_ccnl_msg_t *) rep.content.ptr; - memcpy(reply_buf, rmsg_reply->payload, rmsg_reply->size); - int size = rmsg_reply->size; - - ccnl_free(rmsg_reply); - - return size; -} - -int ccnl_riot_client_register_prefix(kernel_pid_t relay_pid, char *prefix, char *faceid, - unsigned char *reply_buf) -{ - DEBUGMSG(1, "riot_register_prefix: mkPrefixregRequest\n"); - int len = mkPrefixregRequest(reply_buf, 1, prefix, faceid); - - riot_ccnl_msg_t rmsg; - rmsg.payload = reply_buf; - rmsg.size = len; - - msg_t m, rep; - m.content.ptr = (char *) &rmsg; - m.type = CCNL_RIOT_MSG; - DEBUGMSG(1, " sending prefix req to relay\n"); - msg_send(&m, relay_pid); - - /* ######################################################################### */ - - msg_receive(&rep); - DEBUGMSG(1, " received reply from relay\n"); - riot_ccnl_msg_t *rmsg_reply = (riot_ccnl_msg_t *) rep.content.ptr; - memcpy(reply_buf, rmsg_reply->payload, rmsg_reply->size); - reply_buf[rmsg_reply->size] = '\0'; - int size = rmsg_reply->size; - - ccnl_free(rmsg_reply); - - return size; -} - -int ccnl_riot_client_publish(kernel_pid_t relay_pid, char *prefix, char *faceid, char *type, unsigned char *reply_buf) -{ - ccnl_riot_client_new_face(relay_pid, type, faceid, reply_buf); - int content_len = ccnl_riot_client_register_prefix(relay_pid, prefix, faceid, reply_buf); - return content_len; -} diff --git a/sys/net/include/ccn_lite/ccnl-riot.h b/sys/net/include/ccn_lite/ccnl-riot.h deleted file mode 100644 index 83851cf648..0000000000 --- a/sys/net/include/ccn_lite/ccnl-riot.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * @f ccnl-riot.h - * - * Copyright (C) 2013, Christian Mehlis, Freie Universität Berlin - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/** - * @defgroup ccnl CCN lite - * @ingroup net - * @brief CCN-lite, a lightweight implementation of the Content Centric - * Networking Protocol of XEROX Parc - * - * @see - * CCNx Protocol - * - * - * @{ - * @file - * @brief CCN lite interface - * @author Christian Mehlis - */ -#ifndef RIOT_CCN_COMPAT_H_ -#define RIOT_CCN_COMPAT_H_ - -#include - -#include "transceiver.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define TRANSCEIVER TRANSCEIVER_DEFAULT - -#define CCNL_DEFAULT_CHANNEL 6 -#define CCNL_DEFAULT_MAX_CACHE_ENTRIES 0 /* 0: no content caching, cache is disabled */ -#define CCNL_DEFAULT_THRESHOLD_PREFIX 1 -#define CCNL_DEFAULT_THRESHOLD_AGGREGATE 2 - -#define CCNL_RIOT_EVENT_NUMBER_OFFSET (1 << 8) -#define CCNL_RIOT_MSG (CCNL_RIOT_EVENT_NUMBER_OFFSET + 0) -#define CCNL_RIOT_HALT (CCNL_RIOT_EVENT_NUMBER_OFFSET + 1) -#define CCNL_RIOT_POPULATE (CCNL_RIOT_EVENT_NUMBER_OFFSET + 2) -#define CCNL_RIOT_PRINT_STAT (CCNL_RIOT_EVENT_NUMBER_OFFSET + 3) -#define CCNL_RIOT_NACK (CCNL_RIOT_EVENT_NUMBER_OFFSET + 4) -#define CCNL_RIOT_CONFIG_CACHE (CCNL_RIOT_EVENT_NUMBER_OFFSET + 5) -#define CCNL_RIOT_RESERVED (CCNL_RIOT_EVENT_NUMBER_OFFSET + 6) - -#define CCNL_HEADER_SIZE (40) - -#ifdef MODULE_NATIVENET -/* - * static content for testing ccn get has this chunk size - * this test (populate + interest /riot/text) current works - * only on transceiver which can handle ~130 bytes - */ -# define CCNL_RIOT_CHUNK_SIZE (90) -#else -/* XXX: For (at least) IEEE 802.15.4 radios (PAYLOAD_SIZE - CCNL_HEADER_SIZE) - * is one byte too big for transmission. Therefore, we subtract one byte more. - */ -# define CCNL_RIOT_CHUNK_SIZE (PAYLOAD_SIZE - CCNL_HEADER_SIZE - 1) -#endif - -/** - * @brief starts the ccnl relay - * - * @note to stop the relay send msg "RIOT_HALT" to this thread - * - */ -void *ccnl_riot_relay_start(void *arg); - -/** - * @brief starts an appication server, which can repy to ccn interests - * - * @param arg the pid of the relay - */ -void *ccnl_riot_appserver_start(void *arg); - -#ifdef __cplusplus -} -#endif - -/** - * @} - */ -#endif /* RIOT_CCN_COMPAT_H_ */ diff --git a/sys/net/include/ccn_lite/test_data/text.txt.ccnb.h b/sys/net/include/ccn_lite/test_data/text.txt.ccnb.h deleted file mode 100644 index 2eedb00dc9..0000000000 --- a/sys/net/include/ccn_lite/test_data/text.txt.ccnb.h +++ /dev/null @@ -1,367 +0,0 @@ -/* - * @f txt.txt.ccnb.h this is a text file encoded as ccnb chunks - * - * Copyright (C) 2013, Christian Mehlis, Freie Universität Berlin - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -#define RIOT_CCNL_POPULATE (1) - -#if RIOT_CCNL_POPULATE - -unsigned char text_txt_ccnb_0[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x8d, 0x30, 0x00, 0x00, 0x01, 0x9a, - 0x05, 0xd5, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x0a, 0x3d, 0x3d, - 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x0a, 0x0a, 0x32, 0x30, 0x30, 0x38, 0x0a, - 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x0a, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, - 0x74, 0x20, 0x72, 0x6f, 0x6f, 0x74, 0x73, 0x2e, 0x20, 0x54, 0x68, 0x65, - 0x20, 0x73, 0x65, 0x65, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x52, 0x49, - 0x4f, 0x54, 0x20, 0x77, 0x61, 0x73, 0x20, 0x46, 0x65, 0x75, 0x65, 0x72, - 0x57, 0x61, 0x72, 0x65, 0x2c, 0x20, 0x61, 0x6e, 0x20, 0x6f, 0x70, 0x65, - 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_0_len = 118; -unsigned char text_txt_ccnb_1[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x8d, 0x31, 0x00, 0x00, 0x01, 0x9a, - 0x05, 0xd5, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x66, 0x6f, 0x72, 0x20, - 0x57, 0x69, 0x72, 0x65, 0x6c, 0x65, 0x73, 0x73, 0x20, 0x53, 0x65, 0x6e, - 0x73, 0x6f, 0x72, 0x20, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x73, - 0x2e, 0x0a, 0x49, 0x74, 0x20, 0x77, 0x61, 0x73, 0x20, 0x70, 0x61, 0x72, - 0x74, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x46, 0x65, 0x75, - 0x65, 0x72, 0x57, 0x68, 0x65, 0x72, 0x65, 0x20, 0x70, 0x72, 0x6f, 0x6a, - 0x65, 0x63, 0x74, 0x20, 0x77, 0x68, 0x65, 0x72, 0x65, 0x20, 0x66, 0x69, - 0x72, 0x65, 0x66, 0x69, 0x67, 0x68, 0x74, 0x65, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_1_len = 118; -unsigned char text_txt_ccnb_10[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x95, 0x31, 0x30, 0x00, 0x00, 0x01, - 0x9a, 0x05, 0xd5, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6d, 0x69, 0x73, 0x73, - 0x21, 0x0a, 0x0a, 0x0a, 0x54, 0x68, 0x72, 0x65, 0x65, 0x20, 0x67, 0x6f, - 0x6f, 0x64, 0x20, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x73, 0x20, 0x74, - 0x6f, 0x20, 0x74, 0x68, 0x69, 0x6e, 0x6b, 0x20, 0x61, 0x62, 0x6f, 0x75, - 0x74, 0x20, 0x61, 0x20, 0x6e, 0x65, 0x77, 0x20, 0x4f, 0x53, 0x20, 0x66, - 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x49, 0x6f, 0x54, 0x2e, 0x0a, - 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, - 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_10_len = 119; -unsigned char text_txt_ccnb_11[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x95, 0x31, 0x31, 0x00, 0x00, 0x01, - 0x9a, 0x05, 0xd5, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, - 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, - 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, - 0x3d, 0x0a, 0x0a, 0x52, 0x49, 0x4f, 0x54, 0x20, 0x69, 0x73, 0x20, 0x44, - 0x65, 0x76, 0x65, 0x6c, 0x6f, 0x70, 0x65, 0x72, 0x20, 0x46, 0x72, 0x69, - 0x65, 0x6e, 0x64, 0x6c, 0x79, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, - 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, - 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_11_len = 119; -unsigned char text_txt_ccnb_12[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x95, 0x31, 0x32, 0x00, 0x00, 0x01, - 0x9a, 0x05, 0xd5, 0x0a, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x20, - 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x61, 0x72, 0x65, - 0x20, 0x75, 0x73, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x2e, 0x20, 0x44, 0x6f, - 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x77, 0x61, 0x73, 0x74, 0x65, 0x20, 0x74, - 0x69, 0x6d, 0x65, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x63, 0x6f, 0x6d, - 0x70, 0x6c, 0x65, 0x78, 0x20, 0x6f, 0x72, 0x20, 0x6e, 0x65, 0x77, 0x20, - 0x65, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x73, - 0x2e, 0x0a, 0x0a, 0x2d, 0x20, 0x53, 0x74, 0x61, 0x6e, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_12_len = 119; -unsigned char text_txt_ccnb_13[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x95, 0x31, 0x33, 0x00, 0x00, 0x01, - 0x9a, 0x05, 0xd5, 0x64, 0x61, 0x72, 0x64, 0x20, 0x70, 0x72, 0x6f, 0x67, - 0x72, 0x61, 0x6d, 0x6d, 0x69, 0x6e, 0x67, 0x20, 0x69, 0x6e, 0x20, 0x43, - 0x20, 0x6f, 0x72, 0x20, 0x43, 0x2b, 0x2b, 0x0a, 0x2d, 0x20, 0x53, 0x74, - 0x61, 0x6e, 0x64, 0x61, 0x72, 0x64, 0x20, 0x64, 0x65, 0x76, 0x65, 0x6c, - 0x6f, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x74, 0x6f, 0x6f, 0x6c, 0x73, - 0x20, 0x73, 0x75, 0x63, 0x68, 0x20, 0x61, 0x73, 0x20, 0x67, 0x63, 0x63, - 0x2c, 0x20, 0x67, 0x64, 0x62, 0x0a, 0x2d, 0x20, 0x4d, 0x69, 0x6e, 0x69, - 0x6d, 0x69, 0x7a, 0x65, 0x64, 0x20, 0x68, 0x61, 0x72, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_13_len = 119; -unsigned char text_txt_ccnb_14[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x95, 0x31, 0x34, 0x00, 0x00, 0x01, - 0x9a, 0x05, 0xd5, 0x64, 0x77, 0x61, 0x72, 0x65, 0x20, 0x64, 0x65, 0x70, - 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x74, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x0a, - 0x2d, 0x20, 0x5a, 0x65, 0x72, 0x6f, 0x20, 0x6c, 0x65, 0x61, 0x72, 0x6e, - 0x69, 0x6e, 0x67, 0x20, 0x63, 0x75, 0x72, 0x76, 0x65, 0x20, 0x66, 0x6f, - 0x72, 0x20, 0x65, 0x6d, 0x62, 0x65, 0x64, 0x64, 0x65, 0x64, 0x20, 0x70, - 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x6d, 0x69, 0x6e, 0x67, 0x0a, 0x2d, - 0x20, 0x43, 0x6f, 0x64, 0x65, 0x20, 0x6f, 0x6e, 0x63, 0x65, 0x2c, 0x20, - 0x72, 0x75, 0x6e, 0x20, 0x62, 0x6f, 0x74, 0x68, 0x20, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_14_len = 119; -unsigned char text_txt_ccnb_15[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x95, 0x31, 0x35, 0x00, 0x00, 0x01, - 0x9a, 0x05, 0xd5, 0x6f, 0x6e, 0x20, 0x31, 0x36, 0x2d, 0x62, 0x69, 0x74, - 0x20, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x73, 0x20, 0x28, - 0x65, 0x2e, 0x67, 0x2e, 0x20, 0x4d, 0x53, 0x50, 0x34, 0x33, 0x30, 0x29, - 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6f, 0x6e, 0x20, 0x33, 0x32, 0x2d, 0x62, - 0x69, 0x74, 0x20, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x73, - 0x20, 0x28, 0x65, 0x2e, 0x67, 0x2e, 0x20, 0x41, 0x52, 0x4d, 0x29, 0x0a, - 0x2d, 0x20, 0x50, 0x61, 0x72, 0x74, 0x69, 0x61, 0x6c, 0x20, 0x50, 0x4f, - 0x53, 0x49, 0x58, 0x20, 0x63, 0x6f, 0x6d, 0x70, 0x6c, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_15_len = 119; -unsigned char text_txt_ccnb_16[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x95, 0x31, 0x36, 0x00, 0x00, 0x01, - 0x9a, 0x05, 0xd5, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x2e, 0x20, 0x54, 0x6f, - 0x77, 0x61, 0x72, 0x64, 0x73, 0x20, 0x66, 0x75, 0x6c, 0x6c, 0x20, 0x50, - 0x4f, 0x53, 0x49, 0x58, 0x20, 0x63, 0x6f, 0x6d, 0x70, 0x6c, 0x69, 0x61, - 0x6e, 0x63, 0x65, 0x2e, 0x0a, 0x0a, 0x52, 0x49, 0x4f, 0x54, 0x20, 0x69, - 0x73, 0x20, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20, 0x46, - 0x72, 0x69, 0x65, 0x6e, 0x64, 0x6c, 0x79, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, - 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, - 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_16_len = 119; -unsigned char text_txt_ccnb_17[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x95, 0x31, 0x37, 0x00, 0x00, 0x01, - 0x9a, 0x05, 0xd5, 0x0a, 0x0a, 0x42, 0x65, 0x6e, 0x65, 0x66, 0x69, 0x74, - 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x61, 0x20, 0x6d, 0x69, 0x63, 0x72, - 0x6f, 0x6b, 0x65, 0x72, 0x6e, 0x65, 0x6c, 0x20, 0x61, 0x72, 0x63, 0x68, - 0x69, 0x74, 0x65, 0x63, 0x74, 0x75, 0x72, 0x65, 0x20, 0x61, 0x6e, 0x64, - 0x20, 0x61, 0x20, 0x74, 0x69, 0x63, 0x6b, 0x6c, 0x65, 0x73, 0x73, 0x20, - 0x73, 0x63, 0x68, 0x65, 0x64, 0x75, 0x6c, 0x65, 0x72, 0x20, 0x6f, 0x6e, - 0x20, 0x76, 0x65, 0x72, 0x79, 0x20, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x77, - 0x65, 0x69, 0x67, 0x68, 0x74, 0x20, 0x64, 0x65, 0x76, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_17_len = 119; -unsigned char text_txt_ccnb_18[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x95, 0x31, 0x38, 0x00, 0x00, 0x01, - 0x9a, 0x05, 0xd5, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x0a, 0x0a, 0x2d, 0x20, - 0x52, 0x6f, 0x62, 0x75, 0x73, 0x74, 0x6e, 0x65, 0x73, 0x73, 0x20, 0x26, - 0x20, 0x63, 0x6f, 0x64, 0x65, 0x2d, 0x66, 0x6f, 0x6f, 0x74, 0x70, 0x72, - 0x69, 0x6e, 0x74, 0x20, 0x66, 0x6c, 0x65, 0x78, 0x69, 0x62, 0x69, 0x6c, - 0x69, 0x74, 0x79, 0x0a, 0x2d, 0x20, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x69, - 0x6e, 0x67, 0x20, 0x6d, 0x61, 0x78, 0x69, 0x6d, 0x75, 0x6d, 0x20, 0x65, - 0x6e, 0x65, 0x72, 0x67, 0x79, 0x2d, 0x65, 0x66, 0x66, 0x69, 0x63, 0x69, - 0x65, 0x6e, 0x63, 0x79, 0x0a, 0x2d, 0x20, 0x52, 0x65, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_18_len = 119; -unsigned char text_txt_ccnb_19[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x95, 0x31, 0x39, 0x00, 0x00, 0x01, - 0x9a, 0x05, 0xd5, 0x61, 0x6c, 0x2d, 0x74, 0x69, 0x6d, 0x65, 0x20, 0x63, - 0x61, 0x70, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x20, 0x64, 0x75, - 0x65, 0x20, 0x74, 0x6f, 0x20, 0x75, 0x6c, 0x74, 0x72, 0x61, 0x2d, 0x6c, - 0x6f, 0x77, 0x20, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x72, 0x75, 0x70, 0x74, - 0x20, 0x6c, 0x61, 0x74, 0x65, 0x6e, 0x63, 0x79, 0x20, 0x28, 0x7e, 0x35, - 0x30, 0x20, 0x63, 0x6c, 0x6f, 0x63, 0x6b, 0x20, 0x63, 0x79, 0x63, 0x6c, - 0x65, 0x73, 0x29, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x70, 0x72, 0x69, 0x6f, - 0x72, 0x69, 0x74, 0x79, 0x2d, 0x62, 0x61, 0x73, 0x65, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_19_len = 119; -unsigned char text_txt_ccnb_2[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x8d, 0x32, 0x00, 0x00, 0x01, 0x9a, - 0x05, 0xd5, 0x72, 0x73, 0x20, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64, 0x20, - 0x62, 0x65, 0x0a, 0x6d, 0x6f, 0x6e, 0x69, 0x74, 0x6f, 0x72, 0x65, 0x64, - 0x2e, 0x20, 0x4d, 0x61, 0x6a, 0x6f, 0x72, 0x20, 0x64, 0x65, 0x73, 0x69, - 0x67, 0x6e, 0x20, 0x67, 0x6f, 0x61, 0x6c, 0x73, 0x20, 0x77, 0x65, 0x72, - 0x65, 0x20, 0x72, 0x65, 0x6c, 0x69, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, - 0x79, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x72, 0x65, 0x61, 0x6c, 0x2d, 0x74, - 0x69, 0x6d, 0x65, 0x20, 0x67, 0x75, 0x61, 0x72, 0x61, 0x6e, 0x74, 0x65, - 0x65, 0x73, 0x2e, 0x0a, 0x0a, 0x32, 0x30, 0x31, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_2_len = 118; -unsigned char text_txt_ccnb_20[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x95, 0x32, 0x30, 0x00, 0x00, 0x01, - 0x9a, 0x05, 0xd5, 0x64, 0x20, 0x73, 0x63, 0x68, 0x65, 0x64, 0x75, 0x6c, - 0x69, 0x6e, 0x67, 0x0a, 0x2d, 0x20, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x2d, - 0x74, 0x68, 0x72, 0x65, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x77, 0x69, - 0x74, 0x68, 0x20, 0x75, 0x6c, 0x74, 0x72, 0x61, 0x2d, 0x6c, 0x6f, 0x77, - 0x20, 0x74, 0x68, 0x72, 0x65, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x6f, - 0x76, 0x65, 0x72, 0x68, 0x65, 0x61, 0x64, 0x20, 0x28, 0x3c, 0x32, 0x35, - 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x70, 0x65, 0x72, 0x20, 0x74, - 0x68, 0x72, 0x65, 0x61, 0x64, 0x29, 0x0a, 0x0a, 0x52, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_20_len = 119; -unsigned char text_txt_ccnb_21[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x95, 0x32, 0x31, 0x00, 0x00, 0x01, - 0x9a, 0x05, 0xd5, 0x49, 0x4f, 0x54, 0x20, 0x69, 0x73, 0x20, 0x49, 0x6f, - 0x54, 0x20, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x6c, 0x79, 0x0a, 0x2d, - 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, - 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x0a, 0x4d, 0x61, 0x6b, - 0x65, 0x20, 0x79, 0x6f, 0x75, 0x72, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69, - 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x72, 0x65, 0x61, 0x64, - 0x79, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x6d, - 0x61, 0x6c, 0x6c, 0x65, 0x72, 0x20, 0x74, 0x68, 0x69, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_21_len = 119; -unsigned char text_txt_ccnb_22[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x95, 0x32, 0x32, 0x00, 0x00, 0x01, - 0x9a, 0x05, 0xd5, 0x6e, 0x67, 0x73, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, - 0x65, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x77, - 0x69, 0x74, 0x68, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x20, 0x73, - 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, - 0x74, 0x2e, 0x0a, 0x0a, 0x2d, 0x20, 0x36, 0x4c, 0x6f, 0x57, 0x50, 0x41, - 0x4e, 0x2c, 0x20, 0x49, 0x50, 0x76, 0x36, 0x2c, 0x20, 0x52, 0x50, 0x4c, - 0x2c, 0x20, 0x54, 0x43, 0x50, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x55, - 0x44, 0x50, 0x0a, 0x2d, 0x20, 0x53, 0x74, 0x61, 0x74, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_22_len = 119; -unsigned char text_txt_ccnb_23[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x95, 0x32, 0x33, 0x00, 0x00, 0x01, - 0x9a, 0x05, 0xd5, 0x69, 0x63, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x64, 0x79, - 0x6e, 0x61, 0x6d, 0x69, 0x63, 0x20, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, - 0x20, 0x61, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x0a, - 0x2d, 0x20, 0x46, 0x41, 0x54, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x73, - 0x79, 0x73, 0x74, 0x65, 0x6d, 0x0a, 0x2d, 0x20, 0x4c, 0x6f, 0x67, 0x67, - 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x0a, 0x2d, - 0x20, 0x48, 0x69, 0x67, 0x68, 0x20, 0x72, 0x65, 0x73, 0x6f, 0x6c, 0x75, - 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_23_len = 119; -unsigned char text_txt_ccnb_24[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x95, 0x32, 0x34, 0x00, 0x00, 0x01, - 0x9a, 0x05, 0xd5, 0x6c, 0x6f, 0x6e, 0x67, 0x2d, 0x74, 0x65, 0x72, 0x6d, - 0x20, 0x74, 0x69, 0x6d, 0x65, 0x72, 0x73, 0x0a, 0x2d, 0x20, 0x57, 0x69, - 0x73, 0x65, 0x6c, 0x69, 0x62, 0x20, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, - 0x74, 0x20, 0x28, 0x43, 0x2b, 0x2b, 0x20, 0x61, 0x6c, 0x67, 0x6f, 0x72, - 0x69, 0x74, 0x68, 0x6d, 0x20, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, - 0x2c, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x69, 0x6e, 0x67, 0x20, - 0x72, 0x6f, 0x75, 0x74, 0x69, 0x6e, 0x67, 0x2c, 0x20, 0x63, 0x6c, 0x75, - 0x73, 0x74, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x2c, 0x20, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_24_len = 119; -unsigned char text_txt_ccnb_25[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x95, 0x32, 0x35, 0x00, 0x00, 0x01, - 0x9a, 0x03, 0xb5, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x79, 0x6e, 0x63, 0x2c, - 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x2c, 0x20, 0x73, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x20, - 0x61, 0x6e, 0x64, 0x20, 0x6d, 0x6f, 0x72, 0x65, 0x20, 0x61, 0x6c, 0x67, - 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x73, 0x29, 0x0a, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_25_len = 83; -unsigned char text_txt_ccnb_3[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x8d, 0x33, 0x00, 0x00, 0x01, 0x9a, - 0x05, 0xd5, 0x30, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x0a, 0x54, 0x6f, - 0x77, 0x61, 0x72, 0x64, 0x73, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, - 0x65, 0x74, 0x20, 0x63, 0x6f, 0x6d, 0x70, 0x6c, 0x69, 0x61, 0x6e, 0x63, - 0x65, 0x2e, 0x20, 0x54, 0x6f, 0x20, 0x69, 0x6e, 0x63, 0x72, 0x65, 0x61, - 0x73, 0x65, 0x20, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x61, 0x72, 0x69, 0x74, - 0x79, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, - 0x65, 0x20, 0x6e, 0x65, 0x77, 0x20, 0x49, 0x45, 0x54, 0x46, 0x0a, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x73, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_3_len = 118; -unsigned char text_txt_ccnb_4[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x8d, 0x34, 0x00, 0x00, 0x01, 0x9a, - 0x05, 0xd5, 0x2c, 0x20, 0x26, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x3b, 0x6b, - 0x6c, 0x65, 0x6f, 0x73, 0x20, 0x77, 0x61, 0x73, 0x20, 0x66, 0x6f, 0x72, - 0x6b, 0x65, 0x64, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65, - 0x20, 0x6f, 0x72, 0x69, 0x67, 0x6e, 0x61, 0x6c, 0x0a, 0x46, 0x65, 0x75, - 0x65, 0x72, 0x57, 0x61, 0x72, 0x65, 0x20, 0x72, 0x65, 0x70, 0x6f, 0x73, - 0x69, 0x74, 0x6f, 0x72, 0x79, 0x2e, 0x20, 0x53, 0x75, 0x70, 0x70, 0x6f, - 0x72, 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x36, 0x4c, 0x6f, 0x57, 0x50, - 0x41, 0x4e, 0x2c, 0x20, 0x52, 0x50, 0x4c, 0x2c, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_4_len = 118; -unsigned char text_txt_ccnb_5[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x8d, 0x35, 0x00, 0x00, 0x01, 0x9a, - 0x05, 0xd5, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x54, 0x43, 0x50, 0x20, 0x77, - 0x61, 0x73, 0x20, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x74, 0x65, - 0x64, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x0a, 0x66, - 0x6f, 0x6c, 0x6c, 0x6f, 0x77, 0x69, 0x6e, 0x67, 0x20, 0x79, 0x65, 0x61, - 0x72, 0x73, 0x2e, 0x0a, 0x0a, 0x32, 0x30, 0x31, 0x33, 0x0a, 0x2d, 0x2d, - 0x2d, 0x2d, 0x0a, 0x0a, 0x52, 0x49, 0x4f, 0x54, 0x20, 0x67, 0x6f, 0x65, - 0x73, 0x20, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x2e, 0x20, 0x52, 0x49, - 0x4f, 0x54, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_5_len = 118; -unsigned char text_txt_ccnb_6[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x8d, 0x36, 0x00, 0x00, 0x01, 0x9a, - 0x05, 0xd5, 0x65, 0x20, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x20, 0x73, - 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x6f, 0x72, 0x20, 0x6f, 0x66, 0x20, - 0x26, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x3b, 0x6b, 0x6c, 0x65, 0x6f, 0x73, - 0x2e, 0x20, 0x57, 0x65, 0x20, 0x64, 0x65, 0x63, 0x69, 0x64, 0x65, 0x64, - 0x20, 0x6f, 0x6e, 0x0a, 0x72, 0x65, 0x2d, 0x62, 0x72, 0x61, 0x6e, 0x64, - 0x69, 0x6e, 0x67, 0x20, 0x74, 0x6f, 0x20, 0x61, 0x76, 0x6f, 0x69, 0x64, - 0x20, 0x70, 0x72, 0x6f, 0x62, 0x6c, 0x65, 0x6d, 0x73, 0x20, 0x77, 0x69, - 0x74, 0x68, 0x20, 0x73, 0x70, 0x65, 0x6c, 0x6c, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_6_len = 118; -unsigned char text_txt_ccnb_7[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x8d, 0x37, 0x00, 0x00, 0x01, 0x9a, - 0x05, 0xd5, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x70, 0x72, - 0x6f, 0x6e, 0x6f, 0x75, 0x6e, 0x63, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, - 0x65, 0x0a, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, - 0x65, 0x20, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, - 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x20, 0x57, 0x65, 0x20, 0x65, - 0x78, 0x70, 0x6c, 0x69, 0x63, 0x69, 0x74, 0x6c, 0x79, 0x20, 0x70, 0x72, - 0x6f, 0x6d, 0x6f, 0x74, 0x65, 0x20, 0x52, 0x49, 0x4f, 0x54, 0x20, 0x74, - 0x6f, 0x20, 0x61, 0x20, 0x6c, 0x61, 0x72, 0x67, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_7_len = 118; -unsigned char text_txt_ccnb_8[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x8d, 0x38, 0x00, 0x00, 0x01, 0x9a, - 0x05, 0xd5, 0x65, 0x72, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x75, 0x6e, 0x69, - 0x74, 0x79, 0x2e, 0x0a, 0x0a, 0x46, 0x75, 0x74, 0x75, 0x72, 0x65, 0x0a, - 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x0a, 0x42, 0x65, 0x20, 0x70, - 0x61, 0x72, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, - 0x6f, 0x6d, 0x6d, 0x75, 0x6e, 0x69, 0x74, 0x79, 0x2e, 0x20, 0x57, 0x65, - 0x20, 0x69, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x61, 0x62, 0x6f, 0x75, - 0x74, 0x20, 0x6f, 0x6e, 0x67, 0x6f, 0x69, 0x6e, 0x67, 0x20, 0x65, 0x6e, - 0x68, 0x61, 0x6e, 0x63, 0x65, 0x6d, 0x65, 0x6e, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_8_len = 118; -unsigned char text_txt_ccnb_9[] = { - 0x04, 0x82, 0xf2, 0xfa, 0xa5, 0x72, 0x69, 0x6f, 0x74, 0x00, 0xfa, 0xa5, - 0x74, 0x65, 0x78, 0x74, 0x00, 0xfa, 0x8d, 0x39, 0x00, 0x00, 0x01, 0x9a, - 0x05, 0xd5, 0x74, 0x73, 0x0a, 0x69, 0x6e, 0x20, 0x6f, 0x75, 0x72, 0x20, - 0x69, 0x73, 0x73, 0x75, 0x65, 0x20, 0x74, 0x72, 0x61, 0x63, 0x6b, 0x65, - 0x72, 0x2e, 0x20, 0x53, 0x74, 0x61, 0x72, 0x74, 0x20, 0x77, 0x6f, 0x72, - 0x6b, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x6e, 0x20, 0x6e, 0x65, 0x77, 0x20, - 0x66, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x73, 0x20, 0x6f, 0x72, 0x20, - 0x6c, 0x65, 0x74, 0x20, 0x74, 0x68, 0x65, 0x20, 0x52, 0x49, 0x4f, 0x54, - 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x75, 0x6e, 0x69, 0x74, 0x79, 0x20, 0x6b, - 0x6e, 0x6f, 0x77, 0x20, 0x77, 0x68, 0x61, 0x74, 0x00, 0x00 -}; -unsigned int text_txt_ccnb_9_len = 118; - -#endif - -#ifdef __cplusplus -} -#endif diff --git a/sys/net/include/ccn_lite/util/ccnl-riot-client.h b/sys/net/include/ccn_lite/util/ccnl-riot-client.h deleted file mode 100644 index 725c42e8c0..0000000000 --- a/sys/net/include/ccn_lite/util/ccnl-riot-client.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * @f ccnl-riot-client.h client side api for ccnl on RIOT - * - * Copyright (C) 2013, Christian Mehlis, Freie Universität Berlin - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/** - * @ingroup ccnl - * @{ - * @file - * @brief CCN high level client functions - * @author Christian Mehlis - * @} - */ -#ifndef CCNL_RIOT_CLIENT_H -#define CCNL_RIOT_CLIENT_H - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief high level function to fetch a file (all chunks of a file) - * - * @param relay_pid pid of the relay thread - * - * @param name c string represenation of the name to fetch e.g. "/riot/test" - * - * @param reply_buf buffer for the aswer message from the relay - * - * @return the length of the reply message stored in reply_buf - */ -int ccnl_riot_client_get(kernel_pid_t relay_pid, char *name, char *reply_buf); - -/** - * @brief high level function to publish a name, e.g. "/riot/test" - * all interest with "prefix" as prefix received by the rely - * are forwarded to this thread - * - * @note this function uses riot_new_face and riot_register_prefix - * - * @param relay_pid pid of the relay thread - * - * @param prefix c string representation of the name to publish - * - * @param faceid in case of "newMSGface" this is the pid to connect the face to - * in case of "newTRANSface" this is the network address to - * connect the face to - * - * @param type a c string may "newMSGface" for a RIOT message based face or - * "newTRANSface" for a network face - * - * @param reply_buf buffer for the aswer message from the relay - * - * @return the length of the reply message stored in reply_buf - */ -int ccnl_riot_client_publish(kernel_pid_t relay_pid, char *prefix, char *faceid, - char *type, unsigned char *reply_buf); - -/** - * @brief lower layer function to register a new face in the relay - * - * @param relay_pid pid of the relay - * - * @param type a c string may "newMSGface" for a RIOT message based face or - * "newTRANSface" for a network face - * - * @param faceid in case of "newMSGface" this is the pid to connect the face to - * in case of "newTRANSface" this is the network address to - * connect the face to - * - * @param reply_buf buffer for the aswer message from the relay - * - * @return the length of the reply message stored in reply_buf - */ -int ccnl_riot_client_new_face(kernel_pid_t relay_pid, char *type, char *faceid, - unsigned char *reply_buf); - -/** - * @brief lower layer function to register a new prefix - * in the relay - * - * @param relay_pid pid of the relay - * - * @param prefix c string representation of the name to publish - * - * @param faceid in case of "newMSGface" this is the pid to connect the face to - * in case of "newTRANSface" this is the network address to - * connect the face to - * - * @param reply_buf buffer for the aswer message from the relay - * - * @return the length of the reply message stored in reply_buf - */ -int ccnl_riot_client_register_prefix(kernel_pid_t relay_pid, char *prefix, - char *faceid, unsigned char *reply_buf); - -#ifdef __cplusplus -} -#endif - -/** - * @} - */ -#endif /* CCNL_RIOT_CLIENT_H */ diff --git a/sys/net/include/etx_beaconing.h b/sys/net/include/etx_beaconing.h deleted file mode 100644 index 57de38cda1..0000000000 --- a/sys/net/include/etx_beaconing.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2014 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 rpl - * @{ - * @file - * - * Header-file, which includes all constants and functions used for ETX-based beaconing. - * - * @author Stephan Arndt - * @} - */ - -#ifndef ETX_BEACONING_H_ -#define ETX_BEACONING_H_ -#include -#include "sixlowpan.h" -#include "timex.h" - -#ifdef __cplusplus -extern "C" { -#endif - -//[option|length|ipaddr.|packetcount] with up to 15 ipaddr|packetcount pairs -// 1 Byte 1 Byte 1 Byte 1 Byte -#define ETX_BUF_SIZE (32) - -#define ETX_RCV_QUEUE_SIZE (128) - -/* - * Default 40, should be enough to get all messages for neighbors. - * In my tests, the maximum count of neighbors was around 30-something - */ -#if ENABLE_DEBUG -#define ETX_MAX_CANDIDATE_NEIGHBORS (15) //Stacksizes are huge in debug mode, so memory is rare -#else -#define ETX_MAX_CANDIDATE_NEIGHBORS (40) -#endif -//ETX Interval parameters - -/* - * ETX_INTERVAL - * - * Given in ms, the default is 1 second. - * Should be divisible through 2 (For ETX_DEF_JIT_CORRECT) - * and 5 (For ETX_MAX_JITTER) unless those values are adjusted too. - */ -#define ETX_INTERVAL (1ul * MS_IN_USEC) -#define ETX_WINDOW (10) //10 is the default value -#define ETX_BEST_CANDIDATES (15) //Sent only 15 candidates in a beaconing packet -#define ETX_TUPLE_SIZE (2) //1 Byte for Addr, 1 Byte for packets rec. -#define ETX_PKT_REC_OFFSET (ETX_TUPLE_SIZE - 1) //Offset in a tuple of (addr,pkt_rec), will always be the last byte -#define ETX_IPV6_LAST_BYTE (15) //The last byte for an ipv6 address -#define ETX_MAX_JITTER (ETX_INTERVAL / 5ul) //The default value is 20% of ETX_INTERVAL -#define ETX_JITTER_MOD (ETX_MAX_JITTER + 1) //The modulo value for jitter computation -#define ETX_DEF_JIT_CORRECT (ETX_MAX_JITTER / 2) //Default Jitter correction value (normally ETX_MAX_JITTER / 2) -#define ETX_CLOCK_ADJUST (52500) //Adjustment for clockthread computations to stay close/near ETX_INTERVAL - -/* - * The ETX beaconing packet consists of: - * - * 0 1 2 - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- - - - - - - - - * | Option Type | Option Length | Data - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- - - - - - - - - * Option type: Set to 0x20 - * - * Option Length: The length of the Data sent with this packet - * - * Option Data: 2-Octet Pairs of 8 bit for addresses and a positive integer - * denoting the amount of packets received from that IP address - * - * We only need 1 octet for the ip address since RPL for now only allows for - * 255 different addresses. - * - * If the length of this packet says 0, it has received no other beaconing - * packets itself so far. - * - * The packet is always 32bytes long, but may contain varying amounts of - * information. - * The information processed shall not exceed the value set in Option Length. - */ -typedef struct __attribute__((packed)) etx_probe_t { - uint8_t code; - uint8_t length; - uint8_t data[30]; -} etx_probe_t; - -typedef struct etx_neighbor_t { - ipv6_addr_t addr; //The address of this node - uint8_t tx_cur_round; //The indicator for receiving a packet from this candidate this round - uint8_t packets_tx[ETX_WINDOW]; //The packets this node has transmitted TO ME - uint8_t packets_rx; //The packets this node has received FROM ME - double cur_etx; //The currently calculated ETX-value - uint8_t used; //The indicator if this node is active or not -} etx_neighbor_t; - -//prototypes -void etx_init_beaconing(ipv6_addr_t *address); -double etx_get_metric(ipv6_addr_t *address); -void etx_update(etx_neighbor_t *neighbor); - -#define ETX_PKT_OPT (0) //Position of Option-Type-Byte -#define ETX_PKT_OPTVAL (0x20) //Non-standard way of saying this is an ETX-Packet. -#define ETX_PKT_LEN (1) //Position of Length-Byte -#define ETX_DATA_MAXLEN (30) //max length of the data -#define ETX_PKT_HDR_LEN (2) //Option type + Length (1 Byte each) -#define ETX_PKT_DATA (2) //Begin of Data Bytes - -#ifdef __cplusplus -} -#endif - -#endif /* ETX_BEACONING_H_ */ diff --git a/sys/net/include/ieee802154_frame.h b/sys/net/include/ieee802154_frame.h deleted file mode 100644 index e4d9de0d79..0000000000 --- a/sys/net/include/ieee802154_frame.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2013 INRIA. - * - * 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. - */ - -/** - * @defgroup net_ieee802154 IEEE802.15.4 - * @ingroup net - * @brief IEEE802.15.4 adapaption layer - * @{ - * - * @file - * @brief IEEE 802.14.4 framing data structs and prototypes - * - * @author Stephan Zeisberg - * @author Oliver Hahm - */ - -#ifndef IEEE802154_IEEE802154_FRAME -#define IEEE802154_IEEE802154_FRAME - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* maximum 802.15.4 header length */ -#define IEEE_802154_MAX_HDR_LEN (23) -/* ...and FCS*/ -#define IEEE_802154_FCS_LEN (2) - -typedef enum __attribute__((packed)) { - IEEE_802154_BEACON_FRAME = 0, - IEEE_802154_DATA_FRAME = 1, - IEEE_802154_ACK_FRAME = 2, - IEEE_802154_MAC_CMD_FRAME = 3 -} ieee802154_frame_type_t; - -#define IEEE_802154_SHORT_ADDR_M (2) -#define IEEE_802154_LONG_ADDR_M (3) - -#define IEEE_802154_SHORT_MCAST_ADDR (0xffff) -#define IEEE_802154_LONG_MCAST_ADDR {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ - 0xff, 0xff}} - -/** - * @brief The default PAN id to use if not specified otherwise by upper layers - */ -#define IEEE_802154_DEFAULT_PAN_ID (1) - -/** - * @brief Transform 16-bit number from network order (big-endian) to - * little-endian byte order (as used by IEEE 802.15.4). - */ -#define NTOLES(a) (((a) >> 8) | (((a) & 0x00ff) << 8)) - -/** - * @brief Transform 16-bit number from little-endian byte order to network - * order (big-endian). - */ -#define LETONS(a) NTOLES(a) - -/** - * @brief Transform 16-bit number from host byte order to little-endian byte - * order (as used by IEEE 802.15.4). - */ -#define HTOLES(a) a - -/** - * @brief Transform 16-bit number from little-endian byte order to host byte - * order. - */ -#define LETOHS(a) HTOLES(a) - -typedef struct __attribute__((packed)) { - ieee802154_frame_type_t frame_type; - uint8_t sec_enb; - uint8_t frame_pend; - uint8_t ack_req; - uint8_t panid_comp; - uint8_t dest_addr_m; - uint8_t frame_ver; - uint8_t src_addr_m; -} ieee802154_frame_fcf_frame_t; - -typedef struct __attribute__((packed)) { - ieee802154_frame_fcf_frame_t fcf; - uint8_t seq_nr; - uint16_t dest_pan_id; - uint8_t dest_addr[8]; - uint16_t src_pan_id; - uint8_t src_addr[8]; - uint8_t *payload; - uint8_t payload_len; -} ieee802154_frame_t; - -/** - * Structure to represent an IEEE 802.15.4 packet for the transceiver. - */ -typedef struct __attribute__(( packed )) { - /* @{ */ - uint8_t processing; /** < internal processing state */ - uint8_t length; /** < the length of the frame of the frame including fcs*/ - ieee802154_frame_t frame; /** < the ieee802154 frame */ - int8_t rssi; /** < the rssi value */ - uint8_t crc; /** < 1 if crc was successfull, 0 otherwise */ - uint8_t lqi; /** < the link quality indicator */ - /* @} */ -} ieee802154_packet_t; - -uint8_t ieee802154_frame_init(ieee802154_frame_t *frame, uint8_t *buf); -uint8_t ieee802154_frame_get_hdr_len(ieee802154_frame_t *frame); -uint8_t ieee802154_frame_read(uint8_t *buf, ieee802154_frame_t *frame, uint8_t len); -void ieee802154_frame_print_fcf_frame(ieee802154_frame_t *frame); -uint16_t ieee802154_frame_get_fcs(const uint8_t *frame, uint8_t frame_len); - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif /* IEEE802154_IEEE802154_FRAME */ diff --git a/sys/net/include/ipv6.h b/sys/net/include/ipv6.h deleted file mode 100644 index e80702364b..0000000000 --- a/sys/net/include/ipv6.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2014 INRIA. - * - * 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 net_sixlowpan - * @{ - * @file - * @brief IPv6 and ICMP functions - * - * Wraps all API types, constants and functions of - * 6LoWPAN in layer 3. - * - * @author Martine Lenders - */ -#ifndef IPV6_H -#define IPV6_H - -#include "sixlowpan/error.h" -#include "sixlowpan/types.h" -#include "sixlowpan/ip.h" -#include "sixlowpan/icmp.h" -#include "sixlowpan/ndp.h" - -#include "../network_layer/sixlowpan/icmp.h" /* TODO: remove if not needed anymore */ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* IPV6_H */ -/** - * @} - */ diff --git a/sys/net/include/l2_ping.h b/sys/net/include/l2_ping.h deleted file mode 100644 index cb959bdbca..0000000000 --- a/sys/net/include/l2_ping.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (C) 2014, INRIA - * - * 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. - */ - -#ifndef L2_PING_H -#define L2_PING_H - -/** - * @defgroup net_l2_ping Link Layer Ping - * @ingroup net - * @brief Link Layer Ping - * - * @{ - * @file - * @brief Link Layer Ping public interface, data structs, and defines - * - * @author Oliver Hahm - */ - -#include "radio/radio.h" - -#ifdef __cplusplus - extern "C" { -#endif - -/** - * @brief the bitmask of the first link layer payload byte defining the type - */ -#define L2_PAYLOAD_TYPE (0xF0) - -/** - * @brief link layer payload type - * - * @note assure not to interfere with valid network layer values like the - * 6LoWPAN dispatch field - */ -#define L2_PAYLOAD_PING (0x10) - -/** - * @brief the bitmask for the payload identifier, defining the actual l2 ping type - * - * @see l2_ping_type_t - */ -#define L2_PING_TYPE (0x0F) - -/** - * @brief the default interval between two ping packets are sent in microseconds - */ -#define L2_PING_DEFAULT_INTERVAL (50 * 1000u) - -/** - * @brief maximum number of bytes for payload within a l2 ping packet - */ -#define L2_PING_PAYLOAD_SIZE (8) - -/** - * @brief data type for the l2 ping type - */ -typedef enum { - L2_PING = 0x01, /**< ping request packet */ - L2_PONG = 0x02, /**< pong response packet */ - L2_PROBE = 0x04 /**< probe packet */ -} l2_ping_type_t; - -/** - * @brief l2 ping statistics data structure - */ -typedef struct { - radio_address_t dst; /**< the destination address for the last ping request sent */ - uint16_t ping_count; /**< the amount of ping requests sent to this destination */ - uint16_t pong_count; /**< the amount of pong respnses received from this node */ - timex_t last_rtt; /**< the round trip time for the last received pong response */ - timex_t avg_rtt; /**< the average round trip time to this node */ - timex_t max_rtt; /**< the maximum round trip time to this node */ - timex_t min_rtt; /**< the minimum round trip time to this node */ -} l2_ping_stats_t; - -/** - * @brief l2 probe statistics entry - */ -typedef struct { - radio_address_t src; /**< link layer address of the probe's origin */ - uint16_t count; /**< number of received probes from this node */ -} l2_probe_stat_entry_t; - -/** - * @brief payload data structure for l2 ping packets - */ -typedef struct ping_payload { - uint8_t type; /**< the data type */ - uint16_t seq; /**< sequence number */ - /* cppcheck-suppress unusedStructMember */ - char payload[L2_PING_PAYLOAD_SIZE]; /**< the actual payload */ - uint8_t payload_len; /**< number of payload bytes */ -} l2_ping_payload_t; - -/** - * @brief the current l2 ping statistics about the current communication - * partner - */ -extern l2_ping_stats_t l2_ping_stats; - -/** - * @brief initializes the l2 ping module - * - * @note this function gets usually called by auto_init - */ -void l2_ping_init(void); - -/** - * @brief send a ping request - * - * @param[in] addr the destination address - * @param[in] count the number of requests to send, 0 means infinite - * @param[in] interval the interval between sending ping requests, - * if 0 the default interval (#L2_PING_DEFAULT_INTERVAL) - * @param[in] payload optional payload data, may be NULL - * @param[in] payload_len the length of the payload data, must be smaller than - * #L2_PING_PAYLOAD_SIZE - * @param[in] probe_only do not request a pong response - */ -void l2_ping(radio_address_t addr, uint16_t count, uint32_t interval, - const char *payload, uint8_t payload_len, uint8_t probe_only); - -/** - * @brief get l2 probe statistics to check how many probes have been received - * - * @param[out] l2_probe_stats pointer to an array of ::l2_probe_stat_entry_t - * @param[out] count pointer to the number of entries in l2_probe_stats - */ -void l2_probe_stats(l2_probe_stat_entry_t *l2_probe_stats[], uint16_t *count); - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif /* L2_PING_H */ diff --git a/sys/net/include/net_if.h b/sys/net/include/net_if.h deleted file mode 100644 index a877042390..0000000000 --- a/sys/net/include/net_if.h +++ /dev/null @@ -1,511 +0,0 @@ -/* - * Copyright (C) 2013 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. - */ - -/** - * @defgroup net_if Network interfaces - * @brief Abstraction layer between transceiver module and L3 protocol - * implementations. - * @ingroup net - * - * @{ - * - * @file - * @brief Types and functions for network interfaces - * @author Martine Lenders - */ -#ifndef _NET_IF_H -#define _NET_IF_H - -#include -#include - -#include "mutex.h" -#include "transceiver.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief type to specify types of upper layer addresses - */ -typedef uint8_t net_if_l3p_t; - -/** - * @brief Interface protocols (for net_if_t.protocols): Use raw packets with - * static addresses in upper layer. - */ -#define NET_IF_L3P_RAW (0x00) - -/** - * @brief Interface protocols (for net_if_t.protocols): Use unicast IPv6 - * address in upper layer, addr_len must be 128. - */ -#define NET_IF_L3P_IPV6_UNICAST (0x01) - -/** - * @brief Interface protocols (for net_if_t.protocols): Use multicast IPv6 - * address in upper layer, addr_len must be 128. - */ -#define NET_IF_L3P_IPV6_MULTICAST (0x02) - -/** - * @brief Interface protocols (for net_if_t.protocols): Use anycast IPv6 - * address in upper layer, addr_len must be 128. - */ -#define NET_IF_L3P_IPV6_ANYCAST (0x04) - -/** - * @brief Interface protocols (for net_if_t.protocols): Use IPv6 prefix in - * upper layer, addr_len <= 128 becomes prefix length. - */ -#define NET_IF_L3P_IPV6_PREFIX (0x08) - -/** - * @brief Interface protocols (for net_if_t.protocols): Convenience macro - * combining NET_IF_L3P_IPV6_UNICAST, NET_IF_L3P_IPV6_ANYCAST, and - * NET_IF_L3P_IPV6_MULTICAST for comparisons - */ -#define NET_IF_L3P_IPV6_ADDR (NET_IF_L3P_IPV6_UNICAST | NET_IF_L3P_IPV6_ANYCAST \ - | NET_IF_L3P_IPV6_MULTICAST) - -/** - * @brief Interface protocols (for net_if_t.protocols): Convenience macro - * combining NET_IF_L3P_IPV6_UNICAST, NET_IF_L3P_IPV6_ANYCAST, - * NET_IF_L3P_IPV6_MULTICAST, and NET_IF_L3P_IPV6_PREFIX for - * comparisons - */ -#define NET_IF_L3P_IPV6 (NET_IF_L3P_IPV6_UNICAST | NET_IF_L3P_IPV6_ANYCAST \ - | NET_IF_L3P_IPV6_MULTICAST | NET_IF_L3P_IPV6_PREFIX) - -/** - * @brief Interface protocols: Return value of net_if_get_l3p_types() on - * error. - */ -#define NET_IF_L3P_FAILURE (0x80) - -#ifndef NET_IF_MAX -/** - * @brief Maximum number of interfaces. Redefinable via compiler flag. - */ -#define NET_IF_MAX (1) -#endif - -/** - * @brief Data type to represent an EUI-64. - */ -typedef union __attribute__((packed)) { - uint8_t uint8[8]; ///< split into 8 8-bit words. - uint16_t uint16[4]; ///< split into 4 16-bit words. - uint32_t uint32[2]; ///< split into 2 32-bit words. - uint64_t uint64; ///< as one 64-bit word. -} net_if_eui64_t; - -/** - * @brief list type for upper layer address of an interface. - * - * @details The interpretation of the address data is left to the upper layer - * implementations. - */ -typedef struct __attribute__((packed)) net_if_addr_t { - /** - * @brief The next address on the interface. Initialise with NULL - */ - struct net_if_addr_t *addr_next; - - /** - * @brief The next address on the interface. Initialise with NULL - */ - struct net_if_addr_t *addr_prev; - - /** - * @brief Flags to define upper layer protocols this address applies to - */ - net_if_l3p_t addr_protocol; - void *addr_data; ///< The actual upper layer address - uint8_t addr_len; ///< Length of the upper layer address in bit. -} net_if_addr_t; - -typedef uint8_t net_if_trans_addr_m_t; - -/** - * @brief Interface type. - */ -typedef struct { - uint8_t initialized; ///< Detemines if interface is initialized - uint8_t protocols; ///< Interface L3 protocols - transceiver_type_t transceivers; ///< Transceivers to use with this interface - net_if_trans_addr_m_t trans_src_addr_m; ///< Transceiver address mode - mutex_t address_buffer_mutex; ///< Mutex for address buffer operations - net_if_addr_t *addresses; ///< Adresses - uint8_t l3p_data[9]; ///< generic L3 data -} net_if_t; - -#define NET_IF_TRANS_ADDR_M_SHORT 2 ///< Transceiver address mode for short addresses -#define NET_IF_TRANS_ADDR_M_LONG 3 ///< Transceiver address mode for long addresses - -/** - * All registered interfaces. - */ -extern net_if_t interfaces[NET_IF_MAX]; - -/** - * @brief Initializes the module. - */ -void net_if_init(void); - -/** - * @brief Inititializes a new interface - * - * @pre *transceivers* may not be zero. - * - * @param[in] protocols The upper layer protocols to use on this interface. - * @param[in] transceivers The transceivers this interface uses. - * - * @return The new interface's ID on success, -1 on failure. - */ -int net_if_init_interface(net_if_l3p_t protocols, - transceiver_type_t transceivers); - -/** - * @brief Get interface. - * - * @param[in] if_id The interface's ID - * - * @return The interface identified by *if_id* or NULL on failure. - */ -static inline net_if_t *net_if_get_interface(int if_id) -{ - if (if_id < NET_IF_MAX && interfaces[if_id].initialized) { - return &interfaces[if_id]; - } - else { - return NULL; - } -} - - -/** - * @brief Iterates over all intitialized interfaces - * - * @param[in] start Return value of last iteration step. -1 to start iteration. - * - * @return ID of an initialized interface. -1 if end of interface list is - * reached. - */ -int net_if_iter_interfaces(int start); - -/** - * @brief Sets the source address mode for the interface - * - * @param[in] if_id Interface to set source address mode for. - * @param[in] mode The mode to set to. - * - * @return 1 on success, 0 on error - */ -static inline int net_if_set_src_address_mode(int if_id, - net_if_trans_addr_m_t mode) -{ - if (!interfaces[if_id].initialized) { - return 0; - } - - interfaces[if_id].trans_src_addr_m = mode; - return 1; -} - -/** - * @brief Gets the source address mode for the interface - * - * @param[in] if_id Interface to get source address mode from. - * - * @return The interfaces address mode, 0 on error - */ -static inline net_if_trans_addr_m_t net_if_get_src_address_mode(int if_id) -{ - if (!interfaces[if_id].initialized) { - return 0; - } - - return interfaces[if_id].trans_src_addr_m; -} - -/** - * @brief Adds new address to interface - * - * @pre *addr* is not NULL, *addr->addr_data* is not NULL - * - * @param[in] if_id The interface's ID - * @param[in] addr The address to add - * - * @return 1 on success, 0 on failure. - */ -int net_if_add_address(int if_id, net_if_addr_t *addr); - -/** - * @brief Removes first occurance of address from interface - * - * @pre *addr* is not NULL, *addr->addr_data* is not NULL - * - * @param[in] if_id The interface's ID - * @param[in] addr The address to remove - * - * @return 1 on success (and if given address is not registered to this - * interface), 0 on failure - */ -int net_if_del_address(int if_id, net_if_addr_t *addr); - -/** - * @brief Iterates over registered addresses of an interface. - * - * @param[in] if_id The interface's ID - * @param[in,out] addr The previous address as in or the next address as out. - * If *addr* points to NULL it will be set to the - * first address assigned to *if_id*, if *addr* points to - * NULL as out, the last address assigned to *if_id* was - * given as *addr* previously (and the address list was - * completely iterated). - * - * @return The pointer *addr* refers to after call of this function or NULL on - * error - */ -net_if_addr_t *net_if_iter_addresses(int if_id, net_if_addr_t **addr); - -/** - * @brief Get the upper layer protocol types assigned to the interface *if_id* - * - * @param[in] if_id The interface's ID - * @return The upper layer protocol types assigned to the interface *if_id* on - * success, NET_IF_L3P_FAILURE on failure. - */ -net_if_l3p_t net_if_get_l3p_types(int if_id); - -/** - * @brief Add an upper layer protocol types to the interface *if_id* - * - * @param[in] if_id The interface's ID - * @param[in] protocols The upper layer protocol types to assign to the - * interface *if_id* - * @return 1 on success, 0 on failure. - */ -int net_if_add_l3p_types(int if_id, net_if_l3p_t protocols); - -/** - * @brief Remove upper layer protocol types and all addresses of this scope - * from the interface *if_id* - * - * @param[in] if_id The interface's ID - * @param[in] protocols The upper layer protocol types to be removed from the - * interface *if_id* - * @return 1 on success, 0 on failure. - */ -int net_if_del_l3p_types(int if_id, net_if_l3p_t protocols); - -/** - * @brief Sends a packet to a short address over the interface. - * - * @pre Transceivers has to be initialized and transceiver thread has - * to be started. - * - * @param[in] if_id The interface's ID. - * @param[in] target The target's short transceiver address. - * @param[in] packet_data The packet to send - * @param[in] packet_len The length of the packet's data in byte, negative - * number on error. - * - * @return The number of bytes send on success, negative value on failure - */ -int net_if_send_packet(int if_id, uint16_t target, const void *packet_data, - size_t packet_len); - -/** - * @brief Sends a packet to a long address over the interface. If transceiver - * only supports smaller addresses the least significant bit of the - * address will be taken. - * - * @pre Transceivers has to be initialized and transceiver thread has - * to be started. - * - * @param[in] if_id The interface's ID. - * @param[in] target The target's long transceiver address. - * @param[in] packet_data The packet to send - * @param[in] packet_len The length of the packet's data in byte, negative - * number on error. - * - * @return The number of bytes send on success, negative value on failure - */ -int net_if_send_packet_long(int if_id, net_if_eui64_t *target, - const void *packet_data, size_t packet_len); - -/** - * @brief Sends a packet over all initialized interfaces. - * - * @pre Transceivers has to be initialized and transceiver thread has - * to be started. - * - * @param[in] preferred_dest_mode The preferred transceiver address mode for - * the destination broadcast address. Choose - * NET_IF_TRANS_ADDR_M_SHORT if you are not - * sure - * @param[in] payload The packet to send - * @param[in] payload_len The length of the packet's data in byte, - * negative number on error. - * - * @return The number of bytes send on success, negative value on failure - */ -int net_if_send_packet_broadcast(net_if_trans_addr_m_t preferred_dest_mode, - const void *payload, size_t payload_len); - -/** - * @brief register a thread for events an interface's transceiver - * @details This function just wraps transceiver_register(). - * - * @pre Transceivers has to be initialized and transceiver thread has - * to be started. - * - * @param[in] if_id The transceiver's interface to register for - * @param[in] pid The pid of the thread to register - * - * @return 1 on success, 0 otherwise - */ -int net_if_register(int if_id, kernel_pid_t pid); - -/** - * Returns the EUI-64 of the transeivers attached to this interface. This can - * be get by the actual EUI-64 if the transceiver has one or a generated one - * based of the hardware address - * - * @pre Transceivers of this interface has to be initialized and - * transceiver thread has to be started. - * - * @see - * RFC 4944, section 5 - * - * @see - * RFC 6282, section 3.2.2 - * - * - * @param[out] eui64 The EUI-64 to fill - * @param[in] if_id The interface's ID - * @param[in] force_generation Force generation from a short address if the - * hardware supports it, even if the hardware - * supplies an EUI-64 - * - * @return 1 on success, 0 on failure - */ -int net_if_get_eui64(net_if_eui64_t *eui64, int if_id, int force_generation); - -/** - * @brief Parses a string to an EUI-64. - * @details The parsing will be back to front, every non-hexadecimal character - * and every hexadecimal character beyond the count of 8 will be - * ignored - * - * @param[out] eui64 The generated binary EUI-64. - * @param[in] eui64_str A hexadecimal number in string representation. - */ -void net_if_hex_to_eui64(net_if_eui64_t *eui64, const char *eui64_str); - -/** - * Returns the address of the transceiver associated with the given interface. - * - * @pre Transceivers of this interface has to be initialized and - * transceiver thread has to be started. - * - * @param[in] if_id The interface's ID - * - * @return The transceiver's hardware address on success, 0 on failure - */ -uint16_t net_if_get_hardware_address(int if_id); - -/** - * Returns the EUI-64 of the transeivers attached to this interface. This can - * be get by the actual EUI-64 if the transceiver has one or a generated one - * based of the hardware address - * - * @pre Transceivers of this interface has to be initialized and - * transceiver thread has to be started. - * - * @param[in] if_id The interface's ID - * @param[in] eui64 The new EUI-64 - * - * @return 1 on success, 0 on failure - */ -int net_if_set_eui64(int if_id, net_if_eui64_t *eui64); - -/** - * Sets the address of the transceiver associated with the given interface. - * - * @pre Transceivers of this interface has to be initialized and - * transceiver thread has to be started. - * - * @param[in] if_id The interface's ID - * @param[in] addr The new hardware address - * - * @return the new hardware address on success, 0 on failure. - */ -uint16_t net_if_set_hardware_address(int if_id, uint16_t addr); - -/** - * Returns the channel of the transceiver associated with the given interface. - * - * @pre Transceivers of this interface has to be initialized and - * transceiver thread has to be started. - * - * @param[in] if_id The interface's ID - * - * @return The transceiver's frequency channel on success, -1 on failure. - */ -int32_t net_if_get_channel(int if_id); - -/** - * Sets the channel of the transceiver associated with the given interface. - * - * @pre Transceivers of this interface has to be initialized and - * transceiver thread has to be started. - * - * @param[in] if_id The interface's ID - * @param[in] channel The new frequency channel - * - * @return the new channel on success, -1 on failure. - */ -int32_t net_if_set_channel(int if_id, uint16_t channel); - -/** - * Returns the PAN ID of the transceiver associated with the given interface. - * - * @pre Transceivers of this interface has to be initialized and - * transceiver thread has to be started. - * - * @param[in] if_id The interface's ID - * - * @return The transceiver's PAN ID on success, -1 on failure - */ -int32_t net_if_get_pan_id(int if_id); - -/** - * Sets the PAN ID of the transceiver associated with the given interface. - * - * @pre Transceivers of this interface has to be initialized and - * transceiver thread has to be started. - * - * @param[in] if_id The interface's ID - * @param[in] pan_id The new frequency channel - * - * @return the PAN ID on success, -1 on failure. - */ -int32_t net_if_set_pan_id(int if_id, uint16_t pan_id); - -#ifdef __cplusplus -} -#endif - -/** - * @} - */ -#endif /* _NET_IF_H */ diff --git a/sys/net/include/protocol-multiplex.h b/sys/net/include/protocol-multiplex.h deleted file mode 100644 index c712947085..0000000000 --- a/sys/net/include/protocol-multiplex.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. - * - * 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. - */ - -/** - * @defgroup net_mmstack Protocol multiplex - * @ingroup net - * @brief Protocol handler multiplexing - * @{ - * - * @file - * @brief Protocol handler multiplexing - * - * @author Thomas Hillebrandt - * @author Heiko Will - * @author Michael Baar - */ - -#ifndef PROTOCOLMULTIPLEX_H_ -#define PROTOCOLMULTIPLEX_H_ - - -#include "radio/types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - packet_handler_t handler; - protocol_t protocol; -} handler_entry_t; - -typedef struct { - uint8_t size; - handler_entry_t *handler; -} pm_table_t; - -void pm_init_table(pm_table_t *table, uint8_t size, handler_entry_t *handler); -int pm_find_handler_index(const pm_table_t *table, protocol_t protocol, unsigned int start); -int pm_set_handler(const pm_table_t *table, protocol_t protocol, packet_handler_t handler); -void pm_remove_handler(const pm_table_t *table, protocol_t protocol, packet_handler_t handler); -int pm_invoke(const pm_table_t *table, protocol_t protocol, void *payload, int payload_size, packet_info_t *packet_info); - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif /* PROTOCOLMULTIPLEX_H_ */ diff --git a/sys/net/include/rpl.h b/sys/net/include/rpl.h deleted file mode 100644 index 9715e5aaa3..0000000000 --- a/sys/net/include/rpl.h +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright (C) 2013 - 2014 INRIA. - * Copyright (C) 2015 Cenk GündoÄŸan - * - * 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 rpl - * @{ - * - * @file - * @brief RPL header. Declaration of global variables and functions needed for - * core functionality of RPL. - * - * Header which includes all core RPL-functions. Normally it shouldn't be necessary to - * modify this file. - * - * @author Eric Engel - * @author Fabian Brandt - * @author Cenk GündoÄŸan - */ - -#ifndef __RPL_H -#define __RPL_H - -#include -#include -#include -#include -#include "ipv6.h" -#include "rpl/rpl_dodag.h" -#include "rpl/rpl_of_manager.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#undef CC1100_RADIO_MODE -#define CC1100_RADIO_MODE CC1100_MODE_WOR - -#define RPL_PKT_RECV_BUF_SIZE 16 -#define RPL_PROCESS_STACKSIZE THREAD_STACKSIZE_MAIN - -/* global variables */ -extern kernel_pid_t rpl_process_pid; -extern uint8_t rpl_max_routing_entries; -extern ipv6_addr_t my_address; -extern msg_t rpl_msg_queue[RPL_PKT_RECV_BUF_SIZE]; -extern char rpl_process_buf[RPL_PROCESS_STACKSIZE]; -extern uint8_t rpl_buffer[BUFFER_SIZE - LL_HDR_LEN]; -extern uint8_t rpl_if_id; -extern rpl_dodag_t rpl_dodags[RPL_MAX_DODAGS]; - -/** - * @brief Sends a RPL message to a given destination - * - * This function sends any RPL related messages to a given destination. - * - * @param[in] destination IPv6-address of the destination of the message. - * @param[in] payload Payload of the message. - * @param[in] p_len Length of the message - * @param[in] next_header Index to next header in message. - * - */ -void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_t next_header); - -/** - * @brief Initialization of RPL. - * - * This function initializes all basic RPL resources such as - * corresponding objective functions and sixlowpan (including own address). - * - * @param[in] if_id ID of the interface, which correspond to the network under RPL-control - * @param[in] address Global IPv6 address to use - * - * @return 1 if initialization was successful - * @return 0 if initialization was not successful - * - */ -uint8_t rpl_init(int if_id, ipv6_addr_t *address); - -/** - * @brief Initialization of RPL-root. - * - * This function initializes all RPL resources to act as a root node. - * - * @param[in] rpl_opts RPL root node configurations - * - */ -void rpl_init_root(rpl_options_t *rpl_opts); - -/** - * @brief Sends a DIO-message to a given destination in a given dodag - * - * This function sends a DIO message to a given destination in a given dodag. - * - * @param[in] dodag Dodag of the DIO-message. - * @param[in] destination IPv6-address of the destination of the DIO. Should be a direct neighbor. - * - */ -void rpl_send_DIO(rpl_dodag_t *dodag, ipv6_addr_t *destination); - -/** - * @brief Sends a DAO-message to a given destination - * - * This function sends a DAO message to a given destination in a given dodag. - * - * @param[in] dodag Dodag of the DAO-message. - * @param[in] destination IPv6-address of the destination of the DAO. Should be the preferred parent. - * @param[in] lifetime Lifetime of the node. Reflect the estimated time of presence in the network. - * @param[in] default_lifetime If true, param lifetime is ignored and lifetime is dodag default-lifetime - * @param[in] start_index Describes whether a DAO must be split because of too many routing entries. - * - */ -void rpl_send_DAO(rpl_dodag_t *dodag, ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, uint8_t start_index); - -/** - * @brief Sends a DIS-message to a given destination - * - * This function sends a DIS message to a given destination or multicast-address. - * - * @param[in] destination IPv6-address of the destination of the DIS. Should be a direct neighbor or multicast-address. - * - */ -void rpl_send_DIS(ipv6_addr_t *destination); - -#if RPL_DEFAULT_MOP != RPL_MOP_NON_STORING_MODE -/** - * @brief Sends a DAO acknowledgment-message to a given destination - * - * This function sends a DAO_ACK message to a given destination in a given dodag. - * - * @param[in] dodag Dodag of the DAO_ACK message. - * @param[in] destination IPv6-address of the destination of the DAO_ACK. Should be a direct neighbor. - * - */ -void rpl_send_DAO_ACK(rpl_dodag_t *dodag, ipv6_addr_t *destination); -#endif - -/** - * @brief Receives a DIO message - * - * This function handles receiving a DIO message. - * - */ -void rpl_recv_DIO(void); - -/** - * @brief Receives a DAO message - * - * This function handles receiving a DAO message. - * - */ -void rpl_recv_DAO(void); - -/** - * @brief Receives a DIS message - * - * This function handles receiving a DIS message. - * - */ -void rpl_recv_DIS(void); - -/** - * @brief Receives a DAO acknowledgment message - * - * This function handles receiving a DAO_ACK message. - * - */ -void rpl_recv_DAO_ACK(void); - -/** - * @brief Initialization of RPl-root. - * - * This function initializes all RPL resources especially for root purposes. - * corresponding objective functions and sixlowpan (including own address). - * - * @param arg ignored - * @returns nothing - */ -void *rpl_process(void *arg); - -/** - * @brief Returns next hop from routing table. - * - * @deprecated This function is obsolete and will be removed shortly. This will be replaced with a - * common routing information base. - * - * @param[in] addr Destination address - * - * @return Next hop address - * - * */ -ipv6_addr_t *rpl_get_next_hop(ipv6_addr_t *addr); - -/** - * @brief Adds routing entry to routing table - * - * @deprecated This function is obsolete and will be removed shortly. This will be replaced with a - * common routing information base. - * - * @param[in] addr Destination address - * @param[in] next_hop Next hop address - * @param[in] lifetime Lifetime of the entry - * - * */ -void rpl_add_routing_entry(ipv6_addr_t *addr, ipv6_addr_t *next_hop, uint16_t lifetime); - -/** - * @brief Deletes routing entry to routing table - * - * @deprecated This function is obsolete and will be removed shortly. This will be replaced with a - * common routing information base. - * - * @param[in] addr Destination address - * - * */ -void rpl_del_routing_entry(ipv6_addr_t *addr); - -/** - * @brief Finds routing entry for a given destination. - * - * @deprecated This function is obsolete and will be removed shortly. This will be replaced with a - * common routing information base. - * - * @param[in] addr Destination address - * - * @return Routing entry address - * - * */ -rpl_routing_entry_t *rpl_find_routing_entry(ipv6_addr_t *addr); - -/** - * @brief Returns routing table - * - * @deprecated This function is obsolete and will be removed shortly. This will be replaced with a - * common routing information base. - * - * @return Routing table - * - * */ -rpl_routing_entry_t *rpl_get_routing_table(void); - -/** - * @brief Returns the network status of the actual node - * - * @return 1 if root, 0 otherwise - * - * */ -uint8_t rpl_is_root(void); - -#if RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE - -/** - * @brief Adds one pair of child and its parent to the source routing table - * - * @deprecated This function is obsolete and will be removed shortly. This will be replaced with a - * common routing information base. - * - * @param[in] child Child IPv6-address - * @param[in] parent Parent IPv6-address - * @param[in] lifetime Lifetime of the relation - * - * */ -void rpl_add_srh_entry(ipv6_addr_t *child, ipv6_addr_t *parent, uint16_t lifetime); - -/** - * @brief Constructs a source routing header based on an original IPv6-header - * - * @param[in] act_ipv6_hdr Pointer to original IPv6-packet header - * @return Source routing header or NULL - * - * */ -ipv6_srh_t *rpl_get_srh_header(ipv6_hdr_t *act_ipv6_hdr); - -/** - * @brief Manages sending an SRH-header integrated in an original IPv6-package to the next hop. - * - * @param[in] buf Pointer to original payload - * @param[in] len Length of the original payload - * @param[in] src Original source address - * @param[in] dest Destination address - * @param[in] srh_header Pre-build source routing header - * @param[in] srh_length Length of the pre-built source routing header - * @return Status of sending progress - * */ -int rpl_srh_sendto(const void *buf, uint16_t len, ipv6_addr_t *src, ipv6_addr_t *dest, ipv6_srh_t *srh_header, uint8_t srh_length); - -/** - * @brief Sends IPC-message to the service, which is indicated by the next-header-field in the source routing header - * - * @param[in] ipv6_header Actual IPv6-header - * @return IPv6-address of the next-hop. Is NULL on error occurrence. - * - * */ -void rpl_remove_srh_header(ipv6_hdr_t *ipv6_header, const void *buf, uint8_t nextheader); - -#endif /* RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE */ - -#ifdef __cplusplus -} -#endif -/** @} */ -#endif /* __RPL_H */ diff --git a/sys/net/include/rpl/rpl_config.h b/sys/net/include/rpl/rpl_config.h deleted file mode 100644 index 9215a9f619..0000000000 --- a/sys/net/include/rpl/rpl_config.h +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (C) 2013, 2014 INRIA. - * - * 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 rpl - * @{ - * - * @file - * @brief RPL Config - * - * Configuration file, which defines all environmental variables for RPL. - * - * @author Eric Engel - * @} - */ - -#ifndef RPL_CONFIG_H_INCLUDED -#define RPL_CONFIG_H_INCLUDED - -#ifdef __cplusplus -extern "C" { -#endif - -/* Default values */ -#define RPL_MOP_NO_DOWNWARD_ROUTES 0x00 -#define RPL_MOP_NON_STORING_MODE 0x01 -#define RPL_MOP_STORING_MODE_NO_MC 0x02 -#define RPL_MOP_STORING_MODE_MC 0x03 - -#define RPL_SEQUENCE_WINDOW 16 -/* RPL Message type */ -enum RPL_MSG_CODE { - ICMP_CODE_DIS = 0, - ICMP_CODE_DIO, - ICMP_CODE_DAO, - ICMP_CODE_DAO_ACK, - /* put all ICMP codes before the end marker */ - ICMP_CODE_END, - RPL_MSG_TYPE_DAO_HANDLE, - RPL_MSG_TYPE_ROUTING_ENTRY_UPDATE, - RPL_MSG_TYPE_TRICKLE_INTERVAL, - RPL_MSG_TYPE_TRICKLE_CALLBACK -}; - -/* packet base lengths */ -#define DIO_BASE_LEN 24 -#define DIS_BASE_LEN 2 -#define DAO_BASE_LEN 4 -#define DAO_D_LEN 24 -#define DAO_ACK_LEN 4 -#define DAO_ACK_D_LEN 24 -#define RPL_OPT_LEN 2 -#define RPL_OPT_DODAG_CONF_LEN 14 -#define RPL_OPT_DODAG_CONF_LEN_WITH_OPT_LEN (RPL_OPT_DODAG_CONF_LEN + RPL_OPT_LEN) -#define RPL_OPT_PREFIX_INFO_LEN 30 -#define RPL_OPT_PREFIX_INFO_LEN_WITH_OPT_LEN (RPL_OPT_PREFIX_INFO_LEN + RPL_OPT_LEN) -#define RPL_OPT_SOLICITED_INFO_LEN 21 -#define RPL_OPT_TARGET_LEN 18 -#define RPL_OPT_TARGET_LEN_WITH_OPT_LEN (RPL_OPT_TARGET_LEN + RPL_OPT_LEN) -#define RPL_OPT_TRANSIT_LEN 20 -#define RPL_OPT_TRANSIT_LEN_WITH_OPT_LEN (RPL_OPT_TRANSIT_LEN + RPL_OPT_LEN) - -/* message options */ -#define RPL_OPT_PAD1 0 -#define RPL_OPT_PADN 1 -#define RPL_OPT_DAG_METRIC_CONTAINER 2 -#define RPL_OPT_ROUTE_INFO 3 -#define RPL_OPT_DODAG_CONF 4 -#define RPL_OPT_TARGET 5 -#define RPL_OPT_TRANSIT 6 -#define RPL_OPT_SOLICITED_INFO 7 -#define RPL_OPT_PREFIX_INFO 8 -#define RPL_OPT_TARGET_DESC 9 - -/* Counters */ -#define RPL_COUNTER_MAX 255 -#define RPL_COUNTER_LOWER_REGION 127 -#define RPL_COUNTER_SEQ_WINDOW 16 -#define RPL_COUNTER_INIT (RPL_COUNTER_MAX - RPL_COUNTER_SEQ_WINDOW + 1) - -static inline uint8_t RPL_COUNTER_INCREMENT(uint8_t counter) -{ - return (counter > RPL_COUNTER_LOWER_REGION ? (counter == RPL_COUNTER_MAX ? counter = 0 : ++counter) : (counter == RPL_COUNTER_LOWER_REGION ? counter = 0 : ++counter)); -} - -static inline bool RPL_COUNTER_IS_INIT(uint8_t counter) -{ - return (counter > RPL_COUNTER_LOWER_REGION); -} - -static inline bool RPL_COUNTER_GREATER_THAN_LOCAL(uint8_t A, uint8_t B) -{ - return (((A < B) && (RPL_COUNTER_LOWER_REGION + 1 - B + A < RPL_COUNTER_SEQ_WINDOW)) || ((A > B) && (A - B < RPL_COUNTER_SEQ_WINDOW))); -} - -static inline bool RPL_COUNTER_GREATER_THAN(uint8_t A, uint8_t B) -{ - return ((A > RPL_COUNTER_LOWER_REGION) ? ((B > RPL_COUNTER_LOWER_REGION) ? RPL_COUNTER_GREATER_THAN_LOCAL(A, B) : 0) : ((B > RPL_COUNTER_LOWER_REGION) ? 1 : RPL_COUNTER_GREATER_THAN_LOCAL(A, B))); -} - -/* Node Status */ -#define NORMAL_NODE 0 -#define ROOT_NODE 1 -#define LEAF_NODE 2 - -/* Link Metric Type */ -#define METRIC_ETX 1 - -/* RPL Constants and Variables */ -#ifndef RPL_DEFAULT_MOP -# define RPL_DEFAULT_MOP RPL_MOP_STORING_MODE_NO_MC -#endif -#define BASE_RANK 0 -#define INFINITE_RANK 0xFFFF -#define RPL_DEFAULT_INSTANCE 0 -#define DEFAULT_PATH_CONTROL_SIZE 0 -#define DEFAULT_DIO_INTERVAL_MIN 11 -/* standard value: */ -/* #define DEFAULT_DIO_INTERVAL_MIN 3 */ -#define DEFAULT_DIO_INTERVAL_DOUBLINGS 7 -/* standard value: */ -/* #define DEFAULT_DIO_INTERVAL_DOUBLINGS 20 */ -#define DEFAULT_DIO_REDUNDANCY_CONSTANT 10 -#define DEFAULT_MIN_HOP_RANK_INCREASE 256 -#define ROOT_RANK DEFAULT_MIN_HOP_RANK_INCREASE -/* DAO_DELAY is in seconds */ -#define DEFAULT_DAO_DELAY 3 -#define REGULAR_DAO_INTERVAL 300 -#define DAO_SEND_RETRIES 4 -#define DEFAULT_WAIT_FOR_DAO_ACK 15 -#define RPL_DODAG_ID_LEN 128 - -/* others */ - -#define NUMBER_IMPLEMENTED_OFS 2 -#define RPL_MAX_DODAGS 3 -#define RPL_MAX_INSTANCES 1 -#define RPL_MAX_PARENTS 5 -#ifndef RPL_MAX_ROUTING_ENTRIES - #if (RPL_DEFAULT_MOP == RPL_MOP_NO_DOWNWARD_ROUTES) - # define RPL_MAX_ROUTING_ENTRIES (128) - #elif (RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE) - #ifdef RPL_NODE_IS_ROOT - # define RPL_MAX_ROUTING_ENTRIES (128) - #else - # define RPL_MAX_ROUTING_ENTRIES (0) - #endif - #elif (RPL_DEFAULT_MOP == RPL_MOP_STORING_MODE_NO_MC) - # define RPL_MAX_ROUTING_ENTRIES (128) - #else // RPL_DEFAULT_MOP == RPL_MOP_STORING_MODE_MC - # define RPL_MAX_ROUTING_ENTRIES (128) - #endif -#endif -#define RPL_MAX_SRH_PATH_LENGTH 10; -#define RPL_SRH_ENTRIES 15 -#define RPL_ROOT_RANK 256 -#define RPL_DEFAULT_LIFETIME 0xff -#define RPL_LIFETIME_UNIT 2 -#define RPL_LIFETIME_STEP 2 -#define RPL_GROUNDED 1 -#define RPL_PRF_MASK 0x7 -#define RPL_MOP_SHIFT 3 -#define RPL_SHIFTED_MOP_MASK 0x7 -#define RPL_DIS_V_MASK 0x80 -#define RPL_DIS_I_MASK 0x40 -#define RPL_DIS_D_MASK 0x20 -#define RPL_GROUNDED_SHIFT 7 -#define RPL_DEFAULT_OCP 0 - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/sys/net/include/rpl/rpl_dodag.h b/sys/net/include/rpl/rpl_dodag.h deleted file mode 100644 index af2be0288f..0000000000 --- a/sys/net/include/rpl/rpl_dodag.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2013, 2014 INRIA. - * - * 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 rpl - * @{ - * - * @file - * @brief RPL DODAG header - * - * Header file, which defines all public known DODAG-related functions for RPL. - * - * @author Eric Engel - * @} - */ - -#include -#include "ipv6.h" -#include "rpl_structs.h" -#include "rpl_config.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void rpl_dao_ack_received(rpl_dodag_t *dodag); -void rpl_delay_dao(rpl_dodag_t *dodag); -rpl_instance_t *rpl_new_instance(uint8_t instanceid); -rpl_instance_t *rpl_get_instance(uint8_t instanceid); -rpl_instance_t *rpl_get_my_instance(void); -rpl_dodag_t *rpl_new_dodag(rpl_instance_t *inst, ipv6_addr_t *id); -rpl_dodag_t *rpl_get_joined_dodag(uint8_t instanceid); -rpl_dodag_t *rpl_get_my_dodag(void); -void rpl_join_dodag(rpl_dodag_t *dodag, ipv6_addr_t *parent, uint16_t parent_rank); -void rpl_del_dodag(rpl_dodag_t *dodag); -rpl_parent_t *rpl_new_parent(rpl_dodag_t *dodag, ipv6_addr_t *address, uint16_t rank); -rpl_parent_t *rpl_find_parent(rpl_dodag_t *dodag, ipv6_addr_t *address); -void rpl_leave_dodag(rpl_dodag_t *dodag); -bool rpl_equal_id(ipv6_addr_t *id1, ipv6_addr_t *id2); -ipv6_addr_t *rpl_get_my_preferred_parent(void); -void rpl_delete_parent(rpl_parent_t *parent); -void rpl_delete_worst_parent(void); -void rpl_delete_all_parents(rpl_dodag_t *dodag); -rpl_parent_t *rpl_find_preferred_parent(rpl_dodag_t *dodag); -void rpl_parent_update(rpl_dodag_t *dodag, rpl_parent_t *parent); -void rpl_global_repair(rpl_dodag_t *dodag, ipv6_addr_t *p_addr, uint16_t rank); -void rpl_local_repair(rpl_dodag_t *dodag); -uint16_t rpl_calc_rank(uint16_t abs_rank, uint16_t minhoprankincrease); - -#ifdef __cplusplus -} -#endif diff --git a/sys/net/include/rpl/rpl_of_manager.h b/sys/net/include/rpl/rpl_of_manager.h deleted file mode 100644 index c3ece1c592..0000000000 --- a/sys/net/include/rpl/rpl_of_manager.h +++ /dev/null @@ -1,46 +0,0 @@ -/* -* RPL dodag implementation -* -* Copyright (C) 2014 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 rpl -* @{ -* @file -* @brief RPL Objective functions manager header -* @author Fabian Brandt -* @} -*/ - -#ifndef __RPL_OFM_H -#define __RPL_OFM_H - -#include "rpl_structs.h" -#include "rpl_config.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Initialization of Manager and of-functions. - * @param[in] my_address Own address for initialization of beaconing -*/ -void rpl_of_manager_init(ipv6_addr_t *my_address); - -/** - * @brief Returns objective function with a given cope point - * @param[in] ocp Objective code point of objective function - * @return Pointer of corresponding objective function implementation -*/ -rpl_of_t *rpl_get_of_for_ocp(uint16_t ocp); - -#ifdef __cplusplus -} -#endif - -#endif /* __RPL_OFM_H */ -/** @} */ diff --git a/sys/net/include/rpl/rpl_structs.h b/sys/net/include/rpl/rpl_structs.h deleted file mode 100644 index 8f1b05c138..0000000000 --- a/sys/net/include/rpl/rpl_structs.h +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright (C) 2013 INRIA. - * - * 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 rpl - * @{ - * @file - * @brief RPL data structs - * - * File, which defines all structs used by RPL. - * - * @author Eric Engel - * @} - */ - -#ifndef RPL_STRUCTS_H_INCLUDED -#define RPL_STRUCTS_H_INCLUDED - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include "ipv6.h" -#include "trickle.h" - -/* Modes of Operation */ - -/* DIO Base Object (RFC 6550 Fig. 14) */ -typedef struct __attribute__((packed)) { - uint8_t rpl_instanceid; - uint8_t version_number; - network_uint16_t rank; - uint8_t g_mop_prf; - uint8_t dtsn; - uint8_t flags; - uint8_t reserved; - ipv6_addr_t dodagid; -} rpl_dio_t; - -typedef struct __attribute__((packed)) { - uint8_t flags; - uint8_t reserved; -} rpl_dis_t; - -/* DAO Base Object (RFC 6550 Fig. 16) */ -typedef struct __attribute__((packed)) { - uint8_t rpl_instanceid; - uint8_t k_d_flags; - uint8_t reserved; - uint8_t dao_sequence; -} rpl_dao_t; - -/* DAO ACK Base Object (RFC 6550 Fig. 17.) */ -typedef struct __attribute__((packed)) { - uint8_t rpl_instanceid; - uint8_t d_reserved; - uint8_t dao_sequence; - uint8_t status; -} rpl_dao_ack_t; - -/* DODAG ID Struct */ -/* may be present in dao or dao_ack packets */ -typedef struct __attribute__((packed)) { - ipv6_addr_t dodagid; -} dodag_id_t; - -/* RPL-Option Generic Format (RFC 6550 Fig. 19) */ -typedef struct __attribute__((packed)) { - uint8_t type; - uint8_t length; -} rpl_opt_t; - -/* DODAG Configuration-Option (RFC 6550 Fig. 24) */ -typedef struct __attribute__((packed)) { - uint8_t type; - uint8_t length; - uint8_t flags_a_pcs; - uint8_t DIOIntDoubl; - uint8_t DIOIntMin; - uint8_t DIORedun; - network_uint16_t MaxRankIncrease; - network_uint16_t MinHopRankIncrease; - network_uint16_t ocp; - uint8_t reserved; - uint8_t default_lifetime; - network_uint16_t lifetime_unit; -} rpl_opt_dodag_conf_t; - -/* RPL Solicited Information Option (RFC 6550 Fig. 28) */ -typedef struct __attribute__((packed)) { - uint8_t type; - uint8_t length; - uint8_t rplinstanceid; - uint8_t VID_Flags; - ipv6_addr_t dodagid; - uint8_t version; -} rpl_opt_solicited_t; - -/* RPL Target-Option (RFC 6550 Fig. 25) */ -/* TODO: ipv6_addr_t target may be replaced by a target prefix of variable length */ -typedef struct __attribute__((packed)) { - uint8_t type; - uint8_t length; - uint8_t flags; - uint8_t prefix_length; - ipv6_addr_t target; -} rpl_opt_target_t; - -/* RPL Transit-Option (RFC 6550 Fig. 26) */ -typedef struct __attribute__((packed)) { - uint8_t type; - uint8_t length; - uint8_t e_flags; - uint8_t path_control; - uint8_t path_sequence; - uint8_t path_lifetime; - ipv6_addr_t parent; -} rpl_opt_transit_t; - -/* RPL Prefix Information Option (RFC 6550 Fig. 29) */ -typedef struct __attribute__((packed)) { - uint8_t type; - uint8_t length; - uint8_t prefix_length; -/* RFC 6550 https://tools.ietf.org/html/rfc6550#page-61 */ -#define RPL_PREFIX_INFO_ROUTER_ADDRESS (1 << 5) -#define RPL_PREFIX_INFO_AUTO_ADDR_CONF (1 << 6) -#define RPL_PREFIX_INFO_ON_LINK (1 << 7) - uint8_t flags; - network_uint32_t valid_lifetime; - network_uint32_t preferred_lifetime; - network_uint32_t reserved2; - ipv6_addr_t prefix; -} rpl_opt_prefix_information_t; - -struct rpl_dodag_t; - -typedef struct { - ipv6_addr_t addr; - uint16_t rank; - uint8_t dtsn; - struct rpl_dodag_t *dodag; - uint16_t lifetime; - double link_metric; - uint8_t link_metric_type; - uint8_t used; -} rpl_parent_t; - -struct rpl_of_t; - -typedef struct { - uint8_t id; - uint8_t used; - uint8_t joined; -} rpl_instance_t; - -//Node-internal representation of a DODAG, with nodespecific information -typedef struct rpl_dodag_t { - rpl_instance_t *instance; - ipv6_addr_t dodag_id; - uint8_t used; - uint8_t mop; - uint8_t dtsn; - uint8_t prf; - uint8_t dio_interval_doubling; - uint8_t dio_min; - uint8_t dio_redundancy; - uint16_t maxrankincrease; - uint16_t minhoprankincrease; - uint8_t default_lifetime; - uint16_t lifetime_unit; - uint8_t version; - uint8_t grounded; - uint16_t my_rank; - uint8_t node_status; - uint8_t dao_seq; - uint16_t min_rank; - uint8_t joined; - rpl_parent_t *my_preferred_parent; - struct rpl_of_t *of; - trickle_t trickle; - bool ack_received; - uint8_t dao_counter; - ipv6_addr_t prefix; - uint8_t prefix_length; - uint32_t prefix_valid_lifetime; - uint32_t prefix_preferred_lifetime; - uint8_t prefix_flags; - timex_t dao_time; - vtimer_t dao_timer; -} rpl_dodag_t; - -typedef struct rpl_of_t { - uint16_t ocp; - uint16_t (*calc_rank)(rpl_parent_t *parent, uint16_t base_rank); - rpl_parent_t *(*which_parent)(rpl_parent_t *, rpl_parent_t *); - rpl_dodag_t *(*which_dodag)(rpl_dodag_t *, rpl_dodag_t *); - void (*reset)(rpl_dodag_t *); - void (*parent_state_callback)(rpl_parent_t *, int, int); - void (*init)(void); //OF specific init function - void (*process_dio)(void); //DIO processing callback (acc. to OF0 spec, chpt 5) -} rpl_of_t; - -typedef struct { - ipv6_addr_t address; - ipv6_addr_t next_hop; - uint16_t lifetime; - uint8_t used; -} rpl_routing_entry_t; - -/* Parameters passed to RPL on initialization */ -typedef struct { - uint8_t instance_id; - ipv6_addr_t prefix; - uint8_t prefix_len; - uint8_t prefix_flags; - uint32_t prefix_valid_lifetime; - uint32_t prefix_preferred_lifetime; -} rpl_options_t; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/sys/net/include/sixlowpan.h b/sys/net/include/sixlowpan.h deleted file mode 100644 index af37c3aa49..0000000000 --- a/sys/net/include/sixlowpan.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2013 INRIA. - * - * 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. - */ - -/** - * @defgroup net_sixlowpan 6LoWPAN - * @ingroup net - * @brief 6LoWPAN module implements (parts of) the 6LoWPAN adaption layer - * for IPv6 over Low Power Wireless Personal Area Networks - * (6LoWPANs) - * - * @see - * RFC 4919 - IPv6 over Low-Power Wireless Personal Area - * Networks (6LoWPANs): Overview, Assumptions, Problem - * Statement, and Goals - * - * @see - * RFC 4944 - Transmission of IPv6 Packets over - * IEEE 802.15.4 Networks - * - * @see - * RFC 6282 - Compression Format for IPv6 Datagrams over - * IEEE 802.15.4-Based Networks - * - * @see - * RFC 6775 - Neighbor Discovery Optimization for IPv6 - * over Low-Power Wireless Personal Area Networks - * (6LoWPANs) - * - * - * - * @{ - * @file - * @brief 6lowpan link layer and lowpan functions - * - * @author Martine Lenders - */ -#ifndef SIXLOWPAN_H -#define SIXLOWPAN_H - -#include "sixlowpan/error.h" -#include "sixlowpan/types.h" -#include "sixlowpan/lowpan.h" -#include "sixlowpan/mac.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* SIXLOWPAN_H */ -/** @} */ diff --git a/sys/net/include/sixlowpan/error.h b/sys/net/include/sixlowpan/error.h deleted file mode 100644 index d0f434c373..0000000000 --- a/sys/net/include/sixlowpan/error.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) 2013 INRIA. - * - * 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 net_sixlowpan_lowpan - * @{ - * - * @file - * @brief 6LoWPAN error codes - * - * @author Martine Lenders - */ - -#ifndef SIXLOWPAN_ERROR_H -#define SIXLOWPAN_ERROR_H - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Functions return this if call was success. Only defined if not - * already defined by other header. - */ -#define SIXLOWERROR_SUCCESS (0) - -/** - * Error code that signals that array is full. - */ -#define SIXLOWERROR_ARRAYFULL (132) - -/** - * Error code that signals a NULL pointer error. - */ -#define SIXLOWERROR_NULLPTR (133) - -/** - * Error code that signals an illegal value. - */ -#define SIXLOWERROR_VALUE (134) - -/** - * Error code that signals an illegal address. - */ -#define SIXLOWERROR_ADDRESS (135) - -/** - * Error code that signals an unknown 6LoWPAN dispatch - * @see - * RFC 4944, Section 5: LoWPAN Adaptation Layer and Frame Format - * - */ -#define SIXLOWERROR_DISPATCH (136) - -/** - * Error code that signals that the first 6LoWPAN fragment was - * not received - * @see - * RFC 4944, Section 5.3: Fragmentation Type and Header - * - */ -#define SIXLOWERROR_FSTFRAG (137) - -/** - * Error code that signals that an invalid 6LoWPAN fragment was - * received. - * @see - * RFC 4944, Section 5.3: Fragmentation Type and Header - * - */ -#define SIXLOWERROR_INVFRAG (138) - -/** - * Error code that signals that the source context identifier was not - * found. - * @see - * RFC 6282, Section 3.1: LOWPAN_IPHC Encoding format - * - */ -#define SIXLOWERROR_SCI (139) - -/** - * Error code that signals that the destination context identifier was - * not found. - * @see - * RFC 6282, Section 3.1: LOWPAN_IPHC Encoding format - * - */ -#define SIXLOWERROR_DCI (140) - -/** - * Error code that signals that the destination context identifier was - * not found. - */ -#define SIXLOWERROR_CSUM (141) - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif /* SIXLOWPAN_ERROR_H */ diff --git a/sys/net/include/sixlowpan/icmp.h b/sys/net/include/sixlowpan/icmp.h deleted file mode 100644 index 44ac09e3b3..0000000000 --- a/sys/net/include/sixlowpan/icmp.h +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Copyright (C) 2013 INRIA. - * - * 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. - */ - -/** - * @addtogroup net_sixlowpan_ndp Neighbor discovery - * @ingroup net_sixlowpan - * @brief Internet Control Message Protocol version 6 - * - * @{ - * - * @file - * @brief 6LoWPAN ICMP related header - * - * @author Stephan Zeisberg - * @author Martine Lenders - * @author Eric Engel - * @author Oliver Gesch - */ - -#ifndef SIXLOWPAN_ICMP_H -#define SIXLOWPAN_ICMP_H - -#include -#include - -#include "sixlowpan/types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief ICMPv6 packet type for parameter problem message. - * @see - * RFC 4443, section 3.4 - * - */ -#define ICMPV6_TYPE_PARAMETER_PROB (4) - -/** - * @brief ICMPv6 packet type for an echo request. - * @see - * RFC 4443, section 4.1 - * - */ -#define ICMPV6_TYPE_ECHO_REQUEST (128) - -/** - * @brief ICMPv6 packet type for an echo reply. - * @see - * RFC 4443, section 4.2 - * - */ -#define ICMPV6_TYPE_ECHO_REPLY (129) - -/** - * @brief ICMPv6 packet type for a router solicitation. - * @see - * RFC 4861, section 4.1 - * - */ -#define ICMPV6_TYPE_ROUTER_SOL (133) - -/** - * @brief ICMPv6 packet type for a router advertisement. - * @see - * RFC 4861, section 4.2 - * - */ -#define ICMPV6_TYPE_ROUTER_ADV (134) - -/** - * @brief ICMPv6 packet type for a neighbor solicitation. - * @see - * RFC 4861, section 4.3 - * - */ -#define ICMPV6_TYPE_NEIGHBOR_SOL (135) - -/** - * @brief ICMPv6 packet type for a neighbor advertisement. - * @see - * RFC 4861, section 4.4 - * - */ -#define ICMPV6_TYPE_NEIGHBOR_ADV (136) - -/** - * @brief ICMPv6 packet type for a redirect message. - * @see - * RFC 4861, section 4.5 - * - */ -#define ICMPV6_TYPE_REDIRECT (137) - -/** - * @brief ICMPv6 packet type for a rpl control message. - * @note TODO: not RFC conform. - */ -#define ICMPV6_TYPE_RPL_CONTROL (155) - -/** - * @brief ICMPv6 parameter problem message code for - * "Erroneous header field encountered". - * @see - * RFC 4443, section 3.4 - * - */ -#define ICMPV6_PARAMETER_PROB_CODE_ERR (0) - -/** - * @brief ICMPv6 parameter problem message code for - * "Unrecognized Next Header type encountered". - * @see - * RFC 4443, section 3.4 - * - */ -#define ICMPV6_PARAMETER_PROB_CODE_NXT_HDR_UNREC (1) - -/** - * @brief ICMPv6 parameter problem message code for - * "Unrecognized IPv6 option encountered". - * @see - * RFC 4443, section 3.4 - * - */ -#define ICMPV6_PARAMETER_PROB_CODE_IPV6_OPT_UNREC (2) - -/** - * @brief Send ICMPv6 parameter problem message. - * - * @param[in] src Source address for IPv6 header. - * @param[in] dest Destination address for IPv6 header. - * @param[in] code Value for code field of parameter problem - * message. - * @param[in] pointer Value for pointer field of parameter problem - * message. - * @param[in] packet Data payload for echo request. - * @param[in] packet_len Length of data payload. - */ -void icmpv6_send_parameter_prob(ipv6_addr_t *src, ipv6_addr_t *dest, - uint8_t code, uint32_t pointer, - uint8_t *packet, uint8_t packet_len); - -/** - * @brief Send ICMPv6 echo request. - * - * @param[in] destaddr Destination address for IPv6 header. - * @param[in] id Value for identifier field of echo request. - * @param[in] seq Value for sequence number field of echo request. - * @param[in] data Data payload for echo request. - * @param[in] data_len Length of data payload. - */ -void icmpv6_send_echo_request(ipv6_addr_t *destaddr, uint16_t id, - uint16_t seq, uint8_t *data, - size_t data_len); - -/** - * @brief Send ICMPv6 echo reply. - * - * @param[in] destaddr Destination address for IPv6 header. - * @param[in] id Value for identifier field of echo reply. - * @param[in] seq Value for sequence number field of echo reply. - * @param[in] data Data payload for echo reply. - * @param[in] data_len Length of data payload. - */ -void icmpv6_send_echo_reply(ipv6_addr_t *destaddr, uint16_t id, - uint16_t seq, uint8_t *data, size_t data_len); - -/** - * @brief Send ICMPv6 router solicitation. - * - * @param[in] sllao Flag to include source link-layer address - * option. If *sllao* == OPT_SLLAO add it, else - * not. - */ -void icmpv6_send_router_sol(uint8_t sllao); - -/** - * @brief Send ICMPv6 router advertisement. - * - * @param[in] addr Address of node to advertise router to. If - * NULL *addr* is set to the all nodes multicast - * address. - * @param[in] sllao Flag to include source link-layer address - * option. If *sllao* == OPT_SLLAO add it, else - * not. - * @param[in] mtu Flag to include MTU option. If *mtu* == OPT_MTU - * add it, else not. - * @param[in] pi Flag to include prefix information option. If - * *pi* == OPT_PI add it, else not. - * @param[in] sixco Flag to include 6LoWPAN context option. If - * *sixco* == OPT_6CO add it, else not. - * @param[in] abro Flag to include 6LoWPAN authoritive border - * router option. If *abro* == OPT_ABRO add it, - * else not. - */ -void icmpv6_send_router_adv(ipv6_addr_t *addr, uint8_t sllao, - uint8_t mtu, uint8_t pi, uint8_t sixco, - uint8_t abro); - -/** - * @brief Send ICMPv6 neighbor solicitation. - * - * @param[in] src Source address for IPv6 header. - * @param[in] dest Destination address for IPv6 header. - * @param[in] targ Value for target address field of neighbor - * solicitation. - * @param[in] sllao Flag to include source link-layer address - * option. If *sllao* == OPT_SLLAO add it, else - * not. - * @param[in] aro Flag to include address registration option. If - * *aro* == OPT_ARO add it, else not. - */ -void icmpv6_send_neighbor_sol(ipv6_addr_t *src, ipv6_addr_t *dest, - ipv6_addr_t *targ, uint8_t sllao, - uint8_t aro); - -/** - * @brief Send ICMPv6 neighbor advertisement. - * - * @param[in] src Source address for IPv6 header. - * @param[in] dst Destination address for IPv6 header. - * @param[in] tgt Value for target address field of neighbor - * advertisement. - * @param[in] rso Value for flags field of neighbor advertisement. - * @param[in] sllao Flag to include source link-layer address - * option. If *sllao* == OPT_SLLAO add it, else - * not. - * @param[in] aro Flag to include address registration option. If - * *aro* == OPT_ARO add it, else not. - */ -void icmpv6_send_neighbor_adv(ipv6_addr_t *src, ipv6_addr_t *dst, - ipv6_addr_t *tgt, uint8_t rso, - uint8_t sllao, uint8_t aro); - -/** - * @brief Calculates the checksum for ICMPv6 packets. - * - * @param[in] ipv6_buf The initialized IPv6 header of the packet. - * @param[in] icmpv6_buf The initialized ICMPv6_header of the packet - * (except checksum, payload is expected directly - * after the packet header in memory). - * - * @return The internet checksum of the given ICMPv6 packet. - */ -uint16_t icmpv6_csum(ipv6_hdr_t *ipv6_buf, icmpv6_hdr_t *icmpv6_buf); - -#ifdef __cplusplus -} -#endif - -#endif /* SIXLOWPAN_ICMP_H */ -/** @} */ diff --git a/sys/net/include/sixlowpan/ip.h b/sys/net/include/sixlowpan/ip.h deleted file mode 100644 index 1c6eee7ef7..0000000000 --- a/sys/net/include/sixlowpan/ip.h +++ /dev/null @@ -1,590 +0,0 @@ -/* - * Copyright (C) 2013 INRIA. - * - * 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. - */ - -/** - * @defgroup net_sixlowpan_ip IPv6 - * @ingroup net_sixlowpan - * @brief Internet Protocol version 6 - * @{ - * - * @file - * @brief 6LoWPAN constants, data structs, and prototypes for network layer - * - * @author Stephan Zeisberg - * @author Martine Lenders - * @author Eric Engel - * @author Oliver Gesch - */ - -#ifndef SIXLOWPAN_IP_H -#define SIXLOWPAN_IP_H - -#include - -#include "inet_ntop.h" -#include "net_if.h" -#include "net_help.h" -#include "sixlowpan/types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief IPv6 maximum transmission unit. - */ -#define IPV6_MTU (256) - -/** - * @brief Length of an IPv6 address in byte. - */ -#define IPV6_ADDR_LEN (16) - -/** - * @brief Length of an IPv6 address in bit. - */ -#define IPV6_ADDR_BIT_LEN (128) - -/** - * @brief Maximum length of an IPv6 address represented as string. - */ -#define IPV6_MAX_ADDR_STR_LEN (40) - -/** - * @brief L4 protocol number for TCP. - */ -#define IPV6_PROTO_NUM_TCP (6) - -/** - * @brief L4 protocol number for UDP. - */ -#define IPV6_PROTO_NUM_UDP (17) - -/** -* @brief Next header value for source routing -* @see -* RFC 5095, section 1 -* -*/ -#define IPV6_PROTO_NUM_SRH (43) - -/** - * @brief L4 protocol number for ICMPv6. - */ -#define IPV6_PROTO_NUM_ICMPV6 (58) - -/** - * @brief L4 protocol number for no L4 protocol in IPv6. - */ -#define IPV6_PROTO_NUM_NONE (59) - -/** - * @brief L4 protocol number for IPv6 destination options. - */ -#define IPV6_PROTO_NUM_IPV6_OPTS (60) - -/** - * @brief message type for notification - * - * @see ipv6_register_packet_handler() - */ -#define IPV6_PACKET_RECEIVED (UPPER_LAYER_2) - -/** - * @brief Get IPv6 send/receive buffer. - * - * @return Pointer to IPv6 header in send/receive bouffer. - * @note To be deleted in later releases. Here only because it is - * used by the rpl module. - */ -ipv6_hdr_t *ipv6_get_buf(void); - -/** - * @brief Send IPv6 packet to dest. - * - * @param[in] dest Destination of this packet. - * @param[in] next_header Next header ID of payload. - * @param[in] payload Payload of the packet. - * @param[in] payload_length Length of payload. - * @param[in] next_hop Optional next_hop. May be NULL if not provided at call. - * - * @return payload_length : on success - * -1 : if no route to the given dest could be obtained - * Packet is dropped - * In case of reactive routing: routing - * is going to try to find a route - */ -int ipv6_sendto(const ipv6_addr_t *dest, uint8_t next_header, - const uint8_t *payload, uint16_t payload_length, ipv6_addr_t *next_hop); - -/** - * @brief Send an IPv6 packet defined by its header. - * - * @param[in] packet Pointer to an prepared IPv6 packet header. - * The payload is expected directly after the - * packet. - * @param[in] next_hop Optional next-hop address. If NULL, than the function tries - * to find it by methods of the active routing protocol. - * - * @return length of payload : on success - * -1 : if no route to the given dest could be obtained - * Packet is dropped - * In case of reactive routing: routing is going - * to try to find a route - */ -int ipv6_send_packet(ipv6_hdr_t *packet, ipv6_addr_t *next_hop); - -/** - * @brief Determines if node is a router. - * - * @return 1 if node is router, 0 otherwise. - */ -uint8_t ipv6_is_router(void); - -/** - * @brief Sets the default hop limit to use with IPv6 packets. - * - * @param[in] hop_limit The hop limit to set the default hop limit to. - */ -void ipv6_set_default_hop_limit(uint8_t hop_limit); - -/** - * @brief Gets the default hop limit that is used for IPv6 packets. - * - * @return The current default hop limit for IPv6 packets. - */ -uint8_t ipv6_get_default_hop_limit(void); - -/** - * @brief Registers a handler thread for incoming IP packets. - * - * @param[in] pid PID of handler thread. - * - * @return 0 on success, ENOMEN if maximum number of registrable - * threads is exceeded. - */ -uint8_t ipv6_register_packet_handler(kernel_pid_t pid); - -/** - * @brief Registers a handler thread for L4 protocol. - * - * @param[in] next_header Next header ID of the L4 protocol. - * @param[in] pid PID of the handler thread - */ -void ipv6_register_next_header_handler(uint8_t next_header, kernel_pid_t pid); - -/** - * @brief Registers a handler thread for RPL options - * - * @param[in] pid PID of the handler thread. - */ -void ipv6_register_rpl_handler(kernel_pid_t pid); - -/** - * @brief Sets the first 64 bit of *ipv6_addr* to link local prefix. - * - * @param[in,out] ipv6_addr The address to set. - */ -static inline void ipv6_addr_set_link_local_prefix(ipv6_addr_t *ipv6_addr) -{ - ipv6_addr->uint32[0] = HTONL(0xfe800000); - ipv6_addr->uint32[1] = 0; -} - -/** - * @brief Sets IPv6 address *out* according to the remaining - * parameters. - * - * @param[out] out The resulting address. - * @param[in] addr0 The first 16 bit of the new address. - * @param[in] addr1 The second 16 bit of the new address. - * @param[in] addr2 The third 16 bit of the new address. - * @param[in] addr3 The fourth 16 bit of the new address. - * @param[in] addr4 The fifth 16 bit of the new address. - * @param[in] addr5 The sixth 16 bit of the new address. - * @param[in] addr6 The seventh 16 bit of the new address. - * @param[in] addr7 The eighth 16 bit of the new address. - */ -void ipv6_addr_init(ipv6_addr_t *out, uint16_t addr0, uint16_t addr1, - uint16_t addr2, uint16_t addr3, uint16_t addr4, - uint16_t addr5, uint16_t addr6, uint16_t addr7); - -/** - * @brief Sets IPv6 address *out* using the given *prefix* and an interface's - * EUI-64. - * - * - * @param[out] out Address to be set. - * @param[in] if_id The interface to take the EUI-64 from. - * @param[in] prefix 64-bit network prefix to be used for *out* - * (only the first 64 bit of the ipv6_addr_t type - * are copied to *out*) - * - * @return The Address to be set on success, NULL on error. - */ -ipv6_addr_t *ipv6_addr_set_by_eui64(ipv6_addr_t *out, int if_id, - const ipv6_addr_t *prefix); - -/** - * @brief Sets IPv6 address *out* with the first *bits* bit taken - * from *prefix* and the remaining bits to 0. - * - * @param[out] out Prefix to be set. - * @param[in] prefix Address to take prefix from. - * @param[in] bits Bits to be copied from *prefix* to *out* - * (set to 128 when greater than 128). - */ -void ipv6_addr_init_prefix(ipv6_addr_t *out, const ipv6_addr_t *prefix, - uint8_t bits); - -/** - * @brief Set *ipv6_addr* to the loopback address. - * - * @see - * RFC 4291 - * - * - * @param[out] ipv6_addr Is set to the loopback address. - */ -static inline void ipv6_addr_set_loopback_addr(ipv6_addr_t *ipv6_addr) -{ - ipv6_addr->uint32[0] = 0; - ipv6_addr->uint32[1] = 0; - ipv6_addr->uint32[2] = 0; - ipv6_addr->uint32[3] = HTONL(1); -} - -/** - * @brief Set *ipv6_addr* to a link-local all routers multicast - * address (ff02::/16 prefix). - * - * @see - * RFC 4291 - * - * - * @param[out] ipv6_addr Is set to a link-local all routers multicast - * address. - */ -static inline void ipv6_addr_set_all_routers_addr(ipv6_addr_t *ipv6_addr) -{ - ipv6_addr->uint32[0] = HTONL(0xff020000); - ipv6_addr->uint32[1] = 0; - ipv6_addr->uint32[2] = 0; - ipv6_addr->uint32[3] = HTONL(2); -} - -/** - * @brief Set *ipv6_addr* to a link-local all nodes multicast address - * (ff02::/16 prefix). - * - * @see - * RFC 4291 - * - * - * @param[out] ipv6_addr Is set to a link-local all nodes multicast - * address. - */ -static inline void ipv6_addr_set_all_nodes_addr(ipv6_addr_t *ipv6_addr) -{ - ipv6_addr->uint32[0] = HTONL(0xff020000); - ipv6_addr->uint32[1] = 0; - ipv6_addr->uint32[2] = 0; - ipv6_addr->uint32[3] = HTONL(1); -} - -/** - * @brief Set *ipv6_addr* to the all-RPL-nodes multicast address - * (ff02::1a). - * - * @see - * RFC 6550 - * - * - * @param[out] ipv6_addr Is set to the all-RPL-nodes multicast - * address. - */ -static inline void ipv6_addr_set_all_rpl_nodes_addr(ipv6_addr_t *ipv6_addr) -{ - ipv6_addr->uint32[0] = HTONL(0xff020000); - ipv6_addr->uint32[1] = 0; - ipv6_addr->uint32[2] = 0; - ipv6_addr->uint32[3] = HTONL(0x1a); -} - -/** - * @brief Set *ipv6_addr_out* to the solicited-node multicast address - * computed from *ipv6_addr_in*. - * - * @see - * RFC 4291 - * - * - * @param[out] ipv6_addr_out Is set to solicited-node address of - * this node. - * @param[in] ipv6_addr_in The IPv6 address the solicited-node - * address. - */ -static inline void ipv6_addr_set_solicited_node_addr(ipv6_addr_t *ipv6_addr_out, - const ipv6_addr_t *ipv6_addr_in) -{ - /* copy only the last 24-bit of the ip-address that is being resolved */ - ipv6_addr_out->uint32[0] = HTONL(0xff020000); - ipv6_addr_out->uint32[1] = 0; - ipv6_addr_out->uint32[2] = HTONL(1); - ipv6_addr_out->uint8[12] = 0xff; - ipv6_addr_out->uint8[13] = ipv6_addr_in->uint8[13]; - ipv6_addr_out->uint16[7] = ipv6_addr_in->uint16[7]; -} - -/** - * @brief Converts IPv6 address into string. - * - * @param[out] addr_str The IPv6 address as string. Must allocate - * at least IPV6_MAX_ADDR_STR_LEN byte (40 - * byte). - * @param[in] str_len The maximum length available to *addr_str*. - * @param[in] ipv6_addr IPv6 address to be converted. - * - * @return Pointer to addr_str. - */ -static inline const char *ipv6_addr_to_str(char *addr_str, uint8_t str_len, - const ipv6_addr_t *ipv6_addr) -{ - return inet_ntop(AF_INET6, ipv6_addr, addr_str, (size_t)str_len); -} - -/** - * @brief Checks if two IPv6 addresses are equal. - * - * @param[in] a An IPv6 address. - * @param[in] b Another IPv6 address. - * - * @return 1 if *a* and *b* are equal, 0 otherwise. - */ -static inline int ipv6_addr_is_equal(const ipv6_addr_t *a, const ipv6_addr_t *b) -{ - return (a->uint32[0] == b->uint32[0]) && - (a->uint32[1] == b->uint32[1]) && - (a->uint32[2] == b->uint32[2]) && - (a->uint32[3] == b->uint32[3]); -} - -/** - * @brief Checks if *ipv6_addr* is unspecified (all zero). - * - * @see - * RFC 4291 - * - * - * @param[in] ipv6_addr An IPv6 address. - * - * @return 1 if *ipv6_addr* is unspecified address, 0 otherwise. - */ -static inline int ipv6_addr_is_unspecified(const ipv6_addr_t *ipv6_addr) -{ - return (ipv6_addr->uint32[0] == 0) && - (ipv6_addr->uint32[1] == 0) && - (ipv6_addr->uint32[2] == 0) && - (ipv6_addr->uint32[3] == 0); -} - -/** - * @brief Check if *ipv6_addr* is a multicast address. - * - * @see - * RFC 4291 - * - * - * @param[in] ipv6_addr An IPv6 address. - * - * @return 1 if *ipv6_addr* is multicast address, 0 otherwise. - */ -static inline int ipv6_addr_is_multicast(const ipv6_addr_t *ipv6_addr) -{ - return (ipv6_addr->uint8[0] == 0xff); -} - -/** - * @brief Checks if *ipv6_addr* is a loopback address. - * - * @see - * RFC 4291 - * - * - * @param[in] ipv6_addr An IPv6 address. - * - * @return 1 if *ipv6_addr* is loopback address, 0 otherwise. - */ -static inline int ipv6_addr_is_loopback(const ipv6_addr_t *ipv6_addr) -{ - return ipv6_addr->uint32[0] == 0 && - ipv6_addr->uint32[1] == 0 && - ipv6_addr->uint32[2] == 0 && - NTOHL(ipv6_addr->uint32[3]) == 1; -} - -/** - * @brief Check if *ipv6_addr* is a link-local address. - * - * @see - * RFC 4291 - * - * - * @param[in] ipv6_addr An IPv6 address. - * - * @return 1 if *ipv6_addr* is link-local address, 0 otherwise. - */ -static inline int ipv6_addr_is_link_local(const ipv6_addr_t *ipv6_addr) -{ - return ((ipv6_addr->uint32[0] == HTONL(0xfe800000)) && - (ipv6_addr->uint32[1] == 0)) || - (ipv6_addr_is_multicast(ipv6_addr) && - (ipv6_addr->uint8[1] & 0x0f) == 2); -} - -/** - * @brief Check if *ipv6_addr* is unique local unicast address. - * - * @see - * RFC 4193 - * - * - * @param[in] ipv6_addr An IPv6 address. - * - * @return 1 if *ipv6_addr* is unique local unicast address, - * 0 otherwise. - */ -static inline int ipv6_addr_is_unique_local_unicast(const ipv6_addr_t *ipv6_addr) -{ - return ((ipv6_addr->uint8[0] == 0xfc) || (ipv6_addr->uint8[0] == 0xfd)); -} - -/** - * @brief Check if *ipv6_addr* is solicited-node multicast address. - * - * @see - * RFC 4291 - * - * - * @param[in] ipv6_addr An IPv6 address. - * - * @return 1 if *ipv6_addr* is solicited-node multicast address, - * 0 otherwise. - */ -static inline int ipv6_addr_is_solicited_node(const ipv6_addr_t *ipv6_addr) -{ - return (ipv6_addr->uint32[0] == HTONL(0xff020000)) && - (ipv6_addr->uint32[1] == 0) && - (ipv6_addr->uint32[2] == HTONL(1)) && - (ipv6_addr->uint8[12] == 0xff); -} - -/** - * @brief Get pointer to potential EUI-64 bit of the IPv6 address. - * - * @param[in] ipv6_addr An IPv6 address of this node. - * @param[in] prefix_len Length of the prefix. Only multiples of 8 are - * possible. - * - * @return The IID (as EUI-64) of this node. - */ -static inline net_if_eui64_t *ipv6_addr_get_iid(const ipv6_addr_t *ipv6_addr, - uint8_t prefix_len) -{ - return ((net_if_eui64_t *) &ipv6_addr->uint8[prefix_len / 8]); -} - -/* - * TODO to wrap sixlowpan initialisations - * int ipv6_iface_init(transceiver_type_t trans, ..); - */ - -/** - * @brief Add an IPv6 address to one of this nodes interfaces. - * - * @see - * RFC 4862 - * - * - * @param[in] if_id The interface's ID. - * @param[in] addr Address to be added to the interface. - * @param[in] state Initial state of the address. - * @param[in] val_ltime Valid lifetime of this address in seconds. Set 0 - * for unspecified. - * @param[in] pref_ltime Preferred lifetime of this address in - * seconds. Set 0 for unspecified. - * @param[in] is_anycast Determines if an address is anycast. Anycast - * addresses are syntactically undistinguishable - * from unicast addresses and can only be identified - * with this flag. If *addr* is no unicast address - * and *is_anycast* is set, this function will fail. - * - * @return 1 on success, 0 on failure. - */ -int ipv6_net_if_add_addr(int if_id, const ipv6_addr_t *addr, - ndp_addr_state_t state, uint32_t val_ltime, - uint32_t pref_ltime, uint8_t is_anycast); - -/** - * @brief Tries to determine best suitable source address attached to - * an interface of this node based on the given destination - * address. The use-case for this function is to find a - * suitable address for the source address field of an IPv6 - * address upon sending. *src* may be empty (all zero) if there - * is no suitable address attached to the interface. - * - * @param[out] src The best source address for this node (may be - * all zero if there is none). - * @param[in] dest The destination address for a packet we search - * the source address for. - */ -void ipv6_net_if_get_best_src_addr(ipv6_addr_t *src, const ipv6_addr_t *dest); - -/** - * @brief Registers a function that decides how to route incoming - * IP packets with a destination that is not this interface. - * The default behavior is to try forwarding such packets to - * the neighborhood. - * Register a function to change the default behavior. - * Such function shall return the next hop to reach the destination - * of the IP packet, or NULL if no such next hop is known. - * In this case, the packet will be discarded. - * - * @param next_hop function that returns the next hop to reach dest - */ -void ipv6_iface_set_routing_provider(ipv6_addr_t *(*next_hop)(ipv6_addr_t *dest)); - -/** - * @brief Registers a function that decides if a node in a RPL-network is actually the - * root and therefore a source routing header should be integrated. - * Only used in RPL non-storing mode by now. - * - */ -void ipv6_iface_set_srh_indicator(uint8_t (*srh_indi)(void)); - -/** - * @brief Calculates the IPv6 upper-layer checksum. - * - * @see - * RFC 2460, section 8.1 - * - * @param[in] ipv6_header Pointer to the IPv6 header of the packet. - * @param[in] buf Pointer to the upper-layer payload of the IP datagram. - * @param[in] len The length of the upper-layer header and data. - * @param[in] proto Upper-layer protocol number according to RFC1700. - * - * @return The IPv6 upper-layer checksum. - */ -uint16_t ipv6_csum(ipv6_hdr_t *ipv6_header, uint8_t *buf, uint16_t len, uint8_t proto); - -#ifdef __cplusplus -} -#endif - -#endif /* SIXLOWPAN_IP_H */ -/** @} */ diff --git a/sys/net/include/sixlowpan/lowpan.h b/sys/net/include/sixlowpan/lowpan.h deleted file mode 100644 index 25f9285762..0000000000 --- a/sys/net/include/sixlowpan/lowpan.h +++ /dev/null @@ -1,315 +0,0 @@ -/* - * Copyright (C) 2013 INRIA. - * - * 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. - */ - -/** - * @defgroup net_sixlowpan_lowpan 6LoWPAN adaptation layer - * @ingroup net_sixlowpan - * @brief IPv6 over LoW Power wireless Area Networks - * @{ - * - * @file - * @brief 6LoWPAN LoWPAN layer header - * - * @author Stephan Zeisberg - * @author Martine Lenders - * @author Eric Engel - * @author Oliver Gesch - */ - -#ifndef SIXLOWPAN_LOWPAN_H -#define SIXLOWPAN_LOWPAN_H - -#include - -#include "transceiver.h" -#include "net_help.h" -#include "net_if.h" -#include "sixlowpan/types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief 6LoWPAN dispatch value for uncompressed IPv6 packets. - * @see - * RFC 4944, section 5.1 - * - */ -#define SIXLOWPAN_IPV6_DISPATCH (0x41) - -/** - * @brief 6LoWPAN dispatch value for IPv6 header compression (part of - * first byte of LOWPAN_IPHC). - * @see - * RFC 4944, section 3.1.1 - * - */ -#define SIXLOWPAN_IPHC1_DISPATCH (0x60) - -/** - * @brief Flag for Flow Label elision (part of first byte of - * LOWPAN_IPHC). - * @see - * RFC 6282, section 3.1.1 - * - */ -#define SIXLOWPAN_IPHC1_FL_C (0x10) - -/** - * @brief Flag for Traffic Class elision (part of first byte of - * LOWPAN_IPHC). - * @see - * RFC 6282, section 3.1.1 - * - */ -#define SIXLOWPAN_IPHC1_TC_C (0x08) - -/** - * @brief Flag for Next Header Compression (part of first byte of - * LOWPAN_IPHC). - * @see - * RFC 6282, section 3.1.1 - * - */ -#define SIXLOWPAN_IPHC1_NH (0x04) -#define SIXLOWPAN_NHC_UDP_MASK (0xF8) -#define SIXLOWPAN_NHC_UDP_ID (0xF0) - -/** - * @brief Flag for Context Identifier Extention (part of second byte - * of LOWPAN_IPHC). - * @see - * RFC 6282, section 3.1.1 - * - */ -#define SIXLOWPAN_IPHC2_CID (0x80) - -/** - * @brief Flag for Source Address Compression (part of second byte - * of LOWPAN_IPHC). - * @see - * RFC 6282, section 3.1.1 - * - */ -#define SIXLOWPAN_IPHC2_SAC (0x40) - -/** - * @brief Bits for Source Address Mode (part of second byte of - * LOWPAN_IPHC). - * @see - * RFC 6282, section 3.1.1 - * - */ -#define SIXLOWPAN_IPHC2_SAM (0x30) - -/** - * @brief Flag for Destination Address Compression (part of second - * byte of LOWPAN_IPHC). - * @see - * RFC 6282, section 3.1.1 - * - */ -#define SIXLOWPAN_IPHC2_DAC (0x04) - -/** - * @brief Bits for Destination Address Mode (part of second byte of - * LOWPAN_IPHC). - * @see - * RFC 6282, section 3.1.1 - * - */ -#define SIXLOWPAN_IPHC2_DAM (0x03) - -/** - * @brief Flag for Multicast Compression (part of second byte of - * LOWPAN_IPHC). - * @see - * RFC 6282, section 3.1.1 - * - */ -#define SIXLOWPAN_IPHC2_M (0x08) - - -/** - * 6LoWPAN dispatch value for fragmentation header (first fragment) - * @see - * RFC 4944, section 5.1 - * - */ -#define SIXLOWPAN_FRAG1_DISPATCH (0xc0) - -/** - * 6LoWPAN dispatch value for fragmentation header (subsequent fragment) - * @see - * RFC 4944, section 5.1 - * - */ -#define SIXLOWPAN_FRAGN_DISPATCH (0xe0) - - -/** - * 6LoWPAN fragmentation header length (first fragment) - */ -#define SIXLOWPAN_FRAG1_HDR_LEN (4) - -/** - * 6LoWPAN fragmentation header length (subsequent fragment) - */ -#define SIXLOWPAN_FRAGN_HDR_LEN (5) - -/** - * @brief message type for notification - * - * @see sixlowpan_lowpan_register() - */ -#define LOWPAN_FRAME_RECEIVED (UPPER_LAYER_1) - -/** - * @brief Data type to configure 6LoWPAN IPv6 header compression. - */ -typedef enum __attribute__((packed)) { - LOWPAN_IPHC_DISABLE = 0, ///< header compression disabled - LOWPAN_IPHC_ENABLE = 1 ///< header compression enabled -} sixlowpan_lowpan_iphc_status_t; - -/** - * @brief Data type to represent an 6LoWPAN frame as byte stream. - */ -typedef struct __attribute__((packed)) { - uint8_t length; ///< length of the byte stream. - uint8_t *data; ///< the byte stream representing the 6LoWPAN frame. -} sixlowpan_lowpan_frame_t; - - -/** - * @brief Initializes all addresses on an interface needed for 6LoWPAN. - * - * @param[in] if_id The interface to use with 6LoWPAN. - * - * @return 1 on success, 0 on failure. - */ -int sixlowpan_lowpan_init_interface(int if_id); - -/** - * @brief Checks if an EUI-64 was set from a short address. If so - * it returns this address, else 0 - * - * @param[in] iid An EUI-64. - * - * @return The short address on success, 0 on failure. - */ -static inline uint16_t sixlowpan_lowpan_eui64_to_short_addr(const net_if_eui64_t *iid) -{ - if (iid->uint32[0] == HTONL(0x000000ff) && - iid->uint16[2] == HTONS(0xfe00)) { - return NTOHS(iid->uint16[3]); - } - - return 0; -} - -/** - * @brief Initializes all addresses and prefixes on an interface needed - * for 6LoWPAN. Calling this function together with - * sixlowpan_lowpan_init_interface() is not necessary. - * - * @param[in] if_id The interface to use with 6LoWPAN. - * @param[in] prefix the address prefix to advertise. - * - * @return 1 on success, 0 on failure. - */ -int sixlowpan_lowpan_init_adhoc_interface(int if_id, - const ipv6_addr_t *prefix); - -/** - * @brief Initializes a 6LoWPAN border router with an address - * - * @note Currently only working with addresses generated from - * IEEE 802.15.4 16-bit short addresses. - * - * @param[in] if_id The interface to use with 6LoWPAN. - * - * @return 1 on success, 0 on failure. - */ -int sixlowpan_lowpan_border_init(int if_id); - -/** - * @brief Send data via 6LoWPAN to destination node or next hop dest. - * - * @param[in] if_id The interface to send the data over. - * @param[in] dest Hardware address of the next hop or destination node. - * @param[in] dest_len Length of the destination address in byte. - * @param[in] data Data to send to destination node (may be - * manipulated). - * @param[in] data_len Length of data. - * - * @return length of transmitted data on success, -1 on failure. - */ -int sixlowpan_lowpan_sendto(int if_id, const void *dest, int dest_len, - uint8_t *data, uint16_t data_len); - -/** - * @brief Set header compression status for 6LoWPAN. - * - * @param[in] status Header compression status to set to. - */ -void sixlowpan_lowpan_set_iphc_status( - sixlowpan_lowpan_iphc_status_t status); - -/** - * @brief Initialize 6LoWPAN neighbor discovery (i.e. send - * router advertisement with Source Link-Layer Address Option) - * - * @see - * RFC 4861 - * , - * RFC 6775 - * - * - */ -void sixlowpan_lowpan_bootstrapping(void); - -/** - * @brief Registers a thread to read received 6LoWPAN frames. The - * 6LoWPAN frames are delivered as sixlowpan_lowpan_frame_t - * structs. - * - * @param[in] pid The PID of the receiver thread. - * - * @return 1 on success, ENOMEM if maximum number of registrable - * threads is exceeded. - */ -uint8_t sixlowpan_lowpan_register(kernel_pid_t pid); - -#if ENABLE_DEBUG -/** - * @brief Print current buffer of assembled (i. e. not fragmented) - * 6LoWPAN packages. - */ -void sixlowpan_lowpan_print_fifo_buffers(void); - -/** - * @brief Print current buffer for 6LoWPAN fragmentation reassembly. - */ -void sixlowpan_lowpan_print_reassembly_buffers(void); -#endif - -/** - * @brief Initializes 6LoWPAN module. - * - * @return 1 on success, 0 on failure. - */ -int sixlowpan_lowpan_init(void); - -#ifdef __cplusplus -} -#endif - -#endif /* SIXLOWPAN_LOWPAN_H */ -/** @} */ diff --git a/sys/net/include/sixlowpan/mac.h b/sys/net/include/sixlowpan/mac.h deleted file mode 100644 index 32c3e4aa00..0000000000 --- a/sys/net/include/sixlowpan/mac.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2013 INRIA. - * - * 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 net_sixlowpan_lowpan - * @{ - * - * @file - * @brief 6LoWPAN data structs, and prototypes for MAC layer - * - * @author Stephan Zeisberg - * @author Martine Lenders - * @author Eric Engel - * @author Oliver Gesch - */ - -#ifndef SIXLOWPAN_MAC_H -#define SIXLOWPAN_MAC_H - -#include - -#include "transceiver.h" - -#include "sixlowpan/types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Maximum length of a IEEE 802.15.4 long address represented as string. - */ -#define IEEE_802154_MAX_ADDR_STR_LEN (12) - -/** - * @brief Send an IEEE 802.15.4 frame to a long address. - * - * @param[in] if_id The interface to send over (will be ignored if - * *mcast* is 1). - * @param[in] dest The destination address of the frame (will be - * ignored if *mcast* is 1). - * @param[in] dest_len The lengths of the destination address in byte. - * @param[in] payload The payload of the frame. - * @param[in] length The length of the payload. - * @param[in] mcast send frame as multicast frame (*addr* and *if_id* - * will be ignored). - * - * @return Length of transmitted data in byte - */ -int sixlowpan_mac_send_ieee802154_frame(int if_id, const void *dest, - uint8_t dest_len, const void *payload, uint8_t length, uint8_t mcast); - -/** - * @brief Initialise 6LoWPAN MAC layer and register it to interface layer - * - * @return PID of the MAC receiver thread. - */ -kernel_pid_t sixlowpan_mac_init(void); - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif /* SIXLOWPAN_MAC_H */ diff --git a/sys/net/include/sixlowpan/ndp.h b/sys/net/include/sixlowpan/ndp.h deleted file mode 100644 index 48750e15dc..0000000000 --- a/sys/net/include/sixlowpan/ndp.h +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright (C) 2013 INRIA. - * - * 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. - */ - -/** - * @addtogroup net_sixlowpan_ndp - * @ingroup net_sixlowpan - * @brief Neighbor discovery protocol for 6LoWPAN and IPv6 - * @{ - * - * @file - * @brief 6LoWPAN constants, data structs, and prototypes related to NDP - * - * @author Stephan Zeisberg - * @author Martine Lenders - * @author Eric Engel - * @author Oliver Gesch - */ - -#ifndef SIXLOWPAN_NDP_H -#define SIXLOWPAN_NDP_H - -#include - -#include "net_if.h" -#include "timex.h" -#include "sixlowpan/types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define NDP_6LOWPAN_CONTEXT_MAX (16) - -#define NDP_OPT_SLLAO_TYPE (1) -#define NDP_OPT_TLLAO_TYPE (2) -#define NDP_OPT_PI_VLIFETIME_INFINITE (0xffffffff) -#define NDP_OPT_PI_PLIFETIME_INFINITE (0xffffffff) -#define NDP_OPT_ARO_STATE_SUCCESS (0) -#define NDP_OPT_ARO_STATE_DUP_ADDR (1) -#define NDP_OPT_ARO_STATE_NBR_CACHE_FULL (2) - -/** - * @brief Neighbor cache entry state according to - * - * RFC 4861, section 7.3.2 - * . - */ -typedef enum __attribute__((packed)) { - NDP_NCE_STATUS_INCOMPLETE, - NDP_NCE_STATUS_REACHABLE, - NDP_NCE_STATUS_STALE, - NDP_NCE_STATUS_DELAY, - NDP_NCE_STATUS_PROBE, -} ndp_nce_state_t; - -/** - * @brief Neighbor cache entry type according to - * - * RFC 6775, section 3.5 - * . - */ -typedef enum __attribute__((packed)) { - NDP_NCE_TYPE_GC = 1, ///< Garbage-collectible. - NDP_NCE_TYPE_REGISTERED, ///< Registered. - NDP_NCE_TYPE_TENTATIVE ///< Tentetive. -} ndp_nce_type_t; - -/** - * @brief Prefix list type to store information spread by prefix - * information option on the interface. - * - * @see net_if_addr_t - */ -typedef struct __attribute__((packed)) ndp_prefix_info_t { - /** - * @brief The next on the interface. Initialize with NULL - */ - struct ndp_prefix_info_t *addr_next; - /** - * @brief The prev address on the interface. Initialize with NULL - */ - struct ndp_prefix_info_t *addr_prev; - /** - * @brief Flags to define upper layer protocols this address applies to. - * For this layer NET_IF_L3P_IPV6_PREFIX must be set. - */ - net_if_l3p_t prefix_protocol; - ipv6_addr_t *prefix_data; ///< The Prefix. - uint8_t prefix_len; ///< Length of the prefix. - uint8_t inuse; ///< Prefix is in in use. - /** - * Use this information in Prefix Information Options of Router - * Advertisements. - */ - uint8_t advertisable; - uint8_t flags; ///< flags of the prefix information option - uint32_t valid_lifetime; ///< valid lifetime - uint32_t preferred_lifetime; ///< preferred lifetime - uint8_t infinite; ///< flag to set to infinite lifetime -} ndp_prefix_info_t; - -/** - * @brief Default router list to store information spread by - * router advertisement. - */ -typedef struct __attribute__((packed)) { - ipv6_addr_t addr; ///< Address of router. - timex_t inval_time; ///< remaining time until this entry is - ///< invalid. -} ndp_default_router_list_t; - -/** - * @brief Neighbor cache as defined in - * - * RFC 4861, section 5.1 - * . - */ -typedef struct __attribute__((packed)) { - int if_id; ///< Interface the IPv6 address is reachable - ///< over - ndp_nce_type_t type; ///< Type of neighbor cache entry. - ndp_nce_state_t state; ///< State of neighbor cache entry. - uint8_t isrouter; ///< Flag to signify that this neighbor - ///< is a router. - ipv6_addr_t addr; ///< IPv6 address of the neighbor. - uint8_t lladdr[8]; ///< Link-layer address of the neighbor - uint8_t lladdr_len; ///< Length of link-layer address of the - ///< neighbor - timex_t ltime; ///< lifetime of entry. -} ndp_neighbor_cache_t; - -/** - * @brief Authoritive border router cache as defined in - * - * RFC 6775 - * . - */ -typedef struct __attribute__((packed)) { - uint16_t version; ///< version of entry. - ipv6_addr_t abr_addr; ///< Addres of ABR. - uint8_t cids[NDP_6LOWPAN_CONTEXT_MAX]; ///< context IDs. -} ndp_a6br_cache_t; - -ndp_default_router_list_t *ndp_default_router_list_search(ipv6_addr_t *ipaddr); -uint8_t ndp_neighbor_cache_add(int if_id, const ipv6_addr_t *ipaddr, - const void *lladdr, uint8_t lladdr_len, - uint8_t isrouter, ndp_nce_state_t state, - ndp_nce_type_t type, uint16_t ltime); - -/** - * @brief Removes an address from the neighbor cache by IPv6 address. - * - * @param[in] ipaddr IPv6 address to remove, leave NULL if you only want - * to remove by Link-layer address. - * - * @return 1 on success, 0 otherwise. - */ -uint8_t ndp_neighbor_cache_remove(const ipv6_addr_t *ipaddr); - -ndp_neighbor_cache_t *ndp_neighbor_cache_search(ipv6_addr_t *ipaddr); -ndp_neighbor_cache_t *ndp_get_ll_address(ipv6_addr_t *ipaddr); -int ndp_addr_is_on_link(ipv6_addr_t *dest_addr); - -/** - * @brief Adds a prefix information to an interface. If it already exists, - * the values *valid_lifetime*, *preferred_lifetime*, *advertisable*, - * and flags will be updated accordingly and the prefix will be marked - * as *in_use*. - * - * @see - * RFC 4861, section 4.6.2 - * . - * - * @param[in] if_id The interface's ID. - * @param[in] prefix The prefix. - * @param[in] prefix_len The length of the prefix in bit. - * @param[in] valid_lifetime The time in seconds this prefix is valid - * for on-link determination. - * NDP_OPT_PI_VLIFETIME_INFINITE for infinite - * lifetime. - * @param[in] preferred_lifetime The time in seconds addresses generated with - * this prefix remain preferred. - * NDP_OPT_PI_PLIFETIME_INFINITE for infinite - * lifetime. - * @param[in] advertisable Set this to a value != 0 to advertise this - * prefix information with the Prefix - * Information Option, set it to 0 if not. - * @param[in] flags Flags for the Prefix Information Option. - * Valid values are - * ICMPV6_NDP_OPT_PI_FLAG_ON_LINK and - * ICMPV6_NDP_OPT_PI_FLAG_AUTONOM - */ -int ndp_add_prefix_info(int if_id, const ipv6_addr_t *prefix, - uint8_t prefix_len, uint32_t valid_lifetime, - uint32_t preferred_lifetime, uint8_t advertisable, - uint8_t flags); - -/** - * @brief Searches the information for the longest prefix up to *up_to* bits - * on an interface fitting to an address *addr*. - * - * @param[in] if_id The interface's ID. - * @param[in] addr The address to search the prefix for. - * @param[in] up_to The number of bits up to which point the search should - * go. Set to IPV6_ADDR_BIT_LEN for the whole address. - * Values greater then IPV6_ADDR_BIT_LEN are set to - * IPV6_ADDR_BIT_LEN. - * - * @return The found prefix information, NULL when none is found. - */ -ndp_prefix_info_t *ndp_prefix_info_search(int if_id, const ipv6_addr_t *addr, - uint8_t up_to); - -/** - * @brief Searches the information for the prefix that matches *prefix* with - * length *prefix_len*. - * - * @param[in] if_id The interface's ID. - * @param[in] prefix The prefix to search for. - * @param[in] prefix_len The length of the prefix in bit. - * - * @return The found prefix information, NULL when none is found. - */ -ndp_prefix_info_t *ndp_prefix_info_match(int if_id, const ipv6_addr_t *prefix, - uint8_t prefix_len); -ndp_a6br_cache_t *ndp_a6br_cache_get_most_current(void); -ndp_a6br_cache_t *ndp_a6br_cache_get_oldest(void); - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif /* SIXLOWPAN_NDP_H */ diff --git a/sys/net/include/sixlowpan/types.h b/sys/net/include/sixlowpan/types.h deleted file mode 100644 index fd54239598..0000000000 --- a/sys/net/include/sixlowpan/types.h +++ /dev/null @@ -1,408 +0,0 @@ -/* - * Copyright (C) 2013 INRIA. - * - * 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. - */ - -/** - * @defgroup net_sixlowpan_types Type definitions and data structs for 6LoWPAN and IPv6 - * @ingroup net_sixlowpan - * @brief Structs, constants, and enums for 6LoWPAN and IPv6 related functions - * @{ - * - * @file - * @brief 6LoWPAN data types - * - * @author Stephan Zeisberg - * @author Martine Lenders - * @author Eric Engel - * @author Oliver Gesch - */ - -#ifndef SIXLOWPAN_TYPES_H -#define SIXLOWPAN_TYPES_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Data type to represent an EUI-64. - */ -typedef union __attribute__((packed)) { - uint8_t uint8[8]; ///< divided by 8 8-bit words. - uint16_t uint16[4]; ///< divided by 4 16-bit words. -} ieee_802154_long_t; - -/** - * @brief Data type to represent IEEE 802.15.4 short address. - */ -typedef union __attribute__((packed)) { - uint8_t uint8[2]; ///< divided by 2 8-bit words. - uint16_t uint16[1]; ///< as a 16-bit value. -} ieee_802154_short_t; - -/** - * @brief Data type to represent an IPv6 address. - */ -typedef union __attribute__((packed)) { - uint8_t uint8[16]; ///< divided by 16 8-bit words. - uint16_t uint16[8]; ///< divided by 8 16-bit words. - uint32_t uint32[4]; ///< divided by 4 32-bit words. -} ipv6_addr_t; - -/** - * @brief Data type to represent an IPv6 packet header - * - * @see - * RFC 2460 - * - */ -typedef struct __attribute__((packed)) { - uint8_t version_trafficclass; ///< Version field + first 4 bit of Traffic Class. - uint8_t trafficclass_flowlabel; ///< last 4 bit of Traffic Class - ///< and first 4 bit of Flow Label. - uint16_t flowlabel; ///< last 16 bit of Flow Label. - uint16_t length; ///< payload length of this packet. - uint8_t nextheader; ///< type of next header in this packet. - uint8_t hoplimit; ///< hop limit for this packet. - ipv6_addr_t srcaddr; ///< source address of this packet. - ipv6_addr_t destaddr; ///< destination address of this packet. -} ipv6_hdr_t; - -/** - * @brief Data type to represent an IPv6 source routing header for RPL - * - * @see [RFC 6554](http://tools.ietf.org/html/rfc6554) - */ -typedef struct __attribute__((packed)) { - uint8_t nextheader; /**< type of next header in this packet. */ - uint8_t hdrextlen; /**< length of header in 8-octet units. */ - uint8_t routing_type; /**< identify srh-variant. */ - uint8_t segments_left; /**< remaining route segments before reaching destination. */ - unsigned int cmpri:4, cmpre:4; /**< 4+4 bit, expressing prefix octets from each/last segment. */ - unsigned pad :4; /**< number of octets used for padding after addresses. */ - unsigned reserved :10; /**< reserved. Set to 0. */ - unsigned reserved2 :10; /**< reserved. Set to 0. */ - ipv6_addr_t route[]; -} ipv6_srh_t; - -/** - * @brief Data type to represent an ICMPv6 packet header. - * - * @see - * RFC 4443 - * - */ -typedef struct __attribute__((packed)) { - uint8_t type; ///< type field. - uint8_t code; ///< code field. - uint16_t checksum; ///< checksum field. -} icmpv6_hdr_t; - -/** - * @brief Data type to represent the relevant sub-part of an - * ICMPv6 Parameter Problem Message. - * - * @see - * RFC 4443, section 3.4 - * - */ -typedef struct __attribute__((packed)) { - uint8_t pointer; -} icmpv6_parameter_prob_hdr_t; - -/** - * @brief Data type to represent the relevant sub-part of an - * ICMPv6 Echo Request. - * - * @see - * RFC 4443, section 4.1 - * - */ -typedef struct __attribute__((packed)) { - uint16_t id; ///< identifier field. - uint16_t seq; ///< sequence number field. -} icmpv6_echo_request_hdr_t; - -/** - * @brief Data type to represent the relevant sub-part of an - * ICMPv6 Echo Reply. - * - * @see - * RFC 4443, section 4.2 - * - */ -typedef struct __attribute__((packed)) { - uint16_t id; ///< identifier field. - uint16_t seq; ///< sequence number field. -} icmpv6_echo_reply_hdr_t; - -/* - * ICMPv6 Router Solicitation has no fields but reserved fields - * and is thus elided. - */ - -/** - * @brief Data type to represent the relevant sub-part of an - * ICMPv6 Router Advertisement. - * - * @see ICMPV6_ROUTER_ADV_FLAG_MANAGED - * @see ICMPV6_ROUTER_ADV_FLAG_OTHER - * @see - * RFC 4861, section 4.2 - * - */ -typedef struct __attribute__((packed)) { - uint8_t hoplimit; ///< hop limit field. - uint8_t autoconfig_flags; ///< (M)anaged and (Other) flag. - uint16_t router_lifetime; ///< router lifetime field. - uint32_t reachable_time; ///< reachable time field. - uint32_t retrans_timer; ///< retrans timer field. -} icmpv6_router_adv_hdr_t; - -/** - * @brief Bit for (M)anaged flag in Router Advertisement - * @see icmpv6_router_adv_hdr_t - * @see - * RFC 4861, section 4.2 - * - */ -#define ICMPV6_ROUTER_ADV_FLAG_MANAGED (0x80) - -/** - * @brief Bit for (O)ther flag in Router Advertisement - * @see icmpv6_router_adv_hdr_t - * @see - * RFC 4861, section 4.2 - * - */ -#define ICMPV6_ROUTER_ADV_FLAG_OTHER (0x40) - -/** - * @brief Data type to represent the relevant sub-part of an - * ICMPv6 Neighbor Solicitation. - * - * @see - * RFC 4861, section 4.3 - * - */ -typedef struct __attribute__((packed)) { - uint32_t reserved; ///< reserved field. - ipv6_addr_t target_addr; ///< target address field. -} icmpv6_neighbor_sol_hdr_t; - -/** - * @brief Data type to represent the relevant sub-part of an - * ICMPv6 Neighbor Solicitation. - * - * @see ICMPV6_NEIGHBOR_ADV_FLAG_ROUTER - * @see ICMPV6_NEIGHBOR_ADV_FLAG_SOLICITED - * @see ICMPV6_NEIGHBOR_ADV_FLAG_OVERRIDE - * @see - * RFC 4861, section 4.4 - * - */ -typedef struct __attribute__((packed)) { - uint8_t rso; ///< flags + first 5 bits of reserved field. - uint8_t reserved[3]; ///< rest of reserved field. - ipv6_addr_t target_addr; ///< target address field. -} icmpv6_neighbor_adv_hdr_t; - -/** - * @brief Bit for (R)outer flag in Neighbor Advertisement - * @see icmpv6_neighbor_adv_hdr_t - * @see - * RFC 4861, section 4.4 - * - */ -#define ICMPV6_NEIGHBOR_ADV_FLAG_ROUTER (0x80) - -/** - * @brief Bit for (S)olicited flag in Neighbor Advertisement - * @see icmpv6_neighbor_adv_hdr_t - * @see - * RFC 4861, section 4.4 - * - */ -#define ICMPV6_NEIGHBOR_ADV_FLAG_SOLICITED (0x40) - -/** - * @brief Bit for (O)verride flag in Neighbor Advertisement - * @see icmpv6_neighbor_adv_hdr_t - * @see - * RFC 4861, section 4.4 - * - */ -#define ICMPV6_NEIGHBOR_ADV_FLAG_OVERRIDE (0x20) - -/** - * @brief Data type to represent an IPv6 Neighbor Discover Option - * header. - * - * @see - * RFC 4861, section 4.6 - * - */ -typedef struct __attribute__((packed)) { - uint8_t type; ///< type field. - uint8_t length; ///< length field. -} icmpv6_ndp_opt_hdr_t; - -/** - * @brief Data type to represent a Source/Target Link-layer Option - * Address option. Link-layer address may be added in payload. - * - * @see - * RFC 4861, section 4.6.1 - * - */ -typedef struct __attribute__((packed)) { - uint8_t type; ///< type field. - uint8_t length; ///< length field. -} icmpv6_ndp_opt_stllao_t; - -/** - * @brief Data type to represent a Prefix Information option. - * - * @see ICMPV6_NDP_OPT_PI_FLAG_ON_LINK - * @see ICMPV6_NDP_OPT_PI_FLAG_AUTONOM - * @see - * RFC 4861, section 4.6.2 - * - */ -typedef struct __attribute__((packed)) { - uint8_t type; ///< type field. - uint8_t length; ///< length field. - uint8_t prefix_length; ///< prefix length field. - uint8_t l_a_reserved1; ///< flags + reserved1 field. - uint32_t val_ltime; ///< valid lifetime field. - uint32_t pref_ltime; ///< preferred lifetime field. - uint32_t reserved2; ///< reserved2 field. - ipv6_addr_t addr; ///< prefix field. -} icmpv6_ndp_opt_pi_t; - -/** - * @brief Bit for on-(L)ink flag in Prefix Information option. - * @see icmpv6_ndp_opt_pi_t - * @see - * RFC 4861, section 4.6.2 - * - */ -#define ICMPV6_NDP_OPT_PI_FLAG_ON_LINK (0x80) - -/** - * @brief Bit for (A)utonoums address-configuration flag in Prefix - * Information option. - * @see icmpv6_ndp_opt_pi_t - * @see - * RFC 4861, section 4.6.2 - * - */ -#define ICMPV6_NDP_OPT_PI_FLAG_AUTONOM (0x40) - -/** - * @brief Data type to represent a MTU option. - * - * @see - * RFC 4861, section 4.6.4 - * - */ -typedef struct __attribute__((packed)) { - uint8_t type; ///< type field. - uint8_t length; ///< length field. - uint16_t reserved; ///< reserved field. - uint32_t mtu; ///< MTU field. -} icmpv6_ndp_opt_mtu_t; - -/** - * @brief Data type to represent an Address Registration Option. - * - * @see - * RFC 6775, section 4.1 - * - */ -typedef struct __attribute__((packed)) { - uint8_t type; ///< type field. - uint8_t length; ///< length field. - uint8_t status; ///< status field. - uint8_t reserved1; ///< reserved1 field. - uint16_t reserved2; ///< reserved2 field. - uint16_t reg_ltime; ///< registration lifetem field. - ieee_802154_long_t eui64; ///< EUI-64 field. -} icmpv6_ndp_opt_aro_t; - -/** - * @brief Data type to represent an 6LoWPAN Context Option. - * - * @see ICMPV6_NDP_OPT_6CO_FLAG_CCOMPR - * @see ICMPV6_NDP_OPT_6CO_FLAG_CID - * @see - * RFC 6775, section 4.2 - * - */ -typedef struct __attribute__((packed)) { - uint8_t type; ///< type field. - uint8_t length; ///< length field. - uint8_t c_length; ///< context length field. - uint8_t c_flags; ///< Res(erved) field + C flag + CID field. - uint16_t reserved; ///< reserved field. - uint16_t val_ltime; ///< valid lifetime field. -} icmpv6_ndp_opt_6co_hdr_t; - -/** - * @brief Bit for context (C)ompression flag in 6LoWPAN Context - * Option. - * @see icmpv6_ndp_opt_6co_hdr_t - * @see - * RFC 6775, section 4.2 - * - */ -#define ICMPV6_NDP_OPT_6CO_FLAG_CCOMPR (0x10) - -/** - * @brief Bitmask for Context Identifier in 6LoWPAN Context Option. - * @see icmpv6_ndp_opt_6co_hdr_t - * @see - * RFC 6775, section 4.2 - * - */ -#define ICMPV6_NDP_OPT_6CO_FLAG_CID (0x0F) - -/** - * @brief Data type to represent an Authoritative Border Router Option. - * @note TODO not according to RFC. - * - * @see - * RFC 6775, section 4.3 - * - */ -typedef struct __attribute__((packed)) { - uint8_t type; ///< type field. - uint8_t length; ///< length field. - uint16_t version; ///< version field. - uint32_t reserved; ///< reseverd field. - ipv6_addr_t addr; ///< 6LBR address field. -} icmpv6_ndp_opt_abro_t; - -/** - * @brief Data type to represent address types according to - * RFC 4862. - */ -typedef enum __attribute__((packed)) { - NDP_ADDR_STATE_TENTATIVE, ///< tentative address, uniqueness to be verified. - NDP_ADDR_STATE_PREFERRED, ///< preferred address, for unrestricted use. - NDP_ADDR_STATE_DEPRECATED, ///< deprecated address, use discouraged. - NDP_ADDR_STATE_ANY ///< addresses of this state are always permitted. -} ndp_addr_state_t; - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif /* SIXLOWPAN_TYPES_H */ diff --git a/sys/net/include/socket_base.h b/sys/net/include/socket_base.h deleted file mode 100644 index 458bd2ff5f..0000000000 --- a/sys/net/include/socket_base.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2013 INRIA. - * - * 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. - */ - -/** - * @defgroup socket_base Transport layer implementation - * - * @ingroup net - * @brief This module implements basic transport layer socket functionality. - * This includes 6LoWPAN UDP header compression and (experimental) - * 6LoWPAN TCP header compression. - * - * It wraps all API types, constants and functions of the transport layer - * implementation. - * - * @see - * RFC 6282 - Compression Format for IPv6 Datagrams over - * IEEE 802.15.4-Based Networks - UDP Header Compression - * - * @see - * RFC draft-aayadi-6lowpan-tcphc-01 - TCP header compression for - * 6LoWPAN - * - * @{ - * @file - * @brief transport_layer functions - * @author Oliver Gesch - * @author Martine Lenders - */ - -#ifndef SOCKET_BASE_H -#define SOCKET_BASE_H - -#include "socket_base/in.h" -#include "socket_base/socket.h" -#include "socket_base/types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* SOCKET_BASE_H */ -/** @} */ diff --git a/sys/net/include/socket_base/in.h b/sys/net/include/socket_base/in.h deleted file mode 100644 index ca06f3a8f5..0000000000 --- a/sys/net/include/socket_base/in.h +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (C) 2014 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. - */ - -/** - * socket_base/in.h - Constants defined by the internet system, per RFC 790, - * September 1981, and numerous additions, inspired by - * netinet/in.h definitions. - * @{ - * @file - * @brief IP next header constants - * @see - * RFC790 - Assigned Numbers - * - * @see - * IEEE Std 1003.1, 2013 Edition - netinet/in.h - * - * @see - * IANA - Protocol Numbers - * - * @author Oliver Gesch - * @author Martine Lenders - */ - -#ifndef SOCKET_BASE_IN_H -#define SOCKET_BASE_IN_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Protocols (RFC 1700) TODO: may be deleted due to some double definition - * in sys/net/sixlowpan/include/sixlowpan/ip.h - */ -#define IPPROTO_IP (0) ///< dummy for IP -#define IPPROTO_HOPOPTS (0) ///< IP6 hop-by-hop options -#define IPPROTO_ICMP (1) ///< control message protocol -#define IPPROTO_IGMP (2) ///< group mgmt protocol -#define IPPROTO_GGP (3) ///< gateway^2 (deprecated) -#define IPPROTO_IPV4 (4) ///< IPv4 encapsulation -#define IPPROTO_IPIP IPPROTO_IPV4 ///< for compatibility -#define IPPROTO_TCP (6) ///< tcp -#define IPPROTO_ST (7) ///< Stream protocol II -#define IPPROTO_EGP (8) ///< exterior gateway protocol -#define IPPROTO_PIGP (9) ///< private interior gateway -#define IPPROTO_RCCMON (10) ///< BBN RCC Monitoring -#define IPPROTO_NVPII (11) ///< network voice protocol -#define IPPROTO_PUP (12) ///< pup -#define IPPROTO_ARGUS (13) ///< Argus -#define IPPROTO_EMCON (14) ///< EMCON -#define IPPROTO_XNET (15) ///< Cross Net Debugger -#define IPPROTO_CHAOS (16) ///< Chaos -#define IPPROTO_UDP (17) ///< user datagram protocol -#define IPPROTO_MUX (18) ///< Multiplexing -#define IPPROTO_MEAS (19) ///< DCN Measurement Subsystems -#define IPPROTO_HMP (20) ///< Host Monitoring -#define IPPROTO_PRM (21) ///< Packet Radio Measurement -#define IPPROTO_IDP (22) ///< xns idp -#define IPPROTO_TRUNK1 (23) ///< Trunk-1 -#define IPPROTO_TRUNK2 (24) ///< Trunk-2 -#define IPPROTO_LEAF1 (25) ///< Leaf-1 -#define IPPROTO_LEAF2 (26) ///< Leaf-2 -#define IPPROTO_RDP (27) ///< Reliable Data -#define IPPROTO_IRTP (28) ///< Reliable Transaction -#define IPPROTO_TP (29) ///< tp-4 w/ class negotiation -#define IPPROTO_BLT (30) ///< Bulk Data Transfer -#define IPPROTO_NSP (31) ///< Network Services -#define IPPROTO_INP (32) ///< Merit Internodal -#define IPPROTO_SEP (33) ///< Sequential Exchange -#define IPPROTO_3PC (34) ///< Third Party Connect -#define IPPROTO_IDPR (35) ///< InterDomain Policy Routing -#define IPPROTO_XTP (36) ///< XTP -#define IPPROTO_DDP (37) ///< Datagram Delivery -#define IPPROTO_CMTP (38) ///< Control Message Transport -#define IPPROTO_TPXX (39) ///< TP++ Transport -#define IPPROTO_IL (40) ///< IL transport protocol -#define IPPROTO_IPV6 (41) ///< IP6 header -#define IPPROTO_SDRP (42) ///< Source Demand Routing -#define IPPROTO_ROUTING (43) ///< IP6 routing header -#define IPPROTO_FRAGMENT (44) ///< IP6 fragmentation header -#define IPPROTO_IDRP (45) ///< InterDomain Routing -#define IPPROTO_RSVP (46) ///< resource reservation -#define IPPROTO_GRE (47) ///< General Routing Encap. -#define IPPROTO_MHRP (48) ///< Mobile Host Routing -#define IPPROTO_BHA (49) ///< BHA -#define IPPROTO_ESP (50) ///< IP6 Encap Sec. Payload -#define IPPROTO_AH (51) ///< IP6 Auth Header -#define IPPROTO_INLSP (52) ///< Integ. Net Layer Security -#define IPPROTO_SWIPE (53) ///< IP with encryption -#define IPPROTO_NHRP (54) ///< Next Hop Resolution -///< 55-57: Unassigned -#define IPPROTO_ICMPV6 (58) ///< ICMP6 -#define IPPROTO_NONE (59) ///< IP6 no next header -#define IPPROTO_DSTOPTS (60) ///< IP6 destination option -#define IPPROTO_AHIP (61) ///< any host internal protocol -#define IPPROTO_CFTP (62) ///< CFTP -#define IPPROTO_HELLO (63) ///< "hello" routing protocol -#define IPPROTO_SATEXPAK (64) ///< SATNET/Backroom EXPAK -#define IPPROTO_KRYPTOLAN (65) ///< Kryptolan -#define IPPROTO_RVD (66) ///< Remote Virtual Disk -#define IPPROTO_IPPC (67) ///< Pluribus Packet Core -#define IPPROTO_ADFS (68) ///< Any distributed FS -#define IPPROTO_SATMON (69) ///< Satnet Monitoring -#define IPPROTO_VISA (70) ///< VISA Protocol -#define IPPROTO_IPCV (71) ///< Packet Core Utility -#define IPPROTO_CPNX (72) ///< Comp. Prot. Net. Executive -#define IPPROTO_CPHB (73) ///< Comp. Prot. HeartBeat -#define IPPROTO_WSN (74) ///< Wang Span Network -#define IPPROTO_PVP (75) ///< Packet Video Protocol -#define IPPROTO_BRSATMON (76) ///< BackRoom SATNET Monitoring -#define IPPROTO_ND (77) ///< Sun net disk proto (temp.) -#define IPPROTO_WBMON (78) ///< WIDEBAND Monitoring -#define IPPROTO_WBEXPAK (79) ///< WIDEBAND EXPAK -#define IPPROTO_EON (80) ///< ISO cnlp -#define IPPROTO_VMTP (81) ///< VMTP -#define IPPROTO_SVMTP (82) ///< Secure VMTP -#define IPPROTO_VINES (83) ///< Banyon VINES -#define IPPROTO_TTP (84) ///< TTP -#define IPPROTO_IGP (85) ///< NSFNET-IGP -#define IPPROTO_DGP (86) ///< dissimilar gateway prot. -#define IPPROTO_TCF (87) ///< TCF -#define IPPROTO_IGRP (88) ///< Cisco/GXS IGRP -#define IPPROTO_OSPFIGP (89) ///< OSPFIGP -#define IPPROTO_SRPC (90) ///< Strite RPC protocol -#define IPPROTO_LARP (91) ///< Locus Address Resoloution -#define IPPROTO_MTP (92) ///< Multicast Transport -#define IPPROTO_AX25 (93) ///< AX.25 Frames -#define IPPROTO_IPEIP (94) ///< IP encapsulated in IP -#define IPPROTO_MICP (95) ///< Mobile Int.ing control -#define IPPROTO_SCCSP (96) ///< Semaphore Comm. security -#define IPPROTO_ETHERIP (97) ///< Ethernet IP encapsulation -#define IPPROTO_ENCAP (98) ///< encapsulation header -#define IPPROTO_APES (99) ///< any private encr. scheme -#define IPPROTO_GMTP (100) ///< GMTP -#define IPPROTO_IPCOMP (108) ///< payload compression (IPComp) -/** - * 101-254: Partly Unassigned - */ -#define IPPROTO_PIM (103) ///< Protocol Independent Mcast -#define IPPROTO_PGM (113) ///< PGM -/* 255: Reserved */ -/* */ -#define IPPROTO_DIVERT (254) ///< divert pseudo-protocol (BSD Private, local use, namespace incursion) -#define IPPROTO_RAW (255) ///< raw IP packet -#define IPPROTO_MAX (256) - -#define IPPROTO_DONE (257) ///< last return value of *_input(), meaning "all job for this pkt is done". - -#define IN_LOOPBACKNET (127) ///< official! - -#ifdef __cplusplus -} -#endif - -#endif /* SOCKET_BASE_IN_H */ diff --git a/sys/net/include/socket_base/socket.h b/sys/net/include/socket_base/socket.h deleted file mode 100644 index baab3cef9d..0000000000 --- a/sys/net/include/socket_base/socket.h +++ /dev/null @@ -1,341 +0,0 @@ -/** - * socket_base/socket.h - Transport Layer socket API - * - * Copyright (C) 2013 INRIA. - * - * 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 socket_base - * @{ - * @file - * @brief Header for BSD socket API - * @see - * IEEE Std 1003.1, 2013 Edition - sys/socket.h - * - * @author Oliver Gesch - * @author Martine Lenders - */ - - -#ifndef SOCKET_BASE_SOCKET_H -#define SOCKET_BASE_SOCKET_H - -#include - -#include "ipv6.h" - -#include "socket_base/in.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef uint8_t sa_family_t; ///< POSIX compatible type for address family. -typedef uint32_t socklen_t; ///< POSIX compatible type for address length. - - -#define SOCK_STREAM 1 ///< POSIX compatible stream socket type. -#define SOCK_DGRAM 2 ///< POSIX compatible datagram socket type. -#define SOCK_RAW 3 ///< POSIX compatible raw-protocol interface type. -#define SOCK_RDM 4 ///< POSIX compatible reliably-delivered message type. -#define SOCK_SEQPACKET 5 ///< POSIX compatible sequenced packet stream type. - -#define AF_UNSPEC 0 ///< unspecified address family. -#define AF_LOCAL 1 ///< local to host (pipes, portals) address family. -#define AF_UNIX AF_LOCAL ///< alias for AF_LOCAL for backward compatibility. -#ifndef AF_INET -#define AF_INET 2 ///< internetwork address family: UDP, TCP, etc. -#endif -#define AF_IMPLINK 3 ///< ARPAnet IMP address family. -#define AF_PUP 4 ///< PUP protocols address family: e.g. BSP -#define AF_CHAOS 5 ///< MIT CHAOS protocols address family -#define AF_NS 6 ///< XEROX NS protocols address family -#define AF_ISO 7 ///< ISO protocols address family -#define AF_OSI AF_ISO ///< alias for AF_ISO -#define AF_ECMA 8 ///< European computer manufacturers address family -#define AF_DATAKIT 9 ///< datakit protocols address family -#define AF_CCITT 10 ///< CCITT protocols address family, X.25 etc -#define AF_SNA 11 ///< IBM SNA address family -#define AF_DECnet 12 ///< DECnet address family -#define AF_DLI 13 ///< DEC Direct data link interface address family -#define AF_LAT 14 ///< LAT address family -#define AF_HYLINK 15 ///< NSC Hyperchannel address family -#define AF_APPLETALK 16 ///< Apple Talk address family -#define AF_ROUTE 17 ///< Internal Routing Protocol address family -#define AF_LINK 18 ///< Link layer interface address family -#define pseudo_AF_XTP 19 ///< eXpress Transfer Protocol (no AF) -#define AF_COIP 20 ///< connection-oriented IP, aka ST II address family. -#define AF_CNT 21 ///< Computer Network Technology address family -#define pseudo_AF_RTIP 22 ///< Help Identify RTIP packets address family -#define AF_IPX 23 ///< Novell Internet Protocol (no AF) -#define AF_SIP 24 ///< Simple Internet Protocol address family -#define pseudo_AF_PIP 25 ///< Help Identify PIP packets (no AF) -#define AF_ISDN 26 ///< Integrated Services Digital Network address family -#define AF_E164 AF_ISDN ///< CCITT E.164 recommendation -#define pseudo_AF_KEY 27 ///< Internal key-management function (no AF) -#ifndef AF_INET6 -/** - * IPv6 address family. - * - * @see AF_INET - */ -#define AF_INET6 28 -#endif -#define AF_NATM 29 ///< native ATM access address family -#define AF_ATM 30 ///< ATM address family -#define pseudo_AF_HDRCMPLT 31 ///< Used by BPF to not rewrite headers in interface output routine -#define AF_NETGRAPH 32 ///< Netgraph sockets address family -#define AF_MAX 33 ///< Maximum for address families - -/* - * Protocol families, same as address families for now. - */ -#define PF_UNSPEC AF_UNSPEC ///< protocol family - ///< @see AF_UNSPEC -#define PF_LOCAL AF_LOCAL ///< protocol family - ///< @see AF_LOCAL -#define PF_UNIX PF_LOCAL ///< alias for PF_LOCAL for backward compatibility -#define PF_INET AF_INET ///< protocol family - ///< @see AF_INET -#define PF_IMPLINK AF_IMPLINK ///< protocol family - ///< @see AF_IMPLINK -#define PF_PUP AF_PUP ///< protocol family - ///< @see AF_PUP -#define PF_CHAOS AF_CHAOS ///< protocol family - ///< @see AF_CHAOS -#define PF_NS AF_NS ///< protocol family - ///< @see AF_NS -#define PF_ISO AF_ISO ///< protocol family - ///< @see AF_ISO -#define PF_OSI AF_OSI ///< protocol family - ///< @see AF_OSI -#define PF_ECMA AF_ECMA ///< protocol family - ///< @see AF_ECMA -#define PF_DATAKIT AF_DATAKIT ///< protocol family - ///< @see AF_DATAKIT -#define PF_CCITT AF_CCITT ///< protocol family - ///< @see AF_CCITT -#define PF_SNA AF_SNA ///< protocol family - ///< @see AF_SNA -#define PF_DECnet AF_DECnet ///< protocol family - ///< @see AF_DECnet -#define PF_DLI AF_DLI ///< protocol family - ///< @see AF_DLI -#define PF_LAT AF_LAT ///< protocol family - ///< @see AF_LAT -#define PF_HYLINK AF_HYLINK ///< protocol family - ///< @see AF_HYLINK -#define PF_APPLETALK AF_APPLETALK ///< protocol family - ///< @see AF_APPLETALK -#define PF_ROUTE AF_ROUTE ///< protocol family - ///< @see AF_ROUTE -#define PF_LINK AF_LINK ///< protocol family - ///< @see AF_LINK -#define PF_XTP pseudo_AF_XTP ///< protocol family (no address family defined, only PF) - ///< @see pseudo_AF_XTP -#define PF_COIP AF_COIP ///< protocol family - ///< @see AF_COIP -#define PF_CNT AF_CNT ///< protocol family - ///< @see AF_CNT -#define PF_SIP AF_SIP ///< protocol family - ///< @see AF_SIP -#define PF_IPX AF_IPX ///< protocol family (same format as AF_NS) - ///< @see AF_IPX - ///< @see AF_NS -#define PF_RTIP pseudo_AF_RTIP ///< protocol family (same format as AF_INET) - ///< @see pseudo_AF_RTIP -#define PF_PIP pseudo_AF_PIP ///< protocol family - ///< @see pseudo_AF_PIP -#define PF_ISDN AF_ISDN ///< protocol family - ///< @see AF_ISDN -#define PF_KEY pseudo_AF_KEY ///< protocol family - ///< @see pseudo_AF_KEY -#define PF_INET6 AF_INET6 ///< protocol family - ///< @see AF_INET6 -#define PF_NATM AF_NATM ///< protocol family - ///< @see AF_NATM -#define PF_ATM AF_ATM ///< protocol family - ///< @see AF_ATM -#define PF_NETGRAPH AF_NETGRAPH ///< protocol family - ///< @see AF_NETGRAPH -#define PF_MAX AF_MAX ///< maximum of protocol families - ///< @see AF_MAX - -#define TRANSPORT_LAYER_SOCKET_STATIC_MSS 48 ///< Static TCP maxmimum segment size. - -/** - * Static TCP flow control window for window size 1. - */ -#define TRANSPORT_LAYER_SOCKET_STATIC_WINDOW 1 * TRANSPORT_LAYER_SOCKET_STATIC_MSS - -/** - * Maximum size of TCP buffer. - */ -#define TRANSPORT_LAYER_SOCKET_MAX_TCP_BUFFER 1 * TRANSPORT_LAYER_SOCKET_STATIC_WINDOW - -/** - * Socket address type for IPv6 communication. - */ -typedef struct __attribute__((packed)) { - uint8_t sin6_family; ///< set to AF_INET6 - uint16_t sin6_port; ///< transport layer port number - uint32_t sin6_flowinfo; ///< IPv6 flow information - ipv6_addr_t sin6_addr; ///< IPv6 address -} sockaddr6_t; - -/** - * Creates new socket for communication in family *domain*, of type *type*, - * and with protocol *protocol*. Roughly identical to POSIX's - * socket(2). - * - * @param[in] domain Address family. Only AF_INET6 is supported by now (no - * check on creation). - * @param[in] type Communication type. - * @param[in] protocol Protocol type. May be left 0 if domain and type are - * sufficiant enough (I. e. domain=AF_INET6 and type=SOCK_STREAM - * imply IPPROTO_TCP, etc.) - * @return Socket ID on success, -1 otherwise. - */ -int socket_base_socket(int domain, int type, int protocol); - -/** - * Connects socket *socket* with a foreign host with IPv6 address *addr* - * (of length *addrlen*) for connection orientated communication (e. g. - * SOCK_STREAM). Roughly identical to POSIX's - * connect(2). - * - * @param[in] socket The ID of the socket. - * @param[in] addr The IPv6 address to connect to - * @param[in] addrlen Length of the IPv6 address in byte (always 16) - * - * @return 0 on success, -1 otherwise - */ -int socket_base_connect(int socket, sockaddr6_t *addr, - socklen_t addrlen); - -/** - * Receives data through socket *s* and saves it in buffer *buf*. Roughly - * identical to POSIX's recv(2). - * - * @param[in] s The ID of the socket to receive from. - * @param[in] buf Buffer to store received data in. - * @param[in] len Length of buffer. - * @param[in] flags Flags for possible later implementations (currently - * unused). - * - * @return Number of received bytes, -1 on error. - */ -int32_t socket_base_recv(int s, void *buf, uint32_t len, int flags); - -/** - * Receives data through socket *s* and saves it in buffer *buf*. The address - * of the sender is stored in *from*. Roughly identical to POSIX's - * recvfrom(2). - * - * @param[in] s The ID of the socket to receive from. - * @param[in] buf Buffer to store received data in. - * @param[in] len Length of buffer. - * @param[in] flags Flags for possible later implementations (currently - * unused). - * @param[in] from IPv6 Address of the data's sender. - * @param[in] fromlen Length of address in *from* in byte (always 16). - * - * @return Number of received bytes, -1 on error. - */ -int32_t socket_base_recvfrom(int s, void *buf, uint32_t len, int flags, - sockaddr6_t *from, socklen_t *fromlen); - -/** - * Sends data *buf* through socket *s*. Roughly identical to POSIX's - * send(2). - * - * @param[in] s The ID of the socket to send through. - * @param[in] buf Buffer to send the data from. - * @param[in] len Length of buffer. - * @param[in] flags Flags for possible later implementations (currently - * unused). - * - * @return Number of send bytes, -1 on error. - */ -int32_t socket_base_send(int s, const void *buf, uint32_t len, int flags); - -/** - * Sends data *buf* through socket *s* to foreign host with IPv6 address *addr*. - * Roughly identical to POSIX's send(2). - * - * @param[in] s The ID of the socket to send through. - * @param[in] buf Buffer to send the data from. - * @param[in] len Length of buffer. - * @param[in] flags Flags for possible later implementations (currently - * unused). - * @param[in] to IPv6 Address to send data to. - * @param[in] tolen Length of address in *to* in byte (always 16). - * - * @return Number of send bytes, -1 on error. - */ -int32_t socket_base_sendto(int s, const void *buf, uint32_t len, int flags, - sockaddr6_t *to, socklen_t tolen); - -/** - * Closes the socket *s* and removes it. - * - * @param[in] s The ID of the socket to close. - * - * @return 0 on success, -1 otherwise. - */ -int socket_base_close(int s); - -/** - * Assigns an IPv6 address *addr* to the socket *s*. Roughly identical to - * POSIX's bind(2). - * - * @param[in] s The ID of the socket. - * @param[in] addr The IPv6 address to bind to. - * @param[in] addrlen Length of address in byte (always 16) - * - * @return 0 on success, -1 otherwise. - */ -int socket_base_bind(int s, sockaddr6_t *addr, int addrlen); - -/** - * Marks socket *s* as an passive socket, that listens for incoming messages. - * Roughly identical to POSIX's listen(2). - * - * @param[in] s The ID of the socket. - * @param[in] backlog Not implemented yet, may be 0. - * - * @return 0 on success, -1 otherwise. - */ -int socket_base_listen(int s, int backlog); - -/** - * Blocks the current thread and waits for incoming communication on the listening - * socket *s*. Roughly identical to POSIX's - * accept(2). - * - * @param[in] s The ID of the socket. - * @param[in] addr The IPv6 address of the peer socket, or NULL if not - * needed (not implemented yet). - * @param[in] addrlen The length of *addr*, or NULL if not needed. - * - * @return New socket ID for communication. -1 on error. - */ -int socket_base_accept(int s, sockaddr6_t *addr, socklen_t *addrlen); - -/** - * Outputs a list of all open sockets to stdout. Information includes its - * creation parameters, local and foreign address and ports, it's ID and the - * PIDs of the send and receive thread. - */ -void socket_base_print_sockets(void); - -#ifdef __cplusplus -} -#endif - -/** - * @} - */ -#endif /* SOCKET_BASE_SOCKET_H */ diff --git a/sys/net/include/socket_base/types.h b/sys/net/include/socket_base/types.h deleted file mode 100644 index b7f51263de..0000000000 --- a/sys/net/include/socket_base/types.h +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Transport Layer types header - * - * Copyright (C) 2013 INRIA. - * - * 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 transport_layer - * @{ - * @file - * @brief Transport Layer types - * @author Oliver Gesch - * @author Martine Lenders - */ -#ifndef SOCKET_BASE_TYPES_H_ -#define SOCKET_BASE_TYPES_H_ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * UDP packet header length - */ -#define UDP_HDR_LEN 8 - -/** - * TCP packet header length - */ -#define TCP_HDR_LEN 20 - -/** - * UDP packet header - * - * @see RFC 768 - */ -typedef struct __attribute__((packed)) { - uint16_t src_port; ///< source port - uint16_t dst_port; ///< destination port - uint16_t length; ///< payload length - /** - * internet checksum - * - * @see RFC 1071 - */ - uint16_t checksum; -} udp_hdr_t; - -/** - * TCP packet header - * - * @see RFC 793 - */ -typedef struct __attribute__((packed)) { - uint16_t src_port; ///< source port - uint16_t dst_port; ///< destination port - uint32_t seq_nr; ///< sequence number - uint32_t ack_nr; ///< acknowledgement number - unsigned flag_ns :1; ///< ECN-nonce concealment protection (since RFC 3540). - unsigned reserved :3; ///< for future use - set to zero - unsigned data_offset :4; - uint8_t reserved_flags; ///< TODO: break this down into another bitfield: flag_fin, flag_syn, etc - uint16_t window; ///< receiver window - /** - * internet checksum - * - * @see RFC 1071 - */ - uint16_t checksum; - uint16_t urg_pointer; ///< urgent pointer -} tcp_hdr_t; - -#ifdef __cplusplus -} -#endif - -/** - * @} - */ - -#endif /* SOCKET_BASE_TYPES_H_ */ diff --git a/sys/net/include/tcp.h b/sys/net/include/tcp.h deleted file mode 100644 index e32ad0bf54..0000000000 --- a/sys/net/include/tcp.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2013, 2014 INRIA. - * - * 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. - */ - -/** - * @defgroup tcp TCP implementation - * @ingroup net - * @brief This module implements the TCP transport layer protocol. - * This includes an (experimental) 6LoWPAN TCP header ompression. - * @see - * RFC draft-aayadi-6lowpan-tcphc-01 - TCP header compression for - * 6LoWPAN - * - * @{ - * @file - * @brief tcp functions - * @author Oliver Gesch - * @author Martine Lenders - * @author Cenk GündoÄŸan - */ - -#ifndef TCP_H -#define TCP_H - -#include "socket_base/in.h" -#include "socket_base/socket.h" -#include "socket_base/types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Initializes tcp. - * - * @return 0 on success, other else. - */ -int tcp_init_transport_layer(void); - -#ifdef __cplusplus -} -#endif - -#endif /* TCP_H */ -/** @} */ diff --git a/sys/net/include/udp.h b/sys/net/include/udp.h deleted file mode 100644 index 22c264c61a..0000000000 --- a/sys/net/include/udp.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2013, 2014 INRIA. - * - * 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. - */ - -/** - * @defgroup udp UDP implementation - * @ingroup net - * @brief This module implements the transport layer protocol UDP. - * This includes 6LoWPAN UDP header compression. - * @see - * RFC 6282 - Compression Format for IPv6 Datagrams over - * IEEE 802.15.4-Based Networks - UDP Header Compression - * - * @{ - * @file - * @brief udp functions - * @author Oliver Gesch - * @author Martine Lenders - * @author Cenk GündoÄŸan - */ - -#ifndef UDP_H -#define UDP_H - -#include "socket_base/in.h" -#include "socket_base/socket.h" -#include "socket_base/types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Initializes udp. - * - * @return 0 on success, other else. - */ -int udp_init_transport_layer(void); - -#ifdef __cplusplus -} -#endif - -#endif /* UDP_H */ -/** @} */ diff --git a/sys/net/link_layer/ieee802154/Makefile b/sys/net/link_layer/ieee802154/Makefile deleted file mode 100644 index 48422e909a..0000000000 --- a/sys/net/link_layer/ieee802154/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(RIOTBASE)/Makefile.base diff --git a/sys/net/link_layer/ieee802154/ieee802154_frame.c b/sys/net/link_layer/ieee802154/ieee802154_frame.c deleted file mode 100644 index 6a69519845..0000000000 --- a/sys/net/link_layer/ieee802154/ieee802154_frame.c +++ /dev/null @@ -1,304 +0,0 @@ -/** - * implementation for the IEEE 802.15.4 frame format - * - * Copyright (C) 2013 INRIA. - * - * 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 sixlowpan - * @{ - * @file - * @brief IEEE 802.14.4 framing operations - * @author Stephan Zeisberg - * @author Oliver Hahm - * @} - */ - -#include "ieee802154_frame.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -#define IEEE_802154_FCS_POLY (0x8408) /* x^16 + x^12 + x^5 + 1 for LSB first */ - -uint8_t ieee802154_hdr_ptr; -uint8_t ieee802154_payload_ptr; -uint16_t ieee802154_payload_len; - -uint8_t ieee802154_frame_init(ieee802154_frame_t *frame, uint8_t *buf) -{ - /* Frame Control Field - 802.15.4 - 2006 - 7.2.1.1 */ - uint8_t index = 0; - - buf[index] = (((frame->fcf.frame_type) & 0x07) | - ((frame->fcf.sec_enb << 3) & 0x08) | - ((frame->fcf.frame_pend << 4) & 0x10) | - ((frame->fcf.ack_req << 5) & 0x20) | - ((frame->fcf.panid_comp << 6) & 0x40)); - index++; - - buf[index] = (((frame->fcf.dest_addr_m << 2) & 0x0c) | - ((frame->fcf.frame_ver << 4) & 0x30) | - ((frame->fcf.src_addr_m << 6) & 0xc0)); - - index++; - - /* Sequence Number - 802.15.4 - 2006 - 7.2.1.2 */ - buf[index] = frame->seq_nr; - index++; - - /* Destination PAN Identifier - 802.15.4 - 2006 - 7.2.1.3 */ - if (frame->fcf.dest_addr_m == 0x02 || frame->fcf.dest_addr_m == 0x03) { - buf[index + 1] = ((frame->dest_pan_id >> 8) & 0xff); - buf[index] = (frame->dest_pan_id & 0xff); - } - - index += 2; - - /* Destination Address - 802.15.4 - 2006 - 7.2.1.4 */ - if (frame->fcf.dest_addr_m == 0x02) { - buf[index] = frame->dest_addr[1]; - buf[index + 1] = frame->dest_addr[0]; - index += 2; - } - else if (frame->fcf.dest_addr_m == 0x03) { - buf[index] = frame->dest_addr[7]; - buf[index + 1] = frame->dest_addr[6]; - buf[index + 2] = frame->dest_addr[5]; - buf[index + 3] = frame->dest_addr[4]; - buf[index + 4] = frame->dest_addr[3]; - buf[index + 5] = frame->dest_addr[2]; - buf[index + 6] = frame->dest_addr[1]; - buf[index + 7] = frame->dest_addr[0]; - index += 8; - } - - /* Source PAN Identifier - 802.15.4 - 2006 - 7.2.1.5 */ - if (!(frame->fcf.panid_comp & 0x01)) { - if (frame->fcf.src_addr_m == 0x02 || frame->fcf.src_addr_m == 0x03) { - buf[index + 1] = ((frame->src_pan_id >> 8) & 0xff); - buf[index] = (frame->src_pan_id & 0xff); - index += 2; - } - } - - /* Source Address field - 802.15.4 - 2006 - 7.2.1.6 */ - if (frame->fcf.src_addr_m == 0x02) { - buf[index] = frame->src_addr[1]; - buf[index + 1] = frame->src_addr[0]; - index += 2; - } - else if (frame->fcf.src_addr_m == 0x03) { - buf[index] = frame->src_addr[7]; - buf[index + 1] = frame->src_addr[6]; - buf[index + 2] = frame->src_addr[5]; - buf[index + 3] = frame->src_addr[4]; - buf[index + 4] = frame->src_addr[3]; - buf[index + 5] = frame->src_addr[2]; - buf[index + 6] = frame->src_addr[1]; - buf[index + 7] = frame->src_addr[0]; - index += 8; - } - -#if ENABLE_DEBUG - DEBUG("INFO: IEEE 802.15.4 header initialized:\n"); - - for (size_t i = 0; i < index; i++) { - printf("%02x ", buf[i]); - - if (!((i + 1) % 16) || i == index - 1) { - printf("\n"); - } - } - -#endif - - return index; -} - -/** 2 1 2 VAR 2 VAR - * ------------------------------------------- - * | FCF | DSN | DPID | DAD | SPID | SAD | - * ------------------------------------------- - */ -uint8_t ieee802154_frame_get_hdr_len(ieee802154_frame_t *frame) -{ - uint8_t len = 0; - - if (frame->fcf.dest_addr_m == 0x02) { - len += 2; - } - else if (frame->fcf.dest_addr_m == 0x03) { - len += 8; - } - - if (frame->fcf.src_addr_m == 0x02) { - len += 2; - } - else if (frame->fcf.src_addr_m == 0x03) { - len += 8; - } - - if ((frame->fcf.dest_addr_m == 0x02) || (frame->fcf.dest_addr_m == 0x03)) { - len += 2; - } - - if ((frame->fcf.src_addr_m == 0x02) || (frame->fcf.src_addr_m == 0x03)) { - len += 2; - } - - /* if src pan id == dest pan id set compression bit */ - if (frame->src_pan_id == frame->dest_pan_id) { - frame->fcf.panid_comp = 1; - len -= 2; - } - - /* (DPID + DAD + SPID + SAD) + (FCF + DSN) */ - return (len + 3); -} - -uint8_t ieee802154_frame_read(uint8_t *buf, ieee802154_frame_t *frame, - uint8_t len) -{ - uint8_t index = 0; - uint8_t hdrlen; - - frame->fcf.frame_type = (buf[index]) & 0x07; - frame->fcf.sec_enb = (buf[index] >> 3) & 0x01; - frame->fcf.frame_pend = (buf[index] >> 4) & 0x01; - frame->fcf.ack_req = (buf[index] >> 5) & 0x01; - frame->fcf.panid_comp = (buf[index] >> 6) & 0x01; - - index++; - - frame->fcf.dest_addr_m = (buf[index] >> 2) & 0x03; - frame->fcf.frame_ver = (buf[index] >> 4) & 0x03; - frame->fcf.src_addr_m = (buf[index] >> 6) & 0x03; - - index++; - - frame->seq_nr = buf[index]; - - index++; - - if(frame->fcf.dest_addr_m != 0) - { - frame->dest_pan_id = (((uint16_t)buf[index]) << 8) | buf[index + 1]; - index += 2; - } - - switch (frame->fcf.dest_addr_m) { - case (0): { - DEBUG("fcf.dest_addr_m: pan identifier/address fields empty\n"); - break; - } - - case (2): { - /* read address in little-endian order */ - frame->dest_addr[0] = buf[index]; - frame->dest_addr[1] = buf[index + 1]; - index += 2; - break; - } - - case (3): { - /* read address in network order */ - frame->dest_addr[7] = buf[index]; - frame->dest_addr[6] = buf[index + 1]; - frame->dest_addr[5] = buf[index + 2]; - frame->dest_addr[4] = buf[index + 3]; - frame->dest_addr[3] = buf[index + 4]; - frame->dest_addr[2] = buf[index + 5]; - frame->dest_addr[1] = buf[index + 6]; - frame->dest_addr[0] = buf[index + 7]; - index += 8; - break; - } - } - - if (!(frame->fcf.panid_comp == 1)) { - if(frame->fcf.src_addr_m != 0) - { - frame->src_pan_id = (((uint16_t)buf[index]) << 8) | buf[index + 1]; - index += 2; - } - } - - switch (frame->fcf.src_addr_m) { - case (0): { - DEBUG("fcf.src_addr_m: pan identifier/address fields empty\n"); - break; - } - - case (2): { - /* read address in little-endian order */ - frame->src_addr[0] = buf[index]; - frame->src_addr[1] = buf[index + 1]; - index += 2; - break; - } - - case (3): { - /* read address in network order */ - frame->src_addr[7] = buf[index]; - frame->src_addr[6] = buf[index + 1]; - frame->src_addr[5] = buf[index + 2]; - frame->src_addr[4] = buf[index + 3]; - frame->src_addr[3] = buf[index + 4]; - frame->src_addr[2] = buf[index + 5]; - frame->src_addr[1] = buf[index + 6]; - frame->src_addr[0] = buf[index + 7]; - index += 8; - break; - } - } - - frame->payload = (buf + index); - hdrlen = index; - frame->payload_len = (len - hdrlen - IEEE_802154_FCS_LEN); - - return hdrlen; -} - -/* crc with lsb first */ -uint16_t ieee802154_frame_get_fcs(const uint8_t *frame, uint8_t frame_len) -{ - uint16_t r = 0; - - for (uint8_t byte = 0; byte < frame_len; ++byte) { - r ^= frame[byte]; - - for (uint8_t bit = 8; bit > 0; --bit) { - if (r & 0x0001) { - r = (r >> 1) ^ IEEE_802154_FCS_POLY; - } - else { - r = (r >> 1); - } - } - } - - return r; -} - -void ieee802154_frame_print_fcf_frame(ieee802154_frame_t *frame) -{ - printf("frame type: %02x\n" - "security enabled: %02x\n" - "frame pending: %02x\n" - "ack requested: %02x\n" - "pan id compression: %02x\n" - "destination address mode: %02x\n" - "frame version: %02x\n" - "source address mode: %02x\n", - frame->fcf.frame_type, - frame->fcf.sec_enb, - frame->fcf.frame_pend, - frame->fcf.ack_req, - frame->fcf.panid_comp, - frame->fcf.dest_addr_m, - frame->fcf.frame_ver, - frame->fcf.src_addr_m); -} diff --git a/sys/net/link_layer/net_if/Makefile b/sys/net/link_layer/net_if/Makefile deleted file mode 100644 index 2cc42decfe..0000000000 --- a/sys/net/link_layer/net_if/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -INCLUDES += -I$(RIOTBASE)/drivers/include \ - -I$(RIOTBASE)/drivers/cc110x_legacy/include \ - -I$(RIOTBASE)/sys/net/include -include $(RIOTBASE)/Makefile.base diff --git a/sys/net/link_layer/net_if/net_if.c b/sys/net/link_layer/net_if/net_if.c deleted file mode 100644 index e26e3cc27c..0000000000 --- a/sys/net/link_layer/net_if/net_if.c +++ /dev/null @@ -1,545 +0,0 @@ -/* - * Copyright (C) 2013 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 net_if - * @{ - * @file - * @author Martine Lenders - */ -#include - -#include "clist.h" -#include "ieee802154_frame.h" -#include "msg.h" -#include "mutex.h" -#include "transceiver.h" - -#include "net_if.h" -#include "net_help.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -#if ENABLE_DEBUG -/* For PRIu16 etc. */ -#include -#endif - -net_if_t interfaces[NET_IF_MAX]; - -#if ENABLE_DEBUG -void print_addr_hex(net_if_addr_t *addr) -{ - int i; - DEBUG("0x"); - - for (i = 0; i < addr->addr_len; i++) { - DEBUG("%02x", ((char *)addr->addr_data)[i]); - } - - DEBUG("\n"); -} -#endif - -uint8_t net_if_hex_to_dec(char c) -{ - if (c >= '0' && c <= '9') { - return (uint8_t)(c - '0'); - } - else if (c >= 'A' && c <= 'F') { - return (uint8_t)(c - 55); - } - else if (c >= 'a' && c <= 'f') { - return (uint8_t)(c - 87); - } - else { - return 0xff; - } -} - -void net_if_hex_to_eui64(net_if_eui64_t *eui64, const char *eui64_str) -{ - int i; - const char *eui64_rev = &eui64_str[strlen(eui64_str) - 1]; - eui64->uint64 = 0; - - for (i = 7; i >= 0 || eui64_rev >= eui64_str; i--) { - uint8_t digit; - - while ((digit = net_if_hex_to_dec(*eui64_rev)) == 0xFF) { - if (--eui64_rev < eui64_str) { - return; - } - } - - eui64->uint8[i] = digit; - eui64_rev--; - - while ((digit = net_if_hex_to_dec(*eui64_rev)) == 0xFF) { - if (--eui64_rev < eui64_str) { - return; - } - } - - eui64->uint8[i] |= digit << 4; - eui64_rev--; - } -} - -void net_if_init(void) -{ - memset(&interfaces, 0, sizeof(net_if_t) * NET_IF_MAX); -} - -int net_if_init_interface(uint8_t protocols, transceiver_type_t transceivers) -{ - int i; - - if (transceivers == 0) { - DEBUG("Interface initialization: Precondition not met.\n"); - return -1; - } - - for (i = 0; i < NET_IF_MAX; i++) { - if (!interfaces[i].initialized) { - interfaces[i].initialized = 1; - interfaces[i].protocols = protocols; - mutex_init(&interfaces[i].address_buffer_mutex); - interfaces[i].transceivers = transceivers; - DEBUG("Initialized interface %d for protocols %d on transceivers 0x%x\n", - i, protocols, transceivers); - return i; - } - } - - DEBUG("Interface buffer full.\n"); - return -1; -} - -int net_if_iter_interfaces(int start) -{ - if (start == NET_IF_MAX - 1) { - return -1; - } - - start++; - - while (start < NET_IF_MAX && !interfaces[start].initialized) { - start++; - } - - return start; -} - -int net_if_add_address(int if_id, net_if_addr_t *addr) -{ - if (!addr || !addr->addr_data) { - DEBUG("Address addition: Precondition not met.\n"); - return 0; - } - - if (if_id < 0 || if_id >= NET_IF_MAX || !interfaces[if_id].initialized) { - DEBUG("Address addition: No interface initialized with ID %d.\n", if_id); - return 0; - } - - mutex_lock(&interfaces[if_id].address_buffer_mutex); - - interfaces[if_id].protocols |= addr->addr_protocol; - - clist_add((clist_node_t **)&interfaces[if_id].addresses, - (clist_node_t *)addr); - - mutex_unlock(&interfaces[if_id].address_buffer_mutex); - - return 1; -} - -int net_if_del_address(int if_id, net_if_addr_t *addr) -{ - if (!addr || !addr->addr_data) { - DEBUG("Address deletion: Precondition not met.\n"); - return 0; - } - - if (if_id < 0 || if_id >= NET_IF_MAX || !interfaces[if_id].initialized) { - DEBUG("Address deletion: No interface initialized with ID %d.\n", if_id); - return 0; - } - - mutex_lock(&interfaces[if_id].address_buffer_mutex); - - clist_remove((clist_node_t **)&interfaces[if_id].addresses, - (clist_node_t *)addr); - - mutex_unlock(&interfaces[if_id].address_buffer_mutex); - - return 1; -} - -net_if_addr_t *net_if_iter_addresses(int if_id, net_if_addr_t **addr) -{ - if (if_id < 0 || if_id >= NET_IF_MAX || !interfaces[if_id].initialized) { - DEBUG("Address iteration: No interface initialized with ID %d.\n", if_id); - return NULL; - } - - if (*addr == NULL) { - *addr = interfaces[if_id].addresses; - return *addr; - } - - clist_advance((clist_node_t **)addr); - - if (*addr == interfaces[if_id].addresses) { - *addr = NULL; - } - - return *addr; -} - -net_if_l3p_t net_if_get_l3p_types(int if_id) -{ - net_if_l3p_t protocols; - - if (if_id < 0 || if_id >= NET_IF_MAX || !interfaces[if_id].initialized) { - DEBUG("Get L3 protocols: No interface initialized with ID %d.\n", if_id); - return NET_IF_L3P_FAILURE; - } - - mutex_lock(&interfaces[if_id].address_buffer_mutex); - - protocols = interfaces[if_id].protocols; - - mutex_unlock(&interfaces[if_id].address_buffer_mutex); - - return protocols; -} - -int net_if_add_l3p_types(int if_id, net_if_l3p_t protocols) -{ - if (if_id < 0 || if_id >= NET_IF_MAX || !interfaces[if_id].initialized) { - DEBUG("Add L3 protocols: No interface initialized with ID %d.\n", if_id); - return 0; - } - - interfaces[if_id].protocols |= protocols; - - return 1; -} - -int net_if_del_l3p_types(int if_id, net_if_l3p_t protocols) -{ - net_if_addr_t *addr_ptr = NULL; - - if (if_id < 0 || if_id >= NET_IF_MAX || !interfaces[if_id].initialized) { - DEBUG("Remove L3 protocols: No interface initialized with ID %d.\n", if_id); - return 0; - } - - while (net_if_iter_addresses(if_id, &addr_ptr)) { - if (addr_ptr->addr_protocol & protocols) { - net_if_del_address(if_id, addr_ptr); - addr_ptr = NULL; - } - } - - interfaces[if_id].protocols &= ~protocols; - - return 1; -} - -uint32_t net_if_transceiver_get_set_handler(int if_id, uint16_t op_type, - void *data) -{ - DEBUG("net_if_transceiver_get_set_handler: if_id = %d, op_type = %d, data = %p\n", - if_id, op_type, data); - msg_t msg; - transceiver_command_t tcmd; - - tcmd.transceivers = interfaces[if_id].transceivers; - tcmd.data = (char *)data; - msg.content.ptr = (char *)&tcmd; - msg.type = op_type; - msg_send_receive(&msg, &msg, transceiver_pid); - - return msg.content.value; -} - -int net_if_send_packet_broadcast(net_if_trans_addr_m_t preferred_dest_mode, - const void *payload, size_t payload_len) -{ - int if_id = -1; - int res = 0, res_prev = 0; - - while ((if_id = net_if_iter_interfaces(if_id)) >= 0) { - if (interfaces[if_id].transceivers & (TRANSCEIVER_CC1100 | TRANSCEIVER_NATIVE)) { - res = net_if_send_packet(if_id, 0, - payload, payload_len); - } - else if (preferred_dest_mode == NET_IF_TRANS_ADDR_M_SHORT) { - res = net_if_send_packet(if_id, IEEE_802154_SHORT_MCAST_ADDR, - payload, payload_len); - } - else { - net_if_eui64_t mcast_addr = IEEE_802154_LONG_MCAST_ADDR; - res = net_if_send_packet_long(if_id, &mcast_addr, payload, - payload_len); - } - - if (res_prev != 0) { - if (res != res_prev) { - return -1; - } - } - else { - if (res == 0) { - break; - } - } - - res_prev = res; - } - - return res; -} - -int net_if_send_packet(int if_id, uint16_t target, const void *payload, - size_t payload_len) -{ - DEBUG("net_if_send_packet: if_id = %d, target = %d, payload = %p, " - "payload_len = %d\n", if_id, target, payload, payload_len); - uint32_t response; - - if (if_id < 0 || if_id >= NET_IF_MAX || !interfaces[if_id].initialized) { - DEBUG("Send packet: No interface initialized with ID %d.\n", if_id); - return -1; - } - - if (interfaces[if_id].transceivers & (TRANSCEIVER_CC2420 | TRANSCEIVER_AT86RF231 | TRANSCEIVER_MC1322X)) { - ieee802154_packet_t p; - - memset(&p, 0, sizeof(ieee802154_packet_t)); - - p.frame.payload = (uint8_t *)payload; - p.frame.payload_len = (uint8_t)payload_len; - p.frame.fcf.src_addr_m = (uint8_t)interfaces[if_id].trans_src_addr_m; - p.frame.fcf.dest_addr_m = IEEE_802154_SHORT_ADDR_M; - p.frame.fcf.ack_req = 0; - p.frame.fcf.sec_enb = 0; - p.frame.fcf.frame_type = IEEE_802154_DATA_FRAME; - p.frame.fcf.frame_pend = 0; - - p.frame.dest_pan_id = net_if_get_pan_id(if_id); - uint16_t target_h = NTOHS(target); - memcpy(p.frame.dest_addr, &target_h, 2); - response = net_if_transceiver_get_set_handler(if_id, SND_PKT, (void *)&p); - } - else { - radio_packet_t p; - memset(&p, 0, sizeof(radio_packet_t)); - p.data = (uint8_t *) payload; - p.length = payload_len; - p.dst = target; - response = net_if_transceiver_get_set_handler(if_id, SND_PKT, (void *)&p); - } - - - return (response > payload_len) ? (int)payload_len : (int)response; -} - -int net_if_send_packet_long(int if_id, net_if_eui64_t *target, - const void *payload, size_t payload_len) -{ - DEBUG("net_if_send_packet: if_id = %d, target = %016" PRIx64 ", " - "payload = %p, payload_len = %d\n", if_id, NTOHLL(target->uint64), payload, - payload_len); - uint32_t response; - - if (if_id < 0 || if_id >= NET_IF_MAX || !interfaces[if_id].initialized) { - DEBUG("Send packet: No interface initialized with ID %d.\n", if_id); - return -1; - } - - if (interfaces[if_id].transceivers & (TRANSCEIVER_CC2420 | - TRANSCEIVER_AT86RF231 | - TRANSCEIVER_MC1322X)) { - ieee802154_packet_t p; - memset(&p, 0, sizeof(ieee802154_packet_t)); - p.frame.payload = (uint8_t *)payload; - p.frame.payload_len = (uint8_t)payload_len; - p.frame.fcf.src_addr_m = (uint8_t)interfaces[if_id].trans_src_addr_m; - p.frame.fcf.dest_addr_m = IEEE_802154_LONG_ADDR_M; - p.frame.fcf.ack_req = 0; - p.frame.fcf.sec_enb = 0; - p.frame.fcf.frame_type = IEEE_802154_DATA_FRAME; - p.frame.fcf.frame_pend = 0; - p.frame.dest_pan_id = net_if_get_pan_id(if_id); - uint64_t target_h = NTOHLL(target->uint64); - memcpy(p.frame.dest_addr, &target_h, 8); - response = net_if_transceiver_get_set_handler(if_id, SND_PKT, (void *)&p); - } - else { - radio_packet_t p; - memset(&p, 0, sizeof(radio_packet_t)); - p.data = (uint8_t *) payload; - p.length = payload_len; - p.dst = NTOHS(target->uint16[3]); - response = net_if_transceiver_get_set_handler(if_id, SND_PKT, (void *)&p); - } - - - return (response > payload_len) ? (int)payload_len : (int)response; -} - -int net_if_register(int if_id, kernel_pid_t pid) -{ - if (if_id < 0 || if_id >= NET_IF_MAX || !interfaces[if_id].initialized) { - DEBUG("Register thread: No interface initialized with ID %d.\n", if_id); - return 0; - } - - return (int)transceiver_register(interfaces[if_id].transceivers, pid); -} - -int net_if_get_eui64(net_if_eui64_t *eui64, int if_id, int force_generation) -{ - uint64_t tmp; - - if (if_id < 0 || if_id >= NET_IF_MAX || !interfaces[if_id].initialized) { - DEBUG("Get EUI-64: No interface initialized with ID %d.\n", if_id); - return 0; - } - - if (eui64 == NULL) { - DEBUG("Get EUI-64: parameter eui64 is a NULL pointer.\n"); - return 0; - } - - net_if_transceiver_get_set_handler(if_id, GET_LONG_ADDR, &tmp); - - eui64->uint64 = HTONLL(tmp); - - if (eui64->uint64 == 0 || force_generation) { - uint16_t hwaddr = net_if_get_hardware_address(if_id); - - if (hwaddr == 0) { - return 0; - } - - /* RFC 6282 Section 3.2.2 / RFC 2464 Section 4 */ - /* Since this is a short address, which is never globally unique, we set - * the local/universal bit to 1. */ - eui64->uint32[0] = HTONL(0x020000ff); - eui64->uint16[2] = HTONS(0xfe00); - eui64->uint16[3] = HTONS(hwaddr); - } - - return 1; -} - -int net_if_set_eui64(int if_id, net_if_eui64_t *eui64) -{ - if (eui64 == NULL) { - return 0; - } - - uint64_t tmp = NTOHLL(eui64->uint64); - - if (if_id < 0 || if_id >= NET_IF_MAX || !interfaces[if_id].initialized) { - DEBUG("Set EUI-64: No interface initialized with ID %d.\n", if_id); - return 0; - } - - net_if_transceiver_get_set_handler(if_id, SET_LONG_ADDR, (void *) &tmp); - - return eui64->uint64 != 0; -} - -uint16_t net_if_get_hardware_address(int if_id) -{ - uint16_t addr; - - if (if_id < 0 || if_id >= NET_IF_MAX || !interfaces[if_id].initialized) { - DEBUG("Get hardware address: No interface initialized with ID %d.\n", if_id); - return 0; - } - - net_if_transceiver_get_set_handler(if_id, GET_ADDRESS, &addr); - return addr; -} - -uint16_t net_if_set_hardware_address(int if_id, uint16_t addr) -{ - if (if_id < 0 || if_id >= NET_IF_MAX || !interfaces[if_id].initialized) { - DEBUG("Set hardware address: No interface initialized with ID %d.\n", if_id); - return 0; - } - - net_if_transceiver_get_set_handler(if_id, SET_ADDRESS, &addr); - return addr; -} - -int32_t net_if_get_channel(int if_id) -{ - int32_t channel; - - if (if_id < 0 || if_id >= NET_IF_MAX || !interfaces[if_id].initialized) { - DEBUG("Get channel: No interface initialized with ID %d.\n", if_id); - return -1; - } - - net_if_transceiver_get_set_handler(if_id, GET_CHANNEL, &channel); - return channel; -} - -int32_t net_if_set_channel(int if_id, uint16_t channel) -{ - if (if_id < 0 || if_id >= NET_IF_MAX || !interfaces[if_id].initialized) { - DEBUG("Set channel: No interface initialized with ID %d.\n", if_id); - return -1; - } - - net_if_transceiver_get_set_handler(if_id, SET_CHANNEL, &channel); - return channel; -} - -int32_t net_if_get_pan_id(int if_id) -{ - int32_t pan_id; - - if (if_id < 0 || if_id >= NET_IF_MAX || !interfaces[if_id].initialized) { - DEBUG("Get PAN ID: No interface initialized with ID %d.\n", if_id); - return -1; - } - - net_if_transceiver_get_set_handler(if_id, GET_PAN, &pan_id); - if (pan_id < 0) { - return 0; - } - else { - return pan_id; - } - -} - -int32_t net_if_set_pan_id(int if_id, uint16_t pan_id) -{ - if (if_id < 0 || if_id >= NET_IF_MAX || !interfaces[if_id].initialized) { - DEBUG("Set PAN ID: No interface initialized with ID %d.\n", if_id); - return -1; - } - - net_if_transceiver_get_set_handler(if_id, SET_PAN, &pan_id); - return pan_id; -} - -/** - * @} - */ diff --git a/sys/net/link_layer/ping/Makefile b/sys/net/link_layer/ping/Makefile deleted file mode 100644 index 9e5ec0eaca..0000000000 --- a/sys/net/link_layer/ping/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -MODULE := l2_ping - -include $(RIOTBASE)/Makefile.base diff --git a/sys/net/link_layer/ping/ping.c b/sys/net/link_layer/ping/ping.c deleted file mode 100644 index 78b67c6c7b..0000000000 --- a/sys/net/link_layer/ping/ping.c +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright (C) 2013, Igor Merkulow - * Copyright (C) 2014, Oliver Hahm - * - * 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. - */ - -/** - * @file - * @author Igor Merkulow - * @author Oliver Hahm - * - */ - -#include -#include -#include - -#include "thread.h" -#include "msg.h" -#include "mutex.h" - -#include "transceiver.h" -#include "radio/types.h" -#include "vtimer.h" -#include "timex.h" -#include "l2_ping.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -/*--------------------------------------------------------------------------------------*/ -/* interal defines */ -#define RCV_BUFFER_SIZE (64) -#define RADIO_STACK_SIZE (THREAD_STACKSIZE_DEFAULT) -#define MAX_PROB_STATS (64) - -/* internal prototypes */ -/* link layer send function for l2_pings */ -static int8_t send_l2_packet(radio_address_t dst, l2_ping_type_t type, uint16_t seq, const char *payload, uint8_t payload_len); -/* handler for incoming packets from transceiver */ -static void *l2_pkt_handler(void *unused); -/* handles l2 ping requests */ -static void ping_handler(radio_address_t addr, uint16_t seq); -/* handles l2 pong responses */ -static void pong_handler(void); -/* handle l2 probes */ -static void probe_handler(radio_address_t src); -/* calculates the round trip time for a ping-pong exchange */ -static void calc_rtt(void); - -/* internal buffers and variables */ -static char l2_pkt_handler_stack_buffer[RADIO_STACK_SIZE]; -static msg_t msg_q[RCV_BUFFER_SIZE]; - -#ifndef DISABLE_PROB_STATS -static l2_probe_stat_entry_t probe_stats[MAX_PROB_STATS]; -#endif - -static timex_t start, end, rtt_sum; -static uint8_t ping_sent; -static struct mutex_t ping_sender_mutex; -l2_ping_stats_t l2_ping_stats; - -/*--------------------------------------------------------------------------------------*/ -/* public interface functions */ -void l2_ping_init(void) -{ - mutex_init(&ping_sender_mutex); - kernel_pid_t l2_pkt_handler_pid = thread_create(l2_pkt_handler_stack_buffer, - RADIO_STACK_SIZE, - THREAD_PRIORITY_MAIN - 2, - CREATE_STACKTEST, - l2_pkt_handler, NULL, - "l2_pkt_handler"); - uint16_t transceivers = TRANSCEIVER_DEFAULT; - -#ifndef MODULE_NET_IF - transceiver_init(transceivers); - (void) transceiver_start(); -#endif - transceiver_register(transceivers, l2_pkt_handler_pid); -} - -void l2_ping(radio_address_t addr, uint16_t count, uint32_t interval, - const char *payload, uint8_t payload_len, uint8_t probe_only) -{ - l2_ping_type_t pt; - - probe_only ? (pt = L2_PROBE) : (pt = L2_PING); - - if (!interval) { - interval = L2_PING_DEFAULT_INTERVAL; - } - - mutex_lock(&ping_sender_mutex); - l2_ping_stats.dst = addr; - l2_ping_stats.ping_count = 0; - l2_ping_stats.pong_count = 0; - l2_ping_stats.last_rtt = timex_set(0, 0); - l2_ping_stats.avg_rtt = timex_set(0, 0); - l2_ping_stats.max_rtt = timex_set(0, 0); - l2_ping_stats.min_rtt = timex_set(UINT32_MAX, UINT32_MAX); - - for (unsigned i = 1; (count == 0) || (i <= count); i++) { - vtimer_now(&start); - - if (send_l2_packet(addr, pt, i, payload, payload_len)) { - ping_sent = 1; - l2_ping_stats.ping_count++; - } - if ((!count) || (i <= count)) { - vtimer_usleep(interval); - } - } - mutex_unlock(&ping_sender_mutex); -} - -void l2_probe_stats(l2_probe_stat_entry_t *l2_probe_stats[], uint16_t *count) -{ - unsigned i; - *l2_probe_stats = probe_stats; - for (i = 0; i < MAX_PROB_STATS; i++) { - if (!(probe_stats[i]).src) { - break; - } - } - *count = i; -} - -/*--------------------------------------------------------------------------------------*/ -/* internal functions */ -static void *l2_pkt_handler(void *unused) -{ - (void) unused; - - msg_t m; - radio_packet_t *p; - l2_ping_payload_t *pp; - - msg_init_queue(msg_q, RCV_BUFFER_SIZE); - - while (1) { - msg_receive(&m); - - if (m.type == PKT_PENDING) { - vtimer_now(&end); - p = (radio_packet_t *) m.content.ptr; - pp = (l2_ping_payload_t *) p->data; - - if ((pp->type & L2_PAYLOAD_TYPE) == L2_PAYLOAD_PING) { - DEBUGF("INFO: received l2_ping_packet number %d from %d with payload(%d) %.*s.\n", - pp->seq, p->src, pp->payload_len, pp->payload_len, pp->payload); - switch (pp->type & L2_PING_TYPE) { - case L2_PING: - ping_handler(p->src, pp->seq); - break; - case L2_PONG: - pong_handler(); - break; - case L2_PROBE: - probe_handler(p->src); - break; - default: - DEBUGF("ERROR: Unknown L2 PING type\n"); - } - } - else { - DEBUGF("WARN: no L2 ping packet, type is %02X\n", pp->type); - } - - p->processing--; - } - else if (m.type == ENOBUFFER) { - DEBUGF("ERROR: Transceiver buffer full\n"); - } - else { - DEBUGF("ERROR: Unknown messagereceived\n"); - } - } - - return NULL; -} - -static void calc_rtt(void) -{ - timex_t rtt = timex_sub(end, start); - rtt_sum = timex_add(rtt_sum, rtt); - - l2_ping_stats.last_rtt = rtt; - l2_ping_stats.avg_rtt = timex_from_uint64(timex_uint64(rtt_sum) / l2_ping_stats.pong_count); - if (timex_cmp(rtt, l2_ping_stats.max_rtt) > 0) { - l2_ping_stats.max_rtt = rtt; - } - if (timex_cmp(rtt, l2_ping_stats.min_rtt) < 0) { - l2_ping_stats.min_rtt = rtt; - } -} - -static int8_t send_l2_packet(radio_address_t dst, l2_ping_type_t type, uint16_t seq, const char *payload, uint8_t payload_len) -{ - radio_packet_t p; - l2_ping_payload_t pp; - - if (payload_len > L2_PING_PAYLOAD_SIZE) { - DEBUGF("ERROR: payload too big for l2 ping packet of type %u\n", type); - return -1; - } - - transceiver_command_t tcmd; - tcmd.transceivers = TRANSCEIVER_DEFAULT; - tcmd.data = &p; - - pp.type = type | L2_PAYLOAD_PING; - pp.seq = seq; - - memset(pp.payload, 0, L2_PING_PAYLOAD_SIZE); - memcpy(pp.payload, payload, payload_len); - pp.payload_len = payload_len; - - p.data = (uint8_t*) &pp; - p.length = sizeof(pp); - p.dst = dst; - - msg_t mesg; - mesg.type = SND_PKT; - mesg.content.ptr = (char *) &tcmd; - - msg_send_receive(&mesg, &mesg, transceiver_pid); - int8_t response = mesg.content.value; - - if (response <= 0) { - DEBUGF("ERROR: sending L2 packet of type %x failed.\n", type); - } - - return response; -} - -static void ping_handler(radio_address_t addr, uint16_t seq) -{ - send_l2_packet(addr, L2_PONG, seq, NULL, 0); -} - -static void pong_handler(void) -{ - if (ping_sent) { - ping_sent = 0; - l2_ping_stats.pong_count++; - calc_rtt(); - } - else { - DEBUGF("ERROR: received pong without a sent ping\n"); - } -} - -static void probe_handler(radio_address_t src) -{ -#ifdef DISABLE_PROB_STATS - DEBUGF("WARN: L2 probe statistics are disabled, not handling probe packet.\n"); -#else - unsigned i; - for (i = 0; i < MAX_PROB_STATS; i++) { - /* found entry for this source address */ - if (probe_stats[i].src == src) { - probe_stats[i].count++; - return; - } - /* found empty entry */ - else if (!(probe_stats[i].src)) { - probe_stats[i].src = src; - probe_stats[i].count++; - return; - } - } - DEBUGF("ERROR: L2 probe statistics full! Probe data from %u not stored.\n", src); -#endif -} diff --git a/sys/net/link_layer/protocol-multiplex/Makefile b/sys/net/link_layer/protocol-multiplex/Makefile deleted file mode 100644 index c5126f06a4..0000000000 --- a/sys/net/link_layer/protocol-multiplex/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -MODULE = protocol_multiplex - -include $(RIOTBASE)/Makefile.base diff --git a/sys/net/link_layer/protocol-multiplex/protocol-multiplex.c b/sys/net/link_layer/protocol-multiplex/protocol-multiplex.c deleted file mode 100644 index b72db18296..0000000000 --- a/sys/net/link_layer/protocol-multiplex/protocol-multiplex.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2009-2010, Freie Universitaet Berlin (FUB). All rights reserved. - * - * 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. - */ - -/** - * @addtogroup net_mmstack - * @{ - */ - -/** - * @file - * @internal - * @brief Protocol handler multiplexing - * - * @author Thomas Hillebrandt - * @author Heiko Will - * @author Michael Baar - * @version $Revision: 1938 $ - * - * @note $Id: protocol-multiplex.c 1938 2010-03-02 12:14:29Z baar $ - */ - -#include -#include -#include "protocol-multiplex.h" - -//#define DEBUG -#ifdef DEBUG -#include -#define PRINTF(fmt,args...) printf("pm: " fmt "\n", ##args) -#else -#define PRINTF(...) -#endif - -/*---------------------------------------------------------------------------*/ -void pm_init_table(pm_table_t *table, uint8_t size, handler_entry_t *handler) -{ - table->size = size; - table->handler = handler; - memset(handler, 0, sizeof(handler_entry_t) * size); -} -/*---------------------------------------------------------------------------*/ -int pm_find_handler_index(const pm_table_t *table, protocol_t protocol, - unsigned int start) -{ - int i; - handler_entry_t *e = &table->handler[start]; - - for (i = start; i < table->size; i++, e++) { - if (e->protocol == protocol) { - return i; - } - } - - return -1; -} -/*---------------------------------------------------------------------------*/ -int pm_set_handler(const pm_table_t *table, protocol_t protocol, - packet_handler_t handler) -{ - /* Reject illegal values */ - if (protocol == 0 || handler == NULL) { - PRINTF("proto %u rejected", protocol); - return -1; - } - - /* Check if there is already a handler for given protocol */ - int index = pm_find_handler_index(table, protocol, 0); - - if (index >= 0) { - /* Two handlers for same protocol not allowed because only - * one gets called. This hasn't to be the last one who - * registered!*/ - PRINTF("proto %u handler found, reset", protocol); - table->handler[index].protocol = 0; - table->handler[index].handler = NULL; - } - - /* Find free position for handler (protocol value is 0) */ - index = pm_find_handler_index(table, 0, 0); - - /* Store handler if free index found */ - if (index >= 0) { - PRINTF("proto %u, set", protocol); - table->handler[index].protocol = protocol; - table->handler[index].handler = handler; - } - - /* Return result (-1 on error or no free index) */ - return index; -} -/*---------------------------------------------------------------------------*/ -void pm_remove_handler(const pm_table_t *table, protocol_t protocol, - packet_handler_t handler) -{ - int i; - - for (i = 0; i < table->size; i++) { - if (table->handler[i].protocol == protocol && table->handler[i].handler == handler) { - PRINTF("proto %u handler found, reset", protocol); - table->handler[i].protocol = 0; - table->handler[i].handler = NULL; - } - } -} -/*---------------------------------------------------------------------------*/ -int pm_invoke(const pm_table_t *table, protocol_t protocol, void *payload, - int payload_size, packet_info_t *packet_info) -{ - int index = 0; - - /* Reject illegal values */ - if (protocol == 0) { - return -1; - } - - if ((index = pm_find_handler_index(table, protocol, index)) != -1) { - PRINTF("proto %u, invoke", protocol); - table->handler[index].handler(payload, payload_size, packet_info); - } - else { - PRINTF("proto %u invoke failed (no handler)", protocol); - } - - return index; -} -/*---------------------------------------------------------------------------*/ -/** @} */ diff --git a/sys/net/network_layer/sixlowpan/Makefile b/sys/net/network_layer/sixlowpan/Makefile deleted file mode 100644 index 48422e909a..0000000000 --- a/sys/net/network_layer/sixlowpan/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(RIOTBASE)/Makefile.base diff --git a/sys/net/network_layer/sixlowpan/border/border.c b/sys/net/network_layer/sixlowpan/border/border.c deleted file mode 100644 index 8c9b912d42..0000000000 --- a/sys/net/network_layer/sixlowpan/border/border.c +++ /dev/null @@ -1,195 +0,0 @@ -/** - * 6lowpan border router implementation - * - * Copyright (C) 2013 INRIA. - * - * 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 sixlowpan - * @{ - * @file - * @brief constraint node implementation for a 6lowpan border router - * @author Martine Lenders - * @author Oliver Hahm - * @} - */ - -/* TODO: Put this in its own module */ -#include -#include -#include - -#include "mutex.h" -#include "thread.h" -#include "msg.h" -#include "posix_io.h" -#include "board_uart0.h" - -#include "ieee802154_frame.h" -#include "sixlowpan/error.h" -#include "bordermultiplex.h" -#include "flowcontrol.h" -#include "border.h" -#include "ip.h" -#include "icmp.h" -#include "serialnumber.h" - -#include "net_help.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -#define READER_STACK_SIZE (THREAD_STACKSIZE_DEFAULT) - -char serial_reader_stack[READER_STACK_SIZE]; -kernel_pid_t serial_reader_pid = KERNEL_PID_UNDEF; - -uint8_t serial_out_buf[BORDER_BUFFER_SIZE]; -uint8_t serial_in_buf[BORDER_BUFFER_SIZE]; - -ipv6_addr_t *abr_addr; - -uint8_t *get_serial_out_buffer(int offset) -{ - if (offset > BUFFER_SIZE) { - return NULL; - } - - return &(serial_out_buf[offset]); -} - -uint8_t *get_serial_in_buffer(int offset) -{ - if (offset > BUFFER_SIZE) { - return NULL; - } - - return &(serial_in_buf[offset]); -} - -kernel_pid_t border_get_serial_reader() -{ - return serial_reader_pid; -} - -void serial_reader_f(void) -{ - kernel_pid_t main_pid; - msg_t m; - border_packet_t *uart_buf; - - posix_open(uart0_handler_pid, 0); - - msg_receive(&m); - main_pid = m.sender_pid; - - while (1) { - posix_open(uart0_handler_pid, 0); - int bytes = readpacket(get_serial_in_buffer(0), BORDER_BUFFER_SIZE); - - if (bytes < 0) { - switch (bytes) { - case (-SIXLOWERROR_ARRAYFULL): { - printf("ERROR: Array was full\n"); - break; - } - - default: { - printf("ERROR: unknown\n"); - break; - } - } - - continue; - } - - uart_buf = (border_packet_t *)get_serial_in_buffer(0); - - if (uart_buf->empty == 0) { - if (uart_buf->type == BORDER_PACKET_CONF_TYPE) { - border_conf_header_t *conf_packet = (border_conf_header_t *)uart_buf; - - if (conf_packet->conftype == BORDER_CONF_SYN) { - m.content.ptr = (char *)conf_packet; - msg_send(&m, main_pid); - continue; - } - } - - flowcontrol_deliver_from_uart(uart_buf, bytes); - } - } -} - -int sixlowpan_lowpan_border_init(int if_id) -{ - ipv6_net_if_addr_t *addr = NULL; - uint8_t abr_addr_initialized = 0; - - serial_reader_pid = thread_create( - serial_reader_stack, READER_STACK_SIZE, - THREAD_PRIORITY_MAIN - 1, CREATE_STACKTEST, - serial_reader_f, "serial_reader"); - ip_process_pid = thread_create(ip_process_buf, IP_PROCESS_STACKSIZE, - THREAD_PRIORITY_MAIN - 1, CREATE_STACKTEST, - border_process_lowpan, - "border_process_lowpan"); - - if (ip_process_pid != KERNEL_PID_UNDEF) { - return 0; - } - - if (!sixlowpan_lowpan_init_interface(if_id)) { - return 0; - } - - while (net_if_iter_addresses(if_id, (net_if_addr_t **) &addr)) { - if (!ipv6_addr_is_multicast(addr->addr_data) && - !ipv6_addr_is_link_local(addr->addr_data) && - !ipv6_addr_is_loopback(addr->addr_data) && - !ipv6_addr_is_unique_local_unicast(addr->addr_data)) { - abr_addr_initialized = 1; - abr_addr = addr->addr_data; - break; - } - } - - if (!abr_addr_initialized) { - DEBUG("sixlowpan_lowpan_border_init(): A prefix must be initialized to" - "interface %d first", if_id); - return 0; - } - - ipv6_init_as_router(); - - return 1; -} - -void border_process_lowpan(void) -{ - msg_t m; - - while (1) { - msg_receive(&m); - ipv6_hdr_t *ipv6_buf = (ipv6_hdr_t *)m.content.ptr; - - if (ipv6_buf->nextheader == IPV6_PROTO_NUM_ICMPV6) { - icmpv6_hdr_t *icmp_buf = (icmpv6_hdr_t *)(((uint8_t *)ipv6_buf) + IPV6_HDR_LEN); - - if (icmp_buf->type == ICMPV6_TYPE_REDIRECT) { - continue; - } - - if (icmpv6_demultiplex(icmp_buf) == 0) { - continue; - } - - /* Here, other ICMPv6 message types for ND may follow. */ - } - - /* TODO: Bei ICMPv6-Paketen entsprechende LoWPAN-Optionen verarbeiten und entfernen */ - multiplex_send_ipv6_over_uart(ipv6_buf); - } -} diff --git a/sys/net/network_layer/sixlowpan/border/border.h b/sys/net/network_layer/sixlowpan/border/border.h deleted file mode 100644 index 66c5fbc308..0000000000 --- a/sys/net/network_layer/sixlowpan/border/border.h +++ /dev/null @@ -1,49 +0,0 @@ -/** - * 6lowpan border router prototypes - * - * Copyright (C) 2013 INRIA. - * - * 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 sixlowpan - * @{ - * @file - * @brief header for 6lowpan border router - * @author Martine Lenders - * @author Oliver Hahm - * @} - */ - -/* 6LoWPAN Border Router header file */ - -#ifndef _SIXLOWPAN_BORDER_H -#define _SIXLOWPAN_BORDER_H - -#include - -#include "mutex.h" -#include "transceiver.h" - -#include "ip.h" -#include "semaphore.h" - -#ifdef __cplusplus -extern "C" { -#endif - -extern ipv6_addr_t *abr_addr; - -kernel_pid_t border_get_serial_reader(void); - -uint8_t *get_serial_out_buffer(int offset); -uint8_t *get_serial_in_buffer(int offset); - -void border_process_lowpan(void); - -#ifdef __cplusplus -} -#endif - -#endif /* _SIXLOWPAN_BORDER_H*/ diff --git a/sys/net/network_layer/sixlowpan/border/bordermultiplex.c b/sys/net/network_layer/sixlowpan/border/bordermultiplex.c deleted file mode 100644 index 47131ba65c..0000000000 --- a/sys/net/network_layer/sixlowpan/border/bordermultiplex.c +++ /dev/null @@ -1,211 +0,0 @@ -/** - * 6lowpan border router multiplexer - * - * Copyright (C) 2013 INRIA. - * - * 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 sixlowpan - * @{ - * @file - * @brief multiplexiing border router information - * @author Martine Lenders - * @author Oliver Hahm - * @} - */ - -#include -#include - -#include "board_uart0.h" -#include "sixlowpan/error.h" - -#include "flowcontrol.h" -#include "lowpan.h" -#include "icmp.h" -#include "border.h" - -#include "bordermultiplex.h" - -#define END (0xC0) -#define ESC (0xDB) -#define END_ESC (0xDC) -#define ESC_ESC (0xDD) - -void demultiplex(border_packet_t *packet) -{ - switch (packet->type) { - case (BORDER_PACKET_RAW_TYPE): { - fputs(((char *)packet) + sizeof(border_packet_t), stdin); - break; - } - - case (BORDER_PACKET_L3_TYPE): { - border_l3_header_t *l3_header_buf = (border_l3_header_t *)packet; - - switch (l3_header_buf->ethertype) { - case (BORDER_ETHERTYPE_IPV6): { - ipv6_hdr_t *ipv6_buf = (ipv6_hdr_t *)(((unsigned char *)packet) + sizeof(border_l3_header_t)); - ipv6_send_packet(ipv6_buf, NULL); - break; - } - - default: - printf("ERROR: Unknown ethertype 0x%04x\n", l3_header_buf->ethertype); - break; - } - - break; - } - - case (BORDER_PACKET_CONF_TYPE): { - border_conf_header_t *conf_header_buf = (border_conf_header_t *)packet; - - switch (conf_header_buf->conftype) { - case (BORDER_CONF_CONTEXT): { - border_context_packet_t *context = (border_context_packet_t *)packet; - ipv6_addr_t target_addr; - ipv6_addr_set_all_nodes_addr(&target_addr); - mutex_lock(&lowpan_context_mutex); - lowpan_context_update( - context->context.cid, - &context->context.prefix, - context->context.length, - context->context.comp, - context->context.lifetime - ); - mutex_unlock(&lowpan_context_mutex); - abr_add_context(context->context.version, abr_addr, context->context.cid); - /* Send router advertisement */ - break; - } - - case (BORDER_CONF_IPADDR): { - //border_addr_packet_t *addr_packet = (border_addr_packet_t *)packet; - /* add address */ - break; - } - - default: - printf("ERROR: Unknown conftype %02x\n", conf_header_buf->conftype); - break; - } - - break; - } - - default: - printf("ERROR: Unknown border packet type %02x\n", packet->type); - break; - } -} - -void multiplex_send_ipv6_over_uart(ipv6_hdr_t *packet) -{ - border_l3_header_t *serial_buf; - - serial_buf = (border_l3_header_t *)get_serial_out_buffer(0); - serial_buf->empty = 0; - serial_buf->type = BORDER_PACKET_L3_TYPE; - serial_buf->ethertype = BORDER_ETHERTYPE_IPV6; - memcpy(get_serial_in_buffer(0) + sizeof(border_l3_header_t), packet, IPV6_HDR_LEN + packet->length); - - flowcontrol_send_over_uart((border_packet_t *) serial_buf, sizeof(border_l3_header_t)); -} - -void multiplex_send_addr_over_uart(ipv6_addr_t *addr) -{ - border_addr_packet_t *serial_buf; - - serial_buf = (border_addr_packet_t *)get_serial_in_buffer(0); - serial_buf->empty = 0; - serial_buf->type = BORDER_PACKET_CONF_TYPE; - serial_buf->conftype = BORDER_CONF_IPADDR; - memcpy(&serial_buf->addr, addr, sizeof(ipv6_addr_t)); - - flowcontrol_send_over_uart((border_packet_t *) serial_buf, sizeof(border_addr_packet_t)); -} - -int readpacket(uint8_t *packet_buf, size_t size) -{ - uint8_t *line_buf_ptr = packet_buf; - uint8_t esc = 0; - - while (1) { - uint8_t byte = uart0_readc(); - - if (byte == END) { - break; - } - - if ((size_t)(line_buf_ptr - packet_buf) >= size - 1) { - return -SIXLOWERROR_ARRAYFULL; - } - - if (esc) { - esc = 0; - - switch (byte) { - case (END_ESC): { - *line_buf_ptr++ = END; - continue; - } - - case (ESC_ESC): { - *line_buf_ptr++ = ESC; - continue; - } - - default: - continue; - } - } - - if (byte == ESC) { - esc = 1; - continue; - } - - *line_buf_ptr++ = byte; - } - - return (line_buf_ptr - packet_buf - 1); -} - -int writepacket(uint8_t *packet_buf, size_t size) -{ - uint8_t *byte_ptr = packet_buf; - - while ((size_t)(byte_ptr - packet_buf) < size) { - if ((size_t)(byte_ptr - packet_buf) > BORDER_BUFFER_SIZE) { - return -1; - } - - switch (*byte_ptr) { - case (END): { - *byte_ptr = END_ESC; - uart0_putc(ESC); - break; - } - - case (ESC): { - *byte_ptr = ESC_ESC; - uart0_putc(ESC); - break; - } - - default: { - break; - } - } - - uart0_putc(*byte_ptr); - byte_ptr++; - } - - uart0_putc(END); - - return (byte_ptr - packet_buf); -} diff --git a/sys/net/network_layer/sixlowpan/border/bordermultiplex.h b/sys/net/network_layer/sixlowpan/border/bordermultiplex.h deleted file mode 100644 index afbaee8f68..0000000000 --- a/sys/net/network_layer/sixlowpan/border/bordermultiplex.h +++ /dev/null @@ -1,100 +0,0 @@ -/** - * 6lowpan border router multiplexer - * - * Copyright (C) 2013 INRIA. - * - * 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 sixlowpan - * @{ - * @file - * @brief data structs for border router multiplexing - * @author Martine Lenders - * @author Oliver Hahm - * @} - */ - -#ifndef _SIXLOWPAN_BORDERMULTIPLEX_H -#define _SIXLOWPAN_BORDERMULTIPLEX_H - -#include -#include - -#include "ip.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* packet types of uart-packets */ -#define BORDER_PACKET_RAW_TYPE (0) -#define BORDER_PACKET_CONF_TYPE (2) -#define BORDER_PACKET_L3_TYPE (3) - -/* configuration types */ -#define BORDER_CONF_CONTEXT (2) -#define BORDER_CONF_IPADDR (3) - -/* ethertypes for L3 packets */ -#define BORDER_ETHERTYPE_IPV6 (0x86DD) - -typedef struct __attribute__((packed)) { - uint8_t empty; - uint8_t type; - uint8_t seq_num; -} border_packet_t; - -typedef struct __attribute__((packed)) { - uint8_t empty; - uint8_t type; - uint8_t seq_num; - uint16_t ethertype; -} border_l3_header_t; - -typedef struct __attribute__((packed)) { - uint8_t empty; - uint8_t type; - uint8_t seq_num; - uint8_t conftype; -} border_conf_header_t; - -typedef struct __attribute__((packed)) { - uint8_t empty; - uint8_t type; - uint8_t seq_num; - uint8_t conftype; - uint16_t version; - ipv6_addr_t addr; -} border_addr_packet_t; - -typedef struct __attribute__((packed)) { - uint8_t empty; - uint8_t type; - uint8_t seq_num; - uint8_t conftype; - struct border_context_t { - uint16_t version; - uint8_t cid; - ipv6_addr_t prefix; - uint8_t length; - uint8_t comp; - uint16_t lifetime; - } context; -} border_context_packet_t; - -#define BORDER_BUFFER_SIZE (sizeof(border_l3_header_t) + IPV6_MTU) - -void demultiplex(border_packet_t *packet); -void multiplex_send_ipv6_over_uart(ipv6_hdr_t *packet); -void multiplex_send_addr_over_uart(ipv6_addr_t *addr); - -int readpacket(uint8_t *packet_buf, size_t size); -int writepacket(uint8_t *packet_buf, size_t size); - -#ifdef __cplusplus -} -#endif - -#endif /* _SIXLOWPAN_BORDERMULTIPLEX_H*/ diff --git a/sys/net/network_layer/sixlowpan/border/flowcontrol.c b/sys/net/network_layer/sixlowpan/border/flowcontrol.c deleted file mode 100644 index 78280b0007..0000000000 --- a/sys/net/network_layer/sixlowpan/border/flowcontrol.c +++ /dev/null @@ -1,199 +0,0 @@ -/** - * 6lowpan border router flow control - * - * Copyright (C) 2013 INRIA. - * - * 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 sixlowpan - * @{ - * @file - * @brief flowcontrol for constraint node border router implementation - * @author Martine Lenders - * @author Oliver Hahm - * @} - */ - -#include -#include -#include -#include - -#include "vtimer.h" -#include "thread.h" -#include "semaphore.h" -#include "bordermultiplex.h" -#include "flowcontrol.h" - - -static int set_timeout(vtimer_t *timeout, timex_t val, void *args); -static void sending_slot(void); - -char sending_slot_stack[SENDING_SLOT_STACK_SIZE]; -kernel_pid_t sending_slot_pid = KERNEL_PID_UNDEF; - -flowcontrol_stat_t slwin_stat; -sem_t connection_established; -int16_t synack_seqnum = -1; - -ipv6_addr_t init_threeway_handshake(void) -{ - border_syn_packet_t *syn; - msg_t m; - m.content.ptr = NULL; - msg_send(&m, border_get_serial_reader()); - msg_receive(&m); - - syn = (border_syn_packet_t *)m.content.ptr; - border_conf_header_t *synack = (border_conf_header_t *)get_serial_out_buffer(0); - ipv6_addr_t addr; - memcpy(&addr, &(syn->addr), sizeof(ipv6_addr_t)); - - slwin_stat.next_exp = syn->next_seq_num; - slwin_stat.last_frame = syn->next_exp - 1; - slwin_stat.last_ack = slwin_stat.last_frame; - - synack->empty = 0; - synack->type = BORDER_PACKET_CONF_TYPE; - synack->conftype = BORDER_CONF_SYNACK; - - sending_slot_pid = thread_create(sending_slot_stack, SENDING_SLOT_STACK_SIZE, THREAD_PRIORITY_MAIN - 1, CREATE_SLEEPING, sending_slot, "sending slot"); - flowcontrol_send_over_uart((border_packet_t *)synack, sizeof(border_conf_header_t)); - - synack_seqnum = synack->seq_num; - - return addr; -} - -ipv6_addr_t flowcontrol_init(void) -{ - int i; - - sem_init(&slwin_stat.send_win_not_full, 0, BORDER_SWS); - - for (i = 0; i < BORDER_SWS; i++) { - slwin_stat.send_win[i].frame_len = 0; - } - - memset(&slwin_stat.send_win, 0, sizeof(struct send_slot) * BORDER_SWS); - - for (i = 0; i < BORDER_RWS; i++) { - slwin_stat.recv_win[i].received = 0; - slwin_stat.recv_win[i].frame_len = 0; - } - - memset(&slwin_stat.recv_win, 0, sizeof(struct recv_slot) * BORDER_RWS); - - return init_threeway_handshake(); -} - -static void sending_slot(void) -{ - while (1) { - msg_t m; - msg_receive(&m); - - uint8_t seq_num = *((uint8_t *) m.content.ptr); - struct send_slot *slot = &(slwin_stat.send_win[seq_num % BORDER_SWS]); - border_packet_t *tmp = (border_packet_t *)slot->frame; - - if (seq_num == tmp->seq_num) { - writepacket(slot->frame, slot->frame_len); - - if (set_timeout(&slot->timeout, timex_set(0, BORDER_SL_TIMEOUT), (void *)m.content.ptr) != 0) { - printf("ERROR: Error invoking timeout timer\n"); - } - } - } -} - -static int set_timeout(vtimer_t *timeout, timex_t val, void *args) -{ - vtimer_remove(timeout); - - timex_normalize(&val); - return vtimer_set_msg(timeout, val, sending_slot_pid, MSG_TIMER, args); -} - -static int in_window(uint8_t seq_num, uint8_t min, uint8_t max) -{ - uint8_t pos = seq_num - min; - uint8_t maxpos = max - min + 1; - return (pos < maxpos); -} - -void flowcontrol_send_over_uart(border_packet_t *packet, int len) -{ - struct send_slot *slot; - uint8_t args[] = {packet->seq_num}; - - sem_wait(&(slwin_stat.send_win_not_full)); - packet->seq_num = ++slwin_stat.last_frame; - slot = &(slwin_stat.send_win[packet->seq_num % BORDER_SWS]); - memcpy(slot->frame, (uint8_t *)packet, len); - slot->frame_len = len; - - if (set_timeout(&slot->timeout, timex_set(0, BORDER_SL_TIMEOUT * 1000), (void *)args) != 0) { - printf("ERROR: Error invoking timeout timer\n"); - return; - } - - writepacket((uint8_t *)packet, len); -} - -void send_ack(uint8_t seq_num) -{ - border_packet_t *packet = (border_packet_t *)get_serial_out_buffer(0); - packet->empty = 0; - packet->type = BORDER_PACKET_ACK_TYPE; - packet->seq_num = seq_num; - writepacket((uint8_t *)packet, sizeof(border_packet_t)); -} - -void flowcontrol_deliver_from_uart(border_packet_t *packet, int len) -{ - if (packet->type == BORDER_PACKET_ACK_TYPE) { - if (in_window(packet->seq_num, slwin_stat.last_ack + 1, slwin_stat.last_frame)) { - if (synack_seqnum == packet->seq_num) { - synack_seqnum = -1; - sem_post(&connection_established); - } - - do { - struct send_slot *slot; - slot = &(slwin_stat.send_win[++slwin_stat.last_ack % BORDER_SWS]); - vtimer_remove(&slot->timeout); - memset(&slot->frame, 0, BORDER_BUFFER_SIZE); - sem_post(&slwin_stat.send_win_not_full); - } - while (slwin_stat.last_ack != packet->seq_num); - } - } - else { - struct recv_slot *slot; - - slot = &(slwin_stat.recv_win[packet->seq_num % BORDER_RWS]); - - if (!in_window(packet->seq_num, - slwin_stat.next_exp, - slwin_stat.next_exp + BORDER_RWS - 1)) { - return; - } - - memcpy(slot->frame, (uint8_t *)packet, len); - slot->received = 1; - - if (packet->seq_num == slwin_stat.next_exp) { - while (slot->received) { - demultiplex((border_packet_t *)slot->frame); - memset(&slot->frame, 0, BORDER_BUFFER_SIZE); - slot->received = 0; - slot = &slwin_stat.recv_win[++(slwin_stat.next_exp) % BORDER_RWS]; - } - } - - send_ack(slwin_stat.next_exp - 1); - } -} diff --git a/sys/net/network_layer/sixlowpan/border/flowcontrol.h b/sys/net/network_layer/sixlowpan/border/flowcontrol.h deleted file mode 100644 index 63f62ebac6..0000000000 --- a/sys/net/network_layer/sixlowpan/border/flowcontrol.h +++ /dev/null @@ -1,85 +0,0 @@ -/** - * 6lowpan border router flow control - * - * Copyright (C) 2013 INRIA. - * - * 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 sixlowpan - * @{ - * @file - * @brief data structs for border router flowcontrol - * @author Martine Lenders - * @author Oliver Hahm - * @} - */ - -#ifndef _SIXLOWPAN_FLOWCONTROL_H -#define _SIXLOWPAN_FLOWCONTROL_H - -#include - -#include "vtimer.h" - -#include "semaphore.h" -#include "ip.h" -#include "border.h" -#include "bordermultiplex.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* packet types for flowcontrol */ -#define BORDER_PACKET_ACK_TYPE (1) - -/* configuration types for flowcontrol */ -#define BORDER_CONF_SYN (0) -#define BORDER_CONF_SYNACK (1) - -#define BORDER_SWS (1) -#define BORDER_RWS (1) -#define BORDER_SL_TIMEOUT (500) // microseconds, maybe smaller - -#define SENDING_SLOT_STACK_SIZE (THREAD_STACKSIZE_MINIMUM + 256) - -typedef struct { - /* Sender state */ - uint8_t last_ack; - uint8_t last_frame; - sem_t send_win_not_full; - struct send_slot { - vtimer_t timeout; - uint8_t frame[BORDER_BUFFER_SIZE]; - size_t frame_len; - } send_win[BORDER_SWS]; - - /* Receiver state */ - uint8_t next_exp; - struct recv_slot { - int8_t received; - uint8_t frame[BORDER_BUFFER_SIZE]; - size_t frame_len; - } recv_win[BORDER_RWS]; -} flowcontrol_stat_t; - -typedef struct __attribute__((packed)) { - uint8_t empty; - uint8_t type; - uint8_t next_seq_num; - uint8_t conftype; - uint8_t next_exp; - ipv6_addr_t addr; -} border_syn_packet_t; - -ipv6_addr_t flowcontrol_init(void); -void flowcontrol_send_over_uart(border_packet_t *packet, int len); -void flowcontrol_deliver_from_uart(border_packet_t *packet, int len); - -#ifdef __cplusplus -} -#endif - -#endif /* _SIXLOWPAN_FLOWCONTROL_H*/ diff --git a/sys/net/network_layer/sixlowpan/icmp.c b/sys/net/network_layer/sixlowpan/icmp.c deleted file mode 100644 index 2652301b47..0000000000 --- a/sys/net/network_layer/sixlowpan/icmp.c +++ /dev/null @@ -1,1871 +0,0 @@ -/* - * 6lowpan neighbor discovery - * - * Copyright (C) 2013 INRIA. - * - * 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 sixlowpan - * @{ - * @file - * @brief 6lowpan neighbor discovery functions - * @author Stephan Zeisberg - * @author Martine Lenders - * @author Oliver Gesch - * @author Oliver Hahm - * @} - */ - -#include -#include -#include - -#include "vtimer.h" -#include "mutex.h" -#include "net_if.h" -#include "sixlowpan/error.h" - -#include "ip.h" -#include "icmp.h" -#include "serialnumber.h" -#include "net_help.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -#define LLHDR_ICMPV6HDR_LEN (LL_HDR_LEN + IPV6_HDR_LEN + ICMPV6_HDR_LEN) -#define ND_HOPLIMIT (0xFF) - -/* parameter problem [rfc4443] */ -#define PARA_PROB_LEN (8) -/* echo request */ -#define ECHO_REQ_LEN (4) -/* echo reply */ -#define ECHO_REPL_LEN (4) -/* router solicitation */ -#define RTR_SOL_LEN (4) -#define RTR_SOL_INTERVAL (4) -#define RTR_SOL_MAX (3) -/* router advertisment */ -#define RTR_ADV_MAX (3) -#define RTR_ADV_MAX_INTERVAL (600) -#define RTR_ADV_LEN (12) -/* neighbour solicitation */ -#define NBR_SOL_LEN (20) -/* neighbour advertisement */ -#define NBR_ADV_LEN (20) -/* stllao option rfc4861 4.6.1 */ -#define OPT_STLLAO_MIN_LEN (8) -#define OPT_STLLAO_MAX_LEN (16) -/* prefix info option rfc 4.6.2 */ -#define OPT_PI_LIST_LEN (5) //TODO: initalwert suchen -#define OPT_PI_TYPE (3) -#define OPT_PI_LEN (4) -#define OPT_PI_HDR_LEN (32) -/* mtu option rfc4861 4.6.4 */ -#define OPT_MTU_TYPE (5) -#define OPT_MTU_LEN (1) -#define OPT_MTU_HDR_LEN (8) -/* aro - address registration option rfc6775 4.1 */ -#define OPT_ARO_TYPE (33) -#define OPT_ARO_LEN (2) -#define OPT_ARO_HDR_LEN (16) -#define OPT_ARO_LTIME (300) /* TODO: geeigneten wert finden */ -/* 6lowpan context option */ -#define OPT_6CO_TYPE (34) -#define OPT_6CO_MIN_LEN (2) -#define OPT_6CO_MAX_LEN (3) -#define OPT_6CO_HDR_LEN (8) -#define OPT_6CO_LTIME (5) /* TODO geeigneten Wert finden */ -/* authoritative border router option */ -#define OPT_ABRO_TYPE (35) -#define OPT_ABRO_LEN (3) -#define OPT_ABRO_HDR_LEN (24) -/* authoritive border router cache size */ -#define ABR_CACHE_SIZE (2) -/* neighbor cache size */ -#define NBR_CACHE_SIZE (8) -#define NBR_CACHE_LTIME_TEN (20) -/* default router list size */ -#define DEF_RTR_LST_SIZE (3) /* geeigneten wert finden */ - -#define PREFIX_BUF_LEN (NET_IF_MAX * OPT_PI_LIST_LEN) - -/* extern variables */ -uint8_t ipv6_ext_hdr_len = 0; - -/* counter */ -uint8_t abr_count = 0; -uint8_t nbr_count = 0; -uint8_t def_rtr_count = 0; -uint8_t rtr_sol_count = 0; -uint8_t prefix_info_count = 0; -uint8_t prefix_buf_count = 0; - -/* datastructures */ -ndp_a6br_cache_t abr_cache[ABR_CACHE_SIZE]; -ndp_neighbor_cache_t nbr_cache[NBR_CACHE_SIZE]; -ndp_default_router_list_t def_rtr_lst[DEF_RTR_LST_SIZE]; -ndp_prefix_info_t prefix_info_buf[PREFIX_BUF_LEN]; -uint8_t prefix_buf[sizeof(ipv6_addr_t) * PREFIX_BUF_LEN]; - -/* pointer */ -static uint8_t *llao; - -static ipv6_hdr_t *ipv6_buf; -static icmpv6_hdr_t *icmp_buf; -static icmpv6_router_adv_hdr_t *rtr_adv_buf; -static icmpv6_neighbor_sol_hdr_t *nbr_sol_buf; -static icmpv6_neighbor_adv_hdr_t *nbr_adv_buf; -static icmpv6_ndp_opt_hdr_t *opt_buf; -static icmpv6_ndp_opt_stllao_t *opt_stllao_buf; -static icmpv6_ndp_opt_mtu_t *opt_mtu_buf; -static icmpv6_ndp_opt_abro_t *opt_abro_buf; -static icmpv6_ndp_opt_6co_hdr_t *opt_6co_hdr_buf; -static uint8_t *opt_6co_prefix_buf; -static icmpv6_ndp_opt_pi_t *opt_pi_buf; -static icmpv6_ndp_opt_aro_t *opt_aro_buf; - -ndp_neighbor_cache_t *nbr_entry; -ndp_default_router_list_t *def_rtr_entry; - -/* elements */ -//ipv6_addr_t tmpaddr; - -uint8_t recvd_cids[NDP_6LOWPAN_CONTEXT_MAX]; -uint8_t icmpv6_opt_hdr_len = 0; -uint8_t recvd_cids_len = 0; -ndp_prefix_info_t *recvd_prefixes[PREFIX_BUF_LEN]; -uint8_t recvd_pref_len = 0; - -void def_rtr_lst_add(ipv6_addr_t *ipaddr, uint32_t rtr_ltime); -void def_rtr_lst_rem(ndp_default_router_list_t *entry); - -/** - * @brief Set Source link-layer address option according to interface - * configuration. - * - * @param[out] sllao The SLLAO to set. - * @param[in] if_id The interface to get the link-layer address from. - * @param[in] type The value for the type field of the SLLAO. - * @param[in] length The value for the length field of the SLLAO - */ -void icmpv6_ndp_set_sllao(icmpv6_ndp_opt_stllao_t *sllao, int if_id, - uint8_t type, uint8_t length); - -int min(int a, int b) -{ - if (a < b) { - return a; - } - else { - return b; - } -} - -static icmpv6_parameter_prob_hdr_t *get_para_prob_buf(uint8_t ext_len) -{ - return ((icmpv6_parameter_prob_hdr_t *) &sixlowpan_buffer[LLHDR_ICMPV6HDR_LEN + ext_len]); -} - -static icmpv6_echo_request_hdr_t *get_echo_req_buf(uint8_t ext_len) -{ - return ((icmpv6_echo_request_hdr_t *) &sixlowpan_buffer[LLHDR_ICMPV6HDR_LEN + ext_len]); -} - -static icmpv6_echo_reply_hdr_t *get_echo_repl_buf(uint8_t ext_len) -{ - return ((icmpv6_echo_reply_hdr_t *) &sixlowpan_buffer[LLHDR_ICMPV6HDR_LEN + ext_len]); -} - -static icmpv6_router_adv_hdr_t *get_rtr_adv_buf(uint8_t ext_len) -{ - return ((icmpv6_router_adv_hdr_t *) &sixlowpan_buffer[LLHDR_ICMPV6HDR_LEN + ext_len]); -} - -static icmpv6_neighbor_sol_hdr_t *get_nbr_sol_buf(uint8_t ext_len) -{ - return ((icmpv6_neighbor_sol_hdr_t *) &sixlowpan_buffer[LLHDR_ICMPV6HDR_LEN + ext_len]); -} - -static icmpv6_neighbor_adv_hdr_t *get_nbr_adv_buf(uint8_t ext_len) -{ - return ((icmpv6_neighbor_adv_hdr_t *) &sixlowpan_buffer[LLHDR_ICMPV6HDR_LEN + ext_len]); -} - -static icmpv6_ndp_opt_hdr_t *get_opt_buf(uint8_t ext_len, uint8_t opt_len) -{ - return ((icmpv6_ndp_opt_hdr_t *) &sixlowpan_buffer[LLHDR_ICMPV6HDR_LEN + ext_len + opt_len]); -} - -static icmpv6_ndp_opt_stllao_t *get_opt_stllao_buf(uint8_t ext_len, uint8_t opt_len) -{ - return ((icmpv6_ndp_opt_stllao_t *) &sixlowpan_buffer[LLHDR_ICMPV6HDR_LEN + ext_len + opt_len]); -} - -static icmpv6_ndp_opt_mtu_t *get_opt_mtu_buf(uint8_t ext_len, uint8_t opt_len) -{ - return ((icmpv6_ndp_opt_mtu_t *) &sixlowpan_buffer[LLHDR_ICMPV6HDR_LEN + ext_len + opt_len]); -} - -static icmpv6_ndp_opt_abro_t *get_opt_abro_buf(uint8_t ext_len, uint8_t opt_len) -{ - return ((icmpv6_ndp_opt_abro_t *) &sixlowpan_buffer[LLHDR_ICMPV6HDR_LEN + ext_len + opt_len]); -} - -static icmpv6_ndp_opt_6co_hdr_t *get_opt_6co_hdr_buf(uint8_t ext_len, uint8_t opt_len) -{ - return ((icmpv6_ndp_opt_6co_hdr_t *) &sixlowpan_buffer[LLHDR_ICMPV6HDR_LEN + ext_len + opt_len]); -} - -static uint8_t *get_opt_6co_prefix_buf(uint8_t ext_len, uint8_t opt_len) -{ - return ((uint8_t *) &sixlowpan_buffer[LLHDR_ICMPV6HDR_LEN + ext_len + opt_len]); -} - -static icmpv6_ndp_opt_pi_t *get_opt_pi_buf(uint8_t ext_len, uint8_t opt_len) -{ - return ((icmpv6_ndp_opt_pi_t *) &sixlowpan_buffer[LLHDR_ICMPV6HDR_LEN + ext_len + opt_len]); -} - -static icmpv6_ndp_opt_aro_t *get_opt_aro_buf(uint8_t ext_len, uint8_t opt_len) -{ - return ((icmpv6_ndp_opt_aro_t *) &sixlowpan_buffer[LLHDR_ICMPV6HDR_LEN + ext_len + opt_len]); -} - -void icmpv6_send_echo_request(ipv6_addr_t *destaddr, uint16_t id, uint16_t seq, uint8_t *data, size_t data_len) -{ - uint16_t packet_length; - - ipv6_buf = ipv6_get_buf(); - icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len); - icmpv6_echo_request_hdr_t *echo_buf = get_echo_req_buf(ipv6_ext_hdr_len); - uint8_t *echo_data_buf = ((uint8_t *)echo_buf) + sizeof(icmpv6_echo_request_hdr_t); - - icmp_buf->type = ICMPV6_TYPE_ECHO_REQUEST; - icmp_buf->code = 0; - ipv6_buf->version_trafficclass = IPV6_VER; - ipv6_buf->trafficclass_flowlabel = 0; - ipv6_buf->flowlabel = 0; - ipv6_buf->nextheader = IPV6_PROTO_NUM_ICMPV6; - ipv6_buf->hoplimit = ipv6_get_default_hop_limit(); - - memcpy(&ipv6_buf->destaddr, destaddr, sizeof(ipv6_addr_t)); - ipv6_net_if_get_best_src_addr(&ipv6_buf->srcaddr, &ipv6_buf->destaddr); - echo_buf->id = HTONS(id); - echo_buf->seq = HTONS(seq); - - memcpy(echo_data_buf, data, data_len); - packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + ipv6_ext_hdr_len + - ECHO_REQ_LEN + data_len; - - ipv6_buf->length = HTONS(packet_length - IPV6_HDR_LEN); - - icmp_buf->checksum = icmpv6_csum(ipv6_buf, icmp_buf); - -#if ENABLE_DEBUG - char addr_str[IPV6_MAX_ADDR_STR_LEN]; - printf("INFO: send echo request (id = %04x, seq = %d, data_len = %zu) to: %s\n", - id, seq, data_len, ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - &ipv6_buf->destaddr)); -#endif - ipv6_send_packet(ipv6_buf, NULL); -} - -void icmpv6_send_echo_reply(ipv6_addr_t *destaddr, uint16_t id, uint16_t seq, uint8_t *data, size_t data_len) -{ - uint16_t packet_length; - - ipv6_buf = ipv6_get_buf(); - icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len); - icmpv6_echo_reply_hdr_t *echo_buf = get_echo_repl_buf(ipv6_ext_hdr_len); - uint8_t *echo_data_buf = ((uint8_t *)echo_buf) + sizeof(icmpv6_echo_reply_hdr_t); - - icmp_buf->type = ICMPV6_TYPE_ECHO_REPLY; - icmp_buf->code = 0; - ipv6_buf->version_trafficclass = IPV6_VER; - ipv6_buf->trafficclass_flowlabel = 0; - ipv6_buf->flowlabel = 0; - ipv6_buf->nextheader = IPV6_PROTO_NUM_ICMPV6; - ipv6_buf->hoplimit = ipv6_get_default_hop_limit(); - - memcpy(&ipv6_buf->destaddr, destaddr, sizeof(ipv6_addr_t)); - ipv6_net_if_get_best_src_addr(&ipv6_buf->srcaddr, &ipv6_buf->destaddr); - echo_buf->id = HTONS(id); - echo_buf->seq = HTONS(seq); - - memcpy(echo_data_buf, data, data_len); - packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + ipv6_ext_hdr_len + - ECHO_REPL_LEN + data_len; - - ipv6_buf->length = HTONS(packet_length - IPV6_HDR_LEN); - - icmp_buf->checksum = icmpv6_csum(ipv6_buf, icmp_buf); - -#if ENABLE_DEBUG - char addr_str[IPV6_MAX_ADDR_STR_LEN]; - printf("INFO: send echo reply (id = %04x, seq = %d, data_len = %zu) to: %s\n", - id, seq, data_len, ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - &ipv6_buf->destaddr)); -#endif - ipv6_send_packet(ipv6_buf, NULL); -} - -/* send router solicitation message - RFC4861 section 4.1 */ -void icmpv6_send_router_sol(uint8_t sllao) -{ - uint16_t packet_length; - - ipv6_buf = ipv6_get_buf(); - icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len); - - icmp_buf->type = ICMPV6_TYPE_ROUTER_SOL; - icmp_buf->code = 0; - ipv6_buf->version_trafficclass = IPV6_VER; - ipv6_buf->trafficclass_flowlabel = 0; - ipv6_buf->flowlabel = 0; - ipv6_buf->nextheader = IPV6_PROTO_NUM_ICMPV6; - ipv6_buf->hoplimit = ND_HOPLIMIT; - - ipv6_addr_set_all_routers_addr(&ipv6_buf->destaddr); - //iface_find_src_ipaddr(&ipv6_buf->srcaddr, NDP_ADDR_STATE_PREFERRED, - /* IPV6_ADDR_TYPE_MULTICAST); */ - - ipv6_net_if_get_best_src_addr(&(ipv6_buf->srcaddr), &(ipv6_buf->destaddr)); - - icmpv6_opt_hdr_len = RTR_SOL_LEN; - - if (sllao == OPT_SLLAO) { - opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len); - int if_id = 0; // TODO get this somehow - - if (net_if_get_src_address_mode(if_id) == NET_IF_TRANS_ADDR_M_LONG) { - icmpv6_ndp_set_sllao(opt_stllao_buf, if_id, NDP_OPT_SLLAO_TYPE, 2); - packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + ipv6_ext_hdr_len + - RTR_SOL_LEN + OPT_STLLAO_MAX_LEN; - } - else { - icmpv6_ndp_set_sllao(opt_stllao_buf, if_id, NDP_OPT_SLLAO_TYPE, 1); - packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + ipv6_ext_hdr_len + - RTR_SOL_LEN + OPT_STLLAO_MIN_LEN; - } - } - else { - packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + ipv6_ext_hdr_len + - RTR_SOL_LEN; - } - - ipv6_buf->length = HTONS(packet_length - IPV6_HDR_LEN); - - icmp_buf->checksum = icmpv6_csum(ipv6_buf, icmp_buf); - -#if ENABLE_DEBUG - char addr_str[IPV6_MAX_ADDR_STR_LEN]; - printf("INFO: send router solicitation to: %s\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - &ipv6_buf->destaddr)); -#endif - ipv6_send_packet(ipv6_buf, NULL); -} - -void recv_echo_req(void) -{ - ipv6_buf = ipv6_get_buf(); - icmpv6_echo_request_hdr_t *echo_buf = get_echo_req_buf(ipv6_ext_hdr_len); - uint8_t *echo_data_buf = ((uint8_t *)echo_buf) + sizeof(icmpv6_echo_reply_hdr_t); - size_t data_len = NTOHS(ipv6_buf->length) - ICMPV6_HDR_LEN - ECHO_REQ_LEN; - -#if ENABLE_DEBUG - char addr_str[IPV6_MAX_ADDR_STR_LEN]; - printf("INFO: received echo request from: %s\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - &ipv6_buf->srcaddr)); - printf("\n"); - printf("id = 0x%04x, seq = %d, data_len = %zu\n", NTOHS(echo_buf->id), - NTOHS(echo_buf->seq), data_len); - - for (size_t i = 0; i < data_len; i++) { - printf("%02x ", echo_data_buf[i]); - - if (!((i + 1) % 16) || i == data_len - 1) { - printf("\n"); - } - } - -#endif - icmpv6_send_echo_reply(&ipv6_buf->srcaddr, NTOHS(echo_buf->id), - NTOHS(echo_buf->seq), echo_data_buf, data_len); -} - -void recv_echo_repl(void) -{ -#if ENABLE_DEBUG - ipv6_buf = ipv6_get_buf(); - icmpv6_echo_reply_hdr_t *echo_buf = get_echo_repl_buf(ipv6_ext_hdr_len); - uint8_t *echo_data_buf = ((uint8_t *)echo_buf) + sizeof(icmpv6_echo_reply_hdr_t); - size_t data_len = NTOHS(ipv6_buf->length) - ICMPV6_HDR_LEN - ECHO_REPL_LEN; - char addr_str[IPV6_MAX_ADDR_STR_LEN]; - - printf("INFO: received echo reply from: %s\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - &ipv6_buf->srcaddr)); - printf("\n"); - printf("id = 0x%04x, seq = %d, data_len = %zu\n", NTOHS(echo_buf->id), - NTOHS(echo_buf->seq), data_len); - - for (size_t i = 0; i < data_len; i++) { - printf("%02x ", echo_data_buf[i]); - - if (!((i + 1) % 16) || i == data_len - 1) { - printf("\n"); - } - } -#endif -} - -void recv_rtr_sol(void) -{ - icmpv6_opt_hdr_len = RTR_SOL_LEN; - ipv6_buf = ipv6_get_buf(); - - /* check if source option is set*/ - if (opt_stllao_buf->type == NDP_OPT_SLLAO_TYPE) { - opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len); - llao = (uint8_t *)opt_stllao_buf; - icmpv6_opt_hdr_len += (opt_stllao_buf->length) << 3; - } - - if (llao != NULL) { - uint8_t lladdr_len; - nbr_entry = ndp_neighbor_cache_search(&ipv6_buf->srcaddr); - - if (opt_stllao_buf->length == 2) { - lladdr_len = 8; - } - else if (opt_stllao_buf->length == 1) { - lladdr_len = 2; - } - else { - DEBUG("Unknown length for S/TLLAO: %d * 8 Bytes.\n", opt_stllao_buf->length); - return; - } - - int if_id = 0; // TODO, get this somehow - if (nbr_entry != NULL) { - /* found neighbor in cache, update values and check addr */ - if (memcmp(&llao[2], &nbr_entry->lladdr, lladdr_len) == 0) { - nbr_entry->if_id = if_id; - nbr_entry->isrouter = 0; - } - else { - /* new addr found, update */ - nbr_entry->if_id = if_id; - memcpy(&nbr_entry->lladdr, &llao[2], lladdr_len); - nbr_entry->state = NDP_NCE_STATUS_STALE; - nbr_entry->isrouter = 0; - } - } - else { - /* nothing found, add neigbor into cache*/ - ndp_neighbor_cache_add(if_id, &ipv6_buf->srcaddr, &llao[2], lladdr_len, - 0, NDP_NCE_STATUS_STALE, NDP_NCE_TYPE_TENTATIVE, - NBR_CACHE_LTIME_TEN); - } - } - - /* send solicited router advertisment */ - if (abr_count > 0) { - icmpv6_send_router_adv(&ipv6_buf->srcaddr, 0, 0, OPT_PI, OPT_6CO, OPT_ABRO); - } - else { - icmpv6_send_router_adv(&ipv6_buf->srcaddr, 0, 0, OPT_PI, 0, 0); - } -} - -uint8_t set_opt_6co_flags(uint8_t compression_flag, uint8_t cid) -{ - uint8_t flags; - - if (compression_flag) { - flags = ICMPV6_NDP_OPT_6CO_FLAG_CCOMPR; - } - else { - flags = 0; - } - - flags |= cid & ICMPV6_NDP_OPT_6CO_FLAG_CID; - return flags; -} - -void get_opt_6co_flags(uint8_t *compression_flag, uint8_t *cid, uint8_t flags) -{ - compression_flag[0] = flags & ICMPV6_NDP_OPT_6CO_FLAG_CID; - compression_flag[0] = compression_flag[0] != 0; - cid[0] = flags & ICMPV6_NDP_OPT_6CO_FLAG_CID; -} - -lowpan_context_t *abr_get_context(ndp_a6br_cache_t *abr, uint8_t cid); - -void icmpv6_send_router_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8_t pi, - uint8_t sixco, uint8_t abro) -{ - int if_id = 0; // TODO: get this somehow - uint16_t packet_length; - lowpan_context_t *contexts = NULL; - - ndp_a6br_cache_t *msg_abr = NULL; - ipv6_buf = ipv6_get_buf(); - icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len); - - ipv6_buf->version_trafficclass = IPV6_VER; - ipv6_buf->trafficclass_flowlabel = 0; - ipv6_buf->flowlabel = 0; - ipv6_buf->nextheader = IPV6_PROTO_NUM_ICMPV6; - ipv6_buf->hoplimit = ND_HOPLIMIT; - - if (addr == NULL) { - /* not solicited */ - ipv6_addr_set_all_nodes_addr(&ipv6_buf->destaddr); - } - else { - memcpy(&ipv6_buf->destaddr, addr, 16); - } - - ipv6_net_if_get_best_src_addr(&(ipv6_buf->srcaddr), &(ipv6_buf->destaddr)); - - icmp_buf->type = ICMPV6_TYPE_ROUTER_ADV; - icmp_buf->code = 0; - - //TODO: gethoplimit func, set current ttl - - rtr_adv_buf = get_rtr_adv_buf(ipv6_ext_hdr_len); - rtr_adv_buf->hoplimit = MULTIHOP_HOPLIMIT; - /* set M and O flag, last 6 bits are zero */ - rtr_adv_buf->autoconfig_flags = ICMPV6_ROUTER_ADV_FLAG_MANAGED | ICMPV6_ROUTER_ADV_FLAG_OTHER; - rtr_adv_buf->router_lifetime = HTONS(RTR_ADV_MAX_INTERVAL * RTR_ADV_MAX); - rtr_adv_buf->reachable_time = 0; - rtr_adv_buf->retrans_timer = 0; - icmpv6_opt_hdr_len = RTR_ADV_LEN; - - packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + RTR_ADV_LEN; - - if (sllao == OPT_SLLAO) { - /* set link layer address option */ - opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len); - - if (net_if_get_src_address_mode(if_id) == NET_IF_TRANS_ADDR_M_LONG) { - icmpv6_ndp_set_sllao(opt_stllao_buf, if_id, NDP_OPT_SLLAO_TYPE, 2); - icmpv6_opt_hdr_len += OPT_STLLAO_MAX_LEN; - packet_length += OPT_STLLAO_MAX_LEN; - } - else { - icmpv6_ndp_set_sllao(opt_stllao_buf, if_id, NDP_OPT_SLLAO_TYPE, 1); - icmpv6_opt_hdr_len += OPT_STLLAO_MIN_LEN; - packet_length += OPT_STLLAO_MIN_LEN; - } - } - - if (mtu == OPT_MTU) { - /* set MTU options */ - opt_mtu_buf = get_opt_mtu_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len); - opt_mtu_buf->type = OPT_MTU_TYPE; - opt_mtu_buf->length = OPT_MTU_LEN; - opt_mtu_buf->reserved = 0; - opt_mtu_buf->mtu = HTONL(1500); - icmpv6_opt_hdr_len += OPT_MTU_HDR_LEN; - packet_length += OPT_MTU_HDR_LEN; - } - - /* set payload length field */ - - if (abro == OPT_ABRO) { - /* set authoritive border router option */ - if (abr_count > 0) { - msg_abr = ndp_a6br_cache_get_most_current(); - opt_abro_buf = get_opt_abro_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len); - opt_abro_buf->type = OPT_ABRO_TYPE; - opt_abro_buf->length = OPT_ABRO_LEN; - opt_abro_buf->version = HTONS(msg_abr->version); - opt_abro_buf->reserved = 0; - memcpy(&(opt_abro_buf->addr), &(msg_abr->abr_addr), sizeof(ipv6_addr_t)); - } - } - - if (sixco == OPT_6CO) { - /* set 6lowpan context option */ - int contexts_len = 0; - mutex_lock(&lowpan_context_mutex); - - if (msg_abr == NULL) { - contexts = lowpan_context_get(); - contexts_len = lowpan_context_len(); - } - else { - lowpan_context_t c_tmp[NDP_6LOWPAN_CONTEXT_MAX]; - - for (int i = 0; i < NDP_6LOWPAN_CONTEXT_MAX; i++) { - lowpan_context_t *ctx = abr_get_context(msg_abr, i); - - if (ctx != NULL) { - memcpy(&(c_tmp[contexts_len++]), ctx, sizeof(lowpan_context_t)); - } - } - - if (contexts_len > 0) { - contexts = (lowpan_context_t *)malloc(contexts_len * sizeof(lowpan_context_t)); - - if (contexts == NULL) { - DEBUG("icmpv6_send_router_adv: no memory left"); - contexts_len = 0; /* HACK to skip over for loop below */ - } - else { - memcpy(contexts, c_tmp, contexts_len); - } - } - } - - for (int i = 0; i < contexts_len; i++) { - opt_6co_hdr_buf = get_opt_6co_hdr_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len); - opt_6co_hdr_buf->type = OPT_6CO_TYPE; - - if (contexts[i].length > 64) { - opt_6co_hdr_buf->length = OPT_6CO_MAX_LEN; - } - else { - opt_6co_hdr_buf->length = OPT_6CO_MIN_LEN; - } - - opt_6co_hdr_buf->c_length = contexts[i].length; - opt_6co_hdr_buf->c_flags = set_opt_6co_flags(contexts[i].comp, contexts[i].num); - opt_6co_hdr_buf->reserved = 0; - opt_6co_hdr_buf->val_ltime = HTONS(contexts[i].lifetime); - - icmpv6_opt_hdr_len += OPT_6CO_HDR_LEN; - packet_length += OPT_6CO_HDR_LEN; - /* attach prefixes */ - opt_6co_prefix_buf = get_opt_6co_prefix_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len); - - if (opt_6co_hdr_buf->c_length > 64) { - 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); - icmpv6_opt_hdr_len += 16; - packet_length += 16; - } - else { - memset((void *)opt_6co_prefix_buf, 0, 8); - memcpy((void *)opt_6co_prefix_buf, (void *) &contexts[i].prefix.uint8[0], opt_6co_hdr_buf->c_length / 8); - icmpv6_opt_hdr_len += 8; - packet_length += 8; - } - - } - - if (msg_abr != NULL && contexts != NULL) { - free(contexts); - } - - mutex_unlock(&lowpan_context_mutex); - } - - if (pi == OPT_PI) { - ndp_prefix_info_t *prefix = NULL; - - /* set prefix option */ - while (net_if_iter_addresses(if_id, (net_if_addr_t **) &prefix)) { - if (prefix->prefix_protocol & NET_IF_L3P_IPV6_PREFIX && - prefix->inuse && prefix->advertisable) { - opt_pi_buf = get_opt_pi_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len); - memset(&opt_pi_buf->addr, 0, sizeof(ipv6_addr_t)); - memcpy(&opt_pi_buf->addr, &prefix->prefix_data, prefix->prefix_len); - opt_pi_buf->type = OPT_PI_TYPE; - opt_pi_buf->length = OPT_PI_LEN; - opt_pi_buf->prefix_length = prefix->prefix_len; - opt_pi_buf->l_a_reserved1 = prefix->flags; - opt_pi_buf->val_ltime = HTONL(prefix->valid_lifetime); - opt_pi_buf->pref_ltime = HTONL(prefix->preferred_lifetime); - opt_pi_buf->reserved2 = 0; - packet_length += OPT_PI_HDR_LEN; - icmpv6_opt_hdr_len += OPT_PI_HDR_LEN; - } - } - } - - ipv6_buf->length = HTONS(packet_length - IPV6_HDR_LEN); - - /* calculate checksum */ - icmp_buf->checksum = icmpv6_csum(ipv6_buf, icmp_buf); - -#if ENABLE_DEBUG - char addr_str[IPV6_MAX_ADDR_STR_LEN]; - printf("INFO: send router advertisement to: %s\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - &ipv6_buf->destaddr)); -#endif - ipv6_send_packet(ipv6_buf, NULL); -} - -void recv_rtr_adv(void) -{ - int if_id = 0; // TODO: get this somehow - int8_t trigger_ns = -1; - int8_t abro_found = 0; - int16_t abro_version = 0; /* later replaced, just to supress warnings */ - uint16_t packet_length; - ipv6_addr_t abro_addr; - - ipv6_buf = ipv6_get_buf(); - packet_length = IPV6_HDR_LEN + NTOHS(ipv6_buf->length); - icmpv6_opt_hdr_len = RTR_ADV_LEN; - rtr_adv_buf = get_rtr_adv_buf(ipv6_ext_hdr_len); - ipv6_addr_t newaddr; - recvd_cids_len = 0; - - /* update interface reachable time and retrans timer */ - if (rtr_adv_buf->reachable_time != 0) { - ipv6_net_if_ext_t *iface; - - iface = ipv6_net_if_get_ext(if_id); - if (iface) { - iface->adv_reachable_time = NTOHL(rtr_adv_buf->reachable_time); - } - } - - if (rtr_adv_buf->retrans_timer != 0) { - ipv6_net_if_ext_t *iface; - - iface = ipv6_net_if_get_ext(if_id); - if (iface) { - iface->adv_retrans_timer = NTOHL(rtr_adv_buf->retrans_timer); - } - } - - def_rtr_entry = ndp_default_router_list_search(&ipv6_buf->srcaddr); - - if (rtr_adv_buf->router_lifetime != 0) { - if (def_rtr_entry != NULL) { - set_remaining_time(&(def_rtr_entry->inval_time), HTONL(rtr_adv_buf->router_lifetime)); - } - else { - def_rtr_lst_add(&(ipv6_buf->srcaddr), HTONL(rtr_adv_buf->router_lifetime)); - trigger_ns = 1; - } - } - else { - /* remove router from default router list */ - if (def_rtr_entry != NULL) { - def_rtr_lst_rem(def_rtr_entry); - } - } - - mutex_lock(&lowpan_context_mutex); - - /* read options */ - while (packet_length > IPV6_HDR_LEN + ICMPV6_HDR_LEN + icmpv6_opt_hdr_len) { - opt_buf = get_opt_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len); - - switch (opt_buf->type) { - case (NDP_OPT_SLLAO_TYPE): { - break; - } - - case (OPT_MTU_TYPE): { - break; - } - - /* rfc 4862 section 5.5.3 */ - case (OPT_PI_TYPE): { - opt_pi_buf = get_opt_pi_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len); - - /* crazy condition, read 5.5.3a-b-c for further information */ - if (ipv6_addr_is_link_local(&opt_pi_buf->addr) || - (HTONL(opt_pi_buf->pref_ltime) > - HTONL(opt_pi_buf->val_ltime))) { - break; - } - else { - /* check if on-link flag is set */ - if (opt_pi_buf->l_a_reserved1 & ICMPV6_NDP_OPT_PI_FLAG_ON_LINK) { - /* TODO: do on-link pi handling */ - } - - if (opt_pi_buf->l_a_reserved1 & ICMPV6_NDP_OPT_PI_FLAG_AUTONOM) { - ipv6_net_if_hit_t addr_hit; - - if (!ipv6_net_if_addr_prefix_eq(&addr_hit, &opt_pi_buf->addr)) { - /* 5.5.3d */ - if (opt_pi_buf->val_ltime != 0) { - /* iid will also be added here */ - ipv6_addr_set_by_eui64(&newaddr, if_id, - &opt_pi_buf->addr); - /* add into address list - * TODO: duplicate address detection is not - * implementet yet, so all new addresse will - * be added with state PREFFERED */ - ipv6_net_if_add_addr(if_id, &newaddr, - NDP_ADDR_STATE_PREFERRED, - opt_pi_buf->val_ltime, - opt_pi_buf->pref_ltime, 0); - DEBUG("INFO: added address to interface\n"); - trigger_ns = 1; - } - } - else { - /* 5.5.3e */ - set_remaining_time(&addr_hit.addr->preferred_lifetime, - opt_pi_buf->pref_ltime); - - /* 7200 = 2hours in seconds */ - if (HTONL(opt_pi_buf->val_ltime) > 7200 || - HTONL(opt_pi_buf->val_ltime) > - get_remaining_time(&addr_hit.addr->valid_lifetime)) { - set_remaining_time(&addr_hit.addr->valid_lifetime, - HTONL(opt_pi_buf->val_ltime)); - } - else { - /* reset valid lifetime to 2 hours */ - set_remaining_time(&addr_hit.addr->valid_lifetime, - 7200); - } - } - } - } - - ndp_add_prefix_info(if_id, &opt_pi_buf->addr, opt_pi_buf->prefix_length, - opt_pi_buf->val_ltime, opt_pi_buf->pref_ltime, - 0, opt_pi_buf->l_a_reserved1); - - break; - } - - case (OPT_6CO_TYPE): { - uint8_t comp; - uint8_t num; - - opt_6co_hdr_buf = get_opt_6co_hdr_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len); - - get_opt_6co_flags(&comp, &num, opt_6co_hdr_buf->c_flags); - - ipv6_addr_t prefix; - memset(&prefix, 0, 16); - - opt_6co_prefix_buf = get_opt_6co_prefix_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len + OPT_6CO_HDR_LEN); - - memcpy(&prefix, opt_6co_prefix_buf, opt_6co_hdr_buf->c_length); - - lowpan_context_update( - num, - &prefix, - opt_6co_hdr_buf->c_length, - comp, - HTONS(opt_6co_hdr_buf->val_ltime) - ); - recvd_cids[recvd_cids_len] = num; - recvd_cids_len = (recvd_cids_len + 1) % NDP_6LOWPAN_CONTEXT_MAX; - break; - } - - case (OPT_ABRO_TYPE): { - opt_abro_buf = get_opt_abro_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len); - abro_found = 1; - abro_version = HTONS(opt_abro_buf->version); - memcpy(&(abro_addr), &(opt_abro_buf->addr), sizeof(ipv6_addr_t)); - break; - } - - default: - break; - } - - /* multiplied with 8 because options length is in units of 8 bytes */ - icmpv6_opt_hdr_len += (opt_buf->length * 8); - } - - if (abro_found) { - int i; - - for (i = 0; i < recvd_cids_len; i++) { - abr_add_context(abro_version, &abro_addr, recvd_cids[i]); - } - } - - mutex_unlock(&lowpan_context_mutex); - - if (trigger_ns >= 0) { - /* send ns - draft-ietf-6lowpan-nd-15#section-5.5.1 - * - * section-10.2.4 - * "Next the 6LN registers that address with one or more of its - * default routers by sending a unicast NS message with an ARO - * containing its tentative global IPv6 address to register - * - * if new address was configured, set src to newaddr(gp16) */ - icmpv6_send_neighbor_sol(&newaddr, &(ipv6_buf->srcaddr), &(ipv6_buf->srcaddr), OPT_SLLAO, OPT_ARO); - } -} - -void icmpv6_send_neighbor_sol(ipv6_addr_t *src, ipv6_addr_t *dest, ipv6_addr_t *targ, - uint8_t sllao, uint8_t aro) -{ - uint16_t packet_length; - int if_id = 0; // TODO: get this somehow - ipv6_net_if_hit_t hit; - - ipv6_buf = ipv6_get_buf(); - ipv6_buf->version_trafficclass = IPV6_VER; - ipv6_buf->trafficclass_flowlabel = 0; - ipv6_buf->flowlabel = 0; - ipv6_buf->nextheader = IPV6_PROTO_NUM_ICMPV6; - ipv6_buf->hoplimit = ND_HOPLIMIT; - - if (dest == NULL) { - ipv6_addr_set_solicited_node_addr(&(ipv6_buf->destaddr), targ); - } - else { - memcpy(&(ipv6_buf->destaddr.uint8[0]), &(dest->uint8[0]), 16); - } - - ipv6_ext_hdr_len = 0; - icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len); - icmp_buf->type = ICMPV6_TYPE_NEIGHBOR_SOL; - icmp_buf->code = 0; - - nbr_sol_buf = get_nbr_sol_buf(ipv6_ext_hdr_len); - nbr_sol_buf->reserved = 0; - memcpy(&(nbr_sol_buf->target_addr), targ, 16); - icmpv6_opt_hdr_len = NBR_SOL_LEN; - - packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + NBR_SOL_LEN; - - if (!ipv6_net_if_addr_match(&hit, targ)) { - if (src == NULL) { - ipv6_net_if_get_best_src_addr(&(ipv6_buf->srcaddr), &(ipv6_buf->destaddr)); - } - else { - memcpy(&(ipv6_buf->srcaddr), src, 16); - } - - if (sllao == OPT_SLLAO) { - /* set sllao option */ - opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len); - - if (net_if_get_src_address_mode(if_id) == NET_IF_TRANS_ADDR_M_LONG) { - icmpv6_ndp_set_sllao(opt_stllao_buf, if_id, NDP_OPT_SLLAO_TYPE, 2); - icmpv6_opt_hdr_len += OPT_STLLAO_MAX_LEN; - packet_length += OPT_STLLAO_MAX_LEN; - } - else { - icmpv6_ndp_set_sllao(opt_stllao_buf, if_id, NDP_OPT_SLLAO_TYPE, 1); - icmpv6_opt_hdr_len += OPT_STLLAO_MIN_LEN; - packet_length += OPT_STLLAO_MIN_LEN; - } - } - } - - if (aro == OPT_ARO) { - /* set aro option */ - opt_aro_buf = get_opt_aro_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len); - opt_aro_buf->type = OPT_ARO_TYPE; - opt_aro_buf->length = OPT_ARO_LEN; - opt_aro_buf->status = 0; - opt_aro_buf->reserved1 = 0; - opt_aro_buf->reserved2 = 0; - - if (net_if_get_src_address_mode(if_id) == NET_IF_TRANS_ADDR_M_SHORT) { - net_if_get_eui64((net_if_eui64_t *) &opt_aro_buf->eui64, if_id, 1); - } - else if (net_if_get_src_address_mode(if_id) == NET_IF_TRANS_ADDR_M_LONG) { - net_if_get_eui64((net_if_eui64_t *) &opt_aro_buf->eui64, if_id, 0); - } - - icmpv6_opt_hdr_len += OPT_ARO_HDR_LEN; - - packet_length += OPT_ARO_HDR_LEN; - } - - ipv6_buf->length = HTONS(packet_length - IPV6_HDR_LEN); - - icmp_buf->checksum = icmpv6_csum(ipv6_buf, icmp_buf); - -#if ENABLE_DEBUG - char addr_str[IPV6_MAX_ADDR_STR_LEN]; - printf("INFO: send neighbor solicitation to: %s\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - &ipv6_buf->destaddr)); -#endif - ipv6_send_packet(ipv6_buf, NULL); -} - -void recv_nbr_sol(void) -{ - int if_id = 0; // TODO, get this somehow - ipv6_buf = ipv6_get_buf(); - llao = NULL; - icmpv6_opt_hdr_len = NBR_SOL_LEN; - - uint8_t send_na = 0; - uint8_t sllao_set = 0; - uint16_t packet_length = IPV6_HDR_LEN + NTOHS(ipv6_buf->length); - - /* check whick options are set, we need that because an aro - * option condition is that a sllao option is set. thus that we don't - * know which option comes first we need to this here */ - - while (packet_length > IPV6_HDR_LEN + ICMPV6_HDR_LEN + icmpv6_opt_hdr_len) { - opt_buf = get_opt_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len); - - if (opt_buf->type == NDP_OPT_SLLAO_TYPE) { - sllao_set = 1; - } - - icmpv6_opt_hdr_len += (opt_buf->length * 8); - } - - icmpv6_opt_hdr_len = NBR_SOL_LEN; - - while (packet_length > IPV6_HDR_LEN + ICMPV6_HDR_LEN + icmpv6_opt_hdr_len) { - opt_buf = get_opt_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len); - - switch (opt_buf->type) { - case (NDP_OPT_SLLAO_TYPE): { - opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, - icmpv6_opt_hdr_len); - llao = (uint8_t *)opt_stllao_buf; - - if (llao != NULL && - !(ipv6_addr_is_unspecified(&ipv6_buf->srcaddr))) { - nbr_entry = ndp_neighbor_cache_search(&(ipv6_buf->srcaddr)); - - if (nbr_entry != NULL) { - switch (opt_stllao_buf->length) { - case (1): { - if (memcmp(&llao[2], &(nbr_entry->lladdr), 2) == 0) { - nbr_entry->if_id = if_id; - nbr_entry->isrouter = 0; - } - else { - nbr_entry->if_id = if_id; - memcpy(&nbr_entry->lladdr, &llao[2], 2); - nbr_entry->state = NDP_NCE_STATUS_STALE; - nbr_entry->isrouter = 0; - } - - break; - } - - case (2): { - if (memcmp(&llao[2], &(nbr_entry->lladdr), 8) == 0) { - nbr_entry->if_id = if_id; - nbr_entry->isrouter = 0; - } - else { - nbr_entry->if_id = if_id; - memcpy(&nbr_entry->lladdr, &llao[2], 8); - nbr_entry->state = NDP_NCE_STATUS_STALE; - nbr_entry->isrouter = 0; - } - - break; - } - - default: - break; - } - } - else { - switch (opt_stllao_buf->length) { - case (1): { - ndp_neighbor_cache_add(if_id, &ipv6_buf->srcaddr, - &llao[2], 2, 0, - NDP_NCE_STATUS_STALE, - NDP_NCE_TYPE_TENTATIVE, - NBR_CACHE_LTIME_TEN); - - break; - } - - case (2): { - ndp_neighbor_cache_add(if_id, &ipv6_buf->srcaddr, - &llao[2], 8, 0, - NDP_NCE_STATUS_STALE, - NDP_NCE_TYPE_TENTATIVE, - NBR_CACHE_LTIME_TEN); - break; - } - - default: - break; - } - } - } - - break; - } - - case (OPT_ARO_TYPE): { - /* check if sllao option is set, and if address src address - * isn't unspecified - draft-ietf-6lowpan-nd-15#section-6.5 */ - if (!(ipv6_addr_is_unspecified(&ipv6_buf->srcaddr)) && - sllao_set == 1) { - uint8_t aro_state = NDP_OPT_ARO_STATE_SUCCESS; - opt_aro_buf = get_opt_aro_buf(ipv6_ext_hdr_len, - icmpv6_opt_hdr_len); - - if ((opt_aro_buf->length == 2) && - (opt_aro_buf->status == 0)) { - /* check neighbor cache for duplicates */ - nbr_entry = ndp_neighbor_cache_search(&(ipv6_buf->srcaddr)); - - if (nbr_entry == NULL) { - /* create neighbor cache */ - aro_state = ndp_neighbor_cache_add(if_id, &ipv6_buf->srcaddr, - &(opt_aro_buf->eui64), 8, 0, - NDP_NCE_STATUS_STALE, NDP_NCE_TYPE_TENTATIVE, - opt_aro_buf->reg_ltime); - } - else { - if (memcmp(&(nbr_entry->addr.uint16[4]), - &(opt_aro_buf->eui64.uint16[0]), 8) == 0) { - /* update neighbor cache entry */ - if (opt_aro_buf->reg_ltime == 0) { - /* delete neighbor cache entry */ - ndp_neighbor_cache_remove(&nbr_entry->addr); - } - else { - set_remaining_time(&(nbr_entry->ltime), (uint32_t)opt_aro_buf->reg_ltime); - nbr_entry->state = NDP_NCE_STATUS_STALE; - nbr_entry->isrouter = 0; - memcpy(&(nbr_entry->addr.uint8[0]), - &(ipv6_buf->srcaddr.uint8[0]), 16); - } - - aro_state = NDP_OPT_ARO_STATE_SUCCESS; - } - else { - /* duplicate found */ - aro_state = NDP_OPT_ARO_STATE_DUP_ADDR; - } - } - } - - (void) aro_state; - } - - break; - } - - default: - break; - } - - icmpv6_opt_hdr_len += (opt_buf->length * 8); - } - - ipv6_net_if_hit_t alist_targ, alist_dest; - - nbr_sol_buf = get_nbr_sol_buf(ipv6_ext_hdr_len); - - if (ipv6_net_if_addr_match(&alist_targ, &nbr_sol_buf->target_addr) != NULL) { - ipv6_net_if_addr_match(&alist_dest, &ipv6_buf->destaddr); - - if ((memcmp(alist_targ.addr->addr_data, alist_dest.addr->addr_data, 16) == 0) || - ipv6_addr_is_solicited_node(&ipv6_buf->destaddr)) { - memcpy(&(ipv6_buf->destaddr.uint8[0]), - &(ipv6_buf->srcaddr.uint8[0]), sizeof(ipv6_addr_t)); - memcpy(&(ipv6_buf->srcaddr.uint8[0]), - &(nbr_sol_buf->target_addr.uint8[0]), sizeof(ipv6_addr_t)); - send_na = 1; - } - } - - if (send_na) { - /* solicited na */ - uint8_t flags = (ICMPV6_NEIGHBOR_ADV_FLAG_OVERRIDE | ICMPV6_NEIGHBOR_ADV_FLAG_SOLICITED); - icmpv6_send_neighbor_adv(&(ipv6_buf->srcaddr), &(ipv6_buf->destaddr), - alist_targ.addr->addr_data, flags, 0, OPT_ARO); - } -} - -void icmpv6_send_neighbor_adv(ipv6_addr_t *src, ipv6_addr_t *dst, ipv6_addr_t *tgt, - uint8_t rso, uint8_t sllao, uint8_t aro) -{ - int if_id = 0; // TODO: get this somehow - uint16_t packet_length; - - ipv6_buf = ipv6_get_buf(); - ipv6_buf->version_trafficclass = IPV6_VER; - ipv6_buf->trafficclass_flowlabel = 0; - ipv6_buf->flowlabel = 0; - ipv6_buf->nextheader = IPV6_PROTO_NUM_ICMPV6; - ipv6_buf->hoplimit = ND_HOPLIMIT; - - ipv6_ext_hdr_len = 0; - icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len); - icmp_buf->type = ICMPV6_TYPE_NEIGHBOR_ADV; - icmp_buf->code = 0; - - if (&ipv6_buf->destaddr != dst) { - memcpy(&(ipv6_buf->destaddr.uint8[0]), &(dst->uint8[0]), 16); - } - - if (&ipv6_buf->srcaddr != src) { - memcpy(&(ipv6_buf->srcaddr.uint8[0]), &(src->uint8[0]), 16); - } - - nbr_adv_buf = get_nbr_adv_buf(ipv6_ext_hdr_len); - nbr_adv_buf->rso = rso; - - memset(&(nbr_adv_buf->reserved[0]), 0, 3); - memcpy(&(nbr_adv_buf->target_addr.uint8[0]), &(tgt->uint8[0]), 16); - - packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + NBR_ADV_LEN; - - if (sllao == OPT_SLLAO) { - /* set sllao option */ - opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len); - - if (net_if_get_src_address_mode(if_id) == NET_IF_TRANS_ADDR_M_LONG) { - icmpv6_ndp_set_sllao(opt_stllao_buf, if_id, NDP_OPT_SLLAO_TYPE, 2); - icmpv6_opt_hdr_len += OPT_STLLAO_MAX_LEN; - packet_length += OPT_STLLAO_MAX_LEN; - } - else { - icmpv6_ndp_set_sllao(opt_stllao_buf, if_id, NDP_OPT_SLLAO_TYPE, 1); - icmpv6_opt_hdr_len += OPT_STLLAO_MIN_LEN; - packet_length += OPT_STLLAO_MIN_LEN; - } - } - - if (aro == OPT_ARO) { - /* set aro option */ - opt_aro_buf = get_opt_aro_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len); - opt_aro_buf->type = OPT_ARO_TYPE; - opt_aro_buf->length = OPT_ARO_LEN; - opt_aro_buf->status = 0; /* TODO */ - opt_aro_buf->reserved1 = 0; - opt_aro_buf->reserved2 = 0; - - if (net_if_get_src_address_mode(if_id) == NET_IF_TRANS_ADDR_M_SHORT) { - net_if_get_eui64((net_if_eui64_t *) &opt_aro_buf->eui64, if_id, 1); - } - else if (net_if_get_src_address_mode(if_id) == NET_IF_TRANS_ADDR_M_LONG) { - net_if_get_eui64((net_if_eui64_t *) &opt_aro_buf->eui64, if_id, 0); - } - - icmpv6_opt_hdr_len += OPT_ARO_HDR_LEN; - - packet_length += OPT_ARO_HDR_LEN; - } - - ipv6_buf->length = HTONS(packet_length - IPV6_HDR_LEN); - - icmp_buf->checksum = icmpv6_csum(ipv6_buf, icmp_buf); - -#if ENABLE_DEBUG - char addr_str[IPV6_MAX_ADDR_STR_LEN]; - printf("INFO: send neighbor advertisement to: %s\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - &ipv6_buf->destaddr)); -#endif - ipv6_send_packet(ipv6_buf, NULL); -} - -void recv_nbr_adv(void) -{ - ipv6_buf = ipv6_get_buf(); - uint16_t packet_length = IPV6_HDR_LEN + NTOHS(ipv6_buf->length); - icmpv6_opt_hdr_len = NBR_ADV_LEN; - llao = NULL; - nbr_entry = NULL; - nbr_adv_buf = get_nbr_adv_buf(ipv6_ext_hdr_len); - - /* check if options are present */ - while (packet_length > IPV6_HDR_LEN + ICMPV6_HDR_LEN + icmpv6_opt_hdr_len) { - opt_buf = get_opt_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len); - - switch (opt_buf->type) { - case (NDP_OPT_TLLAO_TYPE): { - llao = (uint8_t *)get_opt_stllao_buf(ipv6_ext_hdr_len, - icmpv6_opt_hdr_len); - break; - } - - case (OPT_ARO_TYPE): { - break; - } - } - - icmpv6_opt_hdr_len += (opt_buf->length * 8); - } - - ipv6_net_if_hit_t hit; - - if (ipv6_net_if_addr_match(&hit, &nbr_adv_buf->target_addr) == NULL) { - nbr_entry = ndp_neighbor_cache_search(&nbr_adv_buf->target_addr); - - if (nbr_entry != NULL) { - int8_t new_ll = -1; - if (llao != 0) { - new_ll = memcmp(&llao[2], &(nbr_entry->lladdr), - nbr_entry->lladdr_len); - ((icmpv6_ndp_opt_stllao_t *)llao)->length = nbr_entry->lladdr_len / 8 + 1; - } - - int if_id = 0; // TODO, get this somehow - if (nbr_entry->state == NDP_NCE_STATUS_INCOMPLETE) { - if (llao == NULL) { - return; - } - - if (((icmpv6_ndp_opt_stllao_t *)llao)->length == 2) { - nbr_entry->if_id = if_id; - nbr_entry->lladdr_len = 8; - memcpy(&nbr_entry->lladdr, &llao[2], nbr_entry->lladdr_len); - } - else if (((icmpv6_ndp_opt_stllao_t *)llao)->length == 1) { - nbr_entry->if_id = if_id; - nbr_entry->lladdr_len = 2; - memcpy(&nbr_entry->lladdr, &llao[2], nbr_entry->lladdr_len); - } - else { - return; - } - - if (nbr_adv_buf->rso & ICMPV6_NEIGHBOR_ADV_FLAG_SOLICITED) { - nbr_entry->state = NDP_NCE_STATUS_REACHABLE; - /* TODO: set rechability */ - } - else { - nbr_entry->state = NDP_NCE_STATUS_STALE; - } - - nbr_entry->isrouter = nbr_adv_buf->rso & ICMPV6_NEIGHBOR_ADV_FLAG_ROUTER; - } - else { - if (new_ll && !(nbr_adv_buf->rso & ICMPV6_NEIGHBOR_ADV_FLAG_OVERRIDE)) { - if (nbr_entry->state == NDP_NCE_STATUS_REACHABLE) { - nbr_entry->state = NDP_NCE_STATUS_STALE; - } - - return; - } - else { - if ((nbr_adv_buf->rso & ICMPV6_NEIGHBOR_ADV_FLAG_OVERRIDE) || - (!(nbr_adv_buf->rso & ICMPV6_NEIGHBOR_ADV_FLAG_OVERRIDE) && llao != 0 && - !new_ll)) { - if (llao != 0) { - if (((icmpv6_ndp_opt_stllao_t *)llao)->length == 2) { - nbr_entry->if_id = if_id; - nbr_entry->lladdr_len = 8; - } - else if (((icmpv6_ndp_opt_stllao_t *)llao)->length == 1) { - nbr_entry->if_id = if_id; - nbr_entry->lladdr_len = 2; - } - else { - return; - } - - memcpy(&nbr_entry->lladdr, &llao[2], nbr_entry->lladdr_len); - } - - if (nbr_adv_buf->rso & ICMPV6_NEIGHBOR_ADV_FLAG_SOLICITED) { - nbr_entry->state = NDP_NCE_STATUS_REACHABLE; - /* TODO: set rechablility */ - } - else { - if (llao != 0 && new_ll) { - nbr_entry->state = NDP_NCE_STATUS_STALE; - } - } - } - } - } - } - } -} - -/* link-layer address option - RFC4861 section 4.6.1/ RFC4944 8. */ -void icmpv6_ndp_set_sllao(icmpv6_ndp_opt_stllao_t *sllao, int if_id, - uint8_t type, uint8_t length) -{ - sllao->type = type; - sllao->length = length; - - uint8_t *llao = (uint8_t *)sllao; - - /* get link layer address */ - switch (length) { - case (1): { - uint16_t addr = net_if_get_hardware_address(if_id); - - if (addr != 0) { - addr = HTONS(addr); - memcpy(&llao[2], &addr, 2); - memset(&llao[4], 0, 4); - break; - } - else { - goto SET_SLLAO_DEFAULT; - } - } - - case (2): { - net_if_eui64_t addr; - - if (net_if_get_eui64(&addr, if_id, 0)) { - memcpy(&llao[2], &addr, 8); - memset(&llao[10], 0, 6); - break; - } - else { - goto SET_SLLAO_DEFAULT; - } - } - - SET_SLLAO_DEFAULT: - - default: { - printf("ERROR: llao not set\n"); - break; - } - } -} - -uint16_t icmpv6_csum(ipv6_hdr_t *ipv6_buf, icmpv6_hdr_t *icmpv6_buf) -{ - uint16_t sum; - uint16_t len = NTOHS(ipv6_buf->length); - - icmpv6_buf->checksum = 0; - sum = len + IPV6_PROTO_NUM_ICMPV6; - - sum = net_help_csum(sum, (uint8_t *)&ipv6_buf->srcaddr, 2 * sizeof(ipv6_addr_t)); - sum = net_help_csum(sum, (uint8_t *)icmpv6_buf, len); - - return (sum == 0) ? 0 : ~HTONS(sum); -} - - -void icmpv6_send_parameter_prob(ipv6_addr_t *src, ipv6_addr_t *dest, - uint8_t code, uint32_t pointer, - uint8_t *packet, uint8_t packet_len) -{ - uint16_t packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + PARA_PROB_LEN; - icmpv6_parameter_prob_hdr_t *para_prob_buf; - - memcpy(&(ipv6_buf[packet_length]), packet, min(IPV6_MTU - packet_length, packet_len)); - - ipv6_buf = ipv6_get_buf(); - ipv6_buf->version_trafficclass = IPV6_VER; - ipv6_buf->trafficclass_flowlabel = 0; - ipv6_buf->flowlabel = 0; - ipv6_buf->nextheader = IPV6_PROTO_NUM_ICMPV6; - ipv6_buf->hoplimit = ND_HOPLIMIT; - - ipv6_ext_hdr_len = 0; - icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len); - icmp_buf->type = ICMPV6_TYPE_PARAMETER_PROB; - icmp_buf->code = code; - - memcpy(&(ipv6_buf->destaddr.uint8[0]), &(dest->uint8[0]), 16); - memcpy(&(ipv6_buf->srcaddr.uint8[0]), &(src->uint8[0]), 16); - - para_prob_buf = get_para_prob_buf(ipv6_ext_hdr_len); - - para_prob_buf->pointer = pointer; - - packet_length += min(IPV6_MTU - packet_length, packet_len); - - ipv6_buf->length = HTONS(packet_length - IPV6_HDR_LEN); - - icmp_buf->checksum = icmpv6_csum(ipv6_buf, icmp_buf); - -#if ENABLE_DEBUG - char addr_str[IPV6_MAX_ADDR_STR_LEN]; - printf("INFO: send parameter problem to: %s\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - &ipv6_buf->destaddr)); -#endif - ipv6_send_packet(ipv6_buf, NULL); -} - -//------------------------------------------------------------------------------ -/* neighbor cache functions */ - -ndp_neighbor_cache_t *ndp_neighbor_cache_search(ipv6_addr_t *ipaddr) -{ - int i; - - for (i = 0; i < NBR_CACHE_SIZE; i++) { - if (memcmp(&(nbr_cache[i].addr.uint8[0]), &(ipaddr->uint8[0]), 16) == 0) { - return &nbr_cache[i]; - } - } - - return NULL; -} - -ndp_neighbor_cache_t *ndp_get_ll_address(ipv6_addr_t *ipaddr) -{ - ndp_neighbor_cache_t *nce = ndp_neighbor_cache_search(ipaddr); - - if (nce == NULL || nce->type == NDP_NCE_TYPE_GC || - nce->state == NDP_NCE_STATUS_INCOMPLETE) { - // TODO: send neighbor solicitation, wait, and recheck cache - return NULL; - } - - return nce; -} - -int ndp_addr_is_on_link(ipv6_addr_t *dest_addr) -{ - int if_id = -1; - - if ((ndp_neighbor_cache_search(dest_addr))) { -#if ENABLE_DEBUG - char addr_str[IPV6_MAX_ADDR_STR_LEN]; - DEBUG("INFO: %s is in nbr cache\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, dest_addr)); -#endif - return 1; - } - - while ((if_id = net_if_iter_interfaces(if_id)) >= 0) { - ndp_prefix_info_t *pi; - if ((pi = ndp_prefix_info_search(if_id, dest_addr, 128))) { - return (pi->flags & ICMPV6_NDP_OPT_PI_FLAG_ON_LINK) != 0; - } - } - - /* TODO Other cases (http://tools.ietf.org/html/rfc4861#page-6): - * * neighboring router specifies address as target of - * redircect message - * * neighbor discovery message is received from address. - */ - - return 0; -} - -uint8_t ndp_neighbor_cache_add(int if_id, const ipv6_addr_t *ipaddr, - const void *lladdr, uint8_t lladdr_len, - uint8_t isrouter, ndp_nce_state_t state, - ndp_nce_type_t type, uint16_t ltime) -{ - (void) ltime; - - if (nbr_count == NBR_CACHE_SIZE) { - printf("ERROR: neighbor cache full\n"); - return NDP_OPT_ARO_STATE_NBR_CACHE_FULL; - } - - nbr_cache[nbr_count].if_id = if_id; - memcpy(&(nbr_cache[nbr_count].addr), ipaddr, 16); - memcpy(&(nbr_cache[nbr_count].lladdr), lladdr, lladdr_len); - nbr_cache[nbr_count].lladdr_len = lladdr_len; - nbr_cache[nbr_count].isrouter = isrouter; - nbr_cache[nbr_count].state = state; - nbr_cache[nbr_count].type = type; - - //vtimer_set_wakeup(&(nbr_cache[nbr_count].ltime), t, - /* nd_nbr_cache_rem_pid); */ - - nbr_count++; - - return NDP_OPT_ARO_STATE_SUCCESS; -} - -void nbr_cache_auto_rem(void) -{ - int i; - - for (i = 0; i < NBR_CACHE_SIZE; i++) { - if (get_remaining_time(&(nbr_cache[i].ltime)) == 0 && - nbr_cache[i].type == NDP_NCE_TYPE_TENTATIVE) { - memmove(&(nbr_cache[i]), &(nbr_cache[nbr_count]), - sizeof(ndp_neighbor_cache_t)); - memset(&(nbr_cache[nbr_count]), 0, sizeof(ndp_neighbor_cache_t)); - nbr_count--; - } - } -} - -uint8_t ndp_neighbor_cache_remove(const ipv6_addr_t *ipaddr) -{ - int i; - uint8_t removed = 0; - - for (i = 0; i < NBR_CACHE_SIZE; i++) { - if (memcmp(&(nbr_cache[i].addr.uint8[0]), &(ipaddr->uint8[0]), 16) == 0) { - memmove(&(nbr_cache[i]), &(nbr_cache[nbr_count]), - sizeof(ndp_neighbor_cache_t)); - memset(&(nbr_cache[nbr_count]), 0, sizeof(ndp_neighbor_cache_t)); - nbr_count--; - removed = 1; - } - } - - return removed; -} - -//------------------------------------------------------------------------------ -/* authoritive border router list functions */ -/** - * @brief Finds the most current (by version number) authoritive border - * router information. - * @pre assumes that abro versions are centrally managed - * @return The most current authoritive border router information, NULL - * if no such information is given. - */ -ndp_a6br_cache_t *ndp_a6br_cache_get_most_current(void) -{ - ndp_a6br_cache_t *abr = NULL; - int i; - int version = abr_cache[0].version; - - for (i = 0; i < abr_count; i++) { - if (serial_comp16(version, abr_cache[i].version) == GREATER) { - abr = &(abr_cache[i]); - version = abr_cache[i].version; - } - } - - return abr; -} - -ndp_a6br_cache_t *ndp_a6br_cache_get_oldest(void) -{ - ndp_a6br_cache_t *abr = NULL; - int i; - int version = abr_cache[0].version; - - for (i = 0; i < abr_count; i++) { - if (serial_comp16(version, abr_cache[i].version) == LESS) { - abr = &(abr_cache[i]); - version = abr_cache[i].version; - } - } - - return abr; -} - -ndp_a6br_cache_t *abr_get_version(uint16_t version, ipv6_addr_t *abr_addr) -{ - int i = 0; - - for (i = 0; i < ABR_CACHE_SIZE; i++) { - if (abr_cache[i].version == version && - memcmp(&(abr_cache[i].abr_addr.uint8[0]), - &(abr_addr->uint8[0]), 16 - ) == 0) { - return &(abr_cache[i]); - } - } - - return NULL; -} - -lowpan_context_t *abr_get_context(ndp_a6br_cache_t *abr, uint8_t cid) -{ - if (abr->cids[cid] != cid) { - return NULL; - } - - return lowpan_context_num_lookup(abr->cids[cid]); -} - -ndp_a6br_cache_t *abr_add_context(uint16_t version, ipv6_addr_t *abr_addr, - uint8_t cid) -{ - ndp_a6br_cache_t *abr = abr_get_version(version, abr_addr); - - if (abr == NULL) { - if (abr_count == ABR_CACHE_SIZE) { - abr = ndp_a6br_cache_get_oldest(); - } - else { - abr = &(abr_cache[abr_count++]); - } - - abr->version = version; - memcpy(&(abr->abr_addr), abr_addr, sizeof(ipv6_addr_t)); - memset(abr->cids, 0xFF, NDP_6LOWPAN_CONTEXT_MAX); - } - - abr->cids[cid] = cid; - - return abr; -} - -void abr_remove_context(uint8_t cid) -{ - int i; - - for (i = 0; i < abr_count; i++) { - abr_cache[i].cids[cid] = 0xFF; - } -} - -//------------------------------------------------------------------------------ -/* default router list functions */ - -ndp_default_router_list_t *ndp_default_router_list_search(ipv6_addr_t *ipaddr) -{ - int i; - - for (i = 0; i < DEF_RTR_LST_SIZE; i++) { - if (memcmp(&def_rtr_lst[i].addr.uint8[0], - &(ipaddr->uint8[0]), 16) == 0) { - return &def_rtr_lst[i]; - } - } - - return NULL; -} - -void def_rtr_lst_add(ipv6_addr_t *ipaddr, uint32_t rtr_ltime) -{ - if (def_rtr_count == DEF_RTR_LST_SIZE) { - DEBUG("ERROR: default router list full\n"); - } - else { - memcpy(&(def_rtr_lst[def_rtr_count].addr), ipaddr, 16); - timex_t rltime = {rtr_ltime, 0}; - timex_t now; - vtimer_now(&now); - - def_rtr_lst[def_rtr_count].inval_time = timex_add(now, rltime); - - def_rtr_count++; - } -} - -void def_rtr_lst_rem(ndp_default_router_list_t *entry) -{ - int i; - - for (i = 0; i < DEF_RTR_LST_SIZE; i++) { - if (&def_rtr_lst[i] == entry) { - /* search the to deleted item, then memmove the last item to its - * position, and decrement array count */ - memmove(entry, &def_rtr_lst[def_rtr_count], sizeof(ndp_default_router_list_t)); - memset(&def_rtr_lst[def_rtr_count], 0, sizeof(ndp_default_router_list_t)); - def_rtr_count--; - } - } -} - -//------------------------------------------------------------------------------ -/* prefix information functions */ - -int ndp_add_prefix_info(int if_id, const ipv6_addr_t *prefix, - uint8_t prefix_len, uint32_t valid_lifetime, - uint32_t preferred_lifetime, uint8_t advertisable, - uint8_t flags) -{ - ndp_prefix_info_t *prefix_info = ndp_prefix_info_match(if_id, prefix, - prefix_len); - - if (prefix_info) { - prefix_info->inuse = 1; - prefix_info->advertisable = advertisable; - prefix_info->flags = 0xc0 & flags; - prefix_info->valid_lifetime = HTONL(valid_lifetime); - prefix_info->preferred_lifetime = HTONL(preferred_lifetime); - - return SIXLOWERROR_SUCCESS; - } - - if ((prefix_info_count >= PREFIX_BUF_LEN) || - (prefix_buf_count >= sizeof(prefix_buf))) { - return SIXLOWERROR_ARRAYFULL; - } - - if (prefix_len > 128) { - prefix_len = 128; - } - - prefix_info = &prefix_info_buf[prefix_info_count]; - - if (prefix_len > 0) { - memcpy(&prefix_buf[prefix_buf_count], prefix, (prefix_len / 8) + 1); - } - - prefix_info->prefix_data = (ipv6_addr_t *) &prefix_buf[prefix_buf_count]; - prefix_buf_count += prefix_len; - - prefix_info->prefix_len = prefix_len; - prefix_info->prefix_protocol = NET_IF_L3P_IPV6_PREFIX; - prefix_info->inuse = 1; - prefix_info->advertisable = advertisable; - prefix_info->flags = 0xc0 & flags; - prefix_info->valid_lifetime = HTONL(valid_lifetime); - prefix_info->preferred_lifetime = HTONL(preferred_lifetime); - - if (!net_if_add_address(if_id, (net_if_addr_t *) prefix_info)) { - return SIXLOWERROR_VALUE; - } - - prefix_info_count++; - - return SIXLOWERROR_SUCCESS; -} - -ndp_prefix_info_t *ndp_prefix_info_search(int if_id, const ipv6_addr_t *addr, - uint8_t up_to) -{ - uint8_t best_match = 0; - ndp_prefix_info_t *prefix = NULL, *tmp = NULL; - - if (up_to > 128) { - up_to = 128; - } - - while (net_if_iter_addresses(if_id, (net_if_addr_t **) &prefix)) { - if (prefix->prefix_protocol & NET_IF_L3P_IPV6_PREFIX) { - uint8_t match = 0, len = min(up_to, prefix->prefix_len); - uint8_t byte_len = (len / 8); - - for (int i = 0; i < byte_len; i++) { - if (addr->uint8[i] != prefix->prefix_data->uint8[i]) { - break; - } - - match += 8; - } - - if (byte_len < 16) { - for (int i = len % 8; i > 0; i--) { - if (addr->uint8[byte_len] >> i != - prefix->prefix_data->uint8[byte_len] >> i) { - break; - } - - match += 1; - } - } - - if ((prefix->prefix_len != 0) && (match > best_match)) { - tmp = prefix; - best_match = match; - } - } - } - - return tmp; -} - -ndp_prefix_info_t *ndp_prefix_info_match(int if_id, const ipv6_addr_t *prefix, - uint8_t prefix_len) -{ - ndp_prefix_info_t *res = ndp_prefix_info_search(if_id, prefix, - prefix_len); - - if (res != NULL && res->prefix_len == prefix_len) { - return res; - } - else { - return NULL; - } -} diff --git a/sys/net/network_layer/sixlowpan/icmp.h b/sys/net/network_layer/sixlowpan/icmp.h deleted file mode 100644 index 4a1f459322..0000000000 --- a/sys/net/network_layer/sixlowpan/icmp.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 6lowpan neighbor discovery - * - * Copyright (C) 2013 INRIA. - * - * 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 net_sixlowpan - * @{ - * @file - * @brief 6lowpan neighbor discovery constants, data structs, and prototypes - * @author Stephan Zeisberg - * @author Martine Lenders - * @author Oliver Gesch - * @} - */ - -#ifndef _SIXLOWPAN_ICMP_H -#define _SIXLOWPAN_ICMP_H - -#include - -#include "vtimer.h" -#include "sixlowpan/icmp.h" -#include "sixlowpan/ndp.h" -#include "sixlowpan/types.h" - -#include "lowpan.h" -#include "ip.h" - -#ifdef __cplusplus -extern "C" { -#endif - -enum option_types_t { - OPT_SLLAO = 1, - OPT_TLLAO, - OPT_PI, - OPT_MTU, - OPT_ARO, - OPT_6CO, - OPT_ABRO, - OPT_DAR, - OPT_DAC, -}; - -extern kernel_pid_t nd_nbr_cache_rem_pid; - - -void recv_echo_req(void); -void recv_echo_repl(void); -void recv_rtr_sol(void); -void recv_rtr_adv(void); -void recv_nbr_adv(void); -void recv_nbr_sol(void); - -void nbr_cache_auto_rem(void); -ndp_a6br_cache_t *abr_add_context(uint16_t version, ipv6_addr_t *abr_addr, - uint8_t cid); -void abr_remove_context(uint8_t cid); - -#ifdef __cplusplus -} -#endif - -#endif /* _SIXLOWPAN_ICMP_H*/ diff --git a/sys/net/network_layer/sixlowpan/ip.c b/sys/net/network_layer/sixlowpan/ip.c deleted file mode 100644 index 93e35b9fa1..0000000000 --- a/sys/net/network_layer/sixlowpan/ip.c +++ /dev/null @@ -1,943 +0,0 @@ -/* - * IPv6 implementation - * - * Copyright (C) 2013 INRIA. - * - * 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 sixlowpan - * @{ - * @file - * @brief 6lowpan IP layer functions - * @author Stephan Zeisberg - * @author Martine Lenders - * @author Eric Engel - * @author Oliver Gesch - * @} - */ - -#include -#include -#include - -#include "vtimer.h" -#include "mutex.h" -#include "msg.h" -#include "net_if.h" -#include "sixlowpan/mac.h" - -#include "ip.h" -#include "icmp.h" -#include "lowpan.h" - -#ifdef FIB_COMPAT -#include "ng_fib.h" -#endif - -#include "net_help.h" - -#define ENABLE_DEBUG (0) -#if ENABLE_DEBUG -static char addr_str[IPV6_MAX_ADDR_STR_LEN]; -#endif -#include "debug.h" - -#define IP_PKT_RECV_BUF_SIZE (64) -#define LLHDR_IPV6HDR_LEN (LL_HDR_LEN + IPV6_HDR_LEN) -#define IPV6_NET_IF_ADDR_BUFFER_LEN (NET_IF_MAX * IPV6_NET_IF_ADDR_LIST_LEN) - -static uint8_t ip_send_buffer[BUFFER_SIZE]; -uint8_t sixlowpan_buffer[BUFFER_SIZE]; -static msg_t ip_msg_queue[IP_PKT_RECV_BUF_SIZE]; -static ipv6_hdr_t *ipv6_buf; -static icmpv6_hdr_t *icmp_buf; -static uint8_t *nextheader; - -kernel_pid_t udp_packet_handler_pid = KERNEL_PID_UNDEF; -kernel_pid_t tcp_packet_handler_pid = KERNEL_PID_UNDEF; - -static volatile kernel_pid_t _rpl_process_pid = KERNEL_PID_UNDEF; -#ifndef FIB_COMPAT -ipv6_addr_t *(*ip_get_next_hop)(ipv6_addr_t *); -#endif -uint8_t (*ip_srh_indicator)(void); - -static ipv6_net_if_ext_t ipv6_net_if_ext[NET_IF_MAX]; -static ipv6_net_if_addr_t ipv6_net_if_addr_buffer[IPV6_NET_IF_ADDR_BUFFER_LEN]; -static ipv6_addr_t ipv6_addr_buffer[IPV6_NET_IF_ADDR_BUFFER_LEN]; -static uint8_t ipv6_net_if_addr_buffer_count = 0; - -static uint8_t default_hop_limit = MULTIHOP_HOPLIMIT; - -/* registered upper layer threads */ -kernel_pid_t sixlowip_reg[SIXLOWIP_MAX_REGISTERED]; - -int ipv6_send_packet(ipv6_hdr_t *packet, ipv6_addr_t *next_hop) -{ - uint16_t length = IPV6_HDR_LEN + NTOHS(packet->length); - ndp_neighbor_cache_t *nce; - - if (next_hop == NULL) { - DEBUGF("Got a packet to send to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &packet->destaddr)); - ipv6_net_if_get_best_src_addr(&packet->srcaddr, &packet->destaddr); - } - - if (!ipv6_addr_is_multicast(&packet->destaddr) - && ndp_addr_is_on_link(&packet->destaddr)) { - /* not multicast, on-link */ - nce = ndp_get_ll_address(&packet->destaddr); - - if (nce == NULL - || sixlowpan_lowpan_sendto(nce->if_id, &nce->lladdr, - nce->lladdr_len, (uint8_t *) packet, length) < 0) { - /* XXX: this is wrong, but until ND does work correctly, - * this is the only way (aka the old way)*/ - uint16_t raddr = NTOHS(packet->destaddr.uint16[7]); - sixlowpan_lowpan_sendto(0, &raddr, 2, (uint8_t *) packet, length); - /* return -1; */ - } - - return length; - } - else { - /* see if dest should be routed to a different next hop */ - if (ipv6_addr_is_multicast(&packet->destaddr)) { - /* if_id will be ignored */ - uint16_t addr = TRANSCEIVER_BROADCAST; - return sixlowpan_lowpan_sendto(0, &addr, 2, (uint8_t *) packet, - length); - } - - if (next_hop == NULL) { - DEBUG("Trying to find the next hop for %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &packet->destaddr)); - -#ifdef FIB_COMPAT - ipv6_addr_t nxt; - ipv6_addr_t *dest; - kernel_pid_t iface_id; - size_t nxt_size = sizeof(ipv6_addr_t); - uint32_t nxt_flags; - - int ret = fib_get_next_hop(&iface_id, &nxt.uint8[0], &nxt_size, &nxt_flags, - &packet->destaddr.uint8[0], sizeof(ipv6_addr_t), AF_INET6); - - if (ret == -EHOSTUNREACH) { - return -1; - } - dest = &nxt; -#else - if (ip_get_next_hop == NULL) { - return -1; - } - - ipv6_addr_t *dest = ip_get_next_hop(&packet->destaddr); - - if (dest == NULL) { - return -1; - } -#endif - nce = ndp_get_ll_address(dest); - - if (nce == NULL - || sixlowpan_lowpan_sendto(nce->if_id, &nce->lladdr, - nce->lladdr_len, (uint8_t *) packet, length) < 0) { - /* XXX: this is wrong, but until ND does work correctly, - * this is the only way (aka the old way)*/ - uint16_t raddr = TRANSCEIVER_BROADCAST; /* Broadcast message */ - sixlowpan_lowpan_sendto(0, &raddr, 2, (uint8_t *) packet, - length); - /* return -1; */ - } - } - else { - DEBUGF("Set destination based on next-hop: %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, next_hop)); - nce = ndp_get_ll_address(next_hop); - - if (nce == NULL - || sixlowpan_lowpan_sendto(nce->if_id, &nce->lladdr, - nce->lladdr_len, (uint8_t *) packet, length) < 0) { - /* XXX: this is wrong, but until ND does work correctly, - * this is the only way (aka the old way)*/ - uint16_t raddr = next_hop->uint16[7]; - sixlowpan_lowpan_sendto(0, &raddr, 2, (uint8_t *) packet, - length); - /* return -1; */ - } - } - - return length; - } -} - -ipv6_hdr_t *ipv6_get_buf_send(void) -{ - return ((ipv6_hdr_t *) &ip_send_buffer[LL_HDR_LEN]); -} - -uint8_t *get_payload_buf_send(uint8_t ext_len) -{ - return &(ip_send_buffer[LLHDR_IPV6HDR_LEN + ext_len]); -} - -ipv6_hdr_t *ipv6_get_buf(void) -{ - return ((ipv6_hdr_t *) &sixlowpan_buffer[LL_HDR_LEN]); -} - -icmpv6_hdr_t *get_icmpv6_buf(uint8_t ext_len) -{ - return ((icmpv6_hdr_t *) &sixlowpan_buffer[LLHDR_IPV6HDR_LEN + ext_len]); -} - -uint8_t *get_payload_buf(uint8_t ext_len) -{ - return &(sixlowpan_buffer[LLHDR_IPV6HDR_LEN + ext_len]); -} - -int ipv6_sendto(const ipv6_addr_t *dest, uint8_t next_header, - const uint8_t *payload, uint16_t payload_length, ipv6_addr_t *next_hop) -{ - uint8_t *p_ptr; - - if (next_header == IPV6_PROTO_NUM_TCP) { - p_ptr = get_payload_buf_send(ipv6_ext_hdr_len); - ipv6_buf = ipv6_get_buf_send(); - } - else { - ipv6_buf = ipv6_get_buf(); - p_ptr = get_payload_buf(ipv6_ext_hdr_len); - } - - ipv6_buf->version_trafficclass = IPV6_VER; - ipv6_buf->trafficclass_flowlabel = 0; - ipv6_buf->flowlabel = 0; - ipv6_buf->nextheader = next_header; - ipv6_buf->hoplimit = MULTIHOP_HOPLIMIT; - ipv6_buf->length = HTONS(payload_length); - - memcpy(&(ipv6_buf->destaddr), dest, 16); - memcpy(p_ptr, payload, payload_length); - return ipv6_send_packet(ipv6_buf, next_hop); -} - -void ipv6_set_default_hop_limit(uint8_t hop_limit) -{ - default_hop_limit = hop_limit; -} - -uint8_t ipv6_get_default_hop_limit(void) -{ - return default_hop_limit; -} - -/* Register an upper layer thread */ -uint8_t ipv6_register_packet_handler(kernel_pid_t pid) -{ - uint8_t i; - - for (i = 0; - ((i < SIXLOWIP_MAX_REGISTERED) && (sixlowip_reg[i] != pid) - && (sixlowip_reg[i] != 0)); i++) { - ; - } - - if (i >= SIXLOWIP_MAX_REGISTERED) { - return ENOMEM; - } - else { - sixlowip_reg[i] = pid; - return 1; - } -} - -int icmpv6_demultiplex(const icmpv6_hdr_t *hdr) -{ - switch (hdr->type) { - case (ICMPV6_TYPE_ECHO_REQUEST): { - DEBUG("INFO: packet type: icmp echo request\n"); - /* processing echo request */ - recv_echo_req(); - break; - } - - case (ICMPV6_TYPE_ECHO_REPLY): { - DEBUG("INFO: packet type: icmp echo reply\n"); - /* processing echo reply */ - recv_echo_repl(); - break; - } - - case (ICMPV6_TYPE_ROUTER_SOL): { - DEBUG("INFO: packet type: icmp router solicitation\n"); - /* processing router solicitation */ - recv_rtr_sol(); - /* init solicited router advertisment*/ - break; - } - - case (ICMPV6_TYPE_ROUTER_ADV): { - DEBUG("INFO: packet type: icmp router advertisment\n"); - /* processing router advertisment */ - recv_rtr_adv(); - /* init neighbor solicitation */ - break; - } - - case (ICMPV6_TYPE_NEIGHBOR_SOL): { - DEBUG("INFO: packet type: icmp neighbor solicitation\n"); - recv_nbr_sol(); - break; - } - - case (ICMPV6_TYPE_NEIGHBOR_ADV): { - DEBUG("INFO: packet type: icmp neighbor advertisment\n"); - recv_nbr_adv(); - break; - } - - case (ICMPV6_TYPE_RPL_CONTROL): { - DEBUG("INFO: packet type: RPL message\n"); - - if (_rpl_process_pid != KERNEL_PID_UNDEF) { - msg_t m_send; - m_send.content.ptr = (char *) ipv6_buf; - m_send.type = ((icmpv6_hdr_t *)(m_send.content.ptr + IPV6_HDR_LEN))->code; - msg_send(&m_send, _rpl_process_pid); - } - else { - DEBUG("INFO: no RPL handler registered\n"); - } - - break; - } - - default: - return -1; - } - - return 0; -} - -uint8_t ipv6_get_addr_match(const ipv6_addr_t *src, const ipv6_addr_t *dst) -{ - uint8_t val = 0, xor; - - for (int i = 0; i < 16; i++) { - /* if bytes are equal add 8 */ - if (src->uint8[i] == dst->uint8[i]) { - val += 8; - } - else { - xor = src->uint8[i] ^ dst->uint8[i]; - - /* while bits from byte equal add 1 */ - for (int j = 0; j < 8; j++) { - if ((xor & 0x80) == 0) { - val++; - xor = xor << 1; - } - else { - break; - } - } - - break; - } - } - - return val; -} - -/** - * @brief Check if the given IPv6 address is assigned to any configured - * interface - * - * @param[in] addr The IPv6 address to check - * - * @return 1 If *addr* is assigned to at least one interface - * @return 0 If *addr* is not assigned to any interface - * @return -1 If no IPv6 address is configured to any interface - */ -static int is_our_address(ipv6_addr_t *addr) -{ - int if_id = -1; - int if_counter = -1; - - DEBUGF("Is this my address: %s?\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, addr)); - - while ((if_id = net_if_iter_interfaces(if_id)) >= 0) { - ipv6_net_if_ext_t *net_if_ext = ipv6_net_if_get_ext(if_id); - ipv6_net_if_addr_t *myaddr = NULL; - uint8_t prefix = net_if_ext->prefix / 8; - uint8_t suffix = IPV6_ADDR_LEN - prefix; - - while ((myaddr = (ipv6_net_if_addr_t *) net_if_iter_addresses(if_id, - (net_if_addr_t **) &myaddr)) != NULL) { - if_counter++; - DEBUGF("\tCompare with: %s?\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, (ipv6_addr_t *) myaddr->addr_data)); - - if ((ipv6_get_addr_match(myaddr->addr_data, addr) - >= net_if_ext->prefix) - && (memcmp(&addr->uint8[prefix], - &myaddr->addr_data->uint8[prefix], suffix) == 0)) { - DEBUGF("Found my address\n"); - return 1; - } - } - } - - /* return negative value if no address is configured so far */ - if (if_counter >= 0) { - return 0; - } - - return -1; -} - -void *ipv6_process(void *arg) -{ - (void) arg; - - msg_t m_recv_lowpan, m_send_lowpan; - msg_t m_recv, m_send; - uint8_t i; - uint16_t packet_length; - - msg_init_queue(ip_msg_queue, IP_PKT_RECV_BUF_SIZE); - - while (1) { - msg_receive(&m_recv_lowpan); - - ipv6_buf = (ipv6_hdr_t *) m_recv_lowpan.content.ptr; - - /* identifiy packet */ - nextheader = &ipv6_buf->nextheader; - - for (i = 0; i < SIXLOWIP_MAX_REGISTERED; i++) { - if (sixlowip_reg[i]) { - msg_t m_send; - m_send.type = IPV6_PACKET_RECEIVED; - m_send.content.ptr = (char *) ipv6_buf; - msg_send(&m_send, sixlowip_reg[i]); - } - } - - int addr_match = is_our_address(&ipv6_buf->destaddr); - DEBUGF("Did it match? %d\n", addr_match); - - /* no address configured for this node so far, exit early */ - if (addr_match < 0) { - msg_reply(&m_recv_lowpan, &m_send_lowpan); - continue; - } - /* destination is our address */ - else if (addr_match) { - switch (*nextheader) { - case (IPV6_PROTO_NUM_ICMPV6): { - icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len); - - /* checksum test*/ - if (ipv6_csum(ipv6_buf, (uint8_t *) icmp_buf, - NTOHS(ipv6_buf->length), IPV6_PROTO_NUM_ICMPV6) - != 0xffff) { - DEBUG("ERROR: wrong checksum\n"); - } - - icmpv6_demultiplex(icmp_buf); - break; - } - - case (IPV6_PROTO_NUM_TCP): { - if (tcp_packet_handler_pid != KERNEL_PID_UNDEF) { - m_send.content.ptr = (char *) ipv6_buf; - msg_send_receive(&m_send, &m_recv, tcp_packet_handler_pid); - } - else { - DEBUG("INFO: No TCP handler registered.\n"); - } - - break; - } - - case (IPV6_PROTO_NUM_UDP): { - if (udp_packet_handler_pid != KERNEL_PID_UNDEF) { - m_send.content.ptr = (char *) ipv6_buf; - msg_send_receive(&m_send, &m_recv, udp_packet_handler_pid); - } - else { - DEBUG("INFO: No UDP handler registered.\n"); - } - - break; - } - - case (IPV6_PROTO_NUM_SRH): { - if (_rpl_process_pid != KERNEL_PID_UNDEF) { - m_send.content.ptr = (char *) ipv6_buf; - msg_send(&m_send, _rpl_process_pid); - } - else { - DEBUG("INFO: no RPL handler registered\n"); - } - - break; - } - - case (IPV6_PROTO_NUM_NONE): { - DEBUG("INFO: Packet with no Header following the IPv6 Header received.\n"); - break; - } - - default: - DEBUG("INFO: Unknown next header\n"); - break; - } - } - /* destination is foreign address */ - else { - DEBUG("That's not for me, destination is %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &ipv6_buf->destaddr)); - - if ((ip_srh_indicator != NULL) - && (ipv6_buf->nextheader != IPV6_PROTO_NUM_ICMPV6) - && (ip_srh_indicator() == 1)) { - if (_rpl_process_pid != KERNEL_PID_UNDEF) { - m_send.content.ptr = (char *) ipv6_buf; - msg_send(&m_send, _rpl_process_pid); - } - else { - DEBUG("INFO: no RPL handler registered\n"); - } - } - else { - - packet_length = IPV6_HDR_LEN + NTOHS(ipv6_buf->length); - ndp_neighbor_cache_t *nce; - - ipv6_addr_t *dest; -#ifdef FIB_COMPAT - ipv6_addr_t nxt; - kernel_pid_t iface_id; - size_t nxt_size = sizeof(ipv6_addr_t); - uint32_t nxt_flags; - - int ret = fib_get_next_hop(&iface_id, - &nxt.uint8[0], &nxt_size, &nxt_flags, - &ipv6_buf->destaddr.uint8[0], - sizeof(ipv6_addr_t), AF_INET6); - - if (ret == -EHOSTUNREACH) { - memcpy(&nxt, &ipv6_buf->destaddr, sizeof(ipv6_addr_t)); - } - dest = &nxt; -#else - if (ip_get_next_hop == NULL) { - dest = &ipv6_buf->destaddr; - } - else { - dest = ip_get_next_hop(&ipv6_buf->destaddr); - } -#endif - if ((dest == NULL) || ((--ipv6_buf->hoplimit) == 0)) { - DEBUG("!!! Packet not for me, routing handler is set, but I " - " have no idea where to send or the hop limit is exceeded.\n"); - msg_reply(&m_recv_lowpan, &m_send_lowpan); - continue; - } - - nce = ndp_get_ll_address(dest); - - /* copy received packet to send buffer */ - memcpy(ipv6_get_buf_send(), ipv6_get_buf(), packet_length); - - /* send packet to node ID derived from dest IP */ - if (nce != NULL) { - sixlowpan_lowpan_sendto(nce->if_id, &nce->lladdr, - nce->lladdr_len, (uint8_t *) ipv6_get_buf_send(), - packet_length); - } - else { - /* XXX: this is wrong, but until ND does work correctly, - * this is the only way (aka the old way)*/ - uint16_t raddr = dest->uint16[7]; - sixlowpan_lowpan_sendto(0, &raddr, 2, - (uint8_t *) ipv6_get_buf_send(), packet_length); - } - } - } - - msg_reply(&m_recv_lowpan, &m_send_lowpan); - } -} - -ipv6_net_if_ext_t *ipv6_net_if_get_ext(int if_id) -{ - if (net_if_get_interface(if_id)) { - return &ipv6_net_if_ext[if_id]; - } - else { - return NULL; - } -} - -int ipv6_net_if_add_addr(int if_id, const ipv6_addr_t *addr, - ndp_addr_state_t state, uint32_t val_ltime, uint32_t pref_ltime, - uint8_t is_anycast) -{ - ipv6_net_if_hit_t hit; - - if (ipv6_addr_is_unspecified(addr) == 128) { - DEBUG("ERROR: unspecified address (::) can't be assigned to interface.\n"); - return 0; - } - - if (ipv6_addr_is_multicast(addr) && is_anycast) { - DEBUG("ERROR: anycast addresses must not be multicast addresses " - "(i.e. start with ff::/2)\n"); - return 0; - } - - if (ipv6_net_if_addr_match(&hit, addr)) { - return 1; - } - - if (ipv6_net_if_addr_buffer_count < IPV6_NET_IF_ADDR_BUFFER_LEN) { - timex_t valtime = { val_ltime, 0 }; - timex_t preftime = { pref_ltime, 0 }; - timex_t now; - - vtimer_now(&now); - - ipv6_addr_t *addr_data = - &ipv6_addr_buffer[ipv6_net_if_addr_buffer_count]; - memcpy(addr_data, addr, sizeof(ipv6_addr_t)); - - ipv6_net_if_addr_t *addr_entry = - &ipv6_net_if_addr_buffer[ipv6_net_if_addr_buffer_count]; - addr_entry->addr_data = addr_data; - addr_entry->addr_len = 128; - - if (is_anycast) { - addr_entry->addr_protocol = NET_IF_L3P_IPV6_ANYCAST; - } - else if (ipv6_addr_is_multicast(addr_data)) { - addr_entry->addr_protocol = NET_IF_L3P_IPV6_MULTICAST; - } - else { - addr_entry->addr_protocol = NET_IF_L3P_IPV6_UNICAST; - } - - addr_entry->ndp_state = state; - addr_entry->valid_lifetime = timex_add(now, valtime); - addr_entry->preferred_lifetime = timex_add(now, preftime); - addr_entry->is_anycast = is_anycast; - - ipv6_net_if_addr_buffer_count++; - - net_if_add_address(if_id, (net_if_addr_t *) addr_entry); - - /* Register to Solicited-Node multicast address according to RFC 4291 */ - if (is_anycast || !ipv6_addr_is_multicast(addr)) { - ipv6_addr_t sol_node_mcast_addr; - ipv6_addr_set_solicited_node_addr(&sol_node_mcast_addr, addr); - - if (ipv6_net_if_addr_match(&hit, &sol_node_mcast_addr) == NULL) { - ipv6_net_if_add_addr(if_id, &sol_node_mcast_addr, state, - val_ltime, pref_ltime, 0); - } - } - - return 1; - } - - return 0; -} - -ipv6_net_if_hit_t *ipv6_net_if_addr_match(ipv6_net_if_hit_t *hit, - const ipv6_addr_t *addr) -{ - int if_id = -1; - ipv6_net_if_addr_t *addr_entry = NULL; - - while ((if_id = net_if_iter_interfaces(if_id)) >= 0) { - while (net_if_iter_addresses(if_id, (net_if_addr_t **) &addr_entry) - != NULL) { - if (addr_entry->addr_protocol & NET_IF_L3P_IPV6) { - uint8_t byte_al = addr_entry->addr_len / 8; - uint8_t mask[] = { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, - 0xfe - }; - - if (memcmp(addr_entry->addr_data, addr, byte_al) == 0 - && (addr_entry->addr_len % 8 == 0 - || ((addr_entry->addr_data->uint8[byte_al] - - addr->uint8[byte_al]) - & mask[addr_entry->addr_len - - (byte_al * 8)]))) { - hit->if_id = if_id; - hit->addr = addr_entry; - return hit; - } - } - } - } - - return NULL; -} - -ipv6_net_if_hit_t *ipv6_net_if_addr_prefix_eq(ipv6_net_if_hit_t *hit, - ipv6_addr_t *addr) -{ - int if_id = -1; - ipv6_net_if_addr_t *addr_entry = NULL; - - while ((if_id = net_if_iter_interfaces(if_id)) >= 0) { - while (net_if_iter_addresses(if_id, (net_if_addr_t **) &addr_entry) - != NULL) { - if (addr_entry->addr_protocol & NET_IF_L3P_IPV6) { - if (memcmp(addr_entry->addr_data, addr, 8) == 0) { - hit->if_id = if_id; - hit->addr = addr_entry; - return hit; - } - } - } - } - - return NULL; -} - -/* TODO ipv6_net_if_hit_t returning function similar wrapping - * ipv6_net_if_get_best_src_addr() to search on all interfaces */ - -ipv6_addr_t *ipv6_addr_set_by_eui64(ipv6_addr_t *out, int if_id, - const ipv6_addr_t *prefix) -{ - uint8_t force_generation = 0; - out->uint16[0] = prefix->uint16[0]; - out->uint16[1] = prefix->uint16[1]; - out->uint16[2] = prefix->uint16[2]; - out->uint16[3] = prefix->uint16[3]; - - if (net_if_get_src_address_mode(if_id) == NET_IF_TRANS_ADDR_M_SHORT) { - force_generation = 1; - } - - if (net_if_get_eui64((net_if_eui64_t *) &out->uint8[8], if_id, - force_generation)) { - out->uint8[8] ^= 0x02; - return out; - } - else { - return NULL; - } -} - -void ipv6_addr_init_prefix(ipv6_addr_t *out, const ipv6_addr_t *prefix, - uint8_t bits) -{ - if (bits > 128) { - bits = 128; - } - - uint8_t bytes = bits / 8, mask; - - if (bits % 8) { - mask = 0xff << (8 - (bits - (bytes * 8))); - } - else { - mask = 0x00; - } - - memcpy(out, prefix, bytes); - - if (bytes < 16) { - out->uint8[bytes] = prefix->uint8[bytes] & mask; - } - - memset(&(out->uint8[bytes + 1]), 0, 15 - bytes); -} - -void ipv6_net_if_get_best_src_addr(ipv6_addr_t *src, const ipv6_addr_t *dest) -{ - /* try to find best match if dest is not mcast or link local */ - int if_id = 0; // TODO: get this somehow - ipv6_net_if_addr_t *addr = NULL; - ipv6_net_if_addr_t *tmp_addr = NULL; - - if (!(ipv6_addr_is_link_local(dest)) && !(ipv6_addr_is_multicast(dest))) { - uint8_t bmatch = 0; - while ((addr = (ipv6_net_if_addr_t *) net_if_iter_addresses(if_id, - (net_if_addr_t **) &addr))) { - if (addr->ndp_state == NDP_ADDR_STATE_PREFERRED) { - if (!ipv6_addr_is_link_local(addr->addr_data) - && !ipv6_addr_is_multicast(addr->addr_data)) { - - if (addr->addr_protocol == NET_IF_L3P_IPV6_PREFIX) { - continue; - } - - uint8_t tmp = ipv6_get_addr_match(dest, addr->addr_data); - - if (tmp >= bmatch) { - tmp_addr = addr; - bmatch = tmp; - } - } - } - } - } - else { - while ((addr = (ipv6_net_if_addr_t *) net_if_iter_addresses(if_id, - (net_if_addr_t **) &addr))) { - if (addr->ndp_state == NDP_ADDR_STATE_PREFERRED - && ipv6_addr_is_link_local(addr->addr_data) - && !ipv6_addr_is_multicast(addr->addr_data)) { - tmp_addr = addr; - } - } - } - - if (tmp_addr == NULL) { - memset(src, 0, 16); - } - else { - memcpy(src, tmp_addr->addr_data, 16); - } -} - -void ipv6_addr_init(ipv6_addr_t *out, uint16_t addr0, uint16_t addr1, - uint16_t addr2, uint16_t addr3, uint16_t addr4, uint16_t addr5, - uint16_t addr6, uint16_t addr7) -{ - out->uint16[0] = HTONS(addr0); - out->uint16[1] = HTONS(addr1); - out->uint16[2] = HTONS(addr2); - out->uint16[3] = HTONS(addr3); - out->uint16[4] = HTONS(addr4); - out->uint16[5] = HTONS(addr5); - out->uint16[6] = HTONS(addr6); - out->uint16[7] = HTONS(addr7); -} - -uint32_t get_remaining_time(timex_t *t) -{ - timex_t now; - vtimer_now(&now); - - return (timex_sub(*t, now).seconds); -} - -void set_remaining_time(timex_t *t, uint32_t time) -{ - timex_t tmp = { time, 0 }; - - timex_t now; - vtimer_now(&now); - *t = timex_add(now, tmp); -} - -int ipv6_init_as_router(void) -{ - ipv6_addr_t addr; - int if_id = -1; - - ipv6_addr_set_all_routers_addr(&addr); - - while ((if_id = net_if_iter_interfaces(if_id)) >= 0) { - if (!ipv6_net_if_add_addr(if_id, &addr, NDP_ADDR_STATE_PREFERRED, 0, 0, - 0)) { - return 0; - } - } - - return 1; -} - -uint8_t ipv6_is_router(void) -{ - ipv6_addr_t addr; - ipv6_net_if_hit_t hit; - - ipv6_addr_set_all_routers_addr(&addr); - - if (ipv6_net_if_addr_match(&hit, &addr) != NULL) { - return 1; - } - - return 0; -} - -void set_tcp_packet_handler_pid(kernel_pid_t pid) -{ - tcp_packet_handler_pid = pid; -} - -void set_udp_packet_handler_pid(kernel_pid_t pid) -{ - udp_packet_handler_pid = pid; -} - -void ipv6_register_next_header_handler(uint8_t next_header, kernel_pid_t pid) -{ - switch (next_header) { - case (IPV6_PROTO_NUM_TCP): - set_tcp_packet_handler_pid(pid); - break; - - case (IPV6_PROTO_NUM_UDP): - set_udp_packet_handler_pid(pid); - break; - - default: - /* TODO */ - break; - } -} - -/* register routing function */ -void ipv6_iface_set_routing_provider(ipv6_addr_t *(*next_hop)(ipv6_addr_t *dest)) -{ -#ifdef FIB_COMPAT - (void)next_hop; - puts("[WARNING] you are using FIB_COMPAT!\n\ - \t- The registered get_next_hop() function is NOT USED.\n\ - \t- In turn the fib_get_next_hop() function will be called!"); -#else - ip_get_next_hop = next_hop; -#endif -} - -#ifdef MODULE_RPL -/* register source-routing indicator function */ -void ipv6_iface_set_srh_indicator(uint8_t (*srh_indi)(void)) -{ - ip_srh_indicator = srh_indi; -} - -/* register rpl-process function */ -void ipv6_register_rpl_handler(kernel_pid_t pid) -{ - _rpl_process_pid = pid; -} - -#endif - -uint16_t ipv6_csum(ipv6_hdr_t *ipv6_header, uint8_t *buf, uint16_t len, - uint8_t proto) -{ - uint16_t sum = 0; - DEBUG("Calculate checksum over src: %s, ", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - &ipv6_header->srcaddr)); - DEBUG("dst: %s, len: %04X, buf: %p, proto: %u\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - &ipv6_header->destaddr), - len, buf, proto); - sum = len + proto; - sum = net_help_csum(sum, (uint8_t *) &ipv6_header->srcaddr, - 2 * sizeof(ipv6_addr_t)); - sum = net_help_csum(sum, buf, len); - return (sum == 0) ? 0xffff : HTONS(sum); -} diff --git a/sys/net/network_layer/sixlowpan/ip.h b/sys/net/network_layer/sixlowpan/ip.h deleted file mode 100644 index f421fbc24c..0000000000 --- a/sys/net/network_layer/sixlowpan/ip.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * IPv6 constants, data structs, and prototypes - * - * Copyright (C) 2013 INRIA. - * - * 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 sixlowpan - * @{ - * @file - * @brief 6lowpan IP layer header - * @author Stephan Zeisberg - * @author Martine Lenders - * @author Eric Engel - * @author Oliver Gesch - * @} - */ - -/* 6LoWPAN IP header file */ - -#ifndef _SIXLOWPAN_IP_H -#define _SIXLOWPAN_IP_H - -#include - -#include "kernel.h" -#include "thread.h" -#include "timex.h" -#include "mutex.h" -#include "net_if.h" - -#include "sixlowpan/ip.h" -#include "sixlowpan/types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* IPv6 field values */ -#define IPV6_VER (0x60) -/* size of global buffer */ -#define BUFFER_SIZE (LL_HDR_LEN + IPV6_MTU) - -#define MULTIHOP_HOPLIMIT (64) - -#define SIXLOWIP_MAX_REGISTERED (4) -#define IP_PROCESS_STACKSIZE (THREAD_STACKSIZE_MAIN) - -/* extern variables */ -extern uint8_t ipv6_ext_hdr_len; -extern kernel_pid_t ip_process_pid; - -#ifdef MODULE_RPL -extern int srh_handler_pid; -#endif - -/* base header lengths */ -#define LL_HDR_LEN (0x4) -#define ICMPV6_HDR_LEN (0x4) -#define IPV6_HDR_LEN (0x28) - -#define IPV6_NET_IF_ADDR_LIST_LEN (10) // maybe to much - -/* buffer */ -extern uint8_t sixlowpan_buffer[BUFFER_SIZE]; -extern char ip_process_buf[IP_PROCESS_STACKSIZE]; - -extern kernel_pid_t sixlowip_reg[SIXLOWIP_MAX_REGISTERED]; - -typedef struct __attribute__((packed)) -{ - struct net_if_addr_t *addr_next; - struct net_if_addr_t *addr_prev; - net_if_l3p_t addr_protocol; - ipv6_addr_t *addr_data; - uint8_t addr_len; - ndp_addr_state_t ndp_state; - timex_t valid_lifetime; - timex_t preferred_lifetime; - uint8_t is_anycast; -} -ipv6_net_if_addr_t; - -typedef struct __attribute__((packed)) -{ - ipv6_net_if_addr_t *addr; - int if_id; -} -ipv6_net_if_hit_t; - -typedef struct __attribute__((packed)) -{ - uint8_t prefix; ///< prefix length of the sub-net - uint8_t adv_cur_hop_limit; - uint32_t adv_reachable_time; - uint32_t adv_retrans_timer; -} -ipv6_net_if_ext_t; - -/* function prototypes */ -ipv6_net_if_ext_t *ipv6_net_if_get_ext(int if_id); - -icmpv6_hdr_t *get_icmpv6_buf(uint8_t ext_len); -uint8_t *get_payload_buf(uint8_t ext_len); -uint8_t *get_payload_buf_send(uint8_t ext_len); - -int icmpv6_demultiplex(const icmpv6_hdr_t *hdr); -int ipv6_init_as_router(void); -void *ipv6_process(void *); -ipv6_net_if_hit_t *ipv6_net_if_addr_prefix_eq(ipv6_net_if_hit_t *hit, ipv6_addr_t *addr); -ipv6_net_if_hit_t *ipv6_net_if_addr_match(ipv6_net_if_hit_t *hit, const ipv6_addr_t *addr); -uint32_t get_remaining_time(timex_t *t); -void set_remaining_time(timex_t *t, uint32_t time); - -#ifdef __cplusplus -} -#endif - -#endif /* _SIXLOWPAN_IP_H*/ diff --git a/sys/net/network_layer/sixlowpan/lowpan.c b/sys/net/network_layer/sixlowpan/lowpan.c deleted file mode 100644 index 3a371b7be9..0000000000 --- a/sys/net/network_layer/sixlowpan/lowpan.c +++ /dev/null @@ -1,1789 +0,0 @@ -/* - * 6lowpan implementation - * - * Copyright (C) 2013 INRIA. - * - * 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 sixlowpan - * @{ - * @file - * @brief 6lowpan functions - * @author Stephan Zeisberg - * @author Martine Lenders - * @author Oliver Gesch - * @author Eric Engel - * @} - */ - -#include -#include -#include -#include -#include -#include - -#include "vtimer.h" -#include "timex.h" -#include "thread.h" -#include "mutex.h" -#include "hwtimer.h" -#include "msg.h" -#include "transceiver.h" -#include "sixlowpan/mac.h" -#include "sixlowpan/ndp.h" - -#include "lowpan.h" -#ifdef MODULE_SIXLOWBORDER -#include "border/border.h" -#endif -#include "ip.h" -#include "icmp.h" - -#include "ieee802154_frame.h" -#include "socket_base/in.h" -#include "net_help.h" - -#define ENABLE_DEBUG (0) -#if ENABLE_DEBUG -static char addr_str[IPV6_MAX_ADDR_STR_LEN]; -#endif -#include "debug.h" - -#define CON_STACKSIZE (THREAD_STACKSIZE_DEFAULT) -#define LOWPAN_TRANSFER_BUF_STACKSIZE (THREAD_STACKSIZE_DEFAULT) - -#define SIXLOWPAN_MAX_REGISTERED (4) - -#define LOWPAN_REAS_BUF_TIMEOUT (15ul * 1000ul * 1000ul) -/* TODO: Set back to 3 * 1000 * (1000) */ - -#define IPV6_LL_ADDR_LEN (8) - -#define SIXLOWPAN_FRAG_HDR_MASK (0xf8) - -typedef struct lowpan_interval_list_t { - uint8_t start; - uint8_t end; - struct lowpan_interval_list_t *next; -} lowpan_interval_list_t; - -/** - * @brief 6LoWPAN reassembly buffer. - * - * @see - * RFC 4944, section 5.3 - * - */ -typedef struct lowpan_reas_buf_t { - net_if_eui64_t s_addr; ///< Source address - net_if_eui64_t d_addr; ///< Destination address - uint16_t tag; ///< Fragment tag - timex_t timestamp; ///< Timestamp of last packet fragment - /** - * @brief Size of reassembled packet with possible IPHC header - */ - uint16_t packet_size; - /** - * @brief Additive size of currently already received fragments - */ - uint16_t current_packet_size; - /** - * @brief Pointer to allocated memory for reassembled packet + 6LoWPAN - * Dispatch Byte - */ - uint8_t *packet; - /** - * @brief Pointer to list of intervals of received packet fragments - * (if any) - */ - lowpan_interval_list_t *interval_list_head; - struct lowpan_reas_buf_t *next; -} lowpan_reas_buf_t; - -extern mutex_t lowpan_context_mutex; -uint16_t tag = 0; -uint8_t max_frag_initial = 0; -uint8_t max_frag; - -static uint16_t packet_length; -static sixlowpan_lowpan_iphc_status_t iphc_status = LOWPAN_IPHC_ENABLE; -static ipv6_hdr_t *ipv6_buf; -static lowpan_reas_buf_t *head = NULL; -static lowpan_reas_buf_t *packet_fifo = NULL; - -/* length of compressed packet */ -uint16_t comp_len; -uint8_t frag_size; -uint8_t reas_buf[512]; -uint8_t comp_buf[512]; -uint8_t first_frag = 0; -mutex_t fifo_mutex = MUTEX_INIT; - -kernel_pid_t ip_process_pid = KERNEL_PID_UNDEF; -kernel_pid_t nd_nbr_cache_rem_pid = KERNEL_PID_UNDEF; -kernel_pid_t contexts_rem_pid = KERNEL_PID_UNDEF; -kernel_pid_t transfer_pid = KERNEL_PID_UNDEF; - -mutex_t lowpan_context_mutex = MUTEX_INIT; - -/* registered upper layer threads */ -kernel_pid_t sixlowpan_reg[SIXLOWPAN_MAX_REGISTERED]; -static sixlowpan_lowpan_frame_t current_frame; - -char ip_process_buf[IP_PROCESS_STACKSIZE]; -char con_buf[CON_STACKSIZE]; -char lowpan_transfer_buf[LOWPAN_TRANSFER_BUF_STACKSIZE]; -lowpan_context_t contexts[NDP_6LOWPAN_CONTEXT_MAX]; -uint8_t context_len = 0; -uint16_t local_address = 0; - -int lowpan_init(int as_border); -uint8_t lowpan_iphc_encoding(int if_id, const uint8_t *dest, int dest_len, - ipv6_hdr_t *ipv6_buf_extra, uint8_t *ptr); -void lowpan_iphc_decoding(uint8_t *data, uint8_t length, net_if_eui64_t *s_addr, - net_if_eui64_t *d_addr); -void add_fifo_packet(lowpan_reas_buf_t *current_packet); -lowpan_reas_buf_t *collect_garbage_fifo(lowpan_reas_buf_t *current_buf); -lowpan_reas_buf_t *collect_garbage(lowpan_reas_buf_t *current_buf); -void init_reas_bufs(lowpan_reas_buf_t *buf); -void check_timeout(void); -void print_long_local_addr(net_if_eui64_t *saddr); - -lowpan_context_t *lowpan_context_lookup(ipv6_addr_t *addr); - -/* deliver packet to mac*/ -int sixlowpan_lowpan_sendto(int if_id, const void *dest, int dest_len, - uint8_t *data, uint16_t data_len) -{ - uint8_t mcast = 0; - - ipv6_buf = (ipv6_hdr_t *) data; - uint16_t send_packet_length = data_len; - - if (ipv6_addr_is_multicast(&ipv6_buf->destaddr)) { - /* send broadcast */ - mcast = 1; - } - - /* check if packet needs to be fragmented */ - DEBUG("sixlowpan_lowpan_sendto(%d, dest, %d, data, %"PRIu16")\n", - if_id, dest_len, data_len); -#if ENABLE_DEBUG - DEBUG("dest: "); - - if (dest_len == 8) { - print_long_local_addr((net_if_eui64_t *)dest); - } - else { - printf("0x%04"PRIx16"\n", NTOHS(*((uint16_t *)dest))); - } - - DEBUG("data: \n"); - - for (int i = 0; i < data_len; i++) { - printf("%02x ", data[i]); - - if (!((i + 1) % 16) || i == data_len - 1) { - printf("\n"); - } - } - -#endif - - - if (iphc_status == LOWPAN_IPHC_ENABLE) { - if (!lowpan_iphc_encoding(if_id, dest, dest_len, ipv6_buf, data)) { - return -1; - } - - data = &comp_buf[0]; - send_packet_length = comp_len; - } - else { - memmove(data + 1, data, data_len); - data[0] = SIXLOWPAN_IPV6_DISPATCH; - send_packet_length++; - } - - if (send_packet_length > PAYLOAD_SIZE - IEEE_802154_MAX_HDR_LEN) { - uint16_t remaining; - uint16_t position, datagram_size = send_packet_length; - uint8_t max_frame; - - if (net_if_get_interface(if_id)->transceivers & (IEEE802154_TRANSCEIVER)) { - max_frame = PAYLOAD_SIZE; - } - else { - max_frame = PAYLOAD_SIZE - IEEE_802154_MAX_HDR_LEN; - } - - uint8_t fragbuf[max_frame + 5]; - - /* first fragment */ - max_frag_initial = ((max_frame - 4) / 8) * 8; - - if (data[0] == (char)SIXLOWPAN_IPV6_DISPATCH) { - /* XXX: weird, but only this way we get correct packet output */ - max_frag_initial++; - datagram_size--; - } - - memcpy(&fragbuf[4], data, max_frag_initial); - - fragbuf[0] = ((SIXLOWPAN_FRAG1_DISPATCH << 8) | datagram_size) >> 8; - fragbuf[1] = (SIXLOWPAN_FRAG1_DISPATCH << 8) | datagram_size; - fragbuf[2] = tag >> 8; - fragbuf[3] = tag; - - sixlowpan_mac_send_ieee802154_frame(if_id, dest, dest_len, - &fragbuf, - max_frag_initial + 4, - mcast); - - /* subsequent fragments */ - position = max_frag_initial; - max_frag = ((max_frame - 5) / 8) * 8; - - data += position; - - while (send_packet_length - position > max_frame - 5) { - memset(&fragbuf[0], 0, sizeof(fragbuf)); - memcpy(&fragbuf[5], data, max_frag); - - fragbuf[0] = ((SIXLOWPAN_FRAGN_DISPATCH << 8) | datagram_size) >> 8; - fragbuf[1] = (SIXLOWPAN_FRAGN_DISPATCH << 8) | datagram_size; - fragbuf[2] = tag >> 8; - fragbuf[3] = tag; - fragbuf[4] = position / 8; - - sixlowpan_mac_send_ieee802154_frame(if_id, dest, dest_len, - &fragbuf, - max_frag + 5, mcast); - data += max_frag; - position += max_frag; - } - - remaining = send_packet_length - position; - - memset(&fragbuf[0], 0, sizeof(fragbuf)); - memcpy(&fragbuf[5], data, remaining); - - fragbuf[0] = ((SIXLOWPAN_FRAGN_DISPATCH << 8) | datagram_size) >> 8; - fragbuf[1] = (SIXLOWPAN_FRAGN_DISPATCH << 8) | datagram_size; - fragbuf[2] = tag >> 8; - fragbuf[3] = tag; - fragbuf[4] = position / 8; - - tag++; - - if (sixlowpan_mac_send_ieee802154_frame(if_id, dest, dest_len, - &fragbuf, remaining + 5, mcast) < 0) { - return -1; - } - } - else { - return sixlowpan_mac_send_ieee802154_frame(if_id, dest, dest_len, data, - send_packet_length, mcast); - } - - return data_len; -} - -void sixlowpan_lowpan_set_iphc_status( - sixlowpan_lowpan_iphc_status_t status) -{ - iphc_status = status; -} - -#if ENABLE_DEBUG -void print_long_local_addr(net_if_eui64_t *saddr) -{ - printf("%02x%02x:%02x%02x:%02x%02x:%02x%02x\n", - ((uint8_t *)saddr)[0], ((uint8_t *)saddr)[1], ((uint8_t *)saddr)[2], - ((uint8_t *)saddr)[3], ((uint8_t *)saddr)[4], ((uint8_t *)saddr)[5], - ((uint8_t *)saddr)[6], ((uint8_t *)saddr)[7]); -} - -void sixlowpan_lowpan_print_reassembly_buffers(void) -{ - lowpan_reas_buf_t *temp_buffer; - lowpan_interval_list_t *temp_interval; - temp_buffer = head; - - printf("\n\n--- Reassembly Buffers ---\n"); - - while (temp_buffer != NULL) { - print_long_local_addr(&temp_buffer->s_addr); - printf("Ident.: %i, Packet Size: %i/%i, Timestamp: %"PRIu64"\n", - temp_buffer->tag, temp_buffer->current_packet_size, - temp_buffer->packet_size, timex_uint64(temp_buffer->timestamp)); - temp_interval = temp_buffer->interval_list_head; - - while (temp_interval != NULL) { - printf("\t%i - %i\n", temp_interval->start, temp_interval->end); - temp_interval = temp_interval->next; - } - - temp_buffer = temp_buffer->next; - } -} - -void sixlowpan_lowpan_print_fifo_buffers(void) -{ - lowpan_reas_buf_t *temp_buffer; - lowpan_interval_list_t *temp_interval; - temp_buffer = packet_fifo; - - printf("\n\n--- Reassembly Buffers ---\n"); - - while (temp_buffer != NULL) { - print_long_local_addr(&temp_buffer->s_addr); - printf("Ident.: %i, Packet Size: %i/%i, Timestamp: %"PRIu64"\n", - temp_buffer->tag, temp_buffer->current_packet_size, - temp_buffer->packet_size, timex_uint64(temp_buffer->timestamp)); - temp_interval = temp_buffer->interval_list_head; - - while (temp_interval != NULL) { - printf("\t%i - %i\n", temp_interval->start, temp_interval->end); - temp_interval = temp_interval->next; - } - - temp_buffer = temp_buffer->next; - } -} -#endif - -static void *lowpan_transfer(void *arg) -{ - (void) arg; - - msg_t m_recv, m_send; - ipv6_hdr_t *ipv6_buf; - lowpan_reas_buf_t *current_buf; - - while (1) { - uint8_t gotosleep = 1; - mutex_lock(&fifo_mutex); - current_buf = packet_fifo; - - if (current_buf != NULL) { - mutex_unlock(&fifo_mutex); - - if (current_buf->packet[0] == SIXLOWPAN_IPV6_DISPATCH) { - DEBUG("INFO: Uncompressed IPv6 dispatch (0x%02x) received\n", - current_buf->packet[0]); - ipv6_buf = ipv6_get_buf(); - memcpy(ipv6_buf, (current_buf->packet) + 1, current_buf->packet_size - 1); - m_send.content.ptr = (char *)ipv6_buf; - packet_length = current_buf->packet_size - 1; - msg_send_receive(&m_send, &m_recv, ip_process_pid); - } - else if (((current_buf->packet[0] & 0xf0) == IPV6_VER) && - (iphc_status == LOWPAN_IPHC_DISABLE)) { - ipv6_buf = ipv6_get_buf(); - memcpy(ipv6_buf, (current_buf->packet), current_buf->packet_size); - m_send.content.ptr = (char *)ipv6_buf; - packet_length = current_buf->packet_size; - msg_send_receive(&m_send, &m_recv, ip_process_pid); - } - else if (((current_buf->packet[0] & 0xe0) == SIXLOWPAN_IPHC1_DISPATCH) && - (iphc_status == LOWPAN_IPHC_ENABLE)) { - DEBUG("INFO: IPHC1 dispatch 0x%02x received, decompress\n", - current_buf->packet[0]); - lowpan_iphc_decoding(current_buf->packet, - current_buf->packet_size, - &(current_buf->s_addr), - &(current_buf->d_addr)); - - ipv6_buf = ipv6_get_buf(); - m_send.content.ptr = (char *) ipv6_buf; - msg_send_receive(&m_send, &m_recv, ip_process_pid); - } - else { - DEBUG("ERROR: packet with unknown dispatch 0x%02x received\n", - current_buf->packet[0]); - } - - collect_garbage_fifo(current_buf); - gotosleep = 0; - } - - - if (gotosleep == 1) { - mutex_unlock(&fifo_mutex); - thread_sleep(); - } - } - - return NULL; -} - -uint8_t ll_get_addr_match(net_if_eui64_t *src, net_if_eui64_t *dst) -{ - uint8_t val = 0, xor; - - for (uint8_t i = 0; i < sizeof(net_if_eui64_t); i++) { - /* if bytes are equal add 8 */ - if (src->uint8[i] == dst->uint8[i]) { - val += 8; - } - else { - xor = src->uint8[i] ^ dst->uint8[i]; - - /* while bits from byte equal add 1 */ - for (int j = 0; j < 8; j++) { - if ((xor & 0x80) == 0) { - val++; - xor = xor << 1; - } - else { - break; - } - } - } - } - - return val; -} - -lowpan_reas_buf_t *new_packet_buffer(uint16_t datagram_size, - uint16_t datagram_tag, - net_if_eui64_t *s_addr, - net_if_eui64_t *d_addr, - lowpan_reas_buf_t *current_buf, - lowpan_reas_buf_t *temp_buf) -{ - lowpan_reas_buf_t *new_buf = NULL; - - /* Allocate new memory for a new packet to be reassembled */ - new_buf = malloc(sizeof(lowpan_reas_buf_t)); - - if (new_buf != NULL) { - init_reas_bufs(new_buf); - - new_buf->packet = malloc(datagram_size); - - if (new_buf->packet != NULL) { - memcpy(&new_buf->s_addr, s_addr, 8); - memcpy(&new_buf->d_addr, d_addr, 8); - - new_buf->tag = datagram_tag; - new_buf->packet_size = datagram_size; - - vtimer_now(&new_buf->timestamp); - - if ((current_buf == NULL) && (temp_buf == NULL)) { - head = new_buf; - } - else { - temp_buf->next = new_buf; - } - - return new_buf; - } - else { - free(new_buf); - return NULL; - } - } - else { - return NULL; - } -} - -lowpan_reas_buf_t *get_packet_frag_buf(uint16_t datagram_size, - uint16_t datagram_tag, - net_if_eui64_t *s_addr, - net_if_eui64_t *d_addr) -{ - lowpan_reas_buf_t *current_buf = NULL, *temp_buf = NULL; - current_buf = head; - - while (current_buf != NULL) { - if (((ll_get_addr_match(¤t_buf->s_addr, s_addr)) == 64) && - ((ll_get_addr_match(¤t_buf->d_addr, d_addr)) == 64) && - (current_buf->packet_size == datagram_size) && - (current_buf->tag == datagram_tag) && - current_buf->interval_list_head != NULL) { - /* Found buffer for current packet fragment */ - vtimer_now(¤t_buf->timestamp); - return current_buf; - } - - temp_buf = current_buf; - current_buf = current_buf->next; - } - - return new_packet_buffer(datagram_size, datagram_tag, s_addr, d_addr, - current_buf, temp_buf); -} - -uint8_t is_in_interval(uint8_t start1, uint8_t end1, uint8_t start2, uint8_t end2) -{ - /* 1: Interval 1 and 2 are the same or overlapping */ - /* 0: Interval 1 and 2 are not overlapping or the same */ - - if (((start1 < start2) && (start2 <= end1)) || - ((start2 < start1) && (start1 <= end2)) || - ((start1 == start2) && (end1 == end2))) { - return 1; - } - else { - return 0; - } -} - -uint8_t handle_packet_frag_interval(lowpan_reas_buf_t *current_buf, - uint8_t datagram_offset, uint8_t frag_size) -{ - /* 0: Error, discard fragment */ - /* 1: Finished correctly */ - lowpan_interval_list_t *temp_interval = NULL, *current_interval = NULL, *new_interval = NULL; - current_interval = current_buf->interval_list_head; - - while (current_interval != NULL) { - if (is_in_interval(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 */ - return 0; - } - - temp_interval = current_interval; - current_interval = current_interval->next; - } - - new_interval = malloc(sizeof(lowpan_interval_list_t)); - - if (new_interval != NULL) { - new_interval->start = datagram_offset; - new_interval->end = datagram_offset + frag_size - 1; - new_interval->next = NULL; - - if ((current_interval == NULL) && (temp_interval == NULL)) { - current_buf->interval_list_head = new_interval; - } - else { - temp_interval->next = new_interval; - } - - return 1; - } - - return 0; -} - -lowpan_reas_buf_t *collect_garbage_fifo(lowpan_reas_buf_t *current_buf) -{ - lowpan_interval_list_t *temp_list, *current_list; - lowpan_reas_buf_t *temp_buf, *my_buf, *return_buf; - - mutex_lock(&fifo_mutex); - - temp_buf = packet_fifo; - my_buf = temp_buf; - - if (packet_fifo == current_buf) { - packet_fifo = current_buf->next; - return_buf = packet_fifo; - } - else { - while (temp_buf != current_buf) { - my_buf = temp_buf; - temp_buf = temp_buf->next; - } - - my_buf->next = current_buf->next; - - return_buf = my_buf->next; - } - - mutex_unlock(&fifo_mutex); - - current_list = current_buf->interval_list_head; - temp_list = current_list; - - while (current_list != NULL) { - temp_list = current_list->next; - free(current_list); - current_list = temp_list; - } - - free(current_buf->packet); - free(current_buf); - - return return_buf; -} - -lowpan_reas_buf_t *collect_garbage(lowpan_reas_buf_t *current_buf) -{ - lowpan_interval_list_t *temp_list, *current_list; - lowpan_reas_buf_t *temp_buf, *my_buf, *return_buf; - - temp_buf = head; - my_buf = temp_buf; - - if (head == current_buf) { - head = current_buf->next; - return_buf = head; - } - else { - while (temp_buf != current_buf) { - my_buf = temp_buf; - temp_buf = temp_buf->next; - } - - my_buf->next = current_buf->next; - - return_buf = my_buf->next; - } - - current_list = current_buf->interval_list_head; - temp_list = current_list; - - while (current_list != NULL) { - temp_list = current_list->next; - free(current_list); - current_list = temp_list; - } - - free(current_buf->packet); - free(current_buf); - - return return_buf; -} - -void handle_packet_fragment(uint8_t *data, uint8_t datagram_offset, - uint16_t datagram_size, uint16_t datagram_tag, - net_if_eui64_t *s_addr, net_if_eui64_t *d_addr, - uint8_t hdr_length, uint8_t frag_size) -{ - lowpan_reas_buf_t *current_buf; - /* Is there already a reassembly buffer for this packet fragment? */ - current_buf = get_packet_frag_buf(datagram_size, datagram_tag, s_addr, - d_addr); - - if ((current_buf != NULL) && (handle_packet_frag_interval(current_buf, - datagram_offset, - frag_size) == 1)) { - /* Copy fragment bytes into corresponding packet space area */ - memcpy(current_buf->packet + datagram_offset, data + hdr_length, frag_size); - current_buf->current_packet_size += frag_size; - - if (current_buf->current_packet_size == current_buf->packet_size) { - add_fifo_packet(current_buf); - - if (thread_getstatus(transfer_pid) == STATUS_SLEEPING) { - thread_wakeup(transfer_pid); - } - } - } - else { - /* No memory left or duplicate */ - if (current_buf == NULL) { - printf("ERROR: no memory left!\n"); - } - else { - printf("ERROR: duplicate fragment!\n"); - } - } -} - -void check_timeout(void) -{ - lowpan_reas_buf_t *temp_buf, *smallest_time = NULL; - int count = 0; - - timex_t now; - vtimer_now(&now); - temp_buf = head; - - while (temp_buf != NULL) { - if ((timex_uint64(now) - timex_uint64(temp_buf->timestamp)) >= LOWPAN_REAS_BUF_TIMEOUT) { - printf("TIMEOUT!cur_time: %" PRIu64 ", temp_buf: %" PRIu64 "\n", timex_uint64(now), - timex_uint64(temp_buf->timestamp)); - temp_buf = collect_garbage(temp_buf); - } - else { - if (smallest_time == NULL) { - smallest_time = temp_buf; - } - else if (timex_cmp(temp_buf->timestamp, smallest_time->timestamp) < 0) { - smallest_time = temp_buf; - } - - temp_buf = temp_buf->next; - count++; - } - } - - if ((count > 10) && (smallest_time != NULL)) { - collect_garbage(smallest_time); - } -} - -void add_fifo_packet(lowpan_reas_buf_t *current_packet) -{ - lowpan_reas_buf_t *temp_buf, *my_buf; - - if (head == current_packet) { - head = current_packet->next; - } - else { - temp_buf = head; - - while (temp_buf != current_packet) { - my_buf = temp_buf; - temp_buf = temp_buf->next; - } - - my_buf->next = current_packet->next; - } - - mutex_lock(&fifo_mutex); - - if (packet_fifo == NULL) { - packet_fifo = current_packet; - } - else { - temp_buf = packet_fifo; - - while (temp_buf != NULL) { - my_buf = temp_buf; - temp_buf = temp_buf->next; - } - - my_buf->next = current_packet; - } - - mutex_unlock(&fifo_mutex); - current_packet->next = NULL; -} - -/* Register an upper layer thread */ -uint8_t sixlowpan_lowpan_register(kernel_pid_t pid) -{ - uint8_t i; - - for (i = 0; (((i < SIXLOWPAN_MAX_REGISTERED) && sixlowpan_reg[i] != pid) && - (sixlowpan_reg[i] != 0)); i++) { - ; - } - - if (i >= SIXLOWPAN_MAX_REGISTERED) { - return ENOMEM; - } - else { - sixlowpan_reg[i] = pid; - return 1; - } -} - -void lowpan_read(uint8_t *data, uint8_t length, net_if_eui64_t *s_addr, - net_if_eui64_t *d_addr) -{ - /* check if packet is fragmented */ - short i; - - check_timeout(); - - for (i = 0; i < SIXLOWPAN_MAX_REGISTERED; i++) { - if (sixlowpan_reg[i]) { - msg_t m_send; - m_send.type = LOWPAN_FRAME_RECEIVED;; - current_frame.length = length; - current_frame.data = data; - m_send.content.ptr = (char *) ¤t_frame; - msg_send(&m_send, sixlowpan_reg[i]); - } - } - - /* Fragmented Packet */ - if (((data[0] & SIXLOWPAN_FRAG_HDR_MASK) == SIXLOWPAN_FRAG1_DISPATCH) || - ((data[0] & SIXLOWPAN_FRAG_HDR_MASK) == SIXLOWPAN_FRAGN_DISPATCH)) { - uint8_t hdr_length = 0; - uint8_t datagram_offset = 0; - uint16_t datagram_size = 0; - uint16_t datagram_tag = 0; - uint16_t byte_offset; - DEBUG("INFO: fragmentation dispatch 0x%02x received\n", - data[0] & SIXLOWPAN_FRAG_HDR_MASK); - /* get 11-bit from first 2 byte*/ - datagram_size = (((uint16_t)(data[0] << 8)) | data[1]) & 0x07ff; - - /* get 16-bit datagram tag */ - datagram_tag = (((uint16_t)(data[2] << 8)) | data[3]); - - switch (data[0] & SIXLOWPAN_FRAG_HDR_MASK) { - /* First Fragment */ - case (SIXLOWPAN_FRAG1_DISPATCH): { - datagram_offset = 0; - hdr_length += 4; - - if (data[4] == (char)SIXLOWPAN_IPV6_DISPATCH) { - hdr_length++; - } - - break; - } - - /* Subsequent Fragment */ - case (SIXLOWPAN_FRAGN_DISPATCH): { - datagram_offset = data[4]; - hdr_length += 5; - break; - } - } - - frag_size = length - hdr_length; - byte_offset = datagram_offset * 8; - - DEBUG("Frag size is %u, offset is %u, datagram_size is %u\n", - frag_size, byte_offset, datagram_size); - if ((frag_size % 8) != 0) { - if ((byte_offset + frag_size) != datagram_size) { - printf("ERROR: received invalid fragment\n"); - return; - } - } - - handle_packet_fragment(data, byte_offset, datagram_size, datagram_tag, - s_addr, d_addr, hdr_length, frag_size); - } - /* Regular Packet */ - else { - DEBUG("INFO: unfragmentated packet with first byte 0x%02x received\n", - data[0]); - lowpan_reas_buf_t *current_buf = get_packet_frag_buf(length, 0, s_addr, d_addr); - - if (current_buf && current_buf->packet) { - /* Copy packet bytes into corresponding packet space area */ - memcpy(current_buf->packet, data, length); - current_buf->current_packet_size += length; - add_fifo_packet(current_buf); - } - else { - DEBUG("ERROR: no memory left in packet buffer!\n"); - } - - if (thread_getstatus(transfer_pid) == STATUS_SLEEPING) { - thread_wakeup(transfer_pid); - } - } - -} - -/* RFC6282 https://tools.ietf.org/html/rfc6282#section-3.1 */ -uint8_t lowpan_iphc_encoding(int if_id, const uint8_t *dest, int dest_len, - ipv6_hdr_t *ipv6_buf_extra, uint8_t *ptr) -{ - uint16_t payload_length = NTOHS(ipv6_buf->length); - uint8_t lowpan_iphc[2]; - uint8_t *ipv6_hdr_fields = &comp_buf[2]; - lowpan_context_t *con = NULL; - uint16_t hdr_pos = 0; - uint8_t tc; - net_if_eui64_t own_iid; - - if (net_if_get_src_address_mode(if_id) == NET_IF_TRANS_ADDR_M_SHORT) { - if (!net_if_get_eui64(&own_iid, if_id, 1)) { - return 1; - } - } - else { - if (!net_if_get_eui64(&own_iid, if_id, 0)) { - return 1; - } - } - - own_iid.uint8[0] ^= 0x02; - - ipv6_buf = ipv6_buf_extra; - - memset(&lowpan_iphc, 0, 2); - - /* set iphc dispatch */ - lowpan_iphc[0] = SIXLOWPAN_IPHC1_DISPATCH; - - /* TF: Traffic Class, Flow Label: - * first we need to change DSCP and ECN because in 6lowpan-nd-13 these - * fields are reverse, the original order is DSCP/ECN (rfc 3168) */ - tc = (ipv6_buf->version_trafficclass << 4) | - (ipv6_buf->trafficclass_flowlabel >> 4); - tc = (tc >> 2) | (tc << 6); - - if ((ipv6_buf->flowlabel == 0) && - (ipv6_buf->trafficclass_flowlabel & 0x0f) == 0) { - /* flowlabel is elided */ - lowpan_iphc[0] |= SIXLOWPAN_IPHC1_FL_C; - - if (((ipv6_buf->version_trafficclass & 0x0f) == 0) && - ((ipv6_buf->trafficclass_flowlabel & 0xf0) == 0)) { - /* traffic class is elided */ - lowpan_iphc[0] |= SIXLOWPAN_IPHC1_TC_C; - } - else { - /* ECN + DSCP (1 byte), Flow Label is elided */ - ipv6_hdr_fields[hdr_pos] = tc; - hdr_pos++; - } - } - else { - /* flowlabel not compressible */ - if (((ipv6_buf->version_trafficclass & 0x0f) == 0) && - ((ipv6_buf->trafficclass_flowlabel & 0xf0) == 0)) { - /* traffic class is elided */ - lowpan_iphc[0] |= SIXLOWPAN_IPHC1_TC_C; - /* ECN + 2-bit Pad + Flow Label (3 bytes), DSCP is elided */ - ipv6_hdr_fields[hdr_pos] = ((tc & 0xc0) | - (ipv6_buf->trafficclass_flowlabel & 0x0f)); - memcpy(&(ipv6_hdr_fields[hdr_pos]), &ipv6_buf->flowlabel , 2); - hdr_pos += 3; - } - else { - /* ECN + DSCP + 4-bit Pad + Flow Label (4 bytes) */ - memcpy(&ipv6_hdr_fields[hdr_pos], &ipv6_buf->version_trafficclass, 4); - ipv6_hdr_fields[hdr_pos] = tc; - hdr_pos += 4; - } - } - - /* NH: Next Header: - * TODO: NHC */ - ipv6_hdr_fields[hdr_pos] = ipv6_buf->nextheader; - hdr_pos++; - - /* HLIM: Hop Limit: */ - switch (ipv6_buf->hoplimit) { - case (1): { - /* 01: The Hop Limit field is compressed and the hop limit is 1. */ - lowpan_iphc[0] |= 0x01; - break; - } - - case (64): { - /* 10: The Hop Limit field is compressed and the hop limit is 64. */ - lowpan_iphc[0] |= 0x02; - break; - } - - case (255): { - /* 11: The Hop Limit field is compressed and the hop limit is 255. */ - lowpan_iphc[0] |= 0x03; - break; - } - - default: { - ipv6_hdr_fields[hdr_pos] = ipv6_buf->hoplimit; - hdr_pos++; - break; - } - } - - mutex_lock(&lowpan_context_mutex); - - /* CID: Context Identifier Extension: */ - if ((lowpan_context_lookup(&ipv6_buf->srcaddr) != NULL) || - (lowpan_context_lookup(&ipv6_buf->destaddr) != NULL)) { - lowpan_iphc[1] |= SIXLOWPAN_IPHC2_CID; - memmove(&ipv6_hdr_fields[1], &ipv6_hdr_fields[0], hdr_pos); - hdr_pos++; - } - - /* SAC: Source Address Compression */ - if (ipv6_addr_is_unspecified(&(ipv6_buf->srcaddr))) { - /* SAC = 1 and SAM = 00 */ - lowpan_iphc[1] |= SIXLOWPAN_IPHC2_SAC; - } - else { - if ((con = lowpan_context_lookup(&ipv6_buf->srcaddr)) != NULL) { - /* 1: Source address compression uses stateful, context-based - * compression. */ - lowpan_iphc[1] |= SIXLOWPAN_IPHC2_SAC; - ipv6_hdr_fields[0] |= (con->num << 4); - } - - if (con || ipv6_addr_is_link_local(&ipv6_buf->srcaddr)) { - /* 0: Source address compression uses stateless compression.*/ - if (memcmp(&(ipv6_buf->srcaddr.uint8[8]), &own_iid, 8) == 0) { - /* 0 bits. The address is derived using context information - * and possibly the link-layer addresses.*/ - lowpan_iphc[1] |= 0x30; - } - else if ((ipv6_buf->srcaddr.uint32[2] == HTONL(0x000000ffu)) && - (ipv6_buf->srcaddr.uint16[6] == HTONL(0xfe00u))) { - /* The 48 leading bits of the interface identifier are - * 0000:00FF:FE00, so we can compress the source address-iid to - * 16-bit */ - memcpy(&ipv6_hdr_fields[hdr_pos], &ipv6_buf->srcaddr.uint16[7], 2); - hdr_pos += 2; - /* 16 bits. The address is derived using context information - * and the 16 bits carried inline. */ - lowpan_iphc[1] |= 0x20; - } - else { - memcpy(&ipv6_hdr_fields[hdr_pos], &(ipv6_buf->srcaddr.uint16[4]), 8); - hdr_pos += 8; - /* 64 bits. The address is derived using context information - * and the 64 bits carried inline. */ - lowpan_iphc[1] |= 0x10; - } - } - else { - /* full address carried inline */ - memcpy(&ipv6_hdr_fields[hdr_pos], &(ipv6_buf->srcaddr.uint8[0]), 16); - hdr_pos += 16; - } - } - - /* M: Multicast Compression */ - if (ipv6_addr_is_multicast(&ipv6_buf->destaddr)) { - /* 1: Destination address is a multicast address. */ - lowpan_iphc[1] |= SIXLOWPAN_IPHC2_M; - - /* Check if we can compress any part of the address */ - if ((ipv6_buf->destaddr.uint8[0] == 0xff) && - (ipv6_buf->destaddr.uint16[1] == HTONS(0x0000u)) && - (ipv6_buf->destaddr.uint32[1] == HTONL(0x00000000u)) && - (ipv6_buf->destaddr.uint16[4] == HTONS(0x0000u)) && - (ipv6_buf->destaddr.uint8[10] == 0x00)) { - /* If we got here then the address is on the form: - * FFXX:0000:0000:0000:0000:00XX:XXXX:XXXX - * which means that it can be compressed. */ - if ((ipv6_buf->destaddr.uint8[1] == 0x02) && - (ipv6_buf->destaddr.uint16[5] == HTONS(0x0000u)) && - (ipv6_buf->destaddr.uint16[6] == HTONS(0x0000u)) && - (ipv6_buf->destaddr.uint8[14] == 0x00)) { - /* 11: 8 bits. The address takes the form FF02::00XX. */ - lowpan_iphc[1] |= 0x03; - ipv6_hdr_fields[hdr_pos] = ipv6_buf->destaddr.uint8[15]; - hdr_pos++; - } - else if ((ipv6_buf->destaddr.uint16[5] == HTONS(0x0000u)) && - (ipv6_buf->destaddr.uint8[12] == 0x00)) { - /* 10: 32 bits. The address takes the form FFXX::00XX:XXXX. */ - lowpan_iphc[1] |= 0x02; - /* copy second and last 3 bytes */ - ipv6_hdr_fields[hdr_pos] = ipv6_buf->destaddr.uint8[1]; - hdr_pos++; - memcpy(&ipv6_hdr_fields[hdr_pos], &ipv6_buf->destaddr.uint8[13], 3); - hdr_pos += 3; - } - else { - /* 01: 48 bits. The address takes the form FFXX::00XX:XXXX:XXXX */ - lowpan_iphc[1] |= 0x01; - /* copy second and last 5 byte */ - ipv6_hdr_fields[hdr_pos] = ipv6_buf->destaddr.uint8[1]; - hdr_pos++; - memcpy(&ipv6_hdr_fields[hdr_pos], &ipv6_buf->destaddr.uint8[11], 5); - hdr_pos += 5; - } - } - else { - /* Full 128 bit address */ - memcpy(&ipv6_hdr_fields[hdr_pos], &ipv6_buf->destaddr.uint8[0], 16); - hdr_pos += 16; - } - } - else { - /* 0: Destination address is not a multicast address. */ - if ((con = lowpan_context_lookup(&ipv6_buf->destaddr)) != NULL) { - /* 1: Destination address compression uses stateful, context-based - * compression. */ - lowpan_iphc[1] |= SIXLOWPAN_IPHC2_DAC; - ipv6_hdr_fields[0] = con->num; - - } - - if (con || ipv6_addr_is_link_local(&ipv6_buf->destaddr)) { - if (dest_len == 8 && - ipv6_buf->destaddr.uint8[8] == (dest[0] ^ 0x02) && - memcmp(&ipv6_buf->destaddr.uint8[9], &dest[1], 7) == 0) { - /* 0 bits. The address is derived using context information - * and possibly the link-layer addresses.*/ - lowpan_iphc[1] |= 0x03; - } - else if (ipv6_buf->destaddr.uint32[2] == HTONL(0x000000ff) && - ipv6_buf->destaddr.uint16[6] == HTONS(0xfe00)) { - if (dest_len == 2 && - ipv6_buf->destaddr.uint8[14] == dest[0] && - ipv6_buf->destaddr.uint8[15] == dest[1]) { - /* 0 bits. The address is derived using context information - * and possibly the link-layer addresses.*/ - lowpan_iphc[1] |= 0x03; - } - else { - /* The 48 leading bits of the interface identifier are - * 0000:00FF:FE00, so we can compress the source address-iid to - * 16-bit */ - memcpy(&ipv6_hdr_fields[hdr_pos], &ipv6_buf->destaddr.uint16[7], 2); - hdr_pos += 2; - /* 16 bits. The address is derived using context information - * and the 16 bits carried inline. */ - lowpan_iphc[1] |= 0x02; - } - } - else { - memcpy(&ipv6_hdr_fields[hdr_pos], &(ipv6_buf->destaddr.uint16[4]), 8); - hdr_pos += 8; - /* 64 bits. The address is derived using context information - * and the 64 bits carried inline. */ - lowpan_iphc[1] |= 0x01; - } - } - else { - /* Full 128 bit address */ - memcpy(&ipv6_hdr_fields[hdr_pos], &(ipv6_buf->destaddr.uint8[0]), 16); - hdr_pos += 16; - } - } - - mutex_unlock(&lowpan_context_mutex); - - comp_buf[0] = lowpan_iphc[0]; - comp_buf[1] = lowpan_iphc[1]; - - /*uint8_t *ptr; - if (ipv6_buf->nextheader == IPV6_PROTO_NUM_TCP) - { - ptr = get_payload_buf_send(ipv6_ext_hdr_len); - } - else - { - ptr = get_payload_buf(ipv6_ext_hdr_len); - } - */ - memcpy(&ipv6_hdr_fields[hdr_pos], &ptr[IPV6_HDR_LEN], NTOHS(ipv6_buf->length)); - - comp_len = 2 + hdr_pos + payload_length; - - return 1; -} - -void lowpan_iphc_decoding(uint8_t *data, uint8_t length, net_if_eui64_t *s_addr, - net_if_eui64_t *d_addr) -{ - uint8_t hdr_pos = 0; - uint8_t *ipv6_hdr_fields = data; - uint8_t lowpan_iphc[2]; - uint8_t cid = 0; - uint8_t dci = 0; - - uint8_t ll_prefix[2] = {0xfe, 0x80}; - lowpan_context_t *con = NULL; - - ipv6_buf = ipv6_get_buf(); - - lowpan_iphc[0] = ipv6_hdr_fields[0]; - lowpan_iphc[1] = ipv6_hdr_fields[1]; - hdr_pos += 2; - - /* first check if CID flag is set */ - if (lowpan_iphc[1] & SIXLOWPAN_IPHC2_CID) { - hdr_pos++; - cid = 1; - } - - /* TF: Traffic Class, Flow Label: */ - if (lowpan_iphc[0] & SIXLOWPAN_IPHC1_FL_C) { - /* flowlabel is elided */ - if (lowpan_iphc[0] & SIXLOWPAN_IPHC1_TC_C) { - /* traffic class is elided */ - ipv6_buf->version_trafficclass = 0x60; - ipv6_buf->trafficclass_flowlabel = 0; - ipv6_buf->flowlabel = 0; - } - else { - /* toogle ecn/dscp order */ - ipv6_buf->version_trafficclass = 0x60 | (0x0f & - (ipv6_hdr_fields[hdr_pos] >> 2)); - ipv6_buf->trafficclass_flowlabel = ((ipv6_hdr_fields[hdr_pos] >> 2) & 0x30) | - ((ipv6_hdr_fields[hdr_pos] << 6) & 0xc0); - ipv6_buf->flowlabel = 0; - hdr_pos += 3; - } - } - else { - /* flowlabel carried inline */ - if (lowpan_iphc[0] & SIXLOWPAN_IPHC1_TC_C) { - /* traffic class is elided */ - ipv6_buf->version_trafficclass = 0x60; - /* ecn + 4 bit flowlabel*/ - ipv6_buf->trafficclass_flowlabel = ((ipv6_hdr_fields[hdr_pos] >> 2) & 0x30) | - (ipv6_hdr_fields[hdr_pos] & 0x0f); - hdr_pos++; - /* copy 2byte flowlabel */ - memcpy(&ipv6_buf->flowlabel, &ipv6_hdr_fields[hdr_pos], 2); - hdr_pos += 2; - } - else { - ipv6_buf->version_trafficclass = 0x60 | (0x0f & - (ipv6_hdr_fields[hdr_pos] >> 2)); - ipv6_buf->trafficclass_flowlabel = ((ipv6_hdr_fields[hdr_pos] >> 2) & 0x30) | - (ipv6_hdr_fields[hdr_pos] & 0x0f) | - (ipv6_hdr_fields[hdr_pos + 1] & 0x0f); - hdr_pos += 2; - memcpy(&ipv6_buf->trafficclass_flowlabel, - &ipv6_hdr_fields[hdr_pos], 2); - hdr_pos += 2; - } - } - - /* NH: Next Header: */ - if (!(lowpan_iphc[0] & SIXLOWPAN_IPHC1_NH)) { - ipv6_buf->nextheader = ipv6_hdr_fields[hdr_pos]; - hdr_pos++; - } - - /* HLIM: Hop Limit: */ - if (lowpan_iphc[0] & 0x03) { - switch (lowpan_iphc[0] & 0x03) { - case (0x01): { - ipv6_buf->hoplimit = 1; - break; - } - - case (0x02): { - ipv6_buf->hoplimit = 64; - break; - } - - case (0x03): { - ipv6_buf->hoplimit = 255; - break; - } - - default: - break; - } - } - else { - ipv6_buf->hoplimit = ipv6_hdr_fields[hdr_pos]; - hdr_pos++; - } - - /* Generate IPv6 address from stateless information, if SAC=1 we will use - * this stateless information as a starting point for the stateful - * information. */ - /* RFC 6282 describes each of the following address compression methods */ - switch (((lowpan_iphc[1] & SIXLOWPAN_IPHC2_SAM) >> 4) & 0x03) { - case (0x01): { - /* 64-bits */ - memcpy(&(ipv6_buf->srcaddr.uint8[0]), &ll_prefix[0], 2); - memset(&(ipv6_buf->srcaddr.uint8[2]), 0, 6); - memcpy(&(ipv6_buf->srcaddr.uint8[8]), &ipv6_hdr_fields[hdr_pos], 8); - hdr_pos += 8; - break; - } - - case (0x02): { - /* 16-bits */ - memcpy(&(ipv6_buf->srcaddr.uint8[0]), &ll_prefix[0], 2); - ipv6_buf->srcaddr.uint16[1] = HTONS(0x0000u); - ipv6_buf->srcaddr.uint32[1] = HTONL(0x00000000u); - ipv6_buf->srcaddr.uint32[2] = HTONL(0x000000ffu); - ipv6_buf->srcaddr.uint16[6] = HTONS(0xfe00u); - memcpy(&(ipv6_buf->srcaddr.uint8[14]), &ipv6_hdr_fields[hdr_pos], 2); - hdr_pos += 2; - break; - } - - case (0x03): { - /* 0-bits */ - memcpy(&(ipv6_buf->srcaddr.uint8[0]), &ll_prefix[0], 2); - memset(&(ipv6_buf->srcaddr.uint8[2]), 0, 6); - memcpy(&(ipv6_buf->srcaddr.uint8[8]), &s_addr->uint8[0], 8); - /* Invert Universal/local bit as specified in - * RFC4291, section 2.5.1 "Interface Identifiers" */ - ipv6_buf->srcaddr.uint8[8] ^= 0x02; - break; - } - - default: { - /* full address carried inline */ - memcpy(&(ipv6_buf->srcaddr.uint8[0]), - &ipv6_hdr_fields[hdr_pos], 16); - hdr_pos += 16; - break; - } - } - - /* CID: Context Identifier Extension: + SAC: Source Address Compression */ - if (lowpan_iphc[1] & SIXLOWPAN_IPHC2_SAC) { - /* 1: Source address compression uses stateful, context-based - * compression.*/ - uint8_t sci = 0; - if (cid) { - sci = ipv6_hdr_fields[3] >> 4; - } - - mutex_lock(&lowpan_context_mutex); - - /* check context number */ - if (((lowpan_iphc[1] & SIXLOWPAN_IPHC2_SAM) >> 4) & 0x03) { - con = lowpan_context_num_lookup(sci); - } - - if (con == NULL) { - printf("ERROR: context not found\n"); - mutex_unlock(&lowpan_context_mutex); - return; - } - /* By RFC 6282 3.1.1. Bits covered by context - * information are always used. */ - memcpy(&(ipv6_buf->srcaddr.uint8[0]), &con->prefix, con->length); - - mutex_unlock(&lowpan_context_mutex); - } - - /* M: Multicast Compression + DAC: Destination Address Compression */ - if (lowpan_iphc[1] & SIXLOWPAN_IPHC2_M) { - /* 1: Destination address is a multicast address. */ - if (lowpan_iphc[1] & SIXLOWPAN_IPHC2_DAC) { - /* 1: Destination address compression uses stateful, context-based - * compression. - * If M=1 and DAC=1: */ - if (cid) { - dci = ipv6_hdr_fields[3] & 0x0f; - } - - mutex_lock(&lowpan_context_mutex); - - if ((lowpan_iphc[1] & SIXLOWPAN_IPHC2_DAM) & 0x03) { - con = lowpan_context_num_lookup(dci); - } - - if (con == NULL) { - printf("ERROR: context not found\n"); - mutex_unlock(&lowpan_context_mutex); - return; - } - - // TODO: - mutex_unlock(&lowpan_context_mutex); - } - else { - uint8_t m_prefix[2] = {0xff, 0x02}; - /* If M=1 and DAC=0: */ - switch (lowpan_iphc[1] & SIXLOWPAN_IPHC2_DAM) { - case (0x01): { - m_prefix[1] = ipv6_hdr_fields[hdr_pos]; - hdr_pos++; - memcpy(&(ipv6_buf->destaddr.uint8[0]), &m_prefix[0], 2); - memset(&(ipv6_buf->destaddr.uint8[2]), 0, 9); - memcpy(&(ipv6_buf->destaddr.uint8[11]), &ipv6_hdr_fields[hdr_pos], 5); - hdr_pos += 5; - break; - } - - case (0x02): { - m_prefix[1] = ipv6_hdr_fields[hdr_pos]; - hdr_pos++; - memcpy(&(ipv6_buf->destaddr.uint8[0]), &m_prefix[0], 2); - memset(&(ipv6_buf->destaddr.uint8[2]), 0, 11); - memcpy(&(ipv6_buf->destaddr.uint8[13]), &ipv6_hdr_fields[hdr_pos], 3); - hdr_pos += 3; - break; - } - - case (0x03): { - memcpy(&(ipv6_buf->destaddr.uint8[0]), &m_prefix[0], 2); - memset(&(ipv6_buf->destaddr.uint8[2]), 0, 13); - memcpy(&(ipv6_buf->destaddr.uint8[15]), &ipv6_hdr_fields[hdr_pos], 1); - hdr_pos++; - break; - } - - default: { - memcpy(&(ipv6_buf->destaddr.uint8[0]), &ipv6_hdr_fields[hdr_pos], 16); - hdr_pos += 16; - break; - } - } - } - } - else { - switch ((lowpan_iphc[1] & SIXLOWPAN_IPHC2_DAM) & 0x03) { - case (0x01): { - /* 64-bits */ - memcpy(&(ipv6_buf->destaddr.uint8[0]), &ll_prefix[0], 2); - memset(&(ipv6_buf->destaddr.uint8[2]), 0, 6); - memcpy(&(ipv6_buf->destaddr.uint8[8]), &ipv6_hdr_fields[hdr_pos], 8); - hdr_pos += 8; - break; - } - - case (0x02): { - /* 16-bits */ - memcpy(&(ipv6_buf->destaddr.uint8[0]), &ll_prefix[0], 2); - ipv6_buf->destaddr.uint16[1] = HTONS(0x0000u); - ipv6_buf->destaddr.uint32[1] = HTONL(0x00000000u); - ipv6_buf->destaddr.uint32[2] = HTONL(0x000000ffu); - ipv6_buf->destaddr.uint16[6] = HTONS(0xfe00u); - memcpy(&(ipv6_buf->destaddr.uint8[14]), &ipv6_hdr_fields[hdr_pos], 2); - hdr_pos += 2; - break; - } - - case (0x03): { - /* 0-bits */ - memcpy(&(ipv6_buf->destaddr.uint8[0]), &ll_prefix[0], 2); - memset(&(ipv6_buf->destaddr.uint8[2]), 0, 6); - memcpy(&(ipv6_buf->destaddr.uint8[8]), &d_addr->uint8[0], 8); - /* Invert Universal/local bit as specified in - * RFC4291, section 2.5.1 "Interface Identifiers" */ - ipv6_buf->destaddr.uint8[8] ^= 0x02; - break; - } - - default: { - /* full address carried inline */ - memcpy(&(ipv6_buf->destaddr.uint8[0]), - &ipv6_hdr_fields[hdr_pos], 16); - hdr_pos += 16; - break; - } - } - - if (lowpan_iphc[1] & SIXLOWPAN_IPHC2_DAC) { - /* 1: Destination address compression uses stateful, context-based - * compression. - * If M=0 and DAC=1: */ - if (cid) { - dci = ipv6_hdr_fields[3] & 0x0f; - } - - mutex_lock(&lowpan_context_mutex); - - if ((lowpan_iphc[1] & SIXLOWPAN_IPHC2_DAM) & 0x03) { - con = lowpan_context_num_lookup(dci); - } - - if (con == NULL) { - printf("ERROR: context not found\n"); - mutex_unlock(&lowpan_context_mutex); - return; - } - - /* By RFC 6282 3.1.1. Bits covered by context - * information are always used. */ - memcpy(&(ipv6_buf->destaddr.uint8[0]), &con->prefix, con->length); - - mutex_unlock(&lowpan_context_mutex); - } - } - - uint8_t *ptr = get_payload_buf(ipv6_ext_hdr_len); - - if (lowpan_iphc[0] & SIXLOWPAN_IPHC1_NH) { - if ((ipv6_hdr_fields[hdr_pos] & SIXLOWPAN_NHC_UDP_MASK) == SIXLOWPAN_NHC_UDP_ID) { - ipv6_buf->nextheader = IPV6_PROTO_NUM_UDP; - /* ipv6 length */ - ipv6_buf->length = HTONS(length - hdr_pos + 1); - packet_length = IPV6_HDR_LEN + ipv6_buf->length; - - hdr_pos ++; - /* copy inline src_port and dst_port */ - memcpy(ptr, &ipv6_hdr_fields[hdr_pos], 4); - hdr_pos += 4; - ptr += 4; - /* insert length value */ - *((uint16_t*)ptr) = ipv6_buf->length; - ptr += 2; - } - } - else { - /* ipv6 length */ - ipv6_buf->length = HTONS(length - hdr_pos); - packet_length = IPV6_HDR_LEN + ipv6_buf->length; - } - - memcpy(ptr, &ipv6_hdr_fields[hdr_pos], length - hdr_pos); -} - -uint8_t lowpan_context_len(void) -{ - return context_len; -} - -void lowpan_context_remove(uint8_t num) -{ - int i, j; - - for (i = 0; i < NDP_6LOWPAN_CONTEXT_MAX; i++) { - if (contexts[i].num == num) { - context_len--; - break; - } - } - - abr_remove_context(num); - - for (j = i; j < (NDP_6LOWPAN_CONTEXT_MAX - 1); j++) { - contexts[j] = contexts[j + 1]; - } - memset(&contexts[NDP_6LOWPAN_CONTEXT_MAX - 1], 0, sizeof(lowpan_context_t)); -} - -lowpan_context_t *lowpan_context_update(uint8_t num, const ipv6_addr_t *prefix, - uint8_t length, uint8_t comp, - uint16_t lifetime) -{ - lowpan_context_t *context; - - if (lifetime == 0) { - lowpan_context_remove(num); - return NULL; - } - - if (context_len == NDP_6LOWPAN_CONTEXT_MAX) { - return NULL; - } - - context = lowpan_context_num_lookup(num); - - if (context == NULL) { - context = &(contexts[context_len++]); - } - - context->num = num; - memset((void *)(&context->prefix), 0, 16); - // length in bits - memcpy((void *)(&context->prefix), (void *)prefix, length / 8); - context->length = length; - context->comp = comp; - context->lifetime = lifetime; - return context; -} - -lowpan_context_t *lowpan_context_get(void) -{ - return contexts; -} - -lowpan_context_t *lowpan_context_lookup(ipv6_addr_t *addr) -{ - int i; - - lowpan_context_t *context = NULL; - - for (i = 0; i < lowpan_context_len(); i++) { - if (contexts[i].length > 0 && memcmp((void *)addr, &(contexts[i].prefix), - contexts[i].length) == 0) { - /* longer prefixes are always prefered */ - if (context == NULL || context->length < contexts[i].length) { - context = &contexts[i]; - } - } - } - - return context; -} - -lowpan_context_t *lowpan_context_num_lookup(uint8_t num) -{ - int i; - - for (i = 0; i < lowpan_context_len(); i++) { - if (contexts[i].num == num) { - return &contexts[i]; - } - } - - return NULL; -} - -static void *lowpan_context_auto_remove(void *arg) -{ - (void) arg; - - timex_t minute = timex_set(60, 0); - int i; - int8_t to_remove[NDP_6LOWPAN_CONTEXT_MAX]; - - while (1) { - vtimer_sleep(minute); - int8_t to_remove_size = 0; - mutex_lock(&lowpan_context_mutex); - - for (i = 0; i < lowpan_context_len(); i++) { - if (--(contexts[i].lifetime) == 0) { - to_remove[to_remove_size++] = contexts[i].num; - } - } - - for (i = 0; i < to_remove_size; i++) { - lowpan_context_remove(to_remove[i]); - } - - mutex_unlock(&lowpan_context_mutex); - } - - return NULL; -} - -void init_reas_bufs(lowpan_reas_buf_t *buf) -{ - memset(&buf->s_addr, 0, sizeof(net_if_eui64_t)); - memset(&buf->d_addr, 0, sizeof(net_if_eui64_t)); - buf->tag = 0; - memset(&buf->timestamp, 0, sizeof(timex_t)); - buf->packet_size = 0; - buf->current_packet_size = 0; - buf->packet = NULL; - buf->interval_list_head = NULL; - buf->next = NULL; -} - -int sixlowpan_lowpan_init_adhoc_interface(int if_id, const ipv6_addr_t *prefix) -{ - ipv6_addr_t tmp; - - /* if prefix is set */ - if (prefix != NULL) { - /* init network prefix */ - ipv6_addr_t save_prefix; - - ipv6_addr_init_prefix(&save_prefix, prefix, 64); - ndp_add_prefix_info(if_id, &save_prefix, 64, - NDP_OPT_PI_VLIFETIME_INFINITE, - NDP_OPT_PI_PLIFETIME_INFINITE, 1, - ICMPV6_NDP_OPT_PI_FLAG_AUTONOM); - ipv6_init_as_router(); - - /* add global address */ - if (!ipv6_addr_set_by_eui64(&tmp, if_id, prefix)) { - return 0; - } - - DEBUG("%s, %d: set unique address for interface %d to %s, according " - "to prefix %s\n", __FILE__, __LINE__, if_id, - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &tmp), - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &tmp)); - - if (!ipv6_net_if_add_addr(if_id, &tmp, NDP_ADDR_STATE_PREFERRED, - NDP_OPT_PI_VLIFETIME_INFINITE, - NDP_OPT_PI_PLIFETIME_INFINITE, 0)) { - return 0; - } - } - - return sixlowpan_lowpan_init_interface(if_id); -} - -int sixlowpan_lowpan_init_interface(int if_id) -{ - ipv6_addr_t tmp; - - /* init link-local prefix */ - ipv6_addr_set_link_local_prefix(&tmp); - - if (!ipv6_addr_set_by_eui64(&tmp, if_id, &tmp)) { - DEBUG("Can not set link-local by EUI-64 on interface %d\n", if_id); - return 0; - } - - DEBUG("%s, %d: sixlowpan_lowpan_init(): add link local address to " - "interface %d: %s\n", __FILE__, __LINE__, if_id, - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &tmp)); - - if (!ipv6_net_if_add_addr(if_id, &tmp, NDP_ADDR_STATE_PREFERRED, - NDP_OPT_PI_VLIFETIME_INFINITE, - NDP_OPT_PI_PLIFETIME_INFINITE, 0)) { - DEBUG("Can not add link-local address to interface %d\n", if_id); - return 0; - } - - /* add solicited nodes multicast address of link local address */ - ipv6_addr_set_solicited_node_addr(&tmp, &tmp); - DEBUG("%s, %d: sixlowpan_lowpan_init(): add solicited nodes multicast address " - "to of link layer address interface %d: %s\n", __FILE__, __LINE__, - if_id, ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &tmp)); - - if (!ipv6_net_if_add_addr(if_id, &tmp, NDP_ADDR_STATE_PREFERRED, - NDP_OPT_PI_VLIFETIME_INFINITE, - NDP_OPT_PI_PLIFETIME_INFINITE, 0)) { - DEBUG("Can not add all nodes address to interface %d\n", if_id); - return 0; - } - - /* add all nodes multicast address */ - ipv6_addr_set_all_nodes_addr(&tmp); - DEBUG("%s, %d: sixlowpan_lowpan_init(): add all nodes multicast address " - "to interface %d: %s\n", __FILE__, __LINE__, if_id, - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &tmp)); - - if (!ipv6_net_if_add_addr(if_id, &tmp, NDP_ADDR_STATE_PREFERRED, - NDP_OPT_PI_VLIFETIME_INFINITE, - NDP_OPT_PI_PLIFETIME_INFINITE, 0)) { - DEBUG("Can not add all nodes address to interface %d\n", if_id); - return 0; - } - - /* add loopback address */ - ipv6_addr_set_loopback_addr(&tmp); - DEBUG("%s, %d: sixlowpan_lowpan_init(): add loopback address to interface " - "0: %s\n", __FILE__, __LINE__, - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &tmp)); - - if (!ipv6_net_if_add_addr(0, &tmp, NDP_ADDR_STATE_PREFERRED, - NDP_OPT_PI_VLIFETIME_INFINITE, - NDP_OPT_PI_PLIFETIME_INFINITE, 0)) { - DEBUG("Can not add all nodes address to interface %d\n", if_id); - return 0; - } - - icmpv6_send_router_sol(OPT_SLLAO); - - return 1; -} - -int sixlowpan_lowpan_init(void) -{ - short i; - - /* init mac-layer and radio transceiver */ - sixlowpan_mac_init(); - - if (ip_process_pid == KERNEL_PID_UNDEF) { - ip_process_pid = thread_create(ip_process_buf, IP_PROCESS_STACKSIZE, - THREAD_PRIORITY_MAIN - 1, CREATE_STACKTEST, - ipv6_process, NULL, "ip_process"); - } - - if (ip_process_pid == KERNEL_PID_UNDEF) { - return 0; - } - - nbr_cache_auto_rem(); - - contexts_rem_pid = thread_create(con_buf, CON_STACKSIZE, - THREAD_PRIORITY_MAIN + 1, CREATE_STACKTEST, - lowpan_context_auto_remove, NULL, "lowpan_context_rem"); - - if (contexts_rem_pid == KERNEL_PID_UNDEF) { - return 0; - } - - transfer_pid = thread_create(lowpan_transfer_buf, LOWPAN_TRANSFER_BUF_STACKSIZE, - THREAD_PRIORITY_MAIN - 1, CREATE_STACKTEST, - lowpan_transfer, NULL, "lowpan_transfer"); - - if (transfer_pid == KERNEL_PID_UNDEF) { - return 0; - } - - for (i = 0; i < SIXLOWIP_MAX_REGISTERED; i++) { - sixlowip_reg[i] = 0; - } - - return 0; -} - - -void sixlowpan_lowpan_bootstrapping(void) -{ - - icmpv6_send_router_sol(OPT_SLLAO); -} diff --git a/sys/net/network_layer/sixlowpan/lowpan.h b/sys/net/network_layer/sixlowpan/lowpan.h deleted file mode 100644 index 39e0a4f018..0000000000 --- a/sys/net/network_layer/sixlowpan/lowpan.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2013 INRIA. - * - * 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. - */ - -/** - * @file - * @brief 6lowpan header - * - * @author Stephan Zeisberg - * @author Martine Lenders - * @author Oliver Gesch - * @author Eric Engel - */ - -#ifndef _SIXLOWPAN_LOWPAN_H -#define _SIXLOWPAN_LOWPAN_H - -#include "mutex.h" -#include "net_if.h" -#include "vtimer.h" - -#include "sixlowpan/lowpan.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define IEEE802154_TRANSCEIVER (TRANSCEIVER_AT86RF231 | TRANSCEIVER_CC2420 | TRANSCEIVER_MC1322X) - -typedef struct { - uint8_t num; - ipv6_addr_t prefix; - uint8_t length; - uint8_t comp; - uint16_t lifetime; -} lowpan_context_t; - -extern uint16_t local_address; -extern mutex_t lowpan_context_mutex; - -void lowpan_read(uint8_t *data, uint8_t length, net_if_eui64_t *s_addr, - net_if_eui64_t *d_addr); -uint8_t lowpan_context_len(void); -lowpan_context_t *lowpan_context_update(uint8_t num, - const ipv6_addr_t *prefix, - uint8_t length, uint8_t comp, - uint16_t lifetime); -lowpan_context_t *lowpan_context_get(void); -lowpan_context_t *lowpan_context_num_lookup(uint8_t num); - -#ifdef __cplusplus -} -#endif - -#endif /* _SIXLOWPAN_LOWPAN_H */ diff --git a/sys/net/network_layer/sixlowpan/mac.c b/sys/net/network_layer/sixlowpan/mac.c deleted file mode 100644 index da26e69792..0000000000 --- a/sys/net/network_layer/sixlowpan/mac.c +++ /dev/null @@ -1,340 +0,0 @@ -/* - * 6LoWPAN MAC - layer 2 implementations - * - * Copyright (C) 2013 INRIA. - * - * 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 sixlowpan - * @{ - * @file - * @brief 6lowpan link layer functions - * @author Stephan Zeisberg - * @author Martine Lenders - * @author Eric Engel - * @author Oliver Gesch - * @author Oliver Hahm - * @} - */ - - -#include -#include -#include - -#include "thread.h" -#include "msg.h" -#include "radio/radio.h" -#include "net_if.h" -#include "sixlowpan/mac.h" - -#include "ip.h" -#include "icmp.h" -#include "lowpan.h" -#include "ieee802154_frame.h" -#include "net_help.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -#define RADIO_STACK_SIZE (THREAD_STACKSIZE_MAIN) -#define RADIO_RCV_BUF_SIZE (64) -#define RADIO_SENDING_DELAY (1000) - -#define DEFAULT_IEEE_802154_PAN_ID (0x1234) - -static char radio_stack_buffer[RADIO_STACK_SIZE]; -static msg_t msg_q[RADIO_RCV_BUF_SIZE]; - -static uint8_t lowpan_mac_buf[PAYLOAD_SIZE]; -static uint8_t macdsn; - -static inline void mac_frame_short_to_eui64(net_if_eui64_t *eui64, - uint8_t *frame_short) -{ - /* Since this is a short address, which is never globally unique, we set - * the local/universal bit to 1. */ - eui64->uint32[0] = HTONL(0x020000ff); - eui64->uint16[2] = HTONS(0xfe00); - eui64->uint8[6] = frame_short[1]; - eui64->uint8[7] = frame_short[0]; -} - -static void *recv_ieee802154_frame(void *arg) -{ - (void) arg; - - msg_t m; -#if (defined(MODULE_AT86RF231) | \ - defined(MODULE_CC2420) | \ - defined(MODULE_MC1322X)) - ieee802154_packet_t *p; -#else - radio_packet_t *p; - uint8_t hdrlen; -#endif - uint8_t length; - ieee802154_frame_t frame; - net_if_eui64_t src, dst; - - msg_init_queue(msg_q, RADIO_RCV_BUF_SIZE); - - while (1) { - msg_receive(&m); - - if (m.type == PKT_PENDING) { -#if (defined(MODULE_AT86RF231) | \ - defined(MODULE_CC2420) | \ - defined(MODULE_MC1322X)) - p = (ieee802154_packet_t *) m.content.ptr; - memcpy(&frame, &p->frame, sizeof(ieee802154_frame_t)); - length = p->frame.payload_len; -#else - p = (radio_packet_t *) m.content.ptr; - hdrlen = ieee802154_frame_read(p->data, &frame, p->length); - length = p->length - hdrlen - IEEE_802154_FCS_LEN; -#endif - -#if ENABLE_DEBUG - DEBUG("INFO: Received IEEE 802.15.4. packet (length = %d):\n", length); - DEBUG("INFO: FCF:\n"); - ieee802154_frame_print_fcf_frame(&frame); - - DEBUG("Sender:"); - - for (uint8_t i = 0; i < 8; i++) { - printf("%02x ", frame.src_addr[i]); - } - - DEBUG("\n"); - - DEBUG("Receiver:"); - - for (size_t i = 0; i < 8; i++) { - printf("%02x ", frame.dest_addr[i]); - } - - DEBUG("\n"); - - DEBUG("Payload:\n"); - - for (uint8_t i = 0; i < frame.payload_len; i++) { - printf("%02x ", frame.payload[i]); - - if (!((i + 1) % 16) || i == frame.payload_len - 1) { - printf("\n"); - } - } - -#endif - - if (frame.fcf.src_addr_m == IEEE_802154_SHORT_ADDR_M) { - mac_frame_short_to_eui64(&src, frame.src_addr); - } - else if (frame.fcf.src_addr_m == IEEE_802154_LONG_ADDR_M) { - memcpy(&src, frame.src_addr, 8); - } - else { - DEBUG("Unknown IEEE 802.15.4 source address mode.\n"); - p->processing--; - continue; - } - - if (frame.fcf.dest_addr_m == IEEE_802154_SHORT_ADDR_M) { - mac_frame_short_to_eui64(&dst, frame.dest_addr); - } - else if (frame.fcf.dest_addr_m == IEEE_802154_LONG_ADDR_M) { - memcpy(&dst, frame.dest_addr, 8); - } - else { - DEBUG("Unknown IEEE 802.15.4 destination address mode.\n"); - p->processing--; - continue; - } - - /* deliver packet to network(6lowpan)-layer */ - lowpan_read(frame.payload, length, &src, &dst); - /* TODO: get interface ID somehow */ - - p->processing--; - } - else if (m.type == ENOBUFFER) { - DEBUG("Transceiver buffer full"); - } - else { - DEBUG("Unknown packet received"); - } - } - - return NULL; -} - -void set_ieee802154_fcf_values(ieee802154_frame_t *frame, uint8_t dest_mode, - uint8_t src_mode) -{ - frame->fcf.frame_type = IEEE_802154_DATA_FRAME; - frame->fcf.sec_enb = 0; - frame->fcf.frame_pend = 0; - frame->fcf.ack_req = 0; - frame->fcf.panid_comp = (frame->dest_pan_id == frame->src_pan_id); - frame->fcf.frame_ver = 0; - frame->fcf.src_addr_m = src_mode; - frame->fcf.dest_addr_m = dest_mode; -#if ENABLE_DEBUG - ieee802154_frame_print_fcf_frame(frame); -#endif -} - -void set_ieee802154_frame_values(int if_id, uint16_t dest_pan, - ieee802154_frame_t *frame) -{ - int32_t pan_id = net_if_get_pan_id(if_id); - // TODO: addresse aus ip paket auslesen und in frame einfuegen - - if (pan_id < 0) { - frame->dest_pan_id = NTOLES(dest_pan); - frame->src_pan_id = HTOLES(DEFAULT_IEEE_802154_PAN_ID); - } - else { - frame->dest_pan_id = NTOLES(dest_pan); - frame->src_pan_id = HTOLES((uint16_t)pan_id); - } - - frame->seq_nr = macdsn; - macdsn++; -} - -int sixlowpan_mac_prepare_ieee802144_frame( - ieee802154_frame_t *frame, int if_id, uint16_t dest_pan, const void *dest, - uint8_t dest_len, const void *payload, uint8_t length, uint8_t mcast) -{ - uint8_t src_mode = net_if_get_src_address_mode(if_id); - uint8_t dest_mode; - uint16_t *fcs; - set_ieee802154_frame_values(if_id, dest_pan, frame); - - if (dest_len == 8) { - dest_mode = IEEE_802154_LONG_ADDR_M; - } - else if (dest_len == 2) { - dest_mode = IEEE_802154_SHORT_ADDR_M; - } - else { - DEBUG("Illegal IEEE 802.15.4 address for address length %d\n", dest_len); - return -1; - } - - set_ieee802154_fcf_values(frame, dest_mode, src_mode); - - - if (src_mode == IEEE_802154_LONG_ADDR_M) { - net_if_get_eui64((net_if_eui64_t *)&frame->src_addr[0], if_id, 0); - } - else if (src_mode == IEEE_802154_SHORT_ADDR_M) { - uint16_t src = HTONS(net_if_get_hardware_address(if_id)); - memcpy(&frame->src_addr[0], &src, 2); - } - else { - DEBUG("Illegal IEEE 802.15.4 address mode: %d\n", src_mode); - return -1; - } - - if (mcast) { - memset(&frame->dest_addr[0], 0xff, dest_len); - } - else { - memcpy(&frame->dest_addr[0], dest, dest_len); - } - - frame->payload = (uint8_t *)payload; // payload won't be changed so cast is legal. - frame->payload_len = length; - uint8_t hdrlen = ieee802154_frame_get_hdr_len(frame); - - memset(&lowpan_mac_buf, 0, PAYLOAD_SIZE); - ieee802154_frame_init(frame, (uint8_t *)&lowpan_mac_buf); - memcpy(&lowpan_mac_buf[hdrlen], frame->payload, frame->payload_len); - /* set FCS */ -#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY)) - fcs = (uint16_t *)&lowpan_mac_buf[frame->payload_len + hdrlen+1]; -#else - fcs = (uint16_t *)&lowpan_mac_buf[frame->payload_len + hdrlen]; -#endif - *fcs = ieee802154_frame_get_fcs(lowpan_mac_buf, frame->payload_len + hdrlen); - DEBUG("IEEE802.15.4 frame - FCF: %02X %02X DPID: %02X SPID: %02X DSN: %02X\n", - lowpan_mac_buf[0], lowpan_mac_buf[1], frame->dest_pan_id, - frame->src_pan_id, frame->seq_nr); - - return hdrlen; -} - -int sixlowpan_mac_send_data(int if_id, - const void *dest, uint8_t dest_len, - const void *payload, - uint8_t payload_len, uint8_t mcast) -{ - if (mcast) { - return net_if_send_packet_broadcast(IEEE_802154_SHORT_ADDR_M, - payload, - payload_len); - } - else { - if (dest_len == 8) { - return net_if_send_packet_long(if_id, (net_if_eui64_t *) dest, - payload, (size_t)payload_len); - } - else if (dest_len == 2) { - return net_if_send_packet(if_id, NTOHS((*((net_if_eui64_t*)dest)).uint16[0]), - payload, (size_t)payload_len); - } - } - - return -1; -} - -int sixlowpan_mac_send_ieee802154_frame(int if_id, - const void *dest, uint8_t dest_len, - const void *payload, - uint8_t payload_len, uint8_t mcast) -{ - if (net_if_get_interface(if_id) && - net_if_get_interface(if_id)->transceivers & IEEE802154_TRANSCEIVER) { - return sixlowpan_mac_send_data(if_id, dest, dest_len, payload, - payload_len, mcast); - } - else { - ieee802154_frame_t frame; - uint16_t dest_pan = HTONS(0xabcd); - uint8_t length; - int hdrlen = sixlowpan_mac_prepare_ieee802144_frame(&frame, if_id, - dest_pan, dest, - dest_len, payload, - payload_len, mcast); - - if (hdrlen < 0) { - return -1; - } - - length = hdrlen + frame.payload_len + IEEE_802154_FCS_LEN; - - return sixlowpan_mac_send_data(if_id, dest, dest_len, lowpan_mac_buf, - length, mcast); - } -} - -kernel_pid_t sixlowpan_mac_init(void) -{ - kernel_pid_t recv_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, - THREAD_PRIORITY_MAIN - 2, CREATE_STACKTEST, - recv_ieee802154_frame, NULL, "radio"); - int if_id = -1; - - while ((if_id = net_if_iter_interfaces(if_id)) >= 0) { - net_if_register(if_id, recv_pid); - } - - macdsn = rand() % 256; - - return recv_pid; -} diff --git a/sys/net/network_layer/sixlowpan/serialnumber.c b/sys/net/network_layer/sixlowpan/serialnumber.c deleted file mode 100644 index e328e487d7..0000000000 --- a/sys/net/network_layer/sixlowpan/serialnumber.c +++ /dev/null @@ -1,101 +0,0 @@ -/** - * serial number arithmetics (corresponding RFC1982) for version field in ABRO - * - * Copyright (C) 2013 INRIA. - * - * 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 sixlowpan - * @{ - * @file - * @brief serial number arithmetics (corresponding RFC1982) for version field in ABRO - * @author Martine Lenders - * @author Oliver Hahm - * @} - */ - - -#include "serialnumber.h" - -int serial_add8(uint8_t s, uint8_t n) -{ - if (n > 127) { - return -1; - } - - uint16_t sum = s + n; - return (uint8_t)(sum % 256); -} - -int serial_add16(uint16_t s, uint16_t n) -{ - if (n > 32767) { - return -1; - } - - uint32_t sum = s + n; - return (uint16_t)(sum % 65536); -} - -int serial_add32(uint32_t s, uint32_t n) -{ - if (n > 2147483647) { - return -1; - } - - uint64_t sum = s + n; - return (uint32_t)(sum % 4294967296); -} - -serial_comp_res_t serial_comp8(uint8_t s1, uint8_t s2) -{ - if (s1 == s2) { - return EQUAL; - } - - if ((s1 < s2 && s1 - s2 < 128) || (s1 > s2 && s1 - s2 > 128)) { - return LESS; - } - - if ((s1 < s2 && s1 - s2 > 128) || (s1 > s2 && s1 - s2 < 128)) { - return GREATER; - } - - return UNDEF; -} - -serial_comp_res_t serial_comp16(uint16_t s1, uint16_t s2) -{ - if (s1 == s2) { - return EQUAL; - } - - if ((s1 < s2 && s1 - s2 < 32768) || (s1 > s2 && s1 - s2 > 32768)) { - return LESS; - } - - if ((s1 < s2 && s1 - s2 > 32768) || (s1 > s2 && s1 - s2 < 32768)) { - return GREATER; - } - - return UNDEF; -} - -serial_comp_res_t serial_comp32(uint32_t s1, uint32_t s2) -{ - if (s1 == s2) { - return EQUAL; - } - - if ((s1 < s2 && s1 - s2 < 2147483648) || (s1 > s2 && s1 - s2 > 2147483648)) { - return LESS; - } - - if ((s1 < s2 && s1 - s2 > 2147483648) || (s1 > s2 && s1 - s2 < 2147483648)) { - return GREATER; - } - - return UNDEF; -} diff --git a/sys/net/network_layer/sixlowpan/serialnumber.h b/sys/net/network_layer/sixlowpan/serialnumber.h deleted file mode 100644 index 6a0c23745b..0000000000 --- a/sys/net/network_layer/sixlowpan/serialnumber.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2014 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. - */ - -/* - * Header file for serial number arithmetics [RFC1982] - */ - -#ifndef _SIXLOWPAN_SERIALNUMBER_H -#define _SIXLOWPAN_SERIALNUMBER_H -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum serial_comp_res_t { - LESS = 0, - EQUAL = 1, - GREATER = 2, - UNDEF = 3, -} serial_comp_res_t; - -/** - * @brief Addition for 8-bit unsigned integers in serial number - * arithmetics (corresponding RFC1982 section 3.1). - * @param[in] s first summand in [0 .. 2^8 - 1]. - * @param[in] n second summand in [0 .. 2^7 - 1]. - * @return sum corresponding RFC1982 section 3.1 if n in [0 .. 2^7 - 1] or - * -1 if n not in [0 .. 2^7 - 1]. - **/ -int serial_add8(uint8_t s, uint8_t n); - -/** - * @brief Addition for 16-bit unsigned integers in serial number - * arithmetics (corresponding RFC1982 section 3.1). - * @param[in] s first summand in [0 .. 2^16 - 1]. - * @param[in] n second summand in [0 .. 2^15 - 1]. - * @return sum corresponding RFC1982 section 3.1 if n in [0 .. 2^15 - 1] or - * -1 if n not in [0 .. 2^15 - 1]. - **/ -int serial_add16(uint16_t s, uint16_t n); - -/** - * @brief Addition for 32-bit unsigned integers in serial number - * arithmetics (corresponding RFC1982 section 3.1). - * @param[in] s first summand in [0 .. 2^32 - 1]. - * @param[in] n second summand in [0 .. 2^31 - 1]. - * @return sum corresponding RFC1982 section 3.1 if n in [0 .. 2^31 - 1] or - * -1 if n not in [0 .. 2^31 - 1]. - **/ -int serial_add32(uint32_t s, uint32_t n); - -/** - * @brief Comparison of 8-bit unsigned integers in serial number - * arithmetics (corresponding RFC1982 section 3.2). - * @param[in] s1 first argument. - * @param[in] s2 second argument. - * @return LESS if s1 < s2. - * EQUAL if s1 = s2. - * GREATER if s1 > s2. - * else UNDEF (see RFC1982 section 3.2). - **/ -serial_comp_res_t serial_comp8(uint8_t s1, uint8_t s2); - -/** - * @brief Comparison of 16-bit unsigned integers in serial number - * arithmetics (corresponding RFC1982 section 3.2). - * @param[in] s1 first argument. - * @param[in] s2 second argument. - * @return LESS if s1 < s2. - * EQUAL if s1 = s2. - * GREATER if s1 > s2. - * else UNDEF (see RFC1982 section 3.2). - **/ -serial_comp_res_t serial_comp16(uint16_t s1, uint16_t s2); - -/** - * @brief Comparison of 32-bit unsigned integers in serial number - * arithmetics (corresponding RFC1982 section 3.2). - * @param[in] s1 first argument. - * @param[in] s2 second argument. - * @return LESS if s1 < s2. - * EQUAL if s1 = s2. - * GREATER if s1 > s2. - * else UNDEF (see RFC1982 section 3.2). - **/ -serial_comp_res_t serial_comp32(uint32_t s1, uint32_t s2); - -#ifdef __cplusplus -} -#endif - -#endif /* _SIXLOWPAN_SERIALNUMBER_H*/ diff --git a/sys/net/routing/etx_beaconing.c b/sys/net/routing/etx_beaconing.c deleted file mode 100644 index 7a2cfb00b7..0000000000 --- a/sys/net/routing/etx_beaconing.c +++ /dev/null @@ -1,566 +0,0 @@ -/* - * ETX beaconing implementation - * - * Copyright (C) 2013 Stephan Arndt - * - * 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 rpl - * @{ - * @file - * @brief ETX-beaconing implementation - * - * Implementation for ETX-based beaconing. - * - * @author Stephan Arndt - * @} - */ - -#include -#include -#include - -#include "mutex.h" -#include "hwtimer.h" -#include "vtimer.h" -#include "thread.h" -#include "transceiver.h" -#include "timex.h" - -#include "sixlowpan/ip.h" -#include "ieee802154_frame.h" -#include "etx_beaconing.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -#if ENABLE_DEBUG -#define ETX_BEACON_STACKSIZE (THREAD_STACKSIZE_DEFAULT + THREAD_EXTRA_STACKSIZE_PRINTF_FLOAT) -#define ETX_RADIO_STACKSIZE (THREAD_STACKSIZE_DEFAULT + THREAD_EXTRA_STACKSIZE_PRINTF_FLOAT) -#define ETX_CLOCK_STACKSIZE (THREAD_STACKSIZE_DEFAULT) -#else -#define ETX_BEACON_STACKSIZE (THREAD_STACKSIZE_MAIN) -#define ETX_RADIO_STACKSIZE (THREAD_STACKSIZE_MAIN) -#define ETX_CLOCK_STACKSIZE (THREAD_STACKSIZE_DEFAULT) -#endif - -/* prototytpes */ -static uint8_t etx_count_packet_tx(etx_neighbor_t *candidate); -static void etx_set_packets_received(void); -static bool etx_equal_id(ipv6_addr_t *id1, ipv6_addr_t *id2); - -static void *etx_beacon(void *); -static void *etx_clock(void *); -static void *etx_radio(void *); - -/* Buffer */ -static char etx_beacon_buf[ETX_BEACON_STACKSIZE]; -static char etx_radio_buf[ETX_RADIO_STACKSIZE]; -static char etx_clock_buf[ETX_CLOCK_STACKSIZE]; - -static uint8_t etx_send_buf[ETX_BUF_SIZE]; -static uint8_t etx_rec_buf[ETX_BUF_SIZE]; - -/* PIDs */ -static kernel_pid_t etx_beacon_pid = KERNEL_PID_UNDEF; -static kernel_pid_t etx_radio_pid = KERNEL_PID_UNDEF; -static kernel_pid_t etx_clock_pid = KERNEL_PID_UNDEF; - -/* Message queue for radio */ -static msg_t msg_que[ETX_RCV_QUEUE_SIZE]; - -/* - * The counter for the current 'round'. An ETX beacon is sent every ETX_INTERVAL - * u-seconds and a node computes the ETX value by comparing the the received - * probes vs the expected probes from a neighbor every ETX_ROUND intervals. - */ -static uint8_t cur_round; - -/* - * If we have not yet reached WINDOW intervals, won't calculate the ETX just yet - */ -static char reached_window; - -/* - * This could (and should) be done differently, once the RPL implementation - * deals with candidate neighbors in another way than just defining that every - * possible neighbor we hear from is a parent. - * Right now, we need to keep track of the ETX values of other nodes without - * needing them to be in our parent array, so we have another array here in - * which we put all necessary info for up to ETX_MAX_CANDIDATE_NEIHGBORS - * candidates. - */ -/* Candidate array */ -static etx_neighbor_t candidates[ETX_MAX_CANDIDATE_NEIGHBORS]; - -/* - * Each time we send a beacon packet we need to reset some values for the - * current 'round' (a round being the time between each sent beacon packet). - * - * In this time, no packet may be handled, otherwise it could assume values - * from the last round to count for this round. - */ -static mutex_t etx_mutex = MUTEX_INIT; - -static ipv6_addr_t *own_address; - -static etx_probe_t *etx_get_send_buf(void) -{ - return ((etx_probe_t *) &(etx_send_buf[0])); -} - -static etx_probe_t *etx_get_rec_buf(void) -{ - return ((etx_probe_t *) &(etx_rec_buf[0])); -} - -void etx_show_candidates(void) -{ - etx_neighbor_t *candidate; - etx_neighbor_t *end; - - for (candidate = &candidates[0], end = candidates - + ETX_MAX_CANDIDATE_NEIGHBORS; candidate < end; - candidate++) { - if (candidate->used == 0) { - break; - } - - printf("Candidates Addr:%d\n" - "\t cur_etx:%f\n" - "\t packets_rx:%d\n" - "\t packets_tx:%d\n" - "\t used:%d\n", candidate->addr.uint8[ETX_IPV6_LAST_BYTE], - candidate->cur_etx, candidate->packets_rx, - etx_count_packet_tx(candidate), - candidate->used); - } -} - -void etx_init_beaconing(ipv6_addr_t *address) -{ - own_address = address; - /* set code */ - DEBUGF("ETX BEACON INIT"); - etx_send_buf[0] = ETX_PKT_OPTVAL; - - etx_beacon_pid = thread_create(etx_beacon_buf, sizeof(etx_beacon_buf), - THREAD_PRIORITY_MAIN - 1, CREATE_STACKTEST, - etx_beacon, NULL, "etx_beacon"); - - etx_radio_pid = thread_create(etx_radio_buf, sizeof(etx_radio_buf), - THREAD_PRIORITY_MAIN - 1, CREATE_STACKTEST, - etx_radio, NULL, "etx_radio"); - - etx_clock_pid = thread_create(etx_clock_buf, sizeof(etx_clock_buf), - THREAD_PRIORITY_MAIN - 1, CREATE_STACKTEST, - etx_clock, NULL, "etx_clock"); - /* register at transceiver */ - transceiver_register(TRANSCEIVER_CC1100, etx_radio_pid); - DEBUG("...[DONE]\n"); -} - -static void *etx_beacon(void *arg) -{ - (void) arg; - - /* - * Sends a message every ETX_INTERVAL +/- a jitter-value (default is 10%) . - * A correcting variable is needed to stay at a base interval of - * ETX_INTERVAL between the wakeups. It takes the old jittervalue in account - * and modifies the time to wait accordingly. - */ - etx_probe_t *packet = etx_get_send_buf(); - - while (true) { - thread_sleep(); - mutex_lock(&etx_mutex); - /* Build etx packet */ - uint8_t p_length = 0; - - for (uint8_t i = 0; i < ETX_BEST_CANDIDATES; i++) { - if (candidates[i].used != 0) { - packet->data[i * ETX_TUPLE_SIZE] = - candidates[i].addr.uint8[ETX_IPV6_LAST_BYTE]; - packet->data[i * ETX_TUPLE_SIZE + ETX_PKT_REC_OFFSET] = - etx_count_packet_tx(&candidates[i]); - p_length = p_length + ETX_PKT_HDR_LEN; - } - } - - packet->length = p_length; - /* will be send broadcast, so if_id and destination address will be - * ignored (see documentation) - */ - sixlowpan_mac_send_ieee802154_frame(0, NULL, 8, &etx_send_buf[0], - ETX_DATA_MAXLEN + ETX_PKT_HDR_LEN, 1); - DEBUG("sent beacon!\n"); - etx_set_packets_received(); - cur_round++; - - if (cur_round == ETX_WINDOW) { - if (reached_window != 1) { - /* first round is through */ - reached_window = 1; - } - - cur_round = 0; - } - - mutex_unlock(&etx_mutex); - } - - return NULL; -} - -etx_neighbor_t *etx_find_candidate(ipv6_addr_t *address) -{ - /* - * find the candidate with address address and returns it, or returns NULL - * if no candidate having this address was found. - */ - for (uint8_t i = 0; i < ETX_MAX_CANDIDATE_NEIGHBORS; i++) { - if (candidates[i].used - && (etx_equal_id(&candidates[i].addr, address))) { - return &candidates[i]; - } - } - - return NULL ; -} - -static void *etx_clock(void *arg) -{ - (void) arg; - - /* - * Manages the etx_beacon thread to wake up every full second +- jitter - */ - - /* - * The jittercorrection and jitter variables keep usecond values divided - * through 1000 to fit into uint8 variables. - * - * That is why they are multiplied by 1000 when used for hwtimer_wait. - */ - uint8_t jittercorrection = ETX_DEF_JIT_CORRECT; - uint8_t jitter = (uint8_t)(rand() % ETX_JITTER_MOD); - - while (true) { - thread_wakeup(etx_beacon_pid); - - /* - * Vtimer is buggy, but I seem to have no hwtimers left, so using this - * for now. - */ - vtimer_usleep( - ((ETX_INTERVAL - ETX_MAX_JITTER) * MS_IN_USEC) + - jittercorrection * MS_IN_USEC + - jitter * MS_IN_USEC - ETX_CLOCK_ADJUST); - - /* hwtimer_wait(HWTIMER_TICKS( - ((ETX_INTERVAL - ETX_MAX_JITTER)*MS_IN_USEC) + - jittercorrection*MS_IN_USEC + - jitter*MS_IN_USEC - ETX_CLOCK_ADJUST)); */ - - jittercorrection = (ETX_MAX_JITTER) - jitter; - jitter = (uint8_t)(rand() % ETX_JITTER_MOD); - } - - return NULL; -} - -double etx_get_metric(ipv6_addr_t *address) -{ - etx_neighbor_t *candidate = etx_find_candidate(address); - - if (candidate != NULL) { - if (etx_count_packet_tx(candidate) > 0) { - /* this means the current etx_value is not outdated */ - return candidate->cur_etx; - } - else { - /* The last time I received a packet is too long ago to give a */ - /* good estimate of the etx value */ - return 0; - } - } - - return 0; -} - -etx_neighbor_t *etx_add_candidate(ipv6_addr_t *address) -{ - DEBUG("add candidate\n"); - /* - * Pre-Condition: etx_add_candidate should only be called when the - * candidate is not yet in the list. - * Otherwise the candidate will be added a second time, - * leading to unknown behavior. - * - * Check if there is still enough space to add this candidate - * - * a) - * Space is available: - * Add candidate - * - * b) - * Space is not available: - * ignore new candidate - * This shouldn't really happen though, since we have enough - * place in the array. - * - * Returns the pointer to the candidate if it was added, or a NULL-pointer - * otherwise. - */ - etx_neighbor_t *candidate; - etx_neighbor_t *end; - - for (candidate = &candidates[0], end = candidates - + ETX_MAX_CANDIDATE_NEIGHBORS; candidate < end; - candidate++) { - if (candidate->used) { - /* skip */ - continue; - } - else { - /* We still have a free place add the new candidate */ - memset(candidate, 0, sizeof(*candidate)); - candidate->addr = *address; - candidate->cur_etx = 0; - candidate->packets_rx = 0; - candidate->used = 1; - return candidate; - } - } - - return NULL ; -} - -void etx_handle_beacon(ipv6_addr_t *candidate_address) -{ - /* - * Handle the ETX probe that has been received and update all infos. - * If the candidate address is unknown, try to add it to my struct. - */ - - DEBUG( - "ETX beacon package received with following values:\n" - "\tPackage Option:%x\n" - "\t Data Length:%u\n" - "\tSource Address:%d\n\n", etx_rec_buf[ETX_PKT_OPT], etx_rec_buf[ETX_PKT_LEN], - candidate_address->uint8[ETX_IPV6_LAST_BYTE]); - - etx_neighbor_t *candidate = etx_find_candidate(candidate_address); - - if (candidate == NULL) { - /* Candidate was not found in my list, I should add it */ - candidate = etx_add_candidate(candidate_address); - - if (candidate == NULL) { - DEBUGF("[ERROR] Candidate could not get added\n"); - DEBUG("Increase the constant ETX_MAX_CANDIDATE_NEIHGBORS\n"); - return; - } - } - - /* I have received 1 packet from this candidate in this round */ - /* This value will be reset by etx_update to 0 */ - candidate->tx_cur_round = 1; - - /* If i find my address in this probe, update the packet_rx value for */ - /* this candidate. */ - etx_probe_t *rec_pkt = etx_get_rec_buf(); - - for (uint8_t i = 0; i < rec_pkt->length / ETX_TUPLE_SIZE; i++) { - DEBUG("\tIPv6 short Addr:%u\n" - "\tPackets f. Addr:%u\n\n", rec_pkt->data[i * ETX_TUPLE_SIZE], - rec_pkt->data[i * ETX_TUPLE_SIZE + ETX_PKT_REC_OFFSET]); - - if (rec_pkt->data[i * ETX_TUPLE_SIZE] - == own_address->uint8[ETX_IPV6_LAST_BYTE]) { - - candidate->packets_rx = rec_pkt->data[i * ETX_TUPLE_SIZE - + ETX_PKT_REC_OFFSET]; - } - } - - /* Last, update the ETX value for this candidate */ - etx_update(candidate); -} - -static void *etx_radio(void *arg) -{ - (void) arg; - - msg_t m; - radio_packet_t *p; - - ieee802154_frame_t frame; - - msg_init_queue(msg_que, ETX_RCV_QUEUE_SIZE); - - ipv6_addr_t ll_address; - ipv6_addr_t candidate_addr; - - ipv6_addr_set_link_local_prefix(&ll_address); - ipv6_net_if_get_best_src_addr(&candidate_addr, &ll_address); - - while (1) { - msg_receive(&m); - - if (m.type == PKT_PENDING) { - p = (radio_packet_t *) m.content.ptr; - - ieee802154_frame_read(p->data, &frame, p->length); - - if (frame.payload[0] == ETX_PKT_OPTVAL) { - /* copy to receive buffer */ - memcpy(etx_rec_buf, &frame.payload[0], frame.payload_len); - - /* create IPv6 address from radio packet */ - /* we can do the cast here since rpl nodes can only have addr */ - /* up to 8 bits */ - candidate_addr.uint8[ETX_IPV6_LAST_BYTE] = (uint8_t) p->src; - /* handle the beacon */ - mutex_lock(&etx_mutex); - etx_handle_beacon(&candidate_addr); - mutex_unlock(&etx_mutex); - } - - p->processing--; - } - else if (m.type == ENOBUFFER) { - DEBUGF("Transceiver buffer full\n"); - } - else { - /* packet is not for me, whatever */ - } - } - - return NULL; -} - -void etx_update(etx_neighbor_t *candidate) -{ - DEBUG("update!\n"); - /* - * Update the current ETX value of a candidate - */ - double d_f; - double d_r; - - if (reached_window != 1 || candidate == NULL) { - /* We will wait at least ETX_WINDOW beacons until we decide to */ - /* calculate an ETX value, so that we have a good estimate */ - return; - } - - /* - * Calculate d_f (the forward PDR) from ME to this candidate. - */ - d_f = candidate->packets_rx / (double) ETX_WINDOW; - - /* - * Calculate d_r (the backwards PDR) from this candidate to ME - */ - d_r = etx_count_packet_tx(candidate) / (double) ETX_WINDOW; - - /* - * Calculate the current ETX value for my link to this candidate. - */ - if (d_f * d_r != 0) { - candidate->cur_etx = 1 / (d_f * d_r); - } - else { - candidate->cur_etx = 0; - } - - DEBUG( - "Estimated ETX Metric is %f for candidate w/ addr %d\n" - "Estimated PDR_forward is %f\n" - "Estimated PDR_backwrd is %f\n" - "\n" - "Received Packets: %d\n" - "Sent Packets : %d\n\n", - candidate->cur_etx, candidate->addr.uint8[ETX_IPV6_LAST_BYTE], - d_f, d_r, candidate->packets_rx, etx_count_packet_tx(candidate)); -} - -static uint8_t etx_count_packet_tx(etx_neighbor_t *candidate) -{ - /* - * Counts the number of packets that were received for this candidate - * in the last ETX_WINDOW intervals. - */ - DEBUG("counting packets"); - uint8_t pkt_count = 0; - DEBUG("["); - - for (uint8_t i = 0; i < ETX_WINDOW; i++) { - if (i != cur_round) { - pkt_count = pkt_count + candidate->packets_tx[i]; - DEBUG("%d", candidate->packets_tx[i]); - - if (i < ETX_WINDOW - 1) { - DEBUG(","); - } - } - else { - /* Check if I received something for the current round */ - if (candidate->tx_cur_round == 0) { - /* Didn't receive a packet, zero the field and don't add */ - candidate->packets_tx[i] = 0; - DEBUG("%d!", candidate->packets_tx[i]); - - if (i < ETX_WINDOW - 1) { - DEBUG(","); - } - } - else { - /* Add 1 and set field */ - pkt_count = pkt_count + 1; - candidate->packets_tx[i] = 1; - DEBUG("%d!", candidate->packets_tx[i]); - - if (i < ETX_WINDOW - 1) { - DEBUG(","); - } - } - } - } - - DEBUG("]\n"); - return pkt_count; -} - -static void etx_set_packets_received(void) -{ - /* - * Set for all candidates if they received a packet this round or not - */ - for (uint8_t i = 0; i < ETX_MAX_CANDIDATE_NEIGHBORS; i++) { - if (candidates[i].used) { - if (candidates[i].tx_cur_round != 0) { - candidates[i].packets_tx[cur_round] = 1; - candidates[i].tx_cur_round = 0; - } - } - } -} - -bool etx_equal_id(ipv6_addr_t *id1, ipv6_addr_t *id2) -{ - for (uint8_t i = 0; i < 4; i++) { - if (id1->uint32[i] != id2->uint32[i]) { - return false; - } - } - - return true; - -} diff --git a/sys/net/routing/rpl/Makefile b/sys/net/routing/rpl/Makefile deleted file mode 100644 index d20ddfce5b..0000000000 --- a/sys/net/routing/rpl/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -# RPL_MOP values by IANA https://tools.ietf.org/html/rfc6550#page-129 -# RPL_MOP_NO_DOWNWARD_ROUTES 0x00 -# RPL_MOP_NON_STORING_MODE 0x01 -# RPL_MOP_STORING_MODE_NO_MC 0x02 -# RPL_MOP_STORING_MODE_MC 0x03 - -# Set the RPL MOP iff it is matching a provided mode -MODE := - -ifeq (RPL_MOP_NO_DOWNWARD_ROUTES, $(RPL_MOP)) - MODE := 0x00 -endif -ifeq (RPL_MOP_NON_STORING_MODE, $(RPL_MOP)) - MODE := 0x01 -endif -ifeq (RPL_MOP_STORING_MODE_NO_MC, $(RPL_MOP)) - MODE := 0x02 -endif -ifeq (RPL_MOP_STORING_MODE_MC, $(RPL_MOP)) - MODE := 0x03 -endif - -# If a valid RPL_MOP was provided, use it for RPL -ifneq (,$(MODE)) - CFLAGS += -DRPL_DEFAULT_MOP=$(MODE) -else - # If no (valid) RPL_MOP has been provided, use the following parameters - CFLAGS += -DRPL_DEFAULT_MOP=0x02 -endif - -# Set the maximum number of routing entries to 128 if no number is provided -ifneq (,$(RPL_MAX_ROUTING_ENTRIES)) - CFLAGS += -DRPL_MAX_ROUTING_ENTRIES=$(RPL_MAX_ROUTING_ENTRIES) -endif - -# Define this node as root at compile time (required only for non-storing mode) -ifneq (,$(RPL_NODE_IS_ROOT)) - CFLAGS += -DRPL_NODE_IS_ROOT -endif - -include $(RIOTBASE)/Makefile.base diff --git a/sys/net/routing/rpl/of0.c b/sys/net/routing/rpl/of0.c deleted file mode 100644 index 3f3778cbd7..0000000000 --- a/sys/net/routing/rpl/of0.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2014 Oliver Hahm - * - * 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 rpl - * @{ - * @file - * @brief Objective Function Zero. - * - * Implementation of Objective Function Zero. - * - * @author Eric Engel - * @} - */ - -#include -#include "of0.h" - -//Function Prototypes -static uint16_t calc_rank(rpl_parent_t *, uint16_t); -static rpl_parent_t *which_parent(rpl_parent_t *, rpl_parent_t *); -static rpl_dodag_t *which_dodag(rpl_dodag_t *, rpl_dodag_t *); -static void reset(rpl_dodag_t *); - -static rpl_of_t rpl_of0 = { - 0x0, - calc_rank, - which_parent, - which_dodag, - reset, - NULL, - NULL, - NULL -}; - -rpl_of_t *rpl_get_of0(void) -{ - return &rpl_of0; -} - -void reset(rpl_dodag_t *dodag) -{ - /* Nothing to do in OF0 */ - (void) dodag; -} - -uint16_t calc_rank(rpl_parent_t *parent, uint16_t base_rank) -{ - if (base_rank == 0) { - if (parent == NULL) { - return INFINITE_RANK; - } - - base_rank = parent->rank; - } - - uint16_t add; - - if (parent != NULL) { - add = parent->dodag->minhoprankincrease; - } - else { - add = DEFAULT_MIN_HOP_RANK_INCREASE; - } - - if (base_rank + add < base_rank) { - return INFINITE_RANK; - } - - return base_rank + add; -} - -/* We simply return the Parent with lower rank */ -rpl_parent_t *which_parent(rpl_parent_t *p1, rpl_parent_t *p2) -{ - if (p1->rank < p2->rank) { - return p1; - } - - return p2; -} - -/* Not used yet, as the implementation only makes use of one dodag for now. */ -rpl_dodag_t *which_dodag(rpl_dodag_t *d1, rpl_dodag_t *d2) -{ - (void) d2; - return d1; -} diff --git a/sys/net/routing/rpl/of0.h b/sys/net/routing/rpl/of0.h deleted file mode 100644 index d0394f277e..0000000000 --- a/sys/net/routing/rpl/of0.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2014 Oliver Hahm - * - * 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 rpl - * @{ - * @file - * @brief Objective Function Zero. - * - * Header-file, which defines all functions for the implementation of Objective Function Zero. - * - * @author Eric Engel - * @} - */ - -#ifndef OF0_H -#define OF0_H - -#include "rpl/rpl_structs.h" -#include "rpl/rpl_config.h" - -#ifdef __cplusplus -extern "C" { -#endif - -rpl_of_t *rpl_get_of0(void); - -#ifdef __cplusplus -} -#endif - -#endif /* OF0_H */ diff --git a/sys/net/routing/rpl/of_mrhof.c b/sys/net/routing/rpl/of_mrhof.c deleted file mode 100644 index da77d6893d..0000000000 --- a/sys/net/routing/rpl/of_mrhof.c +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (C) 2013 Stephan Arndt - * - * 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 rpl - * @{ - * @file - * @brief Objective Function MRHOF. - * - * Implementation of Objective Function MRHOF. - * - * @author Eric Engel - * @} - */ - -#include -#include -#include "of_mrhof.h" - -#include "etx_beaconing.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -// Function Prototypes -static uint16_t calc_rank(rpl_parent_t *, uint16_t); -static rpl_parent_t *which_parent(rpl_parent_t *, rpl_parent_t *); -static rpl_dodag_t *which_dodag(rpl_dodag_t *, rpl_dodag_t *); -static void reset(rpl_dodag_t *); -static uint16_t calc_path_cost(rpl_parent_t *parent); - -static uint16_t cur_min_path_cost = MAX_PATH_COST; -static rpl_parent_t *cur_preferred_parent = NULL; - -static rpl_of_t rpl_of_mrhof = { - 0x1, - calc_rank, - which_parent, - which_dodag, - reset, - NULL, - NULL, - NULL -}; - -rpl_of_t *rpl_get_of_mrhof(void) -{ - return &rpl_of_mrhof; -} - -void reset(rpl_dodag_t *dodag) -{ - (void) dodag; -} - -static uint16_t calc_path_cost(rpl_parent_t *parent) -{ - DEBUGF("calc_pathcost\n"); - - /* - * Calculates the path cost through the parent, for now, only for ETX - */ - if (parent == NULL) { - // Shouldn't ever happen since this function is supposed to be always - // run with a parent. If it does happen, we can assume a root called it. - DEBUGF("[WARNING] calc_path_cost called without parent!\n"); - return DEFAULT_MIN_HOP_RANK_INCREASE; - } - - double etx_value = etx_get_metric(&(parent->addr)); - DEBUGF("Metric for parent returned: %f\n", etx_value); - - if (etx_value != 0) { - /* - * (ETX_for_link_to_neighbor * 128) + Rank_of_that_neighbor - * - * This means I get the rank of that neighbor (which is the etx - * of the whole path from him to the root node) plus my ETX to - * that neighbor*128, which would be the 'rank' of the single link - * from me to that neighbor - * - */ - if (etx_value * ETX_RANK_MULTIPLIER > MAX_LINK_METRIC) { - // Disallow links with an estimated ETX of 4 or higher - return MAX_PATH_COST; - } - - if (etx_value * ETX_RANK_MULTIPLIER + parent->rank - < parent->rank) { - //Overflow - return MAX_PATH_COST; - } - - //TODO runden - return etx_value * ETX_RANK_MULTIPLIER - + parent->rank; - } - else { - // IMPLEMENT HANDLING OF OTHER METRICS HERE - // if it is 0, it hasn't been computed, thus we cannot compute a path - // cost - return MAX_PATH_COST; - } -} - -static uint16_t calc_rank(rpl_parent_t *parent, uint16_t base_rank) -{ - DEBUGF("calc_rank\n"); - - /* - * Return the rank for this node. - * - * For now, there is no metric-selection or specification, so the rank com- - * putation will always be assumed to be done for the ETX metric. - * Baserank is pretty much only used to find out if a node is a root or not. - */ - if (parent == NULL) { - if (base_rank == 0) { - //No parent, no rank, a root node would have a rank != 0 - return INFINITE_RANK; - } - - /* - * No parent, base_rank != 0 means this is a root node or a node which - * is recalculating. - * Since a recalculating node must have a parent in this implementation - * (see rpl.c, function global_repair), we can assume this node is root. - */ - return DEFAULT_MIN_HOP_RANK_INCREASE; - } - else { - /* - * We have a parent and are a non-root node, calculate the path cost for - * the parent and choose the maximum of that value and the advertised - * rank of the parent + minhoprankincrease for our rank. - */ - uint16_t calculated_pcost = calc_path_cost(parent); - - if (calculated_pcost < MAX_PATH_COST) { - if ((parent->rank + parent->dodag->minhoprankincrease) - > calculated_pcost) { - return parent->rank + parent->dodag->minhoprankincrease; - } - else { - return calculated_pcost; - } - } - else { - //Path costs are greater than allowed - return INFINITE_RANK; - } - } -} - -static rpl_parent_t *which_parent(rpl_parent_t *p1, rpl_parent_t *p2) -{ - DEBUGF("which_parent\n"); - /* - * Return the parent with the lowest path cost. - * Before returning any of the two given parents, make sure that a switch is - * desirable. - * - */ - uint16_t path_p1 = calc_path_cost(p1); - uint16_t path_p2 = calc_path_cost(p2); - - if (cur_preferred_parent != NULL) { - //test if the parent from which we got this path is still active - if (cur_preferred_parent->used != 0) { - // Test, if the current best path is better than both parents given - if (cur_min_path_cost < path_p1 + PARENT_SWITCH_THRESHOLD - && cur_min_path_cost < path_p2 + PARENT_SWITCH_THRESHOLD) { - return cur_preferred_parent; - } - } - } - - if (path_p1 < path_p2) { - /* - * Return the current best parent, and set it as current best parent - */ - cur_min_path_cost = path_p1; - cur_preferred_parent = p1; - return p1; - } - - cur_min_path_cost = path_p2; - cur_preferred_parent = p2; - return p2; -} - -//Not used yet, as the implementation only makes use of one dodag for now. -static rpl_dodag_t *which_dodag(rpl_dodag_t *d1, rpl_dodag_t *d2) -{ - (void) d2; - return d1; -} diff --git a/sys/net/routing/rpl/of_mrhof.h b/sys/net/routing/rpl/of_mrhof.h deleted file mode 100644 index 71aa8d0424..0000000000 --- a/sys/net/routing/rpl/of_mrhof.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2013 Stephan Arndt - * - * 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 rpl - * @{ - * @file - * @brief Objective Function MRHOF. - * - * Header-file, which defines all functions for the implementation of Objective Function MRHOF. - * - * @author Eric Engel - * @} - */ - -#ifndef OF_MRHOF_H -#define OF_MRHOF_H - -#include "rpl/rpl_structs.h" -#include "rpl/rpl_config.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Disallow links with greater than 4 expected - * transmission counts on the selected path. - */ -#define MAX_LINK_METRIC (512) - -/** - * Disallow paths with greater than 256 - * expected transmission counts. - */ -#define MAX_PATH_COST (0x8000) - -/** - * Switch to a new path only if it is - * expected to require at least 1.5 fewer transmissions than the - * current path. - */ -#define PARENT_SWITCH_THRESHOLD (192) - -/** - * Do not allow a node to become a floating root. - * (Currently unused, since the RPL-implementation does not allow for floating - * roots). - */ -#define ALLOW_FLOATING_ROOT (0) - -/** - * While assigning Rank when using ETX, use the representation of ETX described - * in [RFC6551], i.e., assign Rank equal to ETX * 128. - */ -#define ETX_RANK_MULTIPLIER (0x80) - -rpl_of_t *rpl_get_of_mrhof(void); - -#ifdef __cplusplus -} -#endif - -#endif /* OF_MRHOF_H */ diff --git a/sys/net/routing/rpl/rpl.c b/sys/net/routing/rpl/rpl.c deleted file mode 100644 index 102012c18f..0000000000 --- a/sys/net/routing/rpl/rpl.c +++ /dev/null @@ -1,632 +0,0 @@ -/* - * Copyright (C) 2013 - 2014 INRIA. - * Copyright (C) 2015 Cenk GündoÄŸan - * - * 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 rpl - * @{ - * - * @file - * @brief Implementation of the RPL-core. - * - * Implementation of core RPL-functions. Normally it shouldn't be necessary to - * modify this file. - * - * @author Eric Engel - * @author Fabian Brandt - * @author Cenk GündoÄŸan - */ - -#include -#include "vtimer.h" -#include "thread.h" - -#include "msg.h" -#include "rpl.h" -#include "etx_beaconing.h" -#include "of0.h" -#include "of_mrhof.h" -#include "trickle.h" - -#include "sixlowpan.h" -#include "net_help.h" - -#define ENABLE_DEBUG (0) -#if ENABLE_DEBUG -static char addr_str[IPV6_MAX_ADDR_STR_LEN]; -#endif -#include "debug.h" - -/* global variables */ -kernel_pid_t rpl_process_pid = KERNEL_PID_UNDEF; -msg_t rpl_msg_queue[RPL_PKT_RECV_BUF_SIZE]; -char rpl_process_buf[RPL_PROCESS_STACKSIZE]; -uint8_t rpl_buffer[BUFFER_SIZE - LL_HDR_LEN]; -static timex_t rt_time; -static vtimer_t rt_timer; -uint8_t rpl_if_id; - -static void _dao_handle_send(rpl_dodag_t *dodag); -static void _rpl_update_routing_table(void); - -#if RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE -#if RPL_MAX_ROUTING_ENTRIES != 0 -static uint8_t srh_buffer[BUFFER_SIZE]; -#endif -static uint8_t srh_send_buffer[BUFFER_SIZE]; -static ipv6_addr_t *down_next_hop; -static ipv6_srh_t *srh_header; -static msg_t srh_m_send, srh_m_recv; -#endif - -#if RPL_MAX_ROUTING_ENTRIES != 0 -static rpl_routing_entry_t rpl_routing_table[RPL_MAX_ROUTING_ENTRIES]; -#endif -uint8_t rpl_max_routing_entries; -ipv6_addr_t my_address; - -/* IPv6 message buffer */ -static ipv6_hdr_t *ipv6_buf; - -uint8_t rpl_init(int if_id, ipv6_addr_t *address) -{ - rpl_if_id = if_id; - - /* initialize routing table */ -#if RPL_MAX_ROUTING_ENTRIES != 0 - rpl_max_routing_entries = RPL_MAX_ROUTING_ENTRIES; -#endif - - rpl_process_pid = thread_create(rpl_process_buf, sizeof(rpl_process_buf), - THREAD_PRIORITY_MAIN - 1, CREATE_STACKTEST, - rpl_process, NULL, "rpl_process"); - - sixlowpan_lowpan_init_interface(if_id); - ipv6_register_rpl_handler(rpl_process_pid); - - if (address) { - my_address = *address; - ipv6_net_if_add_addr(if_id, &my_address, NDP_ADDR_STATE_PREFERRED, 0, 0, 0); - } - - /* add all-RPL-nodes address */ - ipv6_addr_t all_rpl_nodes; - ipv6_addr_set_all_rpl_nodes_addr(&all_rpl_nodes); - ipv6_net_if_add_addr(if_id, &all_rpl_nodes, NDP_ADDR_STATE_ANY, 0, 0, 0); - -#if (RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE) - ipv6_iface_set_srh_indicator(rpl_is_root); -#endif - ipv6_iface_set_routing_provider(rpl_get_next_hop); - DEBUGF("All addresses set!\n"); - - /* initialize objective function manager */ - rpl_of_manager_init(&my_address); - - rt_time = timex_set(RPL_LIFETIME_STEP, 0); - vtimer_set_msg(&rt_timer, rt_time, rpl_process_pid, RPL_MSG_TYPE_ROUTING_ENTRY_UPDATE, NULL); - - return SIXLOWERROR_SUCCESS; -} - -#if (RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE) -void internal_srh_process(ipv6_srh_t *srh_header) -{ - /* modify it accordingly - the number of entries is not depending on padding, - * because there is none. - */ - uint8_t n = srh_header->hdrextlen / sizeof(ipv6_addr_t); - - if (srh_header->segments_left > n) { - memset(&down_next_hop, 0, sizeof(ipv6_addr_t)); - DEBUGF("[Error] source-routing header is invalid.\n"); - } - else { - uint8_t segs = srh_header->segments_left; - DEBUGF("SRH-length: %d\n", srh_header->hdrextlen); - down_next_hop = &srh_header->route[n - segs]; - srh_header->segments_left = segs - 1; - DEBUGF("Segments left after reduction: %d\n", srh_header->segments_left); - DEBUGF("Next hop is: %s\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, down_next_hop)); - } -} -#endif - -void *rpl_process(void *arg) -{ - (void) arg; - - msg_t m_recv; - msg_init_queue(rpl_msg_queue, RPL_PKT_RECV_BUF_SIZE); - - rpl_dodag_t *dodag; - trickle_t *trickle; - - while (1) { - msg_receive(&m_recv); - - if (m_recv.type > ICMP_CODE_END) { - switch (m_recv.type) { - case RPL_MSG_TYPE_DAO_HANDLE: - dodag = (rpl_dodag_t *) m_recv.content.ptr; - - if (dodag->joined) { - _dao_handle_send(dodag); - } - - break; - - case RPL_MSG_TYPE_ROUTING_ENTRY_UPDATE: - _rpl_update_routing_table(); - break; - - case RPL_MSG_TYPE_TRICKLE_INTERVAL: - trickle = (trickle_t *) m_recv.content.ptr; - - if (trickle->callback.func != NULL) { - trickle_interval(trickle); - } - - break; - - case RPL_MSG_TYPE_TRICKLE_CALLBACK: - trickle = (trickle_t *) m_recv.content.ptr; - - if (trickle->callback.func != NULL) { - trickle_callback(trickle); - } - - break; - - default: - break; - } - - } - /* This is an RPL-related message. */ - else { - /* differentiate packet types */ - ipv6_buf = (ipv6_hdr_t *) m_recv.content.ptr; - memcpy(&rpl_buffer, ipv6_buf, NTOHS(ipv6_buf->length) + IPV6_HDR_LEN); - - if (ipv6_buf->nextheader == IPV6_PROTO_NUM_ICMPV6) { - - /* get code for message-interpretation and process message */ - DEBUGF("Received RPL information of type %04X and length %u\n", - m_recv.type, NTOHS(ipv6_buf->length)); - - switch (m_recv.type) { - case (ICMP_CODE_DIS): { - rpl_recv_DIS(); - break; - } - - case (ICMP_CODE_DIO): { - rpl_recv_DIO(); - break; - } - - case (ICMP_CODE_DAO): { - rpl_recv_DAO(); - break; - } - - case (ICMP_CODE_DAO_ACK): { - rpl_recv_DAO_ACK(); - break; - } - - default: - break; - } - } - -#if RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE - /* If the message is not RPL-type, it relates to non-storing mode */ - else if (RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE) { - - if (ipv6_buf->nextheader == IPV6_PROTO_NUM_SRH) { - srh_header = ((ipv6_srh_t *)(m_recv.content.ptr + IPV6_HDR_LEN)); - - /* if there are no segments left, the routing is finished */ - if (srh_header->segments_left == 0) { - DEBUGF("Source routing finished with next header: %02X.\n", - srh_header->nextheader); - DEBUGF("Size of srh: %d\n", srh_header->hdrextlen); - uint8_t *payload = ((uint8_t *)(m_recv.content.ptr + - IPV6_HDR_LEN + sizeof(ipv6_srh_t) + srh_header->hdrextlen)); - rpl_remove_srh_header(ipv6_buf, payload, srh_header->nextheader); - } - else { - internal_srh_process(srh_header); - - if (down_next_hop != NULL) { - uint8_t *payload = ((uint8_t *)(m_recv.content.ptr + IPV6_HDR_LEN)); - rpl_srh_sendto(payload, NTOHS(ipv6_buf->length), &ipv6_buf->srcaddr, - down_next_hop, srh_header, 0); - } - } - } - -#if RPL_MAX_ROUTING_ENTRIES != 0 - else { - srh_header = rpl_get_srh_header(ipv6_buf); - - if (srh_header != NULL) { - uint8_t *payload = ((uint8_t *)(m_recv.content.ptr + IPV6_HDR_LEN)); - rpl_srh_sendto(payload, NTOHS(ipv6_buf->length), - &ipv6_buf->srcaddr, &ipv6_buf->destaddr, srh_header, - srh_header->hdrextlen + sizeof(ipv6_srh_t)); - } - } - -#endif - } - -#endif - } - } -} - -void _rpl_update_routing_table(void) -{ - rpl_dodag_t *my_dodag, *end; - rpl_routing_entry_t *rt = rpl_get_routing_table(); - - for (unsigned int i = 0; i < rpl_max_routing_entries; i++) { - if (rt[i].used) { - if (rt[i].lifetime <= 1) { - memset(&rt[i], 0, sizeof(rt[i])); - } - else { - rt[i].lifetime = rt[i].lifetime - RPL_LIFETIME_STEP; - } - } - } - - for (my_dodag = rpl_dodags, end = my_dodag + RPL_MAX_DODAGS; my_dodag < end; my_dodag++) { - if ((my_dodag->used) && (my_dodag->my_preferred_parent != NULL)) { - if (my_dodag->my_preferred_parent->lifetime <= 1) { - DEBUGF("parent lifetime timeout\n"); - rpl_parent_update(my_dodag, NULL); - } - else { - my_dodag->my_preferred_parent->lifetime = - my_dodag->my_preferred_parent->lifetime - RPL_LIFETIME_STEP; - } - } - } - - vtimer_remove(&rt_timer); - vtimer_set_msg(&rt_timer, rt_time, rpl_process_pid, RPL_MSG_TYPE_ROUTING_ENTRY_UPDATE, NULL); -} - -void rpl_delay_dao(rpl_dodag_t *dodag) -{ - dodag->dao_time = timex_set(DEFAULT_DAO_DELAY, 0); - dodag->dao_counter = 0; - dodag->ack_received = false; - vtimer_remove(&dodag->dao_timer); - vtimer_set_msg(&dodag->dao_timer, dodag->dao_time, - rpl_process_pid, RPL_MSG_TYPE_DAO_HANDLE, dodag); -} - -/* This function is used for regular update of the routes. - * The Timer can be overwritten, as the normal delay_dao function gets called - */ -void long_delay_dao(rpl_dodag_t *dodag) -{ - dodag->dao_time = timex_set(REGULAR_DAO_INTERVAL, 0); - dodag->dao_counter = 0; - dodag->ack_received = false; - vtimer_remove(&dodag->dao_timer); - vtimer_set_msg(&dodag->dao_timer, dodag->dao_time, - rpl_process_pid, RPL_MSG_TYPE_DAO_HANDLE, dodag); -} - -void rpl_dao_ack_received(rpl_dodag_t *dodag) -{ - dodag->ack_received = true; - long_delay_dao(dodag); -} - -void _dao_handle_send(rpl_dodag_t *dodag) -{ - if ((dodag->ack_received == false) && (dodag->dao_counter < DAO_SEND_RETRIES)) { - dodag->dao_counter++; - rpl_send_DAO(dodag, NULL, 0, true, 0); - dodag->dao_time = timex_set(DEFAULT_WAIT_FOR_DAO_ACK, 0); - vtimer_remove(&dodag->dao_timer); - vtimer_set_msg(&dodag->dao_timer, dodag->dao_time, - rpl_process_pid, RPL_MSG_TYPE_DAO_HANDLE, dodag); - } - else if (dodag->ack_received == false) { - long_delay_dao(dodag); - } -} - -ipv6_addr_t *rpl_get_next_hop(ipv6_addr_t *addr) -{ - - DEBUGF("Looking up the next hop to %s\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, addr)); - -#if RPL_MAX_ROUTING_ENTRIES != 0 - - for (uint8_t i = 0; i < rpl_max_routing_entries; i++) { - if (rpl_routing_table[i].used) { - DEBUGF("checking %d: %s\n", i, - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &rpl_routing_table[i].address)); - } - - if ((RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE) && rpl_is_root()) { - if (rpl_routing_table[i].used && rpl_equal_id(&rpl_routing_table[i].address, addr)) { - DEBUGF("found %d: %s\n", i, - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - &rpl_routing_table[i].address)); - return &rpl_routing_table[i].address; - } - } - else { - if (rpl_routing_table[i].used && rpl_equal_id(&rpl_routing_table[i].address, addr)) { - DEBUGF("found %d: %s\n", i, - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - &rpl_routing_table[i].next_hop)); - return &rpl_routing_table[i].next_hop; - } - } - } - -#else - (void) addr; -#endif - - return (rpl_get_my_preferred_parent()); -} - -#if RPL_MAX_ROUTING_ENTRIES != 0 -void rpl_add_routing_entry(ipv6_addr_t *addr, ipv6_addr_t *next_hop, uint16_t lifetime) -{ - rpl_routing_entry_t *entry = rpl_find_routing_entry(addr); - - if (entry != NULL) { - entry->lifetime = lifetime; - return; - } - - DEBUGF("Adding routing entry %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, addr)); - - for (uint8_t i = 0; i < rpl_max_routing_entries; i++) { - if (!rpl_routing_table[i].used) { - memcpy(&rpl_routing_table[i].address, addr, sizeof(ipv6_addr_t)); - memcpy(&rpl_routing_table[i].next_hop, next_hop, sizeof(ipv6_addr_t)); - rpl_routing_table[i].lifetime = lifetime; - rpl_routing_table[i].used = 1; - break; - } - } -} -#endif - -#if RPL_MAX_ROUTING_ENTRIES != 0 -void rpl_del_routing_entry(ipv6_addr_t *addr) -{ - - DEBUGF("Deleting routing entry %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, addr)); - - for (uint8_t i = 0; i < rpl_max_routing_entries; i++) { - if (rpl_routing_table[i].used && rpl_equal_id(&rpl_routing_table[i].address, addr)) { - memset(&rpl_routing_table[i], 0, sizeof(rpl_routing_table[i])); - return; - } - } -} -#endif - -#if RPL_MAX_ROUTING_ENTRIES != 0 -rpl_routing_entry_t *rpl_find_routing_entry(ipv6_addr_t *addr) -{ - - DEBUGF("Finding routing entry %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, addr)); - - for (uint8_t i = 0; i < rpl_max_routing_entries; i++) { - if (rpl_routing_table[i].used && rpl_equal_id(&rpl_routing_table[i].address, addr)) { - return &rpl_routing_table[i]; - } - } - - return NULL; -} -#endif - -rpl_routing_entry_t *rpl_get_routing_table(void) -{ -#if RPL_MAX_ROUTING_ENTRIES != 0 - return rpl_routing_table; -#else - return NULL; -#endif -} - -#if RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE -/* everything from here on is non-storing mode related */ - -#if RPL_MAX_ROUTING_ENTRIES != 0 -void rpl_add_srh_entry(ipv6_addr_t *child, ipv6_addr_t *parent, uint16_t lifetime) -{ - - rpl_routing_entry_t *entry = rpl_find_routing_entry(child); - - /* If we already have this entry and the parent from parent/child is the same as already - * registered, we only update the lifetime. If only the parent of the child changes, we - * delete the previous entry and add it below. - */ - if (entry != NULL) { - if (ipv6_addr_is_equal(parent, &entry->next_hop)) { - entry->lifetime = lifetime; - return; - } - else { - rpl_del_routing_entry(child); - } - } - - /* This maybe a bit confusing since the root also using the standard routing table, - * but in this case the code stays cleaner - especially for rt_over_timer from trickle.c. - * Just keep in mind that address is now child (unique, iteration variable) and parent is - * now next_hop. The whole routing table transforms to a list of children and their parents, - * so that route aggregation can be done properly. - */ - DEBUGF("Adding source-routing entry child: %s\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, child)); - DEBUGF("Adding source-routing entry parent: %s\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, parent)); - - for (uint8_t i = 0; i < rpl_max_routing_entries; i++) { - if (!rpl_routing_table[i].used) { - memcpy(&rpl_routing_table[i].address, child, sizeof(ipv6_addr_t)); - memcpy(&rpl_routing_table[i].next_hop, parent, sizeof(ipv6_addr_t)); - rpl_routing_table[i].lifetime = lifetime; - rpl_routing_table[i].used = 1; - break; - } - } -} -#endif - -/** - * @brief Checks if two IPv6 host suffixes are equal. - * - * @param[in] a An IPv6 address. - * @param[in] b Another IPv6 address. - * - * @return 1 if *a* and *b* are equal for host suffixes, 0 otherwise. - */ -int ipv6_suffix_is_equal(const ipv6_addr_t *a, const ipv6_addr_t *b) -{ - return (a->uint32[2] == b->uint32[2]) && - (a->uint32[3] == b->uint32[3]); -} - -#if RPL_MAX_ROUTING_ENTRIES != 0 -ipv6_srh_t *rpl_get_srh_header(ipv6_hdr_t *act_ipv6_hdr) -{ - uint8_t route_length = RPL_MAX_SRH_PATH_LENGTH; - ipv6_addr_t rev_route[route_length]; - ipv6_addr_t *actual_node; - uint8_t counter = 0; - uint8_t traceable; - ipv6_srh_t *srh_header = (ipv6_srh_t *)(&srh_buffer); - - /* init source route with child */ - actual_node = &(act_ipv6_hdr->destaddr); - DEBUGF("DESTINATION NODE: %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, actual_node)); - - while (!(rpl_equal_id(actual_node, &my_address))) { - /* set check variable - this is reversed, - * if a child/parent-relation is found in one iteration of the routing table */ - traceable = 0; - - for (uint8_t i = 0; i < rpl_max_routing_entries; i++) { - if (rpl_routing_table[i].used - && ipv6_suffix_is_equal(&rpl_routing_table[i].address, actual_node)) { - DEBUGF("[INFO] Found parent-child relation with P: %s\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - &rpl_routing_table[i].next_hop)); - DEBUGF(" and C: %s\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, actual_node)); - memcpy(&rev_route[counter], actual_node, sizeof(ipv6_addr_t)); - - actual_node = &rpl_routing_table[i].next_hop; - counter++; - traceable = 1; - - if (counter > route_length) { - DEBUGF("[INFO] Both lengths are %d and %d\n", counter, route_length); - DEBUGF("Error with computing source routing header.\n"); - return NULL; - } - - break; - } - } - - if (traceable == 0) { - DEBUGF("No route to destination.\n"); - return NULL; - } - } - - /* build real route based on reversed route. - * After building it starts with the node next to destination - */ - if (counter > 1) { - for (uint8_t i = 0; i < counter - 1; i++) { - memcpy(&srh_header->route[i], &rev_route[counter - i - 2], sizeof(ipv6_addr_t)); - } - - srh_header->hdrextlen = sizeof(ipv6_addr_t) * (counter - 1); - memcpy(&(act_ipv6_hdr->destaddr), &rev_route[counter - 1], sizeof(ipv6_addr_t)); - DEBUGF("Route size: %d\n", srh_header->hdrextlen); - } - else { - srh_header->hdrextlen = 0; - } - - /* actually build SRH-header */ - memcpy(&srh_header->nextheader, &(act_ipv6_hdr->nextheader), sizeof(uint8_t)); - srh_header->routing_type = 3; - srh_header->segments_left = counter - 1; - /* cmpri & cmpre are both 0, because by now there is only support for full addresses */ - srh_header->cmpri = 0; - srh_header->cmpre = 0; - /* since the route has exactly the length of its intermediate nodes, padding is zero. */ - srh_header->pad = 0; - srh_header->reserved = 0; - /* set the destination-address in ipv6-buf->destaddr, which is the pointer of child */ - return srh_header; -} -#endif - -void rpl_remove_srh_header(ipv6_hdr_t *ipv6_header, const void *buf, uint8_t nextheader) -{ - ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t *)(&srh_send_buffer)); - uint8_t *payload = &srh_send_buffer[IPV6_HDR_LEN]; - memcpy(temp_ipv6_header, ipv6_header, sizeof(ipv6_hdr_t)); - int msg_length = NTOHS(ipv6_header->length) - sizeof(ipv6_srh_t); - temp_ipv6_header->length = HTONS(msg_length); - temp_ipv6_header->nextheader = nextheader; - memcpy(payload, buf, msg_length); - DEBUGF("Source routing header extraction finished.\n"); - DEBUGF("Dest is now: %s\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &temp_ipv6_header->destaddr)); - srh_m_send.content.ptr = (char *) srh_send_buffer; - msg_send_receive(&srh_m_send, &srh_m_recv, ip_process_pid); -} - -int rpl_srh_sendto(const void *buf, uint16_t len, - ipv6_addr_t *src, ipv6_addr_t *dest, ipv6_srh_t *srh_header, uint8_t srh_length) -{ - ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t *)(&srh_send_buffer)); - ipv6_srh_t *current_packet = ((ipv6_srh_t *)(&srh_send_buffer[IPV6_HDR_LEN])); - uint8_t *payload = &srh_send_buffer[IPV6_HDR_LEN + srh_length]; - memcpy(&(temp_ipv6_header->destaddr), dest, sizeof(ipv6_addr_t)); - memcpy(&(temp_ipv6_header->srcaddr), src, sizeof(ipv6_addr_t)); - memcpy(current_packet, srh_header, srh_length); - memcpy(payload, buf, len); - uint16_t plength = srh_length + len; - - DEBUGF("Build SRH package finished. Going to send it.\n"); - DEBUGF("SRH-length: %d\n", current_packet->hdrextlen); - DEBUGF("My payload length: %d\n", plength); - - return ipv6_sendto(&temp_ipv6_header->destaddr, IPV6_PROTO_NUM_SRH, - (uint8_t *)current_packet, plength, &temp_ipv6_header->destaddr); -} -#endif diff --git a/sys/net/routing/rpl/rpl_control_messages.c b/sys/net/routing/rpl/rpl_control_messages.c deleted file mode 100644 index 65588eaab8..0000000000 --- a/sys/net/routing/rpl/rpl_control_messages.c +++ /dev/null @@ -1,990 +0,0 @@ -/* - * Copyright (C) 2013 - 2014 INRIA. - * Copyright (C) 2015 Cenk GündoÄŸan - * - * 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 rpl - * @{ - * - * @brief RPL control messages handling - * - * Implementation of RPL control messages handling - * - * @author Eric Engel - * @author Fabian Brandt - * @author Cenk GündoÄŸan - */ - -#include "rpl.h" -#include "rpl/rpl_structs.h" -#include "rpl/rpl_config.h" -#include "msg.h" -#include "trickle.h" - -#include "sixlowpan.h" -#include "net_help.h" - -#define ENABLE_DEBUG (0) -#if ENABLE_DEBUG -static char addr_str[IPV6_MAX_ADDR_STR_LEN]; -#endif -#include "debug.h" - -/* in send buffer we need space for LL_HDR */ -static uint8_t rpl_send_buffer[BUFFER_SIZE]; - -/* SEND BUFFERS */ -static icmpv6_hdr_t *icmp_send_buf; -static rpl_dis_t *rpl_send_dis_buf; -#if RPL_DEFAULT_MOP != RPL_MOP_NON_STORING_MODE -static rpl_dao_ack_t *rpl_send_dao_ack_buf; -#endif -static ipv6_hdr_t *ipv6_send_buf; -static rpl_dio_t *rpl_send_dio_buf; -static rpl_dao_t *rpl_send_dao_buf; -static rpl_opt_dodag_conf_t *rpl_send_opt_dodag_conf_buf; -static rpl_opt_target_t *rpl_send_opt_target_buf; -static rpl_opt_transit_t *rpl_send_opt_transit_buf; -static rpl_opt_prefix_information_t *rpl_send_opt_prefix_information_buf; - -/* RECEIVE BUFFERS */ -static ipv6_hdr_t *ipv6_buf; -static rpl_dio_t *rpl_dio_buf; -static rpl_dao_t *rpl_dao_buf; -static rpl_dao_ack_t *rpl_dao_ack_buf; -static rpl_opt_dodag_conf_t *rpl_opt_dodag_conf_buf; -static rpl_opt_target_t *rpl_opt_target_buf; -static rpl_opt_transit_t *rpl_opt_transit_buf; -static rpl_dis_t *rpl_dis_buf; -static rpl_opt_t *rpl_opt_buf; -static rpl_opt_solicited_t *rpl_opt_solicited_buf; -static rpl_opt_prefix_information_t *rpl_opt_prefix_information_buf; - -/* SEND BUFFERS */ -static icmpv6_hdr_t *get_rpl_send_icmpv6_buf(uint8_t ext_len) -{ - return ((icmpv6_hdr_t *) & (rpl_send_buffer[IPV6_HDR_LEN + ext_len])); -} - -#if RPL_DEFAULT_MOP != RPL_MOP_NON_STORING_MODE -static rpl_dao_ack_t *get_rpl_send_dao_ack_buf(void) -{ - return ((rpl_dao_ack_t *) & (rpl_send_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN])); -} -#endif - -static rpl_dis_t *get_rpl_send_dis_buf(void) -{ - return ((rpl_dis_t *) & (rpl_send_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN])); -} - -static ipv6_hdr_t *get_rpl_send_ipv6_buf(void) -{ - return ((ipv6_hdr_t *) & (rpl_send_buffer[0])); -} - -static uint8_t *get_rpl_send_payload_buf(uint8_t ext_len) -{ - return &(rpl_send_buffer[IPV6_HDR_LEN + ext_len]); -} - -static rpl_dio_t *get_rpl_send_dio_buf(void) -{ - return ((rpl_dio_t *) & (rpl_send_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN])); -} - -static rpl_dao_t *get_rpl_send_dao_buf(void) -{ - return ((rpl_dao_t *) & (rpl_send_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN])); -} - -static rpl_opt_dodag_conf_t *get_rpl_send_opt_dodag_conf_buf(uint8_t rpl_msg_len) -{ - return ((rpl_opt_dodag_conf_t *) & (rpl_send_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN + rpl_msg_len])); -} - -static rpl_opt_target_t *get_rpl_send_opt_target_buf(uint8_t rpl_msg_len) -{ - return ((rpl_opt_target_t *) & (rpl_send_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN + rpl_msg_len])); -} - -static rpl_opt_transit_t *get_rpl_send_opt_transit_buf(uint8_t rpl_msg_len) -{ - return ((rpl_opt_transit_t *) & (rpl_send_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN + rpl_msg_len])); -} - -static rpl_opt_prefix_information_t *get_rpl_send_opt_prefix_information_buf(uint8_t rpl_msg_len) -{ - return ((rpl_opt_prefix_information_t *) & (rpl_send_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN + rpl_msg_len])); -} - - -/* RECEIVE BUFFERS */ -static ipv6_hdr_t *get_rpl_ipv6_buf(void) -{ - return ((ipv6_hdr_t *) & (rpl_buffer[0])); -} - -static rpl_opt_target_t *get_rpl_opt_target_buf(uint8_t rpl_msg_len) -{ - return ((rpl_opt_target_t *) & (rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN + rpl_msg_len])); -} - -static rpl_opt_transit_t *get_rpl_opt_transit_buf(uint8_t rpl_msg_len) -{ - return ((rpl_opt_transit_t *) & (rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN + rpl_msg_len])); -} - -static rpl_opt_dodag_conf_t *get_rpl_opt_dodag_conf_buf(uint8_t rpl_msg_len) -{ - return ((rpl_opt_dodag_conf_t *) & (rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN + rpl_msg_len])); -} - -static rpl_dio_t *get_rpl_dio_buf(void) -{ - return ((rpl_dio_t *) & (rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN])); -} - -static rpl_dao_t *get_rpl_dao_buf(void) -{ - return ((rpl_dao_t *) & (rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN])); -} - -static rpl_dao_ack_t *get_rpl_dao_ack_buf(void) -{ - return ((rpl_dao_ack_t *) & (sixlowpan_buffer[(LL_HDR_LEN + IPV6_HDR_LEN + ICMPV6_HDR_LEN)])); -} - -static rpl_dis_t *get_rpl_dis_buf(void) -{ - return ((rpl_dis_t *) & (rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN])); -} - -static rpl_opt_t *get_rpl_opt_buf(uint8_t rpl_msg_len) -{ - return ((rpl_opt_t *) & (rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN + rpl_msg_len])); -} - -static rpl_opt_solicited_t *get_rpl_opt_solicited_buf(uint8_t rpl_msg_len) -{ - return ((rpl_opt_solicited_t *) & (rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN + rpl_msg_len])); -} - -static rpl_opt_prefix_information_t *get_rpl_opt_prefix_information_buf(uint8_t rpl_msg_len) -{ - return ((rpl_opt_prefix_information_t *) & (rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN + rpl_msg_len])); -} - -void rpl_init_root(rpl_options_t *rpl_opts) -{ -#if (RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE) -#ifndef RPL_NODE_IS_ROOT - puts("\n############################## ERROR ###############################"); - puts("This configuration has NO ROUTING TABLE available for the root node!"); - puts("The root will NOT be INITIALIZED."); - puts("Please build the binary for root in non-storing MOP with:"); - puts("\t\t'make RPL_NODE_IS_ROOT=1'"); - puts("############################## ERROR ###############################\n"); - return; -#endif -#endif - rpl_instance_t *inst; - rpl_dodag_t *dodag; - - inst = rpl_new_instance(rpl_opts ? rpl_opts->instance_id : RPL_DEFAULT_INSTANCE); - - if (inst == NULL) { - DEBUGF("Error - No memory for another RPL instance\n"); - return; - } - - inst->joined = 1; - - dodag = rpl_new_dodag(inst, &my_address); - - if (dodag != NULL) { - dodag->of = (struct rpl_of_t *) rpl_get_of_for_ocp(RPL_DEFAULT_OCP); - dodag->instance = inst; - dodag->mop = RPL_DEFAULT_MOP; - dodag->dtsn = 1; - dodag->prf = 0; - dodag->dio_interval_doubling = DEFAULT_DIO_INTERVAL_DOUBLINGS; - dodag->dio_min = DEFAULT_DIO_INTERVAL_MIN; - dodag->dio_redundancy = DEFAULT_DIO_REDUNDANCY_CONSTANT; - dodag->maxrankincrease = 0; - dodag->minhoprankincrease = (uint16_t)DEFAULT_MIN_HOP_RANK_INCREASE; - dodag->default_lifetime = (uint8_t)RPL_DEFAULT_LIFETIME; - dodag->lifetime_unit = RPL_LIFETIME_UNIT; - dodag->version = RPL_COUNTER_INIT; - dodag->grounded = RPL_GROUNDED; - dodag->node_status = (uint8_t) ROOT_NODE; - dodag->my_rank = RPL_ROOT_RANK; - dodag->joined = 1; - dodag->my_preferred_parent = NULL; - if (rpl_opts) { - dodag->prefix = rpl_opts->prefix; - dodag->prefix_length = rpl_opts->prefix_len; - dodag->prefix_flags = rpl_opts->prefix_flags; - dodag->prefix_preferred_lifetime = - rpl_opts->prefix_valid_lifetime ? rpl_opts->prefix_preferred_lifetime : 0xffffffff; - dodag->prefix_valid_lifetime = - rpl_opts->prefix_valid_lifetime ? rpl_opts->prefix_valid_lifetime : 0xffffffff; - } - } - else { - DEBUGF("Error - could not generate DODAG\n"); - return; - } - - trickle_start(rpl_process_pid, &dodag->trickle, RPL_MSG_TYPE_TRICKLE_INTERVAL, - RPL_MSG_TYPE_TRICKLE_CALLBACK, (1 << dodag->dio_min), dodag->dio_interval_doubling, - dodag->dio_redundancy); - DEBUGF("ROOT INIT FINISHED\n"); - -} - -/* TODO: this function is used by the ip layer for source routing (non-storing mode) - * to determine if the node is root and change the dodag direction (upwards -> downwards). - * This is a hack and needs to be refactored when the new network stack is ready. - */ -uint8_t rpl_is_root(void) -{ - rpl_dodag_t *dodag, *end; - for (dodag = rpl_dodags, end = dodag + RPL_MAX_DODAGS; dodag < end; dodag++) { - if (dodag->node_status == ROOT_NODE) { - return 1; - } - } - return 0; -} - -void rpl_send_DIO(rpl_dodag_t *mydodag, ipv6_addr_t *destination) -{ -#if ENABLE_DEBUG - - if (destination) { - DEBUGF("Send DIO to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, destination)); - } - -#endif - icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len); - - if (mydodag == NULL) { - DEBUGF("Error - trying to send DIO without being part of a dodag.\n"); - return; - } - - icmp_send_buf->type = ICMPV6_TYPE_RPL_CONTROL; - icmp_send_buf->code = ICMP_CODE_DIO; - - rpl_send_dio_buf = get_rpl_send_dio_buf(); - memset(rpl_send_dio_buf, 0, sizeof(*rpl_send_dio_buf)); - - DEBUGF("Sending DIO with "); - rpl_send_dio_buf->rpl_instanceid = mydodag->instance->id; - DEBUG("instance %02X ", rpl_send_dio_buf->rpl_instanceid); - rpl_send_dio_buf->version_number = mydodag->version; - rpl_send_dio_buf->rank = byteorder_htons(mydodag->my_rank); - DEBUG("rank %04X\n", byteorder_ntohs(rpl_send_dio_buf->rank)); - rpl_send_dio_buf->g_mop_prf = (mydodag->grounded << RPL_GROUNDED_SHIFT) | - (mydodag->mop << RPL_MOP_SHIFT) | mydodag->prf; - rpl_send_dio_buf->dtsn = mydodag->dtsn; - rpl_send_dio_buf->flags = 0; - rpl_send_dio_buf->reserved = 0; - rpl_send_dio_buf->dodagid = mydodag->dodag_id; - - int opt_hdr_len = 0; - /* 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->type = RPL_OPT_DODAG_CONF; - rpl_send_opt_dodag_conf_buf->length = RPL_OPT_DODAG_CONF_LEN; - rpl_send_opt_dodag_conf_buf->flags_a_pcs = 0; - rpl_send_opt_dodag_conf_buf->DIOIntDoubl = mydodag->dio_interval_doubling; - rpl_send_opt_dodag_conf_buf->DIOIntMin = mydodag->dio_min; - rpl_send_opt_dodag_conf_buf->DIORedun = mydodag->dio_redundancy; - rpl_send_opt_dodag_conf_buf->MaxRankIncrease = byteorder_htons(mydodag->maxrankincrease); - rpl_send_opt_dodag_conf_buf->MinHopRankIncrease = byteorder_htons(mydodag->minhoprankincrease); - rpl_send_opt_dodag_conf_buf->ocp = byteorder_htons(mydodag->of->ocp); - rpl_send_opt_dodag_conf_buf->reserved = 0; - rpl_send_opt_dodag_conf_buf->default_lifetime = mydodag->default_lifetime; - rpl_send_opt_dodag_conf_buf->lifetime_unit = byteorder_htons(mydodag->lifetime_unit); - - opt_hdr_len += RPL_OPT_DODAG_CONF_LEN_WITH_OPT_LEN; - - if (!ipv6_addr_is_unspecified(&mydodag->prefix)) { - rpl_send_opt_prefix_information_buf = get_rpl_send_opt_prefix_information_buf(DIO_BASE_LEN + opt_hdr_len); - rpl_send_opt_prefix_information_buf->type = RPL_OPT_PREFIX_INFO; - rpl_send_opt_prefix_information_buf->length = RPL_OPT_PREFIX_INFO_LEN; - rpl_send_opt_prefix_information_buf->flags = mydodag->prefix_flags; - rpl_send_opt_prefix_information_buf->prefix = mydodag->prefix; - rpl_send_opt_prefix_information_buf->prefix_length = mydodag->prefix_length; - rpl_send_opt_prefix_information_buf->preferred_lifetime = byteorder_htonl(mydodag->prefix_preferred_lifetime); - rpl_send_opt_prefix_information_buf->valid_lifetime = byteorder_htonl(mydodag->prefix_valid_lifetime); - - opt_hdr_len += RPL_OPT_PREFIX_INFO_LEN_WITH_OPT_LEN; - } - - uint16_t plen = ICMPV6_HDR_LEN + DIO_BASE_LEN + opt_hdr_len; - rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6); -} - -void rpl_send_DAO(rpl_dodag_t *my_dodag, ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, - uint8_t start_index) -{ -#if RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE - (void) start_index; -#endif - -#if ENABLE_DEBUG - - if (destination) { - DEBUGF("Send DAO to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, destination)); - } - else { - DEBUGF("Send DAO to default destination\n"); - } - -#endif - - if (my_dodag == NULL) { - DEBUGF("send_DAO: I have no my_dodag\n"); - return; - } - - if (my_dodag->node_status == ROOT_NODE) { - return; - } - - if (destination == NULL) { -#if RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE - destination = &my_dodag->dodag_id; -#else - - if (my_dodag->my_preferred_parent == NULL) { - DEBUGF("send_DAO: my_dodag has no my_preferred_parent\n"); - return; - } - - destination = &my_dodag->my_preferred_parent->addr; -#endif - } - - if (default_lifetime) { - lifetime = my_dodag->default_lifetime; - } - - icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len); - - icmp_send_buf->type = ICMPV6_TYPE_RPL_CONTROL; - icmp_send_buf->code = ICMP_CODE_DAO; - - rpl_send_dao_buf = get_rpl_send_dao_buf(); - memset(rpl_send_dao_buf, 0, sizeof(*rpl_send_dao_buf)); - rpl_send_dao_buf->rpl_instanceid = my_dodag->instance->id; - rpl_send_dao_buf->k_d_flags = 0x00; - rpl_send_dao_buf->dao_sequence = my_dodag->dao_seq; - uint16_t opt_len = 0; - rpl_send_opt_target_buf = get_rpl_send_opt_target_buf(DAO_BASE_LEN); -#if RPL_DEFAULT_MOP != RPL_MOP_NON_STORING_MODE - /* add all targets from routing table as targets */ - uint8_t entries = 0; - uint8_t continue_index = 0; - - for (uint8_t i = start_index; i < rpl_max_routing_entries; i++) { - if (rpl_get_routing_table()[i].used) { - rpl_send_opt_target_buf->type = RPL_OPT_TARGET; - rpl_send_opt_target_buf->length = RPL_OPT_TARGET_LEN; - rpl_send_opt_target_buf->flags = 0x00; - rpl_send_opt_target_buf->prefix_length = RPL_DODAG_ID_LEN; - memcpy(&rpl_send_opt_target_buf->target, &rpl_get_routing_table()[i].address, - sizeof(ipv6_addr_t)); - opt_len += RPL_OPT_TARGET_LEN_WITH_OPT_LEN; - rpl_send_opt_transit_buf = get_rpl_send_opt_transit_buf(DAO_BASE_LEN + opt_len); - rpl_send_opt_transit_buf->type = RPL_OPT_TRANSIT; - rpl_send_opt_transit_buf->length = (RPL_OPT_TRANSIT_LEN - sizeof(ipv6_addr_t)); - rpl_send_opt_transit_buf->e_flags = 0x00; - rpl_send_opt_transit_buf->path_control = 0x00; /* not used */ - rpl_send_opt_transit_buf->path_sequence = 0x00; /* not used */ - rpl_send_opt_transit_buf->path_lifetime = lifetime; - opt_len += (RPL_OPT_TRANSIT_LEN_WITH_OPT_LEN - sizeof(ipv6_addr_t)); - rpl_send_opt_target_buf = get_rpl_send_opt_target_buf(DAO_BASE_LEN + opt_len); - entries++; - } - - /* Split DAO, so packages don't get too big. - * The value 5 is based on experience. */ - if (entries >= 5) { - continue_index = i + 1; - break; - } - } - -#endif - /* add own address */ - rpl_send_opt_target_buf->type = RPL_OPT_TARGET; - rpl_send_opt_target_buf->length = RPL_OPT_TARGET_LEN; - rpl_send_opt_target_buf->flags = 0x00; - rpl_send_opt_target_buf->prefix_length = RPL_DODAG_ID_LEN; - if (!ipv6_addr_is_unspecified(&my_dodag->prefix)) { - ipv6_addr_t tmp; - ipv6_addr_set_by_eui64(&tmp, rpl_if_id, &my_dodag->prefix); - memcpy(&rpl_send_opt_target_buf->target, &tmp, sizeof(ipv6_addr_t)); - } - else { - memcpy(&rpl_send_opt_target_buf->target, &my_address, sizeof(ipv6_addr_t)); - } - opt_len += RPL_OPT_TARGET_LEN_WITH_OPT_LEN; - - rpl_send_opt_transit_buf = get_rpl_send_opt_transit_buf(DAO_BASE_LEN + opt_len); - rpl_send_opt_transit_buf->type = RPL_OPT_TRANSIT; - rpl_send_opt_transit_buf->e_flags = 0x00; - rpl_send_opt_transit_buf->path_control = 0x00; - rpl_send_opt_transit_buf->path_sequence = 0x00; - rpl_send_opt_transit_buf->path_lifetime = lifetime; - -#if RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE - rpl_send_opt_transit_buf->length = RPL_OPT_TRANSIT_LEN; - memcpy(&rpl_send_opt_transit_buf->parent, &my_dodag->my_preferred_parent->addr, sizeof(ipv6_addr_t)); - opt_len += RPL_OPT_TRANSIT_LEN_WITH_OPT_LEN; -#else - rpl_send_opt_transit_buf->length = (RPL_OPT_TRANSIT_LEN - sizeof(ipv6_addr_t)); - opt_len += (RPL_OPT_TRANSIT_LEN_WITH_OPT_LEN - sizeof(ipv6_addr_t)); -#endif - - uint16_t plen = ICMPV6_HDR_LEN + DAO_BASE_LEN + opt_len; - rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6); - -#if RPL_DEFAULT_MOP != RPL_MOP_NON_STORING_MODE - - if (continue_index > 1) { - rpl_send_DAO(my_dodag, destination, lifetime, default_lifetime, continue_index); - } - -#endif -} - -void rpl_send_DIS(ipv6_addr_t *destination) -{ -#if ENABLE_DEBUG - - if (destination) { - DEBUGF("Send DIS to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, destination)); - } - -#endif - - icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len); - - icmp_send_buf->type = ICMPV6_TYPE_RPL_CONTROL; - icmp_send_buf->code = ICMP_CODE_DIS; - - rpl_send_dis_buf = get_rpl_send_dis_buf(); - - uint16_t plen = ICMPV6_HDR_LEN + DIS_BASE_LEN; - rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6); -} - -#if RPL_DEFAULT_MOP != RPL_MOP_NON_STORING_MODE -void rpl_send_DAO_ACK(rpl_dodag_t *my_dodag, ipv6_addr_t *destination) -{ -#if ENABLE_DEBUG - - if (destination) { - DEBUGF("Send DAO ACK to %s\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, destination)); - } - -#endif - - if (my_dodag == NULL) { - return; - } - - icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len); - - icmp_send_buf->type = ICMPV6_TYPE_RPL_CONTROL; - icmp_send_buf->code = ICMP_CODE_DAO_ACK; - - rpl_send_dao_ack_buf = get_rpl_send_dao_ack_buf(); - rpl_send_dao_ack_buf->rpl_instanceid = my_dodag->instance->id; - rpl_send_dao_ack_buf->d_reserved = 0; - rpl_send_dao_ack_buf->dao_sequence = my_dodag->dao_seq; - rpl_send_dao_ack_buf->status = 0; - - uint16_t plen = ICMPV6_HDR_LEN + DAO_ACK_LEN; - rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6); -} -#endif - -void rpl_recv_DIO(void) -{ - ipv6_buf = get_rpl_ipv6_buf(); - - rpl_dio_buf = get_rpl_dio_buf(); - DEBUGF("instance %04X ", rpl_dio_buf->rpl_instanceid); - DEBUGF("rank %04X\n", byteorder_ntohs(rpl_dio_buf->rank)); - int len = DIO_BASE_LEN; - - rpl_instance_t *dio_inst = rpl_get_instance(rpl_dio_buf->rpl_instanceid); - - if (dio_inst == NULL) { - dio_inst = rpl_new_instance(rpl_dio_buf->rpl_instanceid); - - if (dio_inst == NULL) { - DEBUGF("Failed to create a new RPL instance!\n"); - return; - } - } - - rpl_dodag_t dio_dodag; - memset(&dio_dodag, 0, sizeof(dio_dodag)); - - memcpy(&dio_dodag.dodag_id, &rpl_dio_buf->dodagid, sizeof(dio_dodag.dodag_id)); - dio_dodag.dtsn = rpl_dio_buf->dtsn; - dio_dodag.mop = ((rpl_dio_buf->g_mop_prf >> RPL_MOP_SHIFT) & RPL_SHIFTED_MOP_MASK); - dio_dodag.grounded = rpl_dio_buf->g_mop_prf >> RPL_GROUNDED_SHIFT; - dio_dodag.prf = (rpl_dio_buf->g_mop_prf & RPL_PRF_MASK); - dio_dodag.version = rpl_dio_buf->version_number; - dio_dodag.instance = dio_inst; - - uint8_t has_dodag_conf_opt = 0; - - /* Parse until all options are consumed. - * ipv6_buf->length contains the packet length minus ipv6 and - * icmpv6 header, so only ICMPV6_HDR_LEN remains to be - * subtracted. */ - while (len < (NTOHS(ipv6_buf->length) - ICMPV6_HDR_LEN)) { - DEBUGF("parsing DIO options\n"); - rpl_opt_buf = get_rpl_opt_buf(len); - - switch (rpl_opt_buf->type) { - - case (RPL_OPT_PAD1): { - len += 1; - break; - } - - case (RPL_OPT_PADN): { - len += rpl_opt_buf->length; - break; - } - - case (RPL_OPT_DAG_METRIC_CONTAINER): { - len += rpl_opt_buf->length; - break; - } - - case (RPL_OPT_ROUTE_INFO): { - len += rpl_opt_buf->length; - break; - } - - case (RPL_OPT_DODAG_CONF): { - has_dodag_conf_opt = 1; - - if (rpl_opt_buf->length != RPL_OPT_DODAG_CONF_LEN) { - DEBUGF("DODAG configuration is malformed.\n"); - /* error malformed */ - return; - } - - rpl_opt_dodag_conf_buf = get_rpl_opt_dodag_conf_buf(len); - dio_dodag.dio_interval_doubling = rpl_opt_dodag_conf_buf->DIOIntDoubl; - dio_dodag.dio_min = rpl_opt_dodag_conf_buf->DIOIntMin; - dio_dodag.dio_redundancy = rpl_opt_dodag_conf_buf->DIORedun; - dio_dodag.maxrankincrease = byteorder_ntohs(rpl_opt_dodag_conf_buf->MaxRankIncrease); - dio_dodag.minhoprankincrease = byteorder_ntohs(rpl_opt_dodag_conf_buf->MinHopRankIncrease); - dio_dodag.default_lifetime = rpl_opt_dodag_conf_buf->default_lifetime; - dio_dodag.lifetime_unit = byteorder_ntohs(rpl_opt_dodag_conf_buf->lifetime_unit); - dio_dodag.of = (struct rpl_of_t *) rpl_get_of_for_ocp(byteorder_ntohs(rpl_opt_dodag_conf_buf->ocp)); - if (dio_dodag.of == NULL) { - DEBUGF("[Error] OCP from DIO is not supported! ocp: %x\n", - byteorder_ntohs(rpl_opt_dodag_conf_buf->ocp)); - return; - } - - len += RPL_OPT_DODAG_CONF_LEN_WITH_OPT_LEN; - break; - } - - case (RPL_OPT_PREFIX_INFO): { - if (rpl_opt_buf->length != RPL_OPT_PREFIX_INFO_LEN) { - /* error malformed */ - return; - } - - rpl_opt_prefix_information_buf = get_rpl_opt_prefix_information_buf(len); - - /* autonomous address-configuration flag */ - if (rpl_opt_prefix_information_buf->flags & (1 << 6)) { - ipv6_addr_t tmp; - tmp = rpl_opt_prefix_information_buf->prefix; - if (!ipv6_addr_is_link_local(&tmp)) { - if (byteorder_ntohl(rpl_opt_prefix_information_buf->preferred_lifetime) - <= byteorder_ntohl(rpl_opt_prefix_information_buf->valid_lifetime)) { - ipv6_addr_set_by_eui64(&tmp, rpl_if_id, &tmp); - ipv6_net_if_add_addr(rpl_if_id, &tmp, - NDP_ADDR_STATE_PREFERRED, - byteorder_ntohl(rpl_opt_prefix_information_buf->valid_lifetime), - byteorder_ntohl(rpl_opt_prefix_information_buf->preferred_lifetime), - 0); - dio_dodag.prefix = rpl_opt_prefix_information_buf->prefix; - dio_dodag.prefix_length = rpl_opt_prefix_information_buf->prefix_length; - dio_dodag.prefix_valid_lifetime = - byteorder_ntohl(rpl_opt_prefix_information_buf->valid_lifetime); - dio_dodag.prefix_preferred_lifetime = - byteorder_ntohl(rpl_opt_prefix_information_buf->preferred_lifetime); - dio_dodag.prefix_flags = rpl_opt_prefix_information_buf->flags; - } - } - } - - len += RPL_OPT_PREFIX_INFO_LEN_WITH_OPT_LEN; - break; - } - - default: - DEBUGF("[Error] Unsupported DIO option\n"); - return; - } - } - - /* handle packet content... */ - rpl_dodag_t *my_dodag = rpl_get_joined_dodag(dio_inst->id); - - if (my_dodag == NULL) { - if (!has_dodag_conf_opt) { - DEBUGF("send DIS\n"); - rpl_send_DIS(&ipv6_buf->srcaddr); - } - - if (byteorder_ntohs(rpl_dio_buf->rank) < ROOT_RANK) { - DEBUGF("DIO with Rank < ROOT_RANK\n"); - } - - if (dio_dodag.mop != RPL_DEFAULT_MOP) { - DEBUGF("Required MOP not supported\n"); - } - - if (dio_dodag.of == NULL) { - DEBUGF("Required objective function not supported\n"); - } - - if (byteorder_ntohs(rpl_dio_buf->rank) != INFINITE_RANK) { - DEBUGF("Will join DODAG\n"); - rpl_join_dodag(&dio_dodag, &ipv6_buf->srcaddr, byteorder_ntohs(rpl_dio_buf->rank)); - } - else { - DEBUGF("Cannot access DODAG because of DIO with infinite rank\n"); - } - - return; - } - - if (rpl_equal_id(&my_dodag->dodag_id, &dio_dodag.dodag_id)) { - /* "our" DODAG */ - if (RPL_COUNTER_GREATER_THAN(dio_dodag.version, my_dodag->version)) { - if (my_dodag->my_rank == ROOT_RANK) { - DEBUGF("[Warning] Inconsistent Dodag Version\n"); - my_dodag->version = RPL_COUNTER_INCREMENT(dio_dodag.version); - trickle_reset_timer(&my_dodag->trickle); - } - else { - DEBUGF("my dodag has no preferred_parent yet - seems to be odd since I have a parent.\n"); - my_dodag->version = dio_dodag.version; - rpl_global_repair(my_dodag, &ipv6_buf->srcaddr, byteorder_ntohs(rpl_dio_buf->rank)); - } - - return; - } - else if (RPL_COUNTER_GREATER_THAN(my_dodag->version, dio_dodag.version)) { - /* lower version number detected -> send more DIOs */ - trickle_reset_timer(&my_dodag->trickle); - return; - } - } - - /* version matches, DODAG matches */ - if (byteorder_ntohs(rpl_dio_buf->rank) == INFINITE_RANK) { - trickle_reset_timer(&my_dodag->trickle); - } - - /* We are root, all done!*/ - if (my_dodag->my_rank == ROOT_RANK) { - if (byteorder_ntohs(rpl_dio_buf->rank) != INFINITE_RANK) { - trickle_increment_counter(&my_dodag->trickle); - } - - return; - } - - /********************* Parent Handling *********************/ - - rpl_parent_t *parent; - parent = rpl_find_parent(my_dodag, &ipv6_buf->srcaddr); - - if (parent == NULL) { - /* add new parent candidate */ - parent = rpl_new_parent(my_dodag, &ipv6_buf->srcaddr, byteorder_ntohs(rpl_dio_buf->rank)); - - if (parent == NULL) { - return; - } - } - else { - /* DIO OK */ - trickle_increment_counter(&my_dodag->trickle); - } - - /* update parent rank */ - parent->rank = byteorder_ntohs(rpl_dio_buf->rank); - rpl_parent_update(my_dodag, parent); - - if (my_dodag->my_preferred_parent == NULL) { - DEBUGF("My dodag has no preferred_parent yet - seems to be odd since I have a parent...\n"); - } - else if (rpl_equal_id(&parent->addr, &my_dodag->my_preferred_parent->addr) && - (parent->dtsn != rpl_dio_buf->dtsn)) { - rpl_delay_dao(my_dodag); - } - - parent->dtsn = rpl_dio_buf->dtsn; - -} - -void rpl_recv_DAO(void) -{ -#if RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE - DEBUGF("[Error] something went wrong - got a DAO.\n"); - return; -#else - ipv6_buf = get_rpl_ipv6_buf(); - rpl_dao_buf = get_rpl_dao_buf(); - DEBUG("instance %04X ", rpl_dao_buf->rpl_instanceid); - DEBUG("sequence %04X\n", rpl_dao_buf->dao_sequence); - - rpl_dodag_t *my_dodag = rpl_get_joined_dodag(rpl_dao_buf->rpl_instanceid); - - if (my_dodag == NULL) { - DEBUG("[Error] got DAO although not a DODAG\n"); - return; - } - - int len = DAO_BASE_LEN; - uint8_t increment_seq = 0; - - while (len < (NTOHS(ipv6_buf->length) - ICMPV6_HDR_LEN)) { - rpl_opt_buf = get_rpl_opt_buf(len); - - switch (rpl_opt_buf->type) { - - case (RPL_OPT_PAD1): { - len += 1; - break; - } - - case (RPL_OPT_PADN): { - len += (rpl_opt_buf->length + RPL_OPT_LEN); - break; - } - - case (RPL_OPT_DAG_METRIC_CONTAINER): { - len += (rpl_opt_buf->length + RPL_OPT_LEN); - break; - } - - case (RPL_OPT_TARGET): { - rpl_opt_target_buf = get_rpl_opt_target_buf(len); - - if (rpl_opt_target_buf->prefix_length != RPL_DODAG_ID_LEN) { - DEBUGF("prefixes are not supported yet\n"); - break; - } - - len += (rpl_opt_target_buf->length + RPL_OPT_LEN); - rpl_opt_transit_buf = get_rpl_opt_transit_buf(len); - - if (rpl_opt_transit_buf->type != RPL_OPT_TRANSIT) { - DEBUGF("[Error] - no transit information for target option type = %d\n", - rpl_opt_transit_buf->type); - break; - } - - len += (rpl_opt_transit_buf->length + RPL_OPT_LEN); - /* route lifetime seconds = (DAO lifetime) * (Unit Lifetime) */ - -#if (RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE) && (RPL_MAX_ROUTING_ENTRIES != 0) - rpl_add_srh_entry(&rpl_opt_target_buf->target, &rpl_opt_transit_buf->parent, - rpl_opt_transit_buf->path_lifetime * my_dodag->lifetime_unit); -#elif (RPL_MAX_ROUTING_ENTRIES != 0) - DEBUG("Adding routing information: Target: %s, Source: %s, Lifetime: %u\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &rpl_opt_target_buf->target), - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &ipv6_buf->srcaddr), - (rpl_opt_transit_buf->path_lifetime * my_dodag->lifetime_unit)); - rpl_add_routing_entry(&rpl_opt_target_buf->target, &ipv6_buf->srcaddr, - rpl_opt_transit_buf->path_lifetime * my_dodag->lifetime_unit); -#endif - increment_seq = 1; - break; - } - - case (RPL_OPT_TRANSIT): { - len += (rpl_opt_buf->length + RPL_OPT_LEN); - break; - } - - case (RPL_OPT_TARGET_DESC): { - len += (rpl_opt_buf->length + RPL_OPT_LEN); - break; - } - - default: - return; - } - } - -#if RPL_DEFAULT_MOP != RPL_MOP_NON_STORING_MODE - rpl_send_DAO_ACK(my_dodag, &ipv6_buf->srcaddr); -#endif - - if (increment_seq) { - RPL_COUNTER_INCREMENT(my_dodag->dao_seq); - rpl_delay_dao(my_dodag); - } -#endif -} - -void rpl_recv_DIS(void) -{ - ipv6_buf = get_rpl_ipv6_buf(); - rpl_dis_buf = get_rpl_dis_buf(); - int len = DIS_BASE_LEN; - rpl_dodag_t *dodag, *end; - uint8_t options_missing = 1; - - while (len < (NTOHS(ipv6_buf->length) - ICMPV6_HDR_LEN)) { - rpl_opt_buf = get_rpl_opt_buf(len); - - switch (rpl_opt_buf->type) { - case (RPL_OPT_PAD1): { - len += 1; - break; - } - - case (RPL_OPT_PADN): { - len += rpl_opt_buf->length; - break; - } - - case (RPL_OPT_SOLICITED_INFO): { - options_missing = 0; - len += RPL_OPT_SOLICITED_INFO_LEN; - - /* extract and check */ - if (rpl_opt_buf->length != RPL_OPT_SOLICITED_INFO_LEN) { - /* error malformed */ - return; - } - - rpl_opt_solicited_buf = get_rpl_opt_solicited_buf(len); - - for (dodag = rpl_dodags, end = dodag + RPL_MAX_DODAGS; dodag < end; dodag++) { - if (dodag->joined) { - if (rpl_opt_solicited_buf->VID_Flags & RPL_DIS_I_MASK) { - if (dodag->instance->id != rpl_opt_solicited_buf->rplinstanceid) { - continue; - } - } - - if (rpl_opt_solicited_buf->VID_Flags & RPL_DIS_D_MASK) { - if (!rpl_equal_id(&dodag->dodag_id, &rpl_opt_solicited_buf->dodagid)) { - continue; - } - } - - if (rpl_opt_solicited_buf->VID_Flags & RPL_DIS_V_MASK) { - if (dodag->version != rpl_opt_solicited_buf->version) { - continue; - } - } - - rpl_send_DIO(dodag, &ipv6_buf->srcaddr); - trickle_reset_timer(&dodag->trickle); - } - } - - break; - } - - default: - return; - } - } - - if (options_missing) { - for (dodag = rpl_dodags, end = dodag + RPL_MAX_DODAGS; dodag < end; dodag++) { - if (dodag->joined) { - rpl_send_DIO(dodag, &ipv6_buf->srcaddr); - trickle_reset_timer(&dodag->trickle); - } - } - } -} - -void rpl_recv_DAO_ACK(void) -{ - rpl_dao_ack_buf = get_rpl_dao_ack_buf(); - - rpl_dodag_t *my_dodag = rpl_get_joined_dodag(rpl_dao_ack_buf->rpl_instanceid); - - if (my_dodag == NULL) { - return; - } - - if (rpl_dao_ack_buf->rpl_instanceid != my_dodag->instance->id) { - return; - } - - if (rpl_dao_ack_buf->status != 0) { - return; - } - - rpl_dao_ack_received(my_dodag); - -} - -/* obligatory for each mode. normally not modified */ -void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_t next_header) -{ - uint8_t *p_ptr; - ipv6_send_buf = get_rpl_send_ipv6_buf(); - p_ptr = get_rpl_send_payload_buf(ipv6_ext_hdr_len); - - ipv6_send_buf->version_trafficclass = IPV6_VER; - ipv6_send_buf->trafficclass_flowlabel = 0; - ipv6_send_buf->flowlabel = 0; - ipv6_send_buf->nextheader = next_header; - ipv6_send_buf->hoplimit = MULTIHOP_HOPLIMIT; - ipv6_send_buf->length = HTONS(p_len); - - memcpy(&(ipv6_send_buf->destaddr), destination, 16); - ipv6_net_if_get_best_src_addr(&(ipv6_send_buf->srcaddr), &(ipv6_send_buf->destaddr)); - - icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len); - icmp_send_buf->checksum = icmpv6_csum(ipv6_send_buf, icmp_send_buf); - - /* The packet was "assembled" in rpl_%mode%.c. Therefore rpl_send_buf was used. - * Therefore memcpy is not needed because the payload is at the - * right memory location already. */ - - if (p_ptr != payload) { - memcpy(p_ptr, payload, p_len); - } - - ipv6_send_packet(ipv6_send_buf, NULL); -} diff --git a/sys/net/routing/rpl/rpl_dodag.c b/sys/net/routing/rpl/rpl_dodag.c deleted file mode 100644 index eb09fb4336..0000000000 --- a/sys/net/routing/rpl/rpl_dodag.c +++ /dev/null @@ -1,450 +0,0 @@ -/** - * Copyright (C) 2013, 2014 INRIA. - * - * 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 rpl - * @{ - * - * @file - * @brief RPL DODAG - * - * Implementation of a DODAG for usage with RPL. - * - * @author Eric Engel - * @} - */ - -#include -#include -#include - -#include "rpl/rpl_dodag.h" -#include "trickle.h" -#include "rpl.h" - -#define ENABLE_DEBUG (0) -#if ENABLE_DEBUG -char addr_str[IPV6_MAX_ADDR_STR_LEN]; -#endif -#include "debug.h" - -static rpl_instance_t instances[RPL_MAX_INSTANCES]; -rpl_dodag_t rpl_dodags[RPL_MAX_DODAGS]; -static rpl_parent_t parents[RPL_MAX_PARENTS]; - -void rpl_trickle_send_dio(void *args) -{ - ipv6_addr_t mcast; - - ipv6_addr_set_all_rpl_nodes_addr(&mcast); - rpl_send_DIO((rpl_dodag_t *) args, &mcast); -} - -rpl_instance_t *rpl_new_instance(uint8_t instanceid) -{ - rpl_instance_t *inst; - rpl_instance_t *end ; - - for (inst = &instances[0], end = inst + RPL_MAX_INSTANCES; inst < end; inst++) { - if (inst->used == 0) { - memset(inst, 0, sizeof(*inst)); - inst->used = 1; - inst->id = instanceid; - return inst; - } - } - - return NULL; -} - -rpl_instance_t *rpl_get_instance(uint8_t instanceid) -{ - for (int i = 0; i < RPL_MAX_INSTANCES; i++) { - if (instances[i].used && (instances[i].id == instanceid)) { - return &instances[i]; - } - } - - return NULL; -} - -rpl_instance_t *rpl_get_my_instance(void) -{ - for (int i = 0; i < RPL_MAX_INSTANCES; i++) { - if (instances[i].joined) { - return &instances[i]; - } - } - - return NULL; -} - -rpl_dodag_t *rpl_new_dodag(rpl_instance_t *inst, ipv6_addr_t *dodagid) -{ - if (inst == NULL) { - DEBUGF("Error - No instance specified\n"); - return NULL; - } - - rpl_dodag_t *dodag; - rpl_dodag_t *end; - - for (dodag = &rpl_dodags[0], end = dodag + RPL_MAX_DODAGS; dodag < end; dodag++) { - if (dodag->used == 0) { - memset(dodag, 0, sizeof(*dodag)); - dodag->instance = inst; - dodag->my_rank = INFINITE_RANK; - dodag->used = 1; - dodag->ack_received = true; - dodag->dao_counter = 0; - dodag->trickle.callback.func = &rpl_trickle_send_dio; - dodag->trickle.callback.args = dodag; - memcpy(&dodag->dodag_id, dodagid, sizeof(*dodagid)); - return dodag; - } - } - - return NULL; - -} - -rpl_dodag_t *rpl_get_joined_dodag(uint8_t instanceid) -{ - for (int i = 0; i < RPL_MAX_DODAGS; i++) { - if (rpl_dodags[i].joined && rpl_dodags[i].instance->id == instanceid) { - return &rpl_dodags[i]; - } - } - - return NULL; -} - -rpl_dodag_t *rpl_get_my_dodag(void) -{ - for (int i = 0; i < RPL_MAX_DODAGS; i++) { - if (rpl_dodags[i].joined) { - return &rpl_dodags[i]; - } - } - - return NULL; -} - -void rpl_del_dodag(rpl_dodag_t *dodag) -{ - rpl_leave_dodag(dodag); - memset(dodag, 0, sizeof(*dodag)); -} - -void rpl_leave_dodag(rpl_dodag_t *dodag) -{ - dodag->joined = 0; - dodag->my_preferred_parent = NULL; - rpl_delete_all_parents(dodag); - trickle_stop(&dodag->trickle); - vtimer_remove(&dodag->dao_timer); -} - -bool rpl_equal_id(ipv6_addr_t *id1, ipv6_addr_t *id2) -{ - for (uint8_t i = 0; i < 2; i++) { - DEBUGF("ID1: %d ID2: %d\n", id1->uint8[12 + i], id2->uint8[12 + i]); - - if (id1->uint8[14 + i] != id2->uint8[14 + i]) { - return false; - } - } - - return true; - -} - -rpl_parent_t *rpl_new_parent(rpl_dodag_t *dodag, ipv6_addr_t *address, uint16_t rank) -{ - rpl_parent_t *parent; - rpl_parent_t *end; - - for (parent = &parents[0], end = parents + RPL_MAX_PARENTS; parent < end; parent++) { - if (parent->used == 0) { - memset(parent, 0, sizeof(*parent)); - parent->used = 1; - parent->addr = *address; - parent->rank = rank; - parent->dodag = dodag; - parent->lifetime = dodag->default_lifetime * dodag->lifetime_unit; - /* dtsn is set at the end of recv_dio function */ - parent->dtsn = 0; - return parent; - } - } - - rpl_delete_worst_parent(); - return rpl_new_parent(dodag, address, rank); -} - -rpl_parent_t *rpl_find_parent(rpl_dodag_t *dodag, ipv6_addr_t *address) -{ - rpl_parent_t *parent; - rpl_parent_t *end; - - for (parent = &parents[0], end = parents + RPL_MAX_PARENTS; parent < end; parent++) { - if ((parent->used) && (rpl_equal_id(address, &parent->addr) - && (parent->dodag->instance->id == dodag->instance->id) - && (!memcmp(&parent->dodag->dodag_id, - &dodag->dodag_id, sizeof(ipv6_addr_t))))) { - return parent; - } - } - - return NULL; -} - -void rpl_delete_parent(rpl_parent_t *parent) -{ - if (parent == parent->dodag->my_preferred_parent) { - parent->dodag->my_preferred_parent = NULL; - } - memset(parent, 0, sizeof(*parent)); -} - -void rpl_delete_worst_parent(void) -{ - uint8_t worst = 0xFF; - uint16_t max_rank = 0x0000; - - for (int i = 0; i < RPL_MAX_PARENTS; i++) { - if (parents[i].rank > max_rank) { - worst = i; - max_rank = parents[i].rank; - } - } - - if (worst == 0xFF) { - /* Fehler, keine parents -> sollte nicht passieren */ - return; - } - - rpl_delete_parent(&parents[worst]); - -} - -void rpl_delete_all_parents(rpl_dodag_t *dodag) -{ - - dodag->my_preferred_parent = NULL; - for (int i = 0; i < RPL_MAX_PARENTS; i++) { - if (parents[i].dodag && (dodag->instance->id == parents[i].dodag->instance->id) && - (!memcmp(&dodag->dodag_id, &parents[i].dodag->dodag_id, sizeof(ipv6_addr_t)))) { - memset(&parents[i], 0, sizeof(parents[i])); - } - } -} - -rpl_parent_t *rpl_find_preferred_parent(rpl_dodag_t *my_dodag) -{ - rpl_parent_t *best = NULL; - - if (my_dodag == NULL) { - DEBUG("Not part of a dodag\n"); - return NULL; - } - - for (uint8_t i = 0; i < RPL_MAX_PARENTS; i++) { - if (parents[i].used - && (parents[i].dodag->instance->id == my_dodag->instance->id) - && (!memcmp(&parents[i].dodag->dodag_id, - &my_dodag->dodag_id, sizeof(ipv6_addr_t)))) { - if ((parents[i].rank == INFINITE_RANK) || (parents[i].lifetime <= 1)) { - DEBUG("Infinite rank, bad parent\n"); - continue; - } - else if (best == NULL) { - DEBUG("possible parent\n"); - best = &parents[i]; - } - else { - best = my_dodag->of->which_parent(best, &parents[i]); - } - } - } - - if (best == NULL) { - return NULL; - } - - if (my_dodag->my_preferred_parent == NULL) { - my_dodag->my_preferred_parent = best; - } - - if (!rpl_equal_id(&my_dodag->my_preferred_parent->addr, &best->addr)) { - if (my_dodag->mop != RPL_MOP_NO_DOWNWARD_ROUTES) { - /* send DAO with ZERO_LIFETIME to old parent */ - rpl_send_DAO(my_dodag, &my_dodag->my_preferred_parent->addr, 0, false, 0); - } - - my_dodag->my_preferred_parent = best; - - if (my_dodag->mop != RPL_MOP_NO_DOWNWARD_ROUTES) { - rpl_delay_dao(my_dodag); - } - - trickle_reset_timer(&my_dodag->trickle); - } - - return best; -} - -void rpl_parent_update(rpl_dodag_t *my_dodag, rpl_parent_t *parent) -{ - uint16_t old_rank; - - if (my_dodag == NULL) { - DEBUG("Not part of a dodag - this should not happen"); - return; - } - - old_rank = my_dodag->my_rank; - - /* update Parent lifetime */ - if (parent != NULL) { - parent->lifetime = my_dodag->default_lifetime * my_dodag->lifetime_unit; - } - - if (rpl_find_preferred_parent(my_dodag) == NULL) { - rpl_local_repair(my_dodag); - } - - if (rpl_calc_rank(old_rank, my_dodag->minhoprankincrease) != - rpl_calc_rank(my_dodag->my_rank, my_dodag->minhoprankincrease)) { - if (my_dodag->my_rank < my_dodag->min_rank) { - my_dodag->min_rank = my_dodag->my_rank; - } - - trickle_reset_timer(&my_dodag->trickle); - } -} - -void rpl_join_dodag(rpl_dodag_t *dodag, ipv6_addr_t *parent, uint16_t parent_rank) -{ - rpl_dodag_t *my_dodag; - rpl_parent_t *preferred_parent; - my_dodag = rpl_new_dodag(dodag->instance, &dodag->dodag_id); - - if (my_dodag == NULL) { - return; - } - - my_dodag->instance->joined = 1; - my_dodag->of = dodag->of; - my_dodag->mop = dodag->mop; - my_dodag->dtsn = dodag->dtsn; - my_dodag->prf = dodag->prf; - my_dodag->dio_interval_doubling = dodag->dio_interval_doubling; - my_dodag->dio_min = dodag->dio_min; - my_dodag->dio_redundancy = dodag->dio_redundancy; - my_dodag->maxrankincrease = dodag->maxrankincrease; - my_dodag->minhoprankincrease = dodag->minhoprankincrease; - my_dodag->default_lifetime = dodag->default_lifetime; - my_dodag->lifetime_unit = dodag->lifetime_unit; - my_dodag->version = dodag->version; - my_dodag->grounded = dodag->grounded; - my_dodag->prefix_length = dodag->prefix_length; - my_dodag->prefix = dodag->prefix; - my_dodag->prefix_valid_lifetime = dodag->prefix_valid_lifetime; - my_dodag->prefix_preferred_lifetime = dodag->prefix_preferred_lifetime; - my_dodag->prefix_flags = dodag->prefix_flags; - my_dodag->joined = 1; - - preferred_parent = rpl_new_parent(my_dodag, parent, parent_rank); - - if (preferred_parent == NULL) { - rpl_del_dodag(my_dodag); - return; - } - - my_dodag->my_preferred_parent = preferred_parent; - my_dodag->node_status = (uint8_t) NORMAL_NODE; - my_dodag->my_rank = dodag->of->calc_rank(preferred_parent, dodag->my_rank); - my_dodag->dao_seq = RPL_COUNTER_INIT; - my_dodag->min_rank = my_dodag->my_rank; - DEBUG("Joint DODAG:\n"); - DEBUG("\tMOP:\t%02X\n", my_dodag->mop); - DEBUG("\tminhoprankincrease :\t%04X\n", my_dodag->minhoprankincrease); - DEBUG("\tdefault_lifetime:\t%02X\n", my_dodag->default_lifetime); - DEBUG("\tgrounded:\t%02X\n", my_dodag->grounded); - DEBUG("\tmy_preferred_parent:\t%s\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - &my_dodag->my_preferred_parent->addr)); - DEBUG("\tmy_preferred_parent rank\t%02X\n", my_dodag->my_preferred_parent->rank); - DEBUG("\tmy_preferred_parent lifetime\t%04X\n", my_dodag->my_preferred_parent->lifetime); - - trickle_start(rpl_process_pid, &my_dodag->trickle, RPL_MSG_TYPE_TRICKLE_INTERVAL, - RPL_MSG_TYPE_TRICKLE_CALLBACK, (1 << my_dodag->dio_min), my_dodag->dio_interval_doubling, - my_dodag->dio_redundancy); - rpl_delay_dao(my_dodag); -} - -void rpl_global_repair(rpl_dodag_t *my_dodag, ipv6_addr_t *p_addr, uint16_t rank) -{ - DEBUGF("[INFO] Global repair started\n"); - - if (my_dodag == NULL) { - DEBUGF("[Error] - no global repair possible, if not part of a DODAG\n"); - return; - } - - rpl_delete_all_parents(my_dodag); - my_dodag->dtsn++; - my_dodag->my_preferred_parent = rpl_new_parent(my_dodag, p_addr, rank); - - if (my_dodag->my_preferred_parent == NULL) { - DEBUGF("[Error] no more parent after global repair\n"); - my_dodag->my_rank = INFINITE_RANK; - } - else { - /* Calc new Rank */ - my_dodag->my_rank = my_dodag->of->calc_rank(my_dodag->my_preferred_parent, - my_dodag->my_rank); - my_dodag->min_rank = my_dodag->my_rank; - trickle_reset_timer(&my_dodag->trickle); - rpl_delay_dao(my_dodag); - } - - DEBUGF("Migrated to DODAG Version %d. My new Rank: %d\n", my_dodag->version, - my_dodag->my_rank); -} - -void rpl_local_repair(rpl_dodag_t *my_dodag) -{ - DEBUGF("[INFO] Local Repair started\n"); - - if (my_dodag == NULL) { - DEBUGF("[Error] - no local repair possible, if not part of a DODAG\n"); - return; - } - - my_dodag->my_rank = INFINITE_RANK; - my_dodag->dtsn++; - rpl_delete_all_parents(my_dodag); - trickle_reset_timer(&my_dodag->trickle); - -} - -ipv6_addr_t *rpl_get_my_preferred_parent(void) -{ - rpl_dodag_t *my_dodag = rpl_get_my_dodag(); - - if (my_dodag == NULL) { - return NULL; - } - - return &my_dodag->my_preferred_parent->addr; -} - -uint16_t rpl_calc_rank(uint16_t abs_rank, uint16_t minhoprankincrease) -{ - return abs_rank / minhoprankincrease; -} diff --git a/sys/net/routing/rpl/rpl_of_manager.c b/sys/net/routing/rpl/rpl_of_manager.c deleted file mode 100644 index 4973aec1e8..0000000000 --- a/sys/net/routing/rpl/rpl_of_manager.c +++ /dev/null @@ -1,60 +0,0 @@ -/* -* RPL dodag implementation -* -* Copyright (C) 2014 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 rpl - * @{ - * @file - * @brief RPL Objective functions manager - * @author Fabian Brandt - * @} - */ - - - -#include "rpl/rpl_of_manager.h" -#include "of0.h" -#include "of_mrhof.h" -#include "etx_beaconing.h" -#include "rpl/rpl_config.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -static rpl_of_t *objective_functions[NUMBER_IMPLEMENTED_OFS]; - -void rpl_of_manager_init(ipv6_addr_t *my_address) -{ - /* insert new objective functions here */ - objective_functions[0] = rpl_get_of0(); - objective_functions[1] = rpl_get_of_mrhof(); - - if (RPL_DEFAULT_OCP == 1) { - DEBUG("%s, %d: INIT ETX BEACONING\n", __FILE__, __LINE__); - etx_init_beaconing(my_address); - } -} - -/* find implemented OF via objective code point */ -rpl_of_t *rpl_get_of_for_ocp(uint16_t ocp) -{ - for (uint16_t i = 0; i < NUMBER_IMPLEMENTED_OFS; i++) { - if (objective_functions[i] == NULL) { - /* fallback if something goes wrong */ - return rpl_get_of0(); - } - else if (ocp == objective_functions[i]->ocp) { - return objective_functions[i]; - } - } - - return NULL; -} diff --git a/sys/net/transport_layer/socket_base/Makefile b/sys/net/transport_layer/socket_base/Makefile deleted file mode 100644 index 48422e909a..0000000000 --- a/sys/net/transport_layer/socket_base/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(RIOTBASE)/Makefile.base diff --git a/sys/net/transport_layer/socket_base/msg_help.c b/sys/net/transport_layer/socket_base/msg_help.c deleted file mode 100644 index 2c8ddb4386..0000000000 --- a/sys/net/transport_layer/socket_base/msg_help.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2013 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. - */ - -/** - * @{ - * @file - * @brief Providing implementation for prototypes defined in msg_help.h. - * @author Oliver Gesch - */ - -#include - -#include "thread.h" - -#include "msg_help.h" - -void socket_base_block_continue_thread(void) -{ - // msg_t recv_m; - // recv_m.type = TCP_NOT_DEFINED; - // while (recv_m.type != TCP_CONTINUE) - // { - // net_msg_receive(&recv_m); - // } -} - -int socket_base_net_msg_receive(msg_t *m) -{ - return msg_receive(m); -} - -int socket_base_net_msg_reply(msg_t *m, msg_t *reply, uint16_t message) -{ - reply->type = message; - return msg_reply(m, reply); -} - -int socket_base_net_msg_send(msg_t *m, kernel_pid_t pid, bool block, uint16_t message) -{ - m->type = message; - if (block) { - return msg_send(m, pid); - } else { - return msg_try_send(m, pid); - } -} - -int socket_base_net_msg_send_recv(msg_t *m, msg_t *reply, kernel_pid_t pid, uint16_t message) -{ - m->type = message; - return msg_send_receive(m, reply, pid);; -} - -/** - * @} - */ diff --git a/sys/net/transport_layer/socket_base/msg_help.h b/sys/net/transport_layer/socket_base/msg_help.h deleted file mode 100644 index 271b83a7cc..0000000000 --- a/sys/net/transport_layer/socket_base/msg_help.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2013 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. - */ - -/** - * @{ - * @file - * @author Oliver Gesch - */ -#ifndef MSG_HELP_H_ -#define MSG_HELP_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// Function IDs -#define FID_SIXLOWIP_TCP 0 -#define FID_SIXLOWIP_UDP 1 -#define FID_TCP_PH 2 -#define FID_UDP_PH 3 -#define FID_H_PAYLOAD 4 -#define FID_SOCKET_RECV 5 -#define FID_SOCKET_RECV_FROM 6 -#define FID_TCP_SYN_ACK 7 -#define FID_SOCKET_CONNECT 8 -#define FID_SOCKET_HANDLE_NEW_TCP_CON 9 -#define FID_TCP_ACK 10 -#define FID_SOCKET_CLOSE 11 -#define FID_TCP_CHT 12 -#define FID_TCP_SHELL 13 - -#define RETURNNOW 4000 - -void socket_base_block_continue_thread(void); -int socket_base_net_msg_receive(msg_t *m); -int socket_base_net_msg_reply(msg_t *m, msg_t *reply, uint16_t message); -int socket_base_net_msg_send(msg_t *m, kernel_pid_t pid, bool block, uint16_t message); -int socket_base_net_msg_send_recv(msg_t *m, msg_t *reply, kernel_pid_t pid, uint16_t message); - -#ifdef __cplusplus -} -#endif - -#endif /* MSG_HELP_H_ */ -/** - * @} - */ diff --git a/sys/net/transport_layer/socket_base/socket.c b/sys/net/transport_layer/socket_base/socket.c deleted file mode 100644 index 841d87f2ff..0000000000 --- a/sys/net/transport_layer/socket_base/socket.c +++ /dev/null @@ -1,425 +0,0 @@ -/* - * Copyright (C) 2013, 2014 INRIA. - * - * 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 socket_base - * @{ - * @file - * @brief functions for BSD socket API, methods return default values and - * will be overwritten by appropriate transport layer protocols. - * @author Oliver Gesch - * @author Cenk GündoÄŸan - * @} - */ - -#include -#include -#include -#include - -#include "hwtimer.h" -#include "ipv6.h" -#include "thread.h" -#include "vtimer.h" - -#include "net_help.h" - -#include "msg_help.h" - -#include "socket.h" - -#define EPHEMERAL_PORTS 49152 - -socket_internal_t socket_base_sockets[MAX_SOCKETS]; - -int __attribute__((weak)) tcp_connect(int socket, sockaddr6_t *addr, uint32_t addrlen) -{ - (void) socket; - (void) addr; - (void) addrlen; - - return -1; -} - -int __attribute__((weak)) tcp_listen(int s, int backlog) -{ - (void) s; - (void) backlog; - - return -1; -} - -int __attribute__((weak)) tcp_accept(int s, sockaddr6_t *addr, uint32_t *addrlen) -{ - (void) s; - (void) addr; - (void) addrlen; - - return -1; -} - -int32_t __attribute__((weak)) tcp_send(int s, const void *buf, uint32_t len, int flags) -{ - (void) s; - (void) buf; - (void) len; - (void) flags; - - return -1; -} - -int32_t __attribute__((weak)) tcp_recv(int s, void *buf, uint32_t len, int flags) -{ - (void) s; - (void) buf; - (void) len; - (void) flags; - - return -1; -} - -int32_t __attribute__((weak)) udp_recvfrom(int s, void *buf, uint32_t len, int flags, - sockaddr6_t *from, uint32_t *fromlen) -{ - (void) s; - (void) buf; - (void) len; - (void) flags; - (void) from; - (void) fromlen; - - return -1; -} - -int32_t __attribute__((weak)) udp_sendto(int s, const void *buf, uint32_t len, int flags, - sockaddr6_t *to, uint32_t tolen) -{ - (void) s; - (void) buf; - (void) len; - (void) flags; - (void) to; - (void) tolen; - - return -1; -} - -int __attribute__((weak)) tcp_bind_socket(int s, sockaddr6_t *name, int namelen, uint8_t pid) -{ - (void) s; - (void) name; - (void) namelen; - (void) pid; - - return -1; -} - -int __attribute__((weak)) udp_bind_socket(int s, sockaddr6_t *name, int namelen, uint8_t pid) -{ - (void) s; - (void) name; - (void) namelen; - (void) pid; - - return -1; -} - -bool __attribute__((weak)) tcp_socket_compliancy(int s) -{ - (void) s; - - return false; -} - -bool __attribute__((weak)) udp_socket_compliancy(int s) -{ - (void) s; - - return false; -} - -int __attribute__((weak)) tcp_teardown(socket_internal_t *current_socket) -{ - (void) current_socket; - - return -1; -} - -void socket_base_print_socket(socket_t *current_socket) -{ - char addr_str[IPV6_MAX_ADDR_STR_LEN]; - printf("Domain: %i, Type: %i, Protocol: %i \n", - current_socket->domain, - current_socket->type, - current_socket->protocol); - printf("Local address: %s\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - ¤t_socket->local_address.sin6_addr)); - printf("Foreign address: %s\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - ¤t_socket->foreign_address.sin6_addr)); - printf("Local Port: %u, Foreign Port: %u\n", - NTOHS(current_socket->local_address.sin6_port), - NTOHS(current_socket->foreign_address.sin6_port)); -} - -void socket_base_print_internal_socket(socket_internal_t *current_socket_internal) -{ - socket_t *current_socket = ¤t_socket_internal->socket_values; - printf("\n--------------------------\n"); - printf("ID: %i, RECV PID: %i SEND PID: %i\n", - current_socket_internal->socket_id, current_socket_internal->recv_pid, - current_socket_internal->send_pid); - socket_base_print_socket(current_socket); - printf("\n--------------------------\n"); -} - -bool socket_base_exists_socket(int socket) -{ - if (socket < 1) { - return false; - } - if ((socket > MAX_SOCKETS) || (socket_base_sockets[socket - 1].socket_id == 0)) { - return false; - } - else { - return true; - } -} - -socket_internal_t *socket_base_get_socket(int s) -{ - if (socket_base_exists_socket(s)) { - return &(socket_base_sockets[s - 1]); - } - else { - return NULL; - } -} - -void socket_base_print_sockets(void) -{ - int i; - printf("\n--- Socket list: ---\n"); - - for (i = 1; i < MAX_SOCKETS + 1; i++) { - if (socket_base_get_socket(i) != NULL) { - socket_base_print_internal_socket(socket_base_get_socket(i)); - } - } -} - -int socket_base_close(int s) -{ - socket_internal_t *current_socket = socket_base_get_socket(s); - - if (udp_socket_compliancy(s)) { - memset(current_socket, 0, sizeof(socket_internal_t)); - return 0; - } - else if (tcp_socket_compliancy(s)) { - return tcp_teardown(current_socket); - } - - printf("Socket Type not supported!\n"); - return -1; -} - -uint16_t socket_base_get_free_source_port(uint8_t protocol) -{ - int i; - uint16_t biggest_port = EPHEMERAL_PORTS - 1; - - /* Remember biggest ephemeral port number used so far and add 1 */ - for (i = 0; i < MAX_SOCKETS; i++) { - if ((socket_base_sockets[i].socket_values.protocol == protocol) && - (socket_base_sockets[i].socket_values.local_address.sin6_port > biggest_port)) { - biggest_port = socket_base_sockets[i].socket_values.local_address.sin6_port; - } - } - - return biggest_port + 1; -} - -int socket_base_socket(int domain, int type, int protocol) -{ - int i = 1; - - while (socket_base_get_socket(i) != NULL) { - i++; - } - - if (i > MAX_SOCKETS) { - return -1; - } - - socket_t *current_socket = &socket_base_sockets[i - 1].socket_values; - socket_base_sockets[i - 1].socket_id = i; - current_socket->domain = domain; - current_socket->type = type; - current_socket->protocol = protocol; -#ifdef MODULE_TCP - current_socket->tcp_control.state = 0; -#endif - return socket_base_sockets[i - 1].socket_id; -} - -int socket_base_connect(int socket, sockaddr6_t *addr, uint32_t addrlen) -{ - if (tcp_socket_compliancy(socket)) { - return tcp_connect(socket, addr, addrlen); - } - else { - printf("Socket Type not supported!\n"); - } - - return -1; -} - -int socket_base_accept(int s, sockaddr6_t *addr, uint32_t *addrlen) -{ - if (tcp_socket_compliancy(s)) { - return tcp_accept(s, addr, addrlen); - } - - printf("Socket Type not supported!\n"); - return -1; -} - -int socket_base_listen(int s, int backlog) -{ - if (tcp_socket_compliancy(s)) { - return tcp_listen(s, backlog); - } - - printf("Socket Type not supported!\n"); - return -1; -} - -int32_t socket_base_recv(int s, void *buf, uint32_t len, int flags) -{ - if (tcp_socket_compliancy(s)) { - return tcp_recv(s, buf, len, flags); - } - - printf("Socket Type not supported!\n"); - return -1; -} - -int32_t socket_base_recvfrom(int s, void *buf, uint32_t len, int flags, - sockaddr6_t *from, uint32_t *fromlen) -{ - if (udp_socket_compliancy(s)) { - return udp_recvfrom(s, buf, len, flags, from, fromlen); - } - else if (tcp_socket_compliancy(s)) { - return tcp_recv(s, buf, len, flags); - } - - printf("Socket Type not supported!\n"); - return -1; -} - -int32_t socket_base_sendto(int s, const void *buf, uint32_t len, int flags, - sockaddr6_t *to, uint32_t tolen) -{ - if (udp_socket_compliancy(s)) { - return udp_sendto(s, buf, len, flags, to, tolen); - } - else if (tcp_socket_compliancy(s)) { - return tcp_send(s, buf, len, flags); - } - else { - printf("Socket Type not supported!\n"); - return -1; - } - - return -1; -} - -int32_t socket_base_send(int s, const void *buf, uint32_t len, int flags) -{ - if (tcp_socket_compliancy(s)) { - return tcp_send(s, buf, len, flags); - } - else { - printf("Socket Type not supported!\n"); - return -1; - } - - return -1; -} - -int socket_base_bind(int s, sockaddr6_t *addr, int addrlen) -{ - if (socket_base_exists_socket(s)) { - socket_t *current_socket = &socket_base_get_socket(s)->socket_values; - - switch (current_socket->domain) { - case (PF_INET): { - /* Not provided */ - return -1; - } - - case (PF_INET6): { - switch (current_socket->type) { - /* TCP */ - case (SOCK_STREAM): { - if ((current_socket->protocol == 0) || - (current_socket->protocol == IPPROTO_TCP)) { - return tcp_bind_socket(s, addr, addrlen, - thread_getpid()); - } - else { - return -1; - } - } - - /* UDP */ - case (SOCK_DGRAM): { - if ((current_socket->protocol == 0) || - (current_socket->protocol == IPPROTO_UDP)) { - return udp_bind_socket(s, addr, addrlen, - thread_getpid()); - } - else { - return -1; - } - } - - case (SOCK_SEQPACKET): { - /* not provided */ - return -1; - } - - case (SOCK_RAW): { - /* not provided */ - return -1; - } - - default: { - return -1; - } - } - - break; - } - - case (PF_UNIX): { - /* Not provided */ - return -1; - } - } - } - else { - printf("SOCKET DOES NOT EXIST!\n"); - return -1; - } - - return -1; -} diff --git a/sys/net/transport_layer/socket_base/socket.h b/sys/net/transport_layer/socket_base/socket.h deleted file mode 100644 index f7a6bdf1ac..0000000000 --- a/sys/net/transport_layer/socket_base/socket.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) 2014 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. - */ - -#ifndef _SOCKET_BASE_SOCKET -#define _SOCKET_BASE_SOCKET - -#include "cpu.h" - -#include "socket_base/socket.h" - -#ifdef MODULE_UDP -#include "udp.h" -#endif - -#ifdef MODULE_TCP -#include "tcp.h" -#endif - -#define MAX_SOCKETS 5 -// #define MAX_QUEUED_SOCKETS 2 - -#define INC_PACKET 0 -#define OUT_PACKET 1 - -#ifdef MODULE_TCP -typedef struct __attribute__((packed)) { - uint16_t context_id; - uint32_t seq_rcv; // Last received packet values - uint32_t ack_rcv; - uint16_t wnd_rcv; - uint32_t seq_snd; // Last sent packet values - uint32_t ack_snd; - uint16_t wnd_snd; - uint8_t hc_type; -} tcp_hc_context_t; - -typedef struct __attribute__((packed)) { - uint32_t send_una; - uint32_t send_nxt; - uint16_t send_wnd; - uint32_t send_iss; - - uint32_t rcv_nxt; - uint16_t rcv_wnd; - uint32_t rcv_irs; - - timex_t last_packet_time; - uint8_t no_of_retries; - uint16_t mss; - - uint8_t state; - - double srtt; - double rttvar; - double rto; - -#ifdef TCP_HC - tcp_hc_context_t tcp_context; -#endif -} tcp_cb_t; -#endif - -typedef struct { - uint8_t domain; - uint8_t type; - uint8_t protocol; -#ifdef MODULE_TCP - tcp_cb_t tcp_control; -#endif - sockaddr6_t local_address; - sockaddr6_t foreign_address; -} socket_t; - -typedef struct { - uint8_t socket_id; - uint8_t recv_pid; - uint8_t send_pid; - socket_t socket_values; -#ifdef MODULE_TCP - uint8_t tcp_input_buffer_end; - mutex_t tcp_buffer_mutex; - uint8_t tcp_input_buffer[TRANSPORT_LAYER_SOCKET_MAX_TCP_BUFFER]; -#endif -} socket_internal_t; - -extern socket_internal_t socket_base_sockets[MAX_SOCKETS]; - -#ifdef __cplusplus -extern "C" { -#endif - -socket_internal_t *socket_base_get_socket(int s); -uint16_t socket_base_get_free_source_port(uint8_t protocol); -bool socket_base_exists_socket(int socket); -int socket_base_socket(int domain, int type, int protocol); -void socket_base_print_sockets(void); - -#ifdef __cplusplus -} -#endif - -#endif /* _SOCKET_BASE_SOCKET */ diff --git a/sys/net/transport_layer/tcp/Makefile b/sys/net/transport_layer/tcp/Makefile deleted file mode 100644 index 8978e06912..0000000000 --- a/sys/net/transport_layer/tcp/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -INCLUDES += -I $(RIOTBASE)/sys/net/transport_layer/socket_base -include $(RIOTBASE)/Makefile.base diff --git a/sys/net/transport_layer/tcp/tcp.c b/sys/net/transport_layer/tcp/tcp.c deleted file mode 100644 index a2f6d25031..0000000000 --- a/sys/net/transport_layer/tcp/tcp.c +++ /dev/null @@ -1,1422 +0,0 @@ -/** - * TCP implementation - * - * Copyright (C) 2013 INRIA. - * - * 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 tcp - * @{ - * @file - * @brief TCP implementation - * @author Oliver Gesch - * @author Cenk GündoÄŸan - * @} - */ - -#include -#include -#include -#include - -#include "sixlowpan.h" -#include "thread.h" -#include "vtimer.h" - -#include "socket_base/in.h" - -#include "net_help.h" - -#include "msg_help.h" -#include "socket.h" -#include "tcp_hc.h" -#include "tcp_timer.h" - -#include "tcp.h" - -#ifdef TCP_HC -mutex_t global_context_counter_mutex; -uint8_t global_context_counter; -#endif - -mutex_t global_sequence_counter_mutex; -uint32_t global_sequence_counter; - -char tcp_stack_buffer[TCP_STACK_SIZE]; -char tcp_timer_stack[TCP_TIMER_STACKSIZE]; - -void set_socket_address(sockaddr6_t *sockaddr, uint8_t sin6_family, - uint16_t sin6_port, uint32_t sin6_flowinfo, ipv6_addr_t *sin6_addr) -{ - sockaddr->sin6_family = sin6_family; - sockaddr->sin6_port = sin6_port; - sockaddr->sin6_flowinfo = sin6_flowinfo; - memcpy(&sockaddr->sin6_addr, sin6_addr, 16); -} - -void printTCPHeader(tcp_hdr_t *tcp_header) -{ - printf("\nBEGIN: TCP HEADER\n"); - printf("ack_nr: %" PRIu32 "\n", tcp_header->ack_nr); - printf("checksum: %i\n", tcp_header->checksum); - printf("data_offset: %i\n", tcp_header->data_offset); - printf("dst_port: %i\n", tcp_header->dst_port); - printf("reserved_flags: %i\n", tcp_header->reserved_flags); - printf("seq_nr: %" PRIu32 "\n", tcp_header->seq_nr); - printf("src_port: %i\n", tcp_header->src_port); - printf("urg_pointer: %i\n", tcp_header->urg_pointer); - printf("window: %i\n", tcp_header->window); - printf("END: TCP HEADER\n"); -} - -void print_tcp_flags(tcp_hdr_t *tcp_header) -{ - printf("FLAGS: "); - - switch (tcp_header->reserved_flags) { - case TCP_ACK: { - printf("ACK "); - break; - } - - case TCP_RST: { - printf("RST "); - break; - } - - case TCP_SYN: { - printf("SYN "); - break; - } - - case TCP_FIN: { - printf("FIN "); - break; - } - - case TCP_URG_PSH: { - printf("URG PSH "); - break; - } - - case TCP_SYN_ACK: { - printf("SYN ACK "); - break; - } - - case TCP_FIN_ACK: { - printf("FIN ACK "); - break; - } - } - - printf("\n"); -} - -void print_tcp_cb(tcp_cb_t *cb) -{ - timex_t now; - vtimer_now(&now); - printf("Send_ISS: %" PRIu32 "\nSend_UNA: %" PRIu32 "\nSend_NXT: %" PRIu32 "\nSend_WND: %u\n", - cb->send_iss, cb->send_una, cb->send_nxt, cb->send_wnd); - printf("Rcv_IRS: %" PRIu32 "\nRcv_NXT: %" PRIu32 "\nRcv_WND: %u\n", - cb->rcv_irs, cb->rcv_nxt, cb->rcv_wnd); - printf("Time difference: %" PRIu64 ", No_of_retries: %u, State: %u\n\n", - timex_uint64(timex_sub(now, cb->last_packet_time)), cb->no_of_retries, cb->state); -} - -void print_tcp_status(int in_or_out, ipv6_hdr_t *ipv6_header, - tcp_hdr_t *tcp_header, socket_t *tcp_socket) -{ - char addr_str[IPV6_MAX_ADDR_STR_LEN]; - printf("--- %s TCP packet: ---\n", - (in_or_out == INC_PACKET ? "Incoming" : "Outgoing")); - printf("IPv6 Source: %s\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - &ipv6_header->srcaddr)); - printf("IPv6 Dest: %s\n", - ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - &ipv6_header->destaddr)); - printf("TCP Length: %x\n", NTOHS(ipv6_header->length) - TCP_HDR_LEN); - printf("Source Port: %x, Dest. Port: %x\n", - NTOHS(tcp_header->src_port), NTOHS(tcp_header->dst_port)); - printf("Source Port: %u, Dest. Port: %u\n", - NTOHS(tcp_header->src_port), NTOHS(tcp_header->dst_port)); - printf("ACK: %" PRIu32 ", SEQ: %" PRIu32 ", Window: %x\n", - tcp_header->ack_nr, tcp_header->seq_nr, tcp_header->window); - printf("ACK: %" PRIu32 ", SEQ: %" PRIu32 ", Window: %u\n", - tcp_header->ack_nr, tcp_header->seq_nr, tcp_header->window); - print_tcp_flags(tcp_header); - print_tcp_cb(&tcp_socket->tcp_control); -#ifdef TCP_HC - printf_tcp_context(&tcp_socket->tcp_control.tcp_context); -#endif -} - -uint16_t tcp_csum(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header) -{ - uint16_t sum; - uint16_t len = NTOHS(ipv6_header->length); - - sum = len + IPPROTO_TCP; - sum = csum(sum, (uint8_t *)&ipv6_header->srcaddr, 2 * sizeof(ipv6_addr_t)); - sum = csum(sum, (uint8_t *)tcp_header, len); - return (sum == 0) ? 0xffff : HTONS(sum); -} - -/* Check for consistent ACK and SEQ number */ -int check_tcp_consistency(socket_t *current_tcp_socket, tcp_hdr_t *tcp_header, uint8_t tcp_payload_len) -{ - if (tcp_payload_len == 0) { - if (tcp_header->ack_nr > (current_tcp_socket->tcp_control.send_nxt)) { - /* ACK of not yet sent byte, discard */ - return ACK_NO_TOO_BIG; - } - else if (tcp_header->ack_nr <= (current_tcp_socket->tcp_control.send_una)) { - /* ACK of previous segments, maybe dropped? */ - 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)) { - /* segment repetition, maybe ACK got lost? */ - return SEQ_NO_TOO_SMALL; - } - - return PACKET_OK; -} - -void set_tcp_cb(tcp_cb_t *tcp_control, uint32_t rcv_nxt, uint16_t rcv_wnd, - uint32_t send_nxt, uint32_t send_una, uint16_t send_wnd) -{ - tcp_control->rcv_nxt = rcv_nxt; - tcp_control->rcv_wnd = rcv_wnd; - tcp_control->send_nxt = send_nxt; - tcp_control->send_una = send_una; - tcp_control->send_wnd = send_wnd; -} - -void switch_tcp_packet_byte_order(tcp_hdr_t *current_tcp_packet) -{ - if (current_tcp_packet->data_offset * 4 > TCP_HDR_LEN) { - if (*(((uint8_t *)current_tcp_packet) + TCP_HDR_LEN) == TCP_MSS_OPTION) { - uint8_t *packet_pointer = (uint8_t *)current_tcp_packet; - packet_pointer += (TCP_HDR_LEN + 2); - uint8_t mss1 = *packet_pointer; - uint8_t mss2 = *(packet_pointer + 1); - *packet_pointer = mss2; - *(packet_pointer + 1) = mss1; - } - - if (*(((uint8_t *)current_tcp_packet) + TCP_HDR_LEN) == TCP_TS_OPTION) { - /* TODO: Timestamp option not implemented */ - } - } - - current_tcp_packet->seq_nr = HTONL(current_tcp_packet->seq_nr); - current_tcp_packet->ack_nr = HTONL(current_tcp_packet->ack_nr); - current_tcp_packet->window = HTONS(current_tcp_packet->window); - current_tcp_packet->urg_pointer = HTONS(current_tcp_packet->urg_pointer); -} - -void set_tcp_packet(tcp_hdr_t *tcp_hdr, uint16_t src_port, uint16_t dst_port, - uint32_t seq_nr, uint32_t ack_nr, uint8_t data_offset, - uint8_t reserved_flags, uint16_t window, uint16_t checksum, - uint16_t urg_pointer) -{ - tcp_hdr->ack_nr = ack_nr; - tcp_hdr->checksum = checksum; - tcp_hdr->data_offset = data_offset; - tcp_hdr->dst_port = dst_port; - tcp_hdr->reserved_flags = reserved_flags; - tcp_hdr->reserved = 0; - tcp_hdr->flag_ns = 0; - tcp_hdr->seq_nr = seq_nr; - tcp_hdr->src_port = src_port; - tcp_hdr->urg_pointer = urg_pointer; - tcp_hdr->window = window; -} - -int send_tcp(socket_internal_t *current_socket, tcp_hdr_t *current_tcp_packet, - ipv6_hdr_t *temp_ipv6_header, uint8_t flags, uint8_t payload_length) -{ - socket_t *current_tcp_socket = ¤t_socket->socket_values; - uint8_t header_length = TCP_HDR_LEN / 4; - - if (IS_TCP_SYN(flags) || IS_TCP_SYN_ACK(flags)) { - tcp_mss_option_t current_mss_option; - header_length += sizeof(tcp_mss_option_t) / 4; - - current_mss_option.kind = TCP_MSS_OPTION; - current_mss_option.len = sizeof(tcp_mss_option_t); - current_mss_option.mss = TRANSPORT_LAYER_SOCKET_STATIC_MSS; - memcpy(((uint8_t *)current_tcp_packet) + TCP_HDR_LEN, - ¤t_mss_option, sizeof(tcp_mss_option_t)); - } - - set_tcp_packet(current_tcp_packet, current_tcp_socket->local_address.sin6_port, - current_tcp_socket->foreign_address.sin6_port, - current_tcp_socket->tcp_control.send_una, - (IS_TCP_ACK(flags) ? current_tcp_socket->tcp_control.rcv_nxt : 0x00), header_length, flags, - current_tcp_socket->tcp_control.rcv_wnd, 0, 0); - - /* Fill IPv6 Header */ - memcpy(&(temp_ipv6_header->destaddr), - ¤t_tcp_socket->foreign_address.sin6_addr, 16); - memcpy(&(temp_ipv6_header->srcaddr), - ¤t_tcp_socket->local_address.sin6_addr, 16); - temp_ipv6_header->length = HTONS(header_length * 4 + payload_length); - - current_tcp_packet->checksum = ~tcp_csum(temp_ipv6_header, current_tcp_packet); - -#ifdef TCP_HC - uint16_t compressed_size; - - compressed_size = compress_tcp_packet(current_socket, - (uint8_t *)current_tcp_packet, - temp_ipv6_header, flags, - payload_length); - - if (compressed_size == 0) { - /* Error in compressing tcp packet header */ - return -1; - } - - return ipv6_sendto(¤t_tcp_socket->foreign_address.sin6_addr, - IPPROTO_TCP, (uint8_t *)(current_tcp_packet), - compressed_size); -#else - switch_tcp_packet_byte_order(current_tcp_packet); - return ipv6_sendto(¤t_tcp_socket->foreign_address.sin6_addr, - IPPROTO_TCP, (uint8_t *)(current_tcp_packet), - header_length * 4 + payload_length, NULL); -#endif -} - -bool is_four_touple(socket_internal_t *current_socket, ipv6_hdr_t *ipv6_header, - tcp_hdr_t *tcp_header) -{ - return (ipv6_addr_is_equal(¤t_socket->socket_values.local_address.sin6_addr, - &ipv6_header->destaddr) && - (current_socket->socket_values.local_address.sin6_port == tcp_header->dst_port) && - ipv6_addr_is_equal(¤t_socket->socket_values.foreign_address.sin6_addr, - &ipv6_header->srcaddr) && - (current_socket->socket_values.foreign_address.sin6_port == tcp_header->src_port)); -} - -socket_internal_t *get_waiting_connection_socket(int socket, - ipv6_hdr_t *ipv6_header, - tcp_hdr_t *tcp_header) -{ - int i; - socket_internal_t *listening_socket = socket_base_get_socket(socket); - - for (i = 1; i < MAX_SOCKETS + 1; i++) { - socket_internal_t *current_socket = socket_base_get_socket(i); - - if (!current_socket) { - continue; - } - - /* Connection establishment ACK, Check for 4 touple and state */ - if ((ipv6_header != NULL) && (tcp_header != NULL)) { - if (is_four_touple(current_socket, ipv6_header, tcp_header) && - (current_socket->socket_values.tcp_control.state == TCP_SYN_RCVD)) { - return current_socket; - } - } - /* Connection establishment SYN ACK, check only for port and state */ - else { - if ((current_socket->socket_values.tcp_control.state == TCP_SYN_RCVD) && - (current_socket->socket_values.local_address.sin6_port == - listening_socket->socket_values.local_address.sin6_port)) { - return current_socket; - } - } - } - - return NULL; -} - -socket_internal_t *new_tcp_queued_socket(ipv6_hdr_t *ipv6_header, - tcp_hdr_t *tcp_header) -{ - int queued_socket_id; - - queued_socket_id = socket_base_socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP); - socket_internal_t *current_queued_socket = socket_base_get_socket(queued_socket_id); - - /* Foreign address */ - set_socket_address(¤t_queued_socket->socket_values.foreign_address, - AF_INET6, tcp_header->src_port, ipv6_header->flowlabel, - &ipv6_header->srcaddr); - - /* Local address */ - set_socket_address(¤t_queued_socket->socket_values.local_address, - AF_INET6, tcp_header->dst_port, 0, - &ipv6_header->destaddr); - - /* Foreign TCP information */ - if ((tcp_header->data_offset * 4 > TCP_HDR_LEN) && - (*(((uint8_t *)tcp_header) + TCP_HDR_LEN) == TCP_MSS_OPTION)) { - current_queued_socket->socket_values.tcp_control.mss = - *((uint16_t *)(((uint8_t *)tcp_header) + TCP_HDR_LEN + 2)); - } - else { - current_queued_socket->socket_values.tcp_control.mss = TRANSPORT_LAYER_SOCKET_STATIC_MSS; - } - - current_queued_socket->socket_values.tcp_control.rcv_irs = - tcp_header->seq_nr; - mutex_lock(&global_sequence_counter_mutex); - current_queued_socket->socket_values.tcp_control.send_iss = - global_sequence_counter; - mutex_unlock(&global_sequence_counter_mutex); - current_queued_socket->socket_values.tcp_control.state = TCP_SYN_RCVD; - set_tcp_cb(¤t_queued_socket->socket_values.tcp_control, - tcp_header->seq_nr + 1, TRANSPORT_LAYER_SOCKET_STATIC_WINDOW, - current_queued_socket->socket_values.tcp_control.send_iss + 1, - current_queued_socket->socket_values.tcp_control.send_iss, - tcp_header->window); - - return current_queued_socket; -} - -socket_internal_t *get_tcp_socket(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header) -{ - uint8_t i = 1; - socket_internal_t *current_socket = NULL; - socket_internal_t *listening_socket = NULL; - uint8_t compare[16]; - memset(compare, 0, 16); - - while (i < MAX_SOCKETS + 1) { - current_socket = socket_base_get_socket(i); - - /* Check for matching 4 touple, TCP_ESTABLISHED connection */ - if (tcp_socket_compliancy(i) && is_four_touple(current_socket, ipv6_header, - tcp_header)) { - return current_socket; - } - /* Sockets in TCP_LISTEN and TCP_SYN_RCVD state should only be tested on local TCP values */ - else if (tcp_socket_compliancy(i) && - ((current_socket->socket_values.tcp_control.state == TCP_LISTEN) || - (current_socket->socket_values.tcp_control.state == TCP_SYN_RCVD)) && - (current_socket->socket_values.local_address.sin6_addr.uint8[15] == - ipv6_header->destaddr.uint8[15]) && - (current_socket->socket_values.local_address.sin6_port == - tcp_header->dst_port) && - (current_socket->socket_values.foreign_address.sin6_addr.uint8[15] == - 0x00) && - (current_socket->socket_values.foreign_address.sin6_port == 0)) { - listening_socket = current_socket; - } - - i++; - } - - /* Return either NULL if nothing was matched or the listening 2 touple socket */ - return listening_socket; -} - -uint8_t handle_payload(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, - socket_internal_t *tcp_socket, uint8_t *payload) -{ - (void) tcp_header; - - msg_t m_send_tcp, m_recv_tcp; - uint8_t tcp_payload_len = NTOHS(ipv6_header->length) - TCP_HDR_LEN; - uint8_t acknowledged_bytes = 0; - - if (tcp_payload_len > tcp_socket->socket_values.tcp_control.rcv_wnd) { - mutex_lock(&tcp_socket->tcp_buffer_mutex); - memcpy(tcp_socket->tcp_input_buffer, payload, - tcp_socket->socket_values.tcp_control.rcv_wnd); - acknowledged_bytes = tcp_socket->socket_values.tcp_control.rcv_wnd; - tcp_socket->socket_values.tcp_control.rcv_wnd = 0; - tcp_socket->tcp_input_buffer_end = tcp_socket->tcp_input_buffer_end + - tcp_socket->socket_values.tcp_control.rcv_wnd; - mutex_unlock(&tcp_socket->tcp_buffer_mutex); - } - else { - mutex_lock(&tcp_socket->tcp_buffer_mutex); - memcpy(tcp_socket->tcp_input_buffer, payload, tcp_payload_len); - tcp_socket->socket_values.tcp_control.rcv_wnd = - tcp_socket->socket_values.tcp_control.rcv_wnd - tcp_payload_len; - acknowledged_bytes = tcp_payload_len; - tcp_socket->tcp_input_buffer_end = tcp_socket->tcp_input_buffer_end + - tcp_payload_len; - mutex_unlock(&tcp_socket->tcp_buffer_mutex); - } - - if (thread_getstatus(tcp_socket->recv_pid) == STATUS_RECEIVE_BLOCKED) { - socket_base_net_msg_send_recv(&m_send_tcp, &m_recv_tcp, tcp_socket->recv_pid, UNDEFINED); - } - - return acknowledged_bytes; -} - -void handle_tcp_ack_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, - socket_internal_t *tcp_socket) -{ - msg_t m_recv_tcp, m_send_tcp; - - if (tcp_socket->socket_values.tcp_control.state == TCP_LAST_ACK) { - uint8_t target_pid = tcp_socket->recv_pid; - memset(tcp_socket, 0, sizeof(socket_internal_t)); - msg_try_send(&m_send_tcp, target_pid); - return; - } - else if (tcp_socket->socket_values.tcp_control.state == TCP_CLOSING) { - msg_try_send(&m_send_tcp, tcp_socket->recv_pid); - msg_try_send(&m_send_tcp, tcp_socket->send_pid); - return; - } - else if (get_waiting_connection_socket(tcp_socket->socket_id, ipv6_header, - tcp_header) != NULL) { - m_send_tcp.content.ptr = (char *)tcp_header; - socket_base_net_msg_send_recv(&m_send_tcp, &m_recv_tcp, tcp_socket->recv_pid, TCP_ACK); - return; - } - else if (tcp_socket->socket_values.tcp_control.state == TCP_ESTABLISHED) { - if (check_tcp_consistency(&tcp_socket->socket_values, tcp_header, 0) == PACKET_OK) { - m_send_tcp.content.ptr = (char *)tcp_header; - socket_base_net_msg_send(&m_send_tcp, tcp_socket->send_pid, 0, TCP_ACK); - return; - } - } - - printf("NO WAY OF HANDLING THIS ACK!\n"); -} - -void handle_tcp_rst_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, - socket_internal_t *tcp_socket) -{ - (void) ipv6_header; - (void) tcp_header; - (void) tcp_socket; - - /* TODO: Reset connection */ -} - -void handle_tcp_syn_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, - socket_internal_t *tcp_socket) -{ - msg_t m_send_tcp; - - if (tcp_socket->socket_values.tcp_control.state == TCP_LISTEN) { - socket_internal_t *new_socket = new_tcp_queued_socket(ipv6_header, - tcp_header); - - if (new_socket != NULL) { -#ifdef TCP_HC - update_tcp_hc_context(true, new_socket, tcp_header); -#endif - /* notify socket function tcp_accept(..) that a new - * connection request has arrived. No need to wait for an answer - * because the server tcp_accept() function isnt reading - * from anything other than the queued sockets */ - socket_base_net_msg_send(&m_send_tcp, tcp_socket->recv_pid, 0, TCP_SYN); - } - else { - printf("Dropped TCP SYN Message because an error occured while "\ - "requesting a new queued socket!\n"); - } - } - else { - printf("Dropped TCP SYN Message because socket was not in state TCP_LISTEN!"); - } -} - -void handle_tcp_syn_ack_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, - socket_internal_t *tcp_socket) -{ - (void) ipv6_header; - - msg_t m_send_tcp; - - if (tcp_socket->socket_values.tcp_control.state == TCP_SYN_SENT) { - m_send_tcp.content.ptr = (char *) tcp_header; - socket_base_net_msg_send(&m_send_tcp, tcp_socket->recv_pid, 0, TCP_SYN_ACK); - } - else { - printf("Socket not in state TCP_SYN_SENT, dropping SYN-ACK-packet!"); - } -} - -void handle_tcp_fin_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, - socket_internal_t *tcp_socket) -{ - (void) ipv6_header; - - msg_t m_send; - socket_t *current_tcp_socket = &tcp_socket->socket_values; - uint8_t send_buffer[BUFFER_SIZE]; - 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])); - - set_tcp_cb(¤t_tcp_socket->tcp_control, tcp_header->seq_nr + 1, - current_tcp_socket->tcp_control.send_wnd, tcp_header->ack_nr + 1, - tcp_header->ack_nr, tcp_header->window); - -#ifdef TCP_HC - current_tcp_socket->tcp_control.tcp_context.hc_type = COMPRESSED_HEADER; -#endif - - if (current_tcp_socket->tcp_control.state == TCP_FIN_WAIT_1) { - current_tcp_socket->tcp_control.state = TCP_CLOSING; - - send_tcp(tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_FIN_ACK, 0); - } - else { - current_tcp_socket->tcp_control.state = TCP_LAST_ACK; - - send_tcp(tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_FIN_ACK, 0); - } - - socket_base_net_msg_send(&m_send, tcp_socket->recv_pid, 0, CLOSE_CONN); -} - -void handle_tcp_fin_ack_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, - socket_internal_t *tcp_socket) -{ - (void) ipv6_header; - - msg_t m_send; - socket_t *current_tcp_socket = &tcp_socket->socket_values; - uint8_t send_buffer[BUFFER_SIZE]; - 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])); - - current_tcp_socket->tcp_control.state = TCP_CLOSED; - - set_tcp_cb(¤t_tcp_socket->tcp_control, tcp_header->seq_nr + 1, - current_tcp_socket->tcp_control.send_wnd, tcp_header->ack_nr, - tcp_header->ack_nr, tcp_header->window); - -#ifdef TCP_HC - current_tcp_socket->tcp_control.tcp_context.hc_type = COMPRESSED_HEADER; -#endif - - send_tcp(tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_ACK, 0); - - msg_try_send(&m_send, tcp_socket->send_pid); - msg_try_send(&m_send, tcp_socket->recv_pid); -} - -void handle_tcp_no_flags_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, - socket_internal_t *tcp_socket, uint8_t *payload, uint8_t tcp_payload_len) -{ - socket_t *current_tcp_socket = &tcp_socket->socket_values; - uint8_t send_buffer[BUFFER_SIZE]; - 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])); - - if (check_tcp_consistency(current_tcp_socket, tcp_header, tcp_payload_len) == PACKET_OK) { - uint8_t read_bytes = handle_payload(ipv6_header, tcp_header, tcp_socket, payload); - - /* Refresh TCP status values */ - current_tcp_socket->tcp_control.state = TCP_ESTABLISHED; - - set_tcp_cb(¤t_tcp_socket->tcp_control, - tcp_header->seq_nr + read_bytes, - current_tcp_socket->tcp_control.rcv_wnd, - current_tcp_socket->tcp_control.send_nxt, - current_tcp_socket->tcp_control.send_una, - current_tcp_socket->tcp_control.send_wnd); - - /* Send packet */ - // block_continue_thread(); -#ifdef TCP_HC - current_tcp_socket->tcp_control.tcp_context.hc_type = COMPRESSED_HEADER; -#endif - send_tcp(tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_ACK, 0); - } - /* ACK packet probably got lost */ - else { - // block_continue_thread(); -#ifdef TCP_HC - current_tcp_socket->tcp_control.tcp_context.hc_type = FULL_HEADER; -#endif - send_tcp(tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_ACK, 0); - } -} - -void *tcp_packet_handler(void *arg) -{ - (void) arg; - - msg_t m_recv_ip, m_send_ip; - socket_internal_t *tcp_socket = NULL; - - while (1) { - msg_receive(&m_recv_ip); - - ipv6_hdr_t *ipv6_header = ((ipv6_hdr_t *)m_recv_ip.content.ptr); - tcp_hdr_t *tcp_header = ((tcp_hdr_t *)(m_recv_ip.content.ptr + IPV6_HDR_LEN)); -#ifdef TCP_HC - tcp_socket = decompress_tcp_packet(ipv6_header); -#else - switch_tcp_packet_byte_order(tcp_header); - tcp_socket = get_tcp_socket(ipv6_header, tcp_header); -#endif - uint16_t chksum = tcp_csum(ipv6_header, tcp_header); - - uint8_t *payload = (uint8_t *)(m_recv_ip.content.ptr + IPV6_HDR_LEN + tcp_header->data_offset * 4); - - if ((chksum == 0xffff) && (tcp_socket != NULL)) { -#ifdef TCP_HC - update_tcp_hc_context(true, tcp_socket, tcp_header); -#endif - /* Remove reserved bits from tcp flags field */ - switch (tcp_header->reserved_flags) { - case TCP_ACK: { - /* only ACK Bit set */ - uint8_t tcp_payload_len = NTOHS(ipv6_header->length) - TCP_HDR_LEN; - uint8_t state = tcp_socket->socket_values.tcp_control.state; - - if ((tcp_payload_len > 0) && (state == TCP_ESTABLISHED)) { - /* handle data segments only when the connection was established successfully */ - handle_tcp_no_flags_packet(ipv6_header, tcp_header, tcp_socket, payload, tcp_payload_len); - } - else if (tcp_payload_len == 0 - && (state == TCP_ESTABLISHED || state == TCP_SYN_RCVD - || state == TCP_CLOSING || state == TCP_LAST_ACK)) { - /* no payload, acknowledging data only */ - handle_tcp_ack_packet(ipv6_header, tcp_header, tcp_socket); - } - break; - } - - case TCP_RST: { - printf("RST Bit set!\n"); - /* only RST Bit set */ - handle_tcp_rst_packet(ipv6_header, tcp_header, tcp_socket); - break; - } - - case TCP_SYN: { - /* only SYN Bit set, look for matching, listening socket - * and request new queued socket */ - printf("SYN Bit set!\n"); - handle_tcp_syn_packet(ipv6_header, tcp_header, tcp_socket); - break; - } - - case TCP_SYN_ACK: { - /* only SYN and ACK Bit set, complete three way handshake - * when socket in state TCP_SYN_SENT */ - handle_tcp_syn_ack_packet(ipv6_header, tcp_header, tcp_socket); - break; - } - - case TCP_FIN_ACK: { - if (tcp_socket->socket_values.tcp_control.state == TCP_ESTABLISHED) { - /* this is the first FIN */ - printf("FIN ACK Bit set!\n"); - handle_tcp_fin_packet(ipv6_header, tcp_header, tcp_socket); - } - else { - /* this is the response to FIN */ - handle_tcp_fin_ack_packet(ipv6_header, tcp_header, tcp_socket); - } - break; - } - - default: { - printf("Unable to process the incoming segment!\n"); - } - } - } - else { - printf("Wrong checksum (%x) or no corresponding socket found!\n", - chksum); - print_tcp_status(INC_PACKET, ipv6_header, tcp_header, - &tcp_socket->socket_values); - } - - msg_reply(&m_recv_ip, &m_send_ip); - } -} - -void printf_tcp_context(tcp_hc_context_t *current_tcp_context) -{ - printf("Context: %u\n", current_tcp_context->context_id); - printf("Rcv Seq: %" PRIu32 " Rcv Ack: %" PRIu32 ", Rcv Wnd: %u\n", current_tcp_context->seq_rcv, current_tcp_context->ack_rcv, current_tcp_context->wnd_rcv); - printf("Snd Seq: %" PRIu32 " Snd Ack: %" PRIu32 ", Snd Wnd: %u\n", current_tcp_context->seq_snd, current_tcp_context->ack_snd, current_tcp_context->wnd_snd); -} - -bool tcp_socket_compliancy(int s) -{ - if ((socket_base_exists_socket(s)) && - (socket_base_get_socket(s)->socket_values.domain == PF_INET6) && - (socket_base_get_socket(s)->socket_values.type == SOCK_STREAM) && - ((socket_base_get_socket(s)->socket_values.protocol == IPPROTO_TCP) || - (socket_base_get_socket(s)->socket_values.protocol == 0))) { - return true; - } - else { - return false; - } -} - -int tcp_bind_socket(int s, sockaddr6_t *name, int namelen, uint8_t pid) -{ - int i; - - socket_internal_t *sock = socket_base_get_socket(s); - - if (!sock) { - return -1; - } - - for (i = 1; i < MAX_SOCKETS + 1; i++) { - if (tcp_socket_compliancy(i) && - (socket_base_get_socket(i)->socket_values.local_address.sin6_port == name->sin6_port)) { - return -1; - } - } - - (void) namelen; - sock->socket_values.local_address = *name; - sock->socket_values.tcp_control.rto = TCP_INITIAL_ACK_TIMEOUT; - sock->recv_pid = pid; - - return 0; -} - -void calculate_rto(tcp_cb_t *tcp_control, timex_t current_time) -{ - double rtt = (double) timex_uint64(timex_sub(current_time, tcp_control->last_packet_time)); - double srtt = tcp_control->srtt; - double rttvar = tcp_control->rttvar; - double rto = tcp_control->rto; - - if ((srtt == 0) && (rttvar == 0) && (rto == TCP_INITIAL_ACK_TIMEOUT)) { - /* First calculation */ - srtt = rtt; - rttvar = 0.5 * rtt; - rto = rtt + (((4 * rttvar) < TCP_TIMER_RESOLUTION) ? - (TCP_TIMER_RESOLUTION) : (4 * rttvar)); - } - else { - /* every other calculation */ - srtt = (1 - TCP_ALPHA) * srtt + TCP_ALPHA * rtt; - rttvar = (1 - TCP_BETA) * rttvar + TCP_BETA * abs(srtt - rtt); - rto = srtt + (((4 * rttvar) < TCP_TIMER_RESOLUTION) ? - (TCP_TIMER_RESOLUTION) : (4 * rttvar)); - } - - if (rto < SECOND) { - rto = SECOND; - } - - tcp_control->srtt = srtt; - tcp_control->rttvar = rttvar; - tcp_control->rto = rto; -} - -int handle_new_tcp_connection(socket_internal_t *current_queued_int_socket, - socket_internal_t *server_socket, uint8_t pid) -{ - (void) pid; - - msg_t msg_recv_client_ack, msg_send_client_ack; - socket_t *current_queued_socket = ¤t_queued_int_socket->socket_values; - uint8_t send_buffer[BUFFER_SIZE]; - ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t *)(&send_buffer)); - tcp_hdr_t *syn_ack_packet = ((tcp_hdr_t *)(&send_buffer[IPV6_HDR_LEN])); - - current_queued_int_socket->recv_pid = thread_getpid(); -#ifdef TCP_HC - current_queued_int_socket->socket_values.tcp_control.tcp_context.hc_type = - FULL_HEADER; - memcpy(¤t_queued_int_socket->socket_values.tcp_control.tcp_context.context_id, - &server_socket->socket_values.tcp_control.tcp_context.context_id, - sizeof(server_socket->socket_values.tcp_control.tcp_context.context_id)); -#endif - /* Remember current time */ - timex_t now; - vtimer_now(&now); - current_queued_int_socket->socket_values.tcp_control.last_packet_time = now; - - current_queued_int_socket->socket_values.tcp_control.no_of_retries = 0; - - /* Set message type to Retry for while loop */ - msg_recv_client_ack.type = TCP_RETRY; - - while (msg_recv_client_ack.type == TCP_RETRY) { - /* Send packet */ - send_tcp(current_queued_int_socket, syn_ack_packet, temp_ipv6_header, - TCP_SYN_ACK, 0); - - /* wait for ACK from Client */ - msg_receive(&msg_recv_client_ack); - - if (msg_recv_client_ack.type == TCP_TIMEOUT) { - /* Set status of internal socket back to TCP_LISTEN */ - server_socket->socket_values.tcp_control.state = TCP_LISTEN; - memset(current_queued_int_socket, 0, sizeof(socket_internal_t)); - return -1; - } - } - - tcp_hdr_t *tcp_header; - - tcp_header = ((tcp_hdr_t *)(msg_recv_client_ack.content.ptr)); - - /* Check for consistency */ - if (tcp_header->ack_nr != current_queued_socket->tcp_control.send_nxt) { - printf("TCP packets not consistent!\n"); - } - - /* Got ack, connection established, refresh local and foreign tcp socket - * status */ - set_tcp_cb(¤t_queued_socket->tcp_control, tcp_header->seq_nr, - current_queued_socket->tcp_control.rcv_wnd, tcp_header->ack_nr, - tcp_header->ack_nr, tcp_header->window); - -#ifdef TCP_HC - /* Copy TCP context information into new socket */ - memset(&server_socket->socket_values.tcp_control.tcp_context, 0, - sizeof(tcp_hc_context_t)); -#endif - - /* Update connection status information */ - current_queued_socket->tcp_control.state = TCP_ESTABLISHED; - - /* Set status of internal socket back to TCP_LISTEN */ - server_socket->socket_values.tcp_control.state = TCP_LISTEN; - - /* send a reply to the TCP handler after processing every information from - * the TCP ACK packet */ - msg_reply(&msg_recv_client_ack, &msg_send_client_ack); - - /* Reset PID to an unlikely value */ - current_queued_int_socket->recv_pid = 255; - - /* Waiting for Clients ACK waiting period to time out */ - vtimer_usleep(TCP_SYN_INITIAL_TIMEOUT / 2); - - socket_base_print_sockets(); - - return current_queued_int_socket->socket_id; -} - -int32_t tcp_send(int s, const void *buf, uint32_t len, int flags) -{ - (void) flags; - - /* Variables */ - msg_t recv_msg; - int32_t sent_bytes = 0; - uint32_t total_sent_bytes = 0; - socket_internal_t *current_int_tcp_socket; - socket_t *current_tcp_socket; - uint8_t send_buffer[BUFFER_SIZE]; - memset(send_buffer, 0, BUFFER_SIZE); - 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])); - - /* Check if socket exists and is TCP socket */ - if (!tcp_socket_compliancy(s)) { - return -1; - } - - current_int_tcp_socket = socket_base_get_socket(s); - current_tcp_socket = ¤t_int_tcp_socket->socket_values; - - /* Check for TCP_ESTABLISHED STATE */ - if (current_tcp_socket->tcp_control.state != TCP_ESTABLISHED) { - return -1; - } - - /* Add thread PID */ - current_int_tcp_socket->send_pid = thread_getpid(); - - recv_msg.type = UNDEFINED; - - while (1) { - current_tcp_socket->tcp_control.no_of_retries = 0; - -#ifdef TCP_HC - current_tcp_socket->tcp_control.tcp_context.hc_type = COMPRESSED_HEADER; - /* Remember TCP Context for possible TCP_RETRY */ - tcp_hc_context_t saved_tcp_context; - memcpy(&saved_tcp_context, ¤t_tcp_socket->tcp_control.tcp_context, - sizeof(tcp_hc_context_t) - 1); -#endif - - while (recv_msg.type != TCP_ACK) { - /* Add packet data */ - if (current_tcp_socket->tcp_control.send_wnd > - current_tcp_socket->tcp_control.mss) { - /* Window size > Maximum Segment Size */ - if ((len - total_sent_bytes) > current_tcp_socket->tcp_control.mss) { - memcpy(&send_buffer[IPV6_HDR_LEN + TCP_HDR_LEN], buf, - current_tcp_socket->tcp_control.mss); - sent_bytes = current_tcp_socket->tcp_control.mss; - total_sent_bytes += sent_bytes; - } - else { - memcpy(&send_buffer[IPV6_HDR_LEN + TCP_HDR_LEN], - (uint8_t *) buf + total_sent_bytes, len - total_sent_bytes); - sent_bytes = len - total_sent_bytes; - total_sent_bytes = len; - } - } - else { - /* Window size <= Maximum Segment Size */ - if ((len - total_sent_bytes) > current_tcp_socket->tcp_control.send_wnd) { - memcpy(&send_buffer[IPV6_HDR_LEN + TCP_HDR_LEN], buf, - current_tcp_socket->tcp_control.send_wnd); - sent_bytes = current_tcp_socket->tcp_control.send_wnd; - total_sent_bytes += sent_bytes; - } - else { - memcpy(&send_buffer[IPV6_HDR_LEN + TCP_HDR_LEN], - (uint8_t *) buf + total_sent_bytes, len - total_sent_bytes); - sent_bytes = len - total_sent_bytes; - total_sent_bytes = len; - } - } - - current_tcp_socket->tcp_control.send_nxt += sent_bytes; - current_tcp_socket->tcp_control.send_wnd -= sent_bytes; - - if (send_tcp(current_int_tcp_socket, current_tcp_packet, - temp_ipv6_header, TCP_ACK, sent_bytes) < 0) { - /* Error while sending tcp data */ - current_tcp_socket->tcp_control.send_nxt -= sent_bytes; - current_tcp_socket->tcp_control.send_wnd += sent_bytes; -#ifdef TCP_HC - memcpy(¤t_tcp_socket->tcp_control.tcp_context, - &saved_tcp_context, sizeof(tcp_hc_context_t)); - current_tcp_socket->tcp_control.tcp_context.hc_type = - COMPRESSED_HEADER; -#endif - printf("Error while sending, returning to application thread!\n"); - return -1; - } - - /* Remember current time */ - vtimer_now(¤t_tcp_socket->tcp_control.last_packet_time); - socket_base_net_msg_receive(&recv_msg); - - switch (recv_msg.type) { - case TCP_ACK: { - if (current_tcp_socket->tcp_control.no_of_retries == 0) { - calculate_rto(¤t_tcp_socket->tcp_control, - current_tcp_socket->tcp_control.last_packet_time); - } - - tcp_hdr_t *tcp_header = ((tcp_hdr_t *)(recv_msg.content.ptr)); - - if ((current_tcp_socket->tcp_control.send_nxt == - 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_nxt = tcp_header->ack_nr; - current_tcp_socket->tcp_control.send_wnd = tcp_header->window; - /* Got ACK for every sent byte */ -#ifdef TCP_HC - current_tcp_socket->tcp_control.tcp_context.hc_type = - COMPRESSED_HEADER; -#endif - return sent_bytes; - } - else if ((current_tcp_socket->tcp_control.send_nxt == - 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_nxt = tcp_header->ack_nr; - current_tcp_socket->tcp_control.send_wnd = tcp_header->window; - /* Got ACK for every sent byte */ -#ifdef TCP_HC - current_tcp_socket->tcp_control.tcp_context.hc_type = - COMPRESSED_HEADER; -#endif - break; - } - - /* else { - * TODO: If window size > MSS, ACK was valid only for - * a few segments, handle retransmit of missing - * segments - * break; - * } */ - break; - } - - case TCP_RETRY: { - current_tcp_socket->tcp_control.send_nxt -= sent_bytes; - current_tcp_socket->tcp_control.send_wnd += sent_bytes; - total_sent_bytes -= sent_bytes; -#ifdef TCP_HC - memcpy(¤t_tcp_socket->tcp_control.tcp_context, - $&saved_tcp_context, sizeof(tcp_hc_context_t)); - current_tcp_socket->tcp_control.tcp_context.hc_type = - MOSTLY_COMPRESSED_HEADER; -#endif - break; - } - - case TCP_TIMEOUT: { - current_tcp_socket->tcp_control.send_nxt -= sent_bytes; - current_tcp_socket->tcp_control.send_wnd += sent_bytes; -#ifdef TCP_HC - memcpy(¤t_tcp_socket->tcp_control.tcp_context, - &saved_tcp_context, sizeof(tcp_hc_context_t)); - current_tcp_socket->tcp_control.tcp_context.hc_type = - COMPRESSED_HEADER; -#endif - return -1; - } - } - } - } - - return sent_bytes; -} - -int tcp_accept(int s, sockaddr6_t *addr, uint32_t *addrlen) -{ - (void) addr; - (void) addrlen; - - socket_internal_t *server_socket = socket_base_get_socket(s); - - if (tcp_socket_compliancy(s) && (server_socket->socket_values.tcp_control.state == TCP_LISTEN)) { - socket_internal_t *current_queued_socket = - get_waiting_connection_socket(s, NULL, NULL); - - if (current_queued_socket != NULL) { - return handle_new_tcp_connection(current_queued_socket, - server_socket, thread_getpid()); - } - else { - /* No waiting connections, waiting for message from TCP Layer */ - msg_t msg_recv_client_syn; - msg_recv_client_syn.type = UNDEFINED; - - while (msg_recv_client_syn.type != TCP_SYN) { - msg_receive(&msg_recv_client_syn); - } - - current_queued_socket = get_waiting_connection_socket(s, NULL, NULL); - - return handle_new_tcp_connection(current_queued_socket, - server_socket, thread_getpid()); - } - } - else { - return -1; - } -} - -int tcp_connect(int socket, sockaddr6_t *addr, uint32_t addrlen) -{ - (void) addrlen; - - /* Variables */ - ipv6_addr_t src_addr; - socket_internal_t *current_int_tcp_socket; - socket_t *current_tcp_socket; - msg_t msg_from_server; - uint8_t send_buffer[BUFFER_SIZE]; - 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])); - - /* Check if socket exists */ - current_int_tcp_socket = socket_base_get_socket(socket); - - if (current_int_tcp_socket == NULL) { - return -1; - } - - current_tcp_socket = ¤t_int_tcp_socket->socket_values; - - current_int_tcp_socket->recv_pid = thread_getpid(); - - /* Local address information */ - ipv6_net_if_get_best_src_addr(&src_addr, &addr->sin6_addr); - set_socket_address(¤t_tcp_socket->local_address, PF_INET6, - HTONS(socket_base_get_free_source_port(IPPROTO_TCP)), 0, &src_addr); - - /* Foreign address information */ - set_socket_address(¤t_tcp_socket->foreign_address, addr->sin6_family, - addr->sin6_port, addr->sin6_flowinfo, &addr->sin6_addr); - - /* Fill lcoal TCP socket information */ - srand(addr->sin6_port); - - current_tcp_socket->tcp_control.rcv_irs = 0; - mutex_lock(&global_sequence_counter_mutex); - current_tcp_socket->tcp_control.send_iss = global_sequence_counter; - mutex_unlock(&global_sequence_counter_mutex); - current_tcp_socket->tcp_control.state = TCP_SYN_SENT; - -#ifdef TCP_HC - /* Choosing random number Context ID */ - mutex_lock(&global_context_counter_mutex); - current_tcp_socket->tcp_control.tcp_context.context_id = global_context_counter; - mutex_unlock(&global_context_counter_mutex); - - current_tcp_socket->tcp_control.tcp_context.hc_type = FULL_HEADER; - - /* Remember TCP Context for possible TCP_RETRY */ - tcp_hc_context_t saved_tcp_context; - memcpy(&saved_tcp_context, ¤t_tcp_socket->tcp_control.tcp_context, - sizeof(tcp_hc_context_t)); -#endif - - set_tcp_cb(¤t_tcp_socket->tcp_control, 0, TRANSPORT_LAYER_SOCKET_STATIC_WINDOW, - current_tcp_socket->tcp_control.send_iss + 1, - current_tcp_socket->tcp_control.send_iss, 0); - - /* Remember current time */ - timex_t now; - vtimer_now(&now); - current_tcp_socket->tcp_control.last_packet_time = now; - current_tcp_socket->tcp_control.no_of_retries = 0; - - msg_from_server.type = TCP_RETRY; - - while (msg_from_server.type == TCP_RETRY) { - /* Send packet */ - send_tcp(current_int_tcp_socket, current_tcp_packet, temp_ipv6_header, - TCP_SYN, 0); - - /* wait for SYN ACK or RETRY */ - msg_receive(&msg_from_server); - - if (msg_from_server.type == TCP_TIMEOUT) { -#ifdef TCP_HC - /* We did not send anything successful so restore last context */ - memcpy(¤t_tcp_socket->tcp_control.tcp_context, - &saved_tcp_context, sizeof(tcp_hc_context_t)); -#endif - return -1; - } - -#ifdef TCP_HC - else if (msg_from_server.type == TCP_RETRY) { - /* We retry sending a packet so set everything to last values again */ - memcpy(¤t_tcp_socket->tcp_control.tcp_context, - &saved_tcp_context, sizeof(tcp_hc_context_t)); - } - -#endif - } - - /* Read packet content */ - tcp_hdr_t *tcp_header = ((tcp_hdr_t *)(msg_from_server.content.ptr)); - - /* Check for consistency */ - if (tcp_header->ack_nr != current_tcp_socket->tcp_control.send_nxt) { - printf("TCP packets not consistent!\n"); - } - - /* Got SYN ACK from Server */ - /* Refresh foreign TCP socket information */ - if ((tcp_header->data_offset * 4 > TCP_HDR_LEN) && - (*(((uint8_t *)tcp_header) + TCP_HDR_LEN) == TCP_MSS_OPTION)) { - current_tcp_socket->tcp_control.mss = - *((uint16_t *)(((uint8_t *)tcp_header) + TCP_HDR_LEN + 2)); - } - else { - current_tcp_socket->tcp_control.mss = TRANSPORT_LAYER_SOCKET_STATIC_MSS; - } - - current_tcp_socket->tcp_control.rcv_irs = tcp_header->seq_nr; - set_tcp_cb(¤t_tcp_socket->tcp_control, tcp_header->seq_nr + 1, - current_tcp_socket->tcp_control.rcv_wnd, - current_tcp_socket->tcp_control.send_una + 1, - tcp_header->ack_nr, - tcp_header->window); - - msg_from_server.type = UNDEFINED; - - /* Remember current time */ - vtimer_now(&now); - current_tcp_socket->tcp_control.last_packet_time = now; - current_tcp_socket->tcp_control.no_of_retries = 0; - -#ifdef TCP_HC - current_tcp_socket->tcp_control.tcp_context.hc_type = FULL_HEADER; - /* Remember TCP Context for possible TCP_RETRY */ - memcpy(&saved_tcp_context, ¤t_tcp_socket->tcp_control.tcp_context, - sizeof(tcp_hc_context_t)); -#endif - - while (msg_from_server.type != TCP_RETRY) { - /* Send packet */ - send_tcp(current_int_tcp_socket, current_tcp_packet, temp_ipv6_header, - TCP_ACK, 0); - - msg_receive(&msg_from_server); -#ifdef TCP_HC - - if (msg_from_server.type == TCP_SYN_ACK) { - /* TCP_SYN_ACK from server arrived again, copy old context and - * send TCP_ACK again */ - memcpy(¤t_tcp_socket->tcp_control.tcp_context, - &saved_tcp_context, sizeof(tcp_hc_context_t)); - } - else if (msg_from_server.type == TCP_RETRY) { - /* We waited for RTT, no TCP_SYN_ACK received, so we assume the - * TCP_ACK packet arrived safely */ - } - -#endif - } - - current_tcp_socket->tcp_control.state = TCP_ESTABLISHED; - - current_int_tcp_socket->recv_pid = 255; - - socket_base_print_sockets(); - return 0; -} - -uint8_t read_from_socket(socket_internal_t *current_int_tcp_socket, - void *buf, int len) -{ - if (len >= current_int_tcp_socket->tcp_input_buffer_end) { - mutex_lock(¤t_int_tcp_socket->tcp_buffer_mutex); - uint8_t read_bytes = current_int_tcp_socket->tcp_input_buffer_end; - memcpy(buf, current_int_tcp_socket->tcp_input_buffer, - current_int_tcp_socket->tcp_input_buffer_end); - current_int_tcp_socket->tcp_input_buffer_end = 0; - current_int_tcp_socket->socket_values.tcp_control.rcv_wnd += read_bytes; - mutex_unlock(¤t_int_tcp_socket->tcp_buffer_mutex); - return read_bytes; - } - else { - mutex_lock(¤t_int_tcp_socket->tcp_buffer_mutex); - memcpy(buf, current_int_tcp_socket->tcp_input_buffer, len); - memmove(current_int_tcp_socket->tcp_input_buffer, - (current_int_tcp_socket->tcp_input_buffer + len), - current_int_tcp_socket->tcp_input_buffer_end - len); - current_int_tcp_socket->tcp_input_buffer_end = - current_int_tcp_socket->tcp_input_buffer_end - len; - current_int_tcp_socket->socket_values.tcp_control.rcv_wnd += len; - mutex_unlock(¤t_int_tcp_socket->tcp_buffer_mutex); - return len; - } -} - -int32_t tcp_recv(int s, void *buf, uint32_t len, int flags) -{ - (void) flags; - - /* Variables */ - msg_t m_recv, m_send; - socket_internal_t *current_int_tcp_socket; - - /* Check if socket exists */ - if (!tcp_socket_compliancy(s)) { - printf("INFO: NO TCP SOCKET!\n"); - return -1; - } - - current_int_tcp_socket = socket_base_get_socket(s); - - /* Setting Thread PID */ - current_int_tcp_socket->recv_pid = thread_getpid(); - - if (current_int_tcp_socket->tcp_input_buffer_end > 0) { - return read_from_socket(current_int_tcp_socket, buf, len); - } - - msg_receive(&m_recv); - - if ((socket_base_exists_socket(s)) && (current_int_tcp_socket->tcp_input_buffer_end > 0)) { - uint8_t read_bytes = read_from_socket(current_int_tcp_socket, buf, len); - socket_base_net_msg_reply(&m_recv, &m_send, UNDEFINED); - return read_bytes; - } - - /* Received FIN */ - if (m_recv.type == CLOSE_CONN) { - /* Sent FIN_ACK, wait for ACK */ - msg_receive(&m_recv); - /* Received ACK, return with closed socket!*/ - return -1; - } - - /* Received Last ACK (connection closed) or no data to read yet */ - return -1; -} - -int tcp_listen(int s, int backlog) -{ - (void) backlog; - - if (tcp_socket_compliancy(s) && socket_base_get_socket(s)->socket_values.tcp_control.state == TCP_CLOSED) { - socket_internal_t *current_socket = socket_base_get_socket(s); - current_socket->socket_values.tcp_control.state = TCP_LISTEN; - return 0; - } - else { - return -1; - } -} - -int tcp_teardown(socket_internal_t *current_socket) -{ - /* Variables */ - msg_t m_recv; - uint8_t send_buffer[BUFFER_SIZE]; - 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])); - - /* Check for TCP_ESTABLISHED STATE */ - if (current_socket->socket_values.tcp_control.state != TCP_ESTABLISHED) { - memset(current_socket, 0, sizeof(socket_internal_t)); - return 0; - } - - current_socket->send_pid = thread_getpid(); - - /* Refresh local TCP socket information */ - current_socket->socket_values.tcp_control.state = TCP_FIN_WAIT_1; -#ifdef TCP_HC - current_socket->socket_values.tcp_control.tcp_context.hc_type = - COMPRESSED_HEADER; -#endif - - send_tcp(current_socket, current_tcp_packet, temp_ipv6_header, - TCP_FIN_ACK, 0); - msg_receive(&m_recv); - memset(current_socket, 0, sizeof(socket_internal_t)); - return 1; -} - -int tcp_init_transport_layer(void) -{ - printf("Initializing transport layer protocol: tcp\n"); - timex_t now; - vtimer_now(&now); - srand(timex_uint64(now)); -#ifdef TCP_HC - printf("TCP_HC enabled!\n"); - global_context_counter = rand(); -#endif - global_sequence_counter = rand(); - - int tcp_thread_pid = thread_create(tcp_stack_buffer, TCP_STACK_SIZE, - THREAD_PRIORITY_MAIN, CREATE_STACKTEST, tcp_packet_handler, NULL, "tcp_packet_handler"); - - if (tcp_thread_pid < 0) { - return -1; - } - - ipv6_register_next_header_handler(IPV6_PROTO_NUM_TCP, tcp_thread_pid); - - if (thread_create(tcp_timer_stack, TCP_TIMER_STACKSIZE, THREAD_PRIORITY_MAIN + 1, - CREATE_STACKTEST, tcp_general_timer, NULL, "tcp_general_timer") < 0) { - return -1; - } - - return 0; -} diff --git a/sys/net/transport_layer/tcp/tcp.h b/sys/net/transport_layer/tcp/tcp.h deleted file mode 100644 index a30b0c8d5b..0000000000 --- a/sys/net/transport_layer/tcp/tcp.h +++ /dev/null @@ -1,123 +0,0 @@ -/** - * TCP header - * - * Copyright (C) 2013 INRIA. - * - * 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 transport_layer - * @{ - * @file - * @brief TCP data structs and prototypes - * @author Oliver Gesch - */ - -#ifndef TCP_H_ -#define TCP_H_ - -#include "ipv6.h" -#include "socket_base/types.h" -#include "socket.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define TCP_EOO_OPTION (0x00) /* End of option list */ -#define TCP_NOP_OPTION (0x01) /* No operation */ -#define TCP_MSS_OPTION (0x02) /* Maximum segment size */ -#define TCP_WSF_OPTION (0x03) /* Window scale factor */ -#define TCP_TS_OPTION (0x08) /* Timestamp */ - -enum tcp_flags { - TCP_FIN = (1 << 0), - TCP_SYN = (1 << 1), - TCP_RST = (1 << 2), - TCP_PSH = (1 << 3), - TCP_ACK = (1 << 4), - TCP_URG = (1 << 5), - TCP_ECE = (1 << 6), - TCP_CWR = (1 << 7), - TCP_SYN_ACK = (TCP_SYN | TCP_ACK), - TCP_URG_PSH = (TCP_URG | TCP_PSH), - TCP_FIN_ACK = (TCP_FIN | TCP_ACK) -}; - -enum tcp_states { - TCP_CLOSED = 0, - TCP_LISTEN = 1, - TCP_SYN_SENT = 2, - TCP_SYN_RCVD = 3, - TCP_ESTABLISHED = 4, - TCP_FIN_WAIT_1 = 5, - TCP_FIN_WAIT_2 = 6, - TCP_CLOSE_WAIT = 7, - TCP_CLOSING = 8, - TCP_LAST_ACK = 9, - TCP_TIME_WAIT = 10, - TCP_UNKNOWN = 11 -}; - -enum tcp_codes { - UNDEFINED = 0, - PACKET_OK = 1, - CLOSE_CONN = 2, - SEQ_NO_TOO_SMALL = 3, - ACK_NO_TOO_SMALL = 4, - ACK_NO_TOO_BIG = 5 -}; - -#define REMOVE_RESERVED (0xFC) - -#define IS_TCP_ACK(a) (((a) & TCP_ACK) == TCP_ACK) /* Test for ACK flag only, ignore URG und PSH flag */ -#define IS_TCP_RST(a) (((a) & TCP_RST) == TCP_RST) -#define IS_TCP_SYN(a) (((a) & TCP_SYN) == TCP_SYN) -#define IS_TCP_SYN_ACK(a) (((a) & TCP_SYN_ACK) == TCP_SYN_ACK) -#define IS_TCP_FIN(a) (((a) & TCP_FIN) == TCP_FIN) -#define IS_TCP_FIN_ACK(a) (((a) & TCP_FIN_ACK) == TCP_FIN_ACK) - -#define SET_TCP_ACK(a) (a) = TCP_ACK -#define SET_TCP_RST(a) (a) = TCP_RST -#define SET_TCP_SYN(a) (a) = TCP_SYN -#define SET_TCP_SYN_ACK(a) (a) = TCP_SYN_ACK -#define SET_TCP_FIN(a) (a) = TCP_FIN -#define SET_TCP_FIN_ACK(a) (a) = TCP_FIN_ACK - -#define TCP_STACK_SIZE (THREAD_STACKSIZE_MAIN) - -typedef struct __attribute__((packed)) tcp_mms_o_t { - uint8_t kind; - uint8_t len; - uint16_t mss; -} tcp_mss_option_t; - -#ifdef TCP_HC -extern mutex_t global_context_counter_mutex; -extern uint8_t global_context_counter; -#endif - -extern mutex_t global_sequence_counter_mutex; -extern uint32_t global_sequence_counter; - -/* methods usde by socket_base */ -int tcp_bind_socket(int s, sockaddr6_t *name, int namelen, uint8_t pid); -bool tcp_socket_compliancy(int s); -int32_t tcp_send(int s, const void *buf, uint32_t len, int flags); -int tcp_accept(int s, sockaddr6_t *addr, socklen_t *addrlen); -int tcp_connect(int socket, sockaddr6_t *addr, uint32_t addrlen); -int tcp_listen(int s, int backlog); -int32_t tcp_recv(int s, void *buf, uint32_t len, int flags); -bool tcp_socket_compliancy(int s); -int tcp_teardown(socket_internal_t *current_socket); - -#ifdef __cplusplus -} -#endif - -/** - * @} - */ - -#endif /* TCP_H_ */ diff --git a/sys/net/transport_layer/tcp/tcp_hc.c b/sys/net/transport_layer/tcp/tcp_hc.c deleted file mode 100644 index 03c05406c1..0000000000 --- a/sys/net/transport_layer/tcp/tcp_hc.c +++ /dev/null @@ -1,637 +0,0 @@ -/** - * TCP header compression - * - * Copyright (C) 2013 INRIA. - * - * 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 transport_layer - * @{ - * @file - * @brief TCP HC - * @author Oliver Gesch - * @} - */ - - -#include -#include -#include - -#include "ipv6.h" - -#include "net_help.h" - -#include "socket.h" -#include "tcp.h" - -#include "tcp_hc.h" - -#ifdef TCP_HC - -socket_internal_t *get_tcp_socket_by_context(ipv6_hdr_t *current_ipv6_header, - uint16_t current_context) -{ - socket_internal_t *temp_socket; - - for (int i = 1; i < MAX_SOCKETS + 1; i++) { - temp_socket = socket_base_get_socket(i); - - if ((temp_socket != NULL) && - ipv6_addr_is_equal(&temp_socket->socket_values.foreign_address.sin6_addr, - ¤t_ipv6_header->srcaddr) && - ipv6_addr_is_equal(&temp_socket->socket_values.local_address.sin6_addr, - ¤t_ipv6_header->destaddr) && - (temp_socket->socket_values.tcp_control.tcp_context.context_id == - current_context)) { - return temp_socket; - } - } - - return NULL; -} - -void update_tcp_hc_context(bool incoming, socket_internal_t *current_socket, - tcp_hdr_t *current_tcp_packet) -{ - tcp_hc_context_t *current_context = - ¤t_socket->socket_values.tcp_control.tcp_context; - - if (incoming) { - current_context->ack_rcv = current_tcp_packet->ack_nr; - current_context->seq_rcv = current_tcp_packet->seq_nr; - current_context->wnd_rcv = current_tcp_packet->window; - } - else { - current_context->ack_snd = current_tcp_packet->ack_nr; - current_context->seq_snd = current_tcp_packet->seq_nr; - current_context->wnd_snd = current_tcp_packet->window; - } -} - -uint16_t compress_tcp_packet(socket_internal_t *current_socket, - uint8_t *current_tcp_packet, - ipv6_hdr_t *temp_ipv6_header, - uint8_t flags, - uint8_t payload_length) -{ - socket_t *current_tcp_socket = ¤t_socket->socket_values; - tcp_hc_context_t *tcp_context = ¤t_tcp_socket->tcp_control.tcp_context; - tcp_cb_t *tcp_cb = ¤t_tcp_socket->tcp_control; - tcp_hdr_t full_tcp_header; - uint16_t packet_size = 0; - - /* Connection establisment phase, use FULL_HEADER TCP */ - if (tcp_context->hc_type == FULL_HEADER) { - /* draft-aayadi-6lowpan-tcphc-01: 5.1 Full header TCP segment. - * Establishing Connection */ - - /* Move tcp packet 3 bytes to add padding and Context ID */ - memmove(current_tcp_packet + 3, current_tcp_packet, - ((((tcp_hdr_t *)current_tcp_packet)->data_offset) * 4) + - payload_length); - - /* 1 padding byte with value 0x01 to introduce full header TCP_HC - * segment */ - memset(current_tcp_packet, 0x01, 1); - - /* Adding Context ID */ - uint16_t current_context = HTONS(tcp_context->context_id); - memcpy(current_tcp_packet + 1, ¤t_context, 2); - - /* Return correct header length (+3) */ - packet_size = ((((tcp_hdr_t *)(current_tcp_packet + 3))->data_offset) * 4) + 3 + - payload_length; - - /* Update the tcp context fields */ - update_tcp_hc_context(false, current_socket, (tcp_hdr_t *)(current_tcp_packet + 3)); - - /* Convert TCP packet to network byte order */ - switch_tcp_packet_byte_order((tcp_hdr_t *)(current_tcp_packet + 3)); - - return packet_size; - } - /* Check for header compression type: COMPRESSED_HEADER */ - else if (tcp_context->hc_type == COMPRESSED_HEADER) { - /* draft-aayadi-6lowpan-tcphc-01: 5.1 Compressed header TCP segment. */ - - /* Temporary variable for TCP_HC_Header Bytes */ - uint16_t tcp_hc_header = 0x0000; - - /* Save TCP_Header to refresh TCP Context values after compressing the - * packet */ - memcpy(&full_tcp_header, current_tcp_packet, TCP_HDR_LEN); - - /* Temporary variable for storing TCP header beginning */ - uint8_t *tcp_packet_begin = current_tcp_packet; - - /* Position for first TCP header value, TCP_HC_Header and Context ID */ - current_tcp_packet += 4; - - /* Packet size value */ - packet_size += 4; - - /* 5.2. LOWPAN_TCPHC Format */ - - /* First 3 bits of TCP_HC_Header are not exactly specified. In this - * implementation they are (1|1|0) * for compressed headers and the - * CID is always 16 bits (1) */ - /* (1|1|0|1) = D */ - tcp_hc_header |= 0xD000; - - /*----------------------------------*/ - /*| Sequence number handling |*/ - /*----------------------------------*/ - if (full_tcp_header.seq_nr == tcp_context->seq_snd) { - /* Nothing to do, Seq = (0|0) */ - } - /* If the 24 most significant bits haven't changed from previous - * packet, don't transmit them */ - else if ((full_tcp_header.seq_nr & 0xFFFFFF00) == (tcp_context->seq_snd & - 0xFFFFFF00)) { - /* Seq = (0|1) */ - tcp_hc_header |= 0x0400; - - /* Copy first 8 less significant bits of sequence number into - * buffer */ - *current_tcp_packet = (uint8_t)(full_tcp_header.seq_nr & 0x000000FF); - current_tcp_packet += 1; - packet_size += 1; - } - /* If the 16 most significant bits haven't changed from previous packet, - * don't transmit them */ - else if ((full_tcp_header.seq_nr & 0xFFFF0000) == (tcp_context->seq_snd & 0xFFFF0000)) { - /* Seq = (1|0) */ - tcp_hc_header |= 0x0800; - - /* Copy first 16 less significant bits of sequence number into buffer */ - *((uint16_t *)current_tcp_packet) = - HTONS((uint16_t)(full_tcp_header.seq_nr & 0x0000FFFF)); - current_tcp_packet += 2; - packet_size += 2; - } - /* Sending uncompressed sequence number */ - else { - /* Seq = (1|1) */ - tcp_hc_header |= 0x0C00; - - /* Copy all bits of sequence number into buffer */ - uint32_t cur_seq_no = HTONL(full_tcp_header.seq_nr); - memcpy(current_tcp_packet, &cur_seq_no, 4); - current_tcp_packet += 4; - packet_size += 4; - } - - /*----------------------------------*/ - /*| Acknowledgment number handling |*/ - /*----------------------------------*/ - if ((IS_TCP_ACK(full_tcp_header.reserved_flags) && - (tcp_cb->tcp_context.ack_snd == full_tcp_header.ack_nr))) { - tcp_context->ack_snd = tcp_context->seq_rcv; - } - - if (full_tcp_header.ack_nr == tcp_context->ack_snd) { - /* Nothing to do, Ack = (0|0) */ - } - /* If the 24 most significant bits haven't changed from previous packet, - * don't transmit them */ - else if ((full_tcp_header.ack_nr & 0xFFFFFF00) == (tcp_context->ack_snd & - 0xFFFFFF00)) { - /* Ack = (0|1) */ - tcp_hc_header |= 0x0100; - - /* Copy first 8 less significant bits of acknowledgment number into - * buffer */ - *current_tcp_packet = (uint8_t)(full_tcp_header.ack_nr & 0x000000FF); - current_tcp_packet += 1; - packet_size += 1; - } - /* If the 16 most significant bits haven't changed from previous packet, - * don't transmit them */ - else if ((full_tcp_header.ack_nr & 0xFFFF0000) == (tcp_context->ack_snd & - 0xFFFF0000)) { - /* Ack = (1|0) */ - tcp_hc_header |= 0x0200; - - /* Copy first 16 less significant bits of acknowledgment number - * into buffer */ - *((uint16_t *)current_tcp_packet) = - HTONS((uint16_t)(full_tcp_header.ack_nr & 0x0000FFFF)); - current_tcp_packet += 2; - packet_size += 2; - } - /* Sending uncompressed acknowledgment number */ - else { - /* Ack = (1|1) */ - tcp_hc_header |= 0x0300; - - /* Copy all bits of acknowledgment number into buffer */ - uint32_t cur_ack_nr = HTONL(full_tcp_header.ack_nr); - memcpy(current_tcp_packet, &cur_ack_nr, 4); - current_tcp_packet += 4; - packet_size += 4; - } - - /*----------------------------------*/ - /*| Window handling |*/ - /*----------------------------------*/ - if (full_tcp_header.window == tcp_context->wnd_snd) { - /* Nothing to do, Wnd = (0|0) */ - } - /* If the 8 most significant bits haven't changed from previous packet, - * don't transmit them */ - else if ((full_tcp_header.window & 0xFF00) == (tcp_context->wnd_snd & 0xFF00)) { - /* Wnd = (0|1) */ - tcp_hc_header |= 0x0040; - - /* Copy first 8 less significant bits of window size into buffer */ - *current_tcp_packet = (uint8_t)(full_tcp_header.window & 0x00FF); - current_tcp_packet += 1; - packet_size += 1; - } - /* If the 8 less significant bits haven't changed from previous packet, - * don't transmit them */ - else if ((full_tcp_header.window & 0x00FF) == (tcp_context->wnd_snd & - 0x00FF)) { - /* Wnd = (1|0) */ - tcp_hc_header |= 0x0080; - - /* Copy first 8 most significant bits of window size into buffer */ - *current_tcp_packet = (uint8_t)(full_tcp_header.window & 0xFF00); - current_tcp_packet += 1; - packet_size += 1; - } - /* Sending uncompressed window */ - else { - /* Wnd = (1|1) */ - tcp_hc_header |= 0x00C0; - - /* Copy all bits of window size into buffer */ - uint16_t cur_window = HTONS(full_tcp_header.window); - memcpy(current_tcp_packet, &cur_window, 2); - current_tcp_packet += 2; - packet_size += 2; - } - - /* FIN flag */ - if (IS_TCP_FIN(full_tcp_header.reserved_flags)) { - /* F = (1) */ - tcp_hc_header |= 0x0008; - } - - /* Copy checksum into buffer */ - uint16_t cur_chk_sum = HTONS(full_tcp_header.checksum); - memcpy(current_tcp_packet, &cur_chk_sum, 2); - current_tcp_packet += 2; - packet_size += 2; - - /* Copy TCP_HC Bytes into buffer */ - uint16_t cur_tcp_hc_header = HTONS(tcp_hc_header); - memcpy(tcp_packet_begin, &cur_tcp_hc_header, 2); - - /* Copy TCP_HC Context ID into buffer */ - uint16_t cur_context_id = HTONS(tcp_context->context_id); - memcpy(tcp_packet_begin + 2, &cur_context_id, 2); - - /* Move payload to end of tcp header */ - memmove(current_tcp_packet, tcp_packet_begin + TCP_HDR_LEN, - payload_length); - - /* Adding TCP payload length to TCP_HC header length */ - packet_size += payload_length; - - update_tcp_hc_context(false, current_socket, &full_tcp_header); - - return packet_size; - } - /* Check for header compression type: MOSTLY_COMPRESSED_HEADER */ - else if (tcp_context->hc_type == MOSTLY_COMPRESSED_HEADER) { - /* draft-aayadi-6lowpan-tcphc-01: 5.1 Compressed header TCP segment. */ - - /* Temporary variable for TCP_HC_Header Bytes */ - uint16_t tcp_hc_header = 0x0000; - - /* Save TCP_Header to refresh TCP Context values after compressing the - * packet */ - memcpy(&full_tcp_header, current_tcp_packet, TCP_HDR_LEN); - - /* Temporary variable for storing TCP header beginning */ - uint8_t *tcp_packet_begin = current_tcp_packet; - - /* Position for first TCP header value, TCP_HC_Header and Context ID */ - current_tcp_packet += 4; - - /* Packet size value */ - packet_size += 4; - - /* 5.2. LOWPAN_TCPHC Format */ - - /* First 3 bits of TCP_HC_Header are not exactly specified. In this - * implementation they are (1|0|0) for mostly compressed headers and - * the CID is always 16 bits (1) */ - /* (1|0|0|1) = 9 */ - tcp_hc_header |= 0x9000; - - /*----------------------------------*/ - /*| Sequence number handling |*/ - /*----------------------------------*/ - /* Sending uncompressed sequence number */ - /* Seq = (1|1) */ - tcp_hc_header |= 0x0C00; - - /* Copy all bits of sequence number into buffer */ - uint32_t cur_seq_no = HTONL(full_tcp_header.seq_nr); - memcpy(current_tcp_packet, &cur_seq_no, 4); - current_tcp_packet += 4; - packet_size += 4; - - /*----------------------------------*/ - /*| Acknowledgment number handling |*/ - /*----------------------------------*/ - /* Ack = (1|1) */ - tcp_hc_header |= 0x0300; - - /* Copy all bits of acknowledgment number into buffer */ - uint32_t cur_ack_nr = HTONL(full_tcp_header.ack_nr); - memcpy(current_tcp_packet, &cur_ack_nr, 4); - current_tcp_packet += 4; - packet_size += 4; - - /*----------------------------------*/ - /*| Window handling |*/ - /*----------------------------------*/ - /* Wnd = (1|1) */ - tcp_hc_header |= 0x00C0; - - /* Copy all bits of window size into buffer */ - uint16_t cur_window = HTONS(full_tcp_header.window); - memcpy(current_tcp_packet, &cur_window, 2); - current_tcp_packet += 2; - packet_size += 2; - - /* FIN flag */ - if (IS_TCP_FIN(full_tcp_header.reserved_flags)) { - /* F = (1) */ - tcp_hc_header |= 0x0008; - } - - /* Copy checksum into buffer */ - uint16_t cur_chk_sum = HTONS(full_tcp_header.checksum); - memcpy(current_tcp_packet, &cur_chk_sum, 2); - current_tcp_packet += 2; - packet_size += 2; - - /* Copy TCP_HC Bytes into buffer */ - uint16_t cur_tcp_hc_header = HTONS(tcp_hc_header); - memcpy(tcp_packet_begin, &cur_tcp_hc_header, 2); - - /* Copy TCP_HC Context ID into buffer */ - uint16_t cur_context_id = HTONS(tcp_context->context_id); - memcpy(tcp_packet_begin + 2, &cur_context_id, 2); - - /* Move payload to end of tcp header */ - memmove(current_tcp_packet, tcp_packet_begin + TCP_HDR_LEN, - payload_length); - - /* Adding TCP payload length to TCP_HC header length */ - packet_size += payload_length; - - update_tcp_hc_context(false, current_socket, &full_tcp_header); - return packet_size; - } - - return 0; -} - -socket_internal_t *decompress_tcp_packet(ipv6_hdr_t *temp_ipv6_header) -{ - uint8_t *packet_buffer = ((uint8_t *)temp_ipv6_header) + IPV6_HDR_LEN; - uint16_t tcp_hc_header; - socket_internal_t *current_socket = NULL; - - /* Full header TCP segment */ - if (*(((uint8_t *)temp_ipv6_header) + IPV6_HDR_LEN) == 0x01) { - switch_tcp_packet_byte_order(((tcp_hdr_t *)(((uint8_t *)temp_ipv6_header) + - IPV6_HDR_LEN + 3))); - current_socket = get_tcp_socket(temp_ipv6_header, - ((tcp_hdr_t *)(((uint8_t *)temp_ipv6_header) + - IPV6_HDR_LEN + 3))); - - if (current_socket != NULL) { - if (current_socket->socket_values.tcp_control.state == LISTEN) { - memcpy(¤t_socket->socket_values.tcp_control.tcp_context.context_id, - ((uint8_t *)temp_ipv6_header) + IPV6_HDR_LEN + 1, 2); - current_socket->socket_values.tcp_control.tcp_context.context_id = - NTOHS(current_socket->socket_values.tcp_control.tcp_context.context_id); - } - - memmove(((uint8_t *)temp_ipv6_header) + IPV6_HDR_LEN, - (((uint8_t *)temp_ipv6_header) + IPV6_HDR_LEN + 3), - temp_ipv6_header->length - 3); - temp_ipv6_header->length -= 3; - return current_socket; - } - else { - printf("Socket Null!\n"); - /* Found no matching socket for this packet -> Drop it */ - return NULL; - } - } - /* Compressed header TCP segment */ - else { - uint16_t packet_size = 0; - - /* Temporary TCP Header */ - tcp_hdr_t full_tcp_header; - memset(&full_tcp_header, 0, sizeof(tcp_hdr_t)); - - /* Current context ID */ - uint16_t current_context; - memcpy(¤t_context, (packet_buffer + 2), 2); - current_context = NTOHS(current_context); - - /* Copy TCP_HC header into local variable - * (1,0,0,1|SEQ,SEQ,0)(1,0,0,1|0,0,0,0) */ - memcpy(&tcp_hc_header, packet_buffer, 2); - tcp_hc_header = NTOHS(tcp_hc_header); - - uint8_t header_type = UNDEFINED; - - if (BITSET(tcp_hc_header, 15) && !BITSET(tcp_hc_header, 14) && - !BITSET(tcp_hc_header, 13)) { - header_type = MOSTLY_COMPRESSED_HEADER; - } - else if (BITSET(tcp_hc_header, 15) && BITSET(tcp_hc_header, 14) && - !BITSET(tcp_hc_header, 13)) { - header_type = COMPRESSED_HEADER; - } - - /* Setting pointer to first tcp_hc field */ - packet_buffer += 4; - packet_size += 4; - - /* Current socket */ - socket_internal_t *current_socket = - get_tcp_socket_by_context(temp_ipv6_header, current_context); - - if (current_socket == NULL) { - printf("Current Socket == NULL!\n"); - return NULL; - } - - /* Current TCP Context values */ - tcp_hc_context_t *current_tcp_context = - ¤t_socket->socket_values.tcp_control.tcp_context; - - /*----------------------------------*/ - /*| Sequence number handling |*/ - /*----------------------------------*/ - if (!BITSET(tcp_hc_header, 11) && !BITSET(tcp_hc_header, 10)) { - /* Seq = (0|0), sequence number didn't change, copy old value */ - memcpy(&full_tcp_header.seq_nr, ¤t_tcp_context->seq_rcv, 4); - } - /* The 24 most significant bits haven't changed from previous packet */ - 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 - * previous packet */ - full_tcp_header.seq_nr |= *packet_buffer; - full_tcp_header.seq_nr |= ((current_tcp_context->seq_rcv) & - 0xFFFFFF00); - packet_buffer += 1; - packet_size += 1; - } - /* If the 16 most significant bits haven't changed from previous packet */ - 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 - * previous packet */ - full_tcp_header.seq_nr |= NTOHS(*((uint16_t *)packet_buffer)); - full_tcp_header.seq_nr |= ((current_tcp_context->seq_rcv) & 0xFFFF0000); - packet_buffer += 2; - packet_size += 2; - } - /* Sending uncompressed sequence number */ - else { - /* Seq = (1|1), copy 4 bytes of tcp_hc packet */ - memcpy(&full_tcp_header.seq_nr, packet_buffer, 4); - full_tcp_header.seq_nr = NTOHL(full_tcp_header.seq_nr); - packet_buffer += 4; - packet_size += 4; - } - - /*----------------------------------*/ - /*| Acknowledgment number handling |*/ - /*----------------------------------*/ - if (!BITSET(tcp_hc_header, 9) && !BITSET(tcp_hc_header, 8)) { - /* Ack = (0|0), acknowledgment number didn't change, copy old value */ - memcpy(&full_tcp_header.ack_nr, ¤t_tcp_context->ack_rcv, 4); - } - /* The 24 most significant bits haven't changed from previous packet */ - 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 - * previous packet */ - full_tcp_header.ack_nr |= *packet_buffer; - full_tcp_header.ack_nr |= ((current_tcp_context->ack_rcv) & 0xFFFFFF00); - packet_buffer += 1; - packet_size += 1; - SET_TCP_ACK(full_tcp_header.reserved_flags); - } - /* If the 16 most significant bits haven't changed from previous packet */ - 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 - * previous packet */ - full_tcp_header.ack_nr |= NTOHS(*((uint16_t *)packet_buffer)); - full_tcp_header.ack_nr |= ((current_tcp_context->ack_rcv) & 0xFFFF0000); - packet_buffer += 2; - packet_size += 2; - SET_TCP_ACK(full_tcp_header.reserved_flags); - } - /* Sending uncompressed acknowledgment number */ - else { - /* Ack = (1|1), copy 4 bytes of tcp_hc packet */ - memcpy(&full_tcp_header.ack_nr, packet_buffer, 4); - full_tcp_header.ack_nr = NTOHL(full_tcp_header.ack_nr); - packet_buffer += 4; - packet_size += 4; - - if (header_type == COMPRESSED_HEADER) { - SET_TCP_ACK(full_tcp_header.reserved_flags); - } - } - - /*----------------------------------*/ - /*| Window handling |*/ - /*----------------------------------*/ - if (!BITSET(tcp_hc_header, 7) && !BITSET(tcp_hc_header, 6)) { - /* Wnd = (0|0), copy old value */ - memcpy(&full_tcp_header.window, ¤t_tcp_context->wnd_rcv, 2); - } - /* The 8 most significant bits haven't changed from previous packet */ - 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 - * previous packet */ - full_tcp_header.window |= *packet_buffer; - full_tcp_header.window |= ((current_tcp_context->wnd_rcv) & 0xFF00); - packet_buffer += 1; - packet_size += 1; - } - /* If the 8 less significant bits haven't changed from previous packet */ - 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 */ - full_tcp_header.window |= ((*((uint16_t *)packet_buffer)) & 0xFF00); - full_tcp_header.window |= ((current_tcp_context->wnd_rcv) & 0x00FF); - packet_buffer += 1; - packet_size += 1; - } - /* Sending uncompressed window size */ - else { - /* Wnd = (1|1), copy 2 bytes of tcp_hc packet */ - memcpy(&full_tcp_header.window, packet_buffer, 2); - full_tcp_header.window = NTOHS(full_tcp_header.window); - packet_buffer += 2; - packet_size += 2; - } - - /* FIN flag */ - if (BITSET(tcp_hc_header, 3)) { - /* F = (1) */ - if (IS_TCP_ACK(full_tcp_header.reserved_flags)) { - SET_TCP_FIN_ACK(full_tcp_header.reserved_flags); - } - else { - SET_TCP_FIN(full_tcp_header.reserved_flags); - } - } - - /* Copy checksum into into tcp header */ - memcpy(&full_tcp_header.checksum, packet_buffer, 2); - full_tcp_header.checksum = NTOHS(full_tcp_header.checksum); - packet_buffer += 2; - packet_size += 2; - - /* Copy dest. and src. port into tcp header */ - memcpy(&full_tcp_header.dst_port, - ¤t_socket->socket_values.local_address.sin6_port, 2); - memcpy(&full_tcp_header.src_port, - ¤t_socket->socket_values.foreign_address.sin6_port, 2); - - /* Ordinary TCP header length */ - full_tcp_header.data_offset = TCP_HDR_LEN / 4; - - /* Move payload to end of tcp header */ - memmove(((uint8_t *)temp_ipv6_header) + IPV6_HDR_LEN + TCP_HDR_LEN, - packet_buffer, temp_ipv6_header->length - packet_size); - - /* Copy TCP uncompressed header in front of payload */ - memcpy(((uint8_t *)temp_ipv6_header) + IPV6_HDR_LEN, &full_tcp_header, - TCP_HDR_LEN); - - /* Set IPV6 header length */ - temp_ipv6_header->length = temp_ipv6_header->length - packet_size + - TCP_HDR_LEN; - return current_socket; - } -} - -#endif diff --git a/sys/net/transport_layer/tcp/tcp_hc.h b/sys/net/transport_layer/tcp/tcp_hc.h deleted file mode 100644 index 4eb6e71ae0..0000000000 --- a/sys/net/transport_layer/tcp/tcp_hc.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2013 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. - */ - -/** - * @{ - * @file - * @author Oliver Gesch - */ -#ifndef TCP_HC_H_ -#define TCP_HC_H_ - -#include "sixlowpan.h" - -#include "socket_base/socket.h" - -#include "tcp.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef TCP_HC - -#define FULL_HEADER 1 -#define MOSTLY_COMPRESSED_HEADER 2 -#define COMPRESSED_HEADER 3 - -void update_tcp_hc_context(bool incoming, socket_internal_t *current_socket, tcp_hdr_t *current_tcp_packet); -uint16_t compress_tcp_packet(socket_internal_t *current_socket, uint8_t *current_tcp_packet, ipv6_hdr_t *temp_ipv6_header, uint8_t flags, uint8_t payload_length); -socket_internal_t *decompress_tcp_packet(ipv6_hdr_t *temp_ipv6_header); -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* TCP_HC_H_ */ -/** - * @} - */ diff --git a/sys/net/transport_layer/tcp/tcp_timer.c b/sys/net/transport_layer/tcp/tcp_timer.c deleted file mode 100644 index c60414c8fb..0000000000 --- a/sys/net/transport_layer/tcp/tcp_timer.c +++ /dev/null @@ -1,156 +0,0 @@ -/** - * TCP timer implementation - * - * Copyright (C) 2013 INRIA. - * - * 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 transport_layer - * @{ - * @file - * @brief TCP timer - * @author Oliver Gesch - * @} - */ - -#include -#include -#include - -#include "sixlowpan.h" -#include "thread.h" -#include "vtimer.h" - -#include "msg_help.h" -#include "socket.h" - -#include "tcp.h" -#include "tcp_timer.h" - -void handle_synchro_timeout(socket_internal_t *current_socket) -{ - msg_t send; - - if (thread_getstatus(current_socket->recv_pid) == STATUS_RECEIVE_BLOCKED) { - timex_t now; - vtimer_now(&now); - - if ((current_socket->socket_values.tcp_control.no_of_retries == 0) && - (timex_uint64(timex_sub(now, current_socket->socket_values.tcp_control.last_packet_time)) > TCP_SYN_INITIAL_TIMEOUT)) { - current_socket->socket_values.tcp_control.no_of_retries++; - socket_base_net_msg_send(&send, current_socket->recv_pid, 0, TCP_RETRY); - } - else if ((current_socket->socket_values.tcp_control.no_of_retries > 0) && - (timex_uint64(timex_sub(now, current_socket->socket_values.tcp_control.last_packet_time)) > - (current_socket->socket_values.tcp_control.no_of_retries * - TCP_SYN_TIMEOUT + TCP_SYN_INITIAL_TIMEOUT))) { - current_socket->socket_values.tcp_control.no_of_retries++; - - if (current_socket->socket_values.tcp_control.no_of_retries > - TCP_MAX_SYN_RETRIES) { - socket_base_net_msg_send(&send, current_socket->recv_pid, 0, TCP_TIMEOUT); - } - else { - socket_base_net_msg_send(&send, current_socket->recv_pid, 0, TCP_RETRY); - } - } - } -} - -void handle_established(socket_internal_t *current_socket) -{ - msg_t send; - double current_timeout = current_socket->socket_values.tcp_control.rto; - - if (current_timeout < SECOND) { - current_timeout = SECOND; - } - - - if ((current_socket->socket_values.tcp_control.send_nxt > - current_socket->socket_values.tcp_control.send_una) && - (thread_getstatus(current_socket->send_pid) == STATUS_RECEIVE_BLOCKED)) { - for (uint8_t i = 0; i < current_socket->socket_values.tcp_control.no_of_retries; - i++) { - current_timeout *= 2; - } - - timex_t now; - vtimer_now(&now); - - if (current_timeout > TCP_ACK_MAX_TIMEOUT) { - socket_base_net_msg_send(&send, current_socket->send_pid, 0, TCP_TIMEOUT); - } - else if (timex_uint64(timex_sub(now, current_socket->socket_values.tcp_control.last_packet_time)) > - current_timeout) { - current_socket->socket_values.tcp_control.no_of_retries++; - socket_base_net_msg_send(&send, current_socket->send_pid, 0, TCP_RETRY); - } - } -} - -void check_sockets(void) -{ - uint8_t i = 1; - - while (i < MAX_SOCKETS + 1) { - socket_internal_t *current_socket = socket_base_get_socket(i); - - if (tcp_socket_compliancy(i)) { - switch (current_socket->socket_values.tcp_control.state) { - case TCP_ESTABLISHED: { - handle_established(current_socket); - break; - } - - case TCP_SYN_SENT: { - handle_synchro_timeout(current_socket); - break; - } - - case TCP_SYN_RCVD: { - handle_synchro_timeout(current_socket); - break; - } - - default: { - break; - } - } - } - - i++; - } -} - -void inc_global_variables(void) -{ - mutex_lock(&global_sequence_counter_mutex); - global_sequence_counter += rand(); - mutex_unlock(&global_sequence_counter_mutex); -#ifdef TCP_HC - mutex_lock(&global_context_counter_mutex); - global_context_counter += rand(); - mutex_unlock(&global_context_counter_mutex); -#endif -} - -void *tcp_general_timer(void *arg) -{ - (void) arg; - - vtimer_t tcp_vtimer; - timex_t interval = timex_set(0, TCP_TIMER_RESOLUTION); - - while (1) { - inc_global_variables(); - check_sockets(); - - vtimer_set_wakeup(&tcp_vtimer, interval, thread_getpid()); - thread_sleep(); - - vtimer_remove(&tcp_vtimer); - } -} diff --git a/sys/net/transport_layer/tcp/tcp_timer.h b/sys/net/transport_layer/tcp/tcp_timer.h deleted file mode 100644 index ec65eb722b..0000000000 --- a/sys/net/transport_layer/tcp/tcp_timer.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2013 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. - */ - -/** - * @{ - * @file - * @author Oliver Gesch - */ - -#ifndef TCP_TIMER_H_ -#define TCP_TIMER_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#define TCP_TIMER_RESOLUTION 500*1000 - -#define SECOND 1000.0f*1000.0f -#define TCP_TIMER_STACKSIZE THREAD_STACKSIZE_DEFAULT -#define TCP_SYN_INITIAL_TIMEOUT 6*SECOND -#define TCP_SYN_TIMEOUT 24*SECOND -#define TCP_MAX_SYN_RETRIES 3 -#define TCP_INITIAL_ACK_TIMEOUT 3.0f*SECOND // still static, should be calculated via RTT -#define TCP_ACK_MAX_TIMEOUT 30*SECOND // TODO: Set back to 90 Seconds - -#define TCP_ALPHA 1.0f/8.0f -#define TCP_BETA 1.0f/4.0f - -#define TCP_NOT_DEFINED 0 -#define TCP_RETRY 1 -#define TCP_TIMEOUT 2 -#define TCP_CONTINUE 3 - -void *tcp_general_timer(void *); - -#ifdef __cplusplus -} -#endif - -#endif /* TCP_TIMER_H_ */ -/** - * @} - */ diff --git a/sys/net/transport_layer/udp/Makefile b/sys/net/transport_layer/udp/Makefile deleted file mode 100644 index 8978e06912..0000000000 --- a/sys/net/transport_layer/udp/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -INCLUDES += -I $(RIOTBASE)/sys/net/transport_layer/socket_base -include $(RIOTBASE)/Makefile.base diff --git a/sys/net/transport_layer/udp/udp.c b/sys/net/transport_layer/udp/udp.c deleted file mode 100644 index bdb27ff5e2..0000000000 --- a/sys/net/transport_layer/udp/udp.c +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright (C) 2013, 2014 INRIA. - * - * 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 udp - * @{ - * @file - * @brief UDP implementation - * @author Oliver Gesch - * @author Cenk GündoÄŸan - * @} - */ - -#include -#include - -#include "ipv6.h" -#include "msg.h" -#include "sixlowpan.h" -#include "thread.h" - -#include "socket_base/in.h" - -#include "net_help.h" - -#include "msg_help.h" -#include "socket.h" - -#include "udp.h" - -msg_t udp_msg_queue[UDP_PKT_RECV_BUF_SIZE]; - -char udp_stack_buffer[UDP_STACK_SIZE]; - -socket_internal_t *get_udp_socket(udp_hdr_t *udp_header) -{ - uint8_t i = 1; - - while (i < MAX_SOCKETS + 1) { - if (udp_socket_compliancy(i) && - (socket_base_get_socket(i)->socket_values.local_address.sin6_port == - udp_header->dst_port)) { - return socket_base_get_socket(i); - } - - i++; - } - - return NULL; -} - -void *udp_packet_handler(void *arg) -{ - (void) arg; - - msg_t m_recv_ip, m_send_ip, m_recv_udp, m_send_udp; - socket_internal_t *udp_socket = NULL; - - msg_init_queue(udp_msg_queue, UDP_PKT_RECV_BUF_SIZE); - - while (1) { - msg_receive(&m_recv_ip); - ipv6_hdr_t *ipv6_header = ((ipv6_hdr_t *)m_recv_ip.content.ptr); - udp_hdr_t *udp_header = ((udp_hdr_t *)(m_recv_ip.content.ptr + IPV6_HDR_LEN)); - - uint16_t chksum = ipv6_csum(ipv6_header, (uint8_t*) udp_header, NTOHS(udp_header->length), IPPROTO_UDP); - - if (chksum == 0xffff) { - udp_socket = get_udp_socket(udp_header); - - if (udp_socket != NULL) { - m_send_udp.content.ptr = (char *)ipv6_header; - - msg_send_receive(&m_send_udp, &m_recv_udp, udp_socket->recv_pid); - } - else { - printf("Dropped UDP Message because no thread ID was found for delivery!\n"); - } - } - else { - printf("Wrong checksum (%x)!\n", chksum); - } - - msg_reply(&m_recv_ip, &m_send_ip); - } -} - -bool udp_socket_compliancy(int s) -{ - if ((socket_base_exists_socket(s)) && - (socket_base_get_socket(s)->socket_values.domain == PF_INET6) && - (socket_base_get_socket(s)->socket_values.type == SOCK_DGRAM) && - ((socket_base_get_socket(s)->socket_values.protocol == IPPROTO_UDP) || - (socket_base_get_socket(s)->socket_values.protocol == 0))) { - return true; - } - else { - return false; - } -} - -int udp_bind_socket(int s, sockaddr6_t *name, int namelen, uint8_t pid) -{ - int i; - - if (!socket_base_exists_socket(s)) { - return -1; - } - - for (i = 1; i < MAX_SOCKETS + 1; i++) { - if (udp_socket_compliancy(i) && - (socket_base_get_socket(i)->socket_values.local_address.sin6_port == name->sin6_port)) { - return -1; - } - } - - memcpy(&socket_base_get_socket(s)->socket_values.local_address, name, namelen); - socket_base_get_socket(s)->recv_pid = pid; - return 0; -} - -int32_t udp_recvfrom(int s, void *buf, uint32_t len, int flags, sockaddr6_t *from, uint32_t *fromlen) -{ - (void) flags; - - msg_t m_recv, m_send; - ipv6_hdr_t *ipv6_header; - udp_hdr_t *udp_header; - uint8_t *payload; - socket_base_get_socket(s)->recv_pid = thread_getpid(); - - msg_receive(&m_recv); - - ipv6_header = ((ipv6_hdr_t *)m_recv.content.ptr); - udp_header = ((udp_hdr_t *)(m_recv.content.ptr + IPV6_HDR_LEN)); - payload = (uint8_t *)(m_recv.content.ptr + IPV6_HDR_LEN + UDP_HDR_LEN); - - memset(buf, 0, len); - /* cppcheck: the memset sets parts of the buffer to 0 even though it will - * be overwritten by the next memcpy. However without the memset the buffer - * could contain stale data (if the copied data is less then the buffer - * length) and setting just the left over part of the buffer to 0 would - * introduce overhead (calculation how much needs to be zeroed). - */ - /* cppcheck-suppress redundantCopy */ - memcpy(buf, payload, NTOHS(udp_header->length) - UDP_HDR_LEN); - memcpy(&from->sin6_addr, &ipv6_header->srcaddr, 16); - from->sin6_family = AF_INET6; - from->sin6_flowinfo = 0; - from->sin6_port = udp_header->src_port; - *fromlen = sizeof(sockaddr6_t); - - msg_reply(&m_recv, &m_send); - return NTOHS(udp_header->length) - UDP_HDR_LEN; -} - -int32_t udp_sendto(int s, const void *buf, uint32_t len, int flags, - sockaddr6_t *to, uint32_t tolen) -{ - (void) flags; - (void) tolen; - - if (udp_socket_compliancy(s) && - (socket_base_get_socket(s)->socket_values.foreign_address.sin6_port == 0)) { - uint8_t send_buffer[BUFFER_SIZE]; - - ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t *)(&send_buffer)); - udp_hdr_t *current_udp_packet = ((udp_hdr_t *)(&send_buffer[IPV6_HDR_LEN])); - uint8_t *payload = &send_buffer[IPV6_HDR_LEN + UDP_HDR_LEN]; - - memcpy(&(temp_ipv6_header->destaddr), &to->sin6_addr, 16); - ipv6_net_if_get_best_src_addr(&(temp_ipv6_header->srcaddr), &(temp_ipv6_header->destaddr)); - - current_udp_packet->src_port = socket_base_get_free_source_port(IPPROTO_UDP); - current_udp_packet->dst_port = to->sin6_port; - current_udp_packet->checksum = 0; - - memcpy(payload, buf, len); - current_udp_packet->length = HTONS(UDP_HDR_LEN + len); - temp_ipv6_header->length = UDP_HDR_LEN + len; - - current_udp_packet->checksum = ~ipv6_csum(temp_ipv6_header, - (uint8_t *) current_udp_packet, - UDP_HDR_LEN + len, - IPPROTO_UDP); - - return ipv6_sendto(&to->sin6_addr, IPPROTO_UDP, - (uint8_t *)(current_udp_packet), - NTOHS(current_udp_packet->length), NULL); - } - else { - return -1; - } -} - -int udp_init_transport_layer(void) -{ - printf("Initializing transport layer protocol: udp\n"); - /* SOCKETS */ - memset(socket_base_sockets, 0, MAX_SOCKETS * sizeof(socket_internal_t)); - - int udp_thread_pid = thread_create(udp_stack_buffer, UDP_STACK_SIZE, THREAD_PRIORITY_MAIN, - CREATE_STACKTEST, udp_packet_handler, NULL, "udp_packet_handler"); - - if (udp_thread_pid < 0) { - return -1; - } - - ipv6_register_next_header_handler(IPV6_PROTO_NUM_UDP, udp_thread_pid); - - return 0; -} diff --git a/sys/net/transport_layer/udp/udp.h b/sys/net/transport_layer/udp/udp.h deleted file mode 100644 index 52a9c4f94b..0000000000 --- a/sys/net/transport_layer/udp/udp.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2013 INRIA - * 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 transport_layer - * @{ - * - * @file - * @brief UDP data structs and prototypes - * - * @author Oliver Gesch - * @author Hauke Petersen - */ - - -#ifndef UDP_H_ -#define UDP_H_ - -#include "ipv6.h" -#include "socket_base/types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Stack size used for the UDP thread - */ -#define UDP_STACK_SIZE THREAD_STACKSIZE_MAIN - -/** - * @brief Size of the UDP receive buffer - */ -#define UDP_PKT_RECV_BUF_SIZE (64) - -/** - * @brief Bind a UDP socket to a given port - * - * @note The name parameter needs to be generalized - * - * @param[in] s socket identifier - * @param[in] name address struct defining the port - * @param[in] namelen the length of the address struct - * @param[in] pid PID of the UDP thread - * - * @return 0 on success - * @return -1 on error - */ -int udp_bind_socket(int s, sockaddr6_t *name, int namelen, uint8_t pid); - -/** - * @brief Receive data via UDP from a given socket - * - * @param[in] s socket identifier - * @param[out] buf buffer to write the received data into - * @param[in] len the maximum number of bytes that fit into the buffer - * @param[in] flags UDP socket flags - * @param[in] from the UDP packets source address - * @param[in] fromlen length of the source address struct - * - * @return the number of bytes that were received - */ -int32_t udp_recvfrom(int s, void *buf, uint32_t len, int flags, - sockaddr6_t *from, uint32_t *fromlen); - -/** - * @brief Send data via UDP to a given address - * - * @param[in] s socket identifier - * @param[in] buf buffer that contains the data to be send - * @param[in] len number of bytes to send - * @param[in] flags UDP socket flags - * @param[in] to the destination address - * @param[in] tolen size of the destination address struct - * - * @return the number of bytes that were sent - */ -int32_t udp_sendto(int s, const void *buf, uint32_t len, int flags, - sockaddr6_t *to, socklen_t tolen); - -/** - * @brief Check if the given socket is a valid UDP socket - * - * @note This functions should be generalized to work also for non IPv6 configurations - * - * @param[in] s socket identifier - * - * @return true if socket is valid - * @return false if socket is not valid - */ -bool udp_socket_compliancy(int s); - -#ifdef __cplusplus -} -#endif - -#endif /* UDP_H_ */ -/** @} */ diff --git a/sys/shell/commands/Makefile b/sys/shell/commands/Makefile index 911b018647..02968ca51d 100644 --- a/sys/shell/commands/Makefile +++ b/sys/shell/commands/Makefile @@ -5,20 +5,6 @@ SRC = shell_commands.c sc_sys.c ifneq (,$(filter config,$(USEMODULE))) SRC += sc_id.c endif -ifneq (,$(filter transceiver,$(USEMODULE))) - SRC += sc_transceiver.c -endif -ifneq (,$(filter cc110x_legacy_csma,$(USEMODULE))) - ifeq (,$(filter transceiver,$(USEMODULE))) - SRC += sc_cc110x_legacy_csma.c - endif -endif -ifneq (,$(filter l2_ping,$(USEMODULE))) - SRC += sc_l2_ping.c -endif -ifneq (,$(filter net_if,$(USEMODULE))) - SRC += sc_net_if.c -endif ifneq (,$(filter mci,$(USEMODULE))) SRC += sc_disk.c endif @@ -28,9 +14,6 @@ endif ifneq (,$(filter ps,$(USEMODULE))) SRC += sc_ps.c endif -ifneq (,$(filter rpl,$(USEMODULE))) - SRC += sc_rpl.c -endif ifneq (,$(filter sht11,$(USEMODULE))) SRC += sc_sht11.c endif diff --git a/sys/shell/commands/sc_cc110x_legacy_csma.c b/sys/shell/commands/sc_cc110x_legacy_csma.c deleted file mode 100644 index 40b4025b6e..0000000000 --- a/sys/shell/commands/sc_cc110x_legacy_csma.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2013 INRIA. - * - * 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 sys_shell_commands - * @{ - * - * @file - * @brief Provides shell commands to configure the cc110x driver - * - * @author Oliver Hahm - * @author Ludwig Ortmann - * - * @} - */ - -#include -#include -#include - -#include "cc110x_legacy_csma.h" - - -int _cc110x_get_set_address_handler(int argc, char **argv) -{ - if (argc > 1) { - int16_t a = atoi(argv[1]); - - printf("[cc110x] Setting address %i ... ", a); - cc1100_set_address((radio_address_t)a); - - if (cc1100_get_address() == (radio_address_t)a) { - puts("[OK]"); - - return 0; - } - else { - puts("Error!"); - - return 1; - } - } - else { - printf("[cc1100] Got address: %i\n", cc1100_get_address()); - - return 0; - } -} - -int _cc110x_get_set_channel_handler(int argc, char **argv) -{ - if (argc > 1) { - int16_t a = atoi(argv[1]); - - printf("[cc110x] Setting channel %i...", a); - cc1100_set_channel(a); - - if (cc1100_get_channel() == a) { - puts("OK"); - - return 0; - } - else { - puts("Error!"); - - return 1; - } - } - else { - printf("[cc1100] Got address: %i\n", cc1100_get_channel()); - - return 0; - } -} diff --git a/sys/shell/commands/sc_l2_ping.c b/sys/shell/commands/sc_l2_ping.c deleted file mode 100644 index 844ecc70e6..0000000000 --- a/sys/shell/commands/sc_l2_ping.c +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (C) 2014, INRIA - * - * 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 sys_shell_commands - * @{ - * - * @file - * @brief Provides shell commands to use link layer ping functionality - * - * @author Oliver Hahm - * - * @} - */ - -#include -#include -#include -#include - -#include "l2_ping.h" -#include "transceiver.h" -#include "timex.h" -#include "vtimer.h" - -int _l2_ping_req_handler(int argc, char **argv) -{ - size_t payload_strlen; - uint16_t count = 5; - timex_t start, end, period; - - if (transceiver_pid == KERNEL_PID_UNDEF) { - puts("Transceiver not initialized"); - return 1; - } - if (argc < 2) { - printf("Usage:\t%s [COUNT] [MSG]\n", argv[0]); - return 1; - } - - char l2_payload[L2_PING_PAYLOAD_SIZE]; - if (argc > 3) { - payload_strlen = strlen(argv[3]); - if (payload_strlen > L2_PING_PAYLOAD_SIZE) { - printf("[l2_ping] Your input is too long and will be truncated to \"%.*s\".\n", L2_PING_PAYLOAD_SIZE, argv[3]); - payload_strlen = L2_PING_PAYLOAD_SIZE; - } - memset(l2_payload, 0, L2_PING_PAYLOAD_SIZE); - strncpy(l2_payload, argv[3], payload_strlen); - } - else { - payload_strlen = 0; - } - - if (argc > 2) { - count = atoi(argv[2]); - } - - printf("[l2_ping] Send %" PRIu8 " ping requests to %" PRIu16 " with interval %" PRIu32 ".%" PRIu32 "s and payload %s\n", - count, atoi(argv[1]), - timex_from_uint64(L2_PING_DEFAULT_INTERVAL).seconds, - timex_from_uint64(L2_PING_DEFAULT_INTERVAL).microseconds, - (argc > 3) ? l2_payload : "NULL"); - vtimer_now(&start); - l2_ping((radio_address_t) atoi(argv[1]), count, L2_PING_DEFAULT_INTERVAL, - l2_payload, payload_strlen, 0); - vtimer_now(&end); - period = timex_sub(end, start); - - printf(" --- ping statistics for host %" PRIu16 " ---\n", l2_ping_stats.dst); - printf(" %" PRIu16 " packets transmitted, %" PRIu16 " received, %" PRIu16 "%% packet loss, time %" PRIu32 ".%06" PRIu32 "s\n", - l2_ping_stats.ping_count, - l2_ping_stats.pong_count, - 100 - ((l2_ping_stats.pong_count * 100) / l2_ping_stats.ping_count), - period.seconds, - period.microseconds); - printf(" rtt min/avg/max = %" PRIu32 ".%06" PRIu32 "/%" PRIu32 ".%06" PRIu32 "/%" PRIu32 ".%06" PRIu32 " s\n", - l2_ping_stats.min_rtt.seconds, l2_ping_stats.min_rtt.microseconds, - l2_ping_stats.avg_rtt.seconds, l2_ping_stats.avg_rtt.microseconds, - l2_ping_stats.max_rtt.seconds, l2_ping_stats.max_rtt.microseconds); - - return 0; -} - -int _l2_ping_probe_handler(int argc, char **argv) -{ - size_t payload_strlen; - uint16_t count = 5; - timex_t start, end, period; - - if (transceiver_pid == KERNEL_PID_UNDEF) { - puts("Transceiver not initialized"); - return 1; - } - if (argc < 2) { - printf("Usage:\t%s [COUNT] [MSG]\n", argv[0]); - return 1; - } - - char l2_payload[L2_PING_PAYLOAD_SIZE]; - if (argc > 3) { - payload_strlen = strlen(argv[3]); - if (payload_strlen > L2_PING_PAYLOAD_SIZE) { - printf("[l2_ping] Your input is too long and will be truncated to \"%.*s\".\n", L2_PING_PAYLOAD_SIZE, argv[3]); - payload_strlen = L2_PING_PAYLOAD_SIZE; - } - memset(l2_payload, 0, L2_PING_PAYLOAD_SIZE); - strncpy(l2_payload, argv[3], payload_strlen); - } - else { - payload_strlen = 0; - } - - if (argc > 2) { - count = atoi(argv[2]); - } - - printf("[l2_ping] Send %" PRIu16 " probes to %" PRIu16 " with interval %u and payload %s\n", - count, atoi(argv[1]), L2_PING_DEFAULT_INTERVAL, (argc > 3) ? l2_payload : "NULL"); - vtimer_now(&start); - l2_ping((radio_address_t) atoi(argv[1]), count, L2_PING_DEFAULT_INTERVAL, - l2_payload, payload_strlen, 1); - vtimer_now(&end); - period = timex_sub(end, start); - - printf(" --- ping statistics for host %" PRIu16 " ---\n", l2_ping_stats.dst); - printf(" %" PRIu16 " packets transmitted in %" PRIu32 ".%06" PRIu32 "s\n", l2_ping_stats.ping_count, - period.seconds, period.microseconds); - - return 0; -} - -int _l2_ping_get_probe_handler(int argc, char **argv) -{ - (void) argc; - (void) argv; - - l2_probe_stat_entry_t *stats; - uint16_t count; - - l2_probe_stats(&stats, &count); - - printf("[l2_ping] Getting link layer probe statistics:\n"); - for (uint16_t i = 0; i < count; i++) { - printf("...received %" PRIu16 " probes from node %" PRIu16 ".\n", stats[i].count, stats[i].src); - } - - return 0; -} diff --git a/sys/shell/commands/sc_net_if.c b/sys/shell/commands/sc_net_if.c deleted file mode 100644 index 6c4830b469..0000000000 --- a/sys/shell/commands/sc_net_if.c +++ /dev/null @@ -1,676 +0,0 @@ -/* - * Copyright (C) 2013 Martine Lenders - * - * 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 sys_shell_commands - * @{ - * - * @file - * @brief Provides shell commands to configure network interfaces - * - * @author Martine Lenders - * - * @} - */ - -#include -#include -#include -#include -#include - -#include "inet_pton.h" -#include "inet_ntop.h" -#include "net_help.h" -#include "net_if.h" -#include "transceiver.h" - -#ifndef MODULE_SIXLOWPAN -#define ADDR_REGISTERED_MAX (6) -#define ADDRS_LEN_MAX (16) - -static uint8_t addr_registered = 0; -static uint8_t addrs[ADDR_REGISTERED_MAX][ADDRS_LEN_MAX]; -#else -#include "ipv6.h" -#endif - -int _net_if_ifconfig_add(int if_id, int argc, char **argv); -int _net_if_ifconfig_add_ipv6(int if_id, int argc, char **argv); -int _net_if_ifconfig_set(int if_id, char *key, char *value); -int _net_if_ifconfig_set_srcaddrmode(int if_id, char *mode); -int _net_if_ifconfig_set_eui64(int if_id, char *addr); -int _net_if_ifconfig_set_hwaddr(int if_id, char *addr); -int _net_if_ifconfig_set_pan_id(int if_id, char *pan_id); -int _net_if_ifconfig_set_channel(int if_id, char *channel); -int _net_if_ifconfig_create(char *transceivers_str); -int _net_if_ifconfig_ipv6_addr_convert(net_if_addr_t *addr, void *addr_data, - char *type, char *addr_data_str, - char *addr_data_len); -int _net_if_ifconfig_list(int if_id); - -int is_number(char *str) -{ - for (; *str; str++) { - if (!isdigit((int)*str)) { - return 0; - } - } - - return 1; -} - -static inline void _eui64_to_str(char *eui64_str, net_if_eui64_t *eui64) -{ - sprintf(eui64_str, "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x", - eui64->uint8[0], eui64->uint8[1], eui64->uint8[2], eui64->uint8[3], - eui64->uint8[4], eui64->uint8[5], eui64->uint8[6], eui64->uint8[7]); -} - -char *addr_data_to_str(char *addr_str, const uint8_t *addr, uint8_t addr_len) -{ - int i; - - for (i = 0; i < addr_len / 8; i++) { - sprintf(addr_str, "%02x", addr[i]); - } - - uint8_t r = addr_len % 8; - - if (r) { - uint8_t mask = 0x00; - - while (r) { - mask |= 0x1 << (8 - (r--)); - } - - sprintf(addr_str, "%02x", addr[addr_len / 8] & mask); - } - - return addr_str; -} - -void add_usage(void) -{ - puts("Usage: ifconfig add ipv6 [multicast|anycast] "); -} - -void set_usage(void) -{ - printf("Usage: ifconfig set \n" - " Sets an transceiver specific value\n" - " may be one of the following\n" - " * \"srcaddrmode\" - sets the source address mode for IEEE\n" - " 802.15.4 transeivers (valid values: \"short\" or \"long\"),\n" - " * \"sam\" - alias for \"srcaddrmode\"\n" - " * \"eui64\" - sets the EUI-64 if supported by transceivers,\n" - " * \"hwaddr\" - sets the 16-bit address (or just the address\n" - " for e.g cc1100) of the transceivers\n" - " * \"pan_id\" - sets the PAN ID of the transceiver\n" - " * \"pan\" - alias for \"pan_id\"\n" - " * \"channel\" - sets the frequency channel of the transceiver\n" - " * \"chan\" - alias for \"channel\"\n"); -} - -void create_usage(void) -{ - puts("Usage: ifconfig create [,,...]\n" - " may be one of the following values:\n" -#ifdef MODULE_AT86RF231 - " * at86rv231\n" -#endif -#ifdef MODULE_CC1020 - " * cc1020\n" -#endif -#if MODULE_CC110X || MODULE_CC110X_LEGACY || MODULE_CC110X_LEGACY_CSMA - " * cc1100\n" -#endif -#ifdef MODULE_CC2420 - " * cc2420\n" -#endif -#ifdef MODULE_MC1322X - " * mc1322x\n" -#endif -#ifdef MODULE_NATIVENET - " * native\n" -#endif - ); -} - -int _net_if_ifconfig(int argc, char **argv) -{ - if (argc < 2) { - int if_id = -1; - - while ((if_id = net_if_iter_interfaces(if_id)) >= 0) { - _net_if_ifconfig_list(if_id); - } - - return 0; - } - else if (strcmp(argv[1], "create") == 0) { - return _net_if_ifconfig_create(argv[2]); - } - else if (is_number(argv[1])) { - int if_id = atoi(argv[1]); - - if (argc < 3) { - return _net_if_ifconfig_list(if_id); - } - else if (strcmp(argv[2], "add") == 0) { - if (argc < 5) { - add_usage(); - return 1; - } - - return _net_if_ifconfig_add(if_id, argc, argv); - } - else if (strcmp(argv[2], "set") == 0) { - if (argc < 5) { - set_usage(); - return 1; - } - - return _net_if_ifconfig_set(if_id, argv[3], argv[4]); - } - } - - create_usage(); - printf("or: ifconfig [ [add |set ]]\n"); - - return 1; -} - -int _net_if_ifconfig_set_srcaddrmode(int if_id, char *mode) -{ - if (mode == NULL) { - set_usage(); - return 1; - } - else if (strcmp(mode, "short") == 0) { - return !net_if_set_src_address_mode(if_id, NET_IF_TRANS_ADDR_M_SHORT); - } - else if (strcmp(mode, "long") == 0) { - return !net_if_set_src_address_mode(if_id, NET_IF_TRANS_ADDR_M_LONG); - } - else { - set_usage(); - return 1; - } -} - -int _net_if_ifconfig_set_eui64(int if_id, char *eui64_str) -{ - net_if_eui64_t eui64; - - if (eui64_str == NULL) { - set_usage(); - return 1; - } - - net_if_hex_to_eui64(&eui64, eui64_str); - net_if_set_eui64(if_id, &eui64); - - return 0; -} - -int _net_if_ifconfig_set_hwaddr(int if_id, char *addr_str) -{ - int addr; - - if (addr_str == NULL) { - set_usage(); - return 1; - } - - if (is_number(addr_str)) { - if ((addr = atoi(addr_str)) > 0xffff) { - set_usage(); - return 1; - } - } - else { - if ((addr = strtoul(addr_str, NULL, 16)) > 0xffff) { - set_usage(); - return 1; - } - } - - return net_if_set_hardware_address(if_id, (uint16_t)addr) == 0; -} - -int _net_if_ifconfig_set_pan_id(int if_id, char *pan_str) -{ - int pan_id; - - if (pan_str == NULL) { - set_usage(); - return 1; - } - - if (is_number(pan_str)) { - if ((pan_id = atoi(pan_str)) > 0xffff) { - set_usage(); - return 1; - } - } - else { - if ((pan_id = strtoul(pan_str, NULL, 16)) > 0xffff) { - set_usage(); - return 1; - } - } - - return net_if_set_pan_id(if_id, (uint16_t) pan_id) == -1; -} - -int _net_if_ifconfig_set_channel(int if_id, char *chan_str) -{ - int channel; - - if (chan_str == NULL) { - set_usage(); - return 1; - } - - if (is_number(chan_str)) { - if ((channel = atoi(chan_str)) > 0xffff) { - set_usage(); - return 1; - } - } - else { - if ((channel = strtoul(chan_str, NULL, 16)) > 0xffff) { - set_usage(); - return 1; - } - } - - return net_if_set_channel(if_id, (uint16_t) channel) == -1; -} - -int _net_if_ifconfig_set(int if_id, char *key, char *value) -{ - if (strcmp(key, "sam") == 0 || strcmp(key, "srcaddrmode") == 0) { - return _net_if_ifconfig_set_srcaddrmode(if_id, value); - } - else if (strcmp(key, "eui64") == 0) { - return _net_if_ifconfig_set_eui64(if_id, value); - } - else if (strcmp(key, "hwaddr") == 0) { - return _net_if_ifconfig_set_hwaddr(if_id, value); - } - else if (strcmp(key, "pan") == 0 || strcmp(key, "pan_id") == 0) { - return _net_if_ifconfig_set_pan_id(if_id, value); - } - else if (strcmp(key, "chan") == 0 || strcmp(key, "channel") == 0) { - return _net_if_ifconfig_set_channel(if_id, value); - } - else { - set_usage(); - return 1; - } -} - -int _net_if_ifconfig_add_ipv6(int if_id, int argc, char **argv) -{ - char *type; - char *addr_str; - char *addr_data_str; - char *addr_data_len; - net_if_addr_t addr; - - if (argc > 5) { - if (strcmp(argv[4], "multicast") == 0 || strcmp(argv[4], "anycast") == 0 || strcmp(argv[4], "unicast") == 0) { - type = argv[4]; - addr_str = argv[5]; - } - else { - add_usage(); - return 1; - } - } - else { - addr_str = argv[4]; - type = NULL; - } - -#ifdef MODULE_SIXLOWPAN - ipv6_addr_t ipv6_addr; - void *addr_data = &ipv6_addr; -#else - void *addr_data = (void *)&addrs[addr_registered][0]; -#endif - - addr_data_str = strtok(addr_str, "/"); - addr_data_len = strtok(NULL, "/"); - - if (!_net_if_ifconfig_ipv6_addr_convert(&addr, addr_data, type, - addr_data_str, addr_data_len)) { - add_usage(); - return 1; - } - -#ifdef MODULE_SIXLOWPAN - - if (addr.addr_protocol & NET_IF_L3P_IPV6_PREFIX) { - if (ndp_add_prefix_info(if_id, &ipv6_addr, addr.addr_len, - NDP_OPT_PI_VLIFETIME_INFINITE, - NDP_OPT_PI_PLIFETIME_INFINITE, 1, - ICMPV6_NDP_OPT_PI_FLAG_AUTONOM) != SIXLOWERROR_SUCCESS) { - add_usage(); - return 1; - } - } - else if (addr.addr_protocol & NET_IF_L3P_IPV6_ADDR) { - uint8_t is_anycast = 0; - - if (addr.addr_protocol & NET_IF_L3P_IPV6_ANYCAST) { - is_anycast = 1; - } - - if (!ipv6_net_if_add_addr(if_id, &ipv6_addr, NDP_ADDR_STATE_PREFERRED, - 0, 0, is_anycast)) { - add_usage(); - return 1; - } - } - else { - add_usage(); - return 1; - } - -#else - - if (net_if_add_address(if_id, &addr) < 0) { - add_usage(); - return 1; - } - - addr_registered++; -#endif - - return 0; -} - -int _net_if_ifconfig_add(int if_id, int argc, char **argv) -{ - if (strcmp(argv[3], "ipv6") == 0) { - return _net_if_ifconfig_add_ipv6(if_id, argc, argv); - } - else { - add_usage(); - return 1; - } -} - -int _net_if_ifconfig_create(char *transceivers_str) -{ - char *transceiver_str; - transceiver_type_t transceivers = TRANSCEIVER_NONE; - int iface; - - transceiver_str = strtok(transceivers_str, ","); - - while (transceiver_str) { - if (strcasecmp(transceiver_str, "at86rv231") == 0) { - transceivers |= TRANSCEIVER_AT86RF231; - } - else if (strcasecmp(transceiver_str, "cc1020") == 0) { - transceivers |= TRANSCEIVER_CC1020; - } - else if (strcasecmp(transceiver_str, "cc1100") == 0) { - transceivers |= TRANSCEIVER_CC1100; - } - else if (strcasecmp(transceiver_str, "cc2420") == 0) { - transceivers |= TRANSCEIVER_CC2420; - } - else if (strcasecmp(transceiver_str, "mc1322x") == 0) { - transceivers |= TRANSCEIVER_MC1322X; - } - else if (strcasecmp(transceiver_str, "native") == 0) { - transceivers |= TRANSCEIVER_NATIVE; - } - else { - create_usage(); - return 1; - } - - transceiver_str = strtok(NULL, ","); - } - - if (!transceivers) { - create_usage(); - return 1; - } - - iface = net_if_init_interface(NET_IF_L3P_RAW, transceivers); - - if (iface < 0) { - puts("Maximum number of allowed interfaces reached.\n"); - return 1; - } - else { - printf("Initialized interface %d\n", iface); - return 0; - } -} - -static inline int _is_multicast(uint8_t *addr) -{ -#ifdef MODULE_SIXLOWPAN - return ipv6_addr_is_multicast((ipv6_addr_t *) addr); -#else - return *addr == 0xff; -#endif -} - -static inline int _is_link_local(uint8_t *addr) -{ -#ifdef MODULE_SIXLOWPAN - return ipv6_addr_is_link_local((ipv6_addr_t *) addr); -#else - return (addr[0] == 0xfe && addr[1] == 0x80) || - (_is_multicast(addr) && (addr[1] & 0x0f) == 2); -#endif -} - -int _set_protocol_from_type(char *type, net_if_addr_t *addr) -{ - if (type != NULL) { - if ((strcmp(type, "multicast") == 0) && - _is_multicast((uint8_t *)addr->addr_data)) { - addr->addr_protocol |= NET_IF_L3P_IPV6_MULTICAST; - return 1; - } - else if ((strcmp(type, "anycast") == 0) && - addr->addr_protocol & NET_IF_L3P_IPV6_PREFIX) { - addr->addr_protocol |= NET_IF_L3P_IPV6_ANYCAST; - return 1; - } - - return 0; - } - else if (_is_multicast((uint8_t *)addr->addr_data)) { - addr->addr_protocol |= NET_IF_L3P_IPV6_MULTICAST; - return 1; - } - else { - addr->addr_protocol |= NET_IF_L3P_IPV6_UNICAST; - return 1; - } -} - -int _net_if_ifconfig_ipv6_addr_convert(net_if_addr_t *addr, void *addr_data, - char *type, char *addr_data_str, - char *addr_data_len) -{ - if (addr_data_len && !is_number(addr_data_len)) { - return 0; - } - - addr->addr_data = addr_data; - - if (!inet_pton(AF_INET6, addr_data_str, addr->addr_data)) { - return 0; - } - - else if (addr_data_len == NULL) { - addr->addr_len = 128; - addr->addr_protocol = 0; - - if (!_set_protocol_from_type(type, addr)) { - return 0; - } - } - else { - addr->addr_len = atoi(addr_data_len); - addr->addr_protocol = NET_IF_L3P_IPV6_PREFIX; - - if (addr->addr_len > 128 || !_set_protocol_from_type(type, addr)) { - return 0; - } - } - - return 1; -} - -int _net_if_ifconfig_list(int if_id) -{ - net_if_t *iface = net_if_get_interface(if_id); - transceiver_type_t transceivers; - uint16_t hw_address; - int32_t channel; - int32_t pan_id; - net_if_eui64_t eui64; - char eui64_str[24]; - net_if_addr_t *addr_ptr = NULL; - - if (!iface) { - return 1; - } - - transceivers = iface->transceivers; - hw_address = net_if_get_hardware_address(if_id); - channel = net_if_get_channel(if_id); - pan_id = net_if_get_pan_id(if_id); - net_if_get_eui64(&eui64, if_id, 0); - _eui64_to_str(eui64_str, &eui64); - - printf("Iface %3d HWaddr: 0x%04x", if_id, - hw_address); - - if (channel < 0) { - printf(" Channel: not set"); - } - else { - printf(" Channel: %d", (uint16_t) channel); - } - - if (pan_id < 0) { - printf(" PAN ID: not set"); - } - else { - printf(" PAN ID: 0x%04x", (uint16_t)pan_id); - } - - printf("\n"); - - printf(" EUI-64: %s\n", eui64_str); - - switch (net_if_get_src_address_mode(if_id)) { - case NET_IF_TRANS_ADDR_M_SHORT: - puts(" Source address mode: short"); - break; - - case NET_IF_TRANS_ADDR_M_LONG: - puts(" Source address mode: long"); - break; - - default: - puts(" Source address mode: unknown"); - break; - } - - puts(" Transceivers:"); - - if (transceivers & TRANSCEIVER_AT86RF231) { - puts(" * at86rf231"); - } - - if (transceivers & TRANSCEIVER_CC1020) { - puts(" * cc1020"); - } - - if (transceivers & TRANSCEIVER_CC1100) { - puts(" * cc1100"); - } - - if (transceivers & TRANSCEIVER_CC2420) { - puts(" * cc2420"); - } - - if (transceivers & TRANSCEIVER_MC1322X) { - puts(" * mc1322x"); - } - - if (transceivers & TRANSCEIVER_NATIVE) { - puts(" * native"); - } - - while (net_if_iter_addresses(if_id, &addr_ptr)) { - if (addr_ptr->addr_protocol == NET_IF_L3P_RAW) { - char addr_str[addr_ptr->addr_len / 4 + 3]; - - printf(" Raw L3 addr: 0x"); - printf("%s", addr_data_to_str(addr_str, addr_ptr->addr_data, - addr_ptr->addr_len)); - puts("\n"); - } - -#ifdef MODULE_SIXLOWPAN - if (addr_ptr->addr_protocol & NET_IF_L3P_IPV6) { - char addr_str[IPV6_MAX_ADDR_STR_LEN]; - printf(" inet6 addr: "); - - if (inet_ntop(AF_INET6, addr_ptr->addr_data, addr_str, - IPV6_MAX_ADDR_STR_LEN)) { - printf("%s/%d", addr_str, addr_ptr->addr_len); - printf(" scope: "); - - if (addr_ptr->addr_len > 2 && _is_link_local((uint8_t *)addr_ptr->addr_data)) { - printf("local"); - } - else { - printf("global"); - } - - if (!(addr_ptr->addr_protocol & NET_IF_L3P_IPV6_UNICAST)) { - printf(" "); - - if (addr_ptr->addr_protocol & NET_IF_L3P_IPV6_MULTICAST) { - printf("[multicast]"); - } - else if (addr_ptr->addr_protocol & NET_IF_L3P_IPV6_ANYCAST) { - printf("[anycast]"); - } - } - - printf("\n"); - } - else { - printf("error in conversion\n"); - } - } -#endif - } - - puts(""); - - return 0; -} diff --git a/sys/shell/commands/sc_rpl.c b/sys/shell/commands/sc_rpl.c deleted file mode 100644 index 9839b8c460..0000000000 --- a/sys/shell/commands/sc_rpl.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2014 Oliver Hahm - * - * 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 sys_shell_commands - * @{ - * - * @file - * @brief Provides shell commands to manage and query RPL - * - * @author Oliver Hahm - * - * @} - */ - -#include -#include - -#include "rpl.h" - -static char addr_str[IPV6_MAX_ADDR_STR_LEN]; - -int _rpl_route_handler(int argc, char **argv) -{ - (void) argc; - (void) argv; - - rpl_routing_entry_t *rtable; - rtable = rpl_get_routing_table(); - if (rtable) { - unsigned c = 0; - puts("--------------------------------------------------------------------"); - puts("Routing table"); - printf(" %-3s %-18s %-18s %s\n", "#", "target", "next hop", "lifetime"); - puts("--------------------------------------------------------------------"); - - for (int i = 0; i < rpl_max_routing_entries; i++) { - if (rtable[i].used) { - c++; - printf(" %03d: %-18s ", i, ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - (&rtable[i].address))); - printf("%-18s ", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, - (&rtable[i].next_hop))); - printf("%d\n", rtable[i].lifetime); - - } - } - puts("--------------------------------------------------------------------"); - printf(" %u routing table entries\n", c); - } - else { - puts("No routing table available"); - } - puts("$"); - - return 0; -} diff --git a/sys/shell/commands/sc_transceiver.c b/sys/shell/commands/sc_transceiver.c deleted file mode 100644 index 2379fbf6cd..0000000000 --- a/sys/shell/commands/sc_transceiver.c +++ /dev/null @@ -1,404 +0,0 @@ -/* - * Copyright (C) 2013 Ludwig Ortmann. - * - * 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 sys_shell_commands - * @{ - * - * @file - * @brief Provides shell commands to configure the transceiver - * - * @author Oliver Hahm - * @author Ludwig Ortmann - * - * @} - */ - -#include -#include -#include -#include - -#ifdef MODULE_NET_IF -#include "net_if.h" -#endif -#include "transceiver.h" -#include "msg.h" - -#if defined( MODULE_CC110X_LEGACY_CSMA ) -#include "cc110x_legacy_csma.h" -#define TEXT_SIZE CC1100_MAX_DATA_LENGTH -#define _TC_TYPE TRANSCEIVER_CC1100 - -#elif defined( MODULE_CC110X_LEGACY ) -#include "cc110x_legacy.h" -#define TEXT_SIZE CC1100_MAX_DATA_LENGTH -#define _TC_TYPE TRANSCEIVER_CC1100 - -#elif defined( MODULE_CC110X ) -#include "cc110x.h" -#define TEXT_SIZE CC1100_MAX_DATA_LENGTH -#define _TC_TYPE TRANSCEIVER_CC1100 - -#elif defined( MODULE_CC2420 ) -#include "cc2420.h" -#include "ieee802154_frame.h" -#define TEXT_SIZE CC2420_MAX_DATA_LENGTH -#define _TC_TYPE TRANSCEIVER_CC2420 - -#elif defined( MODULE_AT86RF231 ) -#include "at86rf231.h" -#include "ieee802154_frame.h" -#define TEXT_SIZE AT86RF231_MAX_DATA_LENGTH -#define _TC_TYPE TRANSCEIVER_AT86RF231 - -#elif defined( MODULE_NATIVENET ) -#include "nativenet.h" -#define TEXT_SIZE NATIVE_MAX_DATA_LENGTH -#define _TC_TYPE TRANSCEIVER_NATIVE - -#elif defined( MODULE_MC1322X ) -#include "mc1322x.h" -#include "maca.h" -#include "maca_packet.h" -#include "ieee802154_frame.h" -#define TEXT_SIZE MACA_MAX_PAYLOAD_SIZE -#define _TC_TYPE TRANSCEIVER_MC1322X -#endif - -/* checked for type safety */ -int _transceiver_get_set_address_handler(int argc, char **argv) -{ - msg_t mesg; - transceiver_command_t tcmd; - radio_address_t a; - - if (transceiver_pid == KERNEL_PID_UNDEF) { - puts("Transceiver not initialized"); - return 1; - } - - tcmd.transceivers = _TC_TYPE; - tcmd.data = &a; - mesg.content.ptr = (char *) &tcmd; - - if (argc > 1) { - a = atoi(argv[1]); - printf("[transceiver] trying to set address %" PRIu16 "\n", a); - mesg.type = SET_ADDRESS; - } - else { - mesg.type = GET_ADDRESS; - } - - msg_send_receive(&mesg, &mesg, transceiver_pid); - printf("[transceiver] got address: %" PRIu16 "\n", a); - - return 0; -} - -#ifndef MODULE_NET_IF -uint8_t hex_to_dec(char c) -{ - if (c >= '0' && c <= '9') { - return (uint8_t)(c - '0'); - } - else if (c >= 'A' && c <= 'F') { - return (uint8_t)(c - 55); - } - else if (c >= 'a' && c <= 'f') { - return (uint8_t)(c - 87); - } - else { - return 0xff; - } -} - -uint64_t _str_to_eui64(const char *eui64_str) -{ - int i; - const char *eui64_rev = &eui64_str[strlen(eui64_str) - 1]; - uint64_t eui64 = 0; - - for (i = 7; i >= 0 || eui64_rev >= eui64_str; i--) { - uint8_t digit; - eui64 <<= 8; - - while ((digit = hex_to_dec(*eui64_rev)) == 0xFF) { - if (--eui64_rev < eui64_str) { - return eui64; - } - } - - eui64 = digit; - eui64_rev--; - - while ((digit = hex_to_dec(*eui64_rev)) == 0xFF) { - if (--eui64_rev < eui64_str) { - return eui64; - } - } - - eui64 |= digit << 4; - eui64_rev--; - } - - return eui64; -} -#endif - -/* checked for type safety */ -int _transceiver_get_set_long_addr_handler(int argc, char **argv) -{ - msg_t mesg; - transceiver_command_t tcmd; - transceiver_eui64_t a; - - if (transceiver_pid == KERNEL_PID_UNDEF) { - puts("Transceiver not initialized"); - return 1; - } - - tcmd.transceivers = _TC_TYPE; - tcmd.data = &a; - mesg.content.ptr = (char *) &tcmd; - - if (argc > 1) { -#ifdef MODULE_NET_IF - net_if_eui64_t eui64; - net_if_hex_to_eui64(&eui64, argv[1]); - a = eui64.uint64; -#else - a = _str_to_eui64(argv[1]); -#endif - printf("[transceiver] trying to set EUI-64 %016"PRIx64"\n", a); - mesg.type = SET_LONG_ADDR; - } - else { - mesg.type = GET_LONG_ADDR; - } - - msg_send_receive(&mesg, &mesg, transceiver_pid); - printf("[transceiver] got EUI-64: %016"PRIx64"\n", a); - - return 0; -} - - -/* checked for type safety */ -int _transceiver_get_set_channel_handler(int argc, char **argv) -{ - msg_t mesg; - transceiver_command_t tcmd; - int32_t c; - - if (transceiver_pid == KERNEL_PID_UNDEF) { - puts("Transceiver not initialized"); - return 1; - } - - tcmd.transceivers = _TC_TYPE; - tcmd.data = &c; - mesg.content.ptr = (char *) &tcmd; - - if (argc > 1) { - c = atoi(argv[1]); - printf("[transceiver] Trying to set channel %" PRIi32 "\n", c); - mesg.type = SET_CHANNEL; - } - else { - mesg.type = GET_CHANNEL; - } - - msg_send_receive(&mesg, &mesg, transceiver_pid); - if (c == -1) { - puts("[transceiver] Error setting/getting channel"); - } - else { - printf("[transceiver] Got channel: %" PRIi32 "\n", c); - } - - return 0; -} - -int _transceiver_send_handler(int argc, char **argv) -{ - if (transceiver_pid == KERNEL_PID_UNDEF) { - puts("Transceiver not initialized"); - return 1; - } - if (argc < 3) { - printf("Usage:\t%s [PAN]\n", argv[0]); - return 1; - } - -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X - ieee802154_packet_t p; - uint16_t short_addr; -#else - radio_packet_t p; -#endif - - transceiver_command_t tcmd; - tcmd.transceivers = _TC_TYPE; - tcmd.data = &p; - - char text_msg[TEXT_SIZE]; - memset(text_msg, 0, TEXT_SIZE); - strcpy(text_msg, argv[2]); - -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X - memset(&p, 0, sizeof(ieee802154_packet_t)); - p.frame.payload = (uint8_t*) text_msg; - p.frame.payload_len = strlen(text_msg) + 1; - p.frame.fcf.frame_type = IEEE_802154_DATA_FRAME; - p.frame.fcf.dest_addr_m = IEEE_802154_SHORT_ADDR_M; - p.frame.fcf.src_addr_m = IEEE_802154_SHORT_ADDR_M; - short_addr = atoi(argv[1]); - p.frame.dest_addr[1] = (short_addr&0xff); - p.frame.dest_addr[0] = (short_addr>>8); - if (argc == 4) { - p.frame.dest_pan_id = atoi(argv[3]); - } - else { - p.frame.dest_pan_id = IEEE_802154_DEFAULT_PAN_ID; - } -#else - p.data = (uint8_t *) text_msg; - p.length = strlen(text_msg) + 1; - p.dst = atoi(argv[1]); -#endif - - msg_t mesg; - mesg.type = SND_PKT; - mesg.content.ptr = (char *) &tcmd; - -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X - printf("[transceiver] Sending packet of length %" PRIu16 " to %" PRIu16 ": %s\n", p.frame.payload_len, p.frame.dest_addr[1], (char*) p.frame.payload); -#else - printf("[transceiver] Sending packet of length %" PRIu16 " to %" PRIu16 ": %s\n", p.length, p.dst, (char*) p.data); -#endif - msg_send_receive(&mesg, &mesg, transceiver_pid); - int8_t response = mesg.content.value; - printf("[transceiver] Packet sent: %" PRIi8 "\n", response); - - return 0; -} - -/* checked for type safety */ -int _transceiver_monitor_handler(int argc, char **argv) -{ - if (transceiver_pid == KERNEL_PID_UNDEF) { - puts("Transceiver not initialized"); - return 1; - } - else if (argc != 2) { - printf("Usage:\n%s \n", argv[0]); - return 1; - } - - uint8_t m = atoi(argv[1]); - printf("Setting monitor mode: %" PRIu8 "\n", m); - - transceiver_command_t tcmd; - tcmd.transceivers = _TC_TYPE; - tcmd.data = &m; - - msg_t mesg; - mesg.content.ptr = (char *) &tcmd; - mesg.type = SET_MONITOR; - - msg_send(&mesg, transceiver_pid); - - return 0; -} - -/* checked for type safety */ -int _transceiver_get_set_pan_handler(int argc, char **argv) -{ - if (transceiver_pid == KERNEL_PID_UNDEF) { - puts("Transceiver not initialized"); - return 1; - } - - int32_t p; - - transceiver_command_t tcmd; - tcmd.transceivers = _TC_TYPE; - tcmd.data = &p; - - msg_t mesg; - mesg.content.ptr = (char*) &tcmd; - if (argc > 1) { - p = atoi(argv[1]); - printf("[transceiver] Trying to set pan %" PRIi32 "\n", p); - mesg.type = SET_PAN; - } - else { - mesg.type = GET_PAN; - } - msg_send_receive(&mesg, &mesg, transceiver_pid); - if (p == -1) { - puts("[transceiver] Error setting/getting pan"); - } - else { - printf("[transceiver] Got pan: %" PRIi32 "\n", p); - } - - return 0; -} - -/* checked for type safety */ -#ifdef DBG_IGNORE -int _transceiver_set_ignore_handler(int argc, char **argv) -{ - - if (transceiver_pid == KERNEL_PID_UNDEF) { - puts("Transceiver not initialized"); - return 1; - } - else if (argc < 2) { - printf("[transceiver] Ignored link layer addresses: "); - for (uint8_t i = 0; i < TRANSCEIVER_MAX_IGNORED_ADDR; i++) { - if (transceiver_ignored_addr[i]) { - printf("%" PRIu16 " ", transceiver_ignored_addr[i]); - } - } - puts(""); - return; - } - else if (argc > 2) { - printf("Usage:\n%s
\n", argv[0]); - return 1; - } - - radio_address_t a; - - transceiver_command_t tcmd; - tcmd.transceivers = _TC_TYPE; - tcmd.data = &a; - - msg_t mesg; - mesg.content.ptr = (char*) &tcmd; - - a = atoi(argv[1]); - printf("[transceiver] trying to add address %" PRIu16 " to the ignore list \n", a); - mesg.type = DBG_IGN; - msg_send_receive(&mesg, &mesg, transceiver_pid); - - int16_t response = a; - if (response == -1) { - printf("Error: ignore list full\n"); - } - else { - printf("Success (added at index %" PRIi16 ").\n", response); - } - - return 0; -} -#endif diff --git a/sys/shell/commands/shell_commands.c b/sys/shell/commands/shell_commands.c index 9d1a58810b..a3fb9d7aa8 100644 --- a/sys/shell/commands/shell_commands.c +++ b/sys/shell/commands/shell_commands.c @@ -77,66 +77,6 @@ extern int _rtc_handler(int argc, char **argv); extern int _x86_lspci(int argc, char **argv); #endif -/* configure available commands for each transceiver device: */ -#ifdef MODULE_TRANSCEIVER -#ifdef DBG_IGNORE -#define _TC_IGN -#endif -#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY) || defined(MODULE_CC2420) || defined(MODULE_AT86RF231) || defined(MODULE_NATIVENET)) -#define _TC_ADDR -#define _TC_CHAN -#define _TC_MON -#define _TC_SEND -#endif -#if (defined(MODULE_CC2420) || defined(MODULE_AT86RF231) || defined(MODULE_NATIVENET)) -#define _TC_LONG_ADDR -#define _TC_PAN -#endif -#else /* WITHOUT MODULE_TRANSCEIVER */ -#ifdef MODULE_CC110X_LEGACY_CSMA -extern int _cc110x_get_set_address_handler(int argc, char **argv); -extern int _cc110x_get_set_channel_handler(int argc, char **argv); -#endif -#endif - -#ifdef MODULE_TRANSCEIVER -#ifdef _TC_ADDR -extern int _transceiver_get_set_address_handler(int argc, char **argv); -#endif -#ifdef _TC_LONG_ADDR -extern int _transceiver_get_set_long_addr_handler(int argc, char **argv); -#endif -#ifdef _TC_CHAN -extern int _transceiver_get_set_channel_handler(int argc, char **argv); -#endif -#ifdef _TC_SEND -extern int _transceiver_send_handler(int argc, char **argv); -#endif -#ifdef _TC_MON -extern int _transceiver_monitor_handler(int argc, char **argv); -#endif -#ifdef _TC_PAN -extern int _transceiver_get_set_pan_handler(int argc, char **argv); -#endif -#ifdef _TC_IGN -extern int _transceiver_set_ignore_handler(int argc, char **argv); -#endif -#endif - -#ifdef MODULE_L2_PING -extern int _l2_ping_req_handler(int argc, char **argv); -extern int _l2_ping_probe_handler(int argc, char **argv); -extern int _l2_ping_get_probe_handler(int argc, char **argv); -#endif - -#ifdef MODULE_NET_IF -extern int _net_if_ifconfig(int argc, char **argv); -#endif - -#ifdef MODULE_RPL -extern int _rpl_route_handler(int argc, char **argv); -#endif - #ifdef MODULE_MCI extern int _get_sectorsize(int argc, char **argv); extern int _get_blocksize(int argc, char **argv); @@ -157,13 +97,9 @@ extern int _mersenne_get(int argc, char **argv); #endif #ifdef MODULE_NG_NETIF -#ifndef MODULE_NET_IF extern int _netif_config(int argc, char **argv); -#endif -#ifndef MODULE_TRANSCEIVER extern int _netif_send(int argc, char **argv); #endif -#endif #ifdef MODULE_FIB extern int _fib_route_handler(int argc, char **argv); @@ -217,45 +153,6 @@ const shell_command_t _shell_command_list[] = { {"cur", "Prints current and average power consumption.", _get_current_handler}, {"rstcur", "Resets coulomb counter.", _reset_current_handler}, #endif -#ifdef MODULE_TRANSCEIVER -#ifdef _TC_ADDR - {"addr", "Gets or sets the address for the transceiver", _transceiver_get_set_address_handler}, -#endif -#ifdef _TC_LONG_ADDR - {"eui64", "Gets or sets the EUI-64 for the transceiver", _transceiver_get_set_long_addr_handler}, -#endif -#ifdef _TC_CHAN - {"chan", "Gets or sets the channel for the transceiver", _transceiver_get_set_channel_handler}, -#endif -#ifdef _TC_SEND - {"txtsnd", "Sends a text message to a given node via the transceiver", _transceiver_send_handler}, -#endif -#ifdef _TC_PAN - {"pan", "Gets or sets the pan id for the transceiver", _transceiver_get_set_pan_handler}, -#endif -#ifdef _TC_MON - {"monitor", "Enables or disables address checking for the transceiver", _transceiver_monitor_handler}, -#endif -#ifdef _TC_IGN - {"ign", "Ignore the address at the transceiver", _transceiver_set_ignore_handler}, -#endif -#else /* WITHOUT MODULE_TRANSCEIVER */ -#ifdef MODULE_CC110X_LEGACY_CSMA - {"addr", "Gets or sets the address for the CC1100 transceiver", _cc110x_get_set_address_handler}, - {"chan", "Gets or sets the channel for the CC1100 transceiver", _cc110x_get_set_channel_handler}, -#endif -#endif -#ifdef MODULE_L2_PING - {"l2_ping", "Sends link layer ping requests", _l2_ping_req_handler}, - {"l2_probe", "Sends link layer probes", _l2_ping_probe_handler}, - {"l2_probe_stats", "Get statistics about received probes", _l2_ping_get_probe_handler}, -#endif -#ifdef MODULE_NET_IF - {"ifconfig", "Configures a network interface", _net_if_ifconfig}, -#endif -#ifdef MODULE_RPL - {"route", "Shows the routing table", _rpl_route_handler}, -#endif #ifdef MODULE_MCI {DISK_READ_SECTOR_CMD, "Reads the specified sector of inserted memory card", _read_sector}, {DISK_READ_BYTES_CMD, "Reads the specified bytes from inserted memory card", _read_bytes}, @@ -279,13 +176,9 @@ const shell_command_t _shell_command_list[] = { {"lspci", "Lists PCI devices", _x86_lspci}, #endif #ifdef MODULE_NG_NETIF -#ifndef MODULE_NET_IF {"ifconfig", "Configure network interfaces", _netif_config}, -#endif -#ifndef MODULE_TRANSCEIVER {"txtsnd", "send raw data", _netif_send }, #endif -#endif #ifdef MODULE_FIB {"fibroute", "Manipulate the FIB (info: 'fibroute [add|del]')", _fib_route_handler}, #endif diff --git a/sys/transceiver/Makefile b/sys/transceiver/Makefile deleted file mode 100644 index e2a870105c..0000000000 --- a/sys/transceiver/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -ifneq (,$(filter cc2420,$(USEMODULE))) - INCLUDES += -I$(RIOTBASE)/sys/net/include -endif - -ifneq (,$(filter at86rf231,$(USEMODULE))) - INCLUDES += -I$(RIOTBASE)/sys/net/include -endif - -ifneq (,$(filter mc1322x,$(USEMODULE))) - INCLUDES += -I$(RIOTBASE)/sys/net/include -endif - -include $(RIOTBASE)/Makefile.base diff --git a/sys/transceiver/transceiver.c b/sys/transceiver/transceiver.c deleted file mode 100644 index e43a1bf6ad..0000000000 --- a/sys/transceiver/transceiver.c +++ /dev/null @@ -1,1276 +0,0 @@ -/** - * Generic transceiver module as an interface to NIC driver. - * - * Copyright (C) 2013 INRIA. - * - * 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 transceiver - * @{ - * @file - * @brief Providing a generic interface to the driver implementation for any supported network device. - * @author Oliver Hahm - * @} - */ - -#include -#include -#include -#include -#include - -#include "thread.h" -#include "msg.h" -#include "irq.h" - -#include "radio/types.h" - -#include "transceiver.h" - -/* supported transceivers */ -#ifdef MODULE_CC110X -#include "cc110x.h" -#endif - -#ifdef MODULE_CC110X_LEGACY_CSMA -#include "cc110x_legacy_csma.h" -#endif - -#ifdef MODULE_CC110X_LEGACY -#include "cc110x_legacy.h" -#endif - -#ifdef MODULE_CC2420 -#include "cc2420.h" -#include "ieee802154_frame.h" -#endif - -#ifdef MODULE_MC1322X -#include "mc1322x.h" -#include "maca.h" -#include "maca_packet.h" -#include "ieee802154_frame.h" -#endif - -#ifdef MODULE_NATIVENET -#include "nativenet.h" -#include "nativenet_internal.h" -#endif - -#ifdef MODULE_AT86RF231 -#include "at86rf231.h" -#include "ieee802154_frame.h" -#endif - -#define ENABLE_DEBUG (0) -#if ENABLE_DEBUG -#undef TRANSCEIVER_STACK_SIZE -#define TRANSCEIVER_STACK_SIZE (THREAD_STACKSIZE_MAIN) -#endif -#include "debug.h" - -/*------------------------------------------------------------------------------------*/ -/* used transceiver types */ -static transceiver_type_t transceivers = TRANSCEIVER_NONE; - -/* registered upper layer threads */ -static registered_t reg[TRANSCEIVER_MAX_REGISTERED]; - -/* packet buffers */ -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X -static ieee802154_packet_t transceiver_buffer[TRANSCEIVER_BUFFER_SIZE]; -#else -static radio_packet_t transceiver_buffer[TRANSCEIVER_BUFFER_SIZE]; -#endif -static uint8_t data_buffer[TRANSCEIVER_BUFFER_SIZE * PAYLOAD_SIZE]; - -/* message buffer */ -static msg_t msg_buffer[TRANSCEIVER_MSG_BUFFER_SIZE]; - -static uint32_t response; ///< response bytes for messages to upper layer threads - -volatile kernel_pid_t transceiver_pid = KERNEL_PID_UNDEF; ///< the transceiver thread's pid - -static volatile uint8_t rx_buffer_pos = 0; -static volatile uint8_t transceiver_buffer_pos = 0; - -#ifdef MODULE_CC110X_LEGACY_CSMA -static void *cc1100_payload; -static int cc1100_payload_size; -static packet_info_t *cc1100_packet_info; -static uint8_t cc1100_pkt[CC1100_MAX_DATA_LENGTH]; -#endif - - -/* transceiver stack */ -static char transceiver_stack[TRANSCEIVER_STACK_SIZE]; - -/*------------------------------------------------------------------------------------*/ -/* function prototypes */ -static void *run(void *arg); -static void receive_packet(uint16_t type, uint8_t pos); -#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY)) -static void receive_cc110x_packet(radio_packet_t *trans_p); -#endif -#ifdef MODULE_CC110X_LEGACY_CSMA -void cc1100_packet_monitor(void *payload, int payload_size, protocol_t protocol, packet_info_t *packet_info); -void receive_cc1100_packet(radio_packet_t *trans_p); -#endif -#ifdef MODULE_CC2420 -static void receive_cc2420_packet(ieee802154_packet_t *trans_p); -#endif -#ifdef MODULE_NATIVENET -static void receive_nativenet_packet(radio_packet_t *trans_p); -#endif -#ifdef MODULE_MC1322X -void receive_mc1322x_packet(ieee802154_packet_t *trans_p); -#endif -#ifdef MODULE_AT86RF231 -void receive_at86rf231_packet(ieee802154_packet_t *trans_p); -#endif -static int8_t send_packet(transceiver_type_t t, void *pkt); -static int32_t get_channel(transceiver_type_t t); -static int32_t set_channel(transceiver_type_t t, void *channel); -static radio_address_t get_address(transceiver_type_t t); -static radio_address_t set_address(transceiver_type_t t, void *address); -static transceiver_eui64_t get_long_addr(transceiver_type_t t); -static transceiver_eui64_t set_long_addr(transceiver_type_t t, - void *address); -static int32_t get_pan(transceiver_type_t t); -static int32_t set_pan(transceiver_type_t t, void *pan); - -static void set_monitor(transceiver_type_t t, void *mode); -static void powerdown(transceiver_type_t t); -static void switch_to_rx(transceiver_type_t t); - -#ifdef DBG_IGNORE -static int16_t ignore_add(transceiver_type_t transceiver, void *address); - -radio_address_t transceiver_ignored_addr[TRANSCEIVER_MAX_IGNORED_ADDR]; -#endif - -/*------------------------------------------------------------------------------------*/ -/* Transceiver init */ -void transceiver_init(transceiver_type_t t) -{ - uint8_t i; - - if (transceiver_pid != KERNEL_PID_UNDEF) { - /* do not re-initialize an already running transceiver */ - return; - } - - /* Initializing transceiver buffer and data buffer */ - memset(transceiver_buffer, 0, sizeof(transceiver_buffer)); - memset(data_buffer, 0, TRANSCEIVER_BUFFER_SIZE * PAYLOAD_SIZE); -#ifdef DBG_IGNORE - memset(transceiver_ignored_addr, 0, sizeof(transceiver_ignored_addr)); -#endif - - for (i = 0; i < TRANSCEIVER_MAX_REGISTERED; i++) { - reg[i].transceivers = TRANSCEIVER_NONE; - reg[i].pid = KERNEL_PID_UNDEF; - } - - /* check if a non defined bit is set */ - if (t & ~(TRANSCEIVER_CC1100 | TRANSCEIVER_CC2420 | TRANSCEIVER_MC1322X | TRANSCEIVER_NATIVE | TRANSCEIVER_AT86RF231)) { - puts("Invalid transceiver type"); - } - else { - transceivers |= t; - } -} - -/* Start the transceiver thread */ -kernel_pid_t transceiver_start(void) -{ - transceiver_pid = thread_create(transceiver_stack, TRANSCEIVER_STACK_SIZE, THREAD_PRIORITY_MAIN - 3, CREATE_STACKTEST, run, NULL, "Transceiver"); - - if (transceiver_pid == KERNEL_PID_UNDEF) { - puts("Error creating transceiver thread"); - } - -#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY)) - else if (transceivers & TRANSCEIVER_CC1100) { - DEBUG("transceiver: Transceiver started for CC1100\n"); - cc110x_init(transceiver_pid); - } - -#endif -#ifdef MODULE_CC110X_LEGACY_CSMA - else if (transceivers & TRANSCEIVER_CC1100) { - DEBUG("transceiver: Transceiver started for CC1100\n"); - cc1100_init(); - cc1100_set_packet_monitor(cc1100_packet_monitor); - } - -#endif -#ifdef MODULE_CC2420 - else if (transceivers & TRANSCEIVER_CC2420) { - DEBUG("transceiver: Transceiver started for CC2420\n"); - cc2420_init(transceiver_pid); - } - -#endif -#ifdef MODULE_AT86RF231 - else if (transceivers & TRANSCEIVER_AT86RF231) { - DEBUG("transceiver: Transceiver started for AT86RF231\n"); - at86rf231_init(transceiver_pid); - } - -#endif -#ifdef MODULE_MC1322X - else if (transceivers & TRANSCEIVER_MC1322X) { - maca_init(); - } - -#endif -#ifdef MODULE_NATIVENET - else if (transceivers & TRANSCEIVER_NATIVE) { - nativenet_init(transceiver_pid); - } - -#endif - return transceiver_pid; -} - -/* Register an upper layer thread */ -uint8_t transceiver_register(transceiver_type_t t, kernel_pid_t pid) -{ - int result = 0; - unsigned state = disableIRQ(); - for (size_t i = 0; i < TRANSCEIVER_MAX_REGISTERED; i++) { - if ((reg[i].pid == pid) || (reg[i].transceivers == TRANSCEIVER_NONE)) { - reg[i].transceivers |= t; - reg[i].pid = pid; - DEBUG("transceiver: Thread %i registered for %i\n", reg[i].pid, reg[i].transceivers); - restoreIRQ(state); - result = 1; - break; - } - } - restoreIRQ(state); - return result; -} - -/* Unregister an upper layer thread */ -uint8_t transceiver_unregister(transceiver_type_t t, kernel_pid_t pid) -{ - int result = 0; - unsigned state = disableIRQ(); - for (size_t i = 0; i < TRANSCEIVER_MAX_REGISTERED; ++i) { - if (reg[i].pid == pid) { - reg[i].transceivers &= ~t; - restoreIRQ(state); - result = 1; - break; - } - } - restoreIRQ(state); - return result; -} - -/*------------------------------------------------------------------------------------*/ -/* Internal functions */ -/*------------------------------------------------------------------------------------*/ - -/* - * @brief The main thread run, receiving and processing messages in an infinite - * loop - */ -static void *run(void *arg) -{ - (void) arg; - - msg_init_queue(msg_buffer, TRANSCEIVER_MSG_BUFFER_SIZE); - - while (1) { - DEBUG("transceiver: Waiting for next message\n"); - msg_t m; - msg_receive(&m); - /* only makes sense for messages for upper layers */ - transceiver_command_t *cmd = (transceiver_command_t *) m.content.ptr; - DEBUG("transceiver: Transceiver: Message received, type: %02X\n", m.type); - - switch (m.type) { - case RCV_PKT_CC1020: - case RCV_PKT_CC1100: - case RCV_PKT_CC2420: - case RCV_PKT_MC1322X: - case RCV_PKT_NATIVE: - case RCV_PKT_AT86RF231: - receive_packet(m.type, m.content.value); - break; - - case SND_PKT: - response = send_packet(cmd->transceivers, cmd->data); - m.content.value = response; - msg_reply(&m, &m); - break; - - case GET_CHANNEL: - *((int32_t *) cmd->data) = get_channel(cmd->transceivers); - msg_reply(&m, &m); - break; - - case SET_CHANNEL: - *((int32_t *) cmd->data) = set_channel(cmd->transceivers, cmd->data); - msg_reply(&m, &m); - break; - - case GET_ADDRESS: - *((radio_address_t *) cmd->data) = get_address(cmd->transceivers); - msg_reply(&m, &m); - break; - - case SET_ADDRESS: - *((radio_address_t *) cmd->data) = set_address(cmd->transceivers, cmd->data); - msg_reply(&m, &m); - break; - - case GET_LONG_ADDR: - *((transceiver_eui64_t *) cmd->data) = get_long_addr(cmd->transceivers); - msg_reply(&m, &m); - break; - - case SET_LONG_ADDR: - *((transceiver_eui64_t *) cmd->data) = set_long_addr(cmd->transceivers, cmd->data); - msg_reply(&m, &m); - break; - - case SET_MONITOR: - set_monitor(cmd->transceivers, cmd->data); - break; - - case POWERDOWN: - powerdown(cmd->transceivers); - break; - - case SWITCH_RX: - switch_to_rx(cmd->transceivers); - break; - - case GET_PAN: - *((int32_t *) cmd->data) = get_pan(cmd->transceivers); - msg_reply(&m, &m); - break; - - case SET_PAN: - *((int32_t *) cmd->data) = set_pan(cmd->transceivers, cmd->data); - msg_reply(&m, &m); - break; - -#ifdef DBG_IGNORE - case DBG_IGN: - *((int16_t *) cmd->data) = ignore_add(cmd->transceivers, cmd->data); - msg_reply(&m, &m); - break; -#endif - - default: - DEBUG("transceiver: Unknown message received\n"); - break; - } - } - - return NULL; -} - -/*------------------------------------------------------------------------------------*/ -/* - * @brief Processes a packet received by any transceiver device - * - * @param type The message type to determine which device has received the - * packet - * @param pos The current device driver's buffer position - */ -static void receive_packet(uint16_t type, uint8_t pos) -{ - size_t i = 0; - transceiver_type_t t; - rx_buffer_pos = pos; - msg_t m; - - DEBUG("Packet received\n"); - - switch (type) { - case RCV_PKT_CC1020: - t = TRANSCEIVER_CC1020; - break; - - case RCV_PKT_CC1100: - t = TRANSCEIVER_CC1100; - break; - - case RCV_PKT_CC2420: - t = TRANSCEIVER_CC2420; - break; - - case RCV_PKT_MC1322X: - t = TRANSCEIVER_MC1322X; - break; - - case RCV_PKT_NATIVE: - t = TRANSCEIVER_NATIVE; - break; - - case RCV_PKT_AT86RF231: - t = TRANSCEIVER_AT86RF231; - break; - - default: - t = TRANSCEIVER_NONE; - break; - } - - /* search first free position in transceiver buffer */ - for (i = 0; (i < TRANSCEIVER_BUFFER_SIZE) && (transceiver_buffer[transceiver_buffer_pos].processing); i++) { - if (++transceiver_buffer_pos == TRANSCEIVER_BUFFER_SIZE) { - transceiver_buffer_pos = 0; - } - } - - /* no buffer left */ - if (i >= TRANSCEIVER_BUFFER_SIZE) { - /* inform upper layers of lost packet */ - m.type = ENOBUFFER; - m.content.value = t; - DEBUG("transceiver: buffer size exceeded, dropping packet\n"); - } - /* copy packet and handle it */ - else { - m.type = PKT_PENDING; - - /* pass a null pointer if a packet from a undefined transceiver is - * received */ - if (type == RCV_PKT_CC1100) { -#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY)) - radio_packet_t *trans_p = &(transceiver_buffer[transceiver_buffer_pos]); - receive_cc110x_packet(trans_p); -#elif MODULE_CC110X_LEGACY_CSMA - radio_packet_t *trans_p = &(transceiver_buffer[transceiver_buffer_pos]); - receive_cc1100_packet(trans_p); -#endif - } - else if (type == RCV_PKT_MC1322X) { -#ifdef MODULE_MC1322X - ieee802154_packet_t *trans_p = &(transceiver_buffer[transceiver_buffer_pos]); - receive_mc1322x_packet(trans_p); -#endif - } - else if (type == RCV_PKT_CC2420) { -#ifdef MODULE_CC2420 - ieee802154_packet_t *trans_p = &(transceiver_buffer[transceiver_buffer_pos]); - receive_cc2420_packet(trans_p); -#endif - } - else if (type == RCV_PKT_AT86RF231) { -#ifdef MODULE_AT86RF231 - ieee802154_packet_t *trans_p = &(transceiver_buffer[transceiver_buffer_pos]); - receive_at86rf231_packet(trans_p); -#endif - } - else if (type == RCV_PKT_NATIVE) { -#ifdef MODULE_NATIVENET - radio_packet_t *trans_p = &(transceiver_buffer[transceiver_buffer_pos]); - receive_nativenet_packet(trans_p); -#endif - } - else { - puts("Invalid transceiver type"); - return; - } - -#ifdef DBG_IGNORE - -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X - radio_address_t short_addr; - short_addr = (transceiver_buffer[transceiver_buffer_pos].frame.src_addr[1] << 8) - | transceiver_buffer[transceiver_buffer_pos].frame.src_addr[0]; - for (size_t j = 0; (j < TRANSCEIVER_MAX_IGNORED_ADDR) && (transceiver_ignored_addr[j]); j++) { - DEBUG("check if source (%u) is ignored -> %u\n", short_addr, transceiver_ignored_addr[j]); - - if (short_addr == transceiver_ignored_addr[j]) { - DEBUG("ignored packet from %" PRIu16 "\n", short_addr); - return; - } - } -#else - for (size_t j = 0; (j < TRANSCEIVER_MAX_IGNORED_ADDR) && (transceiver_ignored_addr[j]); j++) { - DEBUG("check if source (%u) is ignored -> %u\n", transceiver_buffer[transceiver_buffer_pos].src, transceiver_ignored_addr[j]); - - if (transceiver_buffer[transceiver_buffer_pos].src == transceiver_ignored_addr[j]) { - DEBUG("ignored packet from %" PRIu16 "\n", transceiver_buffer[transceiver_buffer_pos].src); - return; - } - } -#endif -#endif - } - - /* finally notify waiting upper layers - * this is done non-blocking, so packets can get lost */ - i = 0; - - while (reg[i].transceivers != TRANSCEIVER_NONE) { - if (reg[i].transceivers & t) { - m.content.ptr = (char *) &(transceiver_buffer[transceiver_buffer_pos]); - DEBUG("transceiver: Notify thread %" PRIkernel_pid "\n", reg[i].pid); - - if (msg_try_send(&m, reg[i].pid) && (m.type != ENOBUFFER)) { - transceiver_buffer[transceiver_buffer_pos].processing++; - } - else { - DEBUG("transceiver: failed to notify upper layer.\n"); - } - } - - i++; - } -} - -#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY)) -/* - * @brief process packets from CC1100 - * - * @param trans_p The current entry in the transceiver buffer - */ -static void receive_cc110x_packet(radio_packet_t *trans_p) -{ - DEBUG("transceiver: Handling CC1100 packet\n"); - /* disable interrupts while copying packet */ - dINT(); - cc110x_packet_t p = cc110x_rx_buffer[rx_buffer_pos].packet; - - trans_p->src = p.phy_src; - trans_p->dst = p.address; - trans_p->rssi = cc110x_rx_buffer[rx_buffer_pos].rssi; - trans_p->lqi = cc110x_rx_buffer[rx_buffer_pos].lqi; - trans_p->length = p.length - CC1100_HEADER_LENGTH; - memcpy((void *) &(data_buffer[transceiver_buffer_pos * PAYLOAD_SIZE]), p.data, CC1100_MAX_DATA_LENGTH); - eINT(); - - trans_p->data = (uint8_t *) &(data_buffer[transceiver_buffer_pos * CC1100_MAX_DATA_LENGTH]); - DEBUG("transceiver: Packet %p (%p) was from %hu to %hu, size: %u\n", trans_p, trans_p->data, trans_p->src, trans_p->dst, trans_p->length); -} -#endif - -#ifdef MODULE_CC110X_LEGACY_CSMA -void receive_cc1100_packet(radio_packet_t *trans_p) -{ - dINT(); - trans_p->src = cc1100_packet_info->source; - trans_p->dst = cc1100_packet_info->destination; - trans_p->rssi = cc1100_packet_info->rssi; - trans_p->lqi = cc1100_packet_info->lqi; - trans_p->length = cc1100_payload_size; - memcpy((void *) &(data_buffer[transceiver_buffer_pos * PAYLOAD_SIZE]), cc1100_payload, CC1100_MAX_DATA_LENGTH); - eINT(); - - trans_p->data = (uint8_t *) &(data_buffer[transceiver_buffer_pos * CC1100_MAX_DATA_LENGTH]); - DEBUG("transceiver: Packet %p (%p) was from %hu to %hu, size: %u\n", trans_p, trans_p->data, trans_p->src, trans_p->dst, trans_p->length); -} -#endif - - -#ifdef MODULE_CC2420 -void receive_cc2420_packet(ieee802154_packet_t *trans_p) -{ - DEBUG("transceiver: Handling CC2420 packet\n"); - dINT(); - cc2420_packet_t *p = &cc2420_rx_buffer[rx_buffer_pos]; - trans_p->length = p->length; - memcpy(&trans_p->frame, &p->frame, sizeof(trans_p->frame)); - trans_p->rssi = p->rssi; - trans_p->crc = p->crc; - trans_p->lqi = p->lqi; - memcpy(&data_buffer[transceiver_buffer_pos * CC2420_MAX_DATA_LENGTH], - p->frame.payload, p->frame.payload_len); - trans_p->frame.payload = (uint8_t *) & (data_buffer[transceiver_buffer_pos * CC2420_MAX_DATA_LENGTH]); - trans_p->frame.payload_len = p->frame.payload_len; - eINT(); - -#if ENABLE_DEBUG - - if (trans_p->frame.fcf.dest_addr_m == IEEE_802154_SHORT_ADDR_M) { - if (trans_p->frame.fcf.src_addr_m == IEEE_802154_SHORT_ADDR_M) { - DEBUG("Packet %p was from %" PRIu16 " to %" PRIu16 ", size: %u\n", trans_p, *((uint16_t *) &trans_p->frame.src_addr[0]), *((uint16_t *) &trans_p->frame.dest_addr), trans_p->frame.payload_len); - } - else if (trans_p->frame.fcf.src_addr_m == IEEE_802154_LONG_ADDR_M) { - DEBUG("Packet %p was from %016" PRIx64 " to %" PRIu16 ", size: %u\n", trans_p, *((uint64_t *) &trans_p->frame.src_addr[0]), *((uint16_t *) &trans_p->frame.dest_addr), trans_p->frame.payload_len); - - } - else { - DEBUG("Illegal source address mode: %d\n", trans_p->frame.fcf.src_addr_m); - return; - } - } - else if (trans_p->frame.fcf.dest_addr_m == IEEE_802154_LONG_ADDR_M) { - if (trans_p->frame.fcf.src_addr_m == IEEE_802154_SHORT_ADDR_M) { - DEBUG("Packet %p was from %" PRIu16 " to %016" PRIx64 ", size: %u\n", trans_p, *((uint16_t *) &trans_p->frame.src_addr[0]), *((uint64_t *) &trans_p->frame.dest_addr), trans_p->frame.payload_len); - } - else if (trans_p->frame.fcf.src_addr_m == IEEE_802154_LONG_ADDR_M) { - DEBUG("Packet %p was from %016" PRIx64 " to %016" PRIx64 ", size: %u\n", trans_p, *((uint64_t *) &trans_p->frame.src_addr[0]), *((uint16_t *) &trans_p->frame.dest_addr), trans_p->frame.payload_len); - - } - else { - DEBUG("Illegal source address mode: %d\n", trans_p->frame.fcf.src_addr_m); - return; - } - } - else { - DEBUG("Illegal destination address mode: %d\n", trans_p->frame.fcf.src_addr_m); - return; - } -#endif - DEBUG("transceiver: Content: %s\n", trans_p->frame.payload); -} -#endif - -#ifdef MODULE_MC1322X -void receive_mc1322x_packet(ieee802154_packet_t *trans_p) -{ - maca_packet_t *maca_pkt; - dINT(); - maca_pkt = (maca_packet_t *)maca_get_rx_packet(); - trans_p->lqi = maca_pkt->lqi; - trans_p->length = maca_pkt->length; - memcpy((void *) &(data_buffer[transceiver_buffer_pos * PAYLOAD_SIZE]), maca_pkt->data, MACA_MAX_PAYLOAD_SIZE); - maca_free_packet(maca_pkt); - eINT(); - - trans_p->frame.payload = (uint8_t *) &(data_buffer[transceiver_buffer_pos * MACA_MAX_PAYLOAD_SIZE]); -} -#endif - - -#ifdef MODULE_NATIVENET -void receive_nativenet_packet(radio_packet_t *trans_p) -{ - unsigned state; - radio_packet_t *p = &_nativenet_rx_buffer[rx_buffer_pos].packet; - - /* disable interrupts while copying packet */ - state = disableIRQ(); - - DEBUG("Handling nativenet packet\n"); - - memcpy(trans_p, p, sizeof(radio_packet_t)); - memcpy(&(data_buffer[transceiver_buffer_pos * PAYLOAD_SIZE]), p->data, p->length); - trans_p->data = (uint8_t *) &(data_buffer[transceiver_buffer_pos * PAYLOAD_SIZE]); - - DEBUG("Packet %p was from %" PRIu16 " to %" PRIu16 ", size: %" PRIu8 "\n", trans_p, trans_p->src, trans_p->dst, trans_p->length); - - /* reset interrupts */ - restoreIRQ(state); -} -#endif - -#ifdef MODULE_AT86RF231 -void receive_at86rf231_packet(ieee802154_packet_t *trans_p) -{ - DEBUG("Handling AT86RF231 packet\n"); - dINT(); - at86rf231_packet_t *p = &at86rf231_rx_buffer[rx_buffer_pos]; - trans_p->length = p->length; - trans_p->rssi = p->rssi; - trans_p->crc = p->crc; - trans_p->lqi = p->lqi; - memcpy(&trans_p->frame, &p->frame, sizeof(trans_p->frame)); - memcpy(&data_buffer[transceiver_buffer_pos * AT86RF231_MAX_DATA_LENGTH], p->frame.payload, - p->frame.payload_len); - trans_p->frame.payload = (uint8_t *) & (data_buffer[transceiver_buffer_pos * AT86RF231_MAX_DATA_LENGTH]); - trans_p->frame.payload_len = p->frame.payload_len; - eINT(); - -#if ENABLE_DEBUG - - if (trans_p->frame.fcf.dest_addr_m == IEEE_802154_SHORT_ADDR_M) { - if (trans_p->frame.fcf.src_addr_m == IEEE_802154_SHORT_ADDR_M) { - DEBUG("Packet %p was from %" PRIu16 " to %" PRIu16 ", size: %u\n", trans_p, *((uint16_t *) &trans_p->frame.src_addr[0]), *((uint16_t *) &trans_p->frame.dest_addr), trans_p->frame.payload_len); - } - else { - DEBUG("Packet %p was from %016" PRIx64 " to %" PRIu16 ", size: %u\n", trans_p, *((uint64_t *) &trans_p->frame.src_addr[0]), *((uint16_t *) &trans_p->frame.dest_addr), trans_p->frame.payload_len); - - } - } - else { - if (trans_p->frame.fcf.src_addr_m == IEEE_802154_SHORT_ADDR_M) { - DEBUG("Packet %p was from %" PRIu16 " to %016" PRIx64 ", size: %u\n", trans_p, *((uint16_t *) &trans_p->frame.src_addr[0]), *((uint64_t *) &trans_p->frame.dest_addr), trans_p->frame.payload_len); - } - else { - DEBUG("Packet %p was from %016" PRIx64 " to %016" PRIx64 ", size: %u\n", trans_p, *((uint64_t *) &trans_p->frame.src_addr[0]), *((uint16_t *) &trans_p->frame.dest_addr), trans_p->frame.payload_len); - - } - } - -#endif - DEBUG("Content: %s\n", trans_p->frame.payload); -} -#endif -/*------------------------------------------------------------------------------------*/ -/* - * @brief Sends a radio packet to the receiver - * - * @param t The transceiver device - * @param pkt Generic pointer to the packet (use ieee802154_packet_t for - * AT86RF231, CC2420, and MC1322X) - * - * @return A negative value if operation failed, 0 or the number of bytes sent otherwise. - */ -static int8_t send_packet(transceiver_type_t t, void *pkt) -{ - int8_t res = -1; -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X - ieee802154_packet_t *p = (ieee802154_packet_t *)pkt; - DEBUG("transceiver: Send packet to "); -#if ENABLE_DEBUG - - for (size_t i = 0; i < 8; i++) { - printf("%02x ", p->frame.dest_addr[i]); - } - - printf("\n"); -#endif -#else - radio_packet_t *p = (radio_packet_t *)pkt; - DEBUG("transceiver: Send packet to %" PRIu16 "\n", p->dst); - for (size_t i = 0; i < p->length; i++) { - DEBUG("%02x ", p->data[i]); - } - - DEBUG("\n"); -#endif - -#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY)) - cc110x_packet_t cc110x_pkt; -#endif -#ifdef MODULE_MC1322X - maca_packet_t *maca_pkt = (maca_packet_t *)maca_get_free_packet(); -#endif - -#ifdef MODULE_CC2420 - cc2420_packet_t cc2420_pkt; -#endif - -#ifdef MODULE_AT86RF231 - at86rf231_packet_t at86rf231_pkt; -#endif - - switch (t) { - case TRANSCEIVER_CC1100: -#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY)) - cc110x_pkt.length = p->length + CC1100_HEADER_LENGTH; - cc110x_pkt.address = p->dst; - cc110x_pkt.flags = 0; - memcpy(cc110x_pkt.data, p->data, p->length); - res = cc110x_send(&cc110x_pkt); -#elif MODULE_CC110X_LEGACY_CSMA - memcpy(cc1100_pkt, p->data, p->length); - - res = cc1100_send_csmaca(p->dst, 4, 0, (char *) cc1100_pkt, p->length); - DEBUG("transceiver: snd_ret (%u) = %i\n", p->length, res); -#else - puts("Unknown transceiver"); -#endif - break; -#ifdef MODULE_CC2420 - - case TRANSCEIVER_CC2420: - memcpy(&cc2420_pkt.frame, &p->frame, sizeof(ieee802154_frame_t)); - cc2420_pkt.length = p->frame.payload_len + IEEE_802154_FCS_LEN; - res = cc2420_send(&cc2420_pkt); - break; -#endif -#ifdef MODULE_MC1322X - - case TRANSCEIVER_MC1322X: - maca_pkt->length = p->length; - memcpy(maca_pkt->data, &p->frame, p->length); - maca_set_tx_packet(maca_pkt); - res = 1; - break; -#endif -#ifdef MODULE_NATIVENET - - case TRANSCEIVER_NATIVE: - res = nativenet_send(p); - break; -#endif -#ifdef MODULE_AT86RF231 - - case TRANSCEIVER_AT86RF231: - memcpy(&at86rf231_pkt.frame, &p->frame, sizeof(ieee802154_frame_t)); - at86rf231_pkt.length = p->frame.payload_len + IEEE_802154_FCS_LEN; - res = at86rf231_send(&at86rf231_pkt); - break; -#endif - - default: - puts("Unknown transceiver"); - break; - } - - return res; -} - -/*------------------------------------------------------------------------------------*/ -/* - * @brief Sets the radio channel for any transceiver device - * - * @param t The transceiver device - * @param channel The channel to be set - * - * @return The radio channel AFTER calling the set command, -1 on error - */ -static int32_t set_channel(transceiver_type_t t, void *channel) -{ - /* cppcheck: c is read depending on enabled modules */ - /* cppcheck-suppress unreadVariable */ - uint8_t c = *((uint8_t *)channel); - - switch (t) { - case TRANSCEIVER_CC1100: -#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY)) - return cc110x_set_channel(c); -#elif MODULE_CC110X_LEGACY_CSMA - return cc1100_set_channel(c); -#else - return -1; -#endif -#ifdef MODULE_CC2420 - - case TRANSCEIVER_CC2420: - return cc2420_set_channel(c); -#endif -#ifdef MODULE_MC1322X - - case TRANSCEIVER_MC1322X: - maca_set_channel(c); - return c; ///< TODO: should be changed!implement get channel -#endif -#ifdef MODULE_NATIVENET - - case TRANSCEIVER_NATIVE: - return nativenet_set_channel(c); -#endif -#ifdef MODULE_AT86RF231 - - case TRANSCEIVER_AT86RF231: - return at86rf231_set_channel(c); -#endif - - default: - return -1; - } -} - -/* - * @brief Get the radio channel of any transceiver device - * - * @param t The transceiver device - * - * @return The current radio channel of the transceiver, -1 on error - */ -static int32_t get_channel(transceiver_type_t t) -{ - switch (t) { - case TRANSCEIVER_CC1100: -#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY)) - return cc110x_get_channel(); -#elif MODULE_CC110X_LEGACY_CSMA - return cc1100_get_channel(); -#else - return -1; -#endif -#ifdef MODULE_CC2420 - - case TRANSCEIVER_CC2420: - return cc2420_get_channel(); -#endif -#ifdef MODULE_MC1322X - - case TRANSCEIVER_MC1322X: - ///< TODO:implement return maca_get_channel(); - return -1; -#endif -#ifdef MODULE_NATIVENET - - case TRANSCEIVER_NATIVE: - return nativenet_get_channel(); -#endif -#ifdef MODULE_AT86RF231 - - case TRANSCEIVER_AT86RF231: - return at86rf231_get_channel(); -#endif - - default: - return -1; - } -} - -/*------------------------------------------------------------------------------------*/ -/* - * @brief Sets the PAN for any transceiver device - * - * @param t The transceiver device - * @param pan The PAN to be set - * - * @return The PAN AFTER calling the set command, -1 on error - */ -static int32_t set_pan(transceiver_type_t t, void *pan) -{ - uint16_t c = *((uint16_t *) pan); - - switch (t) { -#ifdef MODULE_CC2420 - - case TRANSCEIVER_CC2420: - return cc2420_set_pan(c); -#endif -#ifdef MODULE_NATIVENET - - case TRANSCEIVER_NATIVE: - return nativenet_set_pan(c); -#endif -#ifdef MODULE_AT86RF231 - - case TRANSCEIVER_AT86RF231: - return at86rf231_set_pan(c); -#endif -#ifdef MODULE_MC1322X - - case TRANSCEIVER_MC1322X: - return maca_set_pan(c); -#endif - - default: - /* get rid of compiler warning about unused variable */ - (void) c; - return -1; - } -} - -/* - * @brief Get the pan of any transceiver device - * - * @param t The transceiver device - * - * @return The current pan of the transceiver, -1 on error - */ -static int32_t get_pan(transceiver_type_t t) -{ - switch (t) { -#ifdef MODULE_CC2420 - - case TRANSCEIVER_CC2420: - return cc2420_get_pan(); -#endif -#ifdef MODULE_NATIVENET - - case TRANSCEIVER_NATIVE: - return nativenet_get_pan(); -#endif -#ifdef MODULE_AT86RF231 - - case TRANSCEIVER_AT86RF231: - return at86rf231_get_pan(); -#endif -#ifdef MODULE_MC1322X - - case TRANSCEIVER_MC1322X: - return maca_get_pan(); -#endif - - default: - return -1; - } -} -/*------------------------------------------------------------------------------------*/ -/* - * @brief Get the current address of transceiver device - * - * @param t The transceiver device - * - * @return The configured address of the device - * - * TODO: define error behavior - */ -static radio_address_t get_address(transceiver_type_t t) -{ - switch (t) { - case TRANSCEIVER_CC1100: -#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY)) - return cc110x_get_address(); -#elif MODULE_CC110X_LEGACY_CSMA - return cc1100_get_address(); -#else - return 0; /* XXX see TODO above */ -#endif -#ifdef MODULE_CC2420 - - case TRANSCEIVER_CC2420: - return cc2420_get_address(); -#endif -#ifdef MODULE_MC1322X - - case TRANSCEIVER_MC1322X: - return maca_get_address(); -#endif -#ifdef MODULE_NATIVENET - - case TRANSCEIVER_NATIVE: - return nativenet_get_address(); -#endif -#ifdef MODULE_AT86RF231 - - case TRANSCEIVER_AT86RF231: - return at86rf231_get_address(); -#endif - - default: - return 0; /* XXX see TODO above */ - } -} - -/* - * @brief Set the address of the transceiver device - * - * @param t The transceiver device - * @param address Generic pointer to the address to set - * - * @return The new radio address of the device - * - * TODO: define error behavior - */ -static radio_address_t set_address(transceiver_type_t t, void *address) -{ - /* cppcheck: addr is read depending on enabled modules */ - /* cppcheck-suppress unreadVariable */ - radio_address_t addr = *((radio_address_t *)address); - - switch (t) { - case TRANSCEIVER_CC1100: -#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY)) - return cc110x_set_address(addr); -#elif MODULE_CC110X_LEGACY_CSMA - return cc1100_set_address(addr); -#else - return 0; /* XXX see TODO above */ -#endif -#ifdef MODULE_CC2420 - - case TRANSCEIVER_CC2420: - return cc2420_set_address(addr); -#endif -#ifdef MODULE_MC1322X - - case TRANSCEIVER_MC1322X: - return maca_set_address(addr); -#endif -#ifdef MODULE_NATIVENET - - case TRANSCEIVER_NATIVE: - return nativenet_set_address(addr); -#endif -#ifdef MODULE_AT86RF231 - - case TRANSCEIVER_AT86RF231: - return at86rf231_set_address(addr); -#endif - - default: - return 0; /* XXX see TODO above */ - } -} - -/* - * @brief Get the current long address of transceiver device - * - * @param t The transceiver device - * - * @return The configured long address of the device, 0 on error - */ -static transceiver_eui64_t get_long_addr(transceiver_type_t t) -{ - switch (t) { -#ifdef MODULE_CC2420 - - case TRANSCEIVER_CC2420: - return cc2420_get_address_long(); -#endif -#ifdef MODULE_AT86RF231 - - case TRANSCEIVER_AT86RF231: - return at86rf231_get_address_long(); -#endif - - default: - return 0; - } -} - -/* - * @brief Set the long address of the transceiver device - * - * @param t The transceiver device - * @param address Generic pointer to the long address to set - * - * @return The new long radio address of the device, 0 on error - */ -static transceiver_eui64_t set_long_addr(transceiver_type_t t, void *address) -{ - uint64_t addr = *((uint64_t *)address); - - switch (t) { -#ifdef MODULE_CC2420 - - case TRANSCEIVER_CC2420: - return cc2420_set_address_long(addr); -#endif -#ifdef MODULE_AT86RF231 - - case TRANSCEIVER_AT86RF231: - return at86rf231_set_address_long(addr); -#endif - - default: - (void) addr; - return 0; - } -} - -/* - * @brief Set the transceiver device into monitor mode (disabling address check) - * - * @param t The transceiver device - * @param mode 1 for enabling monitor mode, 0 for enabling address check - */ -static void set_monitor(transceiver_type_t t, void *mode) -{ - (void) mode; - - switch (t) { -#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY)) - - case TRANSCEIVER_CC1100: - cc110x_set_monitor(*((uint8_t *)mode)); - break; -#endif -#ifdef MODULE_CC2420 - - case TRANSCEIVER_CC2420: - cc2420_set_monitor(*((uint8_t *) mode)); - break; -#endif -#ifdef MODULE_NATIVENET - - case TRANSCEIVER_NATIVE: - nativenet_set_monitor(*((uint8_t *) mode)); - break; -#endif -#ifdef MODULE_AT86RF231 - - case TRANSCEIVER_AT86RF231: - at86rf231_set_monitor(*((uint8_t *) mode)); -#endif - - default: - break; - } -} - -#ifdef MODULE_CC110X_LEGACY_CSMA -void cc1100_packet_monitor(void *payload, int payload_size, protocol_t protocol, packet_info_t *packet_info) -{ - (void) protocol; - - cc1100_payload = payload; - cc1100_payload_size = payload_size - 3; - cc1100_packet_info = packet_info; - receive_packet(TRANSCEIVER_CC1100, 0); -} -#endif - -/*------------------------------------------------------------------------------------*/ -static void powerdown(transceiver_type_t t) -{ - switch (t) { -#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY)) - - case TRANSCEIVER_CC1100: - cc110x_switch_to_pwd(); - break; -#endif -#ifdef MODULE_MC1322X - - case TRANSCEIVER_MC1322X: - maca_off(); - break; -#endif -#ifdef MODULE_NATIVENET - - case TRANSCEIVER_NATIVE: - nativenet_powerdown(); - break; -#endif - - default: - break; - } -} - -/*------------------------------------------------------------------------------------*/ -static void switch_to_rx(transceiver_type_t t) -{ - switch (t) { -#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY)) - - case TRANSCEIVER_CC1100: - cc110x_switch_to_rx(); - break; -#endif -#ifdef MODULE_CC2420 - - case TRANSCEIVER_CC2420: - - cc2420_switch_to_rx(); - break; -#endif -#ifdef MODULE_NATIVENET - - case TRANSCEIVER_NATIVE: - nativenet_switch_to_rx(); - break; -#endif -#ifdef MODULE_AT86RF231 - - case TRANSCEIVER_AT86RF231: - at86rf231_switch_to_rx(); -#endif - - default: - break; - } -} - -#ifdef DBG_IGNORE -static int16_t ignore_add(transceiver_type_t transceiver, void *address) -{ - (void) transceiver; - radio_address_t addr = *((radio_address_t *)address); - - for (size_t i = 0; i < TRANSCEIVER_MAX_IGNORED_ADDR; i++) { - if (transceiver_ignored_addr[i] == 0) { - transceiver_ignored_addr[i] = addr; - DEBUG("addr %u will be ignored (%u)\n", addr, i); - return i; - } - } - - return -1; -} -#endif diff --git a/tests/nativenet/Makefile b/tests/nativenet/Makefile deleted file mode 100644 index 83469bae24..0000000000 --- a/tests/nativenet/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -APPLICATION = nativenet -include ../Makefile.tests_common - -BOARD_WHITELIST := native - -USEMODULE += nativenet -USEMODULE += transceiver - -include $(RIOTBASE)/Makefile.include - -FORCE: - touch main.c - -sender: CFLAGS += -DSENDER -sender: APPLICATION = nativenet_sender -sender: FORCE all - -test: - ./tests/01-tests.py diff --git a/tests/nativenet/README.md b/tests/nativenet/README.md deleted file mode 100644 index 1850de8f17..0000000000 --- a/tests/nativenet/README.md +++ /dev/null @@ -1,9 +0,0 @@ -Nativenet functionality test -============================ - -To build the sender it *needs* to be build first. So to test this use - -```bash -make clean sender -make all test -``` diff --git a/tests/nativenet/main.c b/tests/nativenet/main.c deleted file mode 100644 index c7d157a59e..0000000000 --- a/tests/nativenet/main.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (C) 2013 INRIA - * - * 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 tests - * @{ - * - * @file - * @brief Nativenet test application - * - * @author Oliver Hahm - * - * @} - */ - -#include -#include -#include -#include - -#include "hwtimer.h" -#include "board.h" -#include "transceiver.h" -#include "nativenet.h" -#include "msg.h" -#include "thread.h" - -#define SENDER_ADDR (1) -#define DEFAULT_RCV_ADDR (2) - -#define PACKET_SIZE (42) -#define WAIT_TIME (60) -#define SECOND (1000 * 1000) -#define SENDING_DELAY (10 * 1000) - -#define RCV_BUFFER_SIZE (64) -#define RADIO_STACK_SIZE (THREAD_STACKSIZE_DEFAULT) - -static char radio_stack_buffer[RADIO_STACK_SIZE]; -static msg_t msg_q[RCV_BUFFER_SIZE]; -static uint8_t snd_buffer[NATIVE_MAX_DATA_LENGTH]; -static uint8_t receiving = 1; -static unsigned int last_seq = 0, missed_cnt = 0; -static int first = -1; - -void *radio(void *arg) -{ - (void) arg; - - msg_t m; - radio_packet_t *p; - unsigned int tmp = 0, cur_seq = 0; - - msg_init_queue(msg_q, RCV_BUFFER_SIZE); - - puts("Start receiving"); - - while (receiving) { - msg_receive(&m); - - if (m.type == PKT_PENDING) { - p = (radio_packet_t *) m.content.ptr; - - if ((p->src == SENDER_ADDR) && (p->length == PACKET_SIZE)) { - puts("received"); - cur_seq = (p->data[0] << 8) + p->data[1]; - - if (first < 0) { - first = cur_seq; - } - else { - tmp = cur_seq - last_seq; - - if (last_seq && (tmp > 1)) { - missed_cnt += (tmp - 1); - } - } - - last_seq = cur_seq; - } - else { - printf("sender was %i\n", p->src); - } - - p->processing--; - } - else if (m.type == ENOBUFFER) { - puts("Transceiver buffer full"); - } - else { - puts("Unknown packet received"); - } - } - - return NULL; -} - -void sender(void) -{ - unsigned int i = 0; - msg_t mesg; - transceiver_command_t tcmd; - radio_packet_t p; - - mesg.type = SND_PKT; - mesg.content.ptr = (char *) &tcmd; - - tcmd.transceivers = TRANSCEIVER_NATIVE; - tcmd.data = &p; - - p.length = PACKET_SIZE; - p.dst = 0; - - puts("Start sending packets"); - - while (1) { - /* filling uint8_t buffer with uint16_t sequence number */ - snd_buffer[0] = (i & 0xFF00) >> 8; - snd_buffer[1] = i & 0x00FF; - p.data = snd_buffer; - i++; - msg_send(&mesg, transceiver_pid); - hwtimer_wait(HWTIMER_TICKS(SENDING_DELAY)); - } -} - -int main(void) -{ - int16_t a; - msg_t mesg; - transceiver_command_t tcmd; - - printf("\n\tmain(): initializing transceiver\n"); - transceiver_init(TRANSCEIVER_NATIVE); - - printf("\n\tmain(): starting transceiver\n"); - transceiver_start(); - -#ifndef SENDER - printf("\n\tmain(): starting radio thread\n"); - kernel_pid_t radio_pid = thread_create( - radio_stack_buffer, sizeof(radio_stack_buffer), - THREAD_PRIORITY_MAIN - 2, CREATE_STACKTEST, - radio, NULL, "radio"); - transceiver_register(TRANSCEIVER_NATIVE, radio_pid); -#endif - -#ifdef SENDER - a = SENDER_ADDR; -#elif defined ADDR - a = ADDR; -#else - a = DEFAULT_RCV_ADDR; -#endif - tcmd.transceivers = TRANSCEIVER_NATIVE; - tcmd.data = &a; - mesg.content.ptr = (char *) &tcmd; - mesg.type = SET_ADDRESS; - - printf("[nativenet] trying to set address %" PRIi16 "\n", a); - msg_send_receive(&mesg, &mesg, transceiver_pid); - -#ifdef SENDER - hwtimer_wait(HWTIMER_TICKS(SECOND)); - sender(); -#else - hwtimer_wait(HWTIMER_TICKS(WAIT_TIME * SECOND)); - receiving = 0; - printf("Missed %u of %u packets after %u seconds\n", missed_cnt, (last_seq - first), WAIT_TIME); -#endif - - return 0; -} diff --git a/tests/nativenet/tests/01-tests.py b/tests/nativenet/tests/01-tests.py deleted file mode 100755 index 31af083eb8..0000000000 --- a/tests/nativenet/tests/01-tests.py +++ /dev/null @@ -1,38 +0,0 @@ -#! /usr/bin/env python - -import sys -from pexpect import spawn - -if __name__ == "__main__": - try: - if len(sys.argv) > 1: - expected_received = int(sys.argv[1]) - else: - expected_received = 5 - except TypeError: - sys.stderr.write("Usage: "+str(sys.argv[0])+" []\n") - sys.exit(1) - - receiver = spawn("bin/native/nativenet.elf tap0") - sender = spawn("bin/native/nativenet_sender.elf tap1") - - - receiver.expect(r"main\(\): initializing transceiver") - receiver.expect(r"main\(\): starting transceiver") - receiver.expect(r"main\(\): starting radio thread") - receiver.expect("Start receiving") - receiver.expect(r"\[nativenet\] trying to set address \d+") - - sender.expect(r"main\(\): initializing transceiver") - sender.expect(r"main\(\): starting transceiver") - sender.expect(r"\[nativenet\] trying to set address \d+") - sender.expect("Start sending packets") - - while expected_received > 0: - receiver.expect("received") - expected_received -= 1 - - if not sender.terminate(): - sender.terminate(force=True) - if not receiver.terminate(): - receiver.terminate(force=True) diff --git a/tests/net_if/Makefile b/tests/net_if/Makefile deleted file mode 100644 index c8020cd321..0000000000 --- a/tests/net_if/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -APPLICATION = net_if - -include ../Makefile.tests_common - -ifeq ($(BOARD),stm32f4discovery) - include Makefile.$(BOARD) -endif - -USEMODULE += net_if -USEMODULE += defaulttransceiver - -include $(RIOTBASE)/Makefile.include diff --git a/tests/net_if/main.c b/tests/net_if/main.c deleted file mode 100644 index fca6753290..0000000000 --- a/tests/net_if/main.c +++ /dev/null @@ -1,442 +0,0 @@ -/* - * Copyright (C) 2013 Martine Lenders - * - * 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. - */ - -#include -#include -#include - -#include "net_if.h" -#include "net_help.h" -#include "transceiver.h" - -int initialize_tests(void); -int test_net_if_initialization(int iface); -int test_net_if_get_add_l3p_types(int iface); -int test_net_if_add_address(int iface, net_if_addr_t *addr1, - net_if_addr_t *addr2); -int test_net_if_del_address(int iface, net_if_addr_t *addr1, - net_if_addr_t *addr2); -int test_net_if_get_set_hardware_address(int iface, uint16_t addr); -int test_net_if_get_set_pan_id(int iface); -int test_net_if_get_set_eui64(int iface, net_if_eui64_t *eui64, - uint16_t addr); - -int main(void) -{ - int iface; - char *addr1_data = "abcdefgh", *addr2_data = "12345678"; - net_if_addr_t addr1 = { - .addr_next = NULL, - .addr_prev = NULL, - .addr_protocol = NET_IF_L3P_IPV6_MULTICAST, - .addr_data = (void *)addr1_data, - .addr_len = (strlen(addr1_data) + 1) * 8 - }; - net_if_addr_t addr2 = { - .addr_next = NULL, - .addr_prev = NULL, - .addr_protocol = NET_IF_L3P_IPV6_PREFIX, - .addr_data = (void *)addr2_data, - .addr_len = (strlen(addr2_data) + 1) * 8 - }; - uint16_t own = 1, target = 2; - net_if_eui64_t eui64; - - iface = initialize_tests(); - - if (!test_net_if_initialization(iface)) { - printf("FAILED: test_net_if_initialization()\n"); - return -1; - } - - if (!test_net_if_get_add_l3p_types(iface)) { - printf("FAILED: test_net_if_get_add_l3p_types()\n"); - return -1; - } - - if (!test_net_if_add_address(iface, &addr1, &addr2)) { - printf("FAILED: test_net_if_add_address()\n"); - return -1; - } - - if (!test_net_if_del_address(iface, &addr1, &addr2)) { - printf("FAILED: test_net_if_del_address()\n"); - return -1; - } - - if (!test_net_if_get_set_hardware_address(iface, own)) { - printf("FAILED: test_net_if_get_set_hardware_address()\n"); - return -1; - } - - if (!test_net_if_get_set_pan_id(iface)) { - printf("FAILED: test_net_if_get_set_pan_id()\n"); - return -1; - } - - if (!test_net_if_get_set_eui64(iface, &eui64, own)) { - printf("FAILED: test_net_if_get_set_eui64()\n"); - return -1; - } - - int count = net_if_send_packet(iface, target, "Test", 4); - - printf("Count was %i after net_if_send_packet()\n", count); - - printf("All test ran successfully.\n"); - - return 0; -} - -int initialize_tests(void) -{ - int iface; - -#ifndef MODULE_AUTO_INIT - transceiver_init(TRANSCEIVER_DEFAULT); - transceiver_start(); - net_if_init(); - iface = net_if_init_interface(0, TRANSCEIVER_DEFAULT); - return iface; -#else - iface = -1; - - while ((iface = net_if_iter_interfaces(iface)) >= 0) { - return iface; - } - - return iface; -#endif -} - -int test_net_if_initialization(int iface) -{ - net_if_addr_t *addr_ptr = NULL; - - if (net_if_get_l3p_types(iface)) { - printf("FAILED: No L3 type expected on interface %d.\n", iface); - return 0; - } - - if (net_if_iter_addresses(iface + 1, &addr_ptr)) { - printf("FAILED: Expected error on interface '%d'\n", iface + 1); - return 0; - } - - if (net_if_iter_addresses(iface, &addr_ptr)) { - printf("FAILED: Expected error on interface '%d'\n", iface); - return 0; - } - - return 1; -} - -int test_net_if_get_add_l3p_types(int iface) -{ - if (net_if_add_l3p_types(iface + 1, NET_IF_L3P_IPV6_UNICAST)) { - printf("FAILED: expected net_if_add_l3p_types to fail for iface %d.\n", - iface + 1); - return 0; - } - - if (!net_if_add_l3p_types(iface, 0)) { - printf("FAILED: expected net_if_add_l3p_types to succeed for iface %d and no type\n", - iface); - return 0; - } - - - if (!net_if_add_l3p_types(iface, NET_IF_L3P_IPV6_UNICAST)) { - printf("FAILED: expected net_if_add_l3p_types to succeed for iface %d and no type\n", - iface); - return 0; - } - - if (!(net_if_get_l3p_types(iface) & NET_IF_L3P_IPV6_UNICAST)) { - printf("FAILED: L3 type IPv6 unicast expected on interface %d.\n", iface); - return 0; - } - - if (net_if_get_l3p_types(iface) & ~NET_IF_L3P_IPV6_UNICAST) { - printf("FAILED: L3 type other than IPv6 unicast not expected on interface %d.\n", - iface); - return 0; - } - - if (net_if_del_l3p_types(iface + 1, NET_IF_L3P_IPV6_UNICAST)) { - printf("FAILED: expected net_if_del_l3p_types to fail for iface %d.\n", - iface + 1); - return 0; - } - - if (!net_if_del_l3p_types(iface, 0)) { - printf("FAILED: expected net_if_del_l3p_types to succeed for iface %d and no type\n", - iface); - return 0; - } - - if (!net_if_del_l3p_types(iface, NET_IF_L3P_IPV6_UNICAST)) { - printf("FAILED: expected net_if_del_l3p_types to succeed for iface %d and no type\n", - iface); - return 0; - } - - if (net_if_get_l3p_types(iface)) { - printf("FAILED: No L3 type expected on interface %d.\n", iface); - return 0; - } - - return 1; -} - -int test_net_if_add_address(int iface, net_if_addr_t *addr1, - net_if_addr_t *addr2) -{ - int count = 0; - net_if_addr_t *addr_ptr = NULL; - - if (net_if_add_address(iface + 1, addr1)) { - printf("FAILED: expected net_if_add_address(%d, %p) to fail.\n", - iface + 1, (void *)addr1); - return 0; - } - - if (net_if_add_address(iface, NULL)) { - printf("FAILED: expected net_if_add_address(%d, NULL) to fail.\n", - iface); - return 0; - } - - if (!net_if_add_address(iface, addr1)) { - printf("FAILED: Address addition failed\n"); - return 0; - } - - if (!(net_if_get_l3p_types(iface) & NET_IF_L3P_IPV6_MULTICAST)) { - printf("FAILED: L3 type IPv6 multicast expected on interface %d.\n", iface); - return 0; - } - - if (net_if_get_l3p_types(iface) & ~NET_IF_L3P_IPV6_MULTICAST) { - printf("FAILED: L3 type other than IPv6 multicast not expected on interface %d.\n", - iface); - return 0; - } - - if (!net_if_add_address(iface, addr2)) { - printf("FAILED: Address addition failed\n"); - return 0; - } - - if (!(net_if_get_l3p_types(iface) & NET_IF_L3P_IPV6_MULTICAST)) { - printf("FAILED: L3 type IPv6 multcast expected on interface %d.\n", iface); - return 0; - } - - if (!(net_if_get_l3p_types(iface) & NET_IF_L3P_IPV6_PREFIX)) { - printf("FAILED: L3 type IPv6 prefix expected on interface %d.\n", iface); - return 0; - } - - if (net_if_get_l3p_types(iface) & ~(NET_IF_L3P_IPV6_MULTICAST | NET_IF_L3P_IPV6_PREFIX)) { - printf("FAILED: L3 type other than IPv6 multicast and IPv6 prefix not expected on interface %d.\n", - iface); - return 0; - } - - while (net_if_iter_addresses(iface, &addr_ptr)) { - if (addr_ptr == addr1 || addr_ptr == addr2) { - count++; - } - } - - if (count != 2) { - printf("FAILED: expected 2 addresses in iface's address list once respectively\n"); - printf(" missing '%d'\n", 2 - count); - return 0; - } - - return 1; -} - -int test_net_if_del_address(int iface, net_if_addr_t *addr1, - net_if_addr_t *addr2) -{ - int count = 0; - net_if_addr_t *addr_ptr = NULL; - - if (net_if_del_address(iface + 1, addr1)) { - printf("FAILED: expected net_if_del_address(%d, %p) to fail.\n", - iface + 1, (void *)addr1); - return 0; - } - - if (net_if_del_address(iface, NULL)) { - printf("FAILED: expected net_if_del_address(%d, NULL) to fail.\n", - iface); - return 0; - } - - if (!net_if_del_address(iface, addr1)) { - printf("FAILED: Address deletion failed\n"); - return 0; - } - - while (net_if_iter_addresses(iface, &addr_ptr)) { - if (addr_ptr == addr1 || addr_ptr == addr2) { - count++; - } - } - - if (count != 1) { - printf("FAILED: expected 1 address in iface's address list\n"); - printf(" missing '%d'\n", 1 - count); - return 0; - } - - return 1; -} - -int test_net_if_get_set_hardware_address(int iface, uint16_t addr) -{ - uint16_t tmp; - - if (net_if_set_hardware_address(iface + 1, addr)) { - printf("FAILED: expected net_if_set_hardware_address(%d, %d) to fail.\n", - iface + 1, addr); - return 0; - } - - if (net_if_set_hardware_address(iface, 0)) { - printf("FAILED: expected net_if_set_hardware_address(%d, 0) to fail.\n", - iface); - return 0; - } - - tmp = net_if_set_hardware_address(iface, addr); - - if (addr != tmp) { - printf("FAILED: Expected '%d' as result of net_if_set_hardware_addr() " - "(was '%d')\n", addr, tmp); - return 0; - } - - tmp = net_if_get_hardware_address(iface); - - if (addr != tmp) { - printf("FAILED: Expected '%d' as result of net_if_get_hardware_addr() " - "(was '%d')\n", addr, tmp); - return 0; - } - - return 1; -} - -int test_net_if_get_set_pan_id(int iface) -{ - uint16_t pan_id = 0xabcd; - - if (net_if_get_pan_id(iface + 1) >= 0) { - printf("FAILED: net_if_get_pan_id(%d) not failed\n", iface); - return 0; - } - - if (net_if_set_pan_id(iface, pan_id) < 0) { - printf("FAILED: net_if_set_pan_id(%d, 0x%04x) failed\n", iface, pan_id); - return 0; - } - -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X - int32_t res = net_if_get_pan_id(iface); - if (res < 0) { - printf("FAILED: net_if_get_pan_id(%d) failed\n", iface); - return 0; - } - - pan_id = (uint16_t) res; -#else - pan_id = 0; -#endif - - return 1; -} - -int test_net_if_get_set_eui64(int iface, net_if_eui64_t *eui64, - uint16_t addr) -{ - if (net_if_get_eui64(NULL, iface, 1)) { - printf("FAILED: expected net_if_get_eui64(NULL, %d, 1) to fail\n", - iface); - return 0; - } - - if (!net_if_get_eui64(eui64, iface, 1)) { - printf("FAILED: Error getting EUI-64 on interface %d\n", iface); - return 0; - } - - if (eui64->uint16[0] != 0 || eui64->uint8[2] != 0 || - eui64->uint8[3] != 0xff || eui64->uint8[4] != 0xfe || - eui64->uint8[5] != 0 || (uint16_t)eui64->uint16[3] != HTONS(addr)) { - printf("FAILED: Expected last 16 bit of EUI-64 to be 0x%04x (is 0x%04x)\n", - addr, NTOHS(eui64->uint16[3])); - return 0; - } - - eui64->uint64 = 0; - - if (net_if_set_eui64(iface, NULL)) { - printf("FAILED: expected error on net_if_set_eui64(%d, NULL)\n", iface); - return 0; - } - - if (net_if_set_eui64(iface, eui64)) { - printf("FAILED: expected error trying to set EUI-64 to broadcast\n"); - return 0; - } - -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X - eui64->uint8[0] = 0x11; - eui64->uint8[1] = 0x22; - eui64->uint8[2] = 0x33; - eui64->uint8[3] = 0x44; - eui64->uint8[4] = 0x55; - eui64->uint8[5] = 0x66; - eui64->uint8[6] = 0x77; - eui64->uint8[7] = 0x88; - - if (!net_if_set_eui64(iface, eui64)) { - printf("FAILED: Error setting EUI-64 on interface %d\n", iface); - return 0; - } - - eui64->uint64 = 0; - - if (!net_if_get_eui64(eui64, iface, 0)) { - printf("FAILED: Error getting EUI-64 on interface %d\n", iface); - return 0; - } - - /* transceivers that do not support EUI-64 addresses convert automatically - * so we have to test both cases */ - if (eui64->uint8[0] != 0x11 || eui64->uint8[1] != 0x22 || - eui64->uint8[2] != 0x33 || eui64->uint8[3] != 0x44 || - eui64->uint8[4] != 0x55 || eui64->uint8[5] != 0x66 || - eui64->uint8[6] != 0x77 || eui64->uint8[7] != 0x88) { - printf("FAILED: EUI-64 to be 11-22-33-44-55-66-77-88 but is " - "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x\n", - eui64->uint8[0], eui64->uint8[1], eui64->uint8[2], - eui64->uint8[3], eui64->uint8[4], eui64->uint8[5], - eui64->uint8[6], eui64->uint8[7]); - return 0; - } - -#endif - - return 1; -} diff --git a/tests/netdev/Makefile b/tests/netdev/Makefile deleted file mode 100644 index 55058abdf4..0000000000 --- a/tests/netdev/Makefile +++ /dev/null @@ -1,48 +0,0 @@ - -SENDER ?= 0 -ifeq (0,$(SENDER)) - export APPLICATION = netdev_receiver -else - export APPLICATION = netdev_sender -endif - -include ../Makefile.tests_common - -USEMODULE += defaulttransceiver -USEMODULE += net_help -USEMODULE += netdev_base - -DISABLE_MODULE += auto_init - -CHANNEL ?= 1 -SENDER_ADDRESS ?= 1 -RECEIVER_ADDRESS ?= 2 -NID ?= 0 - -ifeq (native,$(BOARD)) - RECEIVER_PORT ?= tap0 - SENDER_PORT ?= tap1 -else - RECEIVER_PORT ?= /dev/ttyUSB1 - SENDER_PORT ?= /dev/ttyUSB0 -endif - -ifeq (0,$(SENDER)) - CFLAGS += -DRECEIVER - CFLAGS += -DNETDEV_TEST_ADDRESS=$(RECEIVER_ADDRESS) - PORT ?= $(RECEIVER_PORT) -else - CFLAGS += -DSENDER - CFLAGS += -DNETDEV_TEST_ADDRESS=$(SENDER_ADDRESS) - PORT ?= $(SENDER_PORT) -endif - -include $(RIOTBASE)/Makefile.include - -CFLAGS += -DNETDEV_TEST_CHANNEL=$(CHANNEL) -CFLAGS += -DNETDEV_TEST_NID=$(NID) -CFLAGS += -DNETDEV_TEST_RECEIVER=$(RECEIVER_ADDRESS) -CFLAGS += -DNETDEV_TEST_SENDER=$(SENDER_ADDRESS) - -test: - ./tests/01-interaction.py diff --git a/tests/netdev/README.md b/tests/netdev/README.md deleted file mode 100644 index 98347139ab..0000000000 --- a/tests/netdev/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# netdev tests -This application tests the module `netdev`, it's base module `netdev_base` in -particular. -The tests can be automated by running - -```bash -SENDER=0 make all flash && SENDER=1 make all flash && make test -``` - -The values of the network addresses, the channel, and the network ID can be -configured by the environment variables - -* `NETDEV_TEST_RECEIVER` and `NETDEV_TEST_SENDER`, -* `NETDEV_TEST_CHANNEL`, -* `NETDEV_TEST_NID` - -You can set the role of the application by setting the `SENDER` variable to -either 0 (application is receiver) or any other value (applictation is sender), -but keep in mind, that both versions have to be flashed to to seperate devices -(identified by `RECEIVER_PORT` and `SENDER_PORT` respectively) in order for -`make test` to succeed. diff --git a/tests/netdev/main.c b/tests/netdev/main.c deleted file mode 100644 index f6d298e1ba..0000000000 --- a/tests/netdev/main.c +++ /dev/null @@ -1,1085 +0,0 @@ -/* - * Copyright (C) 2014 Martine Lenders - * - * 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 tests - * @{ - * - * @file - * @brief Tests for general network device interface - * - * - * @author Martine Lenders - * - * @} - */ - -#include -#include -#include -#include - -#ifdef MODULE_NATIVENET -#include "nativenet.h" -#endif - -#include "net_help.h" -#include "netdev/base.h" -#include "netdev/default.h" - -#ifdef NETDEV_DEFAULT -#define SHELL_BUFSIZE (UART0_BUFSIZE) - -static size_t dev_address_len = 0; -static netdev_t *dev = NULL; - -/*********************************** - * helper functions * - ***********************************/ -static inline int _got_uint8_value(char *param_name, uint8_t *value_ptr, size_t value_len, - uint8_t check_value, uint8_t value_exp) -{ - printf("Got %s of value %" PRIu8 " of length %zu\n", param_name, *value_ptr, value_len); - - if (check_value) { - return (*value_ptr == value_exp) ? 1 : 0; - } - else { - return 1; - } -} - -static inline int _got_uint16_value(char *param_name, uint16_t *value_ptr, size_t value_len, - uint8_t check_value, uint16_t value_exp) -{ - printf("Got %s of value %" PRIu16 " of length %zu\n", param_name, *value_ptr, value_len); - - if (check_value) { - return (*value_ptr == value_exp) ? 1 : 0; - } - else { - return 1; - } -} - -static inline int _got_uint32_value(char *param_name, uint32_t *value_ptr, size_t value_len, - uint8_t check_value, uint32_t value_exp) -{ - printf("Got %s of value %" PRIu32 " of length %zu\n", param_name, *value_ptr, value_len); - - if (check_value) { - return (*value_ptr == value_exp) ? 1 : 0; - } - else { - return 1; - } -} - -static inline int _got_uint64_value(char *param_name, uint64_t *value_ptr, size_t value_len, - uint8_t check_value, uint64_t value_exp) -{ - printf("Got %s of value %" PRIu64 " of length %zu\n", param_name, *value_ptr, value_len); - - if (check_value) { - return (*value_ptr == value_exp) ? 1 : 0; - } - else { - return 1; - } -} - -/*********************************** - * test channel * - ***********************************/ -static int init_channel(void) -{ - uint8_t channel = NETDEV_TEST_CHANNEL; - int res = dev->driver->set_option(dev, NETDEV_OPT_CHANNEL, - &channel, sizeof(uint8_t)); - - switch (res) { - case 0: - printf("Channel was set to %" PRIu8 "\n", channel); - return 1; - - case -EINVAL: - printf("Channel %" PRIu8 " not supported\n", channel); - break; - - case -ENODEV: - puts("Device was not initialized"); - break; - - case -ENOTSUP: - puts("Does not support setting the channel"); - return 2; - - case -EOVERFLOW: - puts("1 byte overflows o_o?!!?"); - break; - - default: - puts("unknown error"); - break; - } - - return 0; -} - -static int check_channel(void) -{ - uint8_t channel[sizeof(uint64_t)]; - size_t channel_len = sizeof(uint64_t); - int res = dev->driver->get_option(dev, NETDEV_OPT_CHANNEL, - &channel, &channel_len); - - switch (res) { - case 0: - switch (channel_len) { - case 1: - return _got_uint8_value("channel", (uint8_t *)channel, channel_len, 1, NETDEV_TEST_CHANNEL); - - case 2: - return _got_uint16_value("channel", (uint16_t *)channel, channel_len, 1, NETDEV_TEST_CHANNEL); - - case 4: - return _got_uint32_value("channel", (uint32_t *)channel, channel_len, 1, NETDEV_TEST_CHANNEL); - - case 8: - return _got_uint64_value("channel", (uint64_t *)channel, channel_len, 1, NETDEV_TEST_CHANNEL); - - default: - printf("Unexpected channel type of length %u:", channel_len); - - for (size_t i = 0; i < channel_len; i++) { - printf(" %02x", channel[i]); - } - - printf("\n"); - return 0; - } - - case -ENODEV: - puts("Device was not initialized"); - break; - - case -ENOTSUP: - puts("Does not support getting of channel"); - return 2; - - case -EOVERFLOW: - puts("Channel type bigger then 64 bit."); - break; - - default: - puts("unknown error"); - break; - } - - return 0; -} - -/*********************************** - * test address * - ***********************************/ -static int init_address(void) -{ - uint8_t address = NETDEV_TEST_ADDRESS; - int res = dev->driver->set_option(dev, NETDEV_OPT_ADDRESS, - &address, sizeof(uint8_t)); - - switch (res) { - case 0: - printf("Address was set to %" PRIu8 "\n", address); - return 1; - - case -EINVAL: - printf("Address %" PRIu8 " not supported\n", address); - break; - - case -ENODEV: - puts("Device was not initialized"); - break; - - case -ENOTSUP: - puts("Does not support setting the address"); - return 2; - - case -EOVERFLOW: - puts("1 byte overflows o_o?!!?"); - break; - - default: - puts("unknown error"); - break; - } - - return 0; -} - -static int check_address(void) -{ - uint8_t address[sizeof(uint64_t)]; - size_t address_len = sizeof(uint64_t); - int res = dev->driver->get_option(dev, NETDEV_OPT_ADDRESS, - &address, &address_len); - - switch (res) { - case 0: - dev_address_len = address_len; - - switch (address_len) { - case 1: - return _got_uint8_value("address", (uint8_t *)address, address_len, 1, NETDEV_TEST_ADDRESS); - - case 2: - return _got_uint16_value("address", (uint16_t *)address, address_len, 1, NETDEV_TEST_ADDRESS); - - case 4: - return _got_uint32_value("address", (uint32_t *)address, address_len, 1, NETDEV_TEST_ADDRESS); - - case 6: - printf("Got address of length %u of value: ", address_len); - - for (size_t i = 0; i < address_len; i++) { - printf(" %02x", address[i]); - } - - printf("\n"); - return 1; - - case 8: - return _got_uint64_value("address", (uint64_t *)address, address_len, 1, NETDEV_TEST_ADDRESS); - - default: - printf("Unexpected address type of length %u:", address_len); - - for (size_t i = 0; i < address_len; i++) { - printf(" %02x", address[i]); - } - - printf("\n"); - return 0; - } - - case -ENODEV: - puts("Device was not initialized"); - break; - - case -ENOTSUP: - puts("Does not support getting the address"); - return 2; - - case -EOVERFLOW: - puts("Address type bigger then 64 bit."); - break; - - default: - puts("unknown error"); - break; - } - - return 0; -} - -/*********************************** - * test long address * - ***********************************/ -static int init_long_address(void) -{ - uint8_t address = NETDEV_TEST_ADDRESS; - int res = dev->driver->set_option(dev, NETDEV_OPT_ADDRESS_LONG, - &address, sizeof(uint8_t)); - - switch (res) { - case 0: - printf("Long address was set to %" PRIu8 "\n", address); - return 1; - - case -EINVAL: - printf("Long address %" PRIu8 " not supported\n", address); - break; - - case -ENODEV: - puts("Device was not initialized"); - break; - - case -ENOTSUP: - puts("Does not support setting the long address"); - return 2; - - case -EOVERFLOW: - puts("1 byte overflows o_o?!!?"); - break; - - default: - puts("unknown error"); - break; - } - - return 0; -} - -static int check_long_address(void) -{ - uint8_t address[sizeof(uint64_t)]; - size_t address_len = sizeof(uint64_t); - int res = dev->driver->get_option(dev, NETDEV_OPT_ADDRESS_LONG, - &address, &address_len); - - switch (res) { - case 0: - switch (address_len) { - case 1: - return _got_uint8_value("long address", (uint8_t *)address, address_len, 1, NETDEV_TEST_ADDRESS); - - case 2: - return _got_uint16_value("long address", (uint16_t *)address, address_len, 1, NETDEV_TEST_ADDRESS); - - case 4: - return _got_uint32_value("long address", (uint32_t *)address, address_len, 1, NETDEV_TEST_ADDRESS); - - case 6: - printf("Got long address of length %u of value: ", address_len); - - for (size_t i = 0; i < address_len; i++) { - printf(" %02x", address[i]); - } - - printf("\n"); - return 1; - - case 8: - return _got_uint64_value("long address", (uint64_t *)address, address_len, 1, NETDEV_TEST_ADDRESS); - - default: - printf("Unexpected long address type of length %u:", address_len); - - for (size_t i = 0; i < address_len; i++) { - printf(" %02x", address[i]); - } - - printf("\n"); - return 0; - } - - case -ENODEV: - puts("Device was not initialized"); - break; - - case -ENOTSUP: - puts("Does not support getting the long address"); - return 2; - - case -EOVERFLOW: - puts("Long address type bigger then 64 bit."); - break; - - default: - puts("unknown error"); - break; - } - - return 0; -} - -/*********************************** - * test network ID * - ***********************************/ -static int init_nid(void) -{ - uint8_t nid = NETDEV_TEST_NID; - int res = dev->driver->set_option(dev, NETDEV_OPT_NID, - &nid, sizeof(uint8_t)); - - switch (res) { - case 0: - printf("Network ID was set to %" PRIu8 "\n", nid); - return 1; - - case -EINVAL: - printf("Network ID %" PRIu8 " not supported\n", nid); - break; - - case -ENODEV: - puts("Device was not initialized"); - break; - - case -ENOTSUP: - puts("Does not support setting the network ID"); - return 2; - - case -EOVERFLOW: - puts("1 byte overflows o_o?!!?"); - break; - - default: - puts("unknown error"); - break; - } - - return 0; -} - -static int check_nid(void) -{ - uint8_t nid[sizeof(uint64_t)]; - size_t nid_len = sizeof(uint64_t); - int res = dev->driver->get_option(dev, NETDEV_OPT_NID, - &nid, &nid_len); - - switch (res) { - case 0: - switch (nid_len) { - case 1: - return _got_uint8_value("network ID", (uint8_t *)nid, nid_len, 1, NETDEV_TEST_NID); - - case 2: - return _got_uint16_value("network ID", (uint16_t *)nid, nid_len, 1, NETDEV_TEST_NID); - - case 4: - return _got_uint32_value("network ID", (uint32_t *)nid, nid_len, 1, NETDEV_TEST_NID); - - case 8: - return _got_uint64_value("network ID", (uint64_t *)nid, nid_len, 1, NETDEV_TEST_NID); - - default: - printf("Unexpected network ID type of length %u:", nid_len); - - for (size_t i = 0; i < nid_len; i++) { - printf(" %02x", nid[i]); - } - - printf("\n"); - return 0; - } - - case -ENODEV: - puts("Device was not initialized"); - break; - - case -ENOTSUP: - puts("Does not support getting the network ID"); - return 2; - - case -EOVERFLOW: - puts("Network ID type bigger then 64 bit."); - break; - - default: - puts("unknown error"); - break; - } - - return 0; -} - -/*********************************** - * test maximum packet size * - ***********************************/ -static int check_max_packet_size(void) -{ - uint8_t mps[sizeof(uint64_t)]; - size_t mps_len = sizeof(uint64_t); - int res = dev->driver->get_option(dev, NETDEV_OPT_MAX_PACKET_SIZE, - &mps, &mps_len); - - switch (res) { - case 0: - switch (mps_len) { - case 1: - return _got_uint8_value("maximum packet size", (uint8_t *)mps, mps_len, 0, 0); - - case 2: - return _got_uint16_value("maximum packet size", (uint16_t *)mps, mps_len, 0, 0); - - case 4: - return _got_uint32_value("maximum packet size", (uint32_t *)mps, mps_len, 0, 0); - - case 8: - return _got_uint64_value("maximum packet size", (uint64_t *)mps, mps_len, 0, 0); - - default: - printf("Unexpected maximum packet size type of length %u:", mps_len); - - for (size_t i = 0; i < mps_len; i++) { - printf(" %02x", mps[i]); - } - - printf("\n"); - return 0; - } - - case -ENODEV: - puts("Device was not initialized"); - break; - - case -ENOTSUP: - puts("Does not support getting the maximum packet size"); - return 2; - - case -EOVERFLOW: - puts("Maximum packet size type bigger then 64 bit."); - break; - - default: - puts("unknown error"); - break; - } - - return 0; -} - -/*********************************** - * test protocol * - ***********************************/ -static int check_protocol(void) -{ - netdev_proto_t protocol; - size_t protocol_len = sizeof(netdev_proto_t); - int res = dev->driver->get_option(dev, NETDEV_OPT_PROTO, - &protocol, &protocol_len); - - switch (res) { - case 0: - if (protocol_len != sizeof(netdev_proto_t)) { - puts("Protocol type is not of length sizeof(netdev_proto_t)"); - return 0; - } - - switch (protocol) { - case NETDEV_PROTO_UNKNOWN: - puts("Got protocol: Unknown communication type"); - return 1; - - case NETDEV_PROTO_RADIO: - puts("Got protocol: Radio"); - return 1; - - case NETDEV_PROTO_802154: - puts("Got protocol: IEEE 802.15.4"); - return 1; - - case NETDEV_PROTO_6LOWPAN: - puts("Got protocol: 6LoWPAN"); - return 1; - - case NETDEV_PROTO_IPV6: - puts("Got protocol: IPv6"); - return 1; - - case NETDEV_PROTO_UDP: - puts("Got protocol: UDP"); - return 1; - - case NETDEV_PROTO_TCP: - puts("Got protocol: TCP"); - return 1; - - case NETDEV_PROTO_CCNL: - puts("Got protocol: CCN lite"); - return 1; - - case NETDEV_PROTO_CC110X: - puts("Got protocol: CC110x"); - return 1; - - default: - puts("You probably have to update this switch-case."); - return 0; - } - - case -ENODEV: - puts("Device was not initialized"); - break; - - case -ENOTSUP: - puts("Does not support getting the protocol"); - return 2; - - case -EOVERFLOW: - puts("Protocol type bigger then 64 bit."); - break; - - default: - puts("unknown error"); - break; - } - - return 0; -} - -/************************************* - * state tests * - *************************************/ -static int init_state(void) -{ - int res = dev->driver->set_state(dev, NETDEV_STATE_RX_MODE); - - switch (res) { - case 0: - puts("Device was set to RX mode"); - return 1; - - case -ENODEV: - puts("Device was not initialized"); - break; - - case -ENOTSUP: - puts("Device does not have a RX mode"); - return 2; - - case -ETIME: - puts("Device timed out setting to RX mode"); - break; - - default: - puts("unknown error"); - break; - } - - return 0; -} - -static int check_state(void) -{ - netdev_state_t state; - int res = dev->driver->get_state(dev, &state); - - switch (res) { - case 0: - switch (state) { - case NETDEV_STATE_POWER_OFF: - puts("Device is powered off"); - break; - - case NETDEV_STATE_POWER_SLEEP: - puts("Device is sleeping"); - break; - - case NETDEV_STATE_POWER_IDLE: - puts("Device is idle"); - break; - - case NETDEV_STATE_RX_MODE: - puts("Device is in RX mode"); - break; - - case NETDEV_STATE_PROMISCUOUS_MODE: - puts("Device is in promiscous mode"); - break; - - default: - puts("Device is in unknown state"); - return 0; - } - - return 1; - - case -ENODEV: - puts("Device was not initialized"); - break; - - case -ETIME: - puts("Device timed out getting to RX mode"); - break; - - default: - puts("unknown error"); - break; - } - - return 0; -} - -#ifdef SENDER -static int send_packet(void) -{ - netdev_hlist_t *hlist = NULL; - netdev_hlist_t header1 = {NULL, NULL, NETDEV_PROTO_UNKNOWN, "header 1,", 9}; - netdev_hlist_t header2 = {NULL, NULL, NETDEV_PROTO_UNKNOWN, "header 2,", 9}; - char payload[] = "payload"; - - netdev_hlist_add(&hlist, &header2); - netdev_hlist_add(&hlist, &header1); - - printf("Sending \"%s%s%s\" to", (char *)header1.header, (char *)header2.header, - payload); - - switch (dev_address_len) { - case 1: - do { /* open block to reduce scope of variable */ - uint8_t dest = NETDEV_TEST_RECEIVER; - - printf(" %" PRIu8 "\n", dest); - dev->driver->send_data(dev, &dest, dev_address_len, - hlist, payload, strlen(payload)); - } while (0); - - break; - - case 2: - do { /* open block to reduce scope of variable */ - uint16_t dest = NETDEV_TEST_RECEIVER; - - printf(" %" PRIu16 "\n", dest); - dev->driver->send_data(dev, &dest, dev_address_len, - hlist, payload, strlen(payload)); - } while (0); - - break; - - case 3: - do { /* open block to reduce scope of variable */ - uint16_t dest_int = HTONS(NETDEV_TEST_RECEIVER); - uint8_t dest[dev_address_len]; - - memset(dest, 0, dev_address_len - sizeof(uint16_t)); - memcpy(&(dest[dev_address_len - sizeof(uint16_t)]), &dest_int, - sizeof(uint16_t)); - - for (size_t i = 0; i < dev_address_len; i++) { - printf(" %02x", dest[i]); - } - - puts(""); - - dev->driver->send_data(dev, &dest, dev_address_len, - hlist, payload, strlen(payload)); - } while (0); - - case 4: - do { /* open block to reduce scope of variable */ - uint32_t dest = NETDEV_TEST_RECEIVER; - - printf(" %" PRIu32 "\n", dest); - dev->driver->send_data(dev, &dest, dev_address_len, hlist, - payload, strlen(payload)); - } while (0); - - break; - - case 8: - do { /* open block to reduce scope of variable */ - uint64_t dest = NETDEV_TEST_RECEIVER; - - printf(" %" PRIu64 "\n", dest); - dev->driver->send_data(dev, &dest, dev_address_len, - hlist, payload, strlen(payload)); - } while (0); - - break; - - default: - do { /* open block to reduce scope of variable */ - uint32_t dest_int = HTONL(NETDEV_TEST_RECEIVER); - uint8_t dest[dev_address_len]; - - memset(dest, 0, dev_address_len - sizeof(uint32_t)); - memcpy(&(dest[dev_address_len - sizeof(uint32_t)]), &dest_int, - sizeof(uint32_t)); - - for (size_t i = 0; i < dev_address_len; i++) { - printf(" %02x", dest[i]); - } - - puts(""); - - dev->driver->send_data(dev, &dest, dev_address_len, - hlist, payload, strlen(payload)); - } while (0); - - break; - } - - return 1; -} -#endif - -#ifdef RECEIVER -static int test_callback(netdev_t *rcv_dev, void *src, size_t src_len, - void *dest, size_t dest_len, void *payload, - size_t payload_len) -{ - uint8_t exp_src[dev_address_len]; - uint8_t exp_dest[dev_address_len]; - - if (rcv_dev != dev) { - printf("cb: Device is not the expected one: %p != %p\n", - (void *)rcv_dev, (void *)dev); - return -EINVAL; - } - - switch (dev_address_len) { - case 1: - exp_src[0] = NETDEV_TEST_SENDER; - exp_dest[0] = NETDEV_TEST_RECEIVER; - break; - - case 2: - do { /* open block to reduce scope of variable */ - uint16_t *exp_src_ptr = (uint16_t *)exp_src; - uint16_t *exp_dest_ptr = (uint16_t *)exp_dest; - *exp_src_ptr = NETDEV_TEST_SENDER; - *exp_dest_ptr = NETDEV_TEST_RECEIVER; - } while (0); - - break; - - case 3: - do { /* open block to reduce scope of variable */ - uint16_t exp_src_int = HTONS(NETDEV_TEST_SENDER); - uint16_t exp_dest_int = HTONS(NETDEV_TEST_RECEIVER); - memset(exp_dest, 0, dev_address_len - sizeof(uint16_t)); - memset(exp_src, 0, dev_address_len - sizeof(uint16_t)); - memcpy(&(exp_dest[dev_address_len - sizeof(uint16_t)]), - &exp_dest_int, sizeof(uint16_t)); - memcpy(&(exp_src[dev_address_len - sizeof(uint16_t)]), - &exp_src_int, sizeof(uint16_t)); - } while (0); - - break; - - case 4: - do { /* open block to reduce scope of variable */ - uint32_t *exp_src_ptr = (uint32_t *)exp_src; - uint32_t *exp_dest_ptr = (uint32_t *)exp_dest; - *exp_src_ptr = NETDEV_TEST_SENDER; - *exp_dest_ptr = NETDEV_TEST_RECEIVER; - } while (0); - - break; - - case 8: - do { /* open block to reduce scope of variable */ - uint64_t *exp_src_ptr = (uint64_t *)exp_src; - uint64_t *exp_dest_ptr = (uint64_t *)exp_dest; - *exp_src_ptr = NETDEV_TEST_SENDER; - *exp_dest_ptr = NETDEV_TEST_RECEIVER; - } while (0); - - break; - - default: - do { /* open block to reduce scope of variable */ - uint32_t exp_src_int = HTONL(NETDEV_TEST_SENDER); - uint32_t exp_dest_int = HTONL(NETDEV_TEST_RECEIVER); - memset(exp_dest, 0, dev_address_len - sizeof(uint32_t)); - memset(exp_src, 0, dev_address_len - sizeof(uint32_t)); - memcpy(&(exp_dest[dev_address_len - sizeof(uint32_t)]), - &exp_dest_int, sizeof(uint32_t)); - memcpy(&(exp_src[dev_address_len - sizeof(uint32_t)]), - &exp_src_int, sizeof(uint32_t)); - } while (0); - - break; - } - - if (src_len != dev_address_len || memcmp(exp_src, src, src_len) != 0) { - printf("cb: src is not from sender %d\n", NETDEV_TEST_SENDER); - return -EINVAL; - } - - if (dest_len != dev_address_len || memcmp(exp_dest, dest, dest_len) != 0) { - printf("cb: dest is not for receiver %d\n", NETDEV_TEST_SENDER); - return -EINVAL; - } - - if (strcmp(payload, "header 1,header 2,payload") != 0) { - puts("cb: payload is not as expected (\"header 1,header 2,payload\")"); - return -EINVAL; - } - - printf("Received \""); - - for (size_t i = 0; i < payload_len; i++) { - printf("%c", ((char *)payload)[i]); - } - - printf("\"\n"); - - printf("Sender was"); - - for (size_t i = 0; i < src_len; i++) { - printf(" %02x", ((char *)src)[i]); - } - - printf("\n"); - - return payload_len; -} - -static int init_receiver_callback(void) -{ - int res = dev->driver->add_receive_data_callback(dev, test_callback); - - switch (res) { - case 0: - puts("Added receive callback successfully."); - return 1; - - case -ENODEV: - puts("Device was not initialized"); - break; - - case -ENOBUFS: - puts("Can not add callback: no slot left"); - break; - - default: - puts("Unknown error"); - break; - } - - return 0; -} -#endif - -int main(void) -{ - int init_res; - - puts("\nRIOT netdev test"); - dev = NETDEV_DEFAULT; - - if (dev == NULL) { - puts("Default device was NULL"); - return 1; - } - - printf("Initialized dev "); - - switch (dev->type) { - case NETDEV_TYPE_UNKNOWN: - printf("of unknown type\n"); - break; - - case NETDEV_TYPE_BASE: - printf("as basic device\n"); - break; - - default: - printf("of undefined type\n"); - break; - } - - if (dev->driver == NULL) { - puts("Default driver is defined as NULL!"); - return 1; - } - - dev->driver->init(dev); - - if (!(init_res = init_channel())) { - return 1; - } - - if (check_channel() == 0) { - printf("Channel is not as expected. "); - - if (init_res == 2) { - printf("But initialization is not supported. Continuing.\n"); - } - else { - printf("Aborting\n"); - return 1; - } - } - - if (!(init_res = init_address())) { - return 1; - } - - if (check_address() == 0) { - printf("Address is not as expected. "); - - if (init_res == 2) { - printf("But initialization is not supported. Continuing.\n"); - } - else { - printf("Aborting\n"); - return 1; - } - } - - if (!(init_res = init_long_address())) { - return 1; - } - - if (check_long_address() == 0) { - printf("Long address is not as expected. "); - - if (init_res == 2) { - printf("But initialization is not supported. Continuing.\n"); - } - else { - printf("Aborting\n"); - return 1; - } - } - - if (!(init_res = init_nid())) { - return 1; - } - - if (check_nid() == 0) { - printf("Network ID is not as expected. "); - - if (init_res == 2) { - printf("But initialization is not supported. Continuing.\n"); - } - else { - printf("Aborting\n"); - return 1; - } - } - - if (check_max_packet_size() == 0) { - return 1; - } - - if (check_protocol() == 0) { - return 1; - } - - if (!init_state()) { - return 1; - } - - if (!check_state()) { - return 1; - } - -#ifdef SENDER - - if (!send_packet()) { - return 1; - } - -#elif RECEIVER - - if (!init_receiver_callback()) { - return 1; - } - -#endif - - return 0; -} - -#else - -int main(void) -{ - puts("\nRIOT netdev test"); - puts("Default netdev type and driver unknown!"); - - return 0; -} - -#endif /* !NETDEV_DEFAULT */ diff --git a/tests/netdev/tests/01-interaction.py b/tests/netdev/tests/01-interaction.py deleted file mode 100755 index 2580ac1973..0000000000 --- a/tests/netdev/tests/01-interaction.py +++ /dev/null @@ -1,142 +0,0 @@ -#!/usr/bin/env python - -# Copyright (C) 2014 Martine Lenders -# -# 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. - -import os, signal, sys, time -from pexpect import spawn, TIMEOUT, EOF - -class Abort(Exception): - pass - -board = os.environ.get('BOARD', 'native') - -DEFAULT_TIMEOUT=5 - -def main(): - receiver = None - sender = None - - if "PORT" in os.environ: - del os.environ["PORT"] - - if "TERMFLAGS" in os.environ: - del os.environ["TERMFLAGS"] - - try: - os.environ["SENDER"] = "0" - receiver = spawn("make term", timeout=5) - time.sleep(1) - os.environ["SENDER"] = "1" - sender = spawn("make term", timeout=5) - - receiver.expect(r"RIOT netdev test") - sender.expect(r"RIOT netdev test") - - i = receiver.expect([r"Default netdev type and driver unknown!", - r"Initialized dev "]) - if i == 0: - print('No netdev driver for board %s. Aborting test.' % board) - raise Abort - elif i == 1: - pass - - i = sender.expect([r"Default netdev type and driver unknown!", - r"Initialized dev "]) - if i == 0: - print('No netdev driver for board %s. Aborting test.' % board) - raise Abort - elif i == 1: - pass - - receiver.expect([r"Channel was set to [0-9]+", - r"Does not support setting the channel"]) - receiver.expect([r"Got channel of value [0-9]+ of length [0-9]+", - r"Does not support getting the channel"]) - sender.expect([r"Channel was set to [0-9]+", - r"Does not support setting the channel"]) - sender.expect([r"Got channel of value [0-9]+ of length [0-9]+", - r"Does not support getting the channel"]) - - receiver.expect([r"Address was set to [0-9]+", - r"Does not support setting the address"]) - receiver.expect([r"Got address of value [0-9]+ of length [0-9]+", - r"Got address of length [0-9]+ of value: ([0-9a-f]{2} )+", - r"Does not support getting the address"]) - sender.expect([r"Address was set to [0-9]+", - r"Does not support setting the address"]) - sender.expect([r"Got address of value [0-9]+ of length [0-9]+", - r"Got address of length [0-9]+ of value: ([0-9a-f]{2} )+", - r"Does not support getting the address"]) - - receiver.expect([r"Long address was set to [0-9]+", - r"Does not support setting the long address"]) - receiver.expect([r"Got long address of value [0-9]+ of length [0-9]+", - r"Got long address of value 0x[0-9a-f]+ of length 8", - r"Got long address of length [0-9]+ of value: ([0-9a-f]{2} )+", - r"Does not support getting the long address"]) - sender.expect([r"Long address was set to [0-9]+", - r"Does not support setting the long address"]) - sender.expect([r"Got long address of value [0-9]+ of length [0-9]+", - r"Got long address of value 0x[0-9a-f]+ of length 8", - r"Got long address of length [0-9]+ of value: ([0-9a-f]{2} )+", - r"Does not support getting the long address"]) - - receiver.expect([r"Network ID was set to [0-9]+", - r"Does not support setting the network ID"]) - receiver.expect([r"Got network ID of value [0-9]+ of length [0-9]+", - r"Does not support getting the network ID"]) - sender.expect([r"Network ID was set to [0-9]+", - r"Does not support setting the network ID"]) - sender.expect([r"Got network ID of value [0-9]+ of length [0-9]+", - r"Does not support getting the network ID"]) - - receiver.expect([r"Got maximum packet size of value [0-9]+ of length [0-9]+", - r"Does not support getting the maximum packet size"]) - sender.expect([r"Got maximum packet size of value [0-9]+ of length [0-9]+", - r"Does not support getting the maximum packet size"]) - - receiver.expect([r"Got protocol: ", - r"Does not support getting the protocol"]) - sender.expect([r"Got protocol: ", - r"Does not support getting the protocol"]) - - i = receiver.expect(["Device was set to RX mode", - "Device does not have a RX mode"]) - - if i == 0: - receiver.expect("Device is in RX mode") - elif i == 1: - receiver.expect("Device is") - - i = sender.expect(["Device was set to RX mode", - "Device does not have a RX mode"]) - - if i == 0: - sender.expect("Device is in RX mode") - elif i == 1: - sender.expect("Device is") - - receiver.expect(r"Added receive callback successfully") - - sender.expect(r'Sending "header 1,header 2,payload" to [0-9a-f ]+') - receiver.expect(r'Received "header 1,header 2,payload"') - receiver.expect(r"Sender was [0-9a-f ]+") - - return 0 - except TIMEOUT as exc: - print(exc) - return 1 - except Abort: - return 0 - finally: - if sender and not sender.terminate(): - os.killpg(sender.pid, signal.SIGKILL) - if receiver and not receiver.terminate(): - os.killpg(receiver.pid, signal.SIGKILL) - -if __name__ == "__main__": - sys.exit(main()) diff --git a/tests/pnet/Makefile b/tests/pnet/Makefile deleted file mode 100644 index 07d95d9509..0000000000 --- a/tests/pnet/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -APPLICATION = pnet -include ../Makefile.tests_common - -BOARD_INSUFFICIENT_RAM := chronos msb-430h redbee-econotag telosb wsn430-v1_3b wsn430-v1_4 z1 - -USEMODULE += posix -USEMODULE += pnet -USEMODULE += vtimer -USEMODULE += defaulttransceiver - -include $(RIOTBASE)/Makefile.include diff --git a/tests/pnet/main.c b/tests/pnet/main.c deleted file mode 100644 index d29079484d..0000000000 --- a/tests/pnet/main.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2013 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 tests - * @{ - * - * @file - * @brief PNet test application - * - * @author Martine Lenders - * - * @} - */ - -#include -#include -#include -#include - -#include -#include -#include - -#include "net_if.h" -#include "sixlowpan.h" -#include "ipv6.h" - -#ifndef R_ADDR -#define R_ADDR (1) -#endif - -#define PNET_PORT (1234) - -#define ERROR(...) printf("ERROR: " __VA_ARGS__) - -int init_local_address(uint16_t r_addr) -{ - ipv6_addr_t std_addr; - ipv6_addr_init(&std_addr, 0xabcd, 0xef12, 0, 0, 0x1034, 0x00ff, 0xfe00, - 0); - net_if_set_src_address_mode(0, NET_IF_TRANS_ADDR_M_SHORT); - return net_if_set_hardware_address(0, r_addr) && - sixlowpan_lowpan_init_adhoc_interface(0, &std_addr); -} - -int main(void) -{ - int sockfd, res; - struct sockaddr_in6 my_addr, their_addr; - char buffer[14]; - - their_addr.sin6_family = AF_INET6; -#if R_ADDR == 1 - their_addr.sin6_port = PNET_PORT; -#else - their_addr.sin6_port = 0; -#endif - their_addr.sin6_flowinfo = 0; - memset(&(their_addr.sin6_addr), 0, sizeof(their_addr.sin6_addr)); - their_addr.sin6_addr.uint16[0] = htons(0xabcd); - their_addr.sin6_addr.uint16[1] = htons(0xef12); - their_addr.sin6_addr.uint16[5] = htons(0x00ff); - their_addr.sin6_addr.uint16[6] = htons(0xfe00); -#if R_ADDR == 1 - their_addr.sin6_addr.uint16[7] = htons(2); -#else - their_addr.sin6_addr.uint16[7] = htons(1); -#endif - their_addr.sin6_scope_id = 0; - - if (!init_local_address(R_ADDR)) { - ERROR("Can not initialize IP for hardware address %d.", R_ADDR); - return 1; - } - - memcpy(buffer, "Hello, World!", 14); - memcpy(&my_addr, &in6addr_any, sizeof(my_addr)); - - my_addr.sin6_port = PNET_PORT; - - sockfd = socket(AF_INET6, SOCK_DGRAM, 0); - res = bind(sockfd, (struct sockaddr *)&my_addr, sizeof(my_addr)); - - if (res < 0) { - ERROR("Socket could not be bind"); - return 1; - } - -#if R_ADDR == 1 - res = sendto(sockfd, buffer, strlen(buffer), 0, - (struct sockaddr *)&their_addr, - (socklen_t) sizeof(their_addr)); -#else - socklen_t their_len; - res = recvfrom(sockfd, buffer, strlen(buffer), 0, - (struct sockaddr *)&their_addr, - &their_len); - - if (their_addr.sin6_addr.uint8[15] != 1) { - ERROR("Wrong sender address: %d\n", their_addr.sin6_addr.uint8[11]); - return 1; - } - - printf("Port: %d\n", their_addr.sin6_port); -#endif - - if (res < 0) { - ERROR("Message error"); - return 1; - } - - close(sockfd); - printf("All tests successful.\n"); - return 0; -} diff --git a/tests/unittests/Makefile b/tests/unittests/Makefile index b68fae0541..b58e6fed51 100644 --- a/tests/unittests/Makefile +++ b/tests/unittests/Makefile @@ -20,12 +20,6 @@ DISABLE_MODULE += auto_init # Pull in `Makefile.include`s from the test suites: -include $(UNIT_TESTS:%=$(RIOTBASE)/tests/unittests/%/Makefile.include) -ifneq (,$(filter netdev_dummy,$(USEMODULE))) - USEMODULE += netdev_base - DIRS += netdev_dummy - INCLUDES += -I$(RIOTBASE)/tests/unittests/netdev_dummy/include -endif - DIRS += $(UNIT_TESTS) BASELIBS += $(UNIT_TESTS:%=$(BINDIR)%.a) diff --git a/tests/unittests/netdev_dummy/Makefile b/tests/unittests/netdev_dummy/Makefile deleted file mode 100644 index 48422e909a..0000000000 --- a/tests/unittests/netdev_dummy/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(RIOTBASE)/Makefile.base diff --git a/tests/unittests/netdev_dummy/include/netdev_dummy.h b/tests/unittests/netdev_dummy/include/netdev_dummy.h deleted file mode 100644 index ad36122ccc..0000000000 --- a/tests/unittests/netdev_dummy/include/netdev_dummy.h +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (C) 2014 Martine Lenders - * - * 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. - */ - -/** - * @addtogroup unittests - * @{ - * - * @file - * @brief Provides a virtual device that understands the netdev_base API - * for testing. - * - * @author Martine Lenders - */ - -#ifndef UNITTESTS_NETDEV_DUMMY_H_ -#define UNITTESTS_NETDEV_DUMMY_H_ - -#include - -#include "netdev/base.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef UNITTESTS_NETDEV_DUMMY_MAX_DEV -/** - * @brief Maximum number of devices you can initialize with this module - */ -#define UNITTESTS_NETDEV_DUMMY_MAX_DEV (2) -#endif /* UNITTESTS_NETDEV_DUMMY_MAX_DEV */ - -#ifndef UNITTESTS_NETDEV_DUMMY_MAX_PACKET -/** - * @brief Maximum packet length for the virtual test devices. - */ -#define UNITTESTS_NETDEV_DUMMY_MAX_PACKET (12) -#endif /* UNITTESTS_NETDEV_DUMMY_MAX_PACKET */ - -#ifndef UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN -/** - * @brief The maximum length of the addresses for the test devices - */ -#define UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN (2) -#endif /* UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN */ - -#ifndef UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN -/** - * @brief The maximum length of the addresses for the test devices - */ -#define UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN (4) -#endif /* UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN */ - -#if UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN < UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN -#error "UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN < UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN!\n" -#endif - -#if UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN > 64 -#warning "UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN > 64 is not recommended" -#endif - -#ifndef UNITTESTS_NETDEV_DUMMY_MAX_CB -/** - * @brief Maximum number of callbacks per device - */ -#define UNITTESTS_NETDEV_DUMMY_MAX_CB (4) -#endif /* UNITTESTS_NETDEV_DUMMY_MAX_CB */ - -/** - * @brief Implementation of the driver for the virtual test device - */ -extern const netdev_driver_t unittest_netdev_dummy_driver; - -/** - * @brief Available devices - */ -extern netdev_t unittest_netdev_dummy_devs[UNITTESTS_NETDEV_DUMMY_MAX_DEV]; - -/** - * @brief Fires a receive event on a virtual test device - * - * @param[in] dev Device you want to fire the receive event on - * @param[in] src Source address of the received packet - * @param[in] src_len Length of *src* - * @param[in] dest Destination address of the received packet - * @param[in] dest_len Length of *dest* - * @param[in] data Content of the received packet - * @param[in] data_len Length of *data* - * - * @return 0 on success - * @return -EAFNOSUPPORT, if src_len or dest_len are neither - * UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN nor - * UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN - * @return -ECANCELED, receive event aborted since one of the registered - * callbacks had an error. - * @return -EINVAL, if *src* or *dest* are NULL or - * *data* is NULL and *data_len* is not NULL - * @return -EMSGSIZE, if *data_len* > UNITTESTS_NETDEV_DUMMY_MAX_PACKET - * @return -ENODEV, if device was not initialized by - * unittest_netdev_dummy_driver::init() - */ -int unittest_netdev_dummy_fire_rcv_event(netdev_t *dev, void *src, - size_t src_len, void *dest, size_t dest_len, void *data, - size_t data_len); - -/** - * @brief Checks if the data transmitted by - * unittest_netdev_dummy_driver::send_data() is as expected. - * - * @param[in] dev Device you want to check the transmitted data for - * @param[in] expected_dest The expected destination address. - * @param[in] expected_dest_len The expected length of the destination address. - * @param[in] expected_data The expected data - * @param[in] expected_data_len The expected length of the data - * - * @note Please remember that the device prepends the *upper_layer_hdrs* - * passed to unittest_netdev_dummy_driver::send_data() - * - * @return 0 on success and everything is as expected - * @return 1 on success and something is not as expected - * @return -ENODEV, if *dev* was not initialized by - * unittest_netdev_dummy_driver::init() - * @return -EINVAL, if *expected_data* is NULL and *expected_data_len is not 0 or - * if - */ -int unittest_netdev_dummy_check_transmitted(netdev_t *dev, - void *expected_dest, - size_t expected_dest_len, - void *expected_data, - size_t expected_data_len); - -/** - * @brief Get last event notified by dev::driver::event - * - * @param[in] dev Device you want to get the last event from. - * - * @return The last event as given as parameter to dev::driver::event - * @return ENODEV, if *dev* was not found - */ -uint32_t unittest_netdev_dummy_get_last_event(netdev_t *dev); - -/** - * @brief Resets all dummy devices to their initial state - */ -void unittest_netdev_dummy_init(void); - -#ifdef __cplusplus -} -#endif - -#endif /* UNITTESTS_NETDEV_DUMMY_H_ */ - -/** - * @} - */ diff --git a/tests/unittests/netdev_dummy/netdev_dummy.c b/tests/unittests/netdev_dummy/netdev_dummy.c deleted file mode 100644 index 318b320894..0000000000 --- a/tests/unittests/netdev_dummy/netdev_dummy.c +++ /dev/null @@ -1,699 +0,0 @@ -/* - * Copyright (C) 2014 Martine Lenders - * - * 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. - */ - -/** - * @addtogroup - * @{ - * - * @file - * - * @author Martine Lenders - */ -#include -#include -#include - -#include "netdev/base.h" - -#include "netdev_dummy.h" - -#define _NETDEV_MORE(dev) ((_ut_dev_internal *)(dev->more)) - -typedef struct { - char dst[UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN]; - size_t dst_len; - char src[UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN]; - size_t src_len; - char data[UNITTESTS_NETDEV_DUMMY_MAX_PACKET]; - size_t data_len; -} _unittest_test_buffer; - -typedef struct { - unsigned int channel; - char short_address[UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN]; - unsigned int nid; - char long_address[UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN]; - int tx_power; - netdev_state_t state; - netdev_rcv_data_cb_t callbacks[UNITTESTS_NETDEV_DUMMY_MAX_CB]; - _unittest_test_buffer rx_buffer; - _unittest_test_buffer tx_buffer; - uint32_t last_event; -} _ut_dev_internal; - -netdev_t unittest_netdev_dummy_devs[UNITTESTS_NETDEV_DUMMY_MAX_DEV]; -static _ut_dev_internal _netdevs_internal[UNITTESTS_NETDEV_DUMMY_MAX_DEV]; - -static int _find_dev(netdev_t *dev) -{ - if (dev == NULL || dev < (&(unittest_netdev_dummy_devs[0])) || - dev > (&(unittest_netdev_dummy_devs[UNITTESTS_NETDEV_DUMMY_MAX_DEV - 1]))) { - return -1; - } - - for (int i = 0; i < UNITTESTS_NETDEV_DUMMY_MAX_DEV; i++) { - if (&(unittest_netdev_dummy_devs[i]) == dev) { - return i; - } - } - - return -1; -} - -static int _init(netdev_t *dev) -{ - if (_find_dev(dev) < 0) { - return -ENODEV; - } - - _NETDEV_MORE(dev)->channel = 0; - _NETDEV_MORE(dev)->nid = 0; - _NETDEV_MORE(dev)->state = 0; - memset(_NETDEV_MORE(dev)->short_address, 0, - UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN); - memset(_NETDEV_MORE(dev)->long_address, 0, - UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN); - memset(&(_NETDEV_MORE(dev)->rx_buffer), 0, sizeof(_unittest_test_buffer)); - memset(&(_NETDEV_MORE(dev)->tx_buffer), 0, sizeof(_unittest_test_buffer)); - _NETDEV_MORE(dev)->last_event = 0; - - for (int j = 0; j < UNITTESTS_NETDEV_DUMMY_MAX_CB; j++) { - _NETDEV_MORE(dev)->callbacks[j] = NULL; - } - - return 0; -} - - -static int _send_data(netdev_t *dev, void *dest, size_t dest_len, - netdev_hlist_t *upper_layer_hdrs, void *data, - size_t data_len) -{ - netdev_hlist_t *ptr = upper_layer_hdrs; - size_t tx_ptr = 0; - - if (dest == NULL || data == NULL) { - return -EFAULT; - } - - if (_find_dev(dev) < 0) { - return -ENODEV; - } - - if ((data_len + netdev_get_hlist_len(upper_layer_hdrs)) > - UNITTESTS_NETDEV_DUMMY_MAX_PACKET) { - return -EMSGSIZE; - } - - if (dest_len > UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN) { - return -EAFNOSUPPORT; - } - - memcpy(_NETDEV_MORE(dev)->tx_buffer.dst, dest, dest_len); - _NETDEV_MORE(dev)->tx_buffer.dst_len = dest_len; - _NETDEV_MORE(dev)->tx_buffer.data_len = 0; - - if (upper_layer_hdrs) { - do { - memcpy(&(_NETDEV_MORE(dev)->tx_buffer.data[tx_ptr]), - ptr->header, ptr->header_len); - _NETDEV_MORE(dev)->tx_buffer.data_len += ptr->header_len; - tx_ptr += ptr->header_len; - netdev_hlist_advance(&ptr); - } while (ptr != upper_layer_hdrs); - } - - memcpy(&(_NETDEV_MORE(dev)->tx_buffer.data[tx_ptr]), data, - data_len); - _NETDEV_MORE(dev)->tx_buffer.data_len += data_len; - - return _NETDEV_MORE(dev)->tx_buffer.data_len; -} - -static int _add_receive_data_callback(netdev_t *dev, netdev_rcv_data_cb_t cb) -{ - if (_find_dev(dev) < 0) { - return -ENODEV; - } - - for (int j = 0; j < UNITTESTS_NETDEV_DUMMY_MAX_CB; j++) { - if (_NETDEV_MORE(dev)->callbacks[j] == cb) { - return 0; - } - - if (_NETDEV_MORE(dev)->callbacks[j] == NULL) { - _NETDEV_MORE(dev)->callbacks[j] = cb; - return 0; - } - } - - return -ENOBUFS; -} - -static int _rem_receive_data_callback(netdev_t *dev, netdev_rcv_data_cb_t cb) -{ - if (_find_dev(dev) < 0) { - return -ENODEV; - } - - for (int j = 0; j < UNITTESTS_NETDEV_DUMMY_MAX_CB; j++) { - if (_NETDEV_MORE(dev)->callbacks[j] == cb) { - _NETDEV_MORE(dev)->callbacks[j] = NULL; - return 0; - } - } - - return 0; -} - -static int _get_option(netdev_t *dev, netdev_opt_t opt, void *value, - size_t *value_len) -{ - if (_find_dev(dev) < 0) { - return -ENODEV; - } - - if (value == NULL || value_len == NULL) { - return -EFAULT; - } - - switch (opt) { - case NETDEV_OPT_CHANNEL: - if (*value_len < sizeof(unsigned int)) { - return -EOVERFLOW; - } - - if (*value_len > sizeof(unsigned int)) { - *value_len = sizeof(unsigned int); - } - - *((unsigned int *)value) = _NETDEV_MORE(dev)->channel; - break; - - case NETDEV_OPT_ADDRESS: - if (*value_len < UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN) { - return -EOVERFLOW; - } - - if (*value_len > UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN) { - *value_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - } - - memcpy(value, _NETDEV_MORE(dev)->short_address, *value_len); - break; - - case NETDEV_OPT_NID: - if (*value_len < sizeof(unsigned int)) { - return -EOVERFLOW; - } - - if (*value_len > sizeof(unsigned int)) { - *value_len = sizeof(unsigned int); - } - - *((unsigned int *)value) = _NETDEV_MORE(dev)->nid; - break; - - case NETDEV_OPT_ADDRESS_LONG: - if (*value_len < UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN) { - return -EOVERFLOW; - } - - if (*value_len > UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN) { - *value_len = UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN; - } - - memcpy(value, _NETDEV_MORE(dev)->long_address, *value_len); - break; - - case NETDEV_OPT_TX_POWER: - if (*value_len < sizeof(int)) { - return -EOVERFLOW; - } - - if (*value_len > sizeof(int)) { - *value_len = sizeof(int); - } - - *((unsigned int *)value) = _NETDEV_MORE(dev)->tx_power; - break; - - case NETDEV_OPT_MAX_PACKET_SIZE: -#if UNITTESTS_NETDEV_DUMMY_MAX_PACKET < 256 - if (*value_len == 0) { - return -EOVERFLOW; - } - - *value_len = sizeof(uint8_t); - *((uint8_t *)value) = (uint8_t)UNITTESTS_NETDEV_DUMMY_MAX_PACKET; -#elif UNITTESTS_NETDEV_DUMMY_MAX_PACKET < (1 << 16) - - if (*value_len < sizeof(uint16_t)) { - return -EOVERFLOW; - } - - *value_len = sizeof(uint16_t); - *((uint16_t *)value) = (uint16_t)UNITTESTS_NETDEV_DUMMY_MAX_PACKET; -#elif UNITTESTS_NETDEV_DUMMY_MAX_PACKET < (1 << 32) - - if (*value_len < sizeof(uint32_t)) { - return -EOVERFLOW; - } - - *value_len = sizeof(uint32_t); - *((uint32_t *)value) = (uint32_t)UNITTESTS_NETDEV_DUMMY_MAX_PACKET; -#else - - if (*value_len < sizeof(uint64_t)) { - return -EOVERFLOW; - } - - *value_len = sizeof(uint64_t); - *((uint64_t *)value) = (uint64_t)UNITTESTS_NETDEV_DUMMY_MAX_PACKET; -#endif - - break; - - case NETDEV_OPT_PROTO: - if (*value_len < sizeof(netdev_proto_t)) { - return -EOVERFLOW; - } - - if (*value_len > sizeof(netdev_proto_t)) { - *value_len = sizeof(netdev_proto_t); - } - - *((netdev_proto_t *)value) = NETDEV_PROTO_UNKNOWN; - break; - - default: - return -ENOTSUP; - } - - return 0; -} - -static int _type_pun_up_unsigned(void *value_out, size_t desired_len, - void *value_in, size_t given_len) -{ - if (given_len > desired_len) { - return -EOVERFLOW; - } - - /* XXX this is ugly, but bear with me */ - switch (given_len) { - case 8: - switch (desired_len) { - case 8: - *((uint64_t *)value_out) = (*((uint64_t *)value_in)); - return 0; - - default: - return -EINVAL; - } - - case 4: - switch (desired_len) { - case 8: - *((uint64_t *)value_out) = (uint64_t)(*((uint32_t *)value_in)); - return 0; - - case 4: - *((uint32_t *)value_out) = (*((uint32_t *)value_in)); - return 0; - - default: - return -EINVAL; - } - - case 2: - switch (desired_len) { - case 8: - *((uint64_t *)value_out) = (uint64_t)(*((uint16_t *)value_in)); - return 0; - - case 4: - *((uint32_t *)value_out) = (uint32_t)(*((uint16_t *)value_in)); - return 0; - - case 2: - *((uint16_t *)value_out) = (*((uint16_t *)value_in)); - return 0; - - default: - return -EINVAL; - } - - case 1: - switch (desired_len) { - case 8: - *((uint64_t *)value_out) = (uint64_t)(*((uint8_t *)value_in)); - return 0; - - case 4: - *((uint32_t *)value_out) = (uint32_t)(*((uint8_t *)value_in)); - return 0; - - case 2: - *((uint16_t *)value_out) = (uint16_t)(*((uint8_t *)value_in)); - return 0; - - case 1: - *((uint8_t *)value_out) = (*((uint8_t *)value_in)); - return 0; - - default: - return -EINVAL; - } - - default: - return -EINVAL; - } -} - -static int _type_pun_up_signed(void *value_out, size_t desired_len, - void *value_in, size_t given_len) -{ - if (given_len > desired_len) { - return -EOVERFLOW; - } - - /* XXX this is ugly, but bear with me */ - switch (given_len) { - case 8: - switch (desired_len) { - case 8: - *((int64_t *)value_out) = (*((int64_t *)value_in)); - return 0; - - default: - return -EINVAL; - } - - case 4: - switch (desired_len) { - case 8: - *((int64_t *)value_out) = (int64_t)(*((int32_t *)value_in)); - return 0; - - case 4: - *((int32_t *)value_out) = (*((int32_t *)value_in)); - return 0; - - default: - return -EINVAL; - } - - case 2: - switch (desired_len) { - case 8: - *((int64_t *)value_out) = (int64_t)(*((int16_t *)value_in)); - return 0; - - case 4: - *((int32_t *)value_out) = (int32_t)(*((int16_t *)value_in)); - return 0; - - case 2: - *((int16_t *)value_out) = (*((int16_t *)value_in)); - return 0; - - default: - return -EINVAL; - } - - case 1: - switch (desired_len) { - case 8: - *((int64_t *)value_out) = (int64_t)(*((int8_t *)value_in)); - return 0; - - case 4: - *((int32_t *)value_out) = (int32_t)(*((int8_t *)value_in)); - return 0; - - case 2: - *((int16_t *)value_out) = (int16_t)(*((int8_t *)value_in)); - return 0; - - case 1: - *((int8_t *)value_out) = (*((int8_t *)value_in)); - return 0; - - default: - return -EINVAL; - } - - default: - return -EINVAL; - } -} - -static int _set_option(netdev_t *dev, netdev_opt_t opt, void *value, - size_t value_len) -{ - uint8_t set_value[UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN]; - int res = 0; - - if (_find_dev(dev) < 0) { - return -ENODEV; - } - - if (value == NULL) { - return -EFAULT; - } - - switch (opt) { - case NETDEV_OPT_CHANNEL: - if ((res = _type_pun_up_unsigned(set_value, sizeof(unsigned int), - value, value_len)) == 0) { - _NETDEV_MORE(dev)->channel = *((unsigned int *)value); - } - - break; - - case NETDEV_OPT_ADDRESS: - if (value_len > UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN) { - return -EOVERFLOW; - } - else { - int start = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN - value_len; - - if (value_len == 0) { - return -EINVAL; - } - - if (value_len < UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN) { - memcpy(_NETDEV_MORE(dev)->short_address, value, start); - } - - memcpy(&(_NETDEV_MORE(dev)->short_address[start]), value, - value_len); - } - - break; - - case NETDEV_OPT_NID: - if ((res = _type_pun_up_unsigned(set_value, sizeof(unsigned int), - value, value_len)) == 0) { - _NETDEV_MORE(dev)->nid = *((unsigned int *)value); - } - - break; - - case NETDEV_OPT_ADDRESS_LONG: - if (value_len > UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN) { - return -EOVERFLOW; - } - else { - int start = UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN - value_len; - - if (value_len == 0) { - return -EINVAL; - } - - if (value_len < UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN) { - memcpy(_NETDEV_MORE(dev)->long_address, value, start); - } - - memcpy(&(_NETDEV_MORE(dev)->long_address[start]), value, - value_len); - } - - break; - - case NETDEV_OPT_TX_POWER: - if ((res = _type_pun_up_signed(set_value, sizeof(int), - value, value_len)) == 0) { - _NETDEV_MORE(dev)->tx_power = *((int *)value); - } - - break; - - default: - return -ENOTSUP; - } - - return res; -} - -static int _get_state(netdev_t *dev, netdev_state_t *state) -{ - if (_find_dev(dev) < 0) { - return -ENODEV; - } - - if (state == NULL) { - return -EFAULT; - } - - *state = _NETDEV_MORE(dev)->state; - - return 0; -} - -static int _set_state(netdev_t *dev, netdev_state_t state) -{ - if (_find_dev(dev) < 0) { - return -ENODEV; - } - - switch (state) { - case NETDEV_STATE_POWER_OFF: - case NETDEV_STATE_POWER_SLEEP: - case NETDEV_STATE_POWER_IDLE: - case NETDEV_STATE_RX_MODE: - case NETDEV_STATE_PROMISCUOUS_MODE: - _NETDEV_MORE(dev)->state = state; - return 0; - - default: - return -ENOTSUP; - } -} - -static void _event(netdev_t *dev, uint32_t event_type) -{ - if (_find_dev(dev) < 0) { - return; - } - - _NETDEV_MORE(dev)->last_event = event_type; -} - -const netdev_driver_t unittest_netdev_dummy_driver = { - _init, - _send_data, - _add_receive_data_callback, - _rem_receive_data_callback, - _get_option, - _set_option, - _get_state, - _set_state, - _event, -}; - -int unittest_netdev_dummy_fire_rcv_event(netdev_t *dev, void *src, - size_t src_len, void *dest, size_t dest_len, void *data, - size_t data_len) -{ - if (_find_dev(dev) < 0) { - return -ENODEV; - } - - if ((src_len != UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN && - src_len != UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN) || - (dest_len != UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN && - dest_len != UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN)) { - return -EAFNOSUPPORT; - } - - if (data_len > UNITTESTS_NETDEV_DUMMY_MAX_PACKET) { - return -EMSGSIZE; - } - - if (src == NULL || dest == NULL || (data == NULL && data_len != 0)) { - return -EINVAL; - } - - _NETDEV_MORE(dev)->rx_buffer.src_len = src_len; - _NETDEV_MORE(dev)->rx_buffer.dst_len = dest_len; - _NETDEV_MORE(dev)->rx_buffer.data_len = data_len; - - memcpy(_NETDEV_MORE(dev)->rx_buffer.dst, dest, dest_len); - memcpy(_NETDEV_MORE(dev)->rx_buffer.src, src, src_len); - memcpy(_NETDEV_MORE(dev)->rx_buffer.data, data, data_len); - - for (int j = 0; j < UNITTESTS_NETDEV_DUMMY_MAX_CB; j++) { - if (_NETDEV_MORE(dev)->callbacks[j] != 0) { - int res = _NETDEV_MORE(dev)->callbacks[j](dev, - _NETDEV_MORE(dev)->rx_buffer.src, - _NETDEV_MORE(dev)->rx_buffer.src_len, - _NETDEV_MORE(dev)->rx_buffer.dst, - _NETDEV_MORE(dev)->rx_buffer.dst_len, - _NETDEV_MORE(dev)->rx_buffer.data, - _NETDEV_MORE(dev)->rx_buffer.data_len); - - if (res < 0) { - return -ECANCELED; - } - } - } - - return 0; -} - -int unittest_netdev_dummy_check_transmitted(netdev_t *dev, - void *expected_dest, - size_t expected_dest_len, - void *expected_data, - size_t expected_data_len) -{ - if (_find_dev(dev) < 0) { - return -ENODEV; - } - - if ((expected_dest == NULL && expected_dest_len != 0) || - (expected_data == NULL && expected_data_len != 0)) { - return -EINVAL; - } - - if (!(expected_dest_len == UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN || - expected_dest_len == UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN) || - expected_dest_len != _NETDEV_MORE(dev)->tx_buffer.dst_len || - expected_data_len != _NETDEV_MORE(dev)->tx_buffer.data_len || - (memcmp(expected_dest, _NETDEV_MORE(dev)->tx_buffer.dst, expected_dest_len) != 0) || - (memcmp(expected_data, _NETDEV_MORE(dev)->tx_buffer.data, expected_data_len) != 0)) { - return 1; - } - - return 0; -} - -uint32_t unittest_netdev_dummy_get_last_event(netdev_t *dev) -{ - if (_find_dev(dev) < 0) { - return ENODEV; - } - - return _NETDEV_MORE(dev)->last_event; -} - -void unittest_netdev_dummy_init(void) -{ - for (int i = 0; i < UNITTESTS_NETDEV_DUMMY_MAX_DEV; i++) { - netdev_t *dev = &(unittest_netdev_dummy_devs[i]); - dev->type = NETDEV_TYPE_BASE; - dev->driver = &unittest_netdev_dummy_driver; - dev->more = &(_netdevs_internal[i]); - } -} - -/** - * @} - */ diff --git a/tests/unittests/tests-netdev_dummy/Makefile b/tests/unittests/tests-netdev_dummy/Makefile deleted file mode 100644 index 48422e909a..0000000000 --- a/tests/unittests/tests-netdev_dummy/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(RIOTBASE)/Makefile.base diff --git a/tests/unittests/tests-netdev_dummy/Makefile.include b/tests/unittests/tests-netdev_dummy/Makefile.include deleted file mode 100644 index 2030661591..0000000000 --- a/tests/unittests/tests-netdev_dummy/Makefile.include +++ /dev/null @@ -1 +0,0 @@ -USEMODULE += netdev_dummy diff --git a/tests/unittests/tests-netdev_dummy/tests-netdev_dummy.c b/tests/unittests/tests-netdev_dummy/tests-netdev_dummy.c deleted file mode 100644 index d8de6ab28e..0000000000 --- a/tests/unittests/tests-netdev_dummy/tests-netdev_dummy.c +++ /dev/null @@ -1,989 +0,0 @@ -/* - * Copyright (C) 2014 Martine Lenders - * - * 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. - */ - -#include -#include -#include - -#include "clist.h" - -#include "embUnit.h" - -#include "netdev_dummy.h" - -#include "unittests-constants.h" -#include "tests-netdev_dummy.h" - -static netdev_t *dev = &(unittest_netdev_dummy_devs[0]); -static char received_data[UNITTESTS_NETDEV_DUMMY_MAX_PACKET]; -static char received_src[UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN]; -static char received_dst[UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN]; -static size_t received_data_len = 0, received_src_len = 0, received_dst_len = 0; - -#define OPTION_NUMBER (6) -#define RANDOM_OPTION (TEST_UINT8 % OPTION_NUMBER) + 1 - -static void _reset_received(void) -{ - memset(received_data, 0, sizeof(received_data)); - memset(received_src, 0, sizeof(received_src)); - memset(received_dst, 0, sizeof(received_dst)); - received_data_len = 0; - received_src_len = 0; - received_dst_len = 0; -} - -static void set_up(void) -{ - unittest_netdev_dummy_init(); - dev->driver->init(dev); -} - -static void tear_down(void) -{ - _reset_received(); -} - -/* callback for callback tests */ -int _fill_received(netdev_t *dev_rcv, void *src, size_t src_len, void *dest, - size_t dest_len, void *payload, size_t payload_len) -{ - if ((dev != dev_rcv) || (payload_len > sizeof(received_data)) || - (src_len > sizeof(received_src)) || (dest_len > sizeof(received_dst))) { - /* should not happen */ - return -1; - } - - memcpy(received_src, src, src_len); - received_src_len = src_len; - memcpy(received_dst, dest, dest_len); - received_dst_len = dest_len; - memcpy(received_data, payload, payload_len); - received_data_len = payload_len; - - return 0; -} - -/* callback for callback tests */ -int _always_wrong(netdev_t *dev_rcv, void *src, size_t src_len, void *dest, - size_t dest_len, void *payload, size_t payload_len) -{ - (void)dev_rcv; - (void)src; - (void)src_len; - (void)dest; - (void)dest_len; - (void)payload; - (void)payload_len; - return -1; -} - -/********************************************* - * driver::init tests * - *********************************************/ -static void test_netdev_dummy_init_dev_null(void) -{ - TEST_ASSERT_EQUAL_INT(-ENODEV, dev->driver->init(NULL)); -} - -static void test_netdev_dummy_init_dev_wrong(void) -{ - netdev_t wrong_dev; - - TEST_ASSERT_EQUAL_INT(-ENODEV, dev->driver->init(&wrong_dev)); -} - -/********************************************* - * driver::send_data tests * - *********************************************/ - -static void test_netdev_dummy_send_data_dev_null(void) -{ - char dest[] = TEST_STRING8; - char data[] = TEST_STRING64; - TEST_ASSERT_EQUAL_INT(-ENODEV, dev->driver->send_data(NULL, dest, - UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN, NULL, - data, strlen(data))); -} - -static void test_netdev_dummy_send_data_dev_wrong(void) -{ - char dest[] = TEST_STRING8; - char data[] = TEST_STRING64; - netdev_t wrong_dev; - TEST_ASSERT_EQUAL_INT(-ENODEV, dev->driver->send_data(&wrong_dev, dest, - UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN, NULL, - data, strlen(data))); -} - -static void test_netdev_dummy_send_data_dest_too_long(void) -{ - char dest[] = TEST_STRING8; - char data[] = TEST_STRING64; - TEST_ASSERT_EQUAL_INT(-EAFNOSUPPORT, dev->driver->send_data(dev, dest, - UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN + TEST_UINT8, - NULL, data, 1)); -} - -static void test_netdev_dummy_send_data_data_too_long(void) -{ - char dest[] = TEST_STRING8; - char data[] = TEST_STRING64; - TEST_ASSERT_EQUAL_INT(-EMSGSIZE, dev->driver->send_data(dev, dest, - UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN, NULL, - data, - UNITTESTS_NETDEV_DUMMY_MAX_PACKET + TEST_UINT8)); -} - -static void test_netdev_dummy_send_data_no_ulhs(void) -{ - char dest[] = TEST_STRING64; - size_t dest_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char data[] = TEST_STRING8; -#if UNITTESTS_NETDEV_DUMMY_MAX_PACKET < 8 - size_t data_len = UNITTESTS_NETDEV_DUMMY_MAX_PACKET; -#else - size_t data_len = 8; -#endif - TEST_ASSERT_EQUAL_INT((int)data_len, dev->driver->send_data(dev, dest, - dest_len, NULL, data, data_len)); - TEST_ASSERT_EQUAL_INT(0, unittest_netdev_dummy_check_transmitted(dev, - dest, dest_len, data, data_len)); -} - -#if UNITTESTS_NETDEV_DUMMY_MAX_PACKET > 4 -static void test_netdev_dummy_send_data_with_ulhs(void) -{ - netdev_hlist_t hlist_node = {NULL, NULL, NETDEV_PROTO_UNKNOWN, TEST_STRING8, 4}; - netdev_hlist_t *hlist = NULL; - char dest[] = TEST_STRING64; - size_t dest_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char data[] = TEST_STRING16; -#if UNITTESTS_NETDEV_DUMMY_MAX_PACKET < 12 - size_t data_len = UNITTESTS_NETDEV_DUMMY_MAX_PACKET - 4; - char expected[UNITTESTS_NETDEV_DUMMY_MAX_PACKET]; -#else - size_t data_len = 8; - char expected[12]; -#endif - - memcpy(expected, TEST_STRING8, 4); - memcpy(&(expected[4]), TEST_STRING16, data_len); - - clist_add((clist_node_t **)&hlist, (clist_node_t *)&hlist_node); - TEST_ASSERT_EQUAL_INT((int)sizeof(expected), dev->driver->send_data(dev, - dest, dest_len, hlist, data, data_len)); - TEST_ASSERT_EQUAL_INT(0, unittest_netdev_dummy_check_transmitted(dev, - dest, dest_len, expected, data_len + 4)); -} -#endif - -/********************************************* - * driver::add_receive_data_callback tests * - *********************************************/ - -static void test_netdev_dummy_add_cb_dev_null(void) -{ - TEST_ASSERT_EQUAL_INT(-ENODEV, dev->driver->add_receive_data_callback(NULL, - _fill_received)); -} - -static void test_netdev_dummy_add_cb_dev_wrong(void) -{ - netdev_t wrong_dev; - TEST_ASSERT_EQUAL_INT(-ENODEV, dev->driver->add_receive_data_callback(&wrong_dev, - _fill_received)); -} - -static void test_netdev_dummy_add_cb_buffer_full(void) -{ - for (int i = 0; i < UNITTESTS_NETDEV_DUMMY_MAX_CB; i++) { - - TEST_ASSERT_EQUAL_INT(0, dev->driver->add_receive_data_callback(dev, - (netdev_rcv_data_cb_t)(i + 1))); - } - - TEST_ASSERT_EQUAL_INT(-ENOBUFS, dev->driver->add_receive_data_callback(dev, - _fill_received)); -} - -static void test_netdev_dummy_add_cb_successful(void) -{ - char src[] = TEST_STRING64; - size_t src_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char dest[] = TEST_STRING64; - size_t dest_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char data[] = TEST_STRING8; -#if UNITTESTS_NETDEV_DUMMY_MAX_PACKET < 8 - size_t data_len = UNITTESTS_NETDEV_DUMMY_MAX_PACKET; -#else - size_t data_len = 8; -#endif - TEST_ASSERT_EQUAL_INT(0, dev->driver->add_receive_data_callback(dev, - _fill_received)); - TEST_ASSERT_EQUAL_INT(0, unittest_netdev_dummy_fire_rcv_event(dev, src, - src_len, dest, dest_len, data, data_len)); - TEST_ASSERT_EQUAL_INT(src_len, received_src_len); - TEST_ASSERT_EQUAL_INT(0, memcmp(received_src, src, src_len)); - TEST_ASSERT_EQUAL_INT(dest_len, received_dst_len); - TEST_ASSERT_EQUAL_INT(0, memcmp(received_dst, dest, dest_len)); - TEST_ASSERT_EQUAL_INT(data_len, received_data_len); - TEST_ASSERT_EQUAL_INT(0, memcmp(received_data, data, data_len)); -} - -/********************************************* - * driver::rem_receive_data_callback tests * - *********************************************/ - -static void test_netdev_dummy_rem_cb_dev_null(void) -{ - TEST_ASSERT_EQUAL_INT(-ENODEV, dev->driver->rem_receive_data_callback(NULL, - _fill_received)); -} - -static void test_netdev_dummy_rem_cb_dev_wrong(void) -{ - netdev_t wrong_dev; - TEST_ASSERT_EQUAL_INT(-ENODEV, dev->driver->rem_receive_data_callback( - &wrong_dev, _fill_received)); -} - -static void test_netdev_dummy_rem_cb_unknown_cb(void) -{ - TEST_ASSERT_EQUAL_INT(0, dev->driver->rem_receive_data_callback( - dev, _fill_received)); -} - -static void test_netdev_dummy_rem_cb_successful(void) -{ - char src[] = TEST_STRING64; - size_t src_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char dest[] = TEST_STRING64; - size_t dest_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char data[] = TEST_STRING8; -#if UNITTESTS_NETDEV_DUMMY_MAX_PACKET < 8 - size_t data_len = UNITTESTS_NETDEV_DUMMY_MAX_PACKET; -#else - size_t data_len = 8; -#endif - TEST_ASSERT_EQUAL_INT(0, dev->driver->add_receive_data_callback(dev, - _fill_received)); - TEST_ASSERT_EQUAL_INT(0, unittest_netdev_dummy_fire_rcv_event(dev, src, - src_len, dest, dest_len, data, data_len)); - _reset_received(); - TEST_ASSERT_EQUAL_INT(0, dev->driver->rem_receive_data_callback(dev, - _fill_received)); - TEST_ASSERT_EQUAL_INT(0, unittest_netdev_dummy_fire_rcv_event(dev, src, - src_len, dest, dest_len, data, data_len)); - TEST_ASSERT_EQUAL_INT(0, received_src_len); - TEST_ASSERT_EQUAL_INT(0, received_dst_len); - TEST_ASSERT_EQUAL_INT(0, received_data_len); - - for (int i = 0; i < UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN; i++) { - TEST_ASSERT_EQUAL_INT(0, received_src[i]); - } - - for (int i = 0; i < UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN; i++) { - TEST_ASSERT_EQUAL_INT(0, received_dst[i]); - } - - for (int i = 0; i < UNITTESTS_NETDEV_DUMMY_MAX_PACKET; i++) { - TEST_ASSERT_EQUAL_INT(0, received_data[i]); - } -} - -static void test_netdev_dummy_rem_cb_multiple_added(void) -{ - char src[] = TEST_STRING64; - size_t src_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char dest[] = TEST_STRING64; - size_t dest_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char data[] = TEST_STRING8; -#if UNITTESTS_NETDEV_DUMMY_MAX_PACKET < 8 - size_t data_len = UNITTESTS_NETDEV_DUMMY_MAX_PACKET; -#else - size_t data_len = 8; -#endif - TEST_ASSERT_EQUAL_INT(0, dev->driver->add_receive_data_callback(dev, - _fill_received)); - TEST_ASSERT_EQUAL_INT(0, unittest_netdev_dummy_fire_rcv_event(dev, src, - src_len, dest, dest_len, data, data_len)); - _reset_received(); - TEST_ASSERT_EQUAL_INT(0, dev->driver->add_receive_data_callback(dev, - _always_wrong)); - TEST_ASSERT_EQUAL_INT(-ECANCELED, unittest_netdev_dummy_fire_rcv_event( - dev, src, src_len, dest, dest_len, data, data_len)); - TEST_ASSERT_EQUAL_INT(0, dev->driver->rem_receive_data_callback(dev, - _always_wrong)); - TEST_ASSERT_EQUAL_INT(0, unittest_netdev_dummy_fire_rcv_event(dev, src, - src_len, dest, dest_len, data, data_len)); - TEST_ASSERT_EQUAL_INT(src_len, received_src_len); - TEST_ASSERT_EQUAL_INT(0, memcmp(received_src, src, src_len)); - TEST_ASSERT_EQUAL_INT(dest_len, received_dst_len); - TEST_ASSERT_EQUAL_INT(0, memcmp(received_dst, dest, dest_len)); - TEST_ASSERT_EQUAL_INT(data_len, received_data_len); - TEST_ASSERT_EQUAL_INT(0, memcmp(received_data, data, data_len)); -} - -/********************************************* - * driver::get_option tests * - *********************************************/ - -static void test_netdev_dummy_get_option_dev_null(void) -{ - unsigned int value = (unsigned int)TEST_UINT32; - size_t value_len = sizeof(unsigned int); - TEST_ASSERT_EQUAL_INT(-ENODEV, dev->driver->get_option(NULL, RANDOM_OPTION, - &value, &value_len)); -} - -static void test_netdev_dummy_get_option_dev_wrong(void) -{ - unsigned int value = (unsigned int)TEST_UINT32; - size_t value_len = sizeof(unsigned int); - netdev_t wrong_dev; - TEST_ASSERT_EQUAL_INT(-ENODEV, dev->driver->get_option(&wrong_dev, - RANDOM_OPTION, &value, &value_len)); -} - -static void test_netdev_dummy_get_option_null_value(void) -{ - size_t value_len = sizeof(unsigned int); - TEST_ASSERT_EQUAL_INT(-EFAULT, dev->driver->get_option(dev, - RANDOM_OPTION, NULL, &value_len)); -} - -static void test_netdev_dummy_get_option_null_value_len(void) -{ - unsigned int value = (unsigned int)TEST_UINT32; - TEST_ASSERT_EQUAL_INT(-EFAULT, dev->driver->get_option(dev, - RANDOM_OPTION, &value, NULL)); - TEST_ASSERT_EQUAL_INT((unsigned int)TEST_UINT32, value); -} - -static void test_netdev_dummy_get_option_overflow(void) -{ - unsigned int value = (unsigned int)TEST_UINT32; - size_t value_len = 0; - TEST_ASSERT_EQUAL_INT(-EOVERFLOW, dev->driver->get_option(dev, - RANDOM_OPTION, &value, &value_len)); - TEST_ASSERT_EQUAL_INT((unsigned int)TEST_UINT32, value); -} - -static void test_netdev_dummy_get_option_not_supported(void) -{ - unsigned int value = (unsigned int)TEST_UINT32; - size_t value_len = 0; - TEST_ASSERT_EQUAL_INT(-ENOTSUP, dev->driver->get_option(dev, - (netdev_opt_t)0xffffffff, &value, &value_len)); - TEST_ASSERT_EQUAL_INT((unsigned int)TEST_UINT32, value); -} - -static void test_netdev_dummy_get_channel(void) -{ - unsigned int value = (unsigned int)TEST_UINT32; - size_t value_len = sizeof(unsigned int) + TEST_UINT8; - TEST_ASSERT_EQUAL_INT(0, dev->driver->get_option(dev, NETDEV_OPT_CHANNEL, - &value, &value_len)); - TEST_ASSERT_EQUAL_INT(0, value); - TEST_ASSERT_EQUAL_INT(sizeof(unsigned int), value_len); -} - -static void test_netdev_dummy_get_address(void) -{ - uint8_t value[UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN]; - size_t value_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN + TEST_UINT8; - TEST_ASSERT_EQUAL_INT(0, dev->driver->get_option(dev, NETDEV_OPT_ADDRESS, - value, &value_len)); - - for (int i = 0; i < UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; i++) { - TEST_ASSERT_EQUAL_INT(0, value[i]); - } - - TEST_ASSERT_EQUAL_INT(UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN, value_len); -} - -static void test_netdev_dummy_get_nid(void) -{ - unsigned int value = (unsigned int)TEST_UINT32; - size_t value_len = sizeof(unsigned int) + TEST_UINT8; - TEST_ASSERT_EQUAL_INT(0, dev->driver->get_option(dev, NETDEV_OPT_NID, - &value, &value_len)); - TEST_ASSERT_EQUAL_INT(0, value); - TEST_ASSERT_EQUAL_INT(sizeof(unsigned int), value_len); -} - -static void test_netdev_dummy_get_long_address(void) -{ - uint8_t value[UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN]; - size_t value_len = UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN + TEST_UINT8; - TEST_ASSERT_EQUAL_INT(0, dev->driver->get_option(dev, NETDEV_OPT_ADDRESS_LONG, - value, &value_len)); - - for (int i = 0; i < UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN; i++) { - TEST_ASSERT_EQUAL_INT(0, value[i]); - } - - TEST_ASSERT_EQUAL_INT(UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN, value_len); -} - -static void test_netdev_dummy_get_tx_power(void) -{ - int value = TEST_INT; - size_t value_len = sizeof(int) + TEST_UINT8; - TEST_ASSERT_EQUAL_INT(0, dev->driver->get_option(dev, NETDEV_OPT_TX_POWER, - &value, &value_len)); - TEST_ASSERT_EQUAL_INT(0, value); - TEST_ASSERT_EQUAL_INT(sizeof(int), value_len); -} - -/********************************************* - * driver::set_option tests * - *********************************************/ - -static void test_netdev_dummy_set_option_dev_null(void) -{ - unsigned int value = (unsigned int)TEST_UINT32; - int res = -ENOTSUP; - netdev_opt_t opt = RANDOM_OPTION; - - while (res == -ENOTSUP) { - res = dev->driver->set_option(NULL, opt, &value, sizeof(unsigned int)); - - opt = (opt + 1) % OPTION_NUMBER; - } - - TEST_ASSERT_EQUAL_INT(-ENODEV, res); -} - -static void test_netdev_dummy_set_option_dev_wrong(void) -{ - int value = (unsigned int)TEST_INT; - netdev_t wrong_dev; - int res = -ENOTSUP; - netdev_opt_t opt = RANDOM_OPTION; - - while (res == -ENOTSUP) { - res = dev->driver->set_option(&wrong_dev, opt, &value, - sizeof(unsigned int)); - - opt = (opt + 1) % OPTION_NUMBER; - } - - TEST_ASSERT_EQUAL_INT(-ENODEV, res); -} - -static void test_netdev_dummy_set_option_null_value(void) -{ - int res = -ENOTSUP; - netdev_opt_t opt = RANDOM_OPTION; - - while (res == -ENOTSUP) { - res = dev->driver->set_option(dev, opt, NULL, sizeof(unsigned int)); - - opt = (opt + 1) % OPTION_NUMBER; - } - - TEST_ASSERT_EQUAL_INT(-EFAULT, res); -} - -static void test_netdev_dummy_set_option_inval(void) -{ - unsigned int value = (unsigned int)TEST_UINT32; - int res = -ENOTSUP; - netdev_opt_t opt = RANDOM_OPTION; - - while (res == -ENOTSUP) { - res = dev->driver->set_option(dev, opt, &value, 0); - - opt = (opt + 1) % OPTION_NUMBER; - } - - TEST_ASSERT_EQUAL_INT(-EINVAL, res); - TEST_ASSERT_EQUAL_INT((unsigned int)TEST_UINT32, value); -} - -static void test_netdev_dummy_set_option_overflow(void) -{ - unsigned int value = (unsigned int)TEST_UINT32; - size_t value_len = UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN + TEST_UINT8 + 1; - int res = -ENOTSUP; - netdev_opt_t opt = RANDOM_OPTION; - - while (res == -ENOTSUP) { - res = dev->driver->set_option(dev, opt, &value, value_len); - - opt = (opt + 1) % OPTION_NUMBER; - } - - TEST_ASSERT_EQUAL_INT(-EOVERFLOW, res); - - TEST_ASSERT_EQUAL_INT((unsigned int)TEST_UINT32, value); -} - -static void test_netdev_dummy_set_option_not_supported(void) -{ - unsigned int value = (unsigned int)TEST_UINT32; - TEST_ASSERT_EQUAL_INT(-ENOTSUP, dev->driver->set_option(dev, - (netdev_opt_t)0xffffffff, &value, sizeof(unsigned int))); - TEST_ASSERT_EQUAL_INT((unsigned int)TEST_UINT32, value); -} - -static void test_netdev_dummy_set_get_channel(void) -{ - unsigned int value = (unsigned int)TEST_UINT32; - size_t value_len = sizeof(unsigned int); - TEST_ASSERT_EQUAL_INT(0, dev->driver->set_option(dev, NETDEV_OPT_CHANNEL, - &value, sizeof(unsigned int))); - value = 0; - TEST_ASSERT_EQUAL_INT(0, dev->driver->get_option(dev, NETDEV_OPT_CHANNEL, - &value, &value_len)); - TEST_ASSERT_EQUAL_INT((unsigned int)TEST_UINT32, value); - TEST_ASSERT_EQUAL_INT(sizeof(unsigned int), value_len); -} - -static void test_netdev_dummy_set_get_address(void) -{ - char value[UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN]; - size_t value_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; -#if UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN < 12 - strncpy(value, TEST_STRING12, UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN); -#else - strncpy(value, TEST_STRING12, 12); -#endif - TEST_ASSERT_EQUAL_INT(0, dev->driver->set_option(dev, NETDEV_OPT_ADDRESS, - value, UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN)); -#if UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN < 12 - memset(value, 0, UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN); -#else - memset(value, 0, 12); -#endif - TEST_ASSERT_EQUAL_INT(0, dev->driver->get_option(dev, NETDEV_OPT_ADDRESS, - value, &value_len)); -#if UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN < 12 - TEST_ASSERT(strncmp(value, TEST_STRING12, - UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN) == 0); -#else - TEST_ASSERT(strncmp(value, TEST_STRING12, 12) == 0); -#endif -} - -static void test_netdev_dummy_set_get_nid(void) -{ - unsigned int value = (unsigned int)TEST_UINT32; - size_t value_len = sizeof(unsigned int); - TEST_ASSERT_EQUAL_INT(0, dev->driver->set_option(dev, NETDEV_OPT_NID, - &value, sizeof(unsigned int))); - value = 0; - TEST_ASSERT_EQUAL_INT(0, dev->driver->get_option(dev, NETDEV_OPT_NID, - &value, &value_len)); - TEST_ASSERT_EQUAL_INT((unsigned int)TEST_UINT32, value); - TEST_ASSERT_EQUAL_INT(sizeof(unsigned int), value_len); -} - -static void test_netdev_dummy_set_get_long_address(void) -{ - char value[UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN]; - size_t value_len = UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN; -#if UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN < 12 - strncpy(value, TEST_STRING12, UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN); -#else - strncpy(value, TEST_STRING12, 12); -#endif - TEST_ASSERT_EQUAL_INT(0, dev->driver->set_option(dev, - NETDEV_OPT_ADDRESS_LONG, value, - UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN)); -#if UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN < 12 - memset(value, 0, UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN); -#else - memset(value, 0, 12); -#endif - TEST_ASSERT_EQUAL_INT(0, dev->driver->get_option(dev, - NETDEV_OPT_ADDRESS_LONG, value, &value_len)); -#if UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN < 12 - TEST_ASSERT(strncmp(value, TEST_STRING12, - UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN) == 0); -#else - TEST_ASSERT(strncmp(value, TEST_STRING12, 12) == 0); -#endif - TEST_ASSERT_EQUAL_INT(UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN, value_len); -} - -static void test_netdev_dummy_set_get_tx_power(void) -{ - int value = TEST_INT; - size_t value_len = sizeof(int); - TEST_ASSERT_EQUAL_INT(0, dev->driver->set_option(dev, NETDEV_OPT_TX_POWER, - &value, sizeof(int))); - value = 0; - TEST_ASSERT_EQUAL_INT(0, dev->driver->get_option(dev, NETDEV_OPT_TX_POWER, - &value, &value_len)); - TEST_ASSERT_EQUAL_INT(TEST_INT, value); - TEST_ASSERT_EQUAL_INT(sizeof(int), value_len); -} - -/********************************************* - * driver::get_state tests * - *********************************************/ - -static void test_netdev_dummy_get_state_dev_null(void) -{ - netdev_state_t state; - TEST_ASSERT_EQUAL_INT(-ENODEV, dev->driver->get_state(NULL, &state)); -} - -static void test_netdev_dummy_get_state_dev_wrong(void) -{ - netdev_state_t state; - netdev_t wrong_dev; - TEST_ASSERT_EQUAL_INT(-ENODEV, dev->driver->get_state(&wrong_dev, &state)); -} - -static void test_netdev_dummy_get_state_null(void) -{ - TEST_ASSERT_EQUAL_INT(-EFAULT, dev->driver->get_state(dev, NULL)); -} - -static void test_netdev_dummy_get_state_value(void) -{ - netdev_state_t state; - TEST_ASSERT_EQUAL_INT(0, dev->driver->get_state(dev, &state)); - TEST_ASSERT_EQUAL_INT(NETDEV_STATE_POWER_OFF, state); -} - -/********************************************* - * driver::set_state tests * - *********************************************/ - -static void test_netdev_dummy_set_state_dev_null(void) -{ - TEST_ASSERT_EQUAL_INT(-ENODEV, dev->driver->set_state(NULL, - NETDEV_STATE_RX_MODE)); -} - -static void test_netdev_dummy_set_state_dev_wrong(void) -{ - netdev_t wrong_dev; - TEST_ASSERT_EQUAL_INT(-ENODEV, dev->driver->set_state(&wrong_dev, - NETDEV_STATE_RX_MODE)); -} - -static void test_netdev_dummy_set_state_max(void) -{ - TEST_ASSERT_EQUAL_INT(-ENOTSUP, - dev->driver->set_state(dev, (netdev_state_t)0xffffffff)); -} - -static void test_netdev_dummy_set_state_value(void) -{ - TEST_ASSERT_EQUAL_INT(0, - dev->driver->set_state(dev, NETDEV_STATE_RX_MODE)); -} - -static void test_netdev_dummy_set_get_state_value(void) -{ - netdev_state_t state; - TEST_ASSERT_EQUAL_INT(0, dev->driver->get_state(dev, &state)); - TEST_ASSERT(NETDEV_STATE_POWER_IDLE != state); - state = NETDEV_STATE_POWER_IDLE; - TEST_ASSERT_EQUAL_INT(0, dev->driver->set_state(dev, state)); - TEST_ASSERT_EQUAL_INT(0, dev->driver->get_state(dev, &state)); - TEST_ASSERT_EQUAL_INT(NETDEV_STATE_POWER_IDLE, state); -} - -/********************************************* - * driver::event tests * - *********************************************/ - -static void test_netdev_dummy_event_dev_null(void) -{ - dev->driver->event(NULL, TEST_UINT32); - TEST_ASSERT_EQUAL_INT(0, unittest_netdev_dummy_get_last_event(dev)); -} - -static void test_netdev_dummy_event_dev_wrong(void) -{ - netdev_t wrong_dev; - dev->driver->event(&wrong_dev, TEST_UINT32); - TEST_ASSERT_EQUAL_INT(0, unittest_netdev_dummy_get_last_event(dev)); -} - -static void test_netdev_dummy_event_value(void) -{ - TEST_ASSERT_EQUAL_INT(0, unittest_netdev_dummy_get_last_event(dev)); - dev->driver->event(dev, TEST_UINT32); - TEST_ASSERT_EQUAL_INT((unsigned int)TEST_UINT32, unittest_netdev_dummy_get_last_event(dev)); -} - -/*********************************************** - * unittest_netdev_dummy_fire_rcv_event tests * - ***********************************************/ - -static void test_netdev_dummy_fire_rcv_event_dev_null(void) -{ - char src[] = TEST_STRING64; - size_t src_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char dest[] = TEST_STRING64; - size_t dest_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char data[] = TEST_STRING8; -#if UNITTESTS_NETDEV_DUMMY_MAX_PACKET < 8 - size_t data_len = UNITTESTS_NETDEV_DUMMY_MAX_PACKET; -#else - size_t data_len = 8; -#endif - TEST_ASSERT_EQUAL_INT(-ENODEV, unittest_netdev_dummy_fire_rcv_event(NULL, - src, src_len, dest, dest_len, data, data_len)); -} - -static void test_netdev_dummy_fire_rcv_event_dev_wrong(void) -{ - char src[] = TEST_STRING64; - size_t src_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char dest[] = TEST_STRING64; - size_t dest_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char data[] = TEST_STRING8; -#if UNITTESTS_NETDEV_DUMMY_MAX_PACKET < 8 - size_t data_len = UNITTESTS_NETDEV_DUMMY_MAX_PACKET; -#else - size_t data_len = 8; -#endif - netdev_t wrong_dev; - TEST_ASSERT_EQUAL_INT(-ENODEV, unittest_netdev_dummy_fire_rcv_event( - &wrong_dev, src, src_len, dest, dest_len, data, - data_len)); -} - -static void test_netdev_dummy_fire_rcv_event_data_too_long(void) -{ - char src[] = TEST_STRING64; - size_t src_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char dest[] = TEST_STRING64; - size_t dest_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char data[] = TEST_STRING64; - size_t data_len = UNITTESTS_NETDEV_DUMMY_MAX_PACKET + 1; - TEST_ASSERT_EQUAL_INT(-EMSGSIZE, unittest_netdev_dummy_fire_rcv_event(dev, - src, src_len, dest, dest_len, data, data_len)); -} - -static void test_netdev_dummy_fire_rcv_event_data_null(void) -{ - char src[] = TEST_STRING64; - size_t src_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char dest[] = TEST_STRING64; - size_t dest_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - size_t data_len = UNITTESTS_NETDEV_DUMMY_MAX_PACKET; - TEST_ASSERT_EQUAL_INT(-EINVAL, unittest_netdev_dummy_fire_rcv_event(dev, - src, src_len, dest, dest_len, NULL, data_len)); -} - -static void test_netdev_dummy_fire_rcv_event_data_null_data_len_null(void) -{ - char src[] = TEST_STRING64; - size_t src_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char dest[] = TEST_STRING64; - size_t dest_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - TEST_ASSERT_EQUAL_INT(0, unittest_netdev_dummy_fire_rcv_event(dev, - src, src_len, dest, dest_len, NULL, 0)); -} - -static void test_netdev_dummy_fire_rcv_event_src_too_long(void) -{ - char src[] = TEST_STRING64; - size_t src_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN + 1; - char dest[] = TEST_STRING64; - size_t dest_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char data[] = TEST_STRING8; -#if UNITTESTS_NETDEV_DUMMY_MAX_PACKET < 8 - size_t data_len = UNITTESTS_NETDEV_DUMMY_MAX_PACKET; -#else - size_t data_len = 8; -#endif - TEST_ASSERT_EQUAL_INT(-EAFNOSUPPORT, unittest_netdev_dummy_fire_rcv_event( - dev, src, src_len, dest, dest_len, data, data_len)); -} - -static void test_netdev_dummy_fire_rcv_event_src_null(void) -{ - size_t src_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char dest[] = TEST_STRING64; - size_t dest_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char data[] = TEST_STRING64; - size_t data_len = UNITTESTS_NETDEV_DUMMY_MAX_PACKET; - TEST_ASSERT_EQUAL_INT(-EINVAL, unittest_netdev_dummy_fire_rcv_event(dev, - NULL, src_len, dest, dest_len, data, data_len)); -} - -static void test_netdev_dummy_fire_rcv_event_dest_too_long(void) -{ - char src[] = TEST_STRING64; - size_t src_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char dest[] = TEST_STRING64; - size_t dest_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN + 1; - char data[] = TEST_STRING8; -#if UNITTESTS_NETDEV_DUMMY_MAX_PACKET < 8 - size_t data_len = UNITTESTS_NETDEV_DUMMY_MAX_PACKET; -#else - size_t data_len = 8; -#endif - TEST_ASSERT_EQUAL_INT(-EAFNOSUPPORT, unittest_netdev_dummy_fire_rcv_event( - dev, src, src_len, dest, dest_len, data, - data_len)); -} - -static void test_netdev_dummy_fire_rcv_event_dest_null(void) -{ - char src[] = TEST_STRING64; - size_t src_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - size_t dest_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char data[] = TEST_STRING64; - size_t data_len = UNITTESTS_NETDEV_DUMMY_MAX_PACKET; - TEST_ASSERT_EQUAL_INT(-EINVAL, unittest_netdev_dummy_fire_rcv_event(dev, - src, src_len, NULL, dest_len, data, data_len)); -} - -static void test_netdev_dummy_fire_rcv_event_no_cb(void) -{ - char src[] = TEST_STRING64; - size_t src_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char dest[] = TEST_STRING64; - size_t dest_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char data[] = TEST_STRING8; -#if UNITTESTS_NETDEV_DUMMY_MAX_PACKET < 8 - size_t data_len = UNITTESTS_NETDEV_DUMMY_MAX_PACKET; -#else - size_t data_len = 8; -#endif - TEST_ASSERT_EQUAL_INT(0, unittest_netdev_dummy_fire_rcv_event(dev, src, - src_len, dest, dest_len, data, data_len)); -} - -static void test_netdev_dummy_fire_rcv_event_failing_cb(void) -{ - char src[] = TEST_STRING64; - size_t src_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char dest[] = TEST_STRING64; - size_t dest_len = UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN; - char data[] = TEST_STRING8; -#if UNITTESTS_NETDEV_DUMMY_MAX_PACKET < 8 - size_t data_len = UNITTESTS_NETDEV_DUMMY_MAX_PACKET; -#else - size_t data_len = 8; -#endif - TEST_ASSERT_EQUAL_INT(0, dev->driver->add_receive_data_callback(dev, - _always_wrong)); - TEST_ASSERT_EQUAL_INT(-ECANCELED, unittest_netdev_dummy_fire_rcv_event( - dev, src, src_len, dest, dest_len, data, data_len)); -} - -/*********************************************** - * unittest_netdev_dummy_get_last_event tests * - ***********************************************/ - -static void test_netdev_dummy_last_event_dev_null(void) -{ - TEST_ASSERT_EQUAL_INT(ENODEV, unittest_netdev_dummy_get_last_event(NULL)); -} - -static void test_netdev_dummy_last_event_dev_wrong(void) -{ - netdev_t wrong_dev; - TEST_ASSERT_EQUAL_INT(ENODEV, unittest_netdev_dummy_get_last_event(&wrong_dev)); -} - -Test *tests_netdev_dummy_tests(void) -{ - EMB_UNIT_TESTFIXTURES(fixtures) { - /* driver::init tests */ - new_TestFixture(test_netdev_dummy_init_dev_null), - new_TestFixture(test_netdev_dummy_init_dev_wrong), - /* driver::send_data tests */ - new_TestFixture(test_netdev_dummy_send_data_dev_null), - new_TestFixture(test_netdev_dummy_send_data_dev_wrong), - new_TestFixture(test_netdev_dummy_send_data_dest_too_long), - new_TestFixture(test_netdev_dummy_send_data_data_too_long), - new_TestFixture(test_netdev_dummy_send_data_no_ulhs), -#if UNITTESTS_NETDEV_DUMMY_MAX_PACKET > 4 - new_TestFixture(test_netdev_dummy_send_data_with_ulhs), -#endif - /* driver::add_receive_data_callback tests */ - new_TestFixture(test_netdev_dummy_add_cb_dev_null), - new_TestFixture(test_netdev_dummy_add_cb_dev_wrong), - new_TestFixture(test_netdev_dummy_add_cb_buffer_full), - new_TestFixture(test_netdev_dummy_add_cb_successful), - /* driver::rem_receive_data_callback tests */ - new_TestFixture(test_netdev_dummy_rem_cb_dev_null), - new_TestFixture(test_netdev_dummy_rem_cb_dev_wrong), - new_TestFixture(test_netdev_dummy_rem_cb_unknown_cb), - new_TestFixture(test_netdev_dummy_rem_cb_successful), - new_TestFixture(test_netdev_dummy_rem_cb_multiple_added), - /* driver::get_option tests */ - new_TestFixture(test_netdev_dummy_get_option_dev_null), - new_TestFixture(test_netdev_dummy_get_option_dev_wrong), - new_TestFixture(test_netdev_dummy_get_option_null_value), - new_TestFixture(test_netdev_dummy_get_option_null_value_len), - new_TestFixture(test_netdev_dummy_get_option_overflow), - new_TestFixture(test_netdev_dummy_get_option_not_supported), - new_TestFixture(test_netdev_dummy_get_channel), - new_TestFixture(test_netdev_dummy_get_address), - new_TestFixture(test_netdev_dummy_get_nid), - new_TestFixture(test_netdev_dummy_get_long_address), - new_TestFixture(test_netdev_dummy_get_tx_power), - /* driver::set_option tests */ - new_TestFixture(test_netdev_dummy_set_option_dev_null), - new_TestFixture(test_netdev_dummy_set_option_dev_wrong), - new_TestFixture(test_netdev_dummy_set_option_null_value), - new_TestFixture(test_netdev_dummy_set_option_inval), - new_TestFixture(test_netdev_dummy_set_option_overflow), - new_TestFixture(test_netdev_dummy_set_option_not_supported), - new_TestFixture(test_netdev_dummy_set_get_channel), - new_TestFixture(test_netdev_dummy_set_get_address), - new_TestFixture(test_netdev_dummy_set_get_nid), - new_TestFixture(test_netdev_dummy_set_get_long_address), - new_TestFixture(test_netdev_dummy_set_get_tx_power), - /* driver::get_state tests */ - new_TestFixture(test_netdev_dummy_get_state_dev_null), - new_TestFixture(test_netdev_dummy_get_state_dev_wrong), - new_TestFixture(test_netdev_dummy_get_state_null), - new_TestFixture(test_netdev_dummy_get_state_value), - /* driver::set_state tests */ - new_TestFixture(test_netdev_dummy_set_state_dev_null), - new_TestFixture(test_netdev_dummy_set_state_dev_wrong), - new_TestFixture(test_netdev_dummy_set_state_max), - new_TestFixture(test_netdev_dummy_set_state_value), - new_TestFixture(test_netdev_dummy_set_get_state_value), - /* driver::event tests */ - new_TestFixture(test_netdev_dummy_event_dev_null), - new_TestFixture(test_netdev_dummy_event_dev_wrong), - new_TestFixture(test_netdev_dummy_event_value), - /* unittest_netdev_dummy_fire_rcv_event tests */ - new_TestFixture(test_netdev_dummy_fire_rcv_event_dev_null), - new_TestFixture(test_netdev_dummy_fire_rcv_event_dev_wrong), - new_TestFixture(test_netdev_dummy_fire_rcv_event_data_too_long), - new_TestFixture(test_netdev_dummy_fire_rcv_event_data_null), - new_TestFixture(test_netdev_dummy_fire_rcv_event_data_null_data_len_null), - new_TestFixture(test_netdev_dummy_fire_rcv_event_src_too_long), - new_TestFixture(test_netdev_dummy_fire_rcv_event_src_null), - new_TestFixture(test_netdev_dummy_fire_rcv_event_dest_too_long), - new_TestFixture(test_netdev_dummy_fire_rcv_event_dest_null), - new_TestFixture(test_netdev_dummy_fire_rcv_event_no_cb), - new_TestFixture(test_netdev_dummy_fire_rcv_event_failing_cb), - /* unittest_netdev_dummy_get_last_event tests */ - new_TestFixture(test_netdev_dummy_last_event_dev_null), - new_TestFixture(test_netdev_dummy_last_event_dev_wrong), - }; - - EMB_UNIT_TESTCALLER(netdev_dummy_tests, set_up, tear_down, - fixtures); - - return (Test *)&netdev_dummy_tests; -} - -void tests_netdev_dummy(void) -{ - TESTS_RUN(tests_netdev_dummy_tests()); -} diff --git a/tests/unittests/tests-netdev_dummy/tests-netdev_dummy.h b/tests/unittests/tests-netdev_dummy/tests-netdev_dummy.h deleted file mode 100644 index a3c5891ef4..0000000000 --- a/tests/unittests/tests-netdev_dummy/tests-netdev_dummy.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2014 Martine Lenders - * - * 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. - */ - -/** - * @addtogroup unittests - * @{ - * - * @file - * @brief Unittests for the ``netdev_dummy`` module - * - * @author Martine Lenders - */ -#ifndef TESTS_NETDEV_DUMMY_H_ -#define TESTS_NETDEV_DUMMY_H_ - -#include "embUnit.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief The entry point of this test suite. - */ -void tests_netdev_dummy(void); - -#ifdef __cplusplus -} -#endif - -#endif /* TESTS_NETDEV_DUMMY_H_ */ -/** @} */