Exemplo n.º 1
0
int main(int argc, char** argv) {
    nabto_main_setup* nms = unabto_init_context();

    stream_echo_init();
    
    if (!check_args(argc, argv, nms)) {
        return 1;
    }

    if (!unabto_init()) {
        return 1;
    }
    
    while(true) {
        unabto_tick();
#ifdef WIN32
        Sleep(1);
#endif
#if (_POSIX_C_SOURCE >= 199309L)
        struct timespec sleepTime;
        sleepTime.tv_sec = 0;
        sleepTime.tv_nsec = 10*1000000;
        nanosleep(&sleepTime, NULL);
#endif
    }
    
    unabto_close();
}
Exemplo n.º 2
0
Arquivo: main.c Projeto: nabto/unabto
int main(int argc, char** argv)
{
    nabto_main_setup* nms = unabto_init_context();

    platform_checks();
        
#if NABTO_ENABLE_EPOLL
    unabto_epoll_init();
#endif

    if (!tunnel_parse_args(argc, argv, nms)) {
        NABTO_LOG_FATAL(("failed to parse commandline args"));
    }

#if HANDLE_SIGNALS
#ifdef WIN32
    signal_event = CreateEvent(NULL, FALSE, FALSE, NULL);
#endif
    signal(SIGTERM, handle_signal);
    signal(SIGINT, handle_signal);
#endif

#if NABTO_ENABLE_EPOLL
    if (useSelectBased) {
        tunnel_loop_select();
    } else {
        tunnel_loop_epoll();
    }
#else
    tunnel_loop_select();
#endif
    return 0;
}
Exemplo n.º 3
0
/**
 * Entry point.
 * @param argc  number of parameters
 * @param argv  the parameters
 * - 1 ip-address
 * - 2 serverid | - 
 * - 3 log
 * @return      the result
 */
int main(int argc, char* argv[])
{
    nabto_main_setup* nms;
    nabto_endpoint localEp;

    // flush stdout
    setvbuf(stdout, NULL, _IONBF, 0);

    nms = unabto_init_context();

    /**
     * Overwrite default values with command line args
     */
    if (!check_args(argc, argv, nms)) {
        return 1;
    }

    if (!unabto_init()) {
        NABTO_LOG_FATAL(("Failed at nabto_main_init"));
    }

	localEp.addr=nms->ipAddress;
	localEp.port=nms->localPort;
	
	if (nms->ipAddress != INADDR_ANY) NABTO_LOG_INFO(("Own IP address: " PRIep, MAKE_EP_PRINTABLE(localEp)));
    else NABTO_LOG_INFO(("Own IP address, local IP is set to INADDR_ANY: " PRIep, MAKE_EP_PRINTABLE(localEp)));

    while (true) {
        /*
         * Here the main application should do it's work
         * and then whenever time is left for Nabto (but at least regularly)
         * the nabto_main_tick() should be called.
         *
         * nabto_main_tick()
         * - polls the socket for incoming messages
         * - administers timers to do its own timer based work
         */
        unabto_tick();
#if NABTO_ENABLE_STREAM
        nabto_stream_test_tick();
#endif
#if (_POSIX_C_SOURCE >= 199309L)
        struct timespec sleepTime;
        sleepTime.tv_sec = 0;
        sleepTime.tv_nsec = 10*1000000;
        nanosleep(&sleepTime, NULL);
#endif
    }

    unabto_close();
	return 0;
}
Exemplo n.º 4
0
int main(int argc, char** argv)
{
#if USE_TEST_WEBSERVER
#ifdef WIN32
    HANDLE testWebserverThread;
#else
    pthread_t testWebserverThread;
#endif
#endif

    nabto_main_setup* nms = unabto_init_context();

    platform_checks();
    
#if NABTO_ENABLE_EPOLL
    unabto_epoll_init();
#endif

    if (!tunnel_parse_args(argc, argv, nms)) {
        NABTO_LOG_FATAL(("failed to parse commandline args"));
    }

#if USE_TEST_WEBSERVER
    if (testWebserver) {
#ifdef WIN32
        testWebserverThread = CreateThread(NULL, 0, test_webserver, (void*)testWebserverPortStr, NULL, NULL);
#else
        pthread_create(&testWebserverThread, NULL, test_webserver, (void*)testWebserverPortStr);
#endif
    }
#endif

#if HANDLE_SIGNALS
#ifdef WIN32
    signal_event = CreateEvent(NULL, FALSE, FALSE, NULL);
#endif
    signal(SIGTERM, handle_signal);
    signal(SIGINT, handle_signal);
#endif

#if NABTO_ENABLE_EPOLL
    if (useSelectBased) {
        tunnel_loop_select();
    } else {
        tunnel_loop_epoll();
    }
#else
    tunnel_loop_select();
#endif
    return 0;
}
/**
 * This is a simple example of a custom tunnel implementation.
 */
int main() {
    nabto_main_setup* nms = unabto_init_context();

    // Setup device id.
    nms->id = "deviceid";
    
    // Setup encryption.
    nms->cryptoSuite = CRYPT_W_AES_CBC_HMAC_SHA256;
    nms->secureAttach = true;
    nms->secureData = true;
    // Copy the preshared key into unabto
    // memcpy(nms->presharedKey, key,16);
    
    // Loop forever.
    tunnel_loop();
}
Exemplo n.º 6
0
Arquivo: main.c Projeto: nabto/unabto
/**
 *  main using gopt to check command line arguments
 *  -h for help
 */
int main(int argc, char* argv[])
{
    // Set nabto to default values

    nabto_main_setup* nms = unabto_init_context();

    // Overwrite default values with command line args
    if (!check_args(argc, argv, nms)) {
        return 1;
    }
    NABTO_LOG_INFO(("Identity: '%s'", nms->id));
    NABTO_LOG_INFO(("Program Release %i.%i", RELEASE_MAJOR, RELEASE_MINOR));
    NABTO_LOG_INFO(("Buffer size: %i", nms->bufsize));

    // Initialize nabto
    if (!unabto_init()) {
        NABTO_LOG_FATAL(("Failed at nabto_main_init"));
    }

    nabto_stamp_t attachExpireStamp;
    // 20 seconds
    nabtoSetFutureStamp(&attachExpireStamp, 1000*20);
        
    // The main loop gives nabto a tick from time to time.
    // Everything else is taken care of behind the scenes.
    while (true) {
        unabto_tick();
        nabto_yield(10);
        if (nabtoIsStampPassed(&attachExpireStamp)) {
            NABTO_LOG_ERROR(("Attach took too long."));
            exit(4);
        }
        if (unabto_is_connected_to_gsp()) {
            NABTO_LOG_INFO(("Successfully attached to the gsp, now exiting."));
            exit(0);
        }
    }

    NABTO_LOG_ERROR(("we should not end here"));
    exit(5);
    
    unabto_close();
    return 0;
}
Exemplo n.º 7
0
int main(int argc, char** argv) {
    nabto_main_setup* nms = unabto_init_context();

    stream_echo_init();
    
    if (!check_args(argc, argv, nms)) {
        return 1;
    }

    if (!unabto_init()) {
        return 1;
    }
    
    unabto_time_auto_update(false);
    while(true) {
        unabto_time_update_stamp();
        wait_event();
    }
    
    unabto_close();
}
Exemplo n.º 8
0
/**
 *  main using gopt to check command line arguments
 *  -h for help
 */
int main(int argc, char* argv[])
{

    // Set nabto to default values
    nabto_main_setup* nms = unabto_init_context();


    // Initialise application
    if (!application_init()){
        NABTO_LOG_FATAL(("Unable to initialise serial connection"));
    }

    // Optionally set alternative url to html device driver
    //nmc.nabtoMainSetup.url = "https://dl.dropbox.com/u/15998645/html_dd_demo.zip";

    // Overwrite default values with command line args
    if (!check_args(argc, argv, nms)) {
        return 1;
    }
    NABTO_LOG_INFO(("Identity: '%s'", nms->id));
    NABTO_LOG_INFO(("Program Release %" PRIu32 ".%" PRIu32, RELEASE_MAJOR, RELEASE_MINOR));
    NABTO_LOG_INFO(("Buffer size: %d" , nms->bufsize));

    // Initialize nabto
    if (!unabto_init()) {
        NABTO_LOG_FATAL(("Failed at nabto_main_init"));
    }

    // The main loop gives nabto a tick from time to time.
    // Everything else is taken care of behind the scenes.
    while (true) {
        unabto_tick();
        nabto_yield(10);
    }

    unabto_close();

    return 0;
}
void* main_routine(void* args) {

    nabto_main_setup* nms;
    const char* id = (const char*)args;

    nms = unabto_init_context();
    nms->id = id;
    nms->localPort = 0;
    nms->secureAttach = true;
    nms->secureData = true;
    nms->localPort = 0;
    nms->cryptoSuite = CRYPT_W_AES_CBC_HMAC_SHA256;
    nms->controllerArg.addr = bsip;
    if (random_local_address) {
        nms->ipAddress = 0x7f000001 + (rand() % 1000);
    }

    tunnel_loop();

    free(args);
    return 0;
    
}
unabto_api_status_t unabto_api_platform_init() {
    setup = unabto_init_context();
    return UNABTO_API_OK;
}
Exemplo n.º 11
0
void main(void)
{
  static nabto_main_setup* nms;
  static char versionString[NABTO_DEVICE_VERSION_MAX_SIZE];
  static char idString[NABTO_DEVICE_NAME_MAX_SIZE];
#if NABTO_ENABLE_UCRYPTO
  static const far rom uint8_t dummySharedSecret[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  static const far rom uint8_t* sharedSecret;
#endif

  // <editor-fold desc="Load information from bootloader and application data areas.">

  // Clear the global TCP/IP data structure and load it with the boards unique preprogrammed MAC address.
  memset((void*) &AppConfig, 0x00, sizeof (AppConfig));
  memcpypgm2ram(&AppConfig.MyMACAddr, (const __ROM uint8_t*) bootloaderData.version1.mac, 6);

  if(bootloaderData.base.bootloaderDataVersion == 1)
  {
    strcpypgm2ram(idString, (const far rom char*) bootloaderData.version1.serialNumber);
    strcatpgm2ram(idString, ".nabduino.net");

#if NABTO_ENABLE_UCRYPTO
    //        sharedSecret = applicationData.sharedSecret; // the old pre-bootloader-version-2 way of storing the shared secret - obsolete!
#endif
  }
  else if(bootloaderData.base.bootloaderDataVersion == 2)
  {
    hardwareVersion = (uint8_t) bootloaderData.version2.hardwareVersionMajor;
    hardwareVersion <<= 8;
    hardwareVersion |= (uint8_t) bootloaderData.version2.hardwareVersionMinor;

    if(hardwareVersion == 0x0004)
    {
      hardwareVersionIndex = 0; // first version of the board that was released.
    }
    else if(hardwareVersion == 0x0102)
    {
      hardwareVersionIndex = 1; // second version of the board that was released (yes we jumped from 0.4 beta to 1.2).
    }
    else if(hardwareVersion == 0x0103)
    {
      hardwareVersionIndex = 2; // third version of the board
    }

    strcpypgm2ram(idString, (const far rom char*) bootloaderData.version2.deviceId);
    strcatpgm2ram(idString, (const far rom char*) bootloaderData.version2.productDomain);

#if NABTO_ENABLE_UCRYPTO
    sharedSecret = bootloaderData.version2.sharedSecret;
#endif
  }
  else
  { // unsupported version so it's probably safe to assume that bootloader data has been wiped - please fill in the appropriate values for your Nabduino board
    hardwareVersionIndex = 0; // hardware version 0.4 = 0, v1.2 = 1, v1.3 = 2

    AppConfig.MyMACAddr.v[0] = 0xBC; // Nabto owned MAC OUI is BC:A4:E1
    AppConfig.MyMACAddr.v[1] = 0xA4;
    AppConfig.MyMACAddr.v[2] = 0xE1;
    AppConfig.MyMACAddr.v[3] = 0x00;
    AppConfig.MyMACAddr.v[4] = 0x00;
    AppConfig.MyMACAddr.v[5] = 0x00; // If using more than one Nabduino on the same network make this byte unique for each board

    strcpypgm2ram(idString, "XXX"); // replace XXX with the id of the Nabduino board
    strcatpgm2ram(idString, ".nabduino.net");

#if NABTO_ENABLE_UCRYPTO
    sharedSecret = dummySharedSecret;
#endif
  }

  // </editor-fold>

  // Initialize IOs etc. taking into account the hardware version.
  hal_initialize();

  // Initialize the platform (timing, TCP/IP stack, DHCP and some PIC18 specific stuff)
  platform_initialize();

  network_initialize();

  nms = unabto_init_context();

  nms->id = (const char*) idString;

  // build version string: <application SVN version>/<bootloader SVN version>/<hardware major version>.<hardware minor version>
  itoa(RELEASE_MINOR, versionString);
  strcatpgm2ram(versionString + strlen(versionString), "/");
  itoa(bootloaderData.base.buildVersion, versionString + strlen(versionString));
  strcatpgm2ram(versionString + strlen(versionString), "/");
  itoa(hardwareVersion >> 8, versionString + strlen(versionString));
  strcatpgm2ram(versionString + strlen(versionString), ".");
  itoa(hardwareVersion & 0xff, versionString + strlen(versionString));
  nms->version = (const char*) versionString;

#if NABTO_ENABLE_UCRYPTO
  memcpypgm2ram(nms->presharedKey, (const __ROM void*) sharedSecret, 16);
  nms->secureAttach = true;
  nms->secureData = true;
  nms->cryptoSuite = CRYPT_W_AES_CBC_HMAC_SHA256;
#endif

  setup((char**) &nms->url);

  unabto_init();

  while(1)
  {
    hal_tick();
    platform_tick();
    network_tick();
    unabto_tick();
    loop();
  }
}