Exemplo n.º 1
0
int main(void) {
   u16 i;
   u08 data[2];
   int j=0;

   init();
   test_motor();
   clear_screen();

   _delay_ms(100);

   data[0] = 0x1; //change to WAKE mode
   send_address(0x2A,0);
   write_register(&data[0], 1);
   _delay_ms(100);
   unlock_bus();
   //send_address(0x2);
   //read_register(&data[1], 1);
   print_num(data[0]);
   //while(1) {}
   while(1) {
      //X
      send_address(0x1,1);
      read_register(&(data[0]), 1);
      print_num(data[0]);
      print_string(" ",1);

      //Y
      send_address(0x3,1);
      read_register(&(data[0]), 1);
      print_num(data[0]);
      print_string(" ", 1);

      //Z
      lcd_cursor(0,1);
      send_address(0x5,1);
      read_register(&(data[0]), 1);
      print_num(data[0]);
      print_string(" ",1);
      print_num(SP);
      _delay_ms(150);
      clear_screen();
   }





/*



   USI_TWI_Master_Initialize();
   i2cMessageBuf[0] = 0x1c << 1; // Odd numbers for read
   i2cMessageBuf[1] = 0x0d; // Register 0 contains version number
   i2cMessageBuf[2] = (0x1c << 1) + 1; // Odd numbers for read
   i2cMessageBuf[3] = 0x00; // Register 0 contains version number
   USI_TWI_Start_Read_Write( i2cMessageBuf, 1 );

   */
   while(get_sw1() == 0) {}

   DDRD |= _BV(IR_PIN);

   led_on(1);
   led_on(0);

   clear_screen();

   while(1) {
      _delay_ms(1500);

      if (j) {
         clear_screen();
         print_string("test",4);
         led_on(1);
         led_off(0);
         //sbi(PORTC,LCD_E_PIN);
         //sbi(PORTC,LCD_RS_PIN);
         //PORTA = 0xff;

         sbi(PORTD,IR_PIN); //turn on IR pin

         sbi(PORTC,SERVO0_PIN); //set servo pins
         sbi(PORTC,SERVO1_PIN);
         sbi(PORTC,SERVO2_PIN);
         sbi(PORTF,SERVO3_PIN);

         //test i2c pins
         //sbi(PORTE,4);
         //sbi(PORTE,5);
         
         //motor test
         sbi(PORTB,MOTOR0_EN_PIN);
         sbi(PORTB,MOTOR1_EN_PIN);
         sbi(PORTD,MOTOR0_DIR0_PIN); 
         sbi(PORTD,MOTOR0_DIR1_PIN);
         sbi(PORTD,MOTOR1_DIR0_PIN);
         sbi(PORTD,MOTOR1_DIR1_PIN);
         j=0;
      } else {
         led_off(1);
         led_on(0);
         clear_screen();
         print_string("program",7);
         j=1;
         //cbi(PORTC,LCD_E_PIN);
         //cbi(PORTC,LCD_RS_PIN);
         //PORTA = 0;

         cbi(PORTD,IR_PIN); //turn off IR pin

         cbi(PORTC,SERVO0_PIN); //clear servo pins
         cbi(PORTC,SERVO1_PIN);
         cbi(PORTC,SERVO2_PIN);
         cbi(PORTF,SERVO3_PIN);
         
         //test i2c pins
         //cbi(PORTE,4);
         //cbi(PORTE,5);
         
         //motor test
         cbi(PORTB,MOTOR0_EN_PIN);
         cbi(PORTB,MOTOR1_EN_PIN);
         cbi(PORTD,MOTOR0_DIR0_PIN); 
         cbi(PORTD,MOTOR0_DIR1_PIN);
         cbi(PORTD,MOTOR1_DIR0_PIN);
         cbi(PORTD,MOTOR1_DIR1_PIN);
      }

   }

   return 0;
}
Exemplo n.º 2
0
int handle_message(int message, YR_RULE* rule, void* data)
{
  TAG* tag;
  IDENTIFIER* identifier;
  YR_STRING* string;
  YR_MATCH* match;
  YR_META* meta;

  char* tag_name;
  size_t tag_length;
  int is_matching;
  int string_found;
  int show = TRUE;

  if (show_specified_tags)
  {
    show = FALSE;
    tag = specified_tags_list;

    while (tag != NULL)
    {
      tag_name = rule->tags;
      tag_length = tag_name != NULL ? strlen(tag_name) : 0;

      while (tag_length > 0)
      {
        if (strcmp(tag_name, tag->identifier) == 0)
        {
          show = TRUE;
          break;
        }

        tag_name += tag_length + 1;
        tag_length = strlen(tag_name);
      }

      tag = tag->next;
    }
  }

  if (show_specified_rules)
  {
    show = FALSE;
    identifier = specified_rules_list;

    while (identifier != NULL)
    {
      if (strcmp(identifier->name, rule->identifier) == 0)
      {
        show = TRUE;
        break;
      }

      identifier = identifier->next;
    }
  }

  is_matching = (message == CALLBACK_MSG_RULE_MATCHING);

  show = show && ((!negate && is_matching) || (negate && !is_matching));

  if (show)
  {
    mutex_lock(&output_mutex);
    printf("%s ", rule->identifier);

    if (show_tags)
    {
      printf("[");

      tag_name = rule->tags;
      tag_length = tag_name != NULL ? strlen(tag_name) : 0;

      while (tag_length > 0)
      {
        printf("%s", tag_name);
        tag_name += tag_length + 1;
        tag_length = strlen(tag_name);

        if (tag_length > 0)
          printf(",");
      }

      printf("] ");
    }

    // Show meta-data.

    if (show_meta)
    {
      meta = rule->metas;

      printf("[");

      while(!META_IS_NULL(meta))
      {
        if (meta->type == META_TYPE_INTEGER)
          printf("%s=%d", meta->identifier, meta->integer);
        else if (meta->type == META_TYPE_BOOLEAN)
          printf("%s=%s", meta->identifier, meta->integer ? "true" : "false");
        else
          printf("%s=\"%s\"", meta->identifier, meta->string);

        meta++;

        if (!META_IS_NULL(meta))
          printf(",");
      }

      printf("] ");
    }

    printf("%s\n", (char*) data);

    // Show matched strings.

    if (show_strings)
    {
      string = rule->strings;

      while (!STRING_IS_NULL(string))
      {
        string_found = STRING_FOUND(string);

        if (string_found)
        {
          match = STRING_MATCHES(string).head;

          while (match != NULL)
          {
            printf("0x%" PRIx64 ":%s: ", match->first_offset, string->identifier);

            if (STRING_IS_HEX(string))
            {
              print_hex_string(match->data, match->length);
            }
            else
            {
              print_string(match->data, match->length);
            }

            match = match->next;
          }
        }

        string++;
      }
    }

    mutex_unlock(&output_mutex);
  }

  if (is_matching)
    count++;

  if (limit != 0 && count >= limit)
    return CALLBACK_ABORT;

  return CALLBACK_CONTINUE;
}
Exemplo n.º 3
0
/*
** list_ppkg_types:
** Print a list of packages.  If package_id is 0, list all packages; otherwise
** list the single package specified.  If successful, return the number of
** items listed; otherwise return -1.
*/ 
int
list_ppkg_types(int package_id)
{
    struct fields {
	int   package_id;
	char  display_value[80 + 1];
    };

    int  success;
    int  ret;
    int  no_items;
    int  item_cnt;
    ABP_PPKG_TYPE  keys = NULL, item = NULL, list = NULL;   

    for (success = 0; !success; success = 1) {
	keys = new_abp_ppkg_type();
	if (keys == NULL) {
	    logprintf(LOG_ERR, "new_abp_ppkg_type() failed\n");
	    break;
	}

	unset_abp_ppkg_type(keys);
	if (package_id > 0) {
	    set_abp_ppkg_type_package_id(keys, package_id);
	}

	ret = list_abp_ppkg_types(g_dbhandle, keys, &list);
	if (ret < 0) {
	    LOG_API_ERROR(g_dbhandle, ret);
	    break;
	}
	no_items = ret;

	printf("\n");
	printf("Product Package Type\n");
	printf("--------------------\n");

	for (item = list, item_cnt = 0;
	     item != NULL;
	     item = next_abp_ppkg_type(item), item_cnt++)
	{
	    struct fields f;
	    char *label;
	
	    label = "package_id:";
	    ret = get_abp_ppkg_type_package_id(item, &f.package_id);
	    print_int(ret, label, f.package_id);

	    label = "display_value:";
	    ret = get_abp_ppkg_type_display_value(item, f.display_value);
	    print_string(ret, label, f.display_value);

	    printf("\n");
	}

	if (item_cnt != no_items) {
	    logprintf(LOG_ERR, "item_cnt != no_items\n");
	    break;
	}
    }

    delete_abp_ppkg_type(keys);
    abp_delete_objects(list);

    return success ? item_cnt : -1;
}
Exemplo n.º 4
0
// draw string in OpenGL at position x, y
void draw_string(GLfloat x, GLfloat y, const char* word)
{
	glColor4f(1.0, 1.0, 1.0, 0.0);
	glRasterPos2f(x, y);
	print_string(font_base, word);
}
Exemplo n.º 5
0
void main(void)
{
  x = 'Q';
  print_int(x);
  print_string("\n");
}
Exemplo n.º 6
0
s32 load_file(u8 **wildcards, u8 *result)
{
  DIR *current_dir;
  struct dirent *current_file;
  struct stat file_info;
  u8 current_dir_name[MAX__PATH];
  u8 current_dir_short[81];
  u32 current_dir_length;
  u32 total_filenames_allocated;
  u32 total_dirnames_allocated;
  u8 **file_list;
  u8 **dir_list;
  u32 num_files;
  u32 num_dirs;
  u8 *file_name;
  u32 file_name_length;
  u32 ext_pos = -1;
  u32 chosen_file, chosen_dir;
  u32 dialog_result = 1;
  s32 return_value = 1;
  u32 current_file_selection;
  u32 current_file_scroll_value;
  u32 current_dir_selection;
  u32 current_dir_scroll_value;
  u32 current_file_in_scroll;
  u32 current_dir_in_scroll;
  u32 current_file_number, current_dir_number;
  u32 current_column = 0;
  u32 repeat;
  u32 i;
  gui_action_type gui_action;

  while(return_value == 1)
  {
    current_file_selection = 0;
    current_file_scroll_value = 0;
    current_dir_selection = 0;
    current_dir_scroll_value = 0;
    current_file_in_scroll = 0;
    current_dir_in_scroll = 0;

    total_filenames_allocated = 32;
    total_dirnames_allocated = 32;
    file_list = (u8 **)malloc(sizeof(u8 *) * 32);
    dir_list = (u8 **)malloc(sizeof(u8 *) * 32);
    memset(file_list, 0, sizeof(u8 *) * 32);
    memset(dir_list, 0, sizeof(u8 *) * 32);

    num_files = 0;
    num_dirs = 0;
    chosen_file = 0;
    chosen_dir = 0;

    getcwd(current_dir_name, MAX__PATH);
    current_dir = opendir(current_dir_name);


    do
    {
      if(current_dir)
        current_file = readdir(current_dir);
      else
        current_file = NULL;

      if(current_file)
      {
        file_name = current_file->d_name;
        file_name_length = strlen(file_name);

        if((stat(file_name, &file_info) >= 0) &&
         ((file_name[0] != '.') || (file_name[1] == '.')))
        {
          if(S_ISDIR(file_info.st_mode))
          {
            dir_list[num_dirs] =
             (u8 *)malloc(file_name_length + 1);
            strcpy(dir_list[num_dirs], file_name);

            num_dirs++;
          }
          else
          {
            // Must match one of the wildcards, also ignore the .
            if(file_name_length >= 4)
            {
              if(file_name[file_name_length - 4] == '.')
                ext_pos = file_name_length - 4;
              else

              if(file_name[file_name_length - 3] == '.')
                ext_pos = file_name_length - 3;

              else
                ext_pos = 0;

              for(i = 0; wildcards[i] != NULL; i++)
              {
                if(!strcasecmp((file_name + ext_pos),
                 wildcards[i]))
                {
                  file_list[num_files] =
                   (u8 *)malloc(file_name_length + 1);

                  strcpy(file_list[num_files], file_name);

                  num_files++;
                  break;
                }
              }
            }
          }
        }

        if(num_files == total_filenames_allocated)
        {
          file_list = (u8 **)realloc(file_list, sizeof(u8 *) *
           total_filenames_allocated * 2);
          memset(file_list + total_filenames_allocated, 0,
           sizeof(u8 *) * total_filenames_allocated);
          total_filenames_allocated *= 2;
        }

        if(num_dirs == total_dirnames_allocated)
        {
          dir_list = (u8 **)realloc(dir_list, sizeof(u8 *) *
           total_dirnames_allocated * 2);
          memset(dir_list + total_dirnames_allocated, 0,
           sizeof(u8 *) * total_dirnames_allocated);
          total_dirnames_allocated *= 2;
        }
      }
    } while(current_file);

    qsort((void *)file_list, num_files, sizeof(u8 *), sort_function);
    qsort((void *)dir_list, num_dirs, sizeof(u8 *), sort_function);

    closedir(current_dir);

    current_dir_length = strlen(current_dir_name);

    if(current_dir_length > 80)
    {
      memcpy(current_dir_short, "...", 3);
      memcpy(current_dir_short + 3,
       current_dir_name + current_dir_length - 77, 77);
      current_dir_short[80] = 0;
    }
    else
    {
      memcpy(current_dir_short, current_dir_name,
       current_dir_length + 1);
    }

    repeat = 1;

    if(num_files == 0)
      current_column = 1;

    clear_screen(COLOR_BG);
    u8 print_buffer[81];

    while(repeat)
    {
      flip_screen();

      print_string(current_dir_short, COLOR_ACTIVE_ITEM, COLOR_BG, 0, 0);
#if defined(ZAURUS) || defined(DINGUX_ON_WIN32)
      print_string("Press Cancel to return to the main menu.",
       COLOR_HELP_TEXT, COLOR_BG, 20, 220);
      for(i = 0, current_file_number = i + current_file_scroll_value;
       i < FILE_LIST_ROWS; i++, current_file_number++)
      {
        if(current_file_number < num_files)
        {
          strncpy(print_buffer,file_list[current_file_number],38);
		  print_buffer[38] = 0;
          if((current_file_number == current_file_selection) &&
           (current_column == 0))
          {
            print_string(print_buffer, COLOR_ACTIVE_ITEM,
             COLOR_BG, FILE_LIST_POSITION, ((i + 1) * 10));
          }
          else
          {
            print_string(print_buffer, COLOR_INACTIVE_ITEM,
             COLOR_BG, FILE_LIST_POSITION, ((i + 1) * 10));
          }
        }
      }

      for(i = 0, current_dir_number = i + current_dir_scroll_value;
       i < FILE_LIST_ROWS; i++, current_dir_number++)
      {
        if(current_dir_number < num_dirs)
        {
          strncpy(print_buffer,dir_list[current_dir_number], 13);
		  print_buffer[14] = 0;
          if((current_dir_number == current_dir_selection) &&
           (current_column == 1))
          {
            print_string(print_buffer, COLOR_ACTIVE_ITEM,
             COLOR_BG, DIR_LIST_POSITION, ((i + 1) * 10));
          }
          else
          {
            print_string(print_buffer, COLOR_INACTIVE_ITEM,
             COLOR_BG, DIR_LIST_POSITION, ((i + 1) * 10));
          }
        }
      }
#else
      print_string("Press X to return to the main menu.",
       COLOR_HELP_TEXT, COLOR_BG, 20, 260);
      for(i = 0, current_file_number = i + current_file_scroll_value;
       i < FILE_LIST_ROWS; i++, current_file_number++)
      {
        if(current_file_number < num_files)
        {
          if((current_file_number == current_file_selection) &&
           (current_column == 0))
          {
            print_string(file_list[current_file_number], COLOR_ACTIVE_ITEM,
             COLOR_BG, FILE_LIST_POSITION, ((i + 1) * 10));
          }
          else
          {
            print_string(file_list[current_file_number], COLOR_INACTIVE_ITEM,
             COLOR_BG, FILE_LIST_POSITION, ((i + 1) * 10));
          }
        }
      }

      for(i = 0, current_dir_number = i + current_dir_scroll_value;
       i < FILE_LIST_ROWS; i++, current_dir_number++)
      {
        if(current_dir_number < num_dirs)
        {
          if((current_dir_number == current_dir_selection) &&
           (current_column == 1))
          {
            print_string(dir_list[current_dir_number], COLOR_ACTIVE_ITEM,
             COLOR_BG, DIR_LIST_POSITION, ((i + 1) * 10));
          }
          else
          {
            print_string(dir_list[current_dir_number], COLOR_INACTIVE_ITEM,
             COLOR_BG, DIR_LIST_POSITION, ((i + 1) * 10));
          }
        }
      }
#endif

      gui_action = get_gui_input();

      switch(gui_action)
      {
        case CURSOR_DOWN:
          if(current_column == 0)
          {
            if(current_file_selection < (num_files - 1))
            {
              current_file_selection++;
              if(current_file_in_scroll == (FILE_LIST_ROWS - 1))
              {
                clear_screen(COLOR_BG);
                current_file_scroll_value++;
              }
              else
              {
                current_file_in_scroll++;
              }
            }
          }
          else
          {
            if(current_dir_selection < (num_dirs - 1))
            {
              current_dir_selection++;
              if(current_dir_in_scroll == (FILE_LIST_ROWS - 1))
              {
                clear_screen(COLOR_BG);
                current_dir_scroll_value++;
              }
              else
              {
                current_dir_in_scroll++;
              }
            }
          }

          break;

        case CURSOR_UP:
          if(current_column == 0)
          {
            if(current_file_selection)
            {
              current_file_selection--;
              if(current_file_in_scroll == 0)
              {
                clear_screen(COLOR_BG);
                current_file_scroll_value--;
              }
              else
              {
                current_file_in_scroll--;
              }
            }
          }
          else
          {
            if(current_dir_selection)
            {
              current_dir_selection--;
              if(current_dir_in_scroll == 0)
              {
                clear_screen(COLOR_BG);
                current_dir_scroll_value--;
              }
              else
              {
                current_dir_in_scroll--;
              }
            }
          }
          break;

        case CURSOR_RIGHT:
          if(current_column == 0)
          {
            if(num_dirs != 0)
              current_column = 1;
          }
          break;

        case CURSOR_LEFT:
          if(current_column == 1)
          {
            if(num_files != 0)
              current_column = 0;
          }
          break;

        case CURSOR_SELECT:
          if(current_column == 1)
          {
            repeat = 0;
            chdir(dir_list[current_dir_selection]);
          }
          else
          {
            if(num_files != 0)
            {
              repeat = 0;
              return_value = 0;
              strcpy(result, file_list[current_file_selection]);
            }
          }
          break;

        case CURSOR_BACK:
#ifdef PSP_BUILD
          if(!strcmp(current_dir_name, "ms0:/PSP"))
            break;
#endif
          repeat = 0;
          chdir("..");
          break;

        case CURSOR_EXIT:
          return_value = -1;
          repeat = 0;
          break;
      }
    }

    for(i = 0; i < num_files; i++)
    {
      free(file_list[i]);
    }
    free(file_list);

    for(i = 0; i < num_dirs; i++)
    {
      free(dir_list[i]);
    }
    free(dir_list);
  }

  clear_screen(COLOR_BG);
  return return_value;
}
Exemplo n.º 7
0
static int __init print_string_init(void)
{
	print_string("The module has been inserted.  Hello world!");
	return 0;
}
Exemplo n.º 8
0
/*
 * プロンプトを表示する
 * */
void  print_prompt(FILE *fp) {
    print_string(PROMPT, fp);
}
Exemplo n.º 9
0
/**********************************************************************
 * Description:
 * 		Prints Formatted strings for STD out. Format specifiers
 * provide what type of data to be printed and the data value is taken
 * from the argument list.
 *
 * Input:
 * 		One or more Formatted string messages to be printed allong with
 * other data values to be printed.
 *
 * Output:
 * 		Number of characters actually printed. -1 if failure.
 *********************************************************************/
int printk(char *fmt, ...)
{
	va_list arg;
	int ret = 0;
	uint32_t val;
	uint64_t val64;

	//Check if valid putc() is registered.
	if (_putc == NULL)
		return -1;

	// Variable argument processing
	va_start(arg, fmt);

	// Till the end of string
	while(*fmt != '\0')
	{
		// Format the data to be printed
		if(*fmt == '%')
		{
			fmt++;
			switch(*fmt)
			{
			case 'd':	// Print the integer
				val = va_arg(arg,int);
				ret += print_int32((int)val);
				break;
			case 'x':	// Print Hex
				val = va_arg(arg, uint32_t);
				ret += print_hex32(val, 1);
				break;
			case 'c':	// Print the char
				val = va_arg(arg, int);
				_putc((char)val);
				ret++;
				break;
			case 'u':	// Print unsigned int
				val = va_arg(arg, uint32_t);
				ret += print_uint32(val);
				break;
			case 's':	// Print the string
				val = va_arg(arg, uint32_t);
				ret += print_string((char*)val);
				break;
			case 'l':	// Long data
				switch(*(++fmt))
				{
				case 'u':
					val64 = va_arg(arg, uint64_t);
					ret += print_uint64(val64);
					break;
				case 'd':
					val64 = va_arg(arg, int64_t);
					ret += print_int64(val64);
					break;
				case 'x':
					val64 = va_arg(arg, uint64_t);
					ret += print_hex64(val64);
					break;
				default:
					val64 = va_arg(arg, int64_t);
					ret += print_int64(val64);
					break;
				}
				break;
			default:
				_putc(*fmt);
				ret++;
				break;
			}
		}
		else
		{
Exemplo n.º 10
0
void Print( const Value* value, std::ostream& result )
{
    // TODO: switch on typeid?

    if( !value )
    {
        return;
    }

    const IntegerValue* integervalue = dynamic_cast<const IntegerValue*>(
        value );
    if( integervalue )
    {
        print_integer( integervalue, result );
        return;
    }

    const DecimalValue* decimalvalue = dynamic_cast<const DecimalValue*>(
        value );
    if( decimalvalue )
    {
        print_decimal( decimalvalue, result );
        return;
    }

    const StringValue* stringvalue = dynamic_cast<const StringValue*>(
        value );
    if( stringvalue )
    {
        print_string( stringvalue, result );
        return;
    }

    const TrueValue* truevalue = dynamic_cast<const TrueValue*>(
        value );
    if( truevalue )
    {
        print_true( truevalue, result );
        return;
    }

    const FalseValue* falsevalue = dynamic_cast<const FalseValue*>(
        value );
    if( falsevalue )
    {
        print_false( falsevalue, result );
        return;
    }

    const NilValue* nilvalue = dynamic_cast<const NilValue*>(
        value );
    if( nilvalue )
    {
        print_nil( nilvalue, result );
        return;
    }

    const CombinationValue* combovalue = dynamic_cast<
        const CombinationValue*>( value );
    if( combovalue )
    {
        print_combination( combovalue, result );
        return;
    }

    const SymbolValue* symbolvalue = dynamic_cast<
        const SymbolValue*>( value );
    if( symbolvalue )
    {
        print_symbol( symbolvalue, result );
        return;
    }

    const NativeFunctionValue* fnvalue = dynamic_cast<
        const NativeFunctionValue*>( value );
    if( fnvalue )
    {
        print_built_in_procedure( fnvalue, result );
        return;
    }

    const CompoundProcedureValue* procvalue = dynamic_cast<
        const CompoundProcedureValue*>( value );
    if( procvalue )
    {
        print_compound_procedure( procvalue, result );
        return;
    }

    const PairValue* pairvalue = dynamic_cast<
        const PairValue*>( value );
    if( pairvalue )
    {
        print_pair( pairvalue, result );
        return;
    }

    result << "<<UNPRINTABLE TYPE " << typeid(value).name() << ">>";
}
Exemplo n.º 11
0
static int vti6_parse_opt(struct link_util *lu, int argc, char **argv,
			  struct nlmsghdr *n)
{
	struct ifinfomsg *ifi = NLMSG_DATA(n);
	struct {
		struct nlmsghdr n;
		struct ifinfomsg i;
	} req = {
		.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)),
		.n.nlmsg_flags = NLM_F_REQUEST,
		.n.nlmsg_type = RTM_GETLINK,
		.i.ifi_family = preferred_family,
		.i.ifi_index = ifi->ifi_index,
	};
	struct nlmsghdr *answer;
	struct rtattr *tb[IFLA_MAX + 1];
	struct rtattr *linkinfo[IFLA_INFO_MAX+1];
	struct rtattr *vtiinfo[IFLA_VTI_MAX + 1];
	__be32 ikey = 0;
	__be32 okey = 0;
	inet_prefix saddr, daddr;
	unsigned int link = 0;
	__u32 fwmark = 0;
	int len;

	inet_prefix_reset(&saddr);
	inet_prefix_reset(&daddr);

	if (!(n->nlmsg_flags & NLM_F_CREATE)) {
		const struct rtattr *rta;

		if (rtnl_talk(&rth, &req.n, &answer) < 0) {
get_failed:
			fprintf(stderr,
				"Failed to get existing tunnel info.\n");
			return -1;
		}

		len = answer->nlmsg_len;
		len -= NLMSG_LENGTH(sizeof(*ifi));
		if (len < 0)
			goto get_failed;

		parse_rtattr(tb, IFLA_MAX, IFLA_RTA(NLMSG_DATA(answer)), len);

		if (!tb[IFLA_LINKINFO])
			goto get_failed;

		parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb[IFLA_LINKINFO]);

		if (!linkinfo[IFLA_INFO_DATA])
			goto get_failed;

		parse_rtattr_nested(vtiinfo, IFLA_VTI_MAX,
				    linkinfo[IFLA_INFO_DATA]);

		rta = vtiinfo[IFLA_VTI_LOCAL];
		if (rta && get_addr_rta(&saddr, rta, AF_INET6))
			goto get_failed;

		rta = vtiinfo[IFLA_VTI_REMOTE];
		if (rta && get_addr_rta(&daddr, rta, AF_INET6))
			goto get_failed;

		if (vtiinfo[IFLA_VTI_IKEY])
			ikey = rta_getattr_u32(vtiinfo[IFLA_VTI_IKEY]);

		if (vtiinfo[IFLA_VTI_OKEY])
			okey = rta_getattr_u32(vtiinfo[IFLA_VTI_OKEY]);

		if (vtiinfo[IFLA_VTI_LINK])
			link = rta_getattr_u8(vtiinfo[IFLA_VTI_LINK]);

		if (vtiinfo[IFLA_VTI_FWMARK])
			fwmark = rta_getattr_u32(vtiinfo[IFLA_VTI_FWMARK]);

		free(answer);
	}

	while (argc > 0) {
		if (!matches(*argv, "key")) {
			NEXT_ARG();
			ikey = okey = tnl_parse_key("key", *argv);
		} else if (!matches(*argv, "ikey")) {
			NEXT_ARG();
			ikey = tnl_parse_key("ikey", *argv);
		} else if (!matches(*argv, "okey")) {
			NEXT_ARG();
			okey = tnl_parse_key("okey", *argv);
		} else if (!matches(*argv, "remote")) {
			NEXT_ARG();
			get_addr(&daddr, *argv, AF_INET6);
		} else if (!matches(*argv, "local")) {
			NEXT_ARG();
			get_addr(&saddr, *argv, AF_INET6);
		} else if (!matches(*argv, "dev")) {
			NEXT_ARG();
			link = ll_name_to_index(*argv);
			if (!link)
				exit(nodev(*argv));
		} else if (strcmp(*argv, "fwmark") == 0) {
			NEXT_ARG();
			if (get_u32(&fwmark, *argv, 0))
				invarg("invalid fwmark\n", *argv);
		} else {
			vti6_print_help(lu, argc, argv, stderr);
			return -1;
		}
		argc--; argv++;
	}

	addattr32(n, 1024, IFLA_VTI_IKEY, ikey);
	addattr32(n, 1024, IFLA_VTI_OKEY, okey);
	if (is_addrtype_inet_not_unspec(&saddr))
		addattr_l(n, 1024, IFLA_VTI_LOCAL, saddr.data, saddr.bytelen);
	if (is_addrtype_inet_not_unspec(&daddr))
		addattr_l(n, 1024, IFLA_VTI_REMOTE, daddr.data, daddr.bytelen);
	addattr32(n, 1024, IFLA_VTI_FWMARK, fwmark);
	if (link)
		addattr32(n, 1024, IFLA_VTI_LINK, link);

	return 0;
}

static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{
	char s2[64];

	if (!tb)
		return;

	tnl_print_endpoint("remote", tb[IFLA_VTI_REMOTE], AF_INET6);
	tnl_print_endpoint("local", tb[IFLA_VTI_LOCAL], AF_INET6);

	if (tb[IFLA_VTI_LINK]) {
		__u32 link = rta_getattr_u32(tb[IFLA_VTI_LINK]);

		if (link) {
			print_string(PRINT_ANY, "link", "dev %s ",
				     ll_index_to_name(link));
		}
	}

	if (tb[IFLA_VTI_IKEY]) {
		struct rtattr *rta = tb[IFLA_VTI_IKEY];
		__u32 key = rta_getattr_u32(rta);

		if (key && inet_ntop(AF_INET, RTA_DATA(rta), s2, sizeof(s2)))
			print_string(PRINT_ANY, "ikey", "ikey %s ", s2);
	}

	if (tb[IFLA_VTI_OKEY]) {
		struct rtattr *rta = tb[IFLA_VTI_OKEY];
		__u32 key = rta_getattr_u32(rta);

		if (key && inet_ntop(AF_INET, RTA_DATA(rta), s2, sizeof(s2)))
			print_string(PRINT_ANY, "okey", "okey %s ", s2);
	}

	if (tb[IFLA_VTI_FWMARK]) {
		__u32 fwmark = rta_getattr_u32(tb[IFLA_VTI_FWMARK]);

		if (fwmark) {
			print_0xhex(PRINT_ANY,
				    "fwmark", "fwmark %#llx ", fwmark);
		}
	}
}
Exemplo n.º 12
0
static int vti_parse_opt(struct link_util *lu, int argc, char **argv,
			 struct nlmsghdr *n)
{
	struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
	struct {
		struct nlmsghdr n;
		struct ifinfomsg i;
		char buf[1024];
	} req = {
		.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)),
		.n.nlmsg_flags = NLM_F_REQUEST,
		.n.nlmsg_type = RTM_GETLINK,
		.i.ifi_family = preferred_family,
		.i.ifi_index = ifi->ifi_index,
	};
	struct rtattr *tb[IFLA_MAX + 1];
	struct rtattr *linkinfo[IFLA_INFO_MAX+1];
	struct rtattr *vtiinfo[IFLA_VTI_MAX + 1];
	unsigned int ikey = 0;
	unsigned int okey = 0;
	unsigned int saddr = 0;
	unsigned int daddr = 0;
	unsigned int link = 0;
	unsigned int fwmark = 0;
	int len;

	if (!(n->nlmsg_flags & NLM_F_CREATE)) {
		if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) {
get_failed:
			fprintf(stderr,
				"Failed to get existing tunnel info.\n");
			return -1;
		}

		len = req.n.nlmsg_len;
		len -= NLMSG_LENGTH(sizeof(*ifi));
		if (len < 0)
			goto get_failed;

		parse_rtattr(tb, IFLA_MAX, IFLA_RTA(&req.i), len);

		if (!tb[IFLA_LINKINFO])
			goto get_failed;

		parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb[IFLA_LINKINFO]);

		if (!linkinfo[IFLA_INFO_DATA])
			goto get_failed;

		parse_rtattr_nested(vtiinfo, IFLA_VTI_MAX,
				    linkinfo[IFLA_INFO_DATA]);

		if (vtiinfo[IFLA_VTI_IKEY])
			ikey = rta_getattr_u32(vtiinfo[IFLA_VTI_IKEY]);

		if (vtiinfo[IFLA_VTI_OKEY])
			okey = rta_getattr_u32(vtiinfo[IFLA_VTI_OKEY]);

		if (vtiinfo[IFLA_VTI_LOCAL])
			saddr = rta_getattr_u32(vtiinfo[IFLA_VTI_LOCAL]);

		if (vtiinfo[IFLA_VTI_REMOTE])
			daddr = rta_getattr_u32(vtiinfo[IFLA_VTI_REMOTE]);

		if (vtiinfo[IFLA_VTI_LINK])
			link = rta_getattr_u8(vtiinfo[IFLA_VTI_LINK]);

		if (vtiinfo[IFLA_VTI_FWMARK])
			fwmark = rta_getattr_u32(vtiinfo[IFLA_VTI_FWMARK]);
	}

	while (argc > 0) {
		if (!matches(*argv, "key")) {
			unsigned int uval;

			NEXT_ARG();
			if (strchr(*argv, '.'))
				uval = get_addr32(*argv);
			else {
				if (get_unsigned(&uval, *argv, 0) < 0) {
					fprintf(stderr,
						"Invalid value for \"key\": \"%s\"; it should be an unsigned integer\n", *argv);
					exit(-1);
				}
				uval = htonl(uval);
			}

			ikey = okey = uval;
		} else if (!matches(*argv, "ikey")) {
			unsigned int uval;

			NEXT_ARG();
			if (strchr(*argv, '.'))
				uval = get_addr32(*argv);
			else {
				if (get_unsigned(&uval, *argv, 0) < 0) {
					fprintf(stderr, "invalid value for \"ikey\": \"%s\"; it should be an unsigned integer\n", *argv);
					exit(-1);
				}
				uval = htonl(uval);
			}
			ikey = uval;
		} else if (!matches(*argv, "okey")) {
			unsigned int uval;

			NEXT_ARG();
			if (strchr(*argv, '.'))
				uval = get_addr32(*argv);
			else {
				if (get_unsigned(&uval, *argv, 0) < 0) {
					fprintf(stderr, "invalid value for \"okey\": \"%s\"; it should be an unsigned integer\n", *argv);
					exit(-1);
				}
				uval = htonl(uval);
			}
			okey = uval;
		} else if (!matches(*argv, "remote")) {
			NEXT_ARG();
			if (!strcmp(*argv, "any")) {
				fprintf(stderr, "invalid value for \"remote\": \"%s\"\n", *argv);
				exit(-1);
			} else {
				daddr = get_addr32(*argv);
			}
		} else if (!matches(*argv, "local")) {
			NEXT_ARG();
			if (!strcmp(*argv, "any")) {
				fprintf(stderr, "invalid value for \"local\": \"%s\"\n", *argv);
				exit(-1);
			} else {
				saddr = get_addr32(*argv);
			}
		} else if (!matches(*argv, "dev")) {
			NEXT_ARG();
			link = if_nametoindex(*argv);
			if (link == 0) {
				fprintf(stderr, "Cannot find device \"%s\"\n",
					*argv);
				exit(-1);
			}
		} else if (strcmp(*argv, "fwmark") == 0) {
			NEXT_ARG();
			if (get_u32(&fwmark, *argv, 0))
				invarg("invalid fwmark\n", *argv);
		} else
			usage();
		argc--; argv++;
	}

	addattr32(n, 1024, IFLA_VTI_IKEY, ikey);
	addattr32(n, 1024, IFLA_VTI_OKEY, okey);
	addattr_l(n, 1024, IFLA_VTI_LOCAL, &saddr, 4);
	addattr_l(n, 1024, IFLA_VTI_REMOTE, &daddr, 4);
	addattr32(n, 1024, IFLA_VTI_FWMARK, fwmark);
	if (link)
		addattr32(n, 1024, IFLA_VTI_LINK, link);

	return 0;
}

static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{
	const char *local = "any";
	const char *remote = "any";
	__u32 key;
	unsigned int link;
	char s2[IFNAMSIZ];

	if (!tb)
		return;

	if (tb[IFLA_VTI_REMOTE]) {
		unsigned int addr = rta_getattr_u32(tb[IFLA_VTI_REMOTE]);

		if (addr)
			remote = format_host(AF_INET, 4, &addr);
	}

	print_string(PRINT_ANY, "remote", "remote %s ", remote);

	if (tb[IFLA_VTI_LOCAL]) {
		unsigned int addr = rta_getattr_u32(tb[IFLA_VTI_LOCAL]);

		if (addr)
			local = format_host(AF_INET, 4, &addr);
	}

	print_string(PRINT_ANY, "local", "local %s ", local);

	if (tb[IFLA_VTI_LINK] &&
	    (link = rta_getattr_u32(tb[IFLA_VTI_LINK]))) {
		const char *n = if_indextoname(link, s2);

		if (n)
			print_string(PRINT_ANY, "link", "dev %s ", n);
		else
			print_uint(PRINT_ANY, "link_index", "dev %u ", link);
	}

	if (tb[IFLA_VTI_IKEY] &&
	    (key = rta_getattr_u32(tb[IFLA_VTI_IKEY])))
		print_0xhex(PRINT_ANY, "ikey", "ikey %#x ", ntohl(key));


	if (tb[IFLA_VTI_OKEY] &&
	    (key = rta_getattr_u32(tb[IFLA_VTI_OKEY])))
		print_0xhex(PRINT_ANY, "okey", "okey %#x ", ntohl(key));

	if (tb[IFLA_VTI_FWMARK]) {
		__u32 fwmark = rta_getattr_u32(tb[IFLA_VTI_FWMARK]);

		if (fwmark) {
			SPRINT_BUF(b1);

			snprintf(b1, sizeof(b1), "0x%x", fwmark);
			print_string(PRINT_ANY, "fwmark", "fwmark %s ", s2);
		}
	}
}

static void vti_print_help(struct link_util *lu, int argc, char **argv,
	FILE *f)
{
	print_usage(f);
}
Exemplo n.º 13
0
void print_fp(float number) {
  char s[10];

  dtostre(number,s,3,0);
  print_string(s);
}
Exemplo n.º 14
0
void print_int(u16 number) {
  u08 test[7];

  print_string((char*)itoa(number,test,10
  ));
}
Exemplo n.º 15
0
/* Render a value to text. */
static char *print_value(cJSON *item, int depth, int fmt, printbuffer *p)
{
    char *out = 0;
    if (!item) return 0;
    if (p)
    {
        switch ((item->type) & 255)
        {
            case cJSON_NULL:
            {
                out = ensure(p, 5);
                if (out) strcpy(out, "null");
                break;
            }
            case cJSON_False:
            {
                out = ensure(p, 6);
                if (out) strcpy(out, "false");
                break;
            }
            case cJSON_True:
            {
                out = ensure(p, 5);
                if (out) strcpy(out, "true");
                break;
            }
            case cJSON_Number:
                out = print_number(item, p);
                break;
            case cJSON_String:
                out = print_string(item, p);
                break;
            case cJSON_Array:
                out = print_array(item, depth, fmt, p);
                break;
            case cJSON_Object:
                out = print_object(item, depth, fmt, p);
                break;
        }
    }
    else
    {
        switch ((item->type) & 255)
        {
            case cJSON_NULL:
                out = cJSON_strdup("null");
                break;
            case cJSON_False:
                out = cJSON_strdup("false");
                break;
            case cJSON_True:
                out = cJSON_strdup("true");
                break;
            case cJSON_Number:
                out = print_number(item, 0);
                break;
            case cJSON_String:
                out = print_string(item, 0);
                break;
            case cJSON_Array:
                out = print_array(item, depth, fmt, 0);
                break;
            case cJSON_Object:
                out = print_object(item, depth, fmt, 0);
                break;
        }
    }
    return out;
}
Exemplo n.º 16
0
static void __exit print_string_exit(void)
{
    print_string("Goodbye world!");
}
Exemplo n.º 17
0
 void submenu_savestate()
 {
   print_string("Savestate options:", COLOR_ACTIVE_ITEM, COLOR_BG, 10, 70);
   menu_change_state();
 }
int main(int argc, char* argv[])
{
    codecs_t *cl;
    FILE *f1;
    FILE *f2;
    int c,d,i;
    int pos;
    int section=-1;
    int nr_codecs;
    int win32=-1;
    int dshow=-1;
    int win32ex=-1;

    /*
     * Take path to codecs.conf from command line, or fall back on
     * etc/codecs.conf
     */
    if (!(nr_codecs = parse_codec_cfg((argc>1)?argv[1]:"etc/codecs.conf")))
        exit(1);
    if (codecs_conf_release < CODEC_CFG_MIN)
        exit(1);

    if (argc > 1) {
        int i, j;
        const char* nm[2];
        codecs_t* cod[2];
        int nr[2];

        nm[0] = "builtin_video_codecs";
        cod[0] = video_codecs;
        nr[0] = nr_vcodecs;

        nm[1] = "builtin_audio_codecs";
        cod[1] = audio_codecs;
        nr[1] = nr_acodecs;

        printf("/* GENERATED FROM %s, DO NOT EDIT! */\n\n",argv[1]);
        printf("#include <stddef.h>\n");
        printf("#include \"codec-cfg.h\"\n\n");
        printf("#define CODEC_CFG_MIN %i\n\n", codecs_conf_release);

        for (i=0; i<2; i++) {
            printf("const codecs_t %s[] = {\n", nm[i]);
            for (j = 0; j < nr[i]; j++) {
                printf("{");

                print_int_array(cod[i][j].fourcc, CODECS_MAX_FOURCC);
                printf(", /* fourcc */\n");

                print_int_array(cod[i][j].fourccmap, CODECS_MAX_FOURCC);
                printf(", /* fourccmap */\n");

                print_int_array(cod[i][j].outfmt, CODECS_MAX_OUTFMT);
                printf(", /* outfmt */\n");

                print_char_array(cod[i][j].outflags, CODECS_MAX_OUTFMT);
                printf(", /* outflags */\n");

                print_int_array(cod[i][j].infmt, CODECS_MAX_INFMT);
                printf(", /* infmt */\n");

                print_char_array(cod[i][j].inflags, CODECS_MAX_INFMT);
                printf(", /* inflags */\n");

                print_string(cod[i][j].name);    printf(", /* name */\n");
                print_string(cod[i][j].info);    printf(", /* info */\n");
                print_string(cod[i][j].comment); printf(", /* comment */\n");
                print_string(cod[i][j].dll);     printf(", /* dll */\n");
                print_string(cod[i][j].drv);     printf(", /* drv */\n");

                printf("{ 0x%08lx, %hu, %hu,",
                       cod[i][j].guid.f1,
                       cod[i][j].guid.f2,
                       cod[i][j].guid.f3);
                print_char_array(cod[i][j].guid.f4, sizeof(cod[i][j].guid.f4));
                printf(" }, /* GUID */\n");
                printf("%hd /* flags */, %hd /* status */, %hd /* cpuflags */ }\n",
                       cod[i][j].flags,
                       cod[i][j].status,
                       cod[i][j].cpuflags);
                if (j < nr[i]) printf(",\n");
            }
            printf("};\n\n");
        }
        exit(0);
    }

    f1=fopen("DOCS/tech/codecs-in.html","rb"); if(!f1) exit(1);
    f2=fopen("DOCS/codecs-status.html","wb"); if(!f2) exit(1);

    while((c=fgetc(f1))>=0){
        if(c!='%'){
            fputc(c,f2);
            continue;
        }
        d=fgetc(f1);
        if(d>='0' && d<='9'){
            // begin section
            section=d-'0';
            //printf("BEGIN %d\n",section);
            if(section>=5){
                // audio
                cl = audio_codecs;
                nr_codecs = nr_acodecs;
                dshow=7;win32=4;
            } else {
                // video
                cl = video_codecs;
                nr_codecs = nr_vcodecs;
                dshow=4;win32=2;win32ex=6;
            }
            pos=ftell(f1);
            for(i=0;i<nr_codecs;i++){
                fseek(f1,pos,SEEK_SET);
                switch(section){
                case 0:
                case 5:
                    if(cl[i].status==CODECS_STATUS_WORKING)
//                if(!(!strcmp(cl[i].drv,"vfw") || !strcmp(cl[i].drv,"dshow") || !strcmp(cl[i].drv,"vfwex") || !strcmp(cl[i].drv,"acm")))
                        parsehtml(f1,f2,&cl[i]);
                    break;
#if 0
                case 1:
                case 6:
                    if(cl[i].status==CODECS_STATUS_WORKING)
                        if((!strcmp(cl[i].drv,"vfw") || !strcmp(cl[i].drv,"dshow") || !strcmp(cl[i].drv,"vfwex") || !strcmp(cl[i].drv,"acm")))
                            parsehtml(f1,f2,&cl[i]);
                    break;
#endif
                case 2:
                case 7:
                    if(cl[i].status==CODECS_STATUS_PROBLEMS)
                        parsehtml(f1,f2,&cl[i]);
                    break;
                case 3:
                case 8:
                    if(cl[i].status==CODECS_STATUS_NOT_WORKING)
                        parsehtml(f1,f2,&cl[i]);
                    break;
                case 4:
                case 9:
                    if(cl[i].status==CODECS_STATUS_UNTESTED)
                        parsehtml(f1,f2,&cl[i]);
                    break;
                default:
                    printf("Warning! unimplemented section: %d\n",section);
                }
            }
            fseek(f1,pos,SEEK_SET);
            skiphtml(f1);

            continue;
        }
        fputc(c,f2);
        fputc(d,f2);
    }

    fclose(f2);
    fclose(f1);
    return 0;
}
Exemplo n.º 19
0
static ssize_t
print_option(char *s, ssize_t len, int type, int dl, const uint8_t *data)
{
	const uint8_t *e, *t;
	uint16_t u16;
	int16_t s16;
	uint32_t u32;
	int32_t s32;
	struct in_addr addr;
	ssize_t bytes = 0;
	ssize_t l;
	char *tmp;

	if (type & RFC3397) {
		l = decode_rfc3397(NULL, 0, dl, data);
		if (l < 1)
			return l;
		tmp = xmalloc(l);
		decode_rfc3397(tmp, l, dl, data);
		l = print_string(s, len, l - 1, (uint8_t *)tmp);
		free(tmp);
		return l;
	}

	if (type & RFC3442)
		return decode_rfc3442(s, len, dl, data);

	if (type & STRING) {
		/* Some DHCP servers return NULL strings */
		if (*data == '\0')
			return 0;
		return print_string(s, len, dl, data);
	}

	if (!s) {
		if (type & UINT8)
			l = 3;
		else if (type & UINT16)
			l = 5;
		else if (type & SINT16)
			l = 6;
		else if (type & UINT32)
			l = 10;
		else if (type & SINT32)
			l = 11;
		else if (type & IPV4)
			l = 16;
		else {
			errno = EINVAL;
			return -1;
		}
		return (l + 1) * dl;
	}

	t = data;
	e = data + dl;
	while (data < e) {
		if (data != t) {
			*s++ = ' ';
			bytes++;
			len--;
		}
		if (type & UINT8) {
			l = snprintf(s, len, "%d", *data);
			data++;
		} else if (type & UINT16) {
			memcpy(&u16, data, sizeof(u16));
			u16 = ntohs(u16);
			l = snprintf(s, len, "%d", u16);
			data += sizeof(u16);
		} else if (type & SINT16) {
			memcpy(&s16, data, sizeof(s16));
			s16 = ntohs(s16);
			l = snprintf(s, len, "%d", s16);
			data += sizeof(s16);
		} else if (type & UINT32) {
			memcpy(&u32, data, sizeof(u32));
			u32 = ntohl(u32);
			l = snprintf(s, len, "%d", u32);
			data += sizeof(u32);
		} else if (type & SINT32) {
			memcpy(&s32, data, sizeof(s32));
			s32 = ntohl(s32);
			l = snprintf(s, len, "%d", s32);
			data += sizeof(s32);
		} else if (type & IPV4) {
			memcpy(&addr.s_addr, data, sizeof(addr.s_addr));
			l = snprintf(s, len, "%s", inet_ntoa(addr));
			data += sizeof(addr.s_addr);
		} else
			l = 0;
		len -= l;
		bytes += l;
		s += l;
	}

	return bytes;
}
Exemplo n.º 20
0
void arp_process(u8* arp_buff, int length)
{
	u32 i = 0;
	u8* ptr = NULL;
	ARP_HDR* arp_buff_ptr = (ARP_HDR*)arp_buff;
	u8 dev_mac_addr[6] = {9, 8, 7, 6, 5, 4};

	u8 src_ip_addr[4] = {192, 168, 1, 20};
	ARP_HDR arp_send_buf;
	u8 host_ip_addr[4];
	u8 host_mac_addr[6];
	
	switch(ADJUST_ENDIAN(arp_buff_ptr->opcode))
	{
//		printf_string("arp_buff_ptr->opcode = 0x%x\n", ADJUST_ENDIAN(arp_buff_ptr->opcode));
		case 1:	/* Arp request packet */
			/* 1. Construct arp ack packet */
			memcpy(arp_send_buf.eth_hdr.d_mac, arp_buff_ptr->src_mac, 6);
			memcpy(arp_send_buf.eth_hdr.s_mac,arp_buff_ptr->dst_mac, 6);
			arp_send_buf.eth_hdr.type = ADJUST_ENDIAN(0x0806);

			arp_send_buf.hw_type = ADJUST_ENDIAN(0x01);
			arp_send_buf.protocol = ADJUST_ENDIAN(0x0800);
			arp_send_buf.hw_len = 6;
			arp_send_buf.protocol_len = 4;
			arp_send_buf.opcode = ADJUST_ENDIAN(0x02);
			
			memcpy(arp_send_buf.src_mac, dev_mac_addr, 6);
			memcpy(arp_send_buf.src_ip_addr, src_ip_addr, 4);
			
			memcpy(arp_send_buf.dst_mac, arp_buff_ptr->src_mac, 6);				
			memcpy(arp_send_buf.dst_ip_addr, arp_buff_ptr->src_ip_addr, 4);		
			
			/* 2. Send request packet*/			
			dm9000_send((u8*)&arp_send_buf, (14 + 28));
			
			break;

		case 2: /* Arp ack packet */
			memcpy(host_ip_addr, (*arp_buff_ptr).src_ip_addr, 4);
			memcpy(host_mac_addr, (*arp_buff_ptr).src_mac, 6);
			
			print_string("\nHost ip = ");
			for(i = 0; i < 4; i++)
			{
				printf_string("%d ", host_ip_addr[i]);
			}
			
			print_string("\nHost mac = ");
			for(i = 0; i < 6; i++)
			{
				printf_string("%C ", host_mac_addr[i]);
			}
			print_string("\n");
			
			break;
			
		default:
			break;
	}
}
Exemplo n.º 21
0
static void __exit print_string_exit(void)
{
	print_string("The module has been removed.  Farewell world!");
}
Exemplo n.º 22
0
int main(void) {
   u16 i;
   u08 data[2];
   int j=0;

   init();
   test_motor();
   clear_screen();

/*   while(1){
      set_position(0,0);
      set_position(1,0);
      set_position(2,0);
      set_position(3,0);
      _delay_ms(1000);

      set_position(0,255);
      set_position(1,255);
      set_position(2,255);
      set_position(3,255);
      _delay_ms(1000);
   }
   */



   _delay_ms(100);

   for (i=0;i<1;i++) {
      led_on(1);
      _delay_ms(100);
      led_off(1);
      _delay_ms(100);
   }

   data[0] = 0x1; //change to WAKE mode
   send_address(0x2A,0);
   write_register(&data[0], 1);
   _delay_ms(100);
   unlock_bus();
   //send_address(0x2);
   //read_register(&data[1], 1);
   print_num(data[0]);
   //while(1) {}
   while(1) {
      //X
      send_address(0x1,1);
      read_register(&(data[0]), 1);
      print_num(data[0]);
      print_string(" ");

      //Y
      send_address(0x3,1);
      read_register(&(data[0]), 1);
      print_num(data[0]);
      print_string(" ");

      //Z
      lcd_cursor(0,1);
      send_address(0x5,1);
      read_register(&(data[0]), 1);
      print_num(data[0]);
      print_string(" ");
      print_num(count);
      count++;
      _delay_ms(50);
      clear_screen();
      OCR2A = 28;

   }

   while(get_sw() == 0) {}

   led_on(1);
   led_on(0);

   clear_screen();

   while(1) {
      _delay_ms(1500);

      if (j) {
         clear_screen();
         print_string("test");
         led_on(1);
         led_off(0);
         //sbi(PORTC,LCD_E_PIN);
         //sbi(PORTC,LCD_RS_PIN);
         //PORTA = 0xff;

         sbi(PORTC,SERVO0_PIN); //set servo pins
         sbi(PORTC,SERVO1_PIN);
         sbi(PORTC,SERVO2_PIN);
         sbi(PORTF,SERVO3_PIN);

         //test i2c pins
         //sbi(PORTE,4);
         //sbi(PORTE,5);
         
         //motor test
         sbi(PORTB,MOTOR0_EN_PIN);
         sbi(PORTB,MOTOR1_EN_PIN);
         sbi(PORTD,MOTOR0_DIR0_PIN); 
         sbi(PORTD,MOTOR0_DIR1_PIN);
         sbi(PORTD,MOTOR1_DIR0_PIN);
         sbi(PORTD,MOTOR1_DIR1_PIN);
         j=0;
      } else {
         led_off(1);
         led_on(0);
         clear_screen();
         print_string("program");
         j=1;
         //cbi(PORTC,LCD_E_PIN);
         //cbi(PORTC,LCD_RS_PIN);
         //PORTA = 0;

         cbi(PORTC,SERVO0_PIN); //clear servo pins
         cbi(PORTC,SERVO1_PIN);
         cbi(PORTC,SERVO2_PIN);
         cbi(PORTF,SERVO3_PIN);
         
         //test i2c pins
         //cbi(PORTE,4);
         //cbi(PORTE,5);
         
         //motor test
         cbi(PORTB,MOTOR0_EN_PIN);
         cbi(PORTB,MOTOR1_EN_PIN);
         cbi(PORTD,MOTOR0_DIR0_PIN); 
         cbi(PORTD,MOTOR0_DIR1_PIN);
         cbi(PORTD,MOTOR1_DIR0_PIN);
         cbi(PORTD,MOTOR1_DIR1_PIN);
      }

   }

   return 0;
}
Exemplo n.º 23
0
static inline void
print_string_or_number(const char *str)
{
	is_number(str) ? print_number(str) : print_string(str);
}
Exemplo n.º 24
0
void initIgnTable()
{
	// Initialize load vector
	LOAD[0] = 25;LOAD[1] = 46;LOAD[2] = 66;LOAD[3] = 87;LOAD[4] = 108;LOAD[5] = 128;LOAD[6] = 149;LOAD[7] = 170;

	// NEW ignition table 25.4.16 , NEED TO divide degrees with 10, store 8.0° as 80°, int instead of float
	IGN[7][0] = 20; IGN[7][1] = 100; IGN[7][2] = 285; IGN[7][3] = 329; IGN[7][4] = 370; IGN[7][5] = 370; IGN[7][6] = 370; IGN[7][7] = 370;
	IGN[6][0] = 20; IGN[6][1] = 100; IGN[6][2] = 270; IGN[6][3] = 312; IGN[6][4] = 370; IGN[6][5] = 370; IGN[6][6] = 370; IGN[6][7] = 370;
	IGN[5][0] = 20; IGN[5][1] = 100; IGN[5][2] = 256; IGN[5][3] = 296; IGN[5][4] = 370; IGN[5][5] = 370; IGN[5][6] = 370; IGN[5][7] = 370;
	IGN[4][0] = 20; IGN[4][1] = 100; IGN[4][2] = 242; IGN[4][3] = 279; IGN[4][4] = 279; IGN[4][5] = 279; IGN[4][6] = 279; IGN[4][7] = 279;
	IGN[3][0] = 20; IGN[3][1] = 200; IGN[3][2] = 227; IGN[3][3] = 262; IGN[3][4] = 262; IGN[3][5] = 262; IGN[3][6] = 262; IGN[3][7] = 262;
	IGN[2][0] = 20; IGN[2][1] = 200; IGN[2][2] = 213; IGN[2][3] = 246; IGN[2][4] = 246; IGN[2][5] = 246; IGN[2][6] = 246; IGN[2][7] = 246;
	IGN[1][0] = 20; IGN[1][1] = 200; IGN[1][2] = 198; IGN[1][3] = 229; IGN[1][4] = 229; IGN[1][5] = 229; IGN[1][6] = 229; IGN[1][7] = 229;
	IGN[0][0] = 20;  IGN[0][1] = 200; IGN[0][2] = 184; IGN[0][3] = 212; IGN[0][4] = 212; IGN[0][5] = 212; IGN[0][6] = 212; IGN[0][7] = 212;

	DWELL[0] = 40; DWELL[1] = 40; DWELL[2] = 40; DWELL[3] = 40; DWELL[4] = 40; DWELL[5] = 40; DWELL[6] = 40; DWELL[7] = 40;

	// New ignition RPM vector
	// Initialize RPM vector
	uint8_t temp_rpm[MAX_RPM_TABLE_LENGTH] = {15, 16, 27, 37, 48, 59, 70, 91}; // temporary rpm vector, expressed in RPM / 100
	for (uint8_t i = 0; i < MAX_RPM_TABLE_LENGTH; i++){
		RPM_IGN_C[i] = 600000 / ((long)temp_rpm[i] * TIMER1_US_CONST);
		print_string("IGN_RPM"); print_int(temp_rpm[i]);
		print_string("LOAD"); print_int(LOAD[i]);
		print_string("DWELL"); print_int(DWELL[i]);
		for (uint8_t j = 0; j < MAX_LOAD_TABLE_LENGTH; j++){
			print_string("IGN"); print_int(IGN[i][j]);
		}
		print_string("IGN_Done"); new_line();
	}

	/* kPa
		 * 101
		 * 90
		 * 80
		 * 68
		 * 58
		 * 46
		 * 36
		 * 25
		 *///1500, 1600, 2700, 3700, 4800, 5900, 7000, 9100 RPM


	/*table.RPMLength = MAINTABLE_MAX_RPM_LENGTH;
	table.LoadLength = MAINTABLE_MAX_LOAD_LENGTH;

	unsigned int temp_rpm_ign[MAINTABLE_MAX_RPM_LENGTH] =
			{ 500,700,1100,1500,1900,2300,2700,3100,3500,3900,4300,4700,
			5100,5500,5900,6300,6700,7100,7500,7900,8300,8700,9100};

	float temp_table[MAINTABLE_MAX_RPM_LENGTH] =
			{0.0, 8.0,	8.0, 8.0, 8.0, 12.4, 18.3, 24.2, 30.0, 30.0, 30.0, 30.0,
			30.0, 30.0, 30.0, 30.0, 30.0, 30.0, 30.0, 30.0, 30.0, 26.0, 18.0}; // Byrjaði á -2 breytti 27.3.16 til að testa

	uint8_t temp_dwell[MAINTABLE_MAX_RPM_LENGTH] =
				{40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
				40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40}; // duty cycle in %, 40%

	for(int i = 0; i < table.RPMLength; i++)
	{
		table.RPM[i] = temp_rpm_ign[i];
		unsigned long temp = 60000000 / ((long)temp_rpm_ign[i] * TIMER1_US_CONST) ; // in 4µs count values
		table.Cycle[i] = temp;
		table.Table[i] = temp_table[i];
		table.dwell[i] = temp_dwell[i]; // cycle - 40% duty cycle in counts
		print_string("RPM");print_int(temp_rpm_ign[i]);
		print_string("CycleCounts");print_long(temp);
		print_string("DwellDutyCycle"); print_int(temp_dwell[i]);
	}*/
}
Exemplo n.º 25
0
  void Output(const Mode mode, const char *file, const int line, const char *prefix, const char *delim, const char *name, const string &str)
  {
    if (initialized && str.length())
    {
      string m = message(prefix,delim,name,str);

      // TODO - optional Regal source line numbers.
#if 1
      UNUSED_PARAMETER(file);
      UNUSED_PARAMETER(line);
#else
      m = print_string(file,":",line," ",m);
#endif

#if REGAL_LOG_ONCE
      if (once)
        switch (mode)
        {
          case LOG_WARNING:
            if (uniqueWarnings.find(m)!=uniqueWarnings.end())
              return;
            uniqueWarnings.insert(m);
            break;

          case LOG_ERROR:
            if (uniqueErrors.find(m)!=uniqueErrors.end())
              return;
            uniqueErrors.insert(m);
            break;

          default:
            break;
        }
#endif

      RegalContext *rCtx = NULL;

#if !REGAL_SYS_WGL && !REGAL_NO_TLS
      if (Thread::currentContextKey && pthread_getspecific(Thread::currentContextKey))
        rCtx = REGAL_GET_CONTEXT();
#else
      rCtx = REGAL_GET_CONTEXT();
#endif

#if REGAL_LOG_CALLBACK
      if (callback && rCtx && rCtx->logCallback)
        rCtx->logCallback(GL_LOG_INFO_REGAL, (GLsizei) m.length(), m.c_str(), reinterpret_cast<void *>(rCtx->sysCtx));
#endif

#if REGAL_SYS_WGL
      OutputDebugStringA(m.c_str());
#elif REGAL_SYS_ANDROID
      // ANDROID_LOG_INFO
      // ANDROID_LOG_WARN
      // ANDROID_LOG_ERROR
      __android_log_print(ANDROID_LOG_INFO, REGAL_LOG_TAG, m.c_str());
#endif

#if REGAL_LOG_JSON
      if (json && jsonOutput)
      {
        string m = jsonObject(prefix,name,str);
        fwrite(m.c_str(),m.length(),1,jsonOutput);
      }
#endif

#if REGAL_LOG
      if (log && logOutput)
      {
#if REGAL_SYS_WGL
        OutputDebugStringA(m.c_str());
        fprintf(logOutput, "%s", m.c_str());
        fflush(logOutput);
#elif REGAL_SYS_ANDROID

#else
        fprintf(logOutput, "%s", m.c_str());
        fflush(logOutput);
#endif
      }
#endif

      append(m);
    }
  }
Exemplo n.º 26
0
int main(void)
{
	initialize();
	servo_init();
	motor_init();
	sonar_init();
	set_servo_position(0, 120); //center the servo
	
	print_string("Rodentia Demo");
	next_line();
	print_string("by Austin");
	
	led_on();
	delay_ms(100);
	led_off();
	delay_ms(100);
	led_on();
	delay_ms(100);
	led_off();
	
	//wait for a start signal
	while(!get_sw1())
	{
		/*u08 temp;
		clear_screen();
		temp = analog(0);
		print_int(temp);*/
		delay_ms(50);
	}
	led_on();
	
	while(1)
	{ //find and point toward heading with minimum sonar reading
		u08 heading = 0;
		/*u16 minHeading = 0;
		u16 left = 0;
		u08 aLeft = 1;
		
		u16 right = 0;
		u08 aRight = 1;*/
		u16 sonar = 0x0;
		u16 temp = 0;
		set_servo_position(0, 120); //center the servo
		set_motor_power(0, MIN_POWER);
		set_motor_power(1, -MIN_POWER);
		while(heading < 170) //what's the magic number?
		{
			/*u08 tempL = analog(1);
			u08 tempR = analog(2);
			if(tempL < 25 && aLeft)
			{
				set_motor_power(0, 0);
				left++;
				aLeft = 0;
			}
			if(tempL > 180 && !aLeft)
			{
				set_motor_power(0, 0);
				left++;
				aLeft =  1;
			}
			if(tempR < 25 && aRight)
			{
				set_motor_power(1, 0);
				right++;
				aRight = 0;
			}
			if(tempR > 180 && !aRight)
			{
				set_motor_power(1, 0);
				right++;
				aRight =  1;
			}
			if(left > heading && right > heading)*/
			{
				heading++;
				temp = getSonar(0);
				if(IR(0) > 70)
				{
					temp = 0;
				}
				if(temp > sonar)
				{
					sonar = temp;
					//minHeading = heading;
				}
				clear_screen();
				print_string("here=");
				print_int(temp);
				print_string(" max=");
				print_int(sonar);
				/*next_line();
				print_string("Hdng=");
				print_int(heading);
				print_string(" minH=");
				print_int(minHeading);
				if(left < right)
				{ //left motor on
					set_motor_power(0, MIN_POWER);
				}
				else if (right < left)
				{ //right motor on
					set_motor_power(1, -MIN_POWER);
				}
				else
				{
					set_motor_power(0, MIN_POWER);
					set_motor_power(1, -MIN_POWER);
				}*/
			}
		}
		
		if(sonar > 140)
		{ //set a reasonable maximum value for sonar
			sonar = 140;
		}
		
		//turn back to minumum heading
		temp = 0;
		while( temp < sonar )
		{
			temp = getSonar(0) + 3;
			if(IR(0) > 70)
			{
				temp = 0;
			}
			clear_screen();
			print_string("here=");
			print_int(temp);
			print_string(" max=");
			print_int(sonar);
		}
		/*set_motor_power(0, -MIN_POWER);
		set_motor_power(1, MIN_POWER);
		while(heading > minHeading)
		{
			u08 tempL = analog(1);
			u08 tempR = analog(2);
			if(tempL < 25 && aLeft)
			{
				set_motor_power(0, 0);
				left--;
				aLeft = 0;
			}
			if(tempL > 180 && !aLeft)
			{
				set_motor_power(0, 0);
				left--;
				aLeft =  1;
			}
			if(tempR < 25 && aRight)
			{
				set_motor_power(1, 0);
				right--;
				aRight = 0;
			}
			if(tempR > 180 && !aRight)
			{
				set_motor_power(1, 0);
				right--;
				aRight =  1;
			}
			if(left < heading && right < heading)
			{
				heading--;
				clear_screen();
				print_string("L=");
				print_int(left);
				print_string(" R=");
				print_int(right);
				next_line();
				print_string("Hdng=");
				print_int(heading);
				print_string(" minH=");
				print_int(minHeading);
				if(left > right)
				{ //left motor on
					set_motor_power(0, -MIN_POWER);
				}
				else if (right > left)
				{ //right motor on
					set_motor_power(1, MIN_POWER);
				}
				else
				{
					set_motor_power(0, -MIN_POWER);
					set_motor_power(1, MIN_POWER);
				}
			}
		}*/
		set_motor_power(0, 0);
		set_motor_power(1, 0);
		
		//scan with IR for obstacles
		delay_ms(500);
		u08 dir=120;
		s08 dDir = 1;
		u08 dist = IR(0);
		set_motor_power(0, 100);
		set_motor_power(1, 100);
		while(dist < 100)
		{
			dir += dDir;
			set_servo_position(0, dir);
			if(dir >= 200)
			{
				dDir = -1;
			}
			if(dir <= 40)
			{
				dDir = 1;
			}
			dist = IR(0);
			clear_screen();
			print_string("Distance=");
			print_int(dist);
		}
	}
	/*u08 temp;
	
	while(1)
	{
		clear_screen();
		temp = analog(0);
		print_int(temp);
		set_servo_position(0,temp);
		delay_ms(50);
	}*/
}
Exemplo n.º 27
0
/*
** list_ppkg_component_type:
** Print component type info for the specified component_id.
** If successful, return the number of items found; otherwise return -1.
*/ 
int
list_ppkg_component_type(int component_id)
{
    struct fields {
	int            component_id;
	unsigned char  component_level;
	char           display_value[80 + 1];
    };

    int  success;
    int  ret;
    int  no_items;
    int  item_cnt;
    ABP_PPKG_COMPONENT_TYPE  keys = NULL, item = NULL, list = NULL;   

    for (success = 0; !success; success = 1) {
	keys = new_abp_ppkg_component_type();
	if (keys == NULL) {
	    logprintf(LOG_ERR, "new_abp_ppkg_component_type() failed\n");
	    break;
	}

	unset_abp_ppkg_component_type(keys);
	set_abp_ppkg_component_type_component_id(keys, component_id);

	ret = list_abp_ppkg_component_types(g_dbhandle, keys, &list);
	if (ret < 0) {
	    LOG_API_ERROR(g_dbhandle, ret);
	    break;
	}
	no_items = ret;

	for (item = list, item_cnt = 0;
	     item != NULL;
	     item = next_abp_ppkg_component_type(item), item_cnt++)
	{
	    struct fields f;
	    char *label;

	    label = "component_id:";
	    ret = get_abp_ppkg_component_type_component_id(item,
                &f.component_id);
	    print_int(ret, label, f.component_id);

	    label = "component_level:";       
	    ret = get_abp_ppkg_component_type_component_level(item,
                &f.component_level);
	    print_int(ret, label, (int) f.component_level);

	    label = "display_value:";
	    ret = get_abp_ppkg_component_type_display_value(item,
                f.display_value);
	    print_string(ret, label, f.display_value);

	    printf("\n");
	}

	if (item_cnt != no_items) {
	    logprintf(LOG_ERR, "item_cnt != no_items\n");
	    break;
	}
    }

    delete_abp_ppkg_component_type(keys);
    abp_delete_objects(list);

    return success ? item_cnt : -1;
}
Exemplo n.º 28
0
int main(void)
{
	
	unsigned int addr;
	unsigned char READBYTE;
	unsigned char Mystring[30];


	Serial_Init();
	print_string("\n\rSTART OF EEPROM TEST");
	
	READBYTE = 0x00;		/* readByte variable initialized to zero */


	print_string("\n\rREADING EEPROM");			/* print to serial */

	/* performing READ FROM EEPROM */
	cli();	/* disable global interrupt */
	READBYTE = EEPROM_read(0xA);		//read Byte from address 0xa
	sei();	/* Enable global interrupt */
	
	sprintf(Mystring,"\n\rBYTE AT Address 0xA = 0x%02x",(unsigned int)READBYTE);	/* set the string to be printed on serial */
	print_string(Mystring);			/* print to serial */

	print_string("\n\rWRITING EEPROM");			/* print to serial */

	/* performing WRITE TO EEPROM */
	cli();	/* disable global interrupt	*/
	EEPROM_write(0xA,0x55);		/* write 0x55 at address 0xa */
	sei();	/* Enable global interrupt */
	

	READBYTE = 0x00;		/* readByte variable initialized to zero */

	print_string("\n\rREADING EEPROM");			/* print to serial */

	/* performing READ FROM EEPROM */
	cli();	/* disable global interrupt */
	READBYTE = EEPROM_read(0xA);		/* read Byte from address 0xa */
	sei();	/* Enable global interrupt */

	sprintf(Mystring,"\n\rBYTE AT Address 0xA = 0x%02x",(unsigned int)READBYTE);	//set the string to be printed on serial
	print_string(Mystring);			/* print to serial */

	/* reading from address 0x0000 to 0x000F */
	print_string("\n\r READING IN LOOP from address 0x0000 to 0x000F ");
		for(addr=0x0;addr<0x000F;addr++)
		{
			if(!(addr%20))
			{
				sprintf(Mystring,"\n\r0x%04d	: ",addr);
				print_string(Mystring);
			}
			sprintf(Mystring,"%02x ",(unsigned char)EEPROM_read(addr));	//write Byte at Addr (address Startaddress)
			print_string(Mystring);
		}
	
	print_string("\n\r START WRITING SEQUENCE IN LOOP from address 0x0000 to 0x000F ");

	/* writing from address 0x0000 to 0x000F */
	EEPROM_WRITEFROM(0x0000,0x000F,1,0xA5);		/* NOTE in this sequence is ON so it will start writing data as 0 1 2 3 ...*/
	//EEPROM_WRITEFROM(0x0000,0x000F,0,0xA5);	/*NOTE in this sequence is OFF so it will write data given in call */
	/* reading from address 0x0000 to 0x000F */
	for(addr=0x0;addr<0x000F;addr++)
	{
		if(!(addr%20))
		{
			sprintf(Mystring,"\n\r0x%04d	: ",addr);
			print_string(Mystring);
		}
		sprintf(Mystring,"%02x ",(unsigned char)EEPROM_read(addr));	//write Byte at Addr (address Startaddress)
		print_string(Mystring);
	}

	print_string("\n\rEND OF EEPROM TEST");

	while(1);		/* wait forever */
}
Exemplo n.º 29
0
/*
** list_product_type:
** Print product type info for the specified element_id.
** If successful, return the number of items found; otherwise return -1.
*/ 
int
list_product_type(short element_id)
{
    struct fields {
	int  element_id;
	char   description_text[80 + 1];
    };

    int  success;
    int  ret;
    int  no_items;
    int  item_cnt;
    ABP_PRODUCT_TYPE  keys = NULL, item = NULL, list = NULL;   


    for (success = 0; !success; success = 1) {
	keys = new_abp_product_type();
	if (keys == NULL) {
	    logprintf(LOG_ERR, "new_abp_product_type() failed\n");
	    break;
	}

	unset_abp_product_type(keys);
	set_abp_product_type_element_id(keys, element_id);

	ret = list_abp_product_types(g_dbhandle, keys, &list);
	if (ret < 0) {
	    LOG_API_ERROR(g_dbhandle, ret);
	    break;
	}
	no_items = ret;

	printf("\n");
	printf("Product Type\n");
	printf("------------\n");

	for (item = list, item_cnt = 0;
	     item != NULL;
	     item = next_abp_product_type(item), item_cnt++)
	{
	    struct fields f;
	    char *label;
	
	    label = "element_id:";
	    ret = get_abp_product_type_element_id(item,
                &f.element_id);
	    print_int(ret, label, (int) f.element_id);

	    label = "description_text:";
	    ret = get_abp_product_type_description_text(item,
                f.description_text);
	    print_string(ret, label, f.description_text);

	    printf("\n");
	}

	if (item_cnt != no_items) {
	    logprintf(LOG_ERR, "item_cnt != no_items\n");
	    break;
	}
    }

    delete_abp_product_type(keys);
    abp_delete_objects(list);

    return success ? item_cnt : -1;
}
Exemplo n.º 30
0
/* device creation */
static void macsec_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{
	if (!tb)
		return;

	if (tb[IFLA_MACSEC_SCI]) {
		if (is_json_context()) {
			SPRINT_BUF(b1);

			snprintf(b1, sizeof(b1), "%016llx",
				 ntohll(rta_getattr_u64(tb[IFLA_MACSEC_SCI])));
			print_string(PRINT_JSON, "sci", NULL, b1);
		} else {
			fprintf(f, "sci %016llx ",
				ntohll(rta_getattr_u64(tb[IFLA_MACSEC_SCI])));
		}
	}

	print_flag(tb, "protect", IFLA_MACSEC_PROTECT);

	if (tb[IFLA_MACSEC_CIPHER_SUITE]) {
		__u64 csid
			= rta_getattr_u64(tb[IFLA_MACSEC_CIPHER_SUITE]);

		print_string(PRINT_ANY,
			     "cipher_suite",
			     "cipher %s ",
			     cs_id_to_name(csid));
	}

	if (tb[IFLA_MACSEC_ICV_LEN]) {
		if (is_json_context()) {
			char b2[4];

			snprintf(b2, sizeof(b2), "%hhu",
				 rta_getattr_u8(tb[IFLA_MACSEC_ICV_LEN]));
			print_uint(PRINT_JSON, "icv_len", NULL, atoi(b2));
		} else {
			fprintf(f, "icvlen %hhu ",
				rta_getattr_u8(tb[IFLA_MACSEC_ICV_LEN]));
		}
	}

	if (tb[IFLA_MACSEC_ENCODING_SA]) {
		if (is_json_context()) {
			char b2[4];

			snprintf(b2, sizeof(b2), "%hhu",
				 rta_getattr_u8(tb[IFLA_MACSEC_ENCODING_SA]));
			print_uint(PRINT_JSON, "encoding_sa", NULL, atoi(b2));
		} else {
			fprintf(f, "encodingsa %hhu ",
				rta_getattr_u8(tb[IFLA_MACSEC_ENCODING_SA]));
		}
	}

	if (tb[IFLA_MACSEC_VALIDATION]) {
		__u8 val = rta_getattr_u8(tb[IFLA_MACSEC_VALIDATION]);

		print_string(PRINT_ANY,
			     "validation",
			     "validate %s ",
			     validate_str[val]);
	}

	const char *inc_sci, *es, *replay;

	if (is_json_context()) {
		inc_sci = "inc_sci";
		replay = "replay_protect";
		es = "es";
	} else {
		inc_sci = "send_sci";
		es = "end_station";
		replay = "replay";
	}

	print_flag(tb, "encrypt", IFLA_MACSEC_ENCRYPT);
	print_flag(tb, inc_sci, IFLA_MACSEC_INC_SCI);
	print_flag(tb, es, IFLA_MACSEC_ES);
	print_flag(tb, "scb", IFLA_MACSEC_SCB);
	print_flag(tb, replay, IFLA_MACSEC_REPLAY_PROTECT);

	if (tb[IFLA_MACSEC_WINDOW])
		print_int(PRINT_ANY,
			  "window",
			  "window %d ",
			  rta_getattr_u32(tb[IFLA_MACSEC_WINDOW]));
}