Example #1
0
static int
process_command(int serial, int cid, char *cmd)
{
  /*char *opt, *opt2; */
  char *p, *opt;
  int ret;

  if ((p = strchr(cmd, '\n')))
	*p = '\0';
  else
	return -1;

  if ((opt = strchr(cmd, ' '))) {
	*opt = '\0';
	opt ++;
  } else {
	opt = NULL;
  }

  debug_printf(DEBUG_NOTE, "cmd: %s\n", cmd);

  if (strcmp(cmd, "RELEASE") == 0)
	ret = cmd_release(cid);
  else if (strcmp(cmd, "UNFOCUSED") == 0)
	ret = cmd_unfocused(cid);
  else if (strcmp(cmd, "FOCUSED") == 0)
	ret = cmd_focused(cid);
  else if (strcmp(cmd, "HIDE") == 0)
	ret = cmd_hide(cid);
  else if (strcmp(cmd, "SHOW") == 0)
	ret = cmd_show(cid);
  else if (strcmp(cmd, "NEW") == 0)
  	ret = cmd_new(cid, opt);
  else if (strcmp(cmd, "RESET") == 0)
	ret = cmd_reset(cid);
  else if (strcmp(cmd, "CHANGE") == 0)
  	ret = cmd_change(cid, opt);
  else if (strcmp(cmd, "PROP") == 0)
  	ret = cmd_prop(cid, opt);
  else if (strcmp(cmd, "LABEL") == 0)
  	ret = cmd_label(cid);
  else if (strcmp(cmd, "HELPER") == 0)
	ret = cmd_helper(cid, opt);
  else if (strcmp(cmd, "NOP") == 0)
  	ret = cmd_nop(cid);
  else if (strcmp(cmd, "LIST") == 0)
  	ret = cmd_list();
  else if (strcmp(cmd, "SETENC") == 0)
  	ret = cmd_setenc(opt);
  else if (strcmp(cmd, "GETENC") == 0)
  	ret = cmd_getenc(opt); /* for debug */
  else
	ret = cmd_error();

  return ret;
}
Example #2
0
/* Assemble a scsi command with a struct sg_header attached to the front and
 * send it off.  Expect the reply prepended with a struct sg_header.
 */
int send_cmd(tDeviceCmd cmd, tDeviceSetting val, unsigned char *reply)
{
	int ret;
	unsigned char cmdbuf[sizeof(struct sg_header) + 256];
	unsigned char *ptr = cmdbuf + sizeof(struct sg_header);
	struct inquiry_cmd *inq_cmd;
	struct custom_cmd *custom_cmd;
	int reply_size;

	switch(cmd) {

	case kDeviceCmdInquiry:
		inq_cmd = (struct inquiry_cmd *)(cmdbuf + sizeof(struct sg_header));
		memset(inq_cmd, 0, sizeof(struct inquiry_cmd));
		inq_cmd->opcode = cmd;
		inq_cmd->alloc_len = sizeof(struct inquiry_reply);
		ret = cmd_helper(sizeof(struct inquiry_cmd), cmdbuf,
						 sizeof(struct inquiry_reply), reply);
		break;

	case kDeviceCmdLockDevice:
	case kDeviceCmdUnlockDevice:
	case kDeviceCmdDisconnectOk:
	case kDeviceCmdUndefined:
		custom_cmd = (struct custom_cmd *)(cmdbuf + sizeof(struct sg_header));
		memset(custom_cmd, 0, sizeof(struct custom_cmd));
		custom_cmd->opcode = cmd;
		ret = cmd_helper(sizeof(struct custom_cmd), cmdbuf,
				 0, reply);
		break;

	case kDeviceCmdGetSetting:
		switch (val) {
		case kSettingBatteryLevel:
			reply_size = sizeof(struct battery_reply);
			break;

		case kSettingRTCCounter:
			reply_size = sizeof(struct rtc_reply);
			break;

		case kSettingSerialNumber:
			reply_size = 256;
			break;

		case kSettingUndefined:
			reply_size = 2;
			break;

		default:
			/* unrecognized setting */
			return 1;
		}

		custom_cmd = (struct custom_cmd *)(cmdbuf + sizeof(struct sg_header));
		memset(custom_cmd, 0, sizeof(struct custom_cmd));
		custom_cmd->opcode = cmd;
		custom_cmd->setting = val;
		ret = cmd_helper(sizeof(struct custom_cmd), cmdbuf,
				 reply_size, reply);
		break;

	default:
		/* Unrecognized command */
		return 1;
	}
	return ret;
}