/** command "show logging" */ int _dessert_cli_cmd_logging(struct cli_def* cli, char* command, char* argv[], int argc) { pthread_rwlock_rdlock(&_dessert_logrbuf_len_lock); int i = 0; int max = _dessert_logrbuf_len - 1; char* line; if(_dessert_logrbuf_len < 1) { cli_print( cli, "logging to ringbuffer is disabled - use \"logging ringbuffer [int]\" in config-mode first"); pthread_rwlock_unlock(&_dessert_logrbuf_len_lock); return CLI_ERROR; } if(argc == 1) { int max2 = (int) strtol(argv[0], NULL, 10); if(max2 > 0) { max = max2; } } /* where to start and print? */ if(max > _dessert_logrbuf_used) { max = _dessert_logrbuf_used; } i = _dessert_logrbuf_cur - max - 1; if(i < 0) { i += _dessert_logrbuf_len; } while(max > 0) { i++; max--; if(i == _dessert_logrbuf_len) { i = 0; } line = _dessert_logrbuf + (DESSERT_LOGLINE_MAX * i); cli_print(cli, "%s", line); } pthread_rwlock_unlock(&_dessert_logrbuf_len_lock); return CLI_OK; }
int cmd_bpdu_pid (struct cli_def *cli, const char *command, char *argv[], int argc) { struct mops_ext_bpdu * pd = clipkt->p_desc; u_int32_t i; if ( (strcmp(argv[argc-1],"?")==0) || (argc>1) ) { cli_print(cli, "Specify the BPDU port identifier (0..65535)\r"); cli_print(cli, "\n"); return CLI_OK; } if (argc==0) { cli_print(cli, "Missing argument (use ?)\n"); return CLI_OK; } i = (u_int32_t) str2int (argv[0]); if (i>0xffff) { cli_print(cli, "The port identifier must be within 0..65535\n"); return CLI_OK; } pd->port_id = (u_int16_t) i; return CLI_OK; }
static int process_write(snd_pcm_t* hPlay) { // calculate read chunk size to ensure a entire sample point (all channels) // is read size_t iReadChunkSize = sizeof(short) * (size_t)channels; size_t iNumReadChunks = (unsigned int)fragsize / iReadChunkSize; int nread = fread(inputdata, iReadChunkSize, iNumReadChunks, inputfile); nread *= (int)iReadChunkSize; if (nread <= 0) { cli_print("%s: stopping, end of input", __func__); return 1; } if (nread > 0) { int nwritten; // make it a full frag if (nread < fragsize) { memset(inputdata + nread, 0, (size_t)(fragsize - nread)); } nwritten = snd_pcm_plugin_write(hPlay, inputdata, (size_t)fragsize); if (nwritten != fragsize) { cli_print("snd_pcm_plugin_write: %s", snd_strerror(nwritten)); return 1; } } return 0; }
int cmd_config_stormcontrol(struct cli_def *cli, char *command, char *argv[], int argc) { if (argc>0){ if (strcmp(argv[0],"?")==0){ cli_print(cli, " <cr>"); }else{ cli_print(cli, "%% Invalid input detected."); } }else{ if (strcasecmp(command,"no storm-control broadcast")==0) { swconfig.port_config_global.config.storm_control_broadcast_disable=1; swconfig.port_config_global.config.storm_control_broadcast_strict=0; } if (strcasecmp(command,"storm-control broadcast relaxed")==0) { swconfig.port_config_global.config.storm_control_broadcast_disable=0; swconfig.port_config_global.config.storm_control_broadcast_strict=0; } if (strcasecmp(command,"storm-control broadcast strict")==0) { swconfig.port_config_global.config.storm_control_broadcast_disable=0; swconfig.port_config_global.config.storm_control_broadcast_strict=1; } if (strcasecmp(command,"no storm-control multicast")==0) { swconfig.port_config_global.config.storm_control_multicast_strict=0; } if (strcasecmp(command,"storm-control multicast")==0) { swconfig.port_config_global.config.storm_control_multicast_strict=1; } rtl83xx_setreg16(0x0607,swconfig.port_config_global.raw); } return CLI_OK; }
int cli_set_ara_forw_mode(struct cli_def* cli, const char* command, char* argv[], int argc) { if(argc != 1) { cli_print(cli, "usage %s [BEST, WEIGHTED, RANDOM]", command); return CLI_ERROR; } switch(argv[0][0]) { case 'B': ara_forw_mode = ARA_FORW_B; break; case 'W': ara_forw_mode = ARA_FORW_W; break; case 'R': ara_forw_mode = ARA_FORW_R; break; default: cli_print(cli, "invalid forward mode: %s", argv[0]); dessert_err("invalid forward mode: %s", argv[0]); return CLI_ERROR; } dessert_notice("ara_forw_mode set to %s", ara_forw_mode_strings[ara_forw_mode]); return CLI_OK; }
/** * Modify the interval to flush the log file. * The log file is flushed every periode. * * @param argv[0] interval as string, "0" disables flushing */ int _dessert_cli_log_interval(struct cli_def* cli, char* command, char* argv[], int argc) { if(argc != 1) { cli_print(cli, "usage %s INTERVAL\n", command); return CLI_ERROR; } // disable if(_dessert_log_flush_periodic) { dessert_periodic_del(_dessert_log_flush_periodic); _dessert_log_flush_periodic = NULL; } uint8_t i = (uint8_t) strtoul(argv[0], NULL, 10); // enable if(i) { struct timeval interval; interval.tv_sec = i; interval.tv_usec = 0; struct timeval schedule; gettimeofday(&schedule, NULL); TIMEVAL_ADD(&schedule, i, 0); _dessert_log_flush_periodic = dessert_periodic_add(_dessert_flush_log, NULL, &schedule, &interval); cli_print(cli, "log flush interval set to %d seconds\n", i); dessert_notice("log flush interval set to %d seconds", i); } else { cli_print(cli, "log flushing disabled\n"); dessert_notice("log flushing disabled"); } return CLI_OK; }
static void _CLI_PrintCmd(const char *cmdPath,CLI_EXEC_T *cli_cmd) { char *pszStr; //ASSERT(cli_cmd != NULL); assert(cli_cmd != NULL); //UNUSED(cli_cmd); pszStr = cli_cmd->pszCmdStr; if (cli_cmd->pszCmdAbbrStr!=NULL) { pszStr = cli_cmd->pszCmdAbbrStr; } if (strlen(cmdPath)>0) { cli_print("%s.%s",cmdPath,pszStr); } else { cli_print("%s",pszStr); } if (cli_cmd->pszCmdHelpStr!=NULL) { cli_print("\t\t:%s",cli_cmd->pszCmdHelpStr); } cli_print("\n"); }
int cmd_arp_opcode (struct cli_def *cli, const char *command, char *argv[], int argc) { struct mops_ext_arp * pd = clipkt->p_desc; if ( (strncmp(argv[argc-1],"?",1)==0) || (argc!=1) ) { cli_print(cli,"Specify the ARP operation code (0-ffff)\n"); cli_print(cli,"Optional keywords: 'request' (default) or 'response'\n"); } else if (mz_strcmp(argv[0],"request", 3)==0) { cli_print(cli, "Set ARP mode to request\n"); pd->opcode = 1; } else if (mz_strcmp(argv[0],"response", 3)==0) { cli_print(cli, "Set ARP mode to response\n"); pd->opcode = 2; } else { cli_print(cli, "Invalid ARP mode\n"); } return CLI_OK; }
int cli_set_ara_ack_mode(struct cli_def* cli, const char* command, char* argv[], int argc) { if(argc != 1) { cli_print(cli, "usage %s [LINK, PASSIVE, NETWORK, DISABLED]", command); return CLI_ERROR; } switch(argv[0][0]) { case 'L': // TODO implement mode dessert_err("mode not yet implemented"); break; ara_ack_mode = ARA_ACK_LINK; break; case 'P': ara_ack_mode = ARA_ACK_PASSIVE; break; case 'N': ara_ack_mode = ARA_ACK_NETWORK; break; case 'D': ara_ack_mode = ARA_ACK_DISABLED; break; default: cli_print(cli, "invalid acknowledgement mode: %s", argv[0]); dessert_err("invalid acknowledgement mode: %s", argv[0]); return CLI_ERROR; } dessert_notice("ara_ack_mode set to %s", ara_ack_mode_strings[ara_ack_mode]); return CLI_OK; }
int cmd_bpdu_vlan(struct cli_def *cli, const char *command, char *argv[], int argc) { u_int32_t i; if ( (strcmp(argv[argc-1],"?")==0) || (argc>1) ) { cli_print(cli, "Specify the VLAN number for PVST+ messages (0..4095)\n"); cli_print(cli, "\n"); return CLI_OK; } if (argc==0) { cli_print(cli, "Missing argument (use ?)\n"); return CLI_OK; } i = (u_int32_t) str2int(argv[0]); if (i>65535) { cli_print(cli, "VLAN number is definitely too large! (0..65535 at maximum)\n"); return CLI_OK; } if (i>4095) { cli_print(cli, "Warning: Invalid VLAN number (0..4095) - but let's try it...\n"); } mops_create_bpdu_trailer(clipkt, (u_int16_t) i); return CLI_OK; }
int cmd_bpdu_pc (struct cli_def *cli, const char *command, char *argv[], int argc) { struct mops_ext_bpdu * pd = clipkt->p_desc; unsigned long long int i; if ( (strcmp(argv[argc-1],"?")==0) || (argc>1) ) { cli_print(cli, "Specify the BPDU root path cost (0..4294967295)\r"); cli_print(cli, "\n"); return CLI_OK; } if (argc==0) { cli_print(cli, "Missing argument (use ?)\n"); return CLI_OK; } i = str2lint (argv[0]); if (i>0xffffffff) { cli_print(cli, "Range exceeded (0..4294967295)\n"); } else pd->root_pc = (u_int32_t) i; return CLI_OK; }
int cmd_config_qos_wrr_queue_ratio(struct cli_def *cli, char *command, char *argv[], int argc) { if (argc>0){ if (strcmp(argv[0],"?")==0){ int i; for (i=0;i<4;i++){ cli_print(cli, "%s",wrr_ratio_text[i]); } }else{ int i,hit; hit=0; for (i=0;i<4;i++){ if (strcmp(wrr_ratio_text[i],argv[0])==0){ swconfig.qos_config.config.wrr_ratio=i; hit=1; } } if (hit){ rtl83xx_setreg16(0x0400,swconfig.qos_config.raw); }else{ cli_print(cli, "%% Invalid input detected."); } } }else{ cli_print(cli, "%% Please specify ratio"); } return CLI_OK; }
/**************************************************************************** Function : _CliShowHelp Description : Show CLI command table help string *****************************************************************************/ static void _CliShowHelp(const CLI_EXEC_T * prCmdTbl) { UINT32 u4CmdIdx; UINT32 u4Idx; CHAR szBuf[MAX_STR_SIZE]; if (prCmdTbl == NULL) // root command table { cli_print("[Help.]\r\n"); for (u4Idx = CLI_MANDA_CMD_TBL_IDX; u4Idx < _u4CmdTblNum; u4Idx++) { u4CmdIdx = 0; while (_aprCmdTblBuf[u4Idx][u4CmdIdx].pszCmdHelpStr != NULL) //while (_aprCmdTblBuf[u4Idx][u4CmdIdx].ps_cmd_help_str != NULL) { const CLI_EXEC_T* prCmd; prCmd = &_aprCmdTblBuf[u4Idx][u4CmdIdx]; //VERIFY(_FormatHelpString(szBuf, MAX_STR_SIZE, prCmd->pszCmdStr, prCmd->pszCmdAbbrStr, prCmd->pszCmdHelpStr)); _FormatHelpString(szBuf, MAX_STR_SIZE, prCmd->pszCmdStr, prCmd->pszCmdAbbrStr, prCmd->pszCmdHelpStr); //_FormatHelpString(szBuf, MAX_STR_SIZE, prCmd->ps_cmd_str, prCmd->ps_cmd_abbr_str, prCmd->ps_cmd_help_str); if (((prCmd->prCmdNextLevel == NULL) || (prCmd->prCmdNextLevel->pszCmdStr != NULL)) && (prCmd->eAccessRight >= _eCliMode)) { //if (((prCmd->pt_next_level == NULL) || (prCmd->pt_next_level->ps_cmd_str != NULL)) && (prCmd->e_access_right >= _eCliMode)) { cli_print("%s\r\n", szBuf); } u4CmdIdx++; } } } else { cli_print("[Help..]\r\n"); u4CmdIdx = 0; while (prCmdTbl[u4CmdIdx].pszCmdHelpStr != NULL) //while (prCmdTbl[u4CmdIdx].ps_cmd_help_str != NULL) { const CLI_EXEC_T* prCmd; prCmd = &prCmdTbl[u4CmdIdx]; //VERIFY(_FormatHelpString(szBuf, MAX_STR_SIZE, prCmd->pszCmdStr, prCmd->pszCmdAbbrStr, prCmd->pszCmdHelpStr)); _FormatHelpString(szBuf, MAX_STR_SIZE, prCmd->pszCmdStr, prCmd->pszCmdAbbrStr, prCmd->pszCmdHelpStr); //_FormatHelpString(szBuf, MAX_STR_SIZE, prCmd->ps_cmd_str, prCmd->ps_cmd_abbr_str, prCmd->ps_cmd_help_str); if (((prCmd->prCmdNextLevel == NULL) || (prCmd->prCmdNextLevel->pszCmdStr != NULL)) && (prCmd->eAccessRight >= _eCliMode)) { //if (((prCmd->pt_next_level == NULL) || (prCmd->pt_next_level->ps_cmd_str != NULL)) && (prCmd->e_access_right >= _eCliMode)) { cli_print("%s\r\n", szBuf); } u4CmdIdx++; } } }
//***************************************************************************** // execute callback for microrl library // do what you want here, but don't write to argv!!! read only!! int execute (int argc, const char * const * argv){ if (recursive_execute(argc, argv, chibiutils) == -1){ cli_print ("command: '"); cli_print ((char*)argv[0]); cli_print ("' Not found.\n\r"); } return 0; }
int cli_show_prune_routes(struct cli_def* cli, const char* command, char* argv[], int argc) { if(ara_prune_routes) { cli_print(cli, "altervative routes that are more than %04.02lf times longer than the shortest path are not accepted", ara_prune_routes); } else { cli_print(cli, "route pruning is disabled"); } return CLI_OK; }
int cli_show_pant_interval(struct cli_def* cli, const char* command, char* argv[], int argc) { if(ara_pant_interval) { cli_print(cli, "PANT interval is set to %d seconds", ara_pant_interval); } else { cli_print(cli, "PANTs are disabled"); } return CLI_OK; }
int cli_show_ara_print_rt_periodic(struct cli_def* cli, char* command, char* argv[], int argc) { if(ara_print_rt_interval_s) { cli_print(cli, "routing table is printed every %d seconds", ara_print_rt_interval_s); } else { cli_print(cli, "routing table is not printed periodically"); } return CLI_OK; }
int cmd_set(struct cli_def *cli, char *command, char *argv[], int argc) { if (argc < 2) { cli_print(cli, "Specify a variable to set"); return CLI_OK; } cli_print(cli, "Setting \"%s\" to \"%s\"", argv[0], argv[1]); return CLI_OK; }
int conf_tag_mpls (struct cli_def *cli, const char *command, char *argv[], int argc) { if ( (strcmp(argv[argc-1],"?")==0) || (argc>1) ) { cli_print(cli, "Specify one or more MPLS labels (and parameters)\n"); return CLI_OK; } cli_print(cli, "Not supported in this version\n"); return CLI_OK; }
int conf_tag_dot1q (struct cli_def *cli, const char *command, char *argv[], int argc) { if ( (strcmp(argv[argc-1],"?")==0) || (argc>1) ) { cli_print(cli, "Specify one or more 802.1Q (and optionally 802.1P) tags\n"); return CLI_OK; } cli_print(cli, "Not supported in this version\n"); return CLI_OK; }
int cli_show_ara_print_cl_periodic(struct cli_def* cli, const char* command, char* argv[], int argc) { if(ara_print_cl_interval_s) { cli_print(cli, "path classification table is printed every %d seconds", ara_print_cl_interval_s); } else { cli_print(cli, "path classification table is not printed periodically"); } return CLI_OK; }
int cmd_test(struct cli_def *cli, const char *command, char *argv[], int argc) { int i; cli_print(cli, "called %s with \"%s\"", __FUNCTION__, command); cli_print(cli, "%d arguments:", argc); for (i = 0; i < argc; i++) cli_print(cli, " %s", argv[i]); return CLI_OK; }
static void WriteHdr(FILE* fp, int sampleRate, int nChannels, int dataSize) { struct { char riff_id[4]; int32_t wave_len; struct { char fmt_id[8]; char fmt_len[4]; struct { char format_tag[2]; int16_t voices; int32_t rate; int32_t char_per_sec; int16_t block_align; int16_t bits_per_sample; } fmt; struct { char data_id[4]; int32_t data_len; } data; } wave; } riff_hdr = { {'R', 'I', 'F', 'F'}, 0, { {'W', 'A', 'V', 'E', 'f', 'm', 't', ' ' }, {sizeof (riff_hdr.wave.fmt), 0, 0, 0}, {{1, 0 }, 0, 0, 0, 0, 0}, {{'d', 'a', 't', 'a'}, 0}, } }; int a; if (fp) { fseek(fp, (long)0, SEEK_SET); riff_hdr.wave.fmt.voices = ENDIAN_LE16 (nChannels); riff_hdr.wave.fmt.rate = ENDIAN_LE32 (sampleRate); a = sampleRate * nChannels * 2; riff_hdr.wave.fmt.char_per_sec = ENDIAN_LE32 (a); a = nChannels * 2; riff_hdr.wave.fmt.block_align = ENDIAN_LE16 (a); riff_hdr.wave.fmt.bits_per_sample = ENDIAN_LE16 (16); a = dataSize; riff_hdr.wave.data.data_len = ENDIAN_LE32 (a); a = (((unsigned int)dataSize + sizeof(riff_hdr)) - (unsigned int)8); riff_hdr.wave_len = ENDIAN_LE32 (a); if (fwrite(&riff_hdr, (size_t)1, sizeof(riff_hdr), fp) != sizeof(riff_hdr)) { cli_print("Error writing output wave header"); } } else { cli_print("Error! invalid fp"); } }
int cmd_config_hostname(struct cli_def *cli, char *command, char *argv[], int argc) { if (argc==1){ if (strcmp(argv[0],"?")==0){ cli_print(cli, "Set system's network host name"); }else{ cli_set_hostname(cli,argv[0]); } }else{ cli_print(cli, "%% Invalid hostname specification"); } return CLI_OK; }
int cmd_config_end(struct cli_def *cli, char *command, char *argv[], int argc) { if (argc>0){ if (strcmp(argv[0],"?")==0){ cli_print(cli, " <cr>"); }else{ cli_print(cli, "%% Invalid input detected."); } }else{ cli_set_configmode(cli, MODE_EXEC, NULL); } return CLI_OK; }
int cmd_bpdu_fwd (struct cli_def *cli, const char *command, char *argv[], int argc) { struct mops_ext_bpdu * pd = clipkt->p_desc; u_int32_t i; char str[256]; if ( (strcmp(argv[argc-1],"?")==0) || (argc>2) ) { mz_def16("15 seconds", pd->f_delay, str); cli_print(cli, "Specify the forward delay:\n"); cli_print(cli, " - either in seconds (0..256) e. g. '15 sec'\r"); cli_print(cli, " - or as multiples of 1/256 seconds (0..65535)\n"); cli_print(cli, "%s\n", str); cli_print(cli, "\n"); return CLI_OK; } if (argc==0) { cli_print(cli, "Missing argument (use ?)\n"); return CLI_OK; } i = (u_int32_t) str2int (argv[0]); if (argc==1) // absolute { if (i>0xffff) cli_print(cli, "The forward delay must be within 0..65535\n"); else pd->f_delay = (u_int16_t) i; } else if (mz_strcmp(argv[1], "seconds", 1)==0) // in seconds { if (i>256) cli_print(cli, "The forward delay must be within 0..256 seconds\n"); else { if (i==256) i = 0xffff; // since 256*256=65536 which exceeds 0xffff but 65535/256 = 255.996 else i = i * 256; pd->f_delay = (u_int16_t) i; } } else cli_print(cli, "Invalid argument\n"); return CLI_OK; }
int cli_show_ara_ptrail_mode(struct cli_def* cli, const char* command, char* argv[], int argc) { switch(ara_ptrail_mode) { case ARA_PTRAIL_CLASSIC: case ARA_PTRAIL_CUBIC: case ARA_PTRAIL_LINEAR: cli_print(cli, "pheromone trail mode set to %s", ara_ptrail_mode_strings[ara_ptrail_mode]); break; default: cli_print(cli, "an invalid pheromone trail mode is set: %d", ara_ptrail_mode); break; } return CLI_OK; }
// add a delay int sequence_delay (struct cli_def *cli, char *command, char *argv[], int argc) { int ret=0, ret2=0; struct timespec t; char str[128]; if ( (strcmp(argv[argc-1],"?")==0) || (argc<1) || (argc>2)) { cli_print(cli, "Add a delay to the current sequence.\n"); cli_print(cli, "ARGUMENTS: <delay> [hour | min | sec | msec | usec | nsec]\n"); cli_print(cli, "The default unit is milliseconds (i. e. when no unit is given).\n"); return CLI_OK; } switch (argc) { case 1: // only one argument, but may contain an unit (such as '314sec') ret = delay_parse(&t, argv[0], NULL); break; case 2: // user specified two arguments such as '100 msec' ret = delay_parse(&t, argv[0], argv[1]); break; default: cli_print(cli, "Too many arguments! Expected delay value and unit, such as '10 msec'\n"); return CLI_OK; } switch (ret) { case 1: cli_print(cli, "Invalid unit! Use one of {nsec, usec, msec, sec, min, hours}\n"); return CLI_OK; break; case 2: cli_print(cli, "Value too large! Supported range is from 0 to 999999999\n"); return CLI_OK; break; } ret2 = mops_add_delay_to_sequence (cli_seq, &t); if (ret2==-1) { cli_print(cli, "You must add a packet first.\n"); return CLI_OK; } if (ret2==-2) { cli_print(cli, "Cannot add delay (array full).\n"); return CLI_OK; } sprintf(str, "Delay set to %lu sec and %lu nsec", ((struct pseq*) cli_seq->data)->gap[ret2].tv_sec, ((struct pseq*) cli_seq->data)->gap[ret2].tv_nsec); cli_print(cli, "%s\n", str); return CLI_OK; }
int cmd_rtp_extension (struct cli_def *cli, char *command, char *argv[], int argc) { struct mops_ext_rtp * pd = clipkt->p_desc; if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) { cli_print(cli, "Configure an RTP extension header (default: none).\n"); cli_print(cli, "Currently supported RTP extension headers:\n"); cli_print(cli, "none Don't use any extension.\r"); cli_print(cli, "mausezahn Use the new Mausezahn jitter/RTT measurement extension.\r"); cli_print(cli, " (Note that this is incompatible with Mausezahn's direct\r"); cli_print(cli, " mode jitter measurement.)\r"); cli_print(cli, "\n"); return CLI_OK; } if (mz_strcmp(argv[0], "none", 1)==0) { pd->x_type = 0; pd->x = 0; // X bit in header } else if (mz_strcmp(argv[0], "mausezahn", 1)==0) { pd->x_type = 42; pd->x = 1; // X bit in header pd->ssrc = 0xcafefeed; } else { cli_print(cli, "Unknown keyword.\n"); return CLI_OK; } mops_update_rtp (clipkt); // re-build RTP packet (for proper show commands) return CLI_OK; }
int cmd_config_ip_igmp_snooping(struct cli_def *cli, char *command, char *argv[], int argc) { if (argc>0){ if (strcmp(argv[0],"?")==0){ cli_print(cli, " <cr>"); }else{ cli_print(cli, "%% Invalid input detected."); } }else{ if (strcasecmp(command,"ip igmp snooping")==0) swconfig.alt_igmp_snooping.config.en_igmp_snooping=1; if (strcasecmp(command,"no ip igmp snooping")==0) swconfig.alt_igmp_snooping.config.en_igmp_snooping=0; rtl83xx_setreg16(0x0308,swconfig.alt_igmp_snooping.raw); } return CLI_OK; }