int32_t server_prepare_service_register_response(server_p srv, int32_t fd) { uint8_t const *req = srv->req + sizeof(sdp_pdu_t); uint8_t const *req_end = req + ((sdp_pdu_p)(srv->req))->len; uint8_t *rsp = srv->fdidx[fd].rsp; profile_t *profile = NULL; provider_t *provider = NULL; bdaddr_t const *bdaddr = NULL; int32_t uuid; /* * Minimal Service Register Request * * value16 - uuid 2 bytes * bdaddr - BD_ADDR 6 bytes */ if (!srv->fdidx[fd].control || !srv->fdidx[fd].priv || req_end - req < 8) return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); /* Get ServiceClass UUID */ SDP_GET16(uuid, req); /* Get BD_ADDR */ bdaddr = (bdaddr_t const *) req; req += sizeof(*bdaddr); /* Lookup profile descriptror */ profile = profile_get_descriptor(uuid); if (profile == NULL) return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); /* Validate user data */ if (req_end - req < profile->dsize || profile->valid == NULL || (profile->valid)(req, req_end - req) == 0) return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); /* Register provider */ provider = provider_register(profile, bdaddr, fd, req, req_end - req); if (provider == NULL) return (SDP_ERROR_CODE_INSUFFICIENT_RESOURCES); SDP_PUT16(0, rsp); SDP_PUT32(provider->handle, rsp); /* Set reply size */ srv->fdidx[fd].rsp_limit = srv->fdidx[fd].omtu - sizeof(sdp_pdu_t); srv->fdidx[fd].rsp_size = rsp - srv->fdidx[fd].rsp; srv->fdidx[fd].rsp_cs = 0; return (0); }
///////////////////////////////////////////////////////////////////////////// // Main-Funktion ///////////////////////////////////////////////////////////////////////////// int main(int argc, const char *argv[]) { // Initializations // // first some basic hardware infrastructure timer_init(); // Timer Interrupt initialisieren led_init(); provider_init(); // needs to be in the beginning, as other // modules like serial register here term_init(); // does not need endpoint/provider yet // but can take up to a buffer of text #ifdef __AVR__ stdout = &term_stdout; // redirect stdout #else device_setup(argc, argv); #endif // server communication uarthw_init(); // first hardware provider_t *serial = serial_init(); // then logic layer // now prepare for terminal etc // (note: in the future the assign parameter could be used // to distinguish different UARTs for example) void *epdata = serial->prov_assign(NAMEINFO_UNUSED_DRIVE, NULL); term_endpoint.provider = serial; term_endpoint.provdata = epdata; // and set as default provider_set_default(serial, epdata); // debug output via "terminal" term_set_endpoint(&term_endpoint); // init file handling (active open calls) file_init(); // buffer structures buffer_init(); // direct buffer handling direct_init(); // relfile handling relfile_init(); // init main channel handling channel_init(); // before we init any busses, we init the runtime config code // note it gets the provider to register a listener for X command line params rtconfig_init(&term_endpoint); // bus init // first the general bus (with bus counter) bus_init(); // this call initializes the device-specific hardware // e.g. IEEE488 and IEC busses on xs1541, plus SD card on petSD and so on // it also handles the interrupt initialization if necessary device_init(); #ifdef HAS_EEPROM // read bus-independent settings from non volatile memory nv_restore_common_config(); #endif // enable interrupts enable_interrupts(); // sync with the server serial_sync(); // pull in command line config options from server // also send directory charset rtconfig_pullconfig(argc, argv); #ifdef USE_FAT // register fat provider provider_register("FAT", &fat_provider); //provider_assign(0, "FAT", "/"); // might be overwritten when fetching X-commands //provider_assign(1, "FAT", "/"); // from the server, but useful for standalone-mode #endif // show our version... ListVersion(); // ... and some system info term_printf((" %u Bytes free"), BytesFree()); term_printf((", %d kHz"), FreqKHz()); #ifdef __AVR__ fuse_info(); #endif term_putcrlf(); term_putcrlf(); while (1) // Mainloop-Begin { // keep data flowing on the serial line main_delay(); if (!is_locked) device_loop(); // send out log messages term_flush(); } }