Example #1
0
/**
 * Retrieves a LinphoneAuthInfo previously entered into the LinphoneCore.
**/
const LinphoneAuthInfo *linphone_core_find_auth_info(LinphoneCore *lc, const char *realm, const char *username)
{
	MSList *elem;
	LinphoneAuthInfo *ret=NULL,*candidate=NULL;
	for (elem=lc->auth_info;elem!=NULL;elem=elem->next){
		LinphoneAuthInfo *pinfo=(LinphoneAuthInfo*)elem->data;
		if (realm==NULL){
			/*return the authinfo for any realm provided that there is only one for that username*/
			if (key_match(pinfo->username,username)){
				if (ret!=NULL){
					ms_warning("There are several auth info for username '%s'",username);
					return NULL;
				}
				ret=pinfo;
			}
		}else{
			/*return the exact authinfo, or an authinfo for which realm was not supplied yet*/
			if (pinfo->realm!=NULL){
				if (realm_match(pinfo->realm,realm) 
					&& key_match(pinfo->username,username))
					ret=pinfo;
			}else{
				if (key_match(pinfo->username,username))
					candidate=pinfo;
			}
		}
	}
	if (ret==NULL && candidate!=NULL)
		ret=candidate;
	return ret;
}
Example #2
0
int Zoltan_Map_Find(ZZ *zz, ZOLTAN_MAP* map, int *key, int *data)
{
  char *yo = "Zoltan_Map_Find";
  int index, match;
  ZOLTAN_ENTRY *element;
  ZOLTAN_ID_PTR zkey = (ZOLTAN_ID_PTR)key;

  *data = ZOLTAN_NOT_FOUND;

  if (!map){
    ZOLTAN_PRINT_ERROR(zz->Proc, yo, "Map specified does not exist\n");
    return ZOLTAN_FATAL;
  }

  index = Zoltan_Hash(zkey, map->id_size, map->max_index);

  element = map->entries[index];
  match = 0;

  while (element != NULL){
    match = key_match(map->id_size, element->key, key);
    if (match){
      *data = element->data;
      break;
    }
    element = element->next;
  }
  return ZOLTAN_OK;
}
Example #3
0
int misc_init_r (void)
{
    char kbd_data[KEYBD_DATALEN];
    char keybd_env[2 * KEYBD_DATALEN + 1];
    char *str;
    int i;

    i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);

    i2c_read (CONFIG_SYS_I2C_KEY_ADDR, 0, 0, (uchar *)kbd_data, KEYBD_DATALEN);

    for (i = 0; i < KEYBD_DATALEN; ++i) {
        sprintf (keybd_env + i + i, "%02X", kbd_data[i]);
    }
    setenv ("keybd", keybd_env);

    str = strdup ((char *)key_match ((uchar *)keybd_env));	/* decode keys */

#ifdef CONFIG_PREBOOT	/* automatically configure "preboot" command on key match */
    setenv ("preboot", str);	/* set or delete definition */
#endif /* CONFIG_PREBOOT */
    if (str != NULL) {
        free (str);
    }

    return (0);
}
Example #4
0
int misc_init_r(void)
{
	char *s, buf[32];
#ifdef CONFIG_PREBOOT
	struct kbd_data_t kbd_data;
	/* Decode keys */
	char *str = strdup(key_match(get_keys(&kbd_data)));
	/* Set or delete definition */
	setenv("preboot", str);
	free(str);
#endif /* CONFIG_PREBOOT */

	/* count all restarts, and save this in an environment var */
	s = getenv("restartcount");

	if (s)
		sprintf(buf, "%ld", simple_strtoul(s, NULL, 10) + 1);
	else
		strcpy(buf, "1");

	setenv("restartcount", buf);
	saveenv();

#ifdef CONFIG_HW_WATCHDOG
	davinci_hw_watchdog_enable();
#endif

	return 0;
}
Example #5
0
int board_late_init(void)
{
#ifdef DELTA_CHECK_KEYBD
	uchar kbd_data[KEYBD_DATALEN];
	char keybd_env[2 * KEYBD_DATALEN + 1];
	char *str;
	int i;
#endif /* DELTA_CHECK_KEYBD */

	setenv("stdout", "serial");
	setenv("stderr", "serial");

#ifdef DELTA_CHECK_KEYBD
	keys_init();

	memset(kbd_data, '\0', KEYBD_DATALEN);

	/* check for pressed keys and setup keybd_env */
	get_pressed_keys(kbd_data);

	for (i = 0; i < KEYBD_DATALEN; ++i) {
		sprintf (keybd_env + i + i, "%02X", kbd_data[i]);
	}
	setenv ("keybd", keybd_env);

	str = strdup ((char *)key_match (kbd_data));	/* decode keys */

# ifdef CONFIG_PREBOOT	/* automatically configure "preboot" command on key match */
	setenv ("preboot", str);	/* set or delete definition */
# endif /* CONFIG_PREBOOT */
	if (str != NULL) {
		free (str);
	}
#endif /* DELTA_CHECK_KEYBD */

	init_DA9030();
	return 0;
}
Example #6
0
/*
 * This function interprets the reply and prints it to stdout. It returns
 * 0 if no more should be read and 1 to indicate that more messages of this
 * type may need to be read. 
 */
int audit_print_reply(struct audit_reply *rep, int fd)
{
	_audit_elf = 0; 

	switch (rep->type) {
		case NLMSG_NOOP:
			return 1;
		case NLMSG_DONE:
			// Close the socket so kernel can do other things
			audit_close(fd);
			if (printed == 0)
				printf("No rules\n");
			else {
				lnode *n;
				list_first(&l);
				n = l.cur;
				while (n) {
					print_rule(n->r);
					n = list_next(&l);
				}
				list_clear(&l);
			}
			break;
		case NLMSG_ERROR: 
		        printf("NLMSG_ERROR %d (%s)\n",
				-rep->error->error, 
				strerror(-rep->error->error));
			printed = 1;
			break;
		case AUDIT_GET:
			if (interpret)
				printf("enabled %s\nfailure %s\n",
					get_enable(rep->status->enabled),
					get_failure(rep->status->failure));
			else
				printf("enabled %u\nfailure %u\n",
				rep->status->enabled, rep->status->failure);
			printf("pid %u\nrate_limit %u\nbacklog_limit %u\n"
				"lost %u\nbacklog %u\n",
			rep->status->pid, rep->status->rate_limit,
			rep->status->backlog_limit, rep->status->lost,
			rep->status->backlog);
#if HAVE_DECL_AUDIT_VERSION_BACKLOG_WAIT_TIME
			printf("backlog_wait_time %u\n",
				rep->status->backlog_wait_time);
#endif
			printed = 1;
			break;
#if HAVE_DECL_AUDIT_FEATURE_VERSION
		case AUDIT_GET_FEATURE:
			{
			uint32_t mask = AUDIT_FEATURE_TO_MASK(AUDIT_FEATURE_LOGINUID_IMMUTABLE);
			if (rep->features->mask & mask)
				printf("loginuid_immutable %u %s\n",
					!!(rep->features->features & mask),
					rep->features->lock & mask ? "locked" :
					"unlocked");
			}
			printed = 1;
			break;
#endif
		case AUDIT_LIST_RULES:
			list_requested = 0;
			if (key_match(rep->ruledata))
				 list_append(&l, rep->ruledata,
					sizeof(struct audit_rule_data) +
					rep->ruledata->buflen);
			printed = 1;
			return 1;
		default:
			printf("Unknown: type=%d, len=%d\n", rep->type, 
				rep->nlh->nlmsg_len);
			printed = 1;
			break;
	}
	return 0;
}
Example #7
0
int Zoltan_Map_Find_Add(ZZ *zz, ZOLTAN_MAP* map, int *key, int datain, int *dataout)
{
  char *yo = "Zoltan_Map_Add";
  int index, match, i;
  ZOLTAN_ENTRY *element;
  ZOLTAN_ID_PTR zkey = (ZOLTAN_ID_PTR)key;

  if (!map){
    ZOLTAN_PRINT_ERROR(zz->Proc, yo, "Map specified does not exist\n");
    return ZOLTAN_FATAL;
  }

  index = Zoltan_Hash(zkey, map->id_size, map->max_index);

  /* If this key is not found in the map, then add it */

  element = map->entries[index];
  match = 0;

  while (element != NULL){
    match = key_match(map->id_size, element->key, key);
    if (match){
      break;
    }
    element = element->next;
  }

  if (!match){
    i = map->entry_count;

    if (!map->dynamicEntries && (i == map->max_entries)){
      ZOLTAN_PRINT_ERROR(zz->Proc, yo, "Fixed size map overflow\n");
      return ZOLTAN_FATAL;
    }

    if (map->dynamicEntries){
      element = (ZOLTAN_ENTRY *)ZOLTAN_MALLOC(sizeof(ZOLTAN_ENTRY));
      if (!element)
	return ZOLTAN_MEMERR;
    }
    else{
      element = map->top + i;
    }

    if (map->copyKeys){
      if(map->dynamicEntries) {
	element->key = (int *)ZOLTAN_MALLOC(sizeof(int) * map->id_size);
	if (!element->key)
	  return ZOLTAN_MEMERR;
      }
      else
	element->key = map->keys + map->entry_count;
      memcpy(element->key, key, sizeof(int)*map->id_size);
    }
    else{
      element->key = key;
    }

    element->data = datain;
    element->next = map->entries[index];

    map->entries[index] = element;

    map->entry_count++;
  }
  if (dataout != NULL) {
    *dataout = element->data;
  }

  return ZOLTAN_OK;
}
Example #8
0
/*
 * This function interprets the reply and prints it to stdout. It returns
 * 0 if no more should be read and 1 to indicate that more messages of this
 * type may need to be read. 
 */
static int audit_print_reply(struct audit_reply *rep)
{
	unsigned int i;
	int first;
	int sparse;
	int machine = audit_detect_machine();
	size_t boffset;
	int show_syscall;

	_audit_elf = 0; 
	switch (rep->type) {
		case NLMSG_NOOP:
			return 1;
		case NLMSG_DONE:
			if (printed == 0)
				printf("No rules\n");
			return 0;
		case NLMSG_ERROR: 
		        printf("NLMSG_ERROR %d (%s)\n",
				-rep->error->error, 
				strerror(-rep->error->error));
			printed = 1;
			return 0;
		case AUDIT_GET:
			printf("AUDIT_STATUS: enabled=%d flag=%d pid=%d"
			" rate_limit=%d backlog_limit=%d lost=%d backlog=%u\n",
			rep->status->enabled, rep->status->failure,
			rep->status->pid, rep->status->rate_limit,
			rep->status->backlog_limit, rep->status->lost,
			rep->status->backlog);
			printed = 1;
			return 0;
		case AUDIT_LIST_RULES:
			list_requested = 0;
			boffset = 0;
			show_syscall = 1;
			if (key_match(rep) == 0)
				return 1;
			printed = 1;
			printf("%s: %s,%s", audit_msg_type_to_name(rep->type),
				audit_flag_to_name((int)rep->ruledata->flags),
				audit_action_to_name(rep->ruledata->action));

			for (i = 0; i < rep->ruledata->field_count; i++) {
				const char *name;
				int op = rep->ruledata->fieldflags[i] &
						AUDIT_OPERATORS;
				int field = rep->ruledata->fields[i] &
						~AUDIT_OPERATORS;
                
				name = audit_field_to_name(field);
				if (name) {
					if (strcmp(name, "arch") == 0) { 
						_audit_elf =
						    rep->ruledata->values[i];
						printf(" %s%s%u", name, 
						  audit_operator_to_symbol(op),
					    (unsigned)rep->ruledata->values[i]);
					}
					else if (strcmp(name, "msgtype") == 0) {
						if (!audit_msg_type_to_name(
						      rep->ruledata->values[i]))
							printf(" %s%s%d", name,
								audit_operator_to_symbol(op),
								rep->ruledata->values[i]);
						else {
							printf(" %s%s%s", name,
								audit_operator_to_symbol(op),
								audit_msg_type_to_name(rep->ruledata->values[i]));
						}
					} else if ((field >= AUDIT_SUBJ_USER &&
						  field <= AUDIT_OBJ_LEV_HIGH)
						&& field != AUDIT_PPID &&
					       rep->type == AUDIT_LIST_RULES) {
						printf(" %s%s%.*s", name,
						  audit_operator_to_symbol(op),
						  rep->ruledata->values[i],
						  &rep->ruledata->buf[boffset]);
						boffset +=
						    rep->ruledata->values[i];
					} else if (field == AUDIT_WATCH) {
						printf(" watch=%.*s", 
						  rep->ruledata->values[i],
						  &rep->ruledata->buf[boffset]);
						boffset +=
						    rep->ruledata->values[i];
					} else if (field == AUDIT_DIR) {
						printf(" dir=%.*s", 
						  rep->ruledata->values[i],
						  &rep->ruledata->buf[boffset]);
						boffset +=
						    rep->ruledata->values[i];
					} else if (field == AUDIT_FILTERKEY) {
						char *rkey, *ptr;
						asprintf(&rkey, "%.*s",
						rep->ruledata->values[i],
						&rep->ruledata->buf[boffset]);
						boffset +=
						    rep->ruledata->values[i];
						ptr = strtok(rkey, key_sep);
						while (ptr) {
							printf(" key=%s", ptr);
							ptr = strtok(NULL,
								key_sep);
						}
						free(rkey);
					} else if (field == AUDIT_PERM) {
						char perms[5];
						int val=rep->ruledata->values[i];
						perms[0] = 0;
						if (val & AUDIT_PERM_READ)
							strcat(perms, "r");
						if (val & AUDIT_PERM_WRITE)
							strcat(perms, "w");
						if (val & AUDIT_PERM_EXEC)
							strcat(perms, "x");
						if (val & AUDIT_PERM_ATTR)
							strcat(perms, "a");
						printf(" perm=%s", perms);
						show_syscall = 0;
					} else if (field == AUDIT_INODE) {
						// Unsigned items
						printf(" %s%s%u", name, 
							audit_operator_to_symbol(op),
							rep->ruledata->values[i]);
					} else if (field == AUDIT_FIELD_COMPARE) {
						switch (rep->ruledata->values[i])
						{
						case AUDIT_COMPARE_UID_TO_OBJ_UID:
							printf(" uid%sobj_uid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_GID_TO_OBJ_GID:
							printf(" gid%sobj_gid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_EUID_TO_OBJ_UID:
							printf(" euid%sobj_uid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_EGID_TO_OBJ_GID:
							printf(" egid%sobj_gid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_AUID_TO_OBJ_UID:
							printf(" auid%sobj_uid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_SUID_TO_OBJ_UID:
							printf(" suid%sobj_uid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_SGID_TO_OBJ_GID:
							printf(" sgid%sobj_gid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_FSUID_TO_OBJ_UID:
							printf(" fsuid%sobj_uid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_FSGID_TO_OBJ_GID:
							printf(" fsgid%sobj_gid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_UID_TO_AUID:
							printf(" uid%sauid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_UID_TO_EUID:
							printf(" uid%seuid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_UID_TO_FSUID:
							printf(" uid%sfsuid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_UID_TO_SUID:
							printf(" uid%ssuid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_AUID_TO_FSUID:
							printf(" auid%sfsuid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_AUID_TO_SUID:
							printf(" auid%ssuid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_AUID_TO_EUID:
							printf(" auid%seuid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_EUID_TO_SUID:
							printf(" euid%ssuid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_EUID_TO_FSUID:
							printf(" euid%sfsuid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_SUID_TO_FSUID:
							printf(" suid%sfsuid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_GID_TO_EGID:
							printf(" gid%segid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_GID_TO_FSGID:
							printf(" gid%sfsgid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_GID_TO_SGID:
							printf(" gid%ssgid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_EGID_TO_FSGID:
							printf(" egid%sfsgid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_EGID_TO_SGID:
							printf(" egid%ssgid",audit_operator_to_symbol(op));
							break;
						case AUDIT_COMPARE_SGID_TO_FSGID:
							printf(" sgid%sfsgid",audit_operator_to_symbol(op));
							break;
						}
					} else {
						// Signed items
						printf(" %s%s%d", name, 
							audit_operator_to_symbol(op),
							rep->ruledata->values[i]);
					}
				} else { 
					printf(" f%d%s%d", rep->ruledata->fields[i],
						audit_operator_to_symbol(op),
						rep->ruledata->values[i]);
				}
				/* Avoid printing value if the field type is 
				 * known to return a string. */
				if (rep->ruledata->values[i] && 
						(field < AUDIT_SUBJ_USER ||
						 field > AUDIT_SUBJ_CLR) &&
						field != AUDIT_WATCH &&
						field != AUDIT_FILTERKEY &&
						field != AUDIT_PERM &&
						field != AUDIT_FIELD_COMPARE)
					printf(" (0x%x)", rep->ruledata->values[i]);
			}
			if (show_syscall &&
				((rep->ruledata->flags & AUDIT_FILTER_MASK) != 
						AUDIT_FILTER_USER) &&
				((rep->ruledata->flags & AUDIT_FILTER_MASK) !=
						AUDIT_FILTER_TASK) &&
				((rep->ruledata->flags & AUDIT_FILTER_MASK) !=
						AUDIT_FILTER_EXCLUDE)) {
				printf(" syscall=");
				for (sparse = 0, i = 0; 
					i < (AUDIT_BITMASK_SIZE-1); i++) {
					if (rep->ruledata->mask[i] != (uint32_t)~0)
						sparse = 1;
				}
				if (!sparse) {
					printf("all");
				} else for (first = 1, i = 0;
					i < AUDIT_BITMASK_SIZE * 32; i++) {
					int word = AUDIT_WORD(i);
					int bit  = AUDIT_BIT(i);
					if (rep->ruledata->mask[word] & bit) {
						const char *ptr;
						if (_audit_elf)
							machine = 
							audit_elf_to_machine(
								_audit_elf);
						if (machine < 0)
							ptr = NULL;
						else
							ptr = 
							audit_syscall_to_name(i, 
							machine);
						if (ptr)
							printf("%s%s", 
							first ? "" : ",", ptr);
						else
							printf("%s%d", 
							first ? "" : ",", i);
						first = 0;
					}
				}
			}
			printf("\n");
			return 1; /* get more messages until NLMSG_DONE */
		default:
			printf("Unknown: type=%d, len=%d\n", rep->type, 
				rep->nlh->nlmsg_len);
			printed = 1;
			return 0;
	}
}
Example #9
0
File: kbd.c Project: 01hyang/u-boot
/***********************************************************************
F* Function:     int misc_init_r (void) P*A*Z*
 *
P* Parameters:   none
P*
P* Returnvalue:  int
P*                - 0 is always returned, even in the case of a keyboard
P*                    error.
 *
Z* Intention:    This function is the misc_init_r() method implementation
Z*               for the lwmon board.
Z*               The keyboard controller is initialized and the result
Z*               of a read copied to the environment variable "keybd".
Z*               If KEYBD_SET_DEBUGMODE is defined, a check is made for
Z*               this key, and if found display to the LCD will be enabled.
Z*               The keys in "keybd" are checked against the magic
Z*               keycommands defined in the environment.
Z*               See also key_match().
 *
D* Design:       [email protected]
C* Coding:       [email protected]
V* Verification: [email protected]
 ***********************************************************************/
int misc_init_r_kbd (void)
{
	uchar kbd_data[KEYBD_DATALEN];
	char keybd_env[2 * KEYBD_DATALEN + 1];
	uchar kbd_init_status = gd->arch.kbd_status >> 8;
	uchar kbd_status = gd->arch.kbd_status;
	uchar val;
	ushort data, inv_data;
	char *str;
	int i;

	if (kbd_init_status) {
		printf ("KEYBD: Error %02X\n", kbd_init_status);
	}
	if (kbd_status) {		/* permanent error, report it */
		printf ("*** Keyboard error code %02X ***\n", kbd_status);
		sprintf (keybd_env, "%02X", kbd_status);
		setenv ("keybd", keybd_env);
		return 0;
	}

	/*
	 * Now we know that we have a working  keyboard,  so  disable
	 * all output to the LCD except when a key press is detected.
	 */

	if ((console_assign (stdout, "serial") < 0) ||
		(console_assign (stderr, "serial") < 0)) {
		printf ("Can't assign serial port as output device\n");
	}

	/* Read Version */
	val = KEYBD_CMD_READ_VERSION;
	i2c_write (kbd_addr, 0, 0, &val, 1);
	i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_VERSIONLEN);
	printf ("KEYBD: Version %d.%d\n", kbd_data[0], kbd_data[1]);

	/* Read current keyboard state */
	val = KEYBD_CMD_READ_KEYS;
	i2c_write (kbd_addr, 0, 0, &val, 1);
	i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_DATALEN);

	/* read out start key from bse01 received via can */
	_dspic_read(DSPIC_PON_STATUS_REG, &data);
	/* check highbyte from status register */
	if (data > 0xFF) {
		_dspic_read(DSPIC_PON_INV_STATUS_REG, &inv_data);

		/* check inverse data */
		if ((data+inv_data) == 0xFFFF) {
			/* don't overwrite local key */
			if (kbd_data[1] == 0) {
				/* read key value */
				_dspic_read(DSPIC_PON_KEY_REG, &data);
				str = (char *)&data;
				/* swap bytes */
				kbd_data[1] = str[1];
				kbd_data[2] = str[0];
				printf("CAN received startkey: 0x%X\n", data);
			}
		}
	}

	for (i = 0; i < KEYBD_DATALEN; ++i) {
		sprintf (keybd_env + i + i, "%02X", kbd_data[i]);
	}

	setenv ("keybd", keybd_env);

	str = strdup ((char *)key_match (kbd_data));	/* decode keys */
#ifdef KEYBD_SET_DEBUGMODE
	if (kbd_data[0] == KEYBD_SET_DEBUGMODE) {	/* set debug mode */
		if ((console_assign (stdout, "lcd") < 0) ||
			(console_assign (stderr, "lcd") < 0)) {
			printf ("Can't assign LCD display as output device\n");
		}
	}
#endif /* KEYBD_SET_DEBUGMODE */
#ifdef CONFIG_PREBOOT	/* automatically configure "preboot" command on key match */
	setenv ("preboot", str);	/* set or delete definition */
#endif /* CONFIG_PREBOOT */
	if (str != NULL) {
		free (str);
	}
	return (0);
}
Example #10
0
/***********************************************************************
F* Function:     int misc_init_r (void) P*A*Z*
 *
P* Parameters:   none
P*
P* Returnvalue:  int
P*                - 0 is always returned, even in the case of a keyboard
P*                    error.
 *
Z* Intention:    This function is the misc_init_r() method implementation
Z*               for the lwmon board.
Z*               The keyboard controller is initialized and the result
Z*               of a read copied to the environment variable "keybd".
Z*               If KEYBD_SET_DEBUGMODE is defined, a check is made for
Z*               this key, and if found display to the LCD will be enabled.
Z*               The keys in "keybd" are checked against the magic
Z*               keycommands defined in the environment.
Z*               See also key_match().
 *
D* Design:       [email protected]
C* Coding:       [email protected]
V* Verification: [email protected]
 ***********************************************************************/
int misc_init_r_kbd (void)
{
    uchar kbd_data[KEYBD_DATALEN];
    char keybd_env[2 * KEYBD_DATALEN + 1];
    uchar kbd_init_status = gd->kbd_status >> 8;
    uchar kbd_status = gd->kbd_status;
    uchar val;
    char *str;
    int i;

    if (kbd_init_status) {
        printf ("KEYBD: Error %02X\n", kbd_init_status);
    }
    if (kbd_status) {		/* permanent error, report it */
        printf ("*** Keyboard error code %02X ***\n", kbd_status);
        sprintf (keybd_env, "%02X", kbd_status);
        setenv ("keybd", keybd_env);
        return 0;
    }

    /*
     * Now we know that we have a working  keyboard,  so  disable
     * all output to the LCD except when a key press is detected.
     */

    if ((console_assign (stdout, "serial") < 0) ||
            (console_assign (stderr, "serial") < 0)) {
        printf ("Can't assign serial port as output device\n");
    }

    /* Read Version */
    val = KEYBD_CMD_READ_VERSION;
    i2c_write (kbd_addr, 0, 0, &val, 1);
    i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_VERSIONLEN);
    printf ("KEYBD: Version %d.%d\n", kbd_data[0], kbd_data[1]);

    /* Read current keyboard state */
    val = KEYBD_CMD_READ_KEYS;
    i2c_write (kbd_addr, 0, 0, &val, 1);
    i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_DATALEN);

    for (i = 0; i < KEYBD_DATALEN; ++i) {
        sprintf (keybd_env + i + i, "%02X", kbd_data[i]);
    }
    setenv ("keybd", keybd_env);

    str = strdup ((char *)key_match (kbd_data));	/* decode keys */
#ifdef KEYBD_SET_DEBUGMODE
    if (kbd_data[0] == KEYBD_SET_DEBUGMODE) {	/* set debug mode */
        if ((console_assign (stdout, "lcd") < 0) ||
                (console_assign (stderr, "lcd") < 0)) {
            printf ("Can't assign LCD display as output device\n");
        }
    }
#endif /* KEYBD_SET_DEBUGMODE */
#ifdef CONFIG_PREBOOT	/* automatically configure "preboot" command on key match */
    setenv ("preboot", str);	/* set or delete definition */
#endif /* CONFIG_PREBOOT */
    if (str != NULL) {
        free (str);
    }
    return (0);
}