int LoWPANNDInterface::connect()
{
    // initialize mesh networking resources, memory, timers, etc...
    mesh_system_init();
    nanostack_lock();

    mesh_api = MeshInterfaceFactory::createInterface(MESH_TYPE_6LOWPAN_ND);
    if (!mesh_api) {
        nanostack_unlock();
        return NSAPI_ERROR_NO_MEMORY;
    }
    if (register_rf() < 0) {
        nanostack_unlock();
        return NSAPI_ERROR_DEVICE_ERROR;
    }

    // After the RF is up, we can seed the random from it.
    randLIB_seed_random();

    mesh_error_t status = ((Mesh6LoWPAN_ND *)mesh_api)->init(rf_device_id, AbstractMesh::mesh_network_handler_t(static_cast<MeshInterfaceNanostack *>(this), &LoWPANNDInterface::mesh_network_handler));
    if (status != MESH_ERROR_NONE) {
        nanostack_unlock();
        return map_mesh_error(status);
    }
    int ret = this->actual_connect();

    nanostack_unlock();

    return ret;
}
示例#2
0
bool test_randLIB_get_32bit()
{
    randLIB_seed_random();
    uint32_t test = randLIB_get_32bit();
    if( test == 0 ) {
        test = randLIB_get_32bit();
        if( test == 0 ) {
            return false;
        }
    }
    return true;
}
/**
 * Get a random array of bytes.
 * Called back by mbedtls when it wants to fill a buffer with random data
 * Must return 0 on success.
 */
static int get_random(void *ctx, unsigned char *buf, size_t len)
{
    static int initialised = 0;
    uint32_t i;

    (void)ctx; /* No context */

    if (!initialised) {
        randLIB_seed_random();
        initialised = 1;
    }

    for (i = 0; i < len; i++) {
        buf[i] = (uint8_t)randLIB_get_8bit();
    }
    return 0; /* Success */
}
void app_start(int, char **)
{
	char if_desciption[] = "6LoWPAN_NODE";

	pc.baud(115200);  //Setting the Baud-Rate for trace output
    ns_dyn_mem_init(app_stack_heap, APP_DEFINED_HEAP_SIZE, app_heap_error_handler,0);
    randLIB_seed_random();
    platform_timer_enable();
    eventOS_scheduler_init();
    trace_init();
	set_trace_print_function( trace_printer );
    set_trace_config(TRACE_ACTIVE_LEVEL_DEBUG|TRACE_CARRIAGE_RETURN);
	tr_debug("M \r\n");
    net_init_core();
    rf_phy_device_register_id = rf_device_register();
    net_rf_id = arm_nwk_interface_init(NET_INTERFACE_RF_6LOWPAN, rf_phy_device_register_id, if_desciption);
    eventOS_event_handler_create(&tasklet_main, ARM_LIB_TASKLET_INIT_EVENT);
}
int entropy_poll( void *ctx, unsigned char *output, size_t len,
                           size_t *olen )
{
    (void)ctx;
    //TODO: change to more secure random
    randLIB_seed_random();
    char *c = (char*)ns_dyn_mem_temporary_alloc(len);
    if( !c ){
        return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
    }
    memset(c, 0, len);
    for(uint16_t i=0; i < len; i++){
        *(c + i) = (char)randLIB_get_8bit();
    }
    memmove(output, c, len);
    *olen = len;

    ns_dyn_mem_free(c);
    return( 0 );
}
示例#6
0
void mesh_system_init(void)
{
    if (mesh_initialized == false) {
#ifndef YOTTA_CFG
        ns_hal_init(app_stack_heap, MBED_MESH_API_HEAP_SIZE,
                    mesh_system_heap_error_handler, NULL);
        eventOS_scheduler_mutex_wait();
        net_init_core();
        eventOS_scheduler_mutex_release();
#else
        ns_dyn_mem_init(app_stack_heap, MBED_MESH_API_HEAP_SIZE,
                        mesh_system_heap_error_handler, NULL);
        randLIB_seed_random();
        platform_timer_enable();
        eventOS_scheduler_init();
        trace_init(); // trace system needs to be initialized right after eventOS_scheduler_init
        net_init_core();
        /* initialize 6LoWPAN socket adaptation layer */
        ns_sal_init_stack();
#endif
        mesh_initialized = true;
    }
}
示例#7
0
bool test_randLIB_seed_random()
{
    randLIB_seed_random();
    return true;
}