OSStatus MICOStartBonjourService( WiFi_Interface interface, mico_Context_t * const inContext ) { char temp_txt[500]; char *temp_txt2; OSStatus err; net_para_st para; bonjour_init_t init; memset(&init, 0x0, sizeof(bonjour_init_t)); getNetPara(¶, Station); init.service_name = BONJOUR_SERVICE; /* name#xxxxxx.local. */ snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c.local.", inContext->flashContentInRam.micoSystemConfig.name, inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], \ inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], \ inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] ); init.host_name = (char*)__strdup(temp_txt); /* name#xxxxxx. */ snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c", inContext->flashContentInRam.micoSystemConfig.name, inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], \ inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], \ inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] ); init.instance_name = (char*)__strdup(temp_txt); init.service_port = HA_SERVER_PORT; init.interface = interface; sprintf(temp_txt, "C#=%d.", 0x01); sprintf(temp_txt, "%sff=%d.", temp_txt, 0x10); temp_txt2 = __strdup_trans_dot(inContext->micoStatus.mac); sprintf(temp_txt, "%sid=%s.", temp_txt, temp_txt2); free(temp_txt2); temp_txt2 = __strdup_trans_dot(MODEL); sprintf(temp_txt, "%smd=%s.", temp_txt, temp_txt2); free(temp_txt2); temp_txt2 = __strdup_trans_dot(HA_PV); sprintf(temp_txt, "%spv=%s.", temp_txt, temp_txt2); free(temp_txt2); sprintf(temp_txt, "%ss#=%d.", temp_txt, 0x01); sprintf(temp_txt, "%ssf=%d.", temp_txt, 0x05); temp_txt2 = __strdup_trans_dot(HA_SV); sprintf(temp_txt, "%ssv=%s.", temp_txt, temp_txt2); free(temp_txt2); sprintf(temp_txt, "%sSeed=%u.", temp_txt, inContext->flashContentInRam.micoSystemConfig.seed); init.txt_record = (char*)__strdup(temp_txt); bonjour_service_init(init); free(init.host_name); free(init.instance_name); free(init.txt_record); err = MICOAddNotification( mico_notify_WIFI_STATUS_CHANGED, (void *)BonjourNotify_WifiStatusHandler ); require_noerr( err, exit ); err = MICOAddNotification( mico_notify_SYS_WILL_POWER_OFF, (void *)BonjourNotify_SYSWillPoerOffHandler ); require_noerr( err, exit ); start_bonjour_service(); _bonjourStarted = true; exit: return err; }
OSStatus MICOStartBonjourService( WiFi_Interface interface, mico_Context_t * const inContext ) { char *temp_txt= NULL; char *temp_txt2; OSStatus err; net_para_st para; bonjour_init_t init; temp_txt = malloc(500); require_action(temp_txt, exit, err = kNoMemoryErr); memset(&init, 0x0, sizeof(bonjour_init_t)); micoWlanGetIPStatus(¶, Station); init.service_name = BONJOUR_SERVICE; /* name#xxxxxx.local. */ snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c.local.", inContext->flashContentInRam.micoSystemConfig.name, inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], \ inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], \ inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] ); init.host_name = (char*)__strdup(temp_txt); /* name#xxxxxx. */ snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c", inContext->flashContentInRam.micoSystemConfig.name, inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], \ inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], \ inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] ); init.instance_name = (char*)__strdup(temp_txt); init.service_port = inContext->flashContentInRam.appConfig.localServerPort; init.interface = interface; temp_txt2 = __strdup_trans_dot(inContext->micoStatus.mac); sprintf(temp_txt, "MAC=%s.", temp_txt2); free(temp_txt2); temp_txt2 = __strdup_trans_dot(FIRMWARE_REVISION); sprintf(temp_txt, "%sFirmware Rev=%s.", temp_txt, temp_txt2); free(temp_txt2); temp_txt2 = __strdup_trans_dot(HARDWARE_REVISION); sprintf(temp_txt, "%sHardware Rev=%s.", temp_txt, temp_txt2); free(temp_txt2); temp_txt2 = __strdup_trans_dot(MicoGetVer()); sprintf(temp_txt, "%sMICO OS Rev=%s.", temp_txt, temp_txt2); free(temp_txt2); temp_txt2 = __strdup_trans_dot(MODEL); sprintf(temp_txt, "%sModel=%s.", temp_txt, temp_txt2); free(temp_txt2); temp_txt2 = __strdup_trans_dot(PROTOCOL); sprintf(temp_txt, "%sProtocol=%s.", temp_txt, temp_txt2); free(temp_txt2); temp_txt2 = __strdup_trans_dot(MANUFACTURER); sprintf(temp_txt, "%sManufacturer=%s.", temp_txt, temp_txt2); free(temp_txt2); sprintf(temp_txt, "%sSeed=%u.", temp_txt, inContext->flashContentInRam.micoSystemConfig.seed); init.txt_record = (char*)__strdup(temp_txt); bonjour_service_init(init); free(init.host_name); free(init.instance_name); free(init.txt_record); err = MICOAddNotification( mico_notify_WIFI_STATUS_CHANGED, (void *)BonjourNotify_WifiStatusHandler ); require_noerr( err, exit ); err = MICOAddNotification( mico_notify_SYS_WILL_POWER_OFF, (void *)BonjourNotify_SYSWillPoerOffHandler ); require_noerr( err, exit ); start_bonjour_service(); _bonjourStarted = true; exit: if(temp_txt) free(temp_txt); return err; }
static OSStatus _initBonjourForEasyLink( WiFi_Interface interface, mico_Context_t * const inContext ) { char *temp_txt= NULL; char *temp_txt2; OSStatus err; net_para_st para; bonjour_init_t init; temp_txt = malloc(500); require_action(temp_txt, exit, err = kNoMemoryErr); memset(&init, 0x0, sizeof(bonjour_init_t)); micoWlanGetIPStatus(¶, Station); init.service_name = "_easylink_config._tcp.local."; /* name#xxxxxx.local. */ snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c.local.", inContext->flashContentInRam.micoSystemConfig.name, inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], \ inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], \ inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] ); init.host_name = (char*)__strdup(temp_txt); /* name#xxxxxx. */ snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c", inContext->flashContentInRam.micoSystemConfig.name, inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], \ inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], \ inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] ); init.instance_name = (char*)__strdup(temp_txt); init.service_port = FTC_PORT; init.interface = interface; temp_txt2 = __strdup_trans_dot(inContext->micoStatus.mac); sprintf(temp_txt, "MAC=%s.", temp_txt2); free(temp_txt2); temp_txt2 = __strdup_trans_dot(FIRMWARE_REVISION); sprintf(temp_txt, "%sFirmware Rev=%s.", temp_txt, temp_txt2); free(temp_txt2); temp_txt2 = __strdup_trans_dot(HARDWARE_REVISION); sprintf(temp_txt, "%sHardware Rev=%s.", temp_txt, temp_txt2); free(temp_txt2); temp_txt2 = __strdup_trans_dot(MicoGetVer()); sprintf(temp_txt, "%sMICO OS Rev=%s.", temp_txt, temp_txt2); free(temp_txt2); temp_txt2 = __strdup_trans_dot(MODEL); sprintf(temp_txt, "%sModel=%s.", temp_txt, temp_txt2); free(temp_txt2); temp_txt2 = __strdup_trans_dot(PROTOCOL); sprintf(temp_txt, "%sProtocol=%s.", temp_txt, temp_txt2); free(temp_txt2); temp_txt2 = __strdup_trans_dot(MANUFACTURER); sprintf(temp_txt, "%sManufacturer=%s.", temp_txt, temp_txt2); free(temp_txt2); if(interface == Soft_AP) sprintf(temp_txt, "%swlan unconfigured=T.", temp_txt); else sprintf(temp_txt, "%swlan unconfigured=F.", temp_txt); sprintf(temp_txt, "%sSeed=%u.", temp_txt, inContext->flashContentInRam.micoSystemConfig.seed); init.txt_record = (char*)__strdup(temp_txt); bonjour_service_init(init); free(init.host_name); free(init.instance_name); free(init.txt_record); err = MICOAddNotification( mico_notify_SYS_WILL_POWER_OFF, (void *)_EasyLinkNotify_SYSWillPoerOffHandler ); require_noerr( err, exit ); exit: if(temp_txt) free(temp_txt); return err; }