diff --git a/Makefile.dep b/Makefile.dep
index cc60f4681d952160e5426d3c4ec30e715306b553..b38bd61472be60e2a1f6b6f5845a9ca1de783d54 100644
--- a/Makefile.dep
+++ b/Makefile.dep
@@ -649,11 +649,6 @@ ifneq (,$(filter random,$(USEMODULE)))
   USEMODULE += luid
 endif
 
-ifneq (,$(filter openthread_contrib,$(USEMODULE)))
-  USEMODULE += openthread_contrib_netdev
-  FEATURES_REQUIRED += cpp
-endif
-
 ifneq (,$(filter asymcute,$(USEMODULE)))
   USEMODULE += sock_udp
   USEMODULE += sock_util
diff --git a/examples/openthread/Makefile b/examples/openthread/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..ba9b4911d7051d6c9677ba04fcbe1795afeac8d0
--- /dev/null
+++ b/examples/openthread/Makefile
@@ -0,0 +1,52 @@
+APPLICATION = openthread
+
+# If no BOARD is found in the environment, use this default:
+BOARD ?= samr21-xpro
+
+# These are the boards that OpenThread stack has been tested on
+BOARD_WHITELIST := samr21-xpro iotlab-m3 fox iotlab-a8-m3
+
+# This has to be the absolute path to the RIOT base directory:
+RIOTBASE ?= $(CURDIR)/../..
+
+# Change this to 0 show compiler invocation lines by default:
+QUIET ?= 1
+
+USEPKG += openthread
+OPENTHREAD_TYPE ?= ftd
+ifeq ($(OPENTHREAD_TYPE),mtd)
+  # MTD: A Minimal Thread Device does not have router functionality
+  # compiled in. As a result, it is not necessary to configure the
+  # routerrole on an MTD. At the same time, an MTD may or may not be sleepy.
+  USEMODULE += openthread-mtd
+  USEMODULE += openthread-cli-mtd
+else
+  # ftd: A Full Thread Device has router functionality compiled in
+  USEMODULE += openthread-ftd
+  USEMODULE += openthread-cli-ftd
+endif
+
+#Define PANID, CHANNEL and UART_BAUDRATE used by default
+OPENTHREAD_PANID ?= 0xbeef
+OPENTHREAD_CHANNEL ?= 26
+
+CFLAGS += -DOPENTHREAD_PANID=$(OPENTHREAD_PANID)
+CFLAGS += -DOPENTHREAD_CHANNEL=$(OPENTHREAD_CHANNEL)
+
+ifneq (,$(filter samr21-xpro,$(BOARD)))
+  DRIVER := at86rf233
+endif
+ifneq (,$(filter iotlab-m3 fox iotlab-a8-m3,$(BOARD)))
+  DRIVER := at86rf231
+endif
+
+USEMODULE += $(DRIVER)
+
+USEMODULE += random
+USEMODULE += ps
+
+#required for C++ compiling
+CXXEXFLAGS += -fno-rtti
+USEMODULE += cpp11-compat
+
+include $(RIOTBASE)/Makefile.include
diff --git a/examples/openthread/README.md b/examples/openthread/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..0854debc67c433b7ebe1e07fb1d23de3dcda01b1
--- /dev/null
+++ b/examples/openthread/README.md
@@ -0,0 +1,70 @@
+## OpenThread on RIOT
+
+This example demonstrates how to use the [OpenThread](https://github.com/openthread/openthread)
+open source implementation of [Thread](https://threadgroup.org/) on RIOT.
+
+The [Command Line Interface](https://github.com/openthread/openthread/blob/master/examples/apps/cli/README.md) of
+OpenThread was ported. Please check the
+[full documentation](https://github.com/openthread/openthread/blob/master/src/cli/README.md)
+of the CLI for usage information.
+
+You can either build a FTD or MTD firmware:
+- MTD: A Minimal Thread Device does not have router functionality compiled in.
+       An MTD may or may not be sleepy.
+- FTD: A Full Thread Device has router functionality compiled in.
+
+## Quick usage
+
+With RIOT port, a node is auto-setup and ready to communicate with
+this configuration:
+```
+OPENTHREAD_PANID=0xbeef
+OPENTHREAD_CHANNEL=26
+```
+
+You can pass the panid/channel independently when building the firmware:
+```
+make BOARD=<target> OPENTHREAD_PANID=0xaaaa OPENTHREAD_TYPE=ftd flash term
+```
+```
+make BOARD=<target> OPENTHREAD_CHANNEL=20 OPENTHREAD_TYPE=ftd flash term
+```
+
+To try OpenThread in RIOT, you can do the following:
+
+1. Flash nodes with MTD or FTD functionality:
+```
+make BOARD=<target> clean all flash OPENTHREAD_TYPE=mtd
+```
+```
+make BOARD=<target> clean all flash OPENTHREAD_TYPE=ftd
+```
+
+2. Check the state of the node with `state`. In the beginning, it should be
+`detached`, but after some seconds it should become `leader`
+
+3. Start another node and check that it becomes `router`. There is only one
+leader in a Thread network.
+
+4. Get the mesh IP address of a node with `ipaddr`.
+```
+ipaddr
+   fdde:ad00:beef::ff:fe00:8000
+   fe80::ff:fe00:8000
+   fdde:ad00:beef:0:946a:c722:a5d9:8481
+   fe80::3984:f4eb:d182:5dae
+```
+5. Ping from another node with
+```
+ping fdde:ad00:beef:0:946a:c722:a5d9:848
+```
+
+6. You can try IEEE802.15.4 scan with `scan` command
+
+7. You can also check other commands with `help`
+
+
+## OpenThread port on RIOT status
+
+OpenThread port on RIOT is stable. In case of any bug, please report via
+[GitHub issue](https://github.com/RIOT-OS/RIOT/issues/new?template=bug_report.md&title=Bug).
diff --git a/tests/openthread/main.c b/examples/openthread/main.c
similarity index 64%
rename from tests/openthread/main.c
rename to examples/openthread/main.c
index 591abb3cef78d2ed0e4db4012e522041316aa159..facd03fb6189411a0b17b0bd7cf0b0d3ed82686a 100644
--- a/tests/openthread/main.c
+++ b/examples/openthread/main.c
@@ -10,25 +10,21 @@
  * @file
  * @brief       OpenThread test application
  *
- * @author      Baptiste Clenet <baptiste.clenet@xsoen.com>
+ * @author      Baptiste Clenet <bapclenet@gmail.com>
  */
 
 #include <stdio.h>
 
-#include "net/ipv6/addr.h"
-#include "openthread/ip6.h"
-#include "openthread/thread.h"
-#include "openthread/udp.h"
 #include "ot.h"
-#include "shell.h"
-#include "shell_commands.h"
+
 int main(void)
 {
-    printf("Get PANID\n");
+    puts("This a test for OpenThread");
+    /* Example of how to call OpenThread stack functions */
+    puts("Get PANID ");
     uint16_t panid = 0;
     uint8_t res = ot_call_command("panid", NULL, (void*)&panid);
     printf("Current panid: 0x%x (res:%x)\n", panid, res);
 
-    openthread_uart_run();
     return 0;
 }
diff --git a/pkg/openthread/Makefile b/pkg/openthread/Makefile
index 77da3995d942fe37f05773d6098778541eed233e..863c1af35915031c533d866ea0141f326ec3ad01 100644
--- a/pkg/openthread/Makefile
+++ b/pkg/openthread/Makefile
@@ -1,24 +1,31 @@
 PKG_NAME=openthread
 PKG_URL=https://github.com/openthread/openthread.git
-PKG_VERSION=fbfd76a990b81f007957e1bd774e51bce742e53e
+PKG_VERSION=thread-reference-20170716
 PKG_BUILDDIR ?= $(PKGDIRBASE)/$(PKG_NAME)
 
-$(info Compile OpenThread for FTD device)
-OPENTHREAD_ARGS+= --enable-cli-app=ftd --enable-application-coap
-
-$(info $$OPENTHREAD_ARGS is [$(OPENTHREAD_ARGS)])
+ifneq (,$(filter openthread-cli-ftd,$(USEMODULE)))
+  $(info Compile OpenThread for FTD device)
+  OPENTHREAD_ARGS += --enable-cli-app=ftd
+endif
+ifneq (,$(filter openthread-cli-mtd,$(USEMODULE)))
+  $(info Compile OpenThread for MTD device)
+  OPENTHREAD_ARGS += --enable-cli-app=mtd --enable-joiner
+endif
+OPENTHREAD_ARGS += --enable-application-coap
+CONFIG_FILE      = OPENTHREAD_PROJECT_CORE_CONFIG_FILE='\"platform_config.h\"'
+$(info $$OPENTHREAD_ARGS is [${OPENTHREAD_ARGS}])
 
 .PHONY: all
 
 OPENTHREAD_COMMON_FLAGS = -fdata-sections -ffunction-sections -Os
-OPENTHREAD_COMMON_FLAGS += -Wno-implicit-fallthrough
+OPENTHREAD_COMMON_FLAGS += -Wno-implicit-fallthrough -Wno-unused-parameter
 
 all: git-download
 	cd $(PKG_BUILDDIR) && PREFIX="/" ./bootstrap
 	cd $(PKG_BUILDDIR) && CPP="$(CPP)" CC="$(CC)" CXX="$(CXX)"\
 		OBJC="" OBJCXX="" AR="$(AR)" RANLIB="$(RANLIB)" NM="$(NM)" \
 		STRIP="$(STRIP)" \
-		CPPFLAGS="$(OPENTHREAD_COMMON_FLAGS) $(CFLAGS_CPU) " \
+		CPPFLAGS="$(OPENTHREAD_COMMON_FLAGS) $(CFLAGS_CPU) -D$(CONFIG_FILE)" \
 		CFLAGS="$(OPENTHREAD_COMMON_FLAGS) $(CFLAGS_CPU) " \
 		CXXFLAGS="$(OPENTHREAD_COMMON_FLAGS) $(CFLAGS_CPU) -fno-exceptions -fno-rtti " \
 		LDFLAGS="$(OPENTHREAD_COMMON_FLAGS) $(CFLAGS_CPU) -nostartfiles -specs=nano.specs \
@@ -27,9 +34,14 @@ all: git-download
 		--prefix=/ --enable-default-logging $(OPENTHREAD_ARGS)
 	cd $(PKG_BUILDDIR) &&  DESTDIR=$(PKG_BUILDDIR)/output PREFIX=/ make -j4 --no-print-directory install
 
-	cp $(PKG_BUILDDIR)/output/lib/libmbedcrypto.a $(BINDIR)/libmbedcrypto.a
-	cp $(PKG_BUILDDIR)/output/lib/libopenthread-ftd.a $(BINDIR)/libopenthread.a
-	cp $(PKG_BUILDDIR)/output/lib/libopenthread-cli-ftd.a $(BINDIR)/libopenthread-cli.a
-	sed -ie 's/BASE/_BASE/g' $(PKG_BUILDDIR)/output/include/openthread/types.h
+	cp $(PKG_BUILDDIR)/output/lib/libmbedcrypto.a ${BINDIR}/mbedcrypto.a
+ifneq (,$(filter openthread-cli-ftd,$(USEMODULE)))
+	cp $(PKG_BUILDDIR)/output/lib/libopenthread-ftd.a ${BINDIR}/openthread-ftd.a
+	cp $(PKG_BUILDDIR)/output/lib/libopenthread-cli-ftd.a ${BINDIR}/openthread-cli-ftd.a
+endif
+ifneq (,$(filter openthread-cli-mtd,$(USEMODULE)))
+	cp $(PKG_BUILDDIR)/output/lib/libopenthread-mtd.a ${BINDIR}/openthread-mtd.a
+	cp $(PKG_BUILDDIR)/output/lib/libopenthread-cli-mtd.a ${BINDIR}/openthread-cli-mtd.a
+endif
 
 include $(RIOTBASE)/pkg/pkg.mk
diff --git a/pkg/openthread/Makefile.dep b/pkg/openthread/Makefile.dep
new file mode 100644
index 0000000000000000000000000000000000000000..3792eb87f44620202094b4f316f7dacedd99298e
--- /dev/null
+++ b/pkg/openthread/Makefile.dep
@@ -0,0 +1,10 @@
+ifneq (,$(filter openthread,$(USEPKG)))
+  USEMODULE += openthread_contrib
+  USEMODULE += mbedcrypto
+endif
+
+ifneq (,$(filter openthread_contrib,$(USEMODULE)))
+  USEMODULE += openthread_contrib_netdev
+  USEMODULE += xtimer
+  FEATURES_REQUIRED += cpp
+endif
diff --git a/pkg/openthread/Makefile.include b/pkg/openthread/Makefile.include
index e2efe807b10c39e171c0b2484773012429ca2680..d399a8f90253d2e172879230a5c8d5fa22598556 100644
--- a/pkg/openthread/Makefile.include
+++ b/pkg/openthread/Makefile.include
@@ -1,8 +1,7 @@
 OPENTHREAD_DIR = $(RIOTBASE)/pkg/openthread
 
 INCLUDES += -I$(OPENTHREAD_DIR)/include \
-            -I$(PKGDIRBASE)/openthread/output/include \
-            -I$(PKGDIRBASE)/openthread/include/openthread \
+            -I$(PKGDIRBASE)/openthread/include
 
 ifneq (,$(filter openthread_contrib,$(USEMODULE)))
   DIRS += $(OPENTHREAD_DIR)/contrib
diff --git a/pkg/openthread/contrib/netdev/openthread_netdev.c b/pkg/openthread/contrib/netdev/openthread_netdev.c
old mode 100644
new mode 100755
index 446076cf586cd2d21bb1c3496a85855b76ebcae3..862290a98136a0fcc8cfc615fee210aab2e3094c
--- a/pkg/openthread/contrib/netdev/openthread_netdev.c
+++ b/pkg/openthread/contrib/netdev/openthread_netdev.c
@@ -13,6 +13,7 @@
  * @brief       Netdev adoption for OpenThread
  *
  * @author      Jose Ignacio Alamos <jialamos@uc.cl>
+ * @author      Baptiste Clenet <bapclenet@gmail.com>
  * @}
  */
 
@@ -23,7 +24,7 @@
 #include "openthread/cli.h"
 #include "openthread/instance.h"
 #include "openthread/ip6.h"
-#include "openthread/platform/alarm.h"
+#include "openthread/platform/alarm-milli.h"
 #include "openthread/platform/uart.h"
 #include "openthread/tasklet.h"
 #include "openthread/thread.h"
@@ -39,18 +40,6 @@ static msg_t _queue[OPENTHREAD_QUEUE_LEN];
 static kernel_pid_t _pid;
 static otInstance *sInstance;
 
-/**
- * @name    Default configuration for OpenThread network
- * @{
- */
-#ifndef OPENTHREAD_PANID
-#define OPENTHREAD_PANID            0x1234
-#endif
-#ifndef OPENTHREAD_CHANNEL
-#define OPENTHREAD_CHANNEL          (26U)
-#endif
-/** @} */
-
 uint8_t ot_call_command(char* command, void *arg, void* answer) {
     ot_job_t job;
 
@@ -67,7 +56,7 @@ uint8_t ot_call_command(char* command, void *arg, void* answer) {
 
 /* OpenThread will call this when switching state from empty tasklet to non-empty tasklet. */
 void otTaskletsSignalPending(otInstance *aInstance) {
-    otTaskletsProcess(aInstance);
+    (void) aInstance;
 }
 
 static void *_openthread_event_loop(void *arg) {
@@ -78,18 +67,14 @@ static void *_openthread_event_loop(void *arg) {
     otPlatUartEnable();
 
     /* init OpenThread */
-    sInstance = otInstanceInit();
+    sInstance = otInstanceInitSingle();
 
     msg_init_queue(_queue, OPENTHREAD_QUEUE_LEN);
     netdev_t *dev;
     msg_t msg, reply;
 
+#if defined(MODULE_OPENTHREAD_CLI_FTD) || defined(MODULE_OPENTHREAD_CLI_MTD)
     otCliUartInit(sInstance);
-
-#if OPENTHREAD_ENABLE_DIAG
-    diagInit(sInstance);
-#endif
-
     /* Init default parameters */
     otPanId panid = OPENTHREAD_PANID;
     uint8_t channel = OPENTHREAD_CHANNEL;
@@ -99,31 +84,40 @@ static void *_openthread_event_loop(void *arg) {
     otIp6SetEnabled(sInstance, true);
     /* Start Thread protocol operation */
     otThreadSetEnabled(sInstance, true);
+#endif
+
+#if OPENTHREAD_ENABLE_DIAG
+    diagInit(sInstance);
+#endif
 
-    uint8_t *buf;
     ot_job_t *job;
+    serial_msg_t* serialBuffer;
     while (1) {
-        msg_receive(&msg);
-        switch (msg.type) {
-            case OPENTHREAD_XTIMER_MSG_TYPE_EVENT:
-                /* Tell OpenThread a time event was received */
-                otPlatAlarmFired(sInstance);
-                break;
-            case OPENTHREAD_NETDEV_MSG_TYPE_EVENT:
-                /* Received an event from driver */
-                dev = msg.content.ptr;
-                dev->driver->isr(dev);
-                break;
-            case OPENTHREAD_SERIAL_MSG_TYPE_EVENT:
-                /* Tell OpenThread about the reception of a CLI command */
-                buf = msg.content.ptr;
-                otPlatUartReceived(buf, strlen((char *) buf));
-                break;
-            case OPENTHREAD_JOB_MSG_TYPE_EVENT:
-                job = msg.content.ptr;
-                reply.content.value = ot_exec_command(sInstance, job->command, job->arg, job->answer);
-                msg_reply(&msg, &reply);
-                break;
+        otTaskletsProcess(sInstance);
+        if (otTaskletsArePending(sInstance) == false) {
+            msg_receive(&msg);
+            switch (msg.type) {
+                case OPENTHREAD_XTIMER_MSG_TYPE_EVENT:
+                    /* Tell OpenThread a time event was received */
+                    otPlatAlarmMilliFired(sInstance);
+                    break;
+                case OPENTHREAD_NETDEV_MSG_TYPE_EVENT:
+                    /* Received an event from driver */
+                    dev = msg.content.ptr;
+                    dev->driver->isr(dev);
+                    break;
+                case OPENTHREAD_SERIAL_MSG_TYPE_EVENT:
+                    /* Tell OpenThread about the reception of a CLI command */
+                    serialBuffer = (serial_msg_t*)msg.content.ptr;
+                    otPlatUartReceived((uint8_t*) serialBuffer->buf,serialBuffer->length);
+                    serialBuffer->serial_buffer_status = OPENTHREAD_SERIAL_BUFFER_STATUS_FREE;
+                    break;
+                case OPENTHREAD_JOB_MSG_TYPE_EVENT:
+                    job = msg.content.ptr;
+                    reply.content.value = ot_exec_command(sInstance, job->command, job->arg, job->answer);
+                    msg_reply(&msg, &reply);
+                    break;
+            }
         }
     }
 
diff --git a/pkg/openthread/contrib/openthread.c b/pkg/openthread/contrib/openthread.c
index 882bb9bd7ae69a4a059cfc02084e200079fc2a15..d9584b3a112535e813b02a75a7d29d84437b3a4d 100644
--- a/pkg/openthread/contrib/openthread.c
+++ b/pkg/openthread/contrib/openthread.c
@@ -18,7 +18,7 @@
 
 #include <assert.h>
 
-#include "openthread/platform/alarm.h"
+#include "openthread/platform/alarm-milli.h"
 #include "openthread/platform/uart.h"
 #include "ot.h"
 #include "random.h"
@@ -41,29 +41,10 @@
 static at86rf2xx_t at86rf2xx_dev;
 #endif
 
-#define OPENTHREAD_NETDEV_BUFLEN (ETHERNET_MAX_LEN)
-
 static uint8_t rx_buf[OPENTHREAD_NETDEV_BUFLEN];
 static uint8_t tx_buf[OPENTHREAD_NETDEV_BUFLEN];
 static char ot_thread_stack[2 * THREAD_STACKSIZE_MAIN];
 
-/* init and run OpeanThread's UART simulation (stdio) */
-void openthread_uart_run(void)
-{
-    char buf[256];
-    msg_t msg;
-
-    msg.type = OPENTHREAD_SERIAL_MSG_TYPE_EVENT;
-    msg.content.ptr = buf;
-
-    buf[1] = 0;
-    while (1) {
-        char c = getchar();
-        buf[0] = c;
-        msg_send(&msg, openthread_get_pid());
-    }
-}
-
 void openthread_bootstrap(void)
 {
     /* init random */
diff --git a/pkg/openthread/contrib/platform_alarm.c b/pkg/openthread/contrib/platform_alarm.c
index 52b8d48caa66632dd0c33f8586d73d93c619fe9a..f7d50b0d4f84747be15dbdc79ac1b4681ed840c4 100644
--- a/pkg/openthread/contrib/platform_alarm.c
+++ b/pkg/openthread/contrib/platform_alarm.c
@@ -19,7 +19,7 @@
 #include <stdint.h>
 
 #include "msg.h"
-#include "openthread/platform/alarm.h"
+#include "openthread/platform/alarm-milli.h"
 #include "ot.h"
 #include "thread.h"
 #include "xtimer.h"
@@ -38,7 +38,7 @@ static msg_t ot_alarm_msg;
  * @param[in] aT0        The reference time.
  * @param[in] aDt        The time delay in milliseconds from @p aT0.
  */
-void otPlatAlarmStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt)
+void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt)
 {
     (void)aInstance;
     (void)aT0;
@@ -56,7 +56,7 @@ void otPlatAlarmStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt)
 }
 
 /* OpenThread will call this to stop alarms */
-void otPlatAlarmStop(otInstance *aInstance)
+void otPlatAlarmMilliStop(otInstance *aInstance)
 {
     (void)aInstance;
     DEBUG("openthread: otPlatAlarmStop\n");
@@ -64,7 +64,7 @@ void otPlatAlarmStop(otInstance *aInstance)
 }
 
 /* OpenThread will call this for getting running time in millisecs */
-uint32_t otPlatAlarmGetNow(void)
+uint32_t otPlatAlarmMilliGetNow(void)
 {
     uint32_t now = xtimer_now_usec() / US_PER_MS;
     DEBUG("openthread: otPlatAlarmGetNow: %" PRIu32 "\n", now);
diff --git a/pkg/openthread/contrib/platform_functions_wrapper.c b/pkg/openthread/contrib/platform_functions_wrapper.c
index 832765b4f2c293274b884670a853f64b119a2249..8693f70d17b0779dc6f86904a2a15612ca9b9446 100644
--- a/pkg/openthread/contrib/platform_functions_wrapper.c
+++ b/pkg/openthread/contrib/platform_functions_wrapper.c
@@ -264,26 +264,23 @@ OT_COMMAND ot_state(otInstance* ot_instance, void* arg, void* answer) {
     (void)arg;
 
     if (answer != NULL) {
-        uint8_t state = otThreadGetDeviceRole(ot_instance);
-        *((uint8_t *) answer) = state;
+        otDeviceRole state = otThreadGetDeviceRole(ot_instance);
+        *((otDeviceRole *) answer) = state;
         DEBUG("state: ");
         switch (state) {
-            case kDeviceRoleOffline:
-                puts("offline");
-                break;
-            case kDeviceRoleDisabled:
+            case OT_DEVICE_ROLE_DISABLED:
                 puts("disabled");
                 break;
-            case kDeviceRoleDetached:
+            case OT_DEVICE_ROLE_DETACHED:
                 puts("detached");
                 break;
-            case kDeviceRoleChild:
+            case OT_DEVICE_ROLE_CHILD:
                 puts("child");
                 break;
-            case kDeviceRoleRouter:
+            case OT_DEVICE_ROLE_ROUTER:
                 puts("router");
                 break;
-            case kDeviceRoleLeader:
+            case OT_DEVICE_ROLE_LEADER:
                 puts("leader");
                 break;
             default:
diff --git a/pkg/openthread/contrib/platform_logging.c b/pkg/openthread/contrib/platform_logging.c
index a7deade082bc957757e3674cd7988a0902579838..4917354519646f79112ce421693566a1b27b3779 100644
--- a/pkg/openthread/contrib/platform_logging.c
+++ b/pkg/openthread/contrib/platform_logging.c
@@ -13,6 +13,7 @@
  * @brief       Implementation of OpenThread logging platform abstraction
  *
  * @author      Jose Ignacio Alamos <jialamos@uc.cl>
+ * @author      Baptiste Clenet <bapclenet@gmail.com>
  * @}
  */
 
@@ -20,10 +21,9 @@
 #include <inttypes.h>
 #include <stdarg.h>
 #include <stdio.h>
-#include <stdint.h>
 #include <string.h>
-#include <time.h>
 
+#include "openthread/config.h"
 #include "openthread/platform/logging.h"
 
 /* adapted from OpenThread posix example:
@@ -31,68 +31,11 @@
 __attribute__((__format__ (__printf__, 3, 4)))
 void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
 {
+    (void) aLogLevel;
+    (void) aLogRegion;
     va_list args;
-
-    switch (aLogLevel) {
-        case kLogLevelNone:
-            fprintf(stderr, "NONE ");
-            break;
-
-        case kLogLevelCrit:
-            fprintf(stderr, "CRIT ");
-            break;
-
-        case kLogLevelWarn:
-            fprintf(stderr, "WARN ");
-            break;
-
-        case kLogLevelInfo:
-            fprintf(stderr, "INFO ");
-            break;
-
-        case kLogLevelDebg:
-            fprintf(stderr, "DEBG ");
-            break;
-    }
-
-    switch (aLogRegion) {
-        case kLogRegionApi:
-            fprintf(stderr, "API  ");
-            break;
-
-        case kLogRegionMle:
-            fprintf(stderr, "MLE  ");
-            break;
-
-        case kLogRegionArp:
-            fprintf(stderr, "ARP  ");
-            break;
-
-        case kLogRegionNetData:
-            fprintf(stderr, "NETD ");
-            break;
-
-        case kLogRegionIp6:
-            fprintf(stderr, "IPV6 ");
-            break;
-
-        case kLogRegionIcmp:
-            fprintf(stderr, "ICMP ");
-            break;
-
-        case kLogRegionMac:
-            fprintf(stderr, "MAC  ");
-            break;
-
-        case kLogRegionMem:
-            fprintf(stderr, "MEM  ");
-            break;
-        default:
-            break;
-    }
-
     va_start(args, aFormat);
     vfprintf(stderr, aFormat, args);
-    fprintf(stderr, "\r");
+    fprintf(stderr, "\n");
     va_end(args);
 }
diff --git a/pkg/openthread/contrib/platform_misc.c b/pkg/openthread/contrib/platform_misc.c
index d8bc9af2b3c60c0fe2aa795ecc587f67cc90f544..2d6e97a56bb4ffaf601d5d0c019d4fad56fcf3e7 100644
--- a/pkg/openthread/contrib/platform_misc.c
+++ b/pkg/openthread/contrib/platform_misc.c
@@ -21,10 +21,13 @@
 #include "openthread/platform/misc.h"
 #include "periph/pm.h"
 
+#define ENABLE_DEBUG (0)
+#include "debug.h"
+
 void otPlatReset(otInstance *aInstance)
 {
     (void)aInstance;
-    printf("reboot...\n");
+    DEBUG("reboot...\n");
     pm_reboot();
 }
 
@@ -32,5 +35,10 @@ otPlatResetReason otPlatGetResetReason(otInstance *aInstance)
 {
     (void)aInstance;
     /* TODO: Write me! */
-    return kPlatResetReason_PowerOn;
+    return OT_PLAT_RESET_REASON_POWER_ON;
+}
+
+void otPlatWakeHost(void)
+{
+    /* TODO: implement an operation to wake the host from sleep state. */
 }
diff --git a/pkg/openthread/contrib/platform_radio.c b/pkg/openthread/contrib/platform_radio.c
old mode 100644
new mode 100755
index 8095bb658089dabfe1375442dc4d023ad8c0a6f2..992a6f97069ec54edaa2fad8367cdb78f7d7a891
--- a/pkg/openthread/contrib/platform_radio.c
+++ b/pkg/openthread/contrib/platform_radio.c
@@ -26,6 +26,9 @@
 #include "net/ethertype.h"
 #include "net/ieee802154.h"
 #include "net/netdev/ieee802154.h"
+#include "openthread/config.h"
+#include "openthread/openthread.h"
+#include "openthread/platform/diag.h"
 #include "openthread/platform/radio.h"
 #include "ot.h"
 
@@ -34,14 +37,12 @@
 
 #define RADIO_IEEE802154_FCS_LEN    (2U)
 
-static RadioPacket sTransmitFrame;
-static RadioPacket sReceiveFrame;
+static otRadioFrame sTransmitFrame;
+static otRadioFrame sReceiveFrame;
 static int8_t Rssi;
 
 static netdev_t *_dev;
 
-static bool sDisabled;
-
 /* set 15.4 channel */
 static int _set_channel(uint16_t channel)
 {
@@ -54,6 +55,13 @@ static int _set_power(int16_t power)
     return _dev->driver->set(_dev, NETOPT_TX_POWER, &power, sizeof(int16_t));
 }
 
+static int _get_power(void)
+{
+    int16_t power;
+    _dev->driver->get(_dev, NETOPT_TX_POWER, &power, sizeof(int16_t));
+    return power;
+}
+
 /* set IEEE802.15.4 PAN ID */
 static int _set_panid(uint16_t panid)
 {
@@ -101,6 +109,11 @@ static netopt_state_t _get_state(void)
     return state;
 }
 
+static void _set_off(void)
+{
+    _set_state(NETOPT_STATE_OFF);
+}
+
 /* sets device state to SLEEP */
 static void _set_sleep(void)
 {
@@ -134,7 +147,7 @@ void recv_pkt(otInstance *aInstance, netdev_t *dev)
     /* very unlikely */
     if ((len < 0) || ((uint32_t)len > UINT16_MAX)) {
         DEBUG("Invalid len: %d\n", len);
-        otPlatRadioReceiveDone(aInstance, NULL, kThreadError_Abort);
+        otPlatRadioReceiveDone(aInstance, NULL, OT_ERROR_ABORT);
         return;
     }
 
@@ -148,16 +161,16 @@ void recv_pkt(otInstance *aInstance, netdev_t *dev)
 
     /* Get RSSI from a radio driver. RSSI should be in [dBm] */
     Rssi = (int8_t)rx_info.rssi;
-    sReceiveFrame.mPower = Rssi;
-
-   DEBUG("Received message: len %d\n", (int) sReceiveFrame.mLength);
-    for (int i = 0; i < sReceiveFrame.mLength; ++i) {
-        DEBUG("%x ", sReceiveFrame.mPsdu[i]);
+    if (ENABLE_DEBUG) {
+        DEBUG("Received message: len %d\n", (int) sReceiveFrame.mLength);
+        for (int i = 0; i < sReceiveFrame.mLength; ++i) {
+            DEBUG("%x ", sReceiveFrame.mPsdu[i]);
+        }
+        DEBUG("\n");
     }
-    DEBUG("\n");
 
     /* Tell OpenThread that receive has finished */
-    otPlatRadioReceiveDone(aInstance, res > 0 ? &sReceiveFrame : NULL, res > 0 ? kThreadError_None : kThreadError_Abort);
+    otPlatRadioReceiveDone(aInstance, res > 0 ? &sReceiveFrame : NULL, res > 0 ? OT_ERROR_NONE : OT_ERROR_ABORT);
 }
 
 /* Called upon TX event */
@@ -169,19 +182,19 @@ void send_pkt(otInstance *aInstance, netdev_t *dev, netdev_event_t event)
     switch (event) {
         case NETDEV_EVENT_TX_COMPLETE:
             DEBUG("openthread: NETDEV_EVENT_TX_COMPLETE\n");
-            otPlatRadioTransmitDone(aInstance, &sTransmitFrame, false, kThreadError_None);
+            otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_NONE);
             break;
         case NETDEV_EVENT_TX_COMPLETE_DATA_PENDING:
             DEBUG("openthread: NETDEV_EVENT_TX_COMPLETE_DATA_PENDING\n");
-            otPlatRadioTransmitDone(aInstance, &sTransmitFrame, true, kThreadError_None);
+            otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_NONE);
             break;
         case NETDEV_EVENT_TX_NOACK:
             DEBUG("openthread: NETDEV_EVENT_TX_NOACK\n");
-            otPlatRadioTransmitDone(aInstance, &sTransmitFrame, false, kThreadError_NoAck);
+            otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_NO_ACK);
             break;
         case NETDEV_EVENT_TX_MEDIUM_BUSY:
             DEBUG("openthread: NETDEV_EVENT_TX_MEDIUM_BUSY\n");
-            otPlatRadioTransmitDone(aInstance, &sTransmitFrame, false, kThreadError_ChannelAccessFailure);
+            otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_CHANNEL_ACCESS_FAILURE);
             break;
         default:
             break;
@@ -201,55 +214,59 @@ void otPlatRadioSetExtendedAddress(otInstance *aInstance, uint8_t *aExtendedAddr
 {
     (void)aInstance;
     DEBUG("openthread: otPlatRadioSetExtendedAddress\n");
-    uint8_t reversed_addr[IEEE802154_LONG_ADDRESS_LEN];
+    char reversed_addr[IEEE802154_LONG_ADDRESS_LEN];
     for (unsigned i = 0; i < IEEE802154_LONG_ADDRESS_LEN; i++) {
-        reversed_addr[i] = aExtendedAddress[IEEE802154_LONG_ADDRESS_LEN - 1 - i];
+        reversed_addr[i] = (uint8_t) ((uint8_t *)aExtendedAddress)[IEEE802154_LONG_ADDRESS_LEN - 1 - i];
+    }
+    if (ENABLE_DEBUG) {
+        for (unsigned i = 0; i < IEEE802154_LONG_ADDRESS_LEN; ++i) {
+            DEBUG("%x ", (uint8_t) ((uint8_t *)reversed_addr)[i]);
+        }
+        DEBUG("\n");
     }
-    _set_long_addr(reversed_addr);
+    _set_long_addr((uint8_t*) reversed_addr);
 }
 
 /* OpenThread will call this for setting short address */
 void otPlatRadioSetShortAddress(otInstance *aInstance, uint16_t aShortAddress)
 {
-    (void) aInstance;
+    (void)aInstance;
     DEBUG("openthread: otPlatRadioSetShortAddress: setting address to %04x\n", aShortAddress);
     _set_addr(((aShortAddress & 0xff) << 8) | ((aShortAddress >> 8) & 0xff));
 }
 
 /* OpenThread will call this for enabling the radio */
-ThreadError otPlatRadioEnable(otInstance *aInstance)
+otError otPlatRadioEnable(otInstance *aInstance)
 {
     DEBUG("openthread: otPlatRadioEnable\n");
-    (void) aInstance;
+    (void)aInstance;
 
-    if (sDisabled) {
-        sDisabled = false;
-        _set_idle();
+    if (!otPlatRadioIsEnabled(aInstance)) {
+        _set_sleep();
     }
 
-    return kThreadError_None;
+    return OT_ERROR_NONE;
 }
 
 /* OpenThread will call this for disabling the radio */
-ThreadError otPlatRadioDisable(otInstance *aInstance)
+otError otPlatRadioDisable(otInstance *aInstance)
 {
     DEBUG("openthread: otPlatRadioDisable\n");
-    (void) aInstance;
+    (void)aInstance;
 
-    if (!sDisabled) {
-        sDisabled = true;
-        _set_sleep();
+    if (otPlatRadioIsEnabled(aInstance)) {
+        _set_off();
     }
 
-    return kThreadError_None;
+    return OT_ERROR_NONE;
 }
 
 bool otPlatRadioIsEnabled(otInstance *aInstance)
 {
     DEBUG("otPlatRadioIsEnabled\n");
-    (void) aInstance;
+    (void)aInstance;
     netopt_state_t state = _get_state();
-    if (state == NETOPT_STATE_OFF || state == NETOPT_STATE_SLEEP) {
+    if (state == NETOPT_STATE_OFF) {
         return false;
     } else {
         return true;
@@ -257,30 +274,31 @@ bool otPlatRadioIsEnabled(otInstance *aInstance)
 }
 
 /* OpenThread will call this for setting device state to SLEEP */
-ThreadError otPlatRadioSleep(otInstance *aInstance)
+otError otPlatRadioSleep(otInstance *aInstance)
 {
     DEBUG("otPlatRadioSleep\n");
-    (void) aInstance;
+    (void)aInstance;
 
     _set_sleep();
-    return kThreadError_None;
+    return OT_ERROR_NONE;
 }
 
 /*OpenThread will call this for waiting the reception of a packet */
-ThreadError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel)
+otError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel)
 {
     DEBUG("openthread: otPlatRadioReceive. Channel: %i\n", aChannel);
-    (void) aInstance;
+    (void)aInstance;
 
     _set_idle();
     _set_channel(aChannel);
-    return kThreadError_None;
+    sReceiveFrame.mChannel = aChannel;
+    return OT_ERROR_NONE;
 }
 
 /* OpenThread will call this function to get the transmit buffer */
-RadioPacket *otPlatRadioGetTransmitBuffer(otInstance *aInstance)
+otRadioFrame *otPlatRadioGetTransmitBuffer(otInstance *aInstance)
 {
-    (void) aInstance;
+    (void)aInstance;
     DEBUG("openthread: otPlatRadioGetTransmitBuffer\n");
     return &sTransmitFrame;
 }
@@ -293,8 +311,28 @@ void otPlatRadioSetDefaultTxPower(otInstance *aInstance, int8_t aPower)
     _set_power(aPower);
 }
 
+otError otPlatRadioGetTransmitPower(otInstance *aInstance, int8_t *aPower)
+{
+    (void)aInstance;
+    if (aPower == NULL) {
+        return OT_ERROR_INVALID_ARGS;
+    }
+
+    *aPower = _get_power();
+
+    return OT_ERROR_NONE;
+}
+
+otError otPlatRadioSetTransmitPower(otInstance *aInstance, int8_t aPower)
+{
+    (void)aInstance;
+    _set_power(aPower);
+
+    return OT_ERROR_NONE;
+}
+
 /* OpenThread will call this for transmitting a packet*/
-ThreadError otPlatRadioTransmit(otInstance *aInstance, RadioPacket *aPacket)
+otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aPacket)
 {
     (void) aInstance;
 
@@ -308,33 +346,36 @@ ThreadError otPlatRadioTransmit(otInstance *aInstance, RadioPacket *aPacket)
     };
 
     /*Set channel and power based on transmit frame */
-    DEBUG("otPlatRadioTransmit->channel: %i, length %d\n", (int) aPacket->mChannel, (int)aPacket->mLength);
-    for (int i = 0; i < aPacket->mLength; ++i) {
-        DEBUG("%x ", aPacket->mPsdu[i]);
+    if (ENABLE_DEBUG) {
+        DEBUG("otPlatRadioTransmit->channel: %i, length %d\n",
+              (int) aPacket->mChannel, (int)aPacket->mLength);
+        for (size_t i = 0; i < aPacket->mLength; ++i) {
+            DEBUG("%x ", aPacket->mPsdu[i]);
+        }
+        DEBUG("\n");
     }
-    DEBUG("\n");
     _set_channel(aPacket->mChannel);
-    _set_power(aPacket->mPower);
 
     /* send packet though netdev */
     _dev->driver->send(_dev, &iolist);
+    otPlatRadioTxStarted(aInstance, aPacket);
 
-    return kThreadError_None;
+    return OT_ERROR_NONE;
 }
 
 /* OpenThread will call this for getting the radio caps */
 otRadioCaps otPlatRadioGetCaps(otInstance *aInstance)
 {
-    (void) aInstance;
+    (void)aInstance;
     DEBUG("openthread: otPlatRadioGetCaps\n");
     /* all drivers should handle ACK, including call of NETDEV_EVENT_TX_NOACK */
-    return kRadioCapsNone;
+    return OT_RADIO_CAPS_TRANSMIT_RETRIES | OT_RADIO_CAPS_ACK_TIMEOUT;
 }
 
 /* OpenThread will call this for getting the state of promiscuous mode */
 bool otPlatRadioGetPromiscuous(otInstance *aInstance)
 {
-    (void) aInstance;
+    (void)aInstance;
     DEBUG("openthread: otPlatRadioGetPromiscuous\n");
     return _is_promiscuous();
 }
@@ -342,7 +383,7 @@ bool otPlatRadioGetPromiscuous(otInstance *aInstance)
 /* OpenThread will call this for setting the state of promiscuous mode */
 void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable)
 {
-    (void) aInstance;
+    (void)aInstance;
     DEBUG("openthread: otPlatRadioSetPromiscuous\n");
     _set_promiscuous((aEnable) ? NETOPT_ENABLE : NETOPT_DISABLE);
 }
@@ -350,7 +391,7 @@ void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable)
 int8_t otPlatRadioGetRssi(otInstance *aInstance)
 {
     DEBUG("otPlatRadioGetRssi\n");
-    (void) aInstance;
+    (void)aInstance;
     return Rssi;
 }
 
@@ -361,36 +402,36 @@ void otPlatRadioEnableSrcMatch(otInstance *aInstance, bool aEnable)
     (void)aEnable;
 }
 
-ThreadError otPlatRadioAddSrcMatchShortEntry(otInstance *aInstance, const uint16_t aShortAddress)
+otError otPlatRadioAddSrcMatchShortEntry(otInstance *aInstance, const uint16_t aShortAddress)
 {
     DEBUG("otPlatRadioAddSrcMatchShortEntry\n");
     (void)aInstance;
     (void)aShortAddress;
-    return kThreadError_None;
+    return OT_ERROR_NONE;
 }
 
-ThreadError otPlatRadioAddSrcMatchExtEntry(otInstance *aInstance, const uint8_t *aExtAddress)
+otError otPlatRadioAddSrcMatchExtEntry(otInstance *aInstance, const uint8_t *aExtAddress)
 {
     DEBUG("otPlatRadioAddSrcMatchExtEntry\n");
     (void)aInstance;
     (void)aExtAddress;
-    return kThreadError_None;
+    return OT_ERROR_NONE;
 }
 
-ThreadError otPlatRadioClearSrcMatchShortEntry(otInstance *aInstance, const uint16_t aShortAddress)
+otError otPlatRadioClearSrcMatchShortEntry(otInstance *aInstance, const uint16_t aShortAddress)
 {
     DEBUG("otPlatRadioClearSrcMatchShortEntry\n");
     (void)aInstance;
     (void)aShortAddress;
-    return kThreadError_None;
+    return OT_ERROR_NONE;
 }
 
-ThreadError otPlatRadioClearSrcMatchExtEntry(otInstance *aInstance, const uint8_t *aExtAddress)
+otError otPlatRadioClearSrcMatchExtEntry(otInstance *aInstance, const uint8_t *aExtAddress)
 {
     DEBUG("otPlatRadioClearSrcMatchExtEntry\n");
     (void)aInstance;
     (void)aExtAddress;
-    return kThreadError_None;
+    return OT_ERROR_NONE;
 }
 
 void otPlatRadioClearSrcMatchShortEntries(otInstance *aInstance)
@@ -405,13 +446,13 @@ void otPlatRadioClearSrcMatchExtEntries(otInstance *aInstance)
     (void)aInstance;
 }
 
-ThreadError otPlatRadioEnergyScan(otInstance *aInstance, uint8_t aScanChannel, uint16_t aScanDuration)
+otError otPlatRadioEnergyScan(otInstance *aInstance, uint8_t aScanChannel, uint16_t aScanDuration)
 {
     DEBUG("otPlatRadioEnergyScan\n");
     (void)aInstance;
     (void)aScanChannel;
     (void)aScanDuration;
-    return kThreadError_NotImplemented;
+    return OT_ERROR_NOT_IMPLEMENTED;
 }
 
 void otPlatRadioGetIeeeEui64(otInstance *aInstance, uint8_t *aIeee64Eui64)
diff --git a/pkg/openthread/contrib/platform_random.c b/pkg/openthread/contrib/platform_random.c
index c82bb43ebc7451775caeb68d36ed5c6df7ad8fcc..ae8eb27023acdc5031dbcce4d86730254c625953 100644
--- a/pkg/openthread/contrib/platform_random.c
+++ b/pkg/openthread/contrib/platform_random.c
@@ -49,3 +49,13 @@ uint32_t otPlatRandomGet(void)
     DEBUG("otPlatRandomGet: %i\n", (int) rand_val);
     return rand_val;
 }
+
+otError otPlatRandomGetTrue(uint8_t *aOutput, uint16_t aOutputLength)
+{
+    for (uint16_t index = 0; index < aOutputLength; index++) {
+        aOutput[index] = 0;
+        uint32_t rand_val = random_uint32();
+        aOutput[index] = (uint8_t) rand_val;
+    }
+    return OT_ERROR_NONE;
+}
diff --git a/pkg/openthread/contrib/platform_settings.c b/pkg/openthread/contrib/platform_settings.c
index e95cea34eedb6782bd8fc06b261cf2fb70e0c38a..b8ae084037b2c96b7511657f02cea443e0a8b1ab 100644
--- a/pkg/openthread/contrib/platform_settings.c
+++ b/pkg/openthread/contrib/platform_settings.c
@@ -27,26 +27,26 @@ void otPlatSettingsInit(otInstance *aInstance)
     (void)aInstance;
 }
 
-ThreadError otPlatSettingsBeginChange(otInstance *aInstance)
+otError otPlatSettingsBeginChange(otInstance *aInstance)
 {
     (void)aInstance;
-    return kThreadError_None;
+    return OT_ERROR_NONE;
 }
 
-ThreadError otPlatSettingsCommitChange(otInstance *aInstance)
+otError otPlatSettingsCommitChange(otInstance *aInstance)
 {
     DEBUG("openthread: otPlatSettingsCommitChange\n");
     (void)aInstance;
-    return kThreadError_None;
+    return OT_ERROR_NONE;
 }
 
-ThreadError otPlatSettingsAbandonChange(otInstance *aInstance)
+otError otPlatSettingsAbandonChange(otInstance *aInstance)
 {
     (void)aInstance;
-    return kThreadError_None;
+    return OT_ERROR_NONE;
 }
 
-ThreadError otPlatSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength)
+otError otPlatSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength)
 {
     (void)aInstance;
     (void)aKey;
@@ -55,36 +55,33 @@ ThreadError otPlatSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex,
 
     DEBUG("openthread: otPlatSettingsGet\n");
     *aValueLength = 0;
-    return kThreadError_NotImplemented;
+    return OT_ERROR_NOT_IMPLEMENTED;
 }
 
-ThreadError otPlatSettingsSet(otInstance *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
+otError otPlatSettingsSet(otInstance *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
 {
     (void)aInstance;
     (void)aKey;
     (void)aValue;
     (void)aValueLength;
-
-    return kThreadError_None;
+    return OT_ERROR_NONE;
 }
 
-ThreadError otPlatSettingsAdd(otInstance *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
+otError otPlatSettingsAdd(otInstance *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
 {
     (void)aInstance;
     (void)aKey;
     (void)aValue;
     (void)aValueLength;
-
-    return kThreadError_None;
+    return OT_ERROR_NONE;
 }
 
-ThreadError otPlatSettingsDelete(otInstance *aInstance, uint16_t aKey, int aIndex)
+otError otPlatSettingsDelete(otInstance *aInstance, uint16_t aKey, int aIndex)
 {
     (void)aInstance;
     (void)aKey;
     (void)aIndex;
-
-    return kThreadError_None;
+    return OT_ERROR_NONE;
 }
 
 void otPlatSettingsWipe(otInstance *aInstance)
diff --git a/pkg/openthread/contrib/platform_uart.c b/pkg/openthread/contrib/platform_uart.c
old mode 100644
new mode 100755
index d3aff67af3fc18216f255a0397bf004a3e230faf..122d7f838c2ce0437fc40681ae303795291884bf
--- a/pkg/openthread/contrib/platform_uart.c
+++ b/pkg/openthread/contrib/platform_uart.c
@@ -13,34 +13,82 @@
  * @brief       Implementation of OpenThread UART platform abstraction
  *
  * @author      Jose Ignacio Alamos <jialamos@uc.cl>
+ * @author      Baptiste Clenet <bapclenet@gmail.com>
  * @}
  */
 
 #include <stdint.h>
 #include <stdio.h>
+#include <string.h>
 
+#include "stdio_uart.h"
 #include "periph/uart.h"
+#include "openthread/types.h"
 #include "openthread/platform/uart.h"
+#include "ot.h"
+
+#define ENABLE_DEBUG (0)
+#include "debug.h"
+
+#define OPENTHREAD_SPINEL_FRAME_MARKER      (0x7e)
+
+static serial_msg_t gSerialMessage[OPENTHREAD_NUMBER_OF_SERIAL_BUFFER];
+static uint16_t frameLength = 0;
+
+static void uart_handler(void* arg, char c) {
+    (void)arg;
+
+    if (frameLength == 0) {
+        memset(&gSerialMessage[0], 0, sizeof(serial_msg_t));
+    }
+    switch (c) {
+        case '\r':
+        case '\n':
+            if (frameLength > 0) {
+                gSerialMessage[0].buf[frameLength] = c;
+                frameLength++;
+                gSerialMessage[0].length = frameLength;
+                msg_t msg;
+                msg.type = OPENTHREAD_SERIAL_MSG_TYPE_EVENT;
+                msg.content.ptr = &gSerialMessage[0];
+                msg_send_int(&msg, openthread_get_pid());
+                frameLength = 0;
+            }
+            break;
+        default:
+            if (frameLength < OPENTHREAD_SERIAL_BUFFER_SIZE) {
+                gSerialMessage[0].buf[frameLength] = c;
+                frameLength++;
+            }
+            break;
+    }
+}
 
 /* OpenThread will call this for enabling UART (required for OpenThread's CLI)*/
-ThreadError otPlatUartEnable(void)
+otError otPlatUartEnable(void)
 {
-    return kThreadError_None;
+    for (uint8_t i = 0; i < OPENTHREAD_NUMBER_OF_SERIAL_BUFFER; i++) {
+        gSerialMessage[i].serial_buffer_status = OPENTHREAD_SERIAL_BUFFER_STATUS_FREE;
+    }
+
+    uart_init(STDIO_UART_DEV, STDIO_UART_BAUDRATE, (uart_rx_cb_t) uart_handler, NULL);
+    return OT_ERROR_NONE;
 }
 
 /* OpenThread will call this for disabling UART */
-ThreadError otPlatUartDisable(void)
+otError otPlatUartDisable(void)
 {
-    return kThreadError_None;
+    uart_poweroff(STDIO_UART_DEV);
+    return OT_ERROR_NONE;
 }
 
 /* OpenThread will call this for sending data through UART */
-ThreadError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength)
+otError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength)
 {
-    uart_write(UART_DEV(0), aBuf, aBufLength);
+    uart_write(STDIO_UART_DEV, aBuf, aBufLength);
 
     /* Tell OpenThread the sending of UART is done */
     otPlatUartSendDone();
 
-    return kThreadError_None;
+    return OT_ERROR_NONE;
 }
diff --git a/pkg/openthread/include/ot.h b/pkg/openthread/include/ot.h
old mode 100644
new mode 100755
index 6741ceadbc95b8274faf466b4607089a63a4d3c3..9a9c66485fd4d2df19187aa4572f58f4adb95b52
--- a/pkg/openthread/include/ot.h
+++ b/pkg/openthread/include/ot.h
@@ -17,7 +17,8 @@
  *
  * @file
  *
- * @author  José Ignacio Alamos <jialamos@uc.cl>
+ * @author      Jose Ignacio Alamos <jialamos@uc.cl>
+ * @author      Baptiste Clenet <bapclenet@gmail.com>
  */
 
 #ifndef OT_H
@@ -34,18 +35,55 @@ extern "C" {
 #include "thread.h"
 #include "openthread/types.h"
 
-#define OPENTHREAD_XTIMER_MSG_TYPE_EVENT (0x2235)        /**< xtimer message receiver event*/
-#define OPENTHREAD_NETDEV_MSG_TYPE_EVENT (0x2236)        /**< message received from driver */
-#define OPENTHREAD_SERIAL_MSG_TYPE_EVENT (0x2237)        /**< event indicating a serial (UART) message was sent to OpenThread */
-#define OPENTHREAD_MSG_TYPE_RECV         (0x2238)        /**< event for frame reception */
-#define OPENTHREAD_JOB_MSG_TYPE_EVENT    (0x2240)        /**< event indicating an OT_JOB message */
+/**
+ * @name    Openthread message types
+ * @{
+ */
+/** @brief   xtimer message receiver event */
+#define OPENTHREAD_XTIMER_MSG_TYPE_EVENT                    (0x2235)
+/** @brief   message received from driver */
+#define OPENTHREAD_NETDEV_MSG_TYPE_EVENT                    (0x2236)
+/** @brief   event indicating a serial (UART) message was sent to OpenThread */
+#define OPENTHREAD_SERIAL_MSG_TYPE_EVENT                    (0x2237)
+/** @brief   event for frame reception */
+#define OPENTHREAD_MSG_TYPE_RECV                            (0x2238)
+/** @brief   event indicating an OT_JOB message */
+#define OPENTHREAD_JOB_MSG_TYPE_EVENT                       (0x2240)
+/** @} */
+
+/**
+ * @name    Openthread constants
+ * @{
+ */
+/** @brief   number of serial reception buffer */
+#define OPENTHREAD_NUMBER_OF_SERIAL_BUFFER                  (1U)
+/** @brief   sizeof in bytes the two first members of she serial structure */
+#define OPENTHREAD_SIZEOF_LENGTH_AND_FREEBUFF               (4U)
+/** @brief   sizeof the serial buffer */
+#define OPENTHREAD_SERIAL_BUFFER_SIZE                       OPENTHREAD_SIZEOF_LENGTH_AND_FREEBUFF + 100
+/** @brief   sizeof the spinel payload data */
+#define OPENTHREAD_SERIAL_BUFFER__PAYLOAD_SIZE              OPENTHREAD_SERIAL_BUFFER_SIZE - OPENTHREAD_SIZEOF_LENGTH_AND_FREEBUFF
+/** @brief   error when no more buffer available */
+#define OPENTHREAD_ERROR_NO_EMPTY_SERIAL_BUFFER             -1
+/** @brief   serial buffer ready to use */
+#define OPENTHREAD_SERIAL_BUFFER_STATUS_FREE                (0x0001)
+/** @brief   serial buffer ready for processsing */
+#define OPENTHREAD_SERIAL_BUFFER_STATUS_READY_TO_PROCESS    (0x0002)
+/** @brief   serial buffer payload full */
+#define OPENTHREAD_SERIAL_BUFFER_STATUS_FULL                (0x0004)
+/** @brief   Max length for IEEE802154 frame */
+#define IEEE802154_MAX_LENGTH                               (127U)
+/** @brief   Max length for a netdev buffer  */
+#define OPENTHREAD_NETDEV_BUFLEN                            (IEEE802154_MAX_LENGTH)
+/** @} */
 
 /**
  * @brief   Struct containing a serial message
  */
 typedef struct {
-    void *buf;  /**< buffer containing the message */
-    size_t len; /**< length of the message */
+    uint16_t length;                                        /**< length of the message */
+    uint16_t serial_buffer_status;                          /**< status of the buffer */
+    uint8_t buf[OPENTHREAD_SERIAL_BUFFER__PAYLOAD_SIZE];    /**< buffer containing the message */
 } serial_msg_t;
 
 /**
@@ -115,11 +153,6 @@ kernel_pid_t openthread_get_pid(void);
  */
 void ot_random_init(void);
 
-/**
- * @brief   Run OpenThread UART simulator (stdio)
- */
-void openthread_uart_run(void);
-
 /**
  * @brief   Execute OpenThread command. Call this function only in OpenThread thread
  *
diff --git a/pkg/openthread/include/platform_config.h b/pkg/openthread/include/platform_config.h
new file mode 100644
index 0000000000000000000000000000000000000000..46527a4e72fa6192df76b0f6c9cc48d003f2621c
--- /dev/null
+++ b/pkg/openthread/include/platform_config.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) Baptiste Clenet
+ *
+ * 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
+ * @file
+ * @brief       Implementation of OpenThread platform config
+ *
+ * @author      Baptiste Clenet <bapclenet@gmail.com>
+ * @}
+ */
+
+#ifndef PLATFORM_CONFIG_H
+#define PLATFORM_CONFIG_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @def OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS
+ *
+ * The number of message buffers in buffer pool
+ */
+#if OPENTHREAD_MTD
+#define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS       (20U)
+#else
+#define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS       (10U)
+#endif
+
+
+/**
+ * @def OPENTHREAD_CONFIG_LOG_LEVEL
+ *
+ * Set OpenThread log level
+ *
+ * @see https://openthread.io/releases/thread-reference-20170716/group/plat-logging
+ */
+#define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_NONE
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PLATFORM_CONFIG_H */
diff --git a/pkg/openthread/patches/0001-fix-macro-conflict.patch b/pkg/openthread/patches/0001-fix-macro-conflict.patch
new file mode 100644
index 0000000000000000000000000000000000000000..cbddd8bb7336006cd2a1234c7a69f76f2aabbf41
Binary files /dev/null and b/pkg/openthread/patches/0001-fix-macro-conflict.patch differ
diff --git a/tests/openthread/Makefile b/tests/openthread/Makefile
deleted file mode 100644
index 258d30bc4891699098a4e2a5dc760e8f815f5e76..0000000000000000000000000000000000000000
--- a/tests/openthread/Makefile
+++ /dev/null
@@ -1,43 +0,0 @@
-APPLICATION = openthread
-
-# If no BOARD is found in the environment, use this default:
-BOARD ?= samr21-xpro
-
-BOARD_WHITELIST := samr21-xpro iotlab-m3 fox iotlab-a8-m3
-
-# This has to be the absolute path to the RIOT base directory:
-RIOTBASE ?= $(CURDIR)/../..
-
-# Change this to 0 show compiler invocation lines by default:
-QUIET ?= 1
-
-USEPKG += openthread
-USEMODULE += openthread_contrib
-USEMODULE += libmbedcrypto
-USEMODULE += libopenthread
-USEMODULE += libopenthread-cli
-USEMODULE += xtimer
-
-ifneq (,$(filter samr21-xpro,$(BOARD)))
-  DRIVER := at86rf233
-endif
-ifneq (,$(filter iotlab-m3 fox iotlab-a8-m3,$(BOARD)))
-  DRIVER := at86rf231
-endif
-
-USEMODULE += $(DRIVER)
-
-USEMODULE += random
-USEMODULE += shell
-USEMODULE += shell_commands
-USEMODULE += ps
-USEMODULE += ipv6_addr
-
-#required for C++ compiling
-CXXEXFLAGS += -fno-rtti
-USEMODULE += cpp11-compat
-
-#Define PANID and CHANNEL used by default
-#CFLAGS += -DOPENTHREAD_PANID=0xbeef -DOPENTHREAD_CHANNEL=11
-
-include $(RIOTBASE)/Makefile.include
diff --git a/tests/openthread/README.md b/tests/openthread/README.md
deleted file mode 100644
index 25a79ef83c80c53490365159b14c217c6b656eec..0000000000000000000000000000000000000000
--- a/tests/openthread/README.md
+++ /dev/null
@@ -1,36 +0,0 @@
-## OpenThread on RIOT
-
-This test demonstrates the [OpenThread](https://github.com/openthread/openthread) stack running on RIOT. When flashed,
-it will initialize the OpenThread Command Line Interface for interacting with the stack.
-
-## Quick usage
-
-To test OpenThread on RIOT, you can do the following:
-
-1. Flash nodes with `make BOARD=<target> clean all flash`
-2. Write `panid 0x1234`, `ifconfig up` then `thread start` on one node.
-3. Check the state of the node with `state`. In the beggining should be `detached`, but after some seconds it should
-   become `leader`
-4. Write `panid 0x1234`, `ifconfig up` then `thread start` on another node.
-The second node should become `child` or `router` if there's a leader.
-5. Get the mesh IP address of a node with `ipaddr`.
-
-```
-    ipaddr
-   fdde:ad00:beef::ff:fe00:8000
-   fe80::ff:fe00:8000
-   fdde:ad00:beef:0:946a:c722:a5d9:8481
-   fe80::3984:f4eb:d182:5dae
-```
-
-   Addresses starting with `fd` are mesh-local, and addresses starting with `fe80` are link-local.
-   Mesh-local address types that contain `ff:fe00` are classified as Router Locator (RLOC). Mesh-local address types
-   that don't contain `ff:fe00` are Endpoint Identifies (EID).
-6. Ping from another node to a mesh-local address with `ping fdde:ad00:beef:0:946a:c722:a5d9:8481`.
-7. You can try IEEE802.15.4 scan with `scan` command
-8. You can also check other commands with `help`
-9. Enjoy!
-
-## Note
-
-See the [OpenThread CLI Reference](https://github.com/openthread/openthread/blob/master/src/cli/README.md) for more information about OpenThread CLI commands