/*! * \brief This is a thread function to send the renewal just before the * subscription times out. */ static void GenaAutoRenewSubscription( /*! [in] Thread data(upnp_timeout *) needed to send the renewal. */ IN void *input) { upnp_timeout *event = (upnp_timeout *) input; struct Upnp_Event_Subscribe *sub_struct = (struct Upnp_Event_Subscribe *)event->Event; void *cookie; Upnp_FunPtr callback_fun; struct Handle_Info *handle_info; int send_callback = 0; int eventType = 0; int timeout = 0; int errCode = 0; UpnpString *tmpSID = UpnpString_new(); if (AUTO_RENEW_TIME == 0) { UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, "GENA SUB EXPIRED"); sub_struct->ErrCode = UPNP_E_SUCCESS; send_callback = 1; eventType = UPNP_EVENT_SUBSCRIPTION_EXPIRED; } else { UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, "GENA AUTO RENEW"); timeout = sub_struct->TimeOut; UpnpString_set_String(tmpSID, sub_struct->Sid); errCode = genaRenewSubscription( event->handle, tmpSID, &timeout); sub_struct->ErrCode = errCode; sub_struct->TimeOut = timeout; if (errCode != UPNP_E_SUCCESS && errCode != GENA_E_BAD_SID && errCode != GENA_E_BAD_HANDLE) { send_callback = 1; eventType = UPNP_EVENT_AUTORENEWAL_FAILED; } } if (send_callback) { HandleReadLock(); if( GetHandleInfo( event->handle, &handle_info ) != HND_CLIENT ) { HandleUnlock(); free_upnp_timeout(event); goto end_function; } UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, "HANDLE IS VALID"); /* make callback */ callback_fun = handle_info->Callback; cookie = handle_info->Cookie; HandleUnlock(); callback_fun(eventType, event->Event, cookie); } free_upnp_timeout(event); end_function: UpnpString_delete(tmpSID); return; }
static void BurnProgress(unsigned int nPercent) { callback_fun(1,nPercent, NULL); if(nPercent<100) { sprintf(msg,"b%d ",nPercent); pan_display(LV_pPanDev, msg, 4); } }
/************************************************************************ * Function : GenaAutoRenewSubscription * * Parameters: * IN void *input: Thread data(upnp_timeout *) needed to send the renewal * * Description: * This is a thread function to send the renewal just before the * subscription times out. * * Returns: VOID * ***************************************************************************/ static void GenaAutoRenewSubscription( IN void *input ) { upnp_timeout *event = ( upnp_timeout * ) input; void *cookie; Upnp_FunPtr callback_fun; struct Handle_Info *handle_info; struct Upnp_Event_Subscribe *sub_struct = ( struct Upnp_Event_Subscribe * ) event->Event; int send_callback = 0; int eventType = 0; if( AUTO_RENEW_TIME == 0 ) { DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, "GENA SUB EXPIRED" ) ); sub_struct->ErrCode = UPNP_E_SUCCESS; send_callback = 1; eventType = UPNP_EVENT_SUBSCRIPTION_EXPIRED; } else { DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, "GENA AUTO RENEW" ) ); if( ( ( sub_struct->ErrCode = genaRenewSubscription( event->handle, sub_struct-> Sid, &sub_struct-> TimeOut ) ) != UPNP_E_SUCCESS ) && ( sub_struct->ErrCode != GENA_E_BAD_SID ) && ( sub_struct->ErrCode != GENA_E_BAD_HANDLE ) ) { send_callback = 1; eventType = UPNP_EVENT_AUTORENEWAL_FAILED; } } if( send_callback ) { HandleLock( ); if( GetHandleInfo( event->handle, &handle_info ) != HND_CLIENT ) { HandleUnlock( ); free_upnp_timeout( event ); return; } DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, "HANDLE IS VALID" ) ); callback_fun = handle_info->Callback; cookie = handle_info->Cookie; HandleUnlock( ); //make callback callback_fun( eventType, event->Event, cookie ); } free_upnp_timeout( event ); }
static void UpgradeProgress(unsigned int nPercent) { trans_size += nPercent; INT32 progress = trans_size*100/slave_reorg_size; if(progress > prog) { prog = progress; callback_fun(1,prog,NULL); #if (SYS_CHIP_MODULE != ALI_M3327C || SYS_SDRAM_SIZE != 2) if(prog<100) { sprintf(msg,"u%d ",prog); pan_display(LV_pPanDev, msg, 4); } #endif } // callback_fun(1,nPercent, NULL); }
void gena_process_subscription_request( SOCKINFO *info, http_message_t *request) { UpnpSubscriptionRequest *request_struct = UpnpSubscriptionRequest_new(); Upnp_SID temp_sid; int return_code = 1; int time_out = 1801; service_info *service; subscription *sub; uuid_upnp uid; struct Handle_Info *handle_info; void *cookie; Upnp_FunPtr callback_fun; UpnpDevice_Handle device_handle; memptr nt_hdr; char *event_url_path = NULL; memptr callback_hdr; memptr timeout_hdr; int rc = 0; UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, "Subscription Request Received:\n"); if (httpmsg_find_hdr(request, HDR_NT, &nt_hdr) == NULL) { error_respond(info, HTTP_BAD_REQUEST, request); goto exit_function; } /* check NT header */ /* Windows Millenium Interoperability: */ /* we accept either upnp:event, or upnp:propchange for the NT header */ if (memptr_cmp_nocase(&nt_hdr, "upnp:event") != 0) { error_respond(info, HTTP_PRECONDITION_FAILED, request); goto exit_function; } /* if a SID is present then the we have a bad request "incompatible headers" */ if (httpmsg_find_hdr(request, HDR_SID, NULL) != NULL) { error_respond(info, HTTP_BAD_REQUEST, request); goto exit_function; } /* look up service by eventURL */ event_url_path = str_alloc(request->uri.pathquery.buff, request->uri.pathquery.size); if (event_url_path == NULL) { error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request); goto exit_function; } UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, "SubscriptionRequest for event URL path: %s\n", event_url_path); HandleLock(); if (GetDeviceHandleInfoForPath(event_url_path, info->foreign_sockaddr.ss_family, &device_handle, &handle_info, &service) != HND_DEVICE) { free(event_url_path); error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request); HandleUnlock(); goto exit_function; } free(event_url_path); if (service == NULL || !service->active) { error_respond(info, HTTP_NOT_FOUND, request); HandleUnlock(); goto exit_function; } UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, "Subscription Request: Number of Subscriptions already %d\n " "Max Subscriptions allowed: %d\n", service->TotalSubscriptions, handle_info->MaxSubscriptions); /* too many subscriptions */ if (handle_info->MaxSubscriptions != -1 && service->TotalSubscriptions >= handle_info->MaxSubscriptions) { error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request); HandleUnlock(); goto exit_function; } /* generate new subscription */ sub = (subscription *)malloc(sizeof (subscription)); if (sub == NULL) { error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request); HandleUnlock(); goto exit_function; } sub->ToSendEventKey = 0; sub->active = 0; sub->next = NULL; sub->DeliveryURLs.size = 0; sub->DeliveryURLs.URLs = NULL; sub->DeliveryURLs.parsedURLs = NULL; if (ListInit(&sub->outgoing, 0, free) != 0) { error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request); HandleUnlock(); goto exit_function; } /* check for valid callbacks */ if (httpmsg_find_hdr( request, HDR_CALLBACK, &callback_hdr) == NULL) { error_respond(info, HTTP_PRECONDITION_FAILED, request); freeSubscriptionList(sub); HandleUnlock(); goto exit_function; } return_code = create_url_list(&callback_hdr, &sub->DeliveryURLs); if (return_code == 0) { error_respond(info, HTTP_PRECONDITION_FAILED, request); freeSubscriptionList(sub); HandleUnlock(); goto exit_function; } if (return_code == UPNP_E_OUTOF_MEMORY) { error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request); freeSubscriptionList(sub); HandleUnlock(); goto exit_function; } /* set the timeout */ if (httpmsg_find_hdr(request, HDR_TIMEOUT, &timeout_hdr) != NULL) { if (matchstr(timeout_hdr.buf, timeout_hdr.length, "%iSecond-%d%0", &time_out) == PARSE_OK) { /* nothing */ } else if(memptr_cmp_nocase(&timeout_hdr, "Second-infinite") == 0) { /* infinite timeout */ time_out = -1; } else { /* default is > 1800 seconds */ time_out = DEFAULT_TIMEOUT; } } /* replace infinite timeout with max timeout, if possible */ if (handle_info->MaxSubscriptionTimeOut != -1) { if (time_out == -1 || time_out > handle_info->MaxSubscriptionTimeOut) { time_out = handle_info->MaxSubscriptionTimeOut; } } if (time_out >= 0) { sub->expireTime = time(NULL) + time_out; } else { /* infinite time */ sub->expireTime = 0; } /* generate SID */ uuid_create(&uid); upnp_uuid_unpack(&uid, temp_sid); rc = snprintf(sub->sid, sizeof(sub->sid), "uuid:%s", temp_sid); /* respond OK */ if (rc < 0 || (unsigned int) rc >= sizeof(sub->sid) || (respond_ok(info, time_out, sub, request) != UPNP_E_SUCCESS)) { freeSubscriptionList(sub); HandleUnlock(); goto exit_function; } /* add to subscription list */ sub->next = service->subscriptionList; service->subscriptionList = sub; service->TotalSubscriptions++; /* finally generate callback for init table dump */ UpnpSubscriptionRequest_strcpy_ServiceId(request_struct, service->serviceId); UpnpSubscriptionRequest_strcpy_UDN(request_struct, service->UDN); UpnpSubscriptionRequest_strcpy_SID(request_struct, sub->sid); /* copy callback */ callback_fun = handle_info->Callback; cookie = handle_info->Cookie; HandleUnlock(); /* make call back with request struct */ /* in the future should find a way of mainting that the handle */ /* is not unregistered in the middle of a callback */ callback_fun(UPNP_EVENT_SUBSCRIPTION_REQUEST, request_struct, cookie); exit_function: UpnpSubscriptionRequest_delete(request_struct); }
static BOOL sync_slave(UINT8 mode, UINT32 sync_tmo) { INT32 result, user_int, retry_count = 0; char strTmp[30]; char strTmp1[30]; char strTmp2[30]; char strTmp3[30]; char strTmp4[30]; char strTmp5[30]; if(UPGRADE_MULTI == upgrade_mode) { ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_SLAVES_OK_TO_CONTINUE),strTmp); callback_fun(3, 0,strTmp); } else { ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_SYNCHRONIZING),strTmp); callback_fun(3, 0, strTmp1); } while(1) { sync_twinkle(); result = erom_sync(sync_tmo, mode); if(SUCCESS == result && UPGRADE_MULTI != upgrade_mode) { ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_SYNCHRONIZING_OK),strTmp1); callback_fun(3, 0, strTmp1); break; } else { ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_PLEASE_RESET_TARGET),strTmp2); callback_fun(3, 0,strTmp2); } user_int = get_exit_key(); if(1 == user_int) { ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_UPGRADE_ABORTE),strTmp3); callback_fun(2, 0, strTmp3); return FALSE; } if(UPGRADE_MULTI == upgrade_mode) { if(2 == user_int) break; } else { retry_count++; if(retry_count > MAX_RETRY_NUM*10) { ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_SYNCHRONIZATION_FAILED),strTmp4); callback_fun(2, 0,strTmp4); return FALSE; } if(!(retry_count%10)) { ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_SYNCHRONIZATION_TIMEOUT_RETRY),strTmp5); sprintf(msg, " %d", retry_count/10); strcat(strTmp5,msg); callback_fun(2, 0, strTmp5); } } } // unsigned char data8 = 0x6; // erom_wm(0xB800009B,&data8,1,0); return TRUE; }
UINT32 GetChunk(BYTE *buffer, UINT32 nLen) { UINT8 *p, *pblock; UINT32 chunk_pos; struct sto_device *sto_dev = NULL; UINT8 sVer[16], hVer[16]; INT32 i = 0; char strTmp[30]; #if (defined HDCP_IN_FLASH ||defined DIVX_CERT_ENABLE) INT32 temp_slave_blocks_number=0; CHUNK_HEADER *temp_pslave_list = NULL; #endif switch((unsigned int)buffer[0]) { case 1: case 2: case 7: case 10: slave_Flash_type = 0x80000; //flash size break; case 3: case 4: case 8: case 9: case 11: case 13: slave_Flash_type = 0x100000; break; case 5: case 6: case 12: case 14: case 15: case 16: case 25: case 28: case 30: slave_Flash_type = 0x200000; break; case 17: case 18: case 19: case 33: slave_Flash_type = 0x400000; break; default: slave_Flash_type = 0x200000;/*For unkown flash type,default is 2M*/ //return !SUCCESS; } slave_status = (unsigned int)buffer[1]; if(slave_status==0) slave_blocks_number = (nLen -2)/CHUNK_HEADER_SIZE; else slave_blocks_number = 1; pslave_list= (CHUNK_HEADER *)MALLOC(sizeof(CHUNK_HEADER)*slave_blocks_number); if (pslave_list == NULL) return !SUCCESS; MEMSET((void *)pslave_list,0,sizeof(CHUNK_HEADER)*slave_blocks_number); #if (defined HDCP_IN_FLASH ||defined DIVX_CERT_ENABLE) #ifdef HDCP_IN_FLASH if(m_allcode_include_bootloader==0) #endif { temp_pslave_list= (CHUNK_HEADER *)MALLOC(sizeof(CHUNK_HEADER)*slave_blocks_number); if (temp_pslave_list == NULL) return !SUCCESS; MEMSET((void *)temp_pslave_list,0,sizeof(CHUNK_HEADER)*slave_blocks_number); } #endif pblock = &buffer[2]; for(i=0; i<slave_blocks_number; i++) { p = pblock + CHUNK_ID; pslave_list[i].id = (*p<<24)+(*(p+1)<<16)+(*(p+2)<<8)+(*(p+3)<<0); p = pblock + CHUNK_LENGTH; pslave_list[i].len = (*p<<24)+(*(p+1)<<16)+(*(p+2)<<8)+(*(p+3)<<0); p = pblock + CHUNK_OFFSET; pslave_list[i].offset = (*p<<24)+(*(p+1)<<16)+(*(p+2)<<8)+(*(p+3)<<0); p = pblock + CHUNK_CRC; pslave_list[i].crc = (*p<<24)+(*(p+1)<<16)+(*(p+2)<<8)+(*(p+3)<<0); p = pblock + CHUNK_NAME; STRCPY((char *)pslave_list[i].name, (char *)p); p = pblock + CHUNK_VERSION; STRCPY((char *)pslave_list[i].version, (char *)p); p = pblock + CHUNK_TIME; STRCPY((char *)pslave_list[i].time, (char *)p); #if (defined HDCP_IN_FLASH ||defined DIVX_CERT_ENABLE) #ifdef HDCP_IN_FLASH if(m_allcode_include_bootloader==0) #endif { UINT32 special_type = 0; #ifdef HDCP_IN_FLASH if(pslave_list[i].id == HDCPKEY_CHUNK_ID) { special_type =1; } #endif #ifdef DIVX_CERT_ENABLE if(pslave_list[i].id == DIVX_CHUCK_ID) { special_type =1; } #endif if(special_type!=1) { MEMCPY((temp_pslave_list+temp_slave_blocks_number),(pslave_list+i),sizeof(CHUNK_HEADER)); temp_slave_blocks_number++; } else { if(i > 0) { temp_pslave_list[i-1].offset=(temp_pslave_list[i-1].offset+pslave_list[i].offset); } } } #endif pblock += CHUNK_HEADER_SIZE; } #if (defined HDCP_IN_FLASH ||defined DIVX_CERT_ENABLE) #ifdef HDCP_IN_FLASH if(m_allcode_include_bootloader==0) #endif { FREE(pslave_list); slave_blocks_number=temp_slave_blocks_number; pslave_list = (CHUNK_HEADER *)MALLOC(sizeof(CHUNK_HEADER)*slave_blocks_number); MEMCPY(pslave_list,temp_pslave_list,sizeof(CHUNK_HEADER)*slave_blocks_number); FREE(temp_pslave_list); } #endif STRCPY(sVer, pslave_list[0].version); chunk_pos = sto_chunk_goto(&pblock_list[0].id, 0xFFFFFFFF, 1); sto_dev = (struct sto_device*)dev_get_by_id(HLD_DEV_TYPE_STO, 0); sto_open(sto_dev); sto_lseek(sto_dev, chunk_pos+CHUNK_VERSION, STO_LSEEK_SET); sto_read(sto_dev, hVer, 16); //sto_close(sto_dev); #ifdef FORCE_UPGRADE_OLD_PROTOCOL_BOOTLOADER if(g_protocol_version < NEW_PROTOCOL_VERSION) return SUCCESS; #endif if(CheckVersion(sVer, hVer) != SUCCESS) { ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_STB_VERSION_NOT_COMPATIBLE),strTmp); callback_fun(2,0,strTmp); return !SUCCESS; } }
static BOOL init_slave() { UINT8 *ptr_data_buf, *ptr_temp_buf; UINT32 ptr_zip_pos; UINT8 zero_buf[16]; UINT32 slave_addr; UINT32 total_len, len, chid; int ret; UINT32 i; char strTmp[30]; char strTmp1[30]; ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_INIT_SLAVER),strTmp); callback_fun(2, 0, strTmp); P2PUPG_DBG("init_slave\n"); // init slave sdram for(i=0; i<sizeof(m_SlaveConfig)/sizeof(m_SlaveConfig[0]); i++) { osal_task_sleep(50); // if(0xb8000029 == m_SlaveConfig[i].Address) // { // if(sys_ic_is_M3101()) // m_SlaveConfig[i].Data = *((volatile UINT8 *)m_SlaveConfig[i].Address) & 0x07; // else // m_SlaveConfig[i].Data = *((volatile UINT8 *)m_SlaveConfig[i].Address) & 0x1c; // } erom_wm(m_SlaveConfig[i].Address, &m_SlaveConfig[i].Data, 1, 0); } // set upgrade param init_upgrade_param(); for(i=0; i<sizeof(EROM_UPGRADE_PARAM); i+=sizeof(UINT32)) { if(!send_upgrade_param(i)) { ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_SEND_UPGRADE_PARAM_FAILED),strTmp1); callback_fun(2, 0,strTmp1); return FALSE; } } P2PUPG_DBG("send_upgrade_param OK\n"); unsigned long chunk_id = g_upge_feature_config.chip_flashwr; ptr_zip_pos = (UINT8 *)sto_chunk_goto(&chunk_id, 0xFFFFFFFF, 1); unsigned long zip_size = sto_fetch_long(ptr_zip_pos + CHUNK_LENGTH); ptr_zip_pos += CHUNK_HEADER_SIZE; ptr_data_buf = (UINT8 *)bk_buff; // 48KB for unzip buffer ptr_temp_buf = (UINT8 *)(bk_buff + 0xC000); // 16KB for temp buffer P2PUPG_DBG("ptr_zip_pos = 0x%x\n ptr_data_buf = 0x%x\n ptr_temp_buf = 0x%x\n",ptr_zip_pos,ptr_data_buf,ptr_temp_buf); if(g_upge_feature_config.enable_lzma_out_read == TRUE) ret = un7zip(ptr_zip_pos+SYS_FLASH_BASE_ADDR, zip_size, ptr_temp_buf, 0x4000, ptr_data_buf, 0xC000, NULL); else ret = un7zip(ptr_zip_pos+SYS_FLASH_BASE_ADDR, ptr_data_buf, ptr_temp_buf); P2PUPG_DBG("un7zip ret=%d\n",ret); if(ret) return FALSE; P2PUPG_DBG("un7zip OK"); MEMCPY(&total_len, ptr_temp_buf, sizeof(unsigned int)); P2PUPG_DBG("total_len =%d\n",total_len); uart_high_speed_config(UART_SPEED_NORMAL); // download flashwr erom_download(FLASHWR_RUN_ADDR, ptr_data_buf, total_len); // init slave config buffer P2PUPG_DBG("erom_download1 OK\n"); MEMSET(zero_buf, 0, sizeof(zero_buf)); erom_download(FWCFG_START_ADDR, zero_buf, sizeof(zero_buf)); P2PUPG_DBG("erom_download2 OK\n"); // download config chunk chid = g_upge_feature_config.chip_config; if((chid!=0)&&(chid!=0xFFFFFFFF)) { ptr_data_buf = sto_chunk_goto(&chid, 0xFFFFFFFF, 1); P2PUPG_DBG("ptr_data_buf=0x%x\n",ptr_data_buf); if(ptr_data_buf != NULL) { total_len = sto_fetch_long((unsigned long)(ptr_data_buf+CHUNK_OFFSET)); erom_download(FWCFG_START_ADDR, ptr_data_buf, total_len); } } if(UPGRADE_SINGLE == upgrade_mode) { erom_setpc(FLASHWR_RUN_ADDR); osal_task_sleep(50); sci_mode_set(p2p_uart_id, 115200, SCI_PARITY_EVEN); osal_task_sleep(100); config_uart_speed(UART_DOWNLOAD_SPEED); } return TRUE; }