bool HoRNDIS::start(IOService *provider) { LOG(V_DEBUG, "starting up"); if(!super::start(provider)) return false; if (!fpDevice) { stop(provider); return false; } if (!openInterfaces()) goto bailout; if (!rndisInit()) goto bailout; /* Looks like everything's good... publish the interface! */ if (!createNetworkInterface()) goto bailout; LOG(V_DEBUG, "successful"); return true; bailout: fpDevice->close(this); fpDevice = NULL; stop(provider); return false; }
bool HoRNDIS::start(IOService *provider) { int cfg; int rc; LOG(V_DEBUG, "starting up"); if(!super::start(provider)) return false; fpDevice = OSDynamicCast(IOUSBDevice, provider); if(!fpDevice) { stop(provider); return false; } /* Take control of the device before configuring. */ if (!fpDevice->open(this)) { stop(provider); return false; } /* Initialize and set the appropriate device configuration. */ cfg = probeConfigurations(); if (cfg < 0) goto bailout; rc = fpDevice->SetConfiguration(this, cfg); if (rc != kIOReturnSuccess) { LOG(V_ERROR, "SetConfiguration on RNDIS config failed?"); return false;; } /* Now do the rest of the work to actually bring it up... */ if (!openInterfaces()) goto bailout; if (!rndisInit()) goto bailout; /* Looks like everything's good... publish the interface! */ if (!createNetworkInterface()) goto bailout; LOG(V_DEBUG, "successful"); return true; bailout: fpDevice->close(this); fpDevice = NULL; stop(provider); return false; }
int main(int argc, char *argv[]) { uint16_t eth_hdr_type; int i; SCS = BIT0 | BIT1; /* use fast I/O registers */ VPBDIV = 0x00000001; /* PCLK = CCLK */ PLLCFG = 0x00000024; /* Fosc=12MHz, CCLK=60MHz */ PLLCON = 0x00000001; /* enable the PLL */ PLLFEED = 0x000000AA; /* feed sequence */ PLLFEED = 0x00000055; while (!(PLLSTAT & 0x00000400)); PLLCON = 3; // enable and connect PLLFEED = 0xAA; PLLFEED = 0x55; //busywaitInit(); //systickInit(); //lcdInit(); vicInit(); uart0Init(); DBG("Initializing USB Stack"); usbInit(); rndisInit(); DBG("init 2"); network_device_init(); DBG("init 3"); uip_init(); /* ipaddr_set = 1; uip_ipaddr(ipaddr, 192, 168, 12, 1); uip_ipaddr(dhcpd_client_ipaddr, 192, 168, 12, 2); uip_sethostaddr(ipaddr); */ uip_setethaddr(ethaddr); //uip_setethaddr(eaddr); //telnetd_init(); //net_timers_init(); #ifdef USE_DHCPD dhcpdInit(); #endif DBG("Starting USB Stack"); interruptsEnable(); usbConnect(); //lcdOn(); //lcdClear(); //int xyz = 0; //printf("Frame number %u ",usbFrameNumber()); while(1) { //if (xyz) DBG("is there a packet? bulk ep status = %x",_usbGetEPStatus(RNDIS_BULK_EP | USB_EP_OUT)); uip_len = network_device_read(); //if (xyz) DBG("len=%d",uip_len); if (uip_len > 0) { eth_hdr_type = (uip_buf[0xc] << 8) | uip_buf[0xd]; if(eth_hdr_type == UIP_ETHTYPE_IP) { //DBG("Hey, got an IP packet!!!"); uip_arp_ipin(); uip_input(); if(uip_len > 0) { uip_arp_out(); //DBG("IP Reply! (%d bytes)",uip_len); //int j; //for (j=0; j<uip_len; j++) { // DBG(">%d %02x ",j,uip_buf[j]); //} //DBG(""); network_device_send(); } } else if (eth_hdr_type == UIP_ETHTYPE_ARP) { //DBG("Hey, got an ARP packet!!!"); uip_arp_arpin(); //xyz = 1; if(uip_len > 0) { //DBG("ARP Reply!"); network_device_send(); } } else { DBG("Hey, got some weird packet, not IP, not ARP, type=%x",eth_hdr_type); } } /* * we reply to DHCP requests on another connection, and the connection * is faster if we don't wait for expiration of the timer. * I tried to call uip_udp_periodic_conn(dhcpd_reply_conn) instead of * the loop, but it did not work. */ //if (dhcpd_state != DHCPD_IDLE) { if (udp_poll_request) { udp_poll_request = 0; for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); if(uip_len > 0) { uip_arp_out(); network_device_send(); } } //uip_udp_periodic_conn(dhcpd_reply_conn); } if (net_timers_ip_expired()) { net_timers_ip_reset(); for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); if(uip_len > 0) { uip_arp_out(); network_device_send(); } } #define USE_UDP_PERIODIC #ifdef USE_UDP_PERIODIC for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); if(uip_len > 0) { uip_arp_out(); network_device_send(); } } #endif if(net_timers_arp_expired()) { net_timers_arp_reset(); uip_arp_timer(); } } } return 0; }