int remote_rpc_request(uint32_t command)
{
	struct oem_rapi_client_streaming_func_arg arg;
	struct oem_rapi_client_streaming_func_ret ret;
	char output[4];
	int rc= -1;
	int request_cmd = command;

	Open_check();
	arg.event = LGE_RPC_HANDLE_REQUEST;
	arg.cb_func = NULL;
	arg.handle = (void*) 0;
	arg.in_len = sizeof(request_cmd);
	arg.input = (char*)&request_cmd;
	arg.out_len_valid = 1;
	arg.output_valid = 1;
	arg.output_size = sizeof(output);

	ret.output = (char*)NULL;
	ret.out_len = 0;

	rc = oem_rapi_client_streaming_function(client,&arg,&ret);
	if (rc < 0)
	{
		pr_err("%s, rapi reqeust failed\r\n", __func__);
	}
	else
	{
		rc = lg_rapi_check_validity_and_copy_result((void*)&ret, (char*)output, arg.output_size);
		if(rc == LG_RAPI_INVALID_RESPONSE)
			memset(output,0,sizeof(output));
		
		switch(command)
		{
#ifdef CONFIG_LGE_SYNC_CMD
			case LGE_SYNC_REQUEST:
				pr_info("%s, sync retry count : %d\r\n", __func__, GET_INT32(output));
				if(rc != LG_RAPI_SUCCESS)
					rc = -1;
				break;
#endif
#ifdef CONFIG_LGE_NOTIFY_RECOVERY_MODE
			case LGE_RECOVERY_NOTIFICATION:
				pr_info("%s, recovery notification retry count : %d\r\n", __func__, GET_INT32(output));
				if(rc != LG_RAPI_SUCCESS)
					rc = -1;
				break;
#endif
			default :
				break;
		}
	}
	
	if (ret.output)
		kfree(ret.output);
	if (ret.out_len)
		kfree(ret.out_len);
	
	return rc;
}
Exemple #2
0
int msm_chg_LG_cable_type(void)
{
char output[LG_RAPI_CLIENT_MAX_OUT_BUFF_SIZE];
	#if 0
	struct oem_rapi_client_streaming_func_arg arg;
	struct oem_rapi_client_streaming_func_ret ret;
//	char output[LG_RAPI_CLIENT_MAX_OUT_BUFF_SIZE];
	int rc= -1;
	int errCount= 0;

	Open_check();

/* LGE_CHANGES_S [[email protected]] 2010-09-06, Add error control code. Repeat 3 times if error occurs*/

	do 
	{
		arg.event = LG_FW_RAPI_CLIENT_EVENT_GET_LINE_TYPE;
		arg.cb_func = NULL;
		arg.handle = (void*) 0;
		arg.in_len = 0;
		arg.input = NULL;
		arg.out_len_valid = 1;
		arg.output_valid = 1;
		arg.output_size = 4;

		ret.output = NULL;
		ret.out_len = NULL;

		rc= oem_rapi_client_streaming_function(client, &arg, &ret);
	
		if (rc < 0)
			pr_err("get LG_cable_type error \r\n");
		else
			pr_info("msm_chg_LG_cable_type: %d \r\n", GET_INT32(ret.output));

	} while (rc < 0 && errCount++ < 3);

/* LGE_CHANGES_E [[email protected]] */

/* BEGIN: 0015327 [email protected] 20110204 */
/* MOD 0015327: [KERNEL] LG RAPI validity check */
	memset(output, 0, LG_RAPI_CLIENT_MAX_OUT_BUFF_SIZE);

	rc = lg_rapi_check_validity_and_copy_result((void*)&ret, output, arg.output_size);
/* END: 0015327 [email protected] 20110204 */

/* BEGIN: 0014591 [email protected] 20110122 */
/* MOD 0014591: [LG_RAPI] rpc request heap leakage bug fix */
	// free received buffers if it is not empty
	if (ret.output)
		kfree(ret.output);
	if (ret.out_len)
		kfree(ret.out_len);
/* END: 0014591 [email protected] 2011022 */
#endif 
	return (GET_INT32(output));  


}
int msm_chg_LG_cable_type(void)
{
char output[LG_RAPI_CLIENT_MAX_OUT_BUFF_SIZE];
	#if 0
	struct oem_rapi_client_streaming_func_arg arg;
	struct oem_rapi_client_streaming_func_ret ret;
//	char output[LG_RAPI_CLIENT_MAX_OUT_BUFF_SIZE];
	int rc= -1;
	int errCount= 0;

	Open_check();


	do 
	{
		arg.event = LG_FW_RAPI_CLIENT_EVENT_GET_LINE_TYPE;
		arg.cb_func = NULL;
		arg.handle = (void*) 0;
		arg.in_len = 0;
		arg.input = NULL;
		arg.out_len_valid = 1;
		arg.output_valid = 1;
		arg.output_size = 4;

		ret.output = NULL;
		ret.out_len = NULL;

		rc= oem_rapi_client_streaming_function(client, &arg, &ret);
	
		if (rc < 0)
			pr_err("get LG_cable_type error \r\n");
		else
			pr_info("msm_chg_LG_cable_type: %d \r\n", GET_INT32(ret.output));

	} while (rc < 0 && errCount++ < 3);


/* MOD 0015327: [KERNEL] LG RAPI validity check */
	memset(output, 0, LG_RAPI_CLIENT_MAX_OUT_BUFF_SIZE);

	rc = lg_rapi_check_validity_and_copy_result((void*)&ret, output, arg.output_size);

/* MOD 0014591: [LG_RAPI] rpc request heap leakage bug fix */
	// free received buffers if it is not empty
	if (ret.output)
		kfree(ret.output);
	if (ret.out_len)
		kfree(ret.out_len);
#endif 
	return (GET_INT32(output));  


}
int msm_get_manual_test_mode(void)
{
	struct oem_rapi_client_streaming_func_arg arg;
	struct oem_rapi_client_streaming_func_ret ret;
	char output[4];
	int rc= -1;
	byte temp = 0;

	Open_check();

	arg.event = LG_FW_MANUAL_TEST_MODE;
	arg.cb_func = NULL;
	arg.handle = (void*) 0;
	arg.in_len = sizeof(temp); 
	arg.input = &temp;
	//arg.in_len = 0;
	//arg.input = (char*) NULL;
	arg.out_len_valid = 1;
	arg.output_valid = 1;
	arg.output_size = 4;

	ret.output = NULL;
	ret.out_len = NULL;

	rc = oem_rapi_client_streaming_function(client, &arg, &ret);
	
/* BEGIN: 0015327 [email protected] 20110204 */
/* MOD 0015327: [KERNEL] LG RAPI validity check */
	if (rc < 0)
		pr_err("%s error \r\n", __func__);
	else
	{
		rc = lg_rapi_check_validity_and_copy_result((void*)&ret, (char*)output, arg.output_size);
		if(rc == LG_RAPI_INVALID_RESPONSE)
			memset(output,0,4);
		else
			printk(KERN_INFO "MANUAL_TEST_MODE nv : %d\n", GET_INT32(output));
	}
/* END: 0015327 [email protected] 20110204 */

	//memcpy(output,ret.output,*ret.out_len);

	if (ret.output)
		kfree(ret.output);
	if (ret.out_len)
		kfree(ret.out_len);

	return (GET_INT32(output));
}
int lg_get_hw_version(void)
{
	struct oem_rapi_client_streaming_func_arg arg;
	struct oem_rapi_client_streaming_func_ret ret;
	int pcb_ver;

	Open_check();

	arg.event = LG_FW_GET_PCB_VERSION;
	arg.cb_func = NULL;
	arg.handle = (void *)0;
	arg.in_len = 0;
	arg.input = NULL;
	arg.out_len_valid = 1;
	arg.output_valid = 1;
	arg.output_size = 4;

	ret.output = NULL;
	ret.out_len = NULL;

	oem_rapi_client_streaming_function(client, &arg, &ret);
	memcpy(&pcb_ver, ret.output, *ret.out_len);

	if (ret.output)
		kfree(ret.output);
	if (ret.out_len)
		kfree(ret.out_len);

	return GET_INT32(&pcb_ver);
}
Exemple #6
0
void remote_eri_rpc(void)
{
	struct oem_rapi_client_streaming_func_arg arg;
	struct oem_rapi_client_streaming_func_ret ret;
	int rc= -1;
	int errCount=0;
	int file_size=0;
	char fs_err_buf[20];

	memset(fs_err_buf, 0, sizeof(fs_err_buf));
	Open_check();

	do
	{
		arg.event = LGE_REQUEST_ERI_RPC;
		arg.cb_func = NULL;
		arg.handle = (void*) 0;
		arg.in_len = sizeof(fs_err_buf);
		arg.input = fs_err_buf;
		arg.out_len_valid = 1;
		arg.output_valid = 1;
		arg.output_size = sizeof(eri_data);

		ret.output = NULL;
		ret.out_len = NULL;

		rc = oem_rapi_client_streaming_function(client,&arg,&ret);

		memset(fs_err_buf, 0, sizeof(fs_err_buf));
		//if ((rc < 0) || (GET_INT32(ret.output) <=0))
		if (rc < 0)
			pr_err("%s error \r\n", __func__);
		else
		{
			pr_info("%s succeeded, file size : %s\r\n",__func__, fs_err_to_string(GET_INT32(ret.output), fs_err_buf));
			pr_info("%s succeeded\r\n",__func__);
		}
	}while (rc < 0 && errCount++ < 3);

	if(ret.output == NULL || ret.out_len == NULL){ 
		printk(KERN_ERR "%s, output is NULL\n",__func__);
		return;
	}
	memcpy((void *)eri_data, ret.output, *ret.out_len);
	file_size=(int)*ret.out_len;
	//memcpy((void *)dest, psrc->output, *(psrc->out_len));

	eri_factory_direct_write(ERI_FILE_PATH, (char *)&eri_data,file_size );

/*                                            */
/* MOD 0014591: [LG_RAPI] rpc request heap leakage bug fix */
	// free received buffers if it is not empty
	if (ret.output)
		kfree(ret.output);
	if (ret.out_len)
		kfree(ret.out_len);
/*                                         */
	
	return;
}
Exemple #7
0
void battery_info_get(struct batt_info* resp_buf)
{

	struct oem_rapi_client_streaming_func_arg arg;
	struct oem_rapi_client_streaming_func_ret ret;
	uint32_t out_len;
	int ret_val;
	struct batt_info rsp_buf;

	Open_check();

	arg.event = LG_FW_A2M_BATT_INFO_GET;
	arg.cb_func = NULL;
	arg.handle = (void*) 0;
	arg.in_len = 0;
	arg.input = NULL;
	arg.out_len_valid = 1;
	arg.output_valid = 1;
	arg.output_size = sizeof(rsp_buf);

	ret.output = (char*)&rsp_buf;
	ret.out_len = &out_len;

	ret_val = oem_rapi_client_streaming_function(client, &arg, &ret);
	if(ret_val == 0) {
		resp_buf->valid_batt_id = GET_U_INT32(&rsp_buf.valid_batt_id);
		resp_buf->batt_therm = GET_U_INT32(&rsp_buf.batt_therm);
		resp_buf->batt_temp = GET_INT32(&rsp_buf.batt_temp);
	} else { /* In case error */
		resp_buf->valid_batt_id = 1; /* authenticated battery id */
		resp_buf->batt_therm = 100;  /* 100 battery therm adc */
		resp_buf->batt_temp = 30;    /* 30 degree celcius */
	}
	return;
}
void remote_get_prl_version(int *info)
{
	struct oem_rapi_client_streaming_func_arg arg;
	struct oem_rapi_client_streaming_func_ret ret;
	int ret_val;
	int resp_buf;

	Open_check();

	arg.event = LG_FW_GET_PRL_VERSION;
	arg.cb_func = NULL;
	arg.handle = (void *)0;
	arg.in_len = 0;
	arg.input = NULL;
	arg.out_len_valid = 1;
	arg.output_valid = 1;
	arg.output_size = sizeof(int);

	ret.output = NULL;
	ret.out_len = NULL;

	ret_val = oem_rapi_client_streaming_function(client, &arg, &ret);
	if (ret_val == 0) {
		memcpy(&resp_buf, ret.output, *ret.out_len);
		*info = GET_INT32(&resp_buf);
	} else {
		*info = 0;	//default value
	}

	if (ret.output)
		kfree(ret.output);
	if (ret.out_len)
		kfree(ret.out_len);
}
void remote_get_charging_stat_realtime_update(int *info)
{
	struct oem_rapi_client_streaming_func_arg arg;
	struct oem_rapi_client_streaming_func_ret ret;
	int ret_val;
	int resp_buf;

	Open_check();

	arg.event = LG_FW_GET_CHARGING_STAT_REALTIME_UPDATE;
	arg.cb_func = NULL;
	arg.handle = (void *)0;
	arg.in_len = 0;
	arg.input = NULL;
	arg.out_len_valid = 1;
	arg.output_valid = 1;
	arg.output_size = sizeof(int);

	ret.output = NULL;
	ret.out_len = NULL;

	ret_val = oem_rapi_client_streaming_function(client, &arg, &ret);
	if (ret_val == 0) {
		memcpy(&resp_buf, ret.output, *ret.out_len);
		*info = GET_INT32(&resp_buf);
	} else {
		*info = 0;	//default value
	}

	if (ret.output)
		kfree(ret.output);
	if (ret.out_len)
		kfree(ret.out_len);
}
  JSBool
  ejsaudio_LTX_onLoad(JSContext* cx, JSObject* module)
  {
    AudioConfig ac;
    jsval val;

#define GET_STRING(prop) do{						\
      if (!ejs_evalExpression(cx,module,"ejs.config.Audio."#prop,&val))	\
	JS_ClearPendingException(cx);					\
      else{								\
	JSString* s=NULL;char *cstr=NULL;				\
	if ((!(s=JS_ValueToString(cx,val)))				\
	    || (!(cstr=JS_GetStringBytes(s)))) return JS_FALSE;		\
	ac.prop=cstr;							\
      }									\
    }while(0)

    GET_STRING(sdriver);
    GET_STRING(sdevice);
    
#define GET_INT32(prop) do{						\
      int32 i;								\
      if (!ejs_evalExpression(cx,module,"ejs.config.Audio."#prop,&val))	\
	JS_ClearPendingException(cx);					\
      else{								\
	if (!JS_ValueToECMAInt32(cx,val,&i)) return JS_FALSE;		\
	ac.prop=i;							\
      }									\
    }while(0)
    
    GET_INT32(srate);
    GET_INT32(sbits);
    GET_INT32(sbuffers);

    if (!ejs_evalExpression(cx,module,"ejs.config.Audio.stereo",&val))
      JS_ClearPendingException(cx);
    else{
      JSBool jsb;
      if (!JS_ValueToBoolean(cx, val, &jsb)) return JS_FALSE;
      ac.stereo=jsb;
    }

    Audio::init(ac);

    if (!JS_DefineFunctions(cx, module, static_methods)) return JS_FALSE;
    return JS_TRUE;
  }
int msm_chg_LG_cable_type(void)
{
	struct oem_rapi_client_streaming_func_arg arg;
	struct oem_rapi_client_streaming_func_ret ret;
	char output[LG_RAPI_CLIENT_MAX_OUT_BUFF_SIZE];
	int retValue = 0;
	int rc = -1;
	int errCount = 0;

	Open_check();

	do {
		arg.event = LG_FW_RAPI_CLIENT_EVENT_GET_LINE_TYPE;
		arg.cb_func = NULL;
		arg.handle = (void *)0;
		arg.in_len = 0;
		arg.input = NULL;
		arg.out_len_valid = 1;
		arg.output_valid = 1;
		arg.output_size = 4;

		ret.output = NULL;
		ret.out_len = NULL;

		rc = oem_rapi_client_streaming_function(client, &arg, &ret);
		if (rc < 0) {
			retValue = old_cable_type;
		} 
		else {
			memcpy(output, ret.output, *ret.out_len);
			retValue = GET_INT32(output);

			if (retValue == 0) // no init cable 
				retValue = old_cable_type;
			else //read ok.
				old_cable_type = retValue;
		}

		if (ret.output)
			kfree(ret.output);
		if (ret.out_len)
			kfree(ret.out_len);

	} while (rc < 0 && errCount++ < 3);

#ifdef CONFIG_MACH_MSM7X27_THUNDERC_SPRINT
	if (lge_bd_rev < HW_PCB_REV_B && retValue == 10) // LT_130K
		retValue = 0;
#endif

	printk("USB Cable type: %s(): %d\n", __func__, retValue);
	return retValue;
}
void battery_info_get(struct batt_info *resp_buf)
{
	struct oem_rapi_client_streaming_func_arg arg;
	struct oem_rapi_client_streaming_func_ret ret;
	int ret_val;
	struct batt_info rsp_buf;

	Open_check();

	arg.event = LG_FW_A2M_BATT_INFO_GET;
	arg.cb_func = NULL;
	arg.handle = (void *)0;
	arg.in_len = 0;
	arg.input = NULL;
	arg.out_len_valid = 1;
	arg.output_valid = 1;
	arg.output_size = sizeof(rsp_buf);

	ret.output = NULL;
	ret.out_len = NULL;

	ret_val = oem_rapi_client_streaming_function(client, &arg, &ret);
	if (ret_val == 0) {
		memcpy(&rsp_buf, ret.output, *ret.out_len);

		resp_buf->valid_batt_id = GET_U_INT32(&rsp_buf.valid_batt_id);
		resp_buf->batt_therm = GET_U_INT32(&rsp_buf.batt_therm);
		resp_buf->batt_temp = GET_INT32(&rsp_buf.batt_temp);
#if defined(CONFIG_MACH_MSM7X27_THUNDERC_SPRINT)
		resp_buf->chg_current = GET_U_INT32(&rsp_buf.chg_current);
		resp_buf->batt_thrm_state =
		    GET_U_INT32(&rsp_buf.batt_thrm_state);
#endif
	} else {		/* In case error */
		resp_buf->valid_batt_id = 1;	/* authenticated battery id */
		resp_buf->batt_therm = 100;	/* 100 battery therm adc */
		resp_buf->batt_temp = 30;	/* 30 degree celcius */
#if defined(CONFIG_MACH_MSM7X27_THUNDERC_SPRINT)
		resp_buf->chg_current = 0;
		resp_buf->batt_thrm_state = 0;
#endif
	}

	if (ret.output)
		kfree(ret.output);
	if (ret.out_len)
		kfree(ret.out_len);

}
void remote_eri_rpc(void)
{
	struct oem_rapi_client_streaming_func_arg arg;
	struct oem_rapi_client_streaming_func_ret ret;
	int rc= -1;
	int errCount= 0;
	char fs_err_buf[20];

	Open_check();

	do
	{
		arg.event = LGE_REQUEST_ERI_RPC;
		arg.cb_func = NULL;
		arg.handle = (void*) 0;
		arg.in_len = 0;
		arg.input = (char*) NULL;
		arg.out_len_valid = 1;
		arg.output_valid = 1;
		arg.output_size = 4;

		ret.output = (char*)NULL;
		ret.out_len = 0;

		rc = oem_rapi_client_streaming_function(client,&arg,&ret);

		memset(fs_err_buf, 0, sizeof(fs_err_buf));
		//if ((rc < 0) || (GET_INT32(ret.output) <=0))
		if (rc < 0)
			pr_err("%s error \r\n", __func__);
		else
		{
			pr_info("%s succeeded, file size : %s\r\n",__func__, fs_err_to_string(GET_INT32(ret.output), fs_err_buf));
			pr_info("%s succeeded\r\n",__func__);
		}
	}while (rc < 0 && errCount++ < 3);

/* BEGIN: 0014591 [email protected] 20110122 */
/* MOD 0014591: [LG_RAPI] rpc request heap leakage bug fix */
	// free received buffers if it is not empty
	if (ret.output)
		kfree(ret.output);
	if (ret.out_len)
		kfree(ret.out_len);
/* END: 0014591 [email protected] 2011022 */
	
	return;
}
int msm_chg_LG_cable_type(void)
{
    struct oem_rapi_client_streaming_func_arg arg;
    struct oem_rapi_client_streaming_func_ret ret;
    char output[LG_RAPI_CLIENT_MAX_OUT_BUFF_SIZE];

    Open_check();

    /* S_S [younsuk.song] 2010-09-06, Add error control code. Repeat 3 times if error occurs*/

    int rc= -1;
    int errCount= 0;

    do
    {
        arg.event = LG_FW_RAPI_CLIENT_EVENT_GET_LINE_TYPE;
        arg.cb_func = NULL;
        arg.handle = (void*) 0;
        arg.in_len = 0;
        arg.input = NULL;
        arg.out_len_valid = 1;
        arg.output_valid = 1;
        arg.output_size = 4;

        ret.output = NULL;
        ret.out_len = NULL;

        rc= oem_rapi_client_streaming_function(client, &arg, &ret);

    } while (rc < 0 && errCount++ < 3);

    /* S_E [younsuk.song] */

    memcpy(output,ret.output,*ret.out_len);

    kfree(ret.output);
    kfree(ret.out_len);

    return (GET_INT32(output));
}
void remote_get_ftm_boot(int *info)
{
	struct oem_rapi_client_streaming_func_arg arg;
	struct oem_rapi_client_streaming_func_ret ret;
	int ret_val;
	int resp_buf;
	int errCount = 0;

	Open_check();

	do {
		arg.event = LG_FW_GET_FTM_BOOT;
		arg.cb_func = NULL;
		arg.handle = (void *)0;
		arg.in_len = 0;
		arg.input = NULL;
		arg.out_len_valid = 1;
		arg.output_valid = 1;
		arg.output_size = sizeof(int);

		ret.output = NULL;
		ret.out_len = NULL;

		ret_val = oem_rapi_client_streaming_function(client, &arg, &ret);
		if (ret_val == 0) {
			memcpy(&resp_buf, ret.output, *ret.out_len);
			*info = GET_INT32(&resp_buf);
		} else {
			*info = 0;	//default value
		}

		if (ret.output)
			kfree(ret.output);
		if (ret.out_len)
			kfree(ret.out_len);

	} while (ret_val < 0 && errCount++ < 3);
}
Exemple #16
0
PUBLIC int SpExit()
{
   BUFFER_DECLARATIONS;
   long Status;
   
   DEBUG(( "SP.EXIT" ));
   INIT_BUFFERS;
   
   GET_INT32( Status );
   DEBUG(( "%ld", Status ));

   if( Status == 999999999 )
      Status = TERMINATE_OK_EXIT;
   else if( Status == -999999999 )
      Status = TERMINATE_FAIL_EXIT;
   else
      Status = TERMINATE_OTHER_STATUS;

   DEBUG(( "exit with %d", (int)Status ));

   PUT_BYTE( SP_SUCCESS );
   REPLY ( (int)Status );
}
Exemple #17
0
int s3g_command_read_ext(s3g_context_t *ctx, s3g_command_t *cmd,
			 unsigned char *buf, size_t maxbuf, size_t *buflen)
{
     unsigned char *buf0 = buf;
     ssize_t bytes_expected, bytes_read;
     s3g_command_info_t *ct;
     s3g_command_t dummy;
     foo_32_t f32;
     int iret;
     uint8_t ui8arg;

     iret = -1;

     if (buflen)
	  *buflen = 0;

     // We have to have a read context
     // We don't need a command context to return the command in
     if (!ctx || !buf || maxbuf == 0)
     {
	  fprintf(stderr, "s3g_command_get(%d): Invalid call; ctx=%p, buf=%p, "
		  "maxbuf=%u\n", __LINE__, (void *)ctx, (void *)buf, maxbuf);
	  errno = EINVAL;
	  return(-1);
     }
     else if (!ctx->read)
     {
	  fprintf(stderr, "s3g_command_get(%d): Invalid context; "
		  "ctx->read=NULL\n", __LINE__);
	  errno = EINVAL;
	  return(-1);
     }
     else if (!buf || maxbuf == 0)
     {
	  fprintf(stderr, "s3g_command_get(%d): Invalid context; "
		  "ctx->read=NULL\n", __LINE__);
	  errno = EINVAL;
	  return(-1);
     }

     // Initialize command table
     s3g_init();

     if (1 != (bytes_expected = (*ctx->read)(ctx->rw_ctx, buf, maxbuf, 1)))
     {
	  // End of file condition?
	  if (bytes_expected == 0)
	       return(1); // EOF

	  fprintf(stderr,
		  "s3g_command_get(%d): Error while reading from the s3g file; "
		  "%s (%d)\n",
		  __LINE__, strerror(errno), errno);
	  return(-1);
     }

     ct = command_table + buf[0];  // &command_table[buf[0]]

     buf    += 1;
     maxbuf -= 1;

     if (!cmd)
	  cmd = &dummy;

     cmd->cmd_id   = ct->cmd_id;
     cmd->cmd_name = ct->cmd_name;
     cmd->cmd_len  = ct->cmd_len;

     if (ct->cmd_name == NULL)
     {
	  fprintf(stderr,
		  "s3g_command_get(%d): Unrecognized command, %d\n",
		  __LINE__, buf[0]);
	  goto done;
     }

     switch(cmd->cmd_id)
     {
     default :
     case HOST_CMD_CHANGE_TOOL :
     case HOST_CMD_ENABLE_AXES :
     case HOST_CMD_SET_POSITION :
     case HOST_CMD_DELAY :
     case HOST_CMD_FIND_AXES_MINIMUM :
     case HOST_CMD_FIND_AXES_MAXIMUM :
     case HOST_CMD_WAIT_FOR_TOOL :
     case HOST_CMD_WAIT_FOR_PLATFORM :
     case HOST_CMD_STORE_HOME_POSITION :
     case HOST_CMD_RECALL_HOME_POSITION :
     case HOST_CMD_SET_MAX_ACCEL :
     case HOST_CMD_SET_MAX_FEEDRATE :
     case HOST_CMD_SET_DEFAULT_ACCEL :
     case HOST_CMD_SET_ADVANCED_ACCEL :
     case HOST_CMD_SET_ADVANCED_ACCEL2 :
     case HOST_CMD_SET_ADVANCE_K :
     case HOST_CMD_SET_EXTRUDER_STEPSMM :
     case HOST_CMD_SET_ACCELERATION :
     case HOST_CMD_MOOD_LIGHT_SET_RGB :
     case HOST_CMD_MOOD_LIGHT_SET_HSB :
     case HOST_CMD_MOOD_LIGHT_PLAY_SCRIPT :
     case HOST_CMD_BUZZER_REPEATS :
     case HOST_CMD_BUZZER_BUZZ :
     case HOST_CMD_SET_AXIS_STEPS_MM :
	  // Just read the data
	  bytes_expected = (ssize_t)(ct->cmd_len & 0x7fffffff);
	  if ((bytes_read = (*ctx->read)(ctx->rw_ctx, buf, maxbuf,
					 ct->cmd_len)) != bytes_expected)
	       goto io_error;

	  buf    += bytes_read;
	  maxbuf -= bytes_read;
	  break;

#define GET_INT32(v) \
	  if (maxbuf < 4) goto trunc; \
	  if (4 != (bytes_read = (*ctx->read)(ctx->rw_ctx, buf, maxbuf, 4))) \
	       goto io_error; \
	  memcpy(&f32.u.c, buf, 4); \
	  buf    += bytes_read; \
	  maxbuf -= bytes_read; \
	  cmd->t.v = f32.u.i

#define GET_UINT8(v) \
	  if (maxbuf < 1) goto trunc; \
	  if (1 != (bytes_read = (*ctx->read)(ctx->rw_ctx, buf, maxbuf, 1))) \
	       goto io_error; \
	  ui8arg = buf[0]; \
	  buf    += bytes_read; \
	  maxbuf -= bytes_read; \
	  cmd->t.v = ui8arg

#define ZERO(v,c) cmd->t.v = (c)0

     case HOST_CMD_TOOL_COMMAND :
	  // This command is VERY MBI specific
	  if ((ssize_t)3 != (*ctx->read)(ctx->rw_ctx, buf, maxbuf, 3))
	       goto io_error;
	  if (cmd)
	       cmd->cmd_len = (size_t)buf[2];
	  cmd->t.tool.subcmd_id  = buf[1];
	  cmd->t.tool.index      = buf[0];
	  cmd->t.tool.subcmd_len = bytes_expected = (ssize_t)buf[2];
	  if ((bytes_read = (*ctx->read)(ctx->rw_ctx, buf + 3, maxbuf - 3,
					 (size_t)buf[2])) != bytes_expected)
	       goto io_error;

	  if (cmd->t.tool.subcmd_len == 1)
	       cmd->t.tool.subcmd_value = (uint16_t)buf[3];
	  else if (cmd->t.tool.subcmd_len > 1)
	       memcpy((void *)&cmd->t.tool.subcmd_value, buf + 3, sizeof(uint16_t));
	  else
	       cmd->t.tool.subcmd_value = 0;

	  maxbuf -= 3 + bytes_read;
	  buf    += 3 + bytes_read;

	  switch (cmd->t.tool.subcmd_id)
	  {
	  case SLAVE_CMD_SET_TEMP :
	       cmd->t.tool.subcmd_name = "set temperature";
	       break;

	  case SLAVE_CMD_SET_PLATFORM_TEMP :
	       cmd->t.tool.subcmd_name = "set platform temperature";
	       break;

	  case SLAVE_CMD_SET_MOTOR_1_PWM :
	       cmd->t.tool.subcmd_name = "set motor 1 PWM";
	       break;

	  case SLAVE_CMD_TOGGLE_MOTOR_1 :
	       cmd->t.tool.subcmd_name = "toggle motor 1";
	       break;

	  case SLAVE_CMD_TOGGLE_ABP :
	       cmd->t.tool.subcmd_name = "toggle ABP";
	       break;

	  case SLAVE_CMD_TOGGLE_VALVE :
	       if (cmd->t.tool.subcmd_value == 0)
		    cmd->t.tool.subcmd_name = "segment acceleration off";
	       else
		    cmd->t.tool.subcmd_name = "segment acceleration on";
	       break;

	  default :
	       cmd->t.tool.subcmd_name = "unknown subcommand";
	       break;
	  }
	  break;

     case HOST_CMD_SET_POSITION_EXT :
	  // x4, y4, z4, a4, b4 = 20 bytes
	  GET_INT32(set_position_ext.x);
	  GET_INT32(set_position_ext.y);
	  GET_INT32(set_position_ext.z);
	  GET_INT32(set_position_ext.a);
	  GET_INT32(set_position_ext.b);
	  break;

     case HOST_CMD_QUEUE_POINT_EXT :
	  // x4, y4, z4, a4, b4, dda4 = 24 bytes
	  GET_INT32(queue_point_ext.x);
	  GET_INT32(queue_point_ext.y);
	  GET_INT32(queue_point_ext.z);
	  GET_INT32(queue_point_ext.a);
	  GET_INT32(queue_point_ext.b);
	  GET_INT32(queue_point_ext.dda);
	  ZERO(queue_point_ext.dummy_rel, uint8_t);
	  break;

     case HOST_CMD_QUEUE_POINT_NEW :
	  // x4, y4, z4, a4, b4, us4, relative = 25 bytes
	  GET_INT32(queue_point_new.x);
	  GET_INT32(queue_point_new.y);
	  GET_INT32(queue_point_new.z);
	  GET_INT32(queue_point_new.a);
	  GET_INT32(queue_point_new.b);
	  GET_INT32(queue_point_new.us);
	  GET_UINT8(queue_point_new.rel);
	  break;

     case HOST_CMD_QUEUE_POINT_ABS :
	  // x4, y4, z4, dda4 = 16 bytes
	  GET_INT32(queue_point_abs.x);
	  GET_INT32(queue_point_abs.y);
	  GET_INT32(queue_point_abs.z);
	  GET_INT32(queue_point_abs.dda);
	  ZERO(queue_point_abs.dummy_a, int32_t);
	  ZERO(queue_point_abs.dummy_b, int32_t);
	  ZERO(queue_point_abs.dummy_rel, uint8_t);
	  break;
     }

#undef ZERO
#undef GET_UINT8
#undef GET_INT32

     iret = 0;
     goto done;

io_error:
     fprintf(stderr,
	     "s3g_command_get(%d): Error while reading from the s3g file; "
	     "%s (%d)\n",
	     __LINE__, strerror(errno), errno);
     iret = -1;
     goto done;

trunc:
     fprintf(stderr,
	     "s3g_command_get(%d): Caller supplied read buffer is too small",
	     __LINE__);
     iret = -1;

done:
     if (buflen)
	  *buflen = (size_t)(buf - buf0);

     return(iret);
}
Exemple #18
0
void remote_did_rpc(void)
{
	struct oem_rapi_client_streaming_func_arg arg;
	struct oem_rapi_client_streaming_func_ret ret;
	int rc= -1;
	
	//int file_size=0;
	char fs_err_buf[20];
	//test_mode_emmc_direct_type did_info;

	const MmcPartition *pMisc_part; 
	unsigned int did_bytes_pos_in_emmc ;
	 int mtd_op_result ;
	

	printk(KERN_ERR "%s, start OEM_RAPI\n",__func__);
	//memset(&did_info,0x0,sizeof(test_mode_emmc_direct_type));
	
	//memset(fs_err_buf, 0, sizeof(fs_err_buf));

	Open_check();

		arg.event = LG_FW_DID_BACKUP_REQUEST;
		arg.cb_func = NULL;
		arg.handle = (void*) 0;
		arg.in_len =  sizeof(fs_err_buf);
		arg.input =fs_err_buf;
		arg.out_len_valid = 1;
		arg.output_valid = 1;
		arg.output_size = sizeof(pbuf_emmc);

		ret.output = NULL;
		ret.out_len = NULL;

		rc = oem_rapi_client_streaming_function(client,&arg,&ret);
		#if 0
		memset(fs_err_buf, 0, sizeof(fs_err_buf));
		//if ((rc < 0) || (GET_INT32(ret.output) <=0))
		if (rc < 0)
			pr_err("%s error \r\n", __func__);
		else
		{
			pr_info("%s succeeded, file size : %s\r\n",__func__, fs_err_to_string(GET_INT32(ret.output), fs_err_buf));
			pr_info("%s succeeded\r\n",__func__);
		}
		#endif 
		
	if(ret.output == NULL || ret.out_len == NULL){ 
		printk(KERN_ERR "%s, output is NULL\n",__func__);
		return;
	}	

	
	printk(KERN_ERR "%s, output lenght =%dis\n",__func__,*ret.out_len);	
	//memcpy(&did_info, ret.output, *ret.out_len);
	memcpy((void *)&pbuf_emmc2[0], ret.output, 192);  //form modem  length =192

	
//===================== emmc wirte routine =======================
	printk(KERN_ERR "%s, lge_mmc_scan_partitions\n",__func__);  
	lge_mmc_scan_partitions();
	pMisc_part = lge_mmc_find_partition_by_name("misc");
	printk(KERN_ERR "%s, lge_mmc_find_partition_by_name\n",__func__);  
	if (pMisc_part ==NULL)
	{
		if (ret.output)
		kfree(ret.output);
		if (ret.out_len)
		kfree(ret.out_len);
		return ; 
	}
	
	did_bytes_pos_in_emmc = (pMisc_part->dfirstsec)*512+0x300000;  //3M 
	memset((void *)pbuf_emmc, 0, sizeof(pbuf_emmc));  
	
	mtd_op_result = lge_read_block(did_bytes_pos_in_emmc, pbuf_emmc, 192);
	//printk(KERN_ERR "%s,lge_read_block\n",__func__);  
	//if(memcmp((void *)pbuf_emmc,(void *)ret.output, sizeof(pbuf_emmc)) != 0) 
	if(memcmp((void *)pbuf_emmc,(void *)pbuf_emmc2, sizeof(pbuf_emmc)) != 0) 
	{
	  //printk(KERN_ERR "%s,lge_write_block0\n",__func__);  
	  lge_write_block(did_bytes_pos_in_emmc, pbuf_emmc2, 192);	
	 // printk(KERN_ERR "%s,lge_write_block1\n",__func__);  
	}

//=============================================================			

/* BEGIN: 0014591 [email protected] 20110122 */
/* MOD 0014591: [LG_RAPI] rpc request heap leakage bug fix */
	// free received buffers if it is not empty
	if (ret.output)
		kfree(ret.output);
	if (ret.out_len)
		kfree(ret.out_len);
/* END: 0014591 [email protected] 2011022 */
	
	return;
}
int msm_chg_LG_cable_type(void)
{
char output[LG_RAPI_CLIENT_MAX_OUT_BUFF_SIZE]={0,};
	return (GET_INT32(output));
}
int s3g_command_read_ext(s3g_context_t *ctx, s3g_command_t *cmd,
			 unsigned char *buf, size_t maxbuf, size_t *buflen)
{
     unsigned char *buf0 = buf;
     ssize_t bytes_expected, bytes_read;
     s3g_command_info_t *ct;
     s3g_command_t dummy;
     foo_16_t f16;
     foo_32_t f32;
     int iret;
     uint8_t ui8arg;

     iret = -1;

     if (buflen)
	  *buflen = 0;

     // We have to have a read context
     // We don't need a command context to return the command in
     if (!ctx || !buf || maxbuf == 0)
     {
	  fprintf(stderr, "s3g_command_get(%d): Invalid call; ctx=%p, buf=%p, "
		  "maxbuf=%lu\n", __LINE__, (void *)ctx, (void *)buf, maxbuf);
	  errno = EINVAL;
	  return(-1);
     }
     else if (!ctx->read)
     {
	  fprintf(stderr, "s3g_command_get(%d): Invalid context; "
		  "ctx->read=NULL\n", __LINE__);
	  errno = EINVAL;
	  return(-1);
     }
     else if (!buf || maxbuf == 0)
     {
	  fprintf(stderr, "s3g_command_get(%d): Invalid context; "
		  "ctx->read=NULL\n", __LINE__);
	  errno = EINVAL;
	  return(-1);
     }

     // Initialize command table
     s3g_init();

     if (1 != (bytes_expected = (*ctx->read)(ctx->r_ctx, buf0, maxbuf, 1)))
     {
	  // End of file condition?
	  if (bytes_expected == 0)
	       return(1); // EOF

	  fprintf(stderr,
		  "s3g_command_get(%d): Error while reading from the s3g file; "
		  "%s (%d)\n",
		  __LINE__, strerror(errno), errno);
	  return(-1);
     }

     ct = command_table + buf0[0];  // &command_table[buf0[0]]

     buf    += 1;
     maxbuf -= 1;

     if (!cmd)
	  cmd = &dummy;

     cmd->cmd_id      = ct->cmd_id;
     cmd->cmd_desc    = ct->cmd_desc;
     cmd->cmd_len     = ct->cmd_len;
     cmd->cmd_raw_len = 0;

     if (ct->cmd_desc == NULL)
     {
	  fprintf(stderr,
		  "s3g_command_get(%d): Unrecognized command, %d\n",
		  __LINE__, buf0[0]);
	  goto done;
     }

#define GET_INT32(v) \
	  if (maxbuf < 4) goto trunc; \
	  if (4 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 4))) \
	       goto io_error; \
	  memcpy(&f32.u.c, buf, 4); \
	  buf    += bytes_read; \
	  maxbuf -= bytes_read; \
	  cmd->t.v = f32.u.i

#define GET_UINT32(v) \
	  if (maxbuf < 4) goto trunc; \
	  if (4 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 4))) \
	       goto io_error; \
	  memcpy(&f32.u.c, buf, 4); \
	  buf    += bytes_read; \
	  maxbuf -= bytes_read; \
	  cmd->t.v = f32.u.u

#define GET_FLOAT32(v) \
	  if (maxbuf < 4) goto trunc; \
	  if (4 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 4))) \
	       goto io_error; \
	  memcpy(&f32.u.c, buf, 4); \
	  buf    += bytes_read; \
	  maxbuf -= bytes_read; \
	  cmd->t.v = f32.u.f;

#define GET_UINT8(v) \
	  if (maxbuf < 1) goto trunc; \
	  if (1 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 1))) \
	       goto io_error; \
	  ui8arg = buf[0]; \
	  buf    += bytes_read; \
	  maxbuf -= bytes_read; \
	  cmd->t.v = ui8arg

#define GET_INT16(v) \
	  if (maxbuf < 2) goto trunc; \
	  if (2 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 2))) \
	       goto io_error; \
	  memcpy(&f16.u.c, buf, 2); \
	  buf    += bytes_read; \
	  maxbuf -= bytes_read; \
	  cmd->t.v = f16.u.i

#define GET_UINT16(v) \
	  if (maxbuf < 2) goto trunc; \
	  if (2 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 2))) \
	       goto io_error; \
	  memcpy(&f16.u.c, buf, 2); \
	  buf    += bytes_read; \
	  maxbuf -= bytes_read; \
	  cmd->t.v = f16.u.u

#define ZERO(v,c) cmd->t.v = (c)0

     switch(cmd->cmd_id)
     {
     case HOST_CMD_DELAY :
	  GET_UINT32(delay.millis);
	  break;

     case HOST_CMD_FIND_AXES_MINIMUM :
     case HOST_CMD_FIND_AXES_MAXIMUM :
	  GET_UINT8(find_axes_minmax.flags);
	  GET_UINT32(find_axes_minmax.feedrate);
	  GET_UINT16(find_axes_minmax.timeout);
	  break;

     case HOST_CMD_WAIT_FOR_TOOL :
	  GET_UINT8(wait_for_tool.index);
	  GET_UINT16(wait_for_tool.ping_delay);
	  GET_UINT16(wait_for_tool.timeout);
	  break;

     case HOST_CMD_WAIT_FOR_PLATFORM :
	  GET_UINT8(wait_for_platform.index);
	  GET_UINT16(wait_for_platform.ping_delay);
	  GET_UINT16(wait_for_platform.timeout);
	  break;

     case HOST_CMD_STORE_HOME_POSITION :
	  GET_UINT8(store_home_position.axes);
	  break;

     case HOST_CMD_RECALL_HOME_POSITION :
	  GET_UINT8(recall_home_position.axes);
	  break;

     default :
	  // Just read the data
	  bytes_expected = (ssize_t)(ct->cmd_len & 0x7fffffff);
	  if ((bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf,
					 ct->cmd_len)) != bytes_expected)
	       goto io_error;

	  buf    += bytes_read;
	  maxbuf -= bytes_read;
	  break;

     case HOST_CMD_TOOL_COMMAND :
	  // This command is VERY MBI specific
	  if ((ssize_t)3 != (*ctx->read)(ctx->r_ctx, buf, maxbuf, 3))
	       goto io_error;
	  if (cmd)
	       cmd->cmd_len = (size_t)buf[2];
	  cmd->t.tool.subcmd_id  = buf[1];
	  cmd->t.tool.index      = buf[0];
	  cmd->t.tool.subcmd_len = bytes_expected = (ssize_t)buf[2];
	  if ((bytes_read = (*ctx->read)(ctx->r_ctx, buf + 3, maxbuf - 3,
					 (size_t)buf[2])) != bytes_expected)
	       goto io_error;

	  if (cmd->t.tool.subcmd_len == 1)
	       cmd->t.tool.subcmd_value = (uint16_t)buf[3];
	  else if (cmd->t.tool.subcmd_len > 1)
	       memcpy((void *)&cmd->t.tool.subcmd_value, buf + 3, sizeof(uint16_t));
	  else
	       cmd->t.tool.subcmd_value = 0;

	  maxbuf -= 3 + bytes_read;
	  buf    += 3 + bytes_read;

	  cmd->t.tool.subcmd_desc = tool_command_table[cmd->t.tool.subcmd_id].cmd_desc;
	  if (cmd->t.tool.subcmd_desc == NULL)
	       cmd->t.tool.subcmd_desc = "unknown tool subcommand";
	  break;

     case HOST_CMD_SET_POSITION_EXT :
	  // x4, y4, z4, a4, b4 = 20 bytes
	  GET_INT32(set_position_ext.x);
	  GET_INT32(set_position_ext.y);
	  GET_INT32(set_position_ext.z);
	  GET_INT32(set_position_ext.a);
	  GET_INT32(set_position_ext.b);
	  break;

     case HOST_CMD_QUEUE_POINT_EXT :
	  // x4, y4, z4, a4, b4, dda4 = 24 bytes
	  GET_INT32(queue_point_ext.x);
	  GET_INT32(queue_point_ext.y);
	  GET_INT32(queue_point_ext.z);
	  GET_INT32(queue_point_ext.a);
	  GET_INT32(queue_point_ext.b);
	  GET_INT32(queue_point_ext.dda);
	  ZERO(queue_point_ext.dummy_rel, uint8_t);
	  ZERO(queue_point_ext.dummy_distance, float);
	  ZERO(queue_point_ext.dummy_feedrate_mult_64, uint16_t);
	  break;

     case HOST_CMD_QUEUE_POINT_NEW :
	  // x4, y4, z4, a4, b4, us4, relative = 25 bytes
	  GET_INT32(queue_point_new.x);
	  GET_INT32(queue_point_new.y);
	  GET_INT32(queue_point_new.z);
	  GET_INT32(queue_point_new.a);
	  GET_INT32(queue_point_new.b);
	  GET_INT32(queue_point_new.us);
	  GET_UINT8(queue_point_new.rel);
	  ZERO(queue_point_ext.dummy_distance, float);
	  ZERO(queue_point_ext.dummy_feedrate_mult_64, uint16_t);
	  break;

     case HOST_CMD_QUEUE_POINT_NEW_EXT :
	  // x4, y4, z4, a4, b4, dda_rate4, relative, distance 4, feedrate_mult64 2 = 31 bytes
	  GET_INT32(queue_point_new_ext.x);
	  GET_INT32(queue_point_new_ext.y);
	  GET_INT32(queue_point_new_ext.z);
	  GET_INT32(queue_point_new_ext.a);
	  GET_INT32(queue_point_new_ext.b);
	  GET_INT32(queue_point_new_ext.dda_rate);
	  GET_UINT8(queue_point_new_ext.rel);
	  GET_FLOAT32(queue_point_new_ext.distance);
	  GET_INT16(queue_point_new_ext.feedrate_mult_64);
	  break;

     case HOST_CMD_SET_POT_VALUE :
	  GET_UINT8(digi_pot.axis);
	  GET_UINT8(digi_pot.value);
	  break;

     case HOST_CMD_SET_RGB_LED :
	  GET_UINT8(rgb_led.red);
	  GET_UINT8(rgb_led.green);
	  GET_UINT8(rgb_led.blue);
	  GET_UINT8(rgb_led.blink_rate);
	  GET_UINT8(rgb_led.effect);
	  break;

     case HOST_CMD_SET_BEEP :
	  GET_UINT16(beep.frequency);
	  GET_UINT16(beep.duration);
	  GET_UINT8(beep.effect);
	  break;

     case HOST_CMD_PAUSE_FOR_BUTTON :
	  GET_UINT8(button_pause.mask);
	  GET_UINT16(button_pause.timeout);
	  GET_UINT8(button_pause.timeout_behavior);
	  break;

     case HOST_CMD_DISPLAY_MESSAGE :
	  GET_UINT8(display_message.options);
	  GET_UINT8(display_message.x);
	  GET_UINT8(display_message.y);
	  GET_UINT8(display_message.timeout);
	  cmd->t.display_message.message_len = 0;
	  if (maxbuf < 1) goto trunc;
	  for (;;)
	  {
	       unsigned char uc;
	       if (1 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 1)))
		    goto io_error;
	       uc = buf[0];
	       ++buf;
	       --maxbuf;
	       if (uc == '\0')
		    break;
	       if (cmd->t.display_message.message_len < (sizeof(cmd->t.display_message.message) - 1))
		    cmd->t.display_message.message[cmd->t.display_message.message_len++] = uc;
	       if (maxbuf < 1) goto trunc;
	  }
	  cmd->t.display_message.message[cmd->t.display_message.message_len] = '\0';
	  break;

     case HOST_CMD_SET_BUILD_PERCENT :
	  GET_UINT8(build_percentage.percentage);
	  GET_UINT8(build_percentage.reserved);
	  break;

     case HOST_CMD_QUEUE_SONG :
	  GET_UINT8(queue_song.song_id);
	  break;

     case HOST_CMD_RESET_TO_FACTORY :
	  GET_UINT8(factory_reset.options);
	  break;

     case HOST_CMD_BUILD_START_NOTIFICATION :
	  GET_INT32(build_start.steps);
	  cmd->t.build_start.message_len = 0;
	  if (maxbuf < 1) goto trunc;
	  for (;;)
	  {
	       unsigned char uc;
	       if (1 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 1)))
		    goto io_error;
	       uc = buf[0];
	       ++buf;
	       --maxbuf;
	       if (uc == '\0')
		    break;
	       if (cmd->t.build_start.message_len < (sizeof(cmd->t.build_start.message) - 1))
		    cmd->t.build_start.message[cmd->t.build_start.message_len++] = uc;
	  }
	  cmd->t.build_start.message[cmd->t.build_start.message_len] = '\0';
	  break;

     case HOST_CMD_BUILD_END_NOTIFICATION :
	  GET_UINT8(build_end.flags);
	  break;

     case HOST_CMD_CHANGE_TOOL :
	  GET_UINT8(change_tool.index);
          break;

     case HOST_CMD_ENABLE_AXES :
	  GET_UINT8(enable_axes.axes);
          break;

     case HOST_CMD_SET_ACCELERATION_TOGGLE:
	  GET_UINT8(set_segment_acceleration.s);
	  break;

     case HOST_CMD_STREAM_VERSION:
	  GET_UINT8(x3g_version.version_high);
	  GET_UINT8(x3g_version.version_low);
	  GET_UINT8(x3g_version.reserved1);
	  GET_UINT32(x3g_version.reserved2);
	  GET_UINT16(x3g_version.bot_type);
	  GET_UINT16(x3g_version.reserved3);
	  GET_UINT32(x3g_version.reserved4);
	  GET_UINT32(x3g_version.reserved5);
	  GET_UINT8(x3g_version.reserved6);
	  break;
     }

#undef ZERO
#undef GET_UINT8
#undef GET_INT32

     iret = 0;
     goto done;

io_error:
     fprintf(stderr,
	     "s3g_command_get(%d): Error while reading from the s3g file; "
	     "%s (%d)\n",
	     __LINE__, strerror(errno), errno);
     iret = -1;
     goto done;

trunc:
     fprintf(stderr,
	     "s3g_command_get(%d): Caller supplied read buffer is too small",
	     __LINE__);
     iret = -1;

done:
     cmd->cmd_raw_len = (size_t)(buf - buf0);
     if (buflen)
	  *buflen = cmd->cmd_raw_len;

     return(iret);
}