static int flash_program(struct flash_device *dev, ulong start_addr, ulong end_addr, u8 *data_addr) { int i; u8 *p = data_addr; if(!param_check(dev, start_addr, end_addr)) return 0; /*we always use 8-bits flash till now, if new flash use 16/24-bits,change here*/ if(dev->type != 8){ dprintf("not support 16/24-bits flash now!\n"); return 0; } end_addr -= dev->vaddr; start_addr -= dev->vaddr; { dprintf("starting program flash ...\n"); dprintf("start addr is %x, end addr is %x\n",start_addr, end_addr); for(i = start_addr; i <= end_addr; i++){ dev->ops->flash_program(dev, i, *p++); while(dev->ops->flash_program_busy(dev, i)){ poll_output(100); udelay(10); } } dprintf("program done!\n"); return 1; } return 0; }
/****************************************************************************** * * * Function: main (jacmdweek) * * * * Purpose: the specified day of the week is compared with the present day * * of the week. Inform the current day of the week If the parameter * * is omitted. * * * * Call format: jacmdweek [P1-P7] * * [P1-P7] : day of the week (Sun,Mon,Tue,Wed,Thu,Fri,Sat) * * * * P1(-h) : displays the command version and usage * * * * Return value: 0: day of the week is a mismatch * * 1: match sunday * * 2: match monday * * 3: match tuesday * * 4: match wednesday * * 5: match thursday * * 6: match friday * * 7: match saturday * * -1: an error occurred * * * * Comments: error will output an error message to standard error * * * ******************************************************************************/ int main(int argc, char **argv) { struct tm *tm; time_t now; int rc, i_wday; /* parameter check */ rc = param_check(argc, argv); if (rc != SUCCEED) { return ABNORMAL; } rc = MISMATCH; time(&now); tm = localtime(&now); i_wday = tm->tm_wday + 1; if (i_wday == i_sun || i_wday == i_mon || i_wday == i_tue || i_wday == i_wed || i_wday == i_thu || i_wday == i_fri || i_wday == i_sat) { rc = i_wday; } return rc; }
void lifDIODevice::high(lifMsg msg) { try { param_check(msg, 1); pins.at(get_vector_position(msg.get_param_at(0)))->high(); } catch (std::exception& e) { throw (e); } }
void lifDIODevice::value(lifMsg msg) { bool pinValue; try { param_check(msg, 1); pinValue = pins.at(get_vector_position(msg.get_param_at(0)))->is_high(); std::cout << pins.at(get_vector_position(msg.get_param_at(0)))->get_pin_name() << " is set to: " << pinValue << "." << std::endl; } catch (std::exception& e) { throw (e); } }
bool param_set(__data enum ParamID param, __pdata param_t value) { // Sanity-check the parameter value first. if (!param_check(param, value)) return false; // some parameters we update immediately switch (param) { case PARAM_TXPOWER: // useful to update power level immediately when range // testing in RSSI mode radio_set_transmit_power(value); value = radio_get_transmit_power(); break; case PARAM_DUTY_CYCLE: // update duty cycle immediately value = constrain(value, 0, 100); duty_cycle = value; break; case PARAM_LBT_RSSI: // update LBT RSSI immediately if (value != 0) { value = constrain(value, 25, 220); } lbt_rssi = value; break; case PARAM_MAVLINK: feature_mavlink_framing = (uint8_t) value; value = feature_mavlink_framing; break; case PARAM_OPPRESEND: feature_opportunistic_resend = value?true:false; value = feature_opportunistic_resend?1:0; break; case PARAM_RTSCTS: feature_rtscts = value?true:false; value = feature_rtscts?1:0; break; default: break; } parameter_values[param].val = value; return true; }
/* Inicializa el tablero de n-doku y lo resuelve */ int main(int argc, char** argv) { /* Revisa que el programa haya sido ejecutado correctamente */ if(!param_check(argc, argv)) return 2; /* Comunicamos el n escogido */ printf("%d\n", n); /* Inicializamos la grilla. Inicialmente todas las celdas estan vacías */ nDoku* doku = n_doku_init_empty(n); /* Comunicamos el estado inicial del problema */ n_doku_print(doku); /* Seteamos el contador en 0 */ undo_count = 0; /* Medimos el tiempo */ clock_t start = clock(); /* Intentamos resolver el n-doku */ if(solve_n_doku(doku)) { double time_used = ((double) (clock() - start)) / CLOCKS_PER_SEC; /* Imprimimos las estadisticas */ fprintf(stderr, "%s ha resuelto ", argv[0]); fprintf(stderr, "%d-doku en %lf segundos,", n, time_used); fprintf(stderr, " volviendo %u veces\n", undo_count); /* Comunicamos el valor de cada celda en el estado solucion */ n_doku_print(doku); /* Comunicamos que terminó el programa. El Watcher entenderá */ printf("-1\n"); /* Liberamos la memoria */ n_doku_destroy(doku); /* El programa terminó satisfactoriamente */ return 0; } else { /* Indicamos que no se pudo resolver */ fprintf(stderr,"%s","No solution exists"); /* Comunicamos que terminó el programa. El Watcher entenderá */ printf("-1\n"); /* Liberamos la memoria */ n_doku_destroy(doku); /* El programa terminó con errores */ return 1; } }
int main(int argc, char **argv) { if( argc < 2 || param_check(argc,argv) < 0 ){ usage(); exit(1); } if( arg_flg_make_torrent ){ if( !arg_announce ){ fprintf(stderr,"please use -u specify a announce url!\n"); exit(1);} if( !arg_save_as ){ fprintf(stderr,"please use -s specify a metainfo file name!\n"); exit(1);} if( BTCONTENT.InitialFromFS(arg_metainfo_file, arg_announce, arg_piece_length) < 0 || BTCONTENT.CreateMetainfoFile(arg_save_as) < 0){ fprintf(stderr,"create metainfo failed.\n"); exit(1); } printf("create metainfo file %s successful.\n", arg_save_as); exit(0); } if( BTCONTENT.InitialFromMI(arg_metainfo_file, arg_save_as) < 0){ fprintf(stderr,"error,initial meta info failed.\n"); exit(1); } if( !arg_flg_exam_only && !arg_flg_check_only){ if(WORLD.Initial_ListenPort() < 0){ fprintf(stderr,"warning,you couldn't accept connection.\n"); }else printf("Listen on: %d\n",cfg_listen_port); Tracker.Initial(); Random_init(); #ifndef __OS2__ signal(SIGPIPE,SIG_IGN); #endif signal(SIGINT,sigint_catch); Downloader(); } exit(0); }
static int flash_erase(struct flash_device *dev, ulong start_addr, ulong end_addr) { if(erase_not_aligned(dev, start_addr)) start_addr = head_erase_align(dev, start_addr); end_addr = tail_erase_align(dev, end_addr); if(!param_check(dev, start_addr, end_addr)) return 0; /*first check whether erase the whole chip*/ if(start_addr == dev->vaddr){ if((end_addr + 1 - start_addr) == ((dev->size << 16))){ dprintf("starting erase chip ... "); dev->ops->flash_erase_chip(dev); while(dev->ops->flash_erase_busy(dev, 0)){ udelay(10); } dprintf("\n"); dprintf("erase done!\n"); return 1; } } /*erase some sectors, one by one*/ { ulong offset = start_addr - dev->vaddr; ulong sector_size = dev->sector_size << 12; printf("start addr is 0x%x, end addr is 0x%x\n",start_addr, end_addr); while(dev->vaddr + offset <= end_addr){ dprintf("erase sector %d ...",(offset >> 12)); dev->ops->flash_erase_sector(dev,offset); while(dev->ops->flash_erase_busy(dev, offset)){ udelay(10); } offset += sector_size; dprintf("\n"); } dprintf("erase done!\n"); return 1; } }
int main(int argc, char **argv) { try { if (argc < 2) { throw argc; } } catch (int) { usage(); exit(1); } char *s; Random_init(); arg_user_agent = new char[MAX_PF_LEN + 1](); // free'd at end param_check() //memmove(arg_user_agent, PEER_PFX, MAX_PF_LEN); strcpy(arg_user_agent, PEER_PFX); cfg_user_agent = new char[strlen(PACKAGE_NAME) + strlen(PACKAGE_VERSION) + 2](); if (!cfg_user_agent) return -1; sprintf(cfg_user_agent, "%s/%s", PACKAGE_NAME, PACKAGE_VERSION); do { s = strchr(cfg_user_agent, ' '); if (s != NULL) *s = '-'; } while (s); if (param_check(argc, argv) < 0) { if (arg_user_agent) delete[] arg_user_agent; return -1; } if (arg_flg_make_torrent) { if (!arg_announce) { CONSOLE.Warning(1, "Please use -u to specify an announce URL!"); return EXIT_FAILURE; } if (!arg_save_as) { CONSOLE.Warning(1, "Please use -s to specify a metainfo file name!"); return EXIT_FAILURE; } if (BTCONTENT.InitialFromFS(arg_metainfo_file, arg_announce, arg_piece_length) < 0 || BTCONTENT.CreateMetainfoFile(arg_save_as) < 0) { CONSOLE.Warning(1, "create metainfo failed."); return EXIT_FAILURE; } CONSOLE.Print("Create metainfo file %s successful.", arg_save_as); return EXIT_SUCCESS; } if (arg_daemon) CONSOLE.Daemonize(); if (!arg_flg_exam_only && (!arg_flg_check_only || arg_flg_force_seed_mode)) if (arg_ctcs) CTCS.Initial(); if (BTCONTENT.InitialFromMI(arg_metainfo_file, arg_save_as) < 0) { CONSOLE.Warning(1, "error, initial meta info failed."); exit(1); } if (!arg_flg_exam_only && (!arg_flg_check_only || arg_flg_force_seed_mode)) { if (WORLD.Initial_ListenPort() < 0) { CONSOLE.Warning(2, "warn, you can't accept connections."); } if (Tracker.Initial() < 0) { CONSOLE.Warning(1, "error, tracker setup failed."); return EXIT_FAILURE; } sig_setup(); // setup signal handling CONSOLE.Interact ("Press 'h' or '?' for help (display/control client options)."); Downloader(); if (cfg_cache_size) BTCONTENT.FlushCache(); } if (!arg_flg_exam_only) BTCONTENT.SaveBitfield(); WORLD.CloseAll(); if (arg_verbose) CONSOLE.cpu(); return EXIT_SUCCESS; }
/***************************************************************************** * 函 数 名 : create_crypto_key * * 功能描述 : 使用输入的数据和HUK,生成密钥。当前支持MD5、和SHA-1算法。 * * 生成密钥的方法: * 把HUK和输入的数据连接起来作为MD5或SHA-1算法的输入,计算其HASH值。 * * 输入参数 : data: 用于生成密钥的数据。 * len: 用于生成密钥的数据长度。(byte) * algorithm: 要使用的密钥生成算法。 * klen: 作为输入参数,存放key的缓冲区的长度。(byte) * * 输出参数 : key: 存放生成的密钥。buffer必须大于16(MD5)/20(SHA-1)字节。 * klen: 作为输出参数,存放生成的密钥的长度。(byte) * * 返 回 值 : BSP_OK: 生成成功。 * BSP_ERROR: 生成失败。 * * 其它说明 : klen为输入/输出参数,传入的klen变量所用内存必须可写回。 * 所以避免直接传入类似sizeof()的函数调用结果。 * *****************************************************************************/ int create_crypto_key_o(char *data, int len, CREATE_CRYPTO_KEY_ALGORITHM algorithm, char *key, int *klen) { char* crypto_data = NULL; UINT8 i=0; if(BSP_OK != param_check(data,len,algorithm,key,klen)) { security_print("ERROR create_crypto_key: param is invalid!\n"); goto ERROR_EXIT; } crypto_data = (char*)malloc(len + HUK_LEN); if(crypto_data == NULL) { security_print("ERROR create_crypto_key: malloc failed!\n"); goto ERROR_EXIT; } memset(crypto_data, 0, len + HUK_LEN); /* Read & Copy HUK.*/ if(BSP_OK != bsp_efuse_read((u32*)crypto_data, EFUSE_GRP_HUK, (HUK_LEN/sizeof(uint32)) )) { /*规避EFUSE写入后需要重启才能读取的问题*/ if(!CheckHukIsValid()) { security_print("ERROR create_crypto_key: efuseRead failed!\n"); goto ERROR_EXIT; } } for(i=0;i<HUK_LEN;i++) { if(0 != *(((UINT8*)crypto_data)+i)) { break; } } if(i>=HUK_LEN) { security_print("ERROR create_crypto_key: read_efuse NULL!\n"); goto ERROR_EXIT; } // Copy user data. memcpy((void*)((UINT32)crypto_data + HUK_LEN), data, len); // Encrypt. switch(algorithm) { /*case CREATE_CRYPTO_KEY_ALGORITHM_MD5:*/ /*case CREATE_CRYPTO_KEY_ALGORITHM_SHA1:*/ case CREATE_CRYPTO_KEY_ALGORITHM_SHA256: if(BSP_OK != crypto_hash(crypto_data, len + HUK_LEN, (CRYPTO_HASH_ALGORITHM)algorithm, key, klen)) { security_print("ERROR create_crypto_key: crypto_hash failed!\n"); goto ERROR_EXIT; } break; default: security_print("ERROR create_crypto_key: unknown algorithm!\n"); goto ERROR_EXIT; } //OK_EXIT: if(crypto_data != NULL) { free(crypto_data); } #ifndef _DRV_LLT_ /*REG_WRITE_32(PWR_SC_PERIPH_CLKDIS0, SOC_CLK_CLOSE_DIS0);*/ #endif return BSP_OK; ERROR_EXIT: if(crypto_data != NULL) { free(crypto_data); } return BSP_ERROR; }