Beispiel #1
0
cap_cx *cap_new(char *err)
{
	cap_cx *cx;

	set_err("Out of memory");

	if((cx = malloc(sizeof(cap_cx))))
	{
		memset(cx, 0, sizeof(cap_cx));
		if((cx->hwnd = cap_create_hwnd(err)))
		{
			if(cap_assoc_set(cx->hwnd, cx))
			{
				if(cap_configure(cx, err))
				{
					set_err("");
					return cx;
				}
			}
			DestroyWindow(cx->hwnd);
		}
		free(cx);
	}

	return NULL;
}
Beispiel #2
0
aud_out *aud_outopen(int device, int samplerate, int channels, char *err)
{
	aud_out *cx;
	wv_format fmt;

	if((channels == 1) || (channels == 2))
	{
		if((cx = malloc(sizeof(aud_out))))
		{
			memset(cx, 0, sizeof(aud_out));
			fmt.samplerate = samplerate;
			fmt.samplebits = 16;
			fmt.channels = channels;
			if((cx->wvout = wv_outopen(device, &fmt)))
			{
				cx->samplerate = samplerate;
				cx->channels = channels;
				set_err("");
				return cx;
			}
			free(cx);
		}
	}

	set_err("Can't open audio output device");
	return NULL;
}
Beispiel #3
0
/**
 * Handle a DFU_UPLOAD request.
 *
 * @param[in]  block_num The block sequence number.
 * @param[in]  req_len   The size of the block, i.e., the amount of data the
 * 			 host is requesting.
 * @param[out] data	 The buffer where to write the requested data.
 * @param[out] data_len  The actual amount of data provided by the host (the
 * 			 device shall never provide more data then req_len,
 * 			 while it can provide less data to notify the host
 * 			 that it has no more data to send).
 *
 * @return  0 if no error has occurred, an error code otherwise.
 */
int dfu_process_upload(uint16_t block_num, uint16_t req_len, uint8_t *data,
		       uint16_t *data_len)
{
	switch (dfu_state) {
	case DFU_STATE_DFU_IDLE:
		block_cnt = 0;
		next_block_num = block_num;
		break;
	case DFU_STATE_DFU_UPLOAD_IDLE:
		break;
	default:
		set_err(DFU_STATUS_ERR_STALLEDPKT);
		return -EIO;
	}
	if (block_num != next_block_num) {
		/*
		 * NOTE: this check is not mentioned in the DFU spec;
		 * should we keep it?
		 */
		set_err(DFU_STATUS_ERR_VENDOR);
		return -EIO;
	}
	dfu_rh->fill_upload_blk(block_cnt, data, req_len, data_len);
	next_block_num = block_num + 1;
	block_cnt++;
	/* if the device write less bytes than required then upload is over */
	if (*data_len < req_len) {
		dfu_state = DFU_STATE_DFU_IDLE;
	} else {
		dfu_state = DFU_STATE_DFU_UPLOAD_IDLE;
	}

	return 0;
}
Beispiel #4
0
int
create_mailbox(char *box_name, int box_size,
               int (* async_func) (int *box_id, char *box_name,
               char *message_address, int message_length) )
{
/* int status;*/
 int index;
 int shmid;
 

 /* Test function security */

 if (async_func == NULL) {
  set_err (EFAULT);
  return (0);  /* Verifies function exists */
 }

 if (box_size == 0){
  set_err (EINVAL);
  return (0);
 }

 if (box_name == NULL) {
  set_err (EFAULT);
  return (0);
 }

 index = alloc_entry();               /* Find an entry for id_table */
 if (index == -1) {
  set_err(EMFILE);
  keep_clean();
  return(0);
 }

 if (max_mail == 1 && index > 0) {  /* If only one mail box authorized */
  set_err (EMFILE);
  return(0);
 }

 /* Create shared memory for the process */

 shmid = create_sharedmemory ( &id_table[index].address, box_name, box_size);
 if (shmid == 0) return (0);


 put_pid (index);    /* Put pid of server into shared memory  */

 id_table[index].channel = shmid;              /* Keep id of shared memory */
 id_table[index].size = box_size;              /* Keep size of mail box */
 strncpy(id_table[index].name,box_name,SIZEOFNAME);    /* Keep name of mail box */
 id_table[index].user_func = async_func;       /* Keep user function */


 /* Install asynchronous function : AST function */

  signal (SIGUSR1,  handler); 

 nb_mail++;          
 return (index);
}
Beispiel #5
0
int
remove_mailbox(int *boxid, char *box_name)
{
 if (boxid == 0){
  set_err(EINVAL);
  return (0);
 }

 if (box_name == NULL) {
  set_err(EFAULT);
  return (0);
 }


/*  (*boxid)--; JPT */

 nb_mail--;

 /* If last mail box removed, remove special shared memory */

 if (nb_mail == 0) keep_clean(); 

 remove_sharedmemory (&id_table[*boxid].channel, box_name );  /* Close shared memory */
 id_table[*boxid].address = NULL;

 return (1);
}
Beispiel #6
0
Ref kernel_call(ref_list args){
	if (args->length != 1){
		set_err(ETYPE, "too many arguments");
		return NULL;	
	}
	
	if (arg_isMatrix(args->list[0]) == false) return NULL;
	
	Matrix M = CAST_REF2MATRIX(args->list[0]);

	if (M->nrows != M->ncols) {
		set_err(ETYPE, "not a square Matrix");
		return NULL;
	}

	Matrix K;
	if ( noyau(M, &K) == 0 ) return NULL;
	
	/* Print kernel */
	unsigned int i,j;
	printf("\n");
	for(i = 0 ; i < K->nrows; i++)
	{
		printf("\t");
		for (j = 0; j < K->ncols; j++){
			printf("\t[%- 6.4g]",getElt(K,i,j));
		}
		printf("\n");
	}
	printf("\n\n");

	return NO_REF;
		
			
}
Beispiel #7
0
/*  Solve a system */
Ref solve_call(ref_list args){
	
	if (args->length != 2){
		set_err(ETYPE, "\"solve\" needs 2 arguments");
		return NULL;	
	}

	if (arg_isMatrix(args->list[0]) == false ||
	    arg_isMatrix(args->list[1]) == false ) return NULL;

	Matrix m1 = CAST_REF2MATRIX(args->list[0]);
	Matrix m2 = CAST_REF2MATRIX(args->list[1]);
	
	if (m1->ncols != m2->nrows ||
	    m2->ncols > 1) {
		set_err(EMXDIM, "not a valid system");
		return NULL;
	}
	
	Matrix s = NULL;
	if (solve(m1, m2, &s) == false) return NULL;

	Ref r = new_vref(NULL, s, MATRIX);
	if (r == NULL) dropMatrix(s);

	return r;
} 
Beispiel #8
0
/* Invert one matrix */
Ref invert_call(ref_list args){
	
	if (args->length != 1){
		set_err(ETYPE, "to many arguments");
		return NULL;	
	}
	
	if (arg_isMatrix(args->list[0]) == false) return NULL;
	
	Matrix m = CAST_REF2MATRIX(args->list[0]);

	if (m->nrows != m->ncols) {
		set_err(ETYPE, "not a square Matrix");
		return NULL;
	}

	Matrix inv = NULL;
	if ( invert(m, &inv) == false) return NULL;


	Ref r = new_vref(NULL, inv, MATRIX);
	if (r == NULL) dropMatrix(inv);

	return r;
		
} 
Beispiel #9
0
/* Determinant of one matrix */
Ref determinant_call(ref_list args){
	
	if (args->length != 1){
		set_err(ETYPE, "to many arguments");
		return NULL;	
	}
	
	if (arg_isMatrix(args->list[0]) == false) return NULL;
	
	Matrix m = CAST_REF2MATRIX(args->list[0]);

	if (m->nrows != m->ncols) {
		set_err(ETYPE, "not a square Matrix");
		return NULL;
	}
	
	float* d = malloc(sizeof (float));	
	if (d == NULL) return NULL;

	if ( determinant(m, d) == false){
		free(d);
		return NULL;
	}

	Ref r = new_vref(NULL, d, FLOAT);
	if (r == NULL) free(d);

	return r;
		
} 
Beispiel #10
0
bool tunnelled_device_base::open()
{
  if (!m_tunnel_base_dev)
    return set_err(ENOSYS);
  if (!m_tunnel_base_dev->open())
    return set_err(m_tunnel_base_dev->get_err());
  return true;
}
Beispiel #11
0
smart_device * smart_interface::get_smart_device(const char * name, const char * type)
{
  clear_err();

  // Call platform specific autodetection if no device type specified
  smart_device * dev;
  if (!type || !*type) {
    dev = autodetect_smart_device(name);
    if (!dev && !get_errno())
      set_err(EINVAL, "Unable to detect device type");
    return dev;
  }

  // First check for platform specific device types
  dev = get_custom_smart_device(name, type);
  if (dev || get_errno())
    return dev;

  if (!strcmp(type, "ata"))
    dev = get_ata_device(name, type);
  else if (!strcmp(type, "scsi"))
    dev = get_scsi_device(name, type);

  else if (  ((!strncmp(type, "sat", 3) && (!type[3] || strchr(",+", type[3])))
           || (!strncmp(type, "usb", 3)))) {
    // Split "sat...+base..." -> ("sat...", "base...")
    unsigned satlen = strcspn(type, "+");
    std::string sattype(type, satlen);
    const char * basetype = (type[satlen] ? type+satlen+1 : "");
    // Recurse to allocate base device, default is standard SCSI
    if (!*basetype)
      basetype = "scsi";
    smart_device_auto_ptr basedev( get_smart_device(name, basetype) );
    if (!basedev) {
      set_err(EINVAL, "Type '%s+...': %s", sattype.c_str(), get_errmsg());
      return 0;
    }
    // Result must be SCSI
    if (!basedev->is_scsi()) {
      set_err(EINVAL, "Type '%s+...': Device type '%s' is not SCSI", sattype.c_str(), basetype);
      return 0;
    }
    // Attach SAT tunnel
    ata_device * satdev = get_sat_device(sattype.c_str(), basedev->to_scsi());
    if (!satdev)
      return 0;
    basedev.release();
    return satdev;
  }

  else {
    set_err(EINVAL, "Unknown device type '%s'", type);
    return 0;
  }
  if (!dev && !get_errno())
    set_err(EINVAL, "Not a device of type '%s'", type);
  return dev;
}
Beispiel #12
0
int gmShellPlink::StageIn(const gmdArrayString& locfiles, pCSTR remdir, unsigned flags){
  gmdString tempdir, src, err;
  gmdArrayString srclist;

  if( StageIn_begin(NULL, remdir, flags) )
    return StageIn_end(NULL, remdir, flags);

  for(unsigned i=0; i<locfiles.GetCount(); i++) {
    gmdString lfile = locfiles[i];
    if( lfile.IsEmpty() ) continue;
    lfile.Replace("/", "\\");

    if( has_wildcards(lfile) ) {
      // List all files explicitly if lfile contains wildcards
      gmdArrayString filelist;
      unsigned nfiles = files_by_mask(lfile, filelist, flags);
      if(nfiles)
        for(unsigned k=0; k<nfiles; k++) srclist.Add(filelist[k]);
      else
        set_err(NO_INPUT_FILE, fmt("%s: no such files", (pCSTR)lfile.c_str()));
    }
    else if( path_exists(lfile, flags) )
      srclist.Add(lfile);
    else
      set_err(NO_INPUT_FILE, fmt("%s: no sich file or directory", (pCSTR)lfile.c_str()));
  }

  if( !srclist.IsEmpty() ) {
    if(flags & TEXT) {
      // Convert text files and store them in the temporary dir
      assert_no_recursive(flags);  // combination RECURSIVE & TEXT is not supported!
      tempdir = GetTempDir();
      //dos2unix(srclist, tempdir);
      conv_files(srclist, tempdir, dos2unix);
      src = tempdir + "\\*.*";
    } else {
      // prepare the space separated file list for PLINK
      for(unsigned i=0; i<srclist.GetCount(); i++)
        src += (i>0 ? "\" \"" : "") + srclist[i];
    }

    // Copy files
    if(!error_code) {
      gmdString args = (flags & RECURSIVE) ? "-r \"" : "\"";
      args += src + "\" \"" + userhost + ':' + rem_path_subst(remdir) + "\"";
      pscp_execute(args);
    }

    if( !tempdir.IsEmpty() ) remove_local(tempdir);

    if(!error_code && (flags & MOVE))  // custom move (not using StageIn_end)
      for(unsigned i=0; i<srclist.GetCount(); i++) RemoveLocal(srclist[i], flags);
  }

  return StageIn_end(NULL, remdir, flags);
}
Beispiel #13
0
int gmShellPlink::pscp_execute(const gmdString& args){
  int i, res;
  gmdString errmsg;

  if(!auth_defined)
    LOGJOBERR("Authentification method are not defined, "
      "check 'login', 'host' and 'plink_args' parameters!");

  if(dump_commands)
    LOGJOBMSG4( (pCSTR) ("------ pscp_execute ------\n"
                         " cmd=" + pscp_pre + args + "\n"
              ));

  for(i=0; i<plink_att_num; i++){

    if(i) {  // Retrying on a network error
      LOGJOBMSG( fmt("PLINK connection failed: %s\nRetrying %d more times",
                     (const gmdChar*)errmsg, plink_att_num - i) );
      gmdMilliSleep(plink_retry_delay);  // delay before a retry
    }

    gmdArrayString out, err;
    //ttimer.Resume();
    res = gmdExecute(pscp_pre + args, out, err);
    //ttimer.Pause();
    if(res == -1) 
      return( set_err(EXECUTE_ERROR, "Error executing PSCP!") );

    if(dump_commands && res != 0)
      LOGJOBMSG4( (pCSTR) ("------ pscp_execute (error)------\n"
                           " cout=" + ArrayToString(out)+"\n"
                           " cerr=" + ArrayToString(err)+"\n"
                ));


    if(res == 0) break;

    errmsg = ArrayToString(err);
    if( !errmsg.StartsWith("Fatal: Network error:") ) break;
  }
  
  if(res) { // Replace 'res' by an internal error code
    if(i >= plink_att_num) res = CONNECTION_ERROR;
    else if( ( errmsg.Contains("no such file or directory") ||
               errmsg.Contains("matched no files") ) &&
             !errmsg.Contains("unable to open")
           ) res = NO_INPUT_FILE;
    else res = COPY_ERROR;
    set_err(res, errmsg);
  }

  return res;
}
Beispiel #14
0
int
open_mailbox(char * box_name, int box_size)
{
 int status;
 int index;    /* Index for mail box informations access */

 /* Test function security */

 if (box_size == 0){
  set_err (EINVAL);
  return (0);
 }

 if (box_name == NULL) {
  set_err (EFAULT);
  return (0);
 }

 index = alloc_entry();               /* Find an entry for id_table */
 if (index == -1) {
  set_err(EMFILE);
  if (nb_mail == 0) keep_clean();
  return(0);
 }

 id_table[index].size = box_size;              /* Keep size of mail box */
 strncpy(id_table[index].name,box_name,SIZEOFNAME);    /* Keep name of mail box */

 /* Attach shared memory to the process */

 status = open_sharedmemory ( (int **)&id_table[index].address, box_name,
                       box_size);

 if (status !=0)

 if (get_pid (index) < 0){  /* Get pid from shared memory  */
   set_err(ESRCH);
   return (0);
 }
 

 id_table[index].channel = status;

 if (status != 0) {
  return (index);    
 } 
 else {               /* Error */
  id_table[index].address = NULL;    /* ensure pointer is empty */
  keep_clean();
  return(0);
 }
}
Beispiel #15
0
int cap_setformat(cap_cx *cx, void *pfmt, size_t fmtlen, char *err)
{
	if( (cx->opened) && (!cx->started) )
	{
		if(capSetVideoFormat(cx->hwnd, pfmt, fmtlen))
		{
			set_err("");
			return 1;
		}
	}
	set_err("Can't set video format");
	return 0;
}
Beispiel #16
0
int gmShellPlink::execute(const gmdString& cmd, gmdArrayString& out, gmdArrayString& err){
  // Execute Shell command
  int i, res;
  gmdString errmsg;

  execute_begin(cmd, out, err);

  if(!auth_defined)
    return execute_error(
      set_err(CONNECTION_ERROR,
        "PLINK: Authentification method is not defined, "
        "check 'login', 'host' and 'plink_args' parameters!" )
      );

  // Screed double quotes
  gmdString cmd_scr(cmd);
  cmd_scr.Replace("\"", "\\\"");
  // Avoid empty command that switches plink into the interactive mode
  if( cmd_scr.IsEmpty() ) cmd_scr = "#";

  for(i=0; i<plink_att_num; i++){
    if(i) {  // Retrying on a network error
      LOGJOBMSG( fmt("PLINK connection failed: %s\nRetrying %d more times",
                     (const gmdChar*)errmsg, plink_att_num - i) );
      gmdMilliSleep(plink_retry_delay);  // delay before a retry
    }

    if(dump_commands)
      LOGJOBMSG4( (pCSTR)("------ execute (plink)------\n" + plink_pre + cmd_scr + '\"') );

    res = gmdExecute(plink_pre + cmd_scr + '\"', out, err);
    if(res == -1) {
      execute_end(res, out, err);
      return execute_error( set_err(EXECUTE_ERROR, "Error executing PLINK") );
    }
    else if(res == 0)
      break;

    errmsg = ArrayToString(err);
    if( !errmsg.StartsWith("Unable to open connection") ) break;
  }
  
  if(i >= plink_att_num){ 
    execute_end(-1, out, err); // pausing timer
    return  set_err(CONNECTION_ERROR, errmsg);
  }

  return execute_end(res, out, err);
}
Beispiel #17
0
int cap_open(cap_cx *cx, int id, char *err)
{
	if(!cx->opened)
	{
		if(capDriverConnect(cx->hwnd, id))
		{
			set_err("");
			cx->opened = 1;
			return 1;
		}
	}

	set_err("Can't open specifed device");
	return 0;
}
Beispiel #18
0
bool ata_device::ata_cmd_is_supported(const ata_cmd_in & in,
  unsigned flags, const char * type /* = 0 */)
{
  // Check DATA IN/OUT
  switch (in.direction) {
    case ata_cmd_in::no_data:  break;
    case ata_cmd_in::data_in:  break;
    case ata_cmd_in::data_out: break;
    default:
      return set_err(EINVAL, "Invalid data direction %d", (int)in.direction);
  }

  // Check buffer size
  if (in.direction == ata_cmd_in::no_data) {
    if (in.size)
      return set_err(EINVAL, "Buffer size %u > 0 for NO DATA command", in.size);
  }
  else {
    if (!in.buffer)
      return set_err(EINVAL, "Buffer not set for DATA IN/OUT command");
    unsigned count = (in.in_regs.prev.sector_count<<16)|in.in_regs.sector_count;
    // TODO: Add check for sector count == 0
    if (count * 512 != in.size)
      return set_err(EINVAL, "Sector count %u does not match buffer size %u", count, in.size);
  }

  // Check features
  const char * errmsg = 0;
  if (in.direction == ata_cmd_in::data_out && !(flags & supports_data_out))
    errmsg = "DATA OUT ATA commands not implemented";
  else if (   in.out_needed.is_set() && !(flags & supports_output_regs)
           && !(   in.in_regs.command == ATA_SMART_CMD
                && in.in_regs.features == ATA_SMART_STATUS
                && (flags & supports_smart_status)))
    errmsg = "Read of ATA output registers not implemented";
  else if (!(in.size == 0 || in.size == 512) && !(flags & supports_multi_sector))
    errmsg = "Multi-sector ATA commands not implemented";
  else if (in.in_regs.is_48bit_cmd() && !(flags & (supports_48bit_hi_null|supports_48bit)))
    errmsg = "48-bit ATA commands not implemented";
  else if (in.in_regs.is_real_48bit_cmd() && !(flags & supports_48bit))
    errmsg = "48-bit ATA commands not fully implemented";

  if (errmsg)
    return set_err(ENOSYS, "%s%s%s%s", errmsg,
                   (type ? " [" : ""), (type ? type : ""), (type ? "]" : ""));

  return true;
}
Beispiel #19
0
int gmShellPlink::StageIn(pCSTR locpath, pCSTR rempath, unsigned flags){
  gmdString tempdir, src;

  if( StageIn_begin(locpath, rempath, flags) )
    return StageIn_end(locpath, rempath, flags);

  if( !path_exists(locpath, flags) )
    set_err(NO_INPUT_FILE, fmt("%s: no such file or directory", locpath));
  else if(flags & TEXT){
    // Convert text file
    assert_no_recursive(flags);

    tempdir = GetTempDir(); // we cannot check if 'rempath' is dir or file name 
    gmdArrayString srclist;
    srclist.Add(locpath);
    conv_files(srclist, tempdir, dos2unix);

    gmdFileName filename(locpath);
    src = tempdir + "\\" + filename.GetFullName();
  }
  else
    src = locpath;

  // Copy file
  if(!error_code) {
    gmdString args = (flags & RECURSIVE) ? "-r \"" : "\"";
    args += src + "\" \"" + userhost + ':' + rem_path_subst(rempath) + "\"";
    pscp_execute(args);
  }

  if( !tempdir.IsEmpty() ) remove_local(tempdir);

  return StageIn_end(locpath, rempath, flags);
}
Beispiel #20
0
int cap_ic_start(cap_cx *cx, char *err)
{
	char format[32];
	char message[80];

	if((cx->ic = ICDecompressOpen(
		ICTYPE_VIDEO,
		0,
		&(cx->pfmt->bmiHeader),
		NULL)))
	{
		cx->outfmtlen = ICDecompressGetFormatSize(cx->ic, cx->pfmt);
		if((cx->poutfmt = malloc(cx->outfmtlen)))
		{
			if(ICDecompressGetFormat(cx->ic, cx->pfmt, cx->poutfmt) == ICERR_OK)
			{
				if(ICDecompressBegin(cx->ic, cx->pfmt, cx->poutfmt) == ICERR_OK)
				{
					cx->mode = CAP_USE_IC;
					return 1;
				}
			}
			free(cx->poutfmt);
		}
		ICClose(cx->ic);
	}

	sprintf(message, "Can't open decompressor for format \"%s\"",
		reverse_fourcc(format, cx->pfmt->bmiHeader.biCompression));
	set_err(message);
	
	return 0;
}
Beispiel #21
0
char*
expand_tilde(char *str, const char *home)
{
    if (str == NULL || home == NULL)
        return str;

    int len = strlen(home);

    static char dest[MAX_LEN];

    char *from = str;
    int i = 0;

    for (int i = 0; str[i]; i++) {
        if (i >= (MAX_LEN - 1)) {
            set_err(ERR_DIRS_TOO_LONG);
            strncpy(dest, str, MAX_LEN -1);
            return dest;
        }

        if (str[i] == '~') {
            strncat(dest, from, &str[i] - from);
            strcat(dest, home);

            from = str + i + 1;
        }
    }

    strcat(dest, from);

    return dest;
}
Beispiel #22
0
int cap_configure(cap_cx *cx, char *err)
{
	CAPTUREPARMS params;

	if(capCaptureGetSetup(cx->hwnd, &params, sizeof(params)))
	{
		params.fYield = TRUE;
		params.fCaptureAudio = FALSE;
		params.wPercentDropForError = 100;

		params.fMakeUserHitOKToCapture = FALSE;
		params.fAbortLeftMouse = FALSE;
		params.fAbortRightMouse = FALSE;
		params.vKeyAbort = 0;

		if(capCaptureSetSetup(cx->hwnd, &params, sizeof(params)))
		{
			if(capSetCallbackOnVideoStream(cx->hwnd, cap_stream_cb))
			{
				return 1;
			}
		}
	}

	set_err("Can't set capture settings");
	return 0;
}
Beispiel #23
0
bool legacy_smart_interface::scan_smart_devices(smart_device_list & devlist,
  const char * type, const char * pattern /*= 0*/)
{
  if (pattern) {
    set_err(EINVAL, "DEVICESCAN with pattern not implemented yet");
    return false;
  }

  // Make namelists
  char * * atanames = 0; int numata = 0;
  if (!type || !strcmp(type, "ata")) {
    numata = ::make_device_names(&atanames, "ATA");
    if (numata < 0) {
      set_err(ENOMEM);
      return false;
    }
  }

  char * * scsinames = 0; int numscsi = 0;
  if (!type || !strcmp(type, "scsi")) {
    numscsi = ::make_device_names(&scsinames, "SCSI");
    if (numscsi < 0) {
      free_devnames(atanames, numata);
      set_err(ENOMEM);
      return false;
    }
  }

  // Add to devlist
  int i;
  if (!type)
    type="";
  for (i = 0; i < numata; i++) {
    ata_device * atadev = get_ata_device(atanames[i], type);
    if (atadev)
      devlist.push_back(atadev);
  }
  free_devnames(atanames, numata);

  for (i = 0; i < numscsi; i++) {
    scsi_device * scsidev = get_scsi_device(scsinames[i], type);
    if (scsidev)
      devlist.push_back(scsidev);
  }
  free_devnames(scsinames, numscsi);
  return true;
}
Beispiel #24
0
bool tunnelled_device_base::close()
{
  if (!m_tunnel_base_dev)
    return true;
  if (!m_tunnel_base_dev->close())
    return set_err(m_tunnel_base_dev->get_err());
  return true;
}
Beispiel #25
0
/**
 * Handle a DFU_DNLOAD request.
 *
 * @param[in] bock_num The block sequence number.
 * @param[in] data     The buffer containing the block data.
 * @param[in] len      The size of the block, i.e., the amount of data in the
 * 		       buffer.
 *
 * @return  0 if no error has occurred, an error code otherwise.
 */
int dfu_process_dnload(uint16_t block_num, const uint8_t *data, uint16_t len)
{
	switch (dfu_state) {
	case DFU_STATE_DFU_IDLE:
		if (len == 0) {
			set_err(DFU_STATUS_ERR_STALLEDPKT);
			return -EIO;
		}
		block_cnt = 0;
		break;
	case DFU_STATE_DFU_DNLOAD_IDLE:
		/* If the block is out of order */
		if (block_num != next_block_num) {
			/*
			 * NOTE: this check is not mentioned in the DFU spec;
			 * we keep it for now, but we may consider removing it
			 * for code-size optimization purposes.
			 */
			set_err(DFU_STATUS_ERR_VENDOR);
			return -EIO;
		}
		/* If the block is empty, it signals the end of the download */
		if (len == 0) {
			/* check if finalization is allowed */
			if (dfu_rh->fin_dnload_xfer() == 0) {
				dfu_state = DFU_STATE_DFU_MANIFEST_SYNC;
				return 0;
			} else {
				set_err(DFU_STATUS_ERR_NOTDONE);
				return -EIO;
			}
		}
		break;
	default:
		set_err(DFU_STATUS_ERR_STALLEDPKT);
		return -EIO;
	}
	/* we end up here if a DNLOAD transfer just started or is continuing */
	next_block_num = block_num + 1;
	dfu_rh->proc_dnload_blk(block_cnt, data, len);
	block_cnt++;
	dfu_state = DFU_STATE_DFU_DNLOAD_SYNC;

	return 0;
}
Beispiel #26
0
bool legacy_scsi_device::scsi_pass_through(scsi_cmnd_io * iop)
{
  int status = ::do_scsi_cmnd_io(get_fd(), iop, scsi_debugmode);
  if (status < 0) {
      set_err(-status);
      return false;
  }
  return true;
}
Beispiel #27
0
int cIStream::Write(const char *buf, int len) {
	if (err()) 
		return -1;

    int n = buf_.Write(buf, len);
	if (n == -1)
		set_err(true);
	return n;
}
Beispiel #28
0
bool legacy_smart_device::close()
{
  int fd = m_fd; m_fd = -1;
  if (::deviceclose(fd) < 0) {
    set_err(errno);
    return false;
  }
  return true;
}
Beispiel #29
0
bool legacy_smart_device::open()
{
  m_fd = ::deviceopen(get_dev_name(), const_cast<char*>(m_mode));
  if (m_fd < 0) {
    set_err((errno==ENOENT || errno==ENOTDIR) ? ENODEV : errno);
    return false;
  }
  return true;
}
Beispiel #30
0
cIStream &cIStream::operator<<(const char *s) {
    if (s == nullptr) {
		set_err(true);
		return *this;
	}
	int len = strlen(s);
	Write(s, len);
	return *this;

}