original source code.copy by HorseMa from contiki master branch