int main(const int argc, char* argv[]){ unsigned short portNum; int dropPercent; if(argc == 1){ portNum = DEFAULT_PORT; dropPercent = 10; mountPath = "./"; }else if(argc == 7){ portNum = atoi(argv[2]); dropPercent = atoi(argv[6]); mountPath = argv[4]; if(mountPath[mountPath.length()-1] != '/'){ mountPath +='/'; } int ret = mkdir(mountPath.c_str(),0777); if(ret == -1){ printf("machine already in use\n"); return -1; } } LOG("Starting server...\n"); netInit(portNum,dropPercent); LOG("Server started, waiting for roll call\n"); listen(); }
int main(int argc, char *argv[]) { FD *f; int fd; fd_set localFDSet; int ret; if (!netInit()) { return 1; } if (!threadInit()) { return 1; } fd = netListen(NULL, NULL, &mainPort); if (fd < 0) { fprintf(stderr, "netListen failed\n"); return 1; } f = addFD(fd, acceptNewLogger); if (!f) { fprintf(stderr, "addFD failed\n"); return 1; } while (1) { localFDSet = fdSet; ret = select(maxFD + 1, &localFDSet, NULL, NULL, NULL); if (ret == -1) { perror("select"); } for (fd = 0; fd <= maxFD; fd++) { if (FD_ISSET(fd, &localFDSet)) { if ((*table[fd]->handler)(fd)) { for (fd = 0; fd <= maxFD; fd++) { removeFD(fd); } return 0; } } } } return 1; }
int wrc_ptp_init() { Integer16 ret; netStartup(); ptpPortDS = ptpdStartup(0, NULL, &ret, &rtOpts, &ptpClockDS); initDataClock(&rtOpts, &ptpClockDS); //initialize sockets if (!netInit(&ptpPortDS->netPath, &rtOpts, ptpPortDS)) { PTPD_TRACE(TRACE_WRPC, NULL, "failed to initialize network\n"); return -1; } ptpPortDS->linkUP = FALSE; ptp_enabled = 0; return 0; }
Boolean doInit(RunTimeOpts *rtOpts, PtpClock *ptpClock) { DBG("manufacturerIdentity: %s\n", MANUFACTURER_ID); /* initialize networking */ netShutdown(&ptpClock->netPath); if(!netInit(&ptpClock->netPath, rtOpts, ptpClock)) { ERROR("failed to initialize network\n"); toState(PTP_FAULTY, rtOpts, ptpClock); return FALSE; } /* initialize other stuff */ initData(rtOpts, ptpClock); initTimer(); initClock(rtOpts, ptpClock); m1(ptpClock); msgPackHeader(ptpClock->msgObuf, ptpClock); DBG("sync message interval: %d\n", PTP_SYNC_INTERVAL_TIMEOUT(ptpClock->sync_interval)); DBG("clock identifier: %s\n", ptpClock->clock_identifier); DBG("256*log2(clock variance): %d\n", ptpClock->clock_variance); DBG("clock stratum: %d\n", ptpClock->clock_stratum); DBG("clock preferred?: %s\n", ptpClock->preferred?"yes":"no"); DBG("bound interface name: %s\n", rtOpts->ifaceName); DBG("communication technology: %d\n", ptpClock->port_communication_technology); DBG("uuid: %02x:%02x:%02x:%02x:%02x:%02x\n", ptpClock->port_uuid_field[0], ptpClock->port_uuid_field[1], ptpClock->port_uuid_field[2], ptpClock->port_uuid_field[3], ptpClock->port_uuid_field[4], ptpClock->port_uuid_field[5]); DBG("PTP subdomain name: %s\n", ptpClock->subdomain_name); DBG("subdomain address: %x.%x.%x.%x\n", ptpClock->subdomain_address[0], ptpClock->subdomain_address[1], ptpClock->subdomain_address[2], ptpClock->subdomain_address[3]); DBG("event port address: %x %x\n", ptpClock->event_port_address[0], ptpClock->event_port_address[1]); DBG("general port address: %x %x\n", ptpClock->general_port_address[0], ptpClock->general_port_address[1]); toState(PTP_LISTENING, rtOpts, ptpClock); return TRUE; }
int main(int argc, char *argv[]) { char url[] = "http://www.ps2dev.org/"; setupGu(); netInit(); htmlViewerInit(url); while(updateHtmlViewer()) { sceDisplayWaitVblankStart(); sceGuSwapBuffers(); } netTerm(); sceKernelFreeVpl(vpl, params.memaddr); sceKernelDeleteVpl(vpl); sceKernelExitGame(); return 0; }
bool qbConnect(const char *hostname, unsigned short port) { if(!netInit(hostname,port)) { return false; } #if WIN32 server_thread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)serverThread,NULL,0,&server_thread_id); if(server_thread == NULL) { #else int ret = pthread_create(&server_thread, NULL, serverThread, NULL); if( ret != 0 ) { #endif qbLog("Could not create server thread"); netShutdown(); return false; } /*TODO use pthread_attribs to set higher priority*/ #ifdef WIN32 SetThreadPriority(server_thread,THREAD_PRIORITY_TIME_CRITICAL); #endif if(!netConnect()) { qbLog("Could not connect to server"); netShutdown(); return false; } qbSynchConsole("new"); while(!online) { qbLog("Precaching..."); Sleep(1000); } return true; } void qbBegin(void) { char s[64]; sprintf(s,"begin %d\n",login_key); qbSynchConsole(s); }
void MazeInit(int argc, char **argv) { getMaze(); setRandom(); InitDisplay(argc, argv); NewPosition(M); printf("%d X LOC \n",M->xloc().value()); /* * We don't do ShowPosition() or ShowView() here, but let the update * routine in the window handler do it for the first time when * the window is exposed. */ netInit(); StartDisplay(); RatCursor(); }
static Boolean doInit(PtpClock *ptpClock) { DBG("manufacturerIdentity: %s\n", MANUFACTURER_ID); /* initialize networking */ netShutdown(&ptpClock->netPath); if (!netInit(&ptpClock->netPath, ptpClock)) { ERROR("doInit: failed to initialize network\n"); return FALSE; } else { /* initialize other stuff */ initData(ptpClock); initTimer(); initClock(ptpClock); m1(ptpClock); msgPackHeader(ptpClock, ptpClock->msgObuf); return TRUE; } }
Boolean doInit(RunTimeOpts *rtOpts, PtpClock *ptpClock) { DBG("manufacturerIdentity: %s\n", MANUFACTURER_ID); /* initialize networking */ netShutdown(&ptpClock->netPath); if (!netInit(&ptpClock->netPath, rtOpts, ptpClock)) { ERROR("failed to initialize network\n"); toState(PTP_FAULTY, rtOpts, ptpClock); return FALSE; } /* initialize other stuff */ initData(rtOpts, ptpClock); initTimer(); initClock(rtOpts, ptpClock); m1(rtOpts, ptpClock ); msgPackHeader(ptpClock->msgObuf, ptpClock); toState(PTP_LISTENING, rtOpts, ptpClock); return TRUE; }
//Init Network Prompt static int lua_NetPromptInit(lua_State *L) { int argc = lua_gettop(L); if (argc > 0) { return luaL_error(L, "System.Quit() takes no arguments"); } static int doOnce = 1; if (doOnce) { sceUtilityLoadNetModule(PSP_NET_MODULE_COMMON); sceUtilityLoadNetModule(PSP_NET_MODULE_INET); netInit(); netDialog(); netTerm(); doOnce = 0; } return 0; }
int createSocketThread(int argc, const char *argv[]) { #define BUFF_SIZE 100 int res; static pthread_t a_thread; void *thread_result; char buff[BUFF_SIZE]; int sockfd; struct sockaddr_in servaddr; const char* ip = defaultServerIp; if (argc >= 2) { ip = argv[1]; } printf("v1.1 usage: ./client <ipaddress>\n"); if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { printf("create socket error: %s(errno: %d)\n", strerror(errno), errno); exit(0); } memset(&servaddr, 0, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_port = htons(portno); if (inet_pton(AF_INET, ip, &servaddr.sin_addr) <= 0) { printf("inet_pton error for %s\n", ip); exit(0); } if (connect(sockfd, (struct sockaddr*) &servaddr, sizeof(servaddr)) < 0) { printf("connect error: %s(errno: %d)\n", strerror(errno), errno); exit(0); } netInit(); res = pthread_create(&a_thread, NULL, thread_function, (void *) &sockfd); if (res != 0) { perror("Thread creation failed!"); exit(EXIT_FAILURE); } printf("Waiting for thread to finish.../n"); int count = 0; while(1){ count++; if(count%50 == 0){ printf("\r\nnet running....%d\r\n", count ); } bzero(buff, BUFF_SIZE); netRun(); if(getGpsFlag()){ resetGpsFlag(); netGpsInfo(GPS_TEST, strlen(GPS_TEST)); } if( count %800 == 0){ netHeartBeat(); } usleep(100000); } res = pthread_join(a_thread, &thread_result); if (res != 0) { perror("Thread join failed!/n"); exit(EXIT_FAILURE); } printf("Thread joined, it returned %s/n", (char *) thread_result); exit(EXIT_FAILURE); }
/** * Intializes all Xinu data structures and devices. * @return OK if everything is initialized successfully */ static int sysinit(void) { int i; struct thrent *thrptr; /* thread control block pointer */ struct memblock *pmblock; /* memory block pointer */ /* Initialize system variables */ /* Count this NULLTHREAD as the first thread in the system. */ thrcount = 1; /* Initialize free memory list */ memheap = roundmb(memheap); platform.maxaddr = truncmb(platform.maxaddr); memlist.next = pmblock = (struct memblock *)memheap; memlist.length = (uint)(platform.maxaddr - memheap); pmblock->next = NULL; pmblock->length = (uint)(platform.maxaddr - memheap); /* Initialize thread table */ for (i = 0; i < NTHREAD; i++) { thrtab[i].state = THRFREE; } /* initialize null thread entry */ thrptr = &thrtab[NULLTHREAD]; thrptr->state = THRCURR; thrptr->prio = 0; strlcpy(thrptr->name, "prnull", TNMLEN); thrptr->stkbase = (void *)&_end; thrptr->stklen = (ulong)memheap - (ulong)&_end; thrptr->stkptr = 0; thrptr->memlist.next = NULL; thrptr->memlist.length = 0; thrcurrent = NULLTHREAD; /* Initialize semaphores */ for (i = 0; i < NSEM; i++) { semtab[i].state = SFREE; semtab[i].queue = queinit(); } /* Initialize monitors */ for (i = 0; i < NMON; i++) { montab[i].state = MFREE; } /* Initialize buffer pools */ for (i = 0; i < NPOOL; i++) { bfptab[i].state = BFPFREE; } /* initialize thread ready list */ readylist = queinit(); #if SB_BUS backplaneInit(NULL); #endif /* SB_BUS */ #if RTCLOCK /* initialize real time clock */ clkinit(); #endif /* RTCLOCK */ #ifdef UHEAP_SIZE /* Initialize user memory manager */ { void *userheap; /* pointer to user memory heap */ userheap = stkget(UHEAP_SIZE); if (SYSERR != (int)userheap) { userheap = (void *)((uint)userheap - UHEAP_SIZE + sizeof(int)); memRegionInit(userheap, UHEAP_SIZE); /* initialize memory protection */ safeInit(); /* initialize kernel page mappings */ safeKmapInit(); } } #endif #if USE_TLB /* initialize TLB */ tlbInit(); /* register system call handler */ exceptionVector[EXC_SYS] = syscall_entry; #endif /* USE_TLB */ #if NMAILBOX /* intialize mailboxes */ mailboxInit(); #endif #if NDEVS for (i = 0; i < NDEVS; i++) { devtab[i].init((device*)&devtab[i]); } #endif #ifdef WITH_USB usbinit(); #endif #if NVRAM nvramInit(); #endif #if NNETIF netInit(); #endif #if GPIO gpioLEDOn(GPIO_LED_CISCOWHT); #endif return OK; }
void probe(PtpClock *ptpClock) { UInteger16 i; UInteger16 length; TimeInternal interval, now, finish; /* check */ if(ptpClock->runTimeOpts.probe_management_key == PTP_MM_UPDATE_DEFAULT_DATA_SET || ptpClock->runTimeOpts.probe_management_key == PTP_MM_UPDATE_GLOBAL_TIME_PROPERTIES || ptpClock->runTimeOpts.probe_management_key == PTP_MM_SET_SYNC_INTERVAL) { ERROR("send not supported for that management message\n"); return; } /* init */ if(!netInit(ptpClock)) { ERROR("failed to initialize network\n"); return; } initData(ptpClock); msgPackHeader(ptpClock->msgObuf, ptpClock); memset(&ptpClock->msgTmp.manage, 0, sizeof(MsgManagement)); ptpClock->msgTmp.manage.targetCommunicationTechnology = PTP_DEFAULT; /* send */ for(i = 0; i < KEY_ARRAY_LEN; ++i) { if(ptpClock->runTimeOpts.probe_management_key > 0) { ptpClock->msgTmp.manage.managementMessageKey = ptpClock->runTimeOpts.probe_management_key; ptpClock->msgTmp.manage.recordKey = ptpClock->runTimeOpts.probe_record_key; } else ptpClock->msgTmp.manage.managementMessageKey = management_key_array[i]; if(!(length = msgPackManagement(ptpClock->msgObuf, &ptpClock->msgTmp.manage, ptpClock))) { ERROR("failed to pack management message\n"); return; } printf("\n(sending managementMessageKey %hhu)\n", ptpClock->msgTmp.manage.managementMessageKey); if(!netSendGeneral(ptpClock->msgObuf, length, ptpClock)) { ERROR("failed to send message\n"); return; } if(ptpClock->runTimeOpts.probe_management_key > 0) break; } timerNow(&finish); finish.seconds += PTP_SYNC_INTERVAL_TIMEOUT(ptpClock->sync_interval); for(;;) { interval.seconds = PTP_SYNC_INTERVAL_TIMEOUT(ptpClock->sync_interval); interval.nanoseconds = 0; netSelect(&interval, ptpClock); netRecvEvent(ptpClock->msgIbuf, NULL, ptpClock); if(netRecvGeneral(ptpClock->msgIbuf, ptpClock)) { msgUnpackHeader(ptpClock->msgIbuf, &ptpClock->msgTmpHeader); if(ptpClock->msgTmpHeader.control == PTP_MANAGEMENT_MESSAGE) { msgUnpackManagement(ptpClock->msgIbuf, &ptpClock->msgTmp.manage); msgUnpackManagementPayload(ptpClock->msgIbuf, &ptpClock->msgTmp.manage); displayManagement(&ptpClock->msgTmpHeader, &ptpClock->msgTmp.manage); } fflush(stdout); } timerNow(&now); if( now.seconds > finish.seconds || (now.seconds == finish.seconds && now.nanoseconds > finish.nanoseconds) ) break; } /* done */ printf("\n"); ptpdShutdown(); exit(0); }
int_t main(void) { error_t error; NetInterface *interface; OsTask *task; MacAddr macAddr; #if (APP_USE_DHCP == DISABLED) Ipv4Addr ipv4Addr; #endif #if (APP_USE_SLAAC == DISABLED) Ipv6Addr ipv6Addr; #endif //Initialize kernel osInitKernel(); //Configure debug UART debugInit(115200); //Start-up message TRACE_INFO("\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("*** CycloneTCP Web Server Demo ***\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("Copyright: 2010-2016 Oryx Embedded SARL\r\n"); TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__); TRACE_INFO("Target: SAM7SE512\r\n"); TRACE_INFO("\r\n"); //Configure I/Os ioInit(); //Generate a random seed //PRNG initialization error = yarrowInit(&yarrowContext); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize PRNG!\r\n"); } //Properly seed the PRNG error = yarrowSeed(&yarrowContext, seed, sizeof(seed)); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to seed PRNG!\r\n"); } //TCP/IP stack initialization error = netInit(); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n"); } //Configure the first Ethernet interface interface = &netInterface[0]; //Set interface name netSetInterfaceName(interface, "eth0"); //Set host name netSetHostname(interface, "WebServerDemo"); //Select the relevant network adapter netSetDriver(interface, &dm9000Driver); //Set external interrupt line driver netSetExtIntDriver(interface, &extIntDriver); //Set host MAC address macStringToAddr(APP_MAC_ADDR, &macAddr); netSetMacAddr(interface, &macAddr); //Initialize network interface error = netConfigInterface(interface); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name); } #if (IPV4_SUPPORT == ENABLED) #if (APP_USE_DHCP == ENABLED) //Get default settings dhcpClientGetDefaultSettings(&dhcpClientSettings); //Set the network interface to be configured by DHCP dhcpClientSettings.interface = interface; //Disable rapid commit option dhcpClientSettings.rapidCommit = FALSE; //DHCP client initialization error = dhcpClientInit(&dhcpClientContext, &dhcpClientSettings); //Failed to initialize DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to initialize DHCP client!\r\n"); } //Start DHCP client error = dhcpClientStart(&dhcpClientContext); //Failed to start DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to start DHCP client!\r\n"); } #else //Set IPv4 host address ipv4StringToAddr(APP_IPV4_HOST_ADDR, &ipv4Addr); ipv4SetHostAddr(interface, ipv4Addr); //Set subnet mask ipv4StringToAddr(APP_IPV4_SUBNET_MASK, &ipv4Addr); ipv4SetSubnetMask(interface, ipv4Addr); //Set default gateway ipv4StringToAddr(APP_IPV4_DEFAULT_GATEWAY, &ipv4Addr); ipv4SetDefaultGateway(interface, ipv4Addr); //Set primary and secondary DNS servers ipv4StringToAddr(APP_IPV4_PRIMARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 0, ipv4Addr); ipv4StringToAddr(APP_IPV4_SECONDARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 1, ipv4Addr); #endif #endif #if (IPV6_SUPPORT == ENABLED) #if (APP_USE_SLAAC == ENABLED) //Get default settings slaacGetDefaultSettings(&slaacSettings); //Set the network interface to be configured slaacSettings.interface = interface; //SLAAC initialization error = slaacInit(&slaacContext, &slaacSettings); //Failed to initialize SLAAC? if(error) { //Debug message TRACE_ERROR("Failed to initialize SLAAC!\r\n"); } //Start IPv6 address autoconfiguration process error = slaacStart(&slaacContext); //Failed to start SLAAC process? if(error) { //Debug message TRACE_ERROR("Failed to start SLAAC!\r\n"); } #else //Set link-local address ipv6StringToAddr(APP_IPV6_LINK_LOCAL_ADDR, &ipv6Addr); ipv6SetLinkLocalAddr(interface, &ipv6Addr); //Set IPv6 prefix ipv6StringToAddr(APP_IPV6_PREFIX, &ipv6Addr); ipv6SetPrefix(interface, 0, &ipv6Addr, APP_IPV6_PREFIX_LENGTH); //Set global address ipv6StringToAddr(APP_IPV6_GLOBAL_ADDR, &ipv6Addr); ipv6SetGlobalAddr(interface, 0, &ipv6Addr); //Set default router ipv6StringToAddr(APP_IPV6_ROUTER, &ipv6Addr); ipv6SetDefaultRouter(interface, 0, &ipv6Addr); //Set primary and secondary DNS servers ipv6StringToAddr(APP_IPV6_PRIMARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 0, &ipv6Addr); ipv6StringToAddr(APP_IPV6_SECONDARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 1, &ipv6Addr); #endif #endif //Get default settings httpServerGetDefaultSettings(&httpServerSettings); //Bind HTTP server to the desired interface httpServerSettings.interface = &netInterface[0]; //Listen to port 80 httpServerSettings.port = HTTP_PORT; //Client connections httpServerSettings.maxConnections = APP_HTTP_MAX_CONNECTIONS; httpServerSettings.connections = httpConnections; //Specify the server's root directory strcpy(httpServerSettings.rootDirectory, "/www/"); //Set default home page strcpy(httpServerSettings.defaultDocument, "index.shtm"); //Callback functions httpServerSettings.authCallback = httpServerAuthCallback; httpServerSettings.cgiCallback = httpServerCgiCallback; httpServerSettings.uriNotFoundCallback = httpServerUriNotFoundCallback; //HTTP server initialization error = httpServerInit(&httpServerContext, &httpServerSettings); //Failed to initialize HTTP server? if(error) { //Debug message TRACE_ERROR("Failed to initialize HTTP server!\r\n"); } //Start HTTP server error = httpServerStart(&httpServerContext); //Failed to start HTTP server? if(error) { //Debug message TRACE_ERROR("Failed to start HTTP server!\r\n"); } //Create a task to blink the LED task = osCreateTask("Blink", blinkTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Start the execution of tasks osStartKernel(); //This function should never return return 0; }
int_t main(void) { error_t error; NetInterface *interface; OsTask *task; MacAddr macAddr; #if (APP_USE_DHCP == DISABLED) Ipv4Addr ipv4Addr; #endif #if (APP_USE_SLAAC == DISABLED) Ipv6Addr ipv6Addr; #endif //System initialization systemInit(); //Initialize kernel osInitKernel(); //Configure debug UART debugInit(115200); //Start-up message TRACE_INFO("\r\n"); TRACE_INFO("***********************************\r\n"); TRACE_INFO("*** CycloneTCP SMTP Client Demo ***\r\n"); TRACE_INFO("***********************************\r\n"); TRACE_INFO("Copyright: 2010-2015 Oryx Embedded SARL\r\n"); TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__); TRACE_INFO("Target: PIC32MX795F512L\r\n"); TRACE_INFO("\r\n"); //Configure I/Os ioInit(); //Generate a random seed //PRNG initialization error = yarrowInit(&yarrowContext); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize PRNG!\r\n"); } //Properly seed the PRNG error = yarrowSeed(&yarrowContext, seed, sizeof(seed)); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to seed PRNG!\r\n"); } //TCP/IP stack initialization error = netInit(); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n"); } //Configure the first Ethernet interface interface = &netInterface[0]; //Set interface name netSetInterfaceName(interface, "eth0"); //Set host name netSetHostname(interface, "SMTPClientDemo"); //Select the relevant network adapter netSetDriver(interface, &pic32mxEthDriver); netSetPhyDriver(interface, &dp83848PhyDriver); //Set external interrupt line driver netSetExtIntDriver(interface, &extIntDriver); #if (APP_USE_DEFAULT_MAC_ADDR == ENABLED) //Use the factory preprogrammed MAC address macStringToAddr("00-00-00-00-00-00", &macAddr); netSetMacAddr(interface, &macAddr); #else //Override the factory preprogrammed address macStringToAddr(APP_MAC_ADDR, &macAddr); netSetMacAddr(interface, &macAddr); #endif //Initialize network interface error = netConfigInterface(interface); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name); } #if (IPV4_SUPPORT == ENABLED) #if (APP_USE_DHCP == ENABLED) //Get default settings dhcpClientGetDefaultSettings(&dhcpClientSettings); //Set the network interface to be configured by DHCP dhcpClientSettings.interface = interface; //Disable rapid commit option dhcpClientSettings.rapidCommit = FALSE; //DHCP client initialization error = dhcpClientInit(&dhcpClientContext, &dhcpClientSettings); //Failed to initialize DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to initialize DHCP client!\r\n"); } //Start DHCP client error = dhcpClientStart(&dhcpClientContext); //Failed to start DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to start DHCP client!\r\n"); } #else //Set IPv4 host address ipv4StringToAddr(APP_IPV4_HOST_ADDR, &ipv4Addr); ipv4SetHostAddr(interface, ipv4Addr); //Set subnet mask ipv4StringToAddr(APP_IPV4_SUBNET_MASK, &ipv4Addr); ipv4SetSubnetMask(interface, ipv4Addr); //Set default gateway ipv4StringToAddr(APP_IPV4_DEFAULT_GATEWAY, &ipv4Addr); ipv4SetDefaultGateway(interface, ipv4Addr); //Set primary and secondary DNS servers ipv4StringToAddr(APP_IPV4_PRIMARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 0, ipv4Addr); ipv4StringToAddr(APP_IPV4_SECONDARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 1, ipv4Addr); #endif #endif #if (IPV6_SUPPORT == ENABLED) #if (APP_USE_SLAAC == ENABLED) //Get default settings slaacGetDefaultSettings(&slaacSettings); //Set the network interface to be configured slaacSettings.interface = interface; //SLAAC initialization error = slaacInit(&slaacContext, &slaacSettings); //Failed to initialize SLAAC? if(error) { //Debug message TRACE_ERROR("Failed to initialize SLAAC!\r\n"); } //Start IPv6 address autoconfiguration process error = slaacStart(&slaacContext); //Failed to start SLAAC process? if(error) { //Debug message TRACE_ERROR("Failed to start SLAAC!\r\n"); } #else //Set link-local address ipv6StringToAddr(APP_IPV6_LINK_LOCAL_ADDR, &ipv6Addr); ipv6SetLinkLocalAddr(interface, &ipv6Addr); //Set IPv6 prefix ipv6StringToAddr(APP_IPV6_PREFIX, &ipv6Addr); ipv6SetPrefix(interface, &ipv6Addr, APP_IPV6_PREFIX_LENGTH); //Set global address ipv6StringToAddr(APP_IPV6_GLOBAL_ADDR, &ipv6Addr); ipv6SetGlobalAddr(interface, &ipv6Addr); //Set router ipv6StringToAddr(APP_IPV6_ROUTER, &ipv6Addr); ipv6SetRouter(interface, &ipv6Addr); //Set primary and secondary DNS servers ipv6StringToAddr(APP_IPV6_PRIMARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 0, &ipv6Addr); ipv6StringToAddr(APP_IPV6_SECONDARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 1, &ipv6Addr); #endif #endif //Create user task task = osCreateTask("User Task", userTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Create a task to blink the LED task = osCreateTask("Blink", blinkTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Start the execution of tasks osStartKernel(); //This function should never return return 0; }
int main(int argc, char *argv[]) { char *ampersand; App *app; unsigned char *equals; HTTPNameValue *h; HTTPNameValue *headers; char *name; unsigned char *newURL; char *p; char *query; unsigned char *referer; URL *u; unsigned char *url; char *verbose; char *version; View *view; if (!netInit()) { return 1; } if (!threadInit()) { return 1; } referer = NULL; url = NULL; verbose = "?url="; query = getenv("QUERY_STRING"); app = appAlloc(); app->html = cgiviewHTML; app->htmlAttributeName = cgiviewHTMLAttributeName; app->htmlAttributeValue = cgiviewHTMLAttributeValue; app->htmlDeclaration = cgiviewHTMLDeclaration; app->htmlProcessingInstruction = cgiviewHTMLProcessingInstruction; app->htmlTag = cgiviewHTMLTag; app->htmlText = cgiviewHTMLText; app->httpRequest = cgiviewHTTPRequest; app->httpRequestHeaderName = cgiviewHTTPRequestHeaderName; app->httpRequestHeaderValue = cgiviewHTTPRequestHeaderValue; app->httpResponse = cgiviewHTTPResponse; app->httpResponseBody = cgiviewHTTPResponseBody; app->httpResponseHeaderName = cgiviewHTTPResponseHeaderName; app->httpResponseHeaderValue = cgiviewHTTPResponseHeaderValue; app->printHTML = cgiviewPrintHTML; view = &app->view; view->out = stdout; freopen("/dev/null", "w", stderr); fprintf(view->out, "Content-Type: text/html\n"); fprintf(view->out, "\n"); if (query) { p = query; do { name = p; ampersand = strchr(p, '&'); if (ampersand) { *ampersand = 0; p = ampersand + 1; } equals = (unsigned char *) strchr(name, '='); if (equals) { *equals = 0; if (!strcmp(name, "referer")) { referer = equals + 1; urlDecode(referer); } else if (!strcmp(name, "url")) { url = equals + 1; urlDecode(url); } else if (!strcmp(name, "verbose")) { verbose = "?verbose=on&url="; viewVerbose(); } } } while (ampersand); } else if (argc > 1) { url = (unsigned char *) argv[1]; } else { fprintf(view->out, "no environment variable QUERY_STRING<br>\n"); fprintf(view->out, "and no arg passed<br>\n"); return 1; } if (url && (*url)) { fprintf(view->out, "<html><head><title>View %s</title>", url); fprintf(view->out, "<link rel=stylesheet href=view.css>"); fprintf(view->out, "</head><body>\n"); viewReport(app, "input url:"); viewReport(app, (char *) url); viewReportHTML(app, "<hr>"); u = urlParse(url); if ( ((!u->scheme)||(!strcmp((char *) u->scheme, "http"))) && (!u->host) && (*url != '/') ) { newURL = calloc(strlen((char *) url) + 3, 1); if (!newURL) { viewReport(app, "calloc failed"); return 1; } strcpy((char *) newURL, "//"); strcat((char *) newURL, (char *) url); } else { newURL = copyString(url); } urlFree(u); u = urlParse(newURL); if ( ( (!u->scheme) || (!strcmp((char *) u->scheme, "http")) ) && (!*u->path) ) { url = newURL; newURL = calloc(strlen((char *) url) + 2, 1); if (!newURL) { viewReport(app, "calloc failed"); return 1; } strcpy((char *) newURL, (char *) url); free(url); strcat((char *) newURL, "/"); } urlFree(u); u = urlRelative( (unsigned char *) "http://www.mozilla.org/index.html", newURL); free(newURL); viewReport(app, "fully qualified url:"); viewReport(app, (char *) u->url); viewReportHTML(app, "<hr>"); if (!strcmp((char *) u->scheme, "http")) { version = NULL; headers = cgiviewGetEnv(app, (char *) referer, verbose, &version); if (!headers) { return 1; } httpFree(httpProcess(app, u, version, headers)); h = headers; while (h->name) { free(h->name); free(h->value); h++; } free(headers); } else { fprintf ( view->out, "Sorry, %s URLs are not supported yet. " "Only http URLs are supported.", u->scheme ); } fprintf(view->out, "</body></html>\n"); } else { fprintf(view->out, "<html><head><title>SniffURI Error</title>"); fprintf(view->out, "</head><body><h2>Please enter a URI</h2>"); fprintf(view->out, "<a href=index.html>Go Back</a>"); fprintf(view->out, "</body></html>"); } exit(0); return 1; }
int main (int argc, char *argv[]) { int numbytes; static char buf[MAXBUFLEN]; //int c; //int ret = 0; prog = strdup( base_name(argv[0]) ); /* program header */ std::cout << prog << " - a communication radio based on VoIP with IAX/Asterisk" << std::endl; std::cout << "Original (c) 2007-2011 by H. Wirtz <*****@*****.**>" << std::endl; std::cout << "OSX and Windows ports 2012 by Yves Sablonier and Geoff R. McLane, respectively." << std::endl; std::cout << "Version " << FGCOM_VERSION << " build " << SVN_REV << " date " << __DATE__ << ", at " << __TIME__ << std::endl; std::cout << "Using iaxclient library Version " << iaxc_version (tmp) << std::endl; std::cout << std::endl; /* init values */ voipserver = DEFAULT_VOIP_SERVER; fgserver = DEFAULT_FG_SERVER; port = DEFAULT_FG_PORT; username = DEFAULT_USER; password = DEFAULT_PASSWORD; codec_option = DEFAULT_CODEC; mode = 0; /* 0 = ATC mode, 1 = FG mode */ positions_file = (char *) DEFAULT_POSITIONS_FILE; frequency_file = (char *) SPECIAL_FREQUENCIES_FILE; #ifndef _WIN32 /* catch signals */ signal (SIGINT, quit); signal (SIGQUIT, quit); signal (SIGTERM, quit); #endif /* setup iax */ #ifdef HAVE_IAX12 if (iaxc_initialize (DEFAULT_MAX_CALLS)) #else if (iaxc_initialize (DEFAULT_IAX_AUDIO, DEFAULT_MAX_CALLS)) #endif fatal_error ("cannot initialize iaxclient!\nHINT: Have you checked the mic and speakers?"); initialized = 1; // option parser fgcomInitOptions (fgcomOptionArray, argc, argv); // codec if (codec_option) { switch (codec_option) { case 'u': codec = IAXC_FORMAT_ULAW; break; case 'a': codec = IAXC_FORMAT_ALAW; break; case 'g': codec = IAXC_FORMAT_GSM; break; case '7': codec = IAXC_FORMAT_G726; break; case 's': codec = IAXC_FORMAT_SPEEX; break; } } // airport if (airport_option) { strtoupper (airport_option, airport, sizeof (airport)); } // input level if (level_in > 1.0) { level_in = 1.0; } if (level_in < 0.0) { level_in = 0.0; } // output level if (level_out > 1.0) { level_out = 1.0; } if (level_out < 0.0) { level_out = 0.0; } // microphone boost if (mic_boost) { iaxc_mic_boost_set (1); } if (list_audio) { std::cout << "Input audio devices:" << std::endl; std::cout << report_devices (IAXC_AD_INPUT) << std::endl; std::cout << "Output audio devices:" << std::endl; std::cout << report_devices (IAXC_AD_OUTPUT) << std::endl; iaxc_shutdown (); exit (1); } if (audio_in) { set_device (audio_in, 0); } if (audio_out) { set_device (audio_out, 1); } //#ifdef DEBUG /* Print any remaining command line arguments (not options). */ //if (optind < argc) { // printf ("non-option ARGV-elements: "); // while (optind < argc) // printf ("%s ", argv[optind++]); // putchar ('\n'); //} //#endif /* checking consistency of arguments */ if (frequency > 0.0 && frequency < 1000.0) { if (strlen (airport) == 0 || strlen (airport) > 4) { strcpy (airport, "ZZZZ"); } /* airport and frequency are given => ATC mode */ mode = 0; } else { /* no airport => FG mode */ mode = 1; } /* Read special frequencies file (if exists). * If no file $(INSTALL_DIR)/special_frequencies.txt exists, then default frequencies * are used and are hard coded. */ if (fix_input_files()) { /* adjust default input per OS */ fatal_error ("cannot adjust default input files per OS!\nHINT: Maybe recompile with larger buffer."); } if((special_frequencies = read_special_frequencies(frequency_file)) == 0) { std::cout << "Failed to load file [" << frequency_file << "]!\nUsing internal defaults." << std::endl; special_frequencies = special_frq; } else { std::cout << "Loaded file [" << frequency_file << "]." << std::endl; } /* read airport frequencies and positions */ airportlist = read_airports (positions_file); /* never returns if fail! */ /* preconfigure iax */ std::cout << "Initializing IAX client as " << username << ":" << "xxxxxxxxxxx@" << voipserver << std::endl; iaxc_set_callerid (const_cast < char *>(username), const_cast < char *>("0125252525122750")); iaxc_set_formats (codec, IAXC_FORMAT_ULAW | IAXC_FORMAT_GSM | IAXC_FORMAT_SPEEX); iaxc_set_event_callback (iaxc_callback); iaxc_start_processing_thread (); if (username && password && voipserver) { reg_id = iaxc_register (const_cast < char *>(username), const_cast < char *>(password), const_cast < char *>(voipserver)); #ifdef DEBUG std::cout << "DEBUG: Registered as '" << username << "' at '" << voipserver << "'." << std::endl; #endif } else { std::cout << "Failed iaxc_register!\nHINT: Check user name, pwd and ip of server." << std::endl; exitcode = 130; quit (0); } iaxc_millisleep (DEFAULT_MILLISLEEP); /* main loop */ #ifdef DEBUG std::cout << "Entering main loop in mode " << mode_map[mode] << "." << std::endl; #endif if (mode == 1) { /* only in FG mode */ netInit (); netSocket fgsocket; fgsocket.open (false); fgsocket.bind (fgserver, port); /* mute mic, speaker on */ iaxc_input_level_set (0); iaxc_output_level_set (level_out); ulClock clock; clock.update (); double next_update = clock.getAbsTime () + DEFAULT_ALARM_TIMER; /* get data from flightgear */ while (1) { clock.update (); double wait = next_update - clock.getAbsTime (); if (wait > 0.001) { netSocket *readsockets[2] = { &fgsocket, 0 }; if (fgsocket.select (readsockets, readsockets + 1, (int) (wait * 1000)) == 1) { netAddress their_addr; if ((numbytes = fgsocket.recvfrom (buf, MAXBUFLEN - 1, 0, &their_addr)) == -1) { perror ("recvfrom"); exit (1); } buf[numbytes] = '\0'; #ifdef DEBUG std:: cout << "DEBUG: got packet from " << their_addr.getHost () << ":" << their_addr.getPort () << std::endl; std::cout << "packet is " << numbytes << " bytes long" << std::endl; std:: cout << "packet contains \"" << buf << "\"" << std::endl; #endif process_packet (buf); } } else { alarm_handler (0); clock.update (); next_update = clock.getAbsTime () + DEFAULT_ALARM_TIMER; } } } else { /* only in ATC mode */ struct pos p; /* mic on, speaker on */ iaxc_input_level_set (level_in); iaxc_output_level_set (level_out); /* get geo positions of the airport */ p = posbyicao (airportlist, airport); icao2number (airport, frequency, tmp); #ifdef DEBUG printf ("DEBUG: dialing %s %3.3f MHz: %s\n", airport, frequency, tmp); #endif do_iaxc_call (username, password, voipserver, tmp); /* iaxc_select_call (0); */ while (1) { /* sleep endless */ ulSleep (3600); } } /* should never be reached */ exitcode = 999; quit (0); }
int_t main(void) { error_t error; NetInterface *interface; OsTask *task; MacAddr macAddr; #if (APP_USE_DHCP == DISABLED) Ipv4Addr ipv4Addr; #endif #if (APP_USE_SLAAC == DISABLED) Ipv6Addr ipv6Addr; #endif //MPU configuration MPU_Config(); //HAL library initialization HAL_Init(); //Configure the system clock SystemClock_Config(); //Enable I-cache and D-cache SCB_EnableICache(); SCB_EnableDCache(); //Initialize kernel osInitKernel(); //Configure debug UART debugInit(115200); //Start-up message TRACE_INFO("\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("*** CycloneTCP FTP Client Demo ***\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("Copyright: 2010-2015 Oryx Embedded SARL\r\n"); TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__); TRACE_INFO("Target: STM32F746\r\n"); TRACE_INFO("\r\n"); //LED configuration BSP_LED_Init(LED1); //Clear LEDs BSP_LED_Off(LED1); //Initialize user button BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO); //Initialize LCD display BSP_LCD_Init(); BSP_LCD_LayerDefaultInit(0, LCD_FRAME_BUFFER_LAYER0); BSP_LCD_SelectLayer(0); BSP_LCD_SetBackColor(LCD_COLOR_BLUE); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_SetFont(&Font24); BSP_LCD_DisplayOn(); //Clear LCD display BSP_LCD_Clear(LCD_COLOR_BLUE); //Welcome message lcdSetCursor(0, 0); printf("FTP Client Demo\r\n"); //TCP/IP stack initialization error = netInit(); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n"); } //Configure the first Ethernet interface interface = &netInterface[0]; //Set interface name netSetInterfaceName(interface, "eth0"); //Set host name netSetHostname(interface, "FTPClientDemo"); //Select the relevant network adapter netSetDriver(interface, &stm32f7xxEthDriver); netSetPhyDriver(interface, &lan8742PhyDriver); //Set host MAC address macStringToAddr(APP_MAC_ADDR, &macAddr); netSetMacAddr(interface, &macAddr); //Initialize network interface error = netConfigInterface(interface); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name); } #if (IPV4_SUPPORT == ENABLED) #if (APP_USE_DHCP == ENABLED) //Get default settings dhcpClientGetDefaultSettings(&dhcpClientSettings); //Set the network interface to be configured by DHCP dhcpClientSettings.interface = interface; //Disable rapid commit option dhcpClientSettings.rapidCommit = FALSE; //DHCP client initialization error = dhcpClientInit(&dhcpClientContext, &dhcpClientSettings); //Failed to initialize DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to initialize DHCP client!\r\n"); } //Start DHCP client error = dhcpClientStart(&dhcpClientContext); //Failed to start DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to start DHCP client!\r\n"); } #else //Set IPv4 host address ipv4StringToAddr(APP_IPV4_HOST_ADDR, &ipv4Addr); ipv4SetHostAddr(interface, ipv4Addr); //Set subnet mask ipv4StringToAddr(APP_IPV4_SUBNET_MASK, &ipv4Addr); ipv4SetSubnetMask(interface, ipv4Addr); //Set default gateway ipv4StringToAddr(APP_IPV4_DEFAULT_GATEWAY, &ipv4Addr); ipv4SetDefaultGateway(interface, ipv4Addr); //Set primary and secondary DNS servers ipv4StringToAddr(APP_IPV4_PRIMARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 0, ipv4Addr); ipv4StringToAddr(APP_IPV4_SECONDARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 1, ipv4Addr); #endif #endif #if (IPV6_SUPPORT == ENABLED) #if (APP_USE_SLAAC == ENABLED) //Get default settings slaacGetDefaultSettings(&slaacSettings); //Set the network interface to be configured slaacSettings.interface = interface; //SLAAC initialization error = slaacInit(&slaacContext, &slaacSettings); //Failed to initialize SLAAC? if(error) { //Debug message TRACE_ERROR("Failed to initialize SLAAC!\r\n"); } //Start IPv6 address autoconfiguration process error = slaacStart(&slaacContext); //Failed to start SLAAC process? if(error) { //Debug message TRACE_ERROR("Failed to start SLAAC!\r\n"); } #else //Set link-local address ipv6StringToAddr(APP_IPV6_LINK_LOCAL_ADDR, &ipv6Addr); ipv6SetLinkLocalAddr(interface, &ipv6Addr); //Set IPv6 prefix ipv6StringToAddr(APP_IPV6_PREFIX, &ipv6Addr); ipv6SetPrefix(interface, &ipv6Addr, APP_IPV6_PREFIX_LENGTH); //Set global address ipv6StringToAddr(APP_IPV6_GLOBAL_ADDR, &ipv6Addr); ipv6SetGlobalAddr(interface, &ipv6Addr); //Set router ipv6StringToAddr(APP_IPV6_ROUTER, &ipv6Addr); ipv6SetRouter(interface, &ipv6Addr); //Set primary and secondary DNS servers ipv6StringToAddr(APP_IPV6_PRIMARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 0, &ipv6Addr); ipv6StringToAddr(APP_IPV6_SECONDARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 1, &ipv6Addr); #endif #endif //Create user task task = osCreateTask("User Task", userTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Create a task to blink the LED task = osCreateTask("Blink", blinkTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Start the execution of tasks osStartKernel(); //This function should never return return 0; }
int_t main(void) { error_t error; NetInterface *interface; OsTask *task; MacAddr macAddr; #if (APP_USE_DHCP == DISABLED) Ipv4Addr ipv4Addr; #endif #if (APP_USE_SLAAC == DISABLED) Ipv6Addr ipv6Addr; #endif //Initialize kernel osInitKernel(); //Configure debug UART debugInit(115200); //Start-up message TRACE_INFO("\r\n"); TRACE_INFO("******************************\r\n"); TRACE_INFO("*** CycloneSSL Client Demo ***\r\n"); TRACE_INFO("******************************\r\n"); TRACE_INFO("Copyright: 2010-2015 Oryx Embedded SARL\r\n"); TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__); TRACE_INFO("Target: AT32UC3A0512\r\n"); TRACE_INFO("\r\n"); //Configure I/Os ioInit(); //Initialize LCD display /*GLCD_Init(); GLCD_SetBackColor(Blue); GLCD_SetTextColor(White); GLCD_Clear(Blue);*/ //Welcome message lcdSetCursor(0, 0); printf("SSL Client Demo\r\n"); //Generate a random seed //PRNG initialization error = yarrowInit(&yarrowContext); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize PRNG!\r\n"); } //Properly seed the PRNG error = yarrowSeed(&yarrowContext, seed, sizeof(seed)); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to seed PRNG!\r\n"); } //Debug message TRACE_INFO("Loading credentials...\r\n"); //Start of exception handling block do { //Load trusted CA certificates error = resGetData(APP_CA_CERT_BUNDLE, (uint8_t **) &trustedCaList, &trustedCaListLength); //Any error to report? if(error) break; //Load client's certificate error = resGetData(APP_CLIENT_CERT, (uint8_t **) &clientCert, &clientCertLength); //Any error to report? if(error) break; //Load client's private key error = resGetData(APP_CLIENT_PRIVATE_KEY, (uint8_t **) &clientPrivateKey, &clientPrivateKeyLength); //Any error to report? if(error) break; //End of exception handling block } while(0); //Check error code if(error) { //Debug message TRACE_ERROR("Failed to load credentials!\r\n"); } //TCP/IP stack initialization error = netInit(); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n"); } //Configure the first Ethernet interface interface = &netInterface[0]; //Set interface name netSetInterfaceName(interface, "eth0"); //Set host name netSetHostname(interface, "SSLClientDemo"); //Select the relevant network adapter netSetDriver(interface, &avr32EthDriver); netSetPhyDriver(interface, &dp83848PhyDriver); //Set host MAC address macStringToAddr(APP_MAC_ADDR, &macAddr); netSetMacAddr(interface, &macAddr); //Initialize network interface error = netConfigInterface(interface); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name); } #if (IPV4_SUPPORT == ENABLED) #if (APP_USE_DHCP == ENABLED) //Get default settings dhcpClientGetDefaultSettings(&dhcpClientSettings); //Set the network interface to be configured by DHCP dhcpClientSettings.interface = interface; //Disable rapid commit option dhcpClientSettings.rapidCommit = FALSE; //DHCP client initialization error = dhcpClientInit(&dhcpClientContext, &dhcpClientSettings); //Failed to initialize DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to initialize DHCP client!\r\n"); } //Start DHCP client error = dhcpClientStart(&dhcpClientContext); //Failed to start DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to start DHCP client!\r\n"); } #else //Set IPv4 host address ipv4StringToAddr(APP_IPV4_HOST_ADDR, &ipv4Addr); ipv4SetHostAddr(interface, ipv4Addr); //Set subnet mask ipv4StringToAddr(APP_IPV4_SUBNET_MASK, &ipv4Addr); ipv4SetSubnetMask(interface, ipv4Addr); //Set default gateway ipv4StringToAddr(APP_IPV4_DEFAULT_GATEWAY, &ipv4Addr); ipv4SetDefaultGateway(interface, ipv4Addr); //Set primary and secondary DNS servers ipv4StringToAddr(APP_IPV4_PRIMARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 0, ipv4Addr); ipv4StringToAddr(APP_IPV4_SECONDARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 1, ipv4Addr); #endif #endif #if (IPV6_SUPPORT == ENABLED) #if (APP_USE_SLAAC == ENABLED) //Get default settings slaacGetDefaultSettings(&slaacSettings); //Set the network interface to be configured slaacSettings.interface = interface; //SLAAC initialization error = slaacInit(&slaacContext, &slaacSettings); //Failed to initialize SLAAC? if(error) { //Debug message TRACE_ERROR("Failed to initialize SLAAC!\r\n"); } //Start IPv6 address autoconfiguration process error = slaacStart(&slaacContext); //Failed to start SLAAC process? if(error) { //Debug message TRACE_ERROR("Failed to start SLAAC!\r\n"); } #else //Set link-local address ipv6StringToAddr(APP_IPV6_LINK_LOCAL_ADDR, &ipv6Addr); ipv6SetLinkLocalAddr(interface, &ipv6Addr); //Set IPv6 prefix ipv6StringToAddr(APP_IPV6_PREFIX, &ipv6Addr); ipv6SetPrefix(interface, &ipv6Addr, APP_IPV6_PREFIX_LENGTH); //Set global address ipv6StringToAddr(APP_IPV6_GLOBAL_ADDR, &ipv6Addr); ipv6SetGlobalAddr(interface, &ipv6Addr); //Set router ipv6StringToAddr(APP_IPV6_ROUTER, &ipv6Addr); ipv6SetRouter(interface, &ipv6Addr); //Set primary and secondary DNS servers ipv6StringToAddr(APP_IPV6_PRIMARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 0, &ipv6Addr); ipv6StringToAddr(APP_IPV6_SECONDARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 1, &ipv6Addr); #endif #endif //Create user task task = osCreateTask("User Task", userTask, NULL, 850, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Create a task to blink the LED task = osCreateTask("Blink", blinkTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Start the execution of tasks osStartKernel(); //This function should never return return 0; }
int_t main(void) { error_t error; NetInterface *interface; OsTask *task; MacAddr macAddr; #if (APP_USE_DHCP == DISABLED) Ipv4Addr ipv4Addr; #endif #if (APP_USE_SLAAC == DISABLED) Ipv6Addr ipv6Addr; #endif //Initialize kernel osInitKernel(); //Configure debug UART debugInit(115200); //Start-up message TRACE_INFO("\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("*** CycloneTCP FTP Server Demo ***\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("Copyright: 2010-2015 Oryx Embedded SARL\r\n"); TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__); TRACE_INFO("Target: STM32F407\r\n"); TRACE_INFO("\r\n"); //LED configuration STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); //Clear LEDs STM_EVAL_LEDOff(LED1); STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); //Initialize I/O expander IOE_Config(); //Initialize user button STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); //Initialize LCD display STM324xG_LCD_Init(); LCD_SetBackColor(Blue); LCD_SetTextColor(White); LCD_SetFont(&Font16x24); LCD_Clear(Blue); //Welcome message lcdSetCursor(0, 0); printf("FTP Server Demo\r\n"); //File system initialization error = fsInit(); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize file system!\r\n"); } //TCP/IP stack initialization error = netInit(); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n"); } //Configure the first Ethernet interface interface = &netInterface[0]; //Set interface name netSetInterfaceName(interface, "eth0"); //Set host name netSetHostname(interface, "FTPServerDemo"); //Select the relevant network adapter netSetDriver(interface, &stm32f4x7EthDriver); netSetPhyDriver(interface, &dp83848PhyDriver); //Set external interrupt line driver netSetExtIntDriver(interface, &extIntDriver); //Set host MAC address macStringToAddr(APP_MAC_ADDR, &macAddr); netSetMacAddr(interface, &macAddr); //Initialize network interface error = netConfigInterface(interface); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name); } #if (IPV4_SUPPORT == ENABLED) #if (APP_USE_DHCP == ENABLED) //Get default settings dhcpClientGetDefaultSettings(&dhcpClientSettings); //Set the network interface to be configured by DHCP dhcpClientSettings.interface = interface; //Disable rapid commit option dhcpClientSettings.rapidCommit = FALSE; //DHCP client initialization error = dhcpClientInit(&dhcpClientContext, &dhcpClientSettings); //Failed to initialize DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to initialize DHCP client!\r\n"); } //Start DHCP client error = dhcpClientStart(&dhcpClientContext); //Failed to start DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to start DHCP client!\r\n"); } #else //Set IPv4 host address ipv4StringToAddr(APP_IPV4_HOST_ADDR, &ipv4Addr); ipv4SetHostAddr(interface, ipv4Addr); //Set subnet mask ipv4StringToAddr(APP_IPV4_SUBNET_MASK, &ipv4Addr); ipv4SetSubnetMask(interface, ipv4Addr); //Set default gateway ipv4StringToAddr(APP_IPV4_DEFAULT_GATEWAY, &ipv4Addr); ipv4SetDefaultGateway(interface, ipv4Addr); //Set primary and secondary DNS servers ipv4StringToAddr(APP_IPV4_PRIMARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 0, ipv4Addr); ipv4StringToAddr(APP_IPV4_SECONDARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 1, ipv4Addr); #endif #endif #if (IPV6_SUPPORT == ENABLED) #if (APP_USE_SLAAC == ENABLED) //Get default settings slaacGetDefaultSettings(&slaacSettings); //Set the network interface to be configured slaacSettings.interface = interface; //SLAAC initialization error = slaacInit(&slaacContext, &slaacSettings); //Failed to initialize SLAAC? if(error) { //Debug message TRACE_ERROR("Failed to initialize SLAAC!\r\n"); } //Start IPv6 address autoconfiguration process error = slaacStart(&slaacContext); //Failed to start SLAAC process? if(error) { //Debug message TRACE_ERROR("Failed to start SLAAC!\r\n"); } #else //Set link-local address ipv6StringToAddr(APP_IPV6_LINK_LOCAL_ADDR, &ipv6Addr); ipv6SetLinkLocalAddr(interface, &ipv6Addr); //Set IPv6 prefix ipv6StringToAddr(APP_IPV6_PREFIX, &ipv6Addr); ipv6SetPrefix(interface, &ipv6Addr, APP_IPV6_PREFIX_LENGTH); //Set global address ipv6StringToAddr(APP_IPV6_GLOBAL_ADDR, &ipv6Addr); ipv6SetGlobalAddr(interface, &ipv6Addr); //Set router ipv6StringToAddr(APP_IPV6_ROUTER, &ipv6Addr); ipv6SetRouter(interface, &ipv6Addr); //Set primary and secondary DNS servers ipv6StringToAddr(APP_IPV6_PRIMARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 0, &ipv6Addr); ipv6StringToAddr(APP_IPV6_SECONDARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 1, &ipv6Addr); #endif #endif //Get default settings ftpServerGetDefaultSettings(&ftpServerSettings); //Bind FTP server to the desired interface ftpServerSettings.interface = &netInterface[0]; //Listen to port 21 ftpServerSettings.port = FTP_PORT; //Root directory strcpy(ftpServerSettings.rootDir, "/"); //User verification callback function ftpServerSettings.checkUserCallback = ftpServerCheckUserCallback; //Password verification callback function ftpServerSettings.checkPasswordCallback = ftpServerCheckPasswordCallback; //Callback used to retrieve file permissions ftpServerSettings.getFilePermCallback = ftpServerGetFilePermCallback; //FTP server initialization error = ftpServerInit(&ftpServerContext, &ftpServerSettings); //Failed to initialize FTP server? if(error) { //Debug message TRACE_ERROR("Failed to initialize FTP server!\r\n"); } //Start FTP server error = ftpServerStart(&ftpServerContext); //Failed to start FTP server? if(error) { //Debug message TRACE_ERROR("Failed to start FTP server!\r\n"); } //Create user task task = osCreateTask("User Task", userTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Create a task to blink the LED task = osCreateTask("Blink", blinkTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Start the execution of tasks osStartKernel(); //This function should never return return 0; }
Boolean doInit(PtpClock *ptpClock) { DBG("manufacturerIdentity: %s\n", MANUFACTURER_ID); /* initialize networking */ netShutdown(ptpClock); if(!netInit(ptpClock)) { ERROR("failed to initialize network\n"); toState(PTP_FAULTY, ptpClock); return FALSE; } /* initialize timing, may fail e.g. if timer depends on hardware */ if(!initTime(ptpClock)) { ERROR("failed to initialize timing\n"); toState(PTP_FAULTY, ptpClock); return FALSE; } switch (ptpClock->runTimeOpts.time) { case TIME_SYSTEM: case TIME_SYSTEM_LINUX_HW: case TIME_SYSTEM_LINUX_SW: /* * send time stamp will be returned to socket when available, * either via IP_MULTICAST_LOOP or SIOCSHWTSTAMP + error queue */ ptpClock->delayedTiming = FALSE; break; default: /* ask for time stamp shortly after sending */ ptpClock->delayedTiming = TRUE; break; } /* initialize other stuff */ initData(ptpClock); initTimer(); initClock(ptpClock); m1(ptpClock); msgPackHeader(ptpClock->msgObuf, ptpClock); DBG("sync message interval: %d\n", PTP_SYNC_INTERVAL_TIMEOUT(ptpClock->sync_interval)); DBG("clock identifier: %s\n", ptpClock->clock_identifier); DBG("256*log2(clock variance): %d\n", ptpClock->clock_variance); DBG("clock stratum: %d\n", ptpClock->clock_stratum); DBG("clock preferred?: %s\n", ptpClock->preferred?"yes":"no"); DBG("bound interface name: %s\n", ptpClock->runTimeOpts.ifaceName); DBG("communication technology: %d\n", ptpClock->port_communication_technology); DBG("uuid: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n", ptpClock->port_uuid_field[0], ptpClock->port_uuid_field[1], ptpClock->port_uuid_field[2], ptpClock->port_uuid_field[3], ptpClock->port_uuid_field[4], ptpClock->port_uuid_field[5]); DBG("PTP subdomain name: %s\n", ptpClock->subdomain_name); DBG("subdomain address: %hhx.%hhx.%hhx.%hhx\n", ptpClock->subdomain_address[0], ptpClock->subdomain_address[1], ptpClock->subdomain_address[2], ptpClock->subdomain_address[3]); DBG("event port address: %hhx %hhx\n", ptpClock->event_port_address[0], ptpClock->event_port_address[1]); DBG("general port address: %hhx %hhx\n", ptpClock->general_port_address[0], ptpClock->general_port_address[1]); toState(PTP_LISTENING, ptpClock); return TRUE; }
int_t main(void) { error_t error; NetInterface *interface; OsTask *task; MacAddr macAddr; #if (APP_USE_DHCP == DISABLED) Ipv4Addr ipv4Addr; #endif #if (APP_USE_SLAAC == DISABLED) Ipv6Addr ipv6Addr; #endif //Initialize kernel osInitKernel(); //Configure debug UART debugInit(115200); //Start-up message TRACE_INFO("\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("*** CycloneTCP FTP Client Demo ***\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("Copyright: 2010-2015 Oryx Embedded SARL\r\n"); TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__); TRACE_INFO("Target: RX63N\r\n"); TRACE_INFO("\r\n"); //Configure I/Os ioInit(); //Initialize RSPI channel R_RSPI_Init(RSPI_CHANNEL_0); //Initialize LCD display GlyphOpen(&lcdHandle, 0); GlyphNormalScreen(lcdHandle); GlyphSetFont(lcdHandle, GLYPH_FONT_6_BY_13); //Clear display GlyphClearScreen(lcdHandle); //Welcome message lcdSetCursor(0, 0); printf("FTP Client\r\nDemo\r\n"); //TCP/IP stack initialization error = netInit(); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n"); } //Configure the first Ethernet interface interface = &netInterface[0]; //Set interface name netSetInterfaceName(interface, "eth0"); //Set host name netSetHostname(interface, "FTPClientDemo"); //Select the relevant network adapter netSetDriver(interface, &rx63nEthDriver); netSetPhyDriver(interface, &dp83620PhyDriver); //Set external interrupt line driver netSetExtIntDriver(interface, &extIntDriver); //Set host MAC address macStringToAddr(APP_MAC_ADDR, &macAddr); netSetMacAddr(interface, &macAddr); //Initialize network interface error = netConfigInterface(interface); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name); } #if (IPV4_SUPPORT == ENABLED) #if (APP_USE_DHCP == ENABLED) //Get default settings dhcpClientGetDefaultSettings(&dhcpClientSettings); //Set the network interface to be configured by DHCP dhcpClientSettings.interface = interface; //Disable rapid commit option dhcpClientSettings.rapidCommit = FALSE; //DHCP client initialization error = dhcpClientInit(&dhcpClientContext, &dhcpClientSettings); //Failed to initialize DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to initialize DHCP client!\r\n"); } //Start DHCP client error = dhcpClientStart(&dhcpClientContext); //Failed to start DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to start DHCP client!\r\n"); } #else //Set IPv4 host address ipv4StringToAddr(APP_IPV4_HOST_ADDR, &ipv4Addr); ipv4SetHostAddr(interface, ipv4Addr); //Set subnet mask ipv4StringToAddr(APP_IPV4_SUBNET_MASK, &ipv4Addr); ipv4SetSubnetMask(interface, ipv4Addr); //Set default gateway ipv4StringToAddr(APP_IPV4_DEFAULT_GATEWAY, &ipv4Addr); ipv4SetDefaultGateway(interface, ipv4Addr); //Set primary and secondary DNS servers ipv4StringToAddr(APP_IPV4_PRIMARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 0, ipv4Addr); ipv4StringToAddr(APP_IPV4_SECONDARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 1, ipv4Addr); #endif #endif #if (IPV6_SUPPORT == ENABLED) #if (APP_USE_SLAAC == ENABLED) //Get default settings slaacGetDefaultSettings(&slaacSettings); //Set the network interface to be configured slaacSettings.interface = interface; //SLAAC initialization error = slaacInit(&slaacContext, &slaacSettings); //Failed to initialize SLAAC? if(error) { //Debug message TRACE_ERROR("Failed to initialize SLAAC!\r\n"); } //Start IPv6 address autoconfiguration process error = slaacStart(&slaacContext); //Failed to start SLAAC process? if(error) { //Debug message TRACE_ERROR("Failed to start SLAAC!\r\n"); } #else //Set link-local address ipv6StringToAddr(APP_IPV6_LINK_LOCAL_ADDR, &ipv6Addr); ipv6SetLinkLocalAddr(interface, &ipv6Addr); //Set IPv6 prefix ipv6StringToAddr(APP_IPV6_PREFIX, &ipv6Addr); ipv6SetPrefix(interface, &ipv6Addr, APP_IPV6_PREFIX_LENGTH); //Set global address ipv6StringToAddr(APP_IPV6_GLOBAL_ADDR, &ipv6Addr); ipv6SetGlobalAddr(interface, &ipv6Addr); //Set router ipv6StringToAddr(APP_IPV6_ROUTER, &ipv6Addr); ipv6SetRouter(interface, &ipv6Addr); //Set primary and secondary DNS servers ipv6StringToAddr(APP_IPV6_PRIMARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 0, &ipv6Addr); ipv6StringToAddr(APP_IPV6_SECONDARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 1, &ipv6Addr); #endif #endif //Create user task task = osCreateTask("User Task", userTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Create a task to blink the LED task = osCreateTask("Blink", blinkTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Enable interrupts __enable_interrupt(); //Start the execution of tasks osStartKernel(); //This function should never return return 0; }
/** * Intializes all Xinu data structures and devices. * @return OK if everything is initialized successfully */ static int sysinit(void) { int i; void *userheap; /* pointer to user memory heap */ struct thrent *thrptr; /* thread control block pointer */ device *devptr; /* device entry pointer */ struct sement *semptr; /* semaphore entry pointer */ struct memblock *pmblock; /* memory block pointer */ struct bfpentry *bfpptr; /* Initialize system variables */ /* Count this NULLTHREAD as the first thread in the system. */ thrcount = 1; kprintf("variable i in this function is at 0x%x\r\n", &i); kprintf("this function sysinit is at 0x%x\r\n", &sysinit); kprintf("_start is at 0x%x\r\n", _start); kprintf("_end is at (the end) at 0x%x\r\n", &_end); kprintf("readylist is at 0x%x\r\n", &readylist); kprintf("kputc is at 0x%x\r\n", &kputc); kprintf("NTHREAD is %d\r\n", NTHREAD); kprintf("memheap is 0x%x\r\n", memheap); /* Initialize free memory list */ memheap = roundmb(memheap); platform.maxaddr = truncmb(platform.maxaddr); kprintf("platform.maxaddr is 0x%x\r\n", platform.maxaddr); memlist.next = pmblock = (struct memblock *)memheap; memlist.length = (uint)(platform.maxaddr - memheap); pmblock->next = NULL; pmblock->length = (uint)(platform.maxaddr - memheap); /* Initialize thread table */ for (i = 0; i < NTHREAD; i++) { thrtab[i].state = THRFREE; } kprintf("thrtab is at 0x%x, size %d\r\n", thrtab, sizeof(thrtab)); /* initialize null thread entry */ thrptr = &thrtab[NULLTHREAD]; thrptr->state = THRCURR; thrptr->prio = 0; strncpy(thrptr->name, "prnull", 7); thrptr->stkbase = (void *)&_end; thrptr->stklen = (ulong)memheap - (ulong)&_end; thrptr->stkptr = 0; thrptr->memlist.next = NULL; thrptr->memlist.length = 0; thrcurrent = NULLTHREAD; kprintf("&_end is 0x%x\n", &_end); /* Initialize semaphores */ for (i = 0; i < NSEM; i++) { semptr = &semtab[i]; semptr->state = SFREE; semptr->count = 0; semptr->queue = queinit(); } kprintf("NPOOL is %d\n", NPOOL); /* Initialize buffer pools */ for (i = 0; i < NPOOL; i++) { bfpptr = &bfptab[i]; bfpptr->state = BFPFREE; } kprintf("calling queinit() for readylist\r\n"); /* initialize thread ready list */ readylist = queinit(); #if SB_BUS backplaneInit(NULL); #endif /* SB_BUS */ #if RTCLOCK /* initialize real time clock */ kprintf("Clock being initialized.\r\n" ); clkinit(); #endif /* RTCLOCK */ #ifdef UHEAP_SIZE /* Initialize user memory manager */ userheap = stkget(UHEAP_SIZE); if (SYSERR != (int)userheap) { userheap = (void *)((uint)userheap - UHEAP_SIZE + sizeof(int)); memRegionInit(userheap, UHEAP_SIZE); /* initialize memory protection */ safeInit(); /* initialize kernel page mappings */ safeKmapInit(); } #else userheap = NULL; #endif /* UHEAP_SIZE */ #if USE_TLB /* initialize TLB */ tlbInit(); /* register system call handler */ exceptionVector[EXC_SYS] = syscall_entry; #endif /* USE_TLB */ #if NMAILBOX /* intialize mailboxes */ mailboxInit(); #endif #if NDEVS for (i = 0; i < NDEVS; i++) { if (!isbaddev(i)) { devptr = (device *)&devtab[i]; (devptr->init) (devptr); } } #endif #if 0 #if NVRAM nvramInit(); #endif kprintf("SO MUCH MORE NOT done with sysinit()\r\n"); #if NNETIF netInit(); #endif kprintf("NOT done with sysinit()\r\n"); #if GPIO gpioLEDOn(GPIO_LED_CISCOWHT); #endif #endif kprintf("done with sysinit()\r\n"); return OK; }