void set_factory_ip()
{
	struct ip_addr ipaddr, netmask, gw;
	
	
	memcpy(EEPROM_Data.BoxIPAddress, DEFAULT_Data.BoxIPAddress , 4);
	memcpy(EEPROM_Data.SubNetMask, DEFAULT_Data.SubNetMask , 4);
	memcpy(EEPROM_Data.GetwayAddress, DEFAULT_Data.GetwayAddress , 4);
	
	ipaddr.addr =  get32( EEPROM_Data.BoxIPAddress );
	netmask.addr = get32( EEPROM_Data.SubNetMask );
	gw.addr = get32( EEPROM_Data.GetwayAddress );
		
#if 0	//ZOTIPS		
	netif_set_ipaddr(WLanface, &ipaddr);
	netif_set_netmask(WLanface, &netmask);
	netif_set_gw(WLanface, &gw);
#endif //ZOTIPS
	
	netif_set_ipaddr(Lanface, &ipaddr);
	netif_set_netmask(Lanface, &netmask);
	netif_set_gw(Lanface, &gw);
	
	mib_DHCP_p->IPAddr = DWordSwap(Lanface->ip_addr.addr);
	mib_DHCP_p->SubnetMask = DWordSwap(Lanface->netmask.addr);
	mib_DHCP_p->GwyAddr = DWordSwap(Lanface->gw.addr);

}
Esempio n. 2
0
unsigned int spi_transfer16(unsigned int data, unsigned char cs) {
	unsigned char l = data & 0xFF;
	unsigned char h = (data & 0xFF00) >> 8;
	put32(AUX_SPI0_CS, 0x000000B0 | cs);
	while (1) {
		if (get32(AUX_SPI0_CS) & (1 << 18)) {
			break;
		}
	}
	put8(AUX_SPI0_FIFO, h);
	while (1) {
		if (get32(AUX_SPI0_CS) & (1 << 16)) {
			break;
		}
	}
	h = get8(AUX_SPI0_FIFO);
	while (1) {
		if (get32(AUX_SPI0_CS) & (1 << 18)) {
			break;
		}
	}
	put8(AUX_SPI0_FIFO, l);
	while (1) {
		if (get32(AUX_SPI0_CS) & (1 << 16)) {
			break;
		}
	}
	l = get8(AUX_SPI0_FIFO);
	put32(AUX_SPI0_CS, 0x00000000 | cs);
	return (h << 8) | l;
}
Esempio n. 3
0
char uart_recv ( void )
{
	while(1) {
		if(get32(AUX_MU_LSR_REG)&0x01) 
			break;
	}
	return(get32(AUX_MU_IO_REG)&0xFF);
}
Esempio n. 4
0
/*
  Return the last found cert.  Caller must free it.
 */
int
keybox_get_cert (KEYBOX_HANDLE hd, ksba_cert_t *r_cert)
{
  const unsigned char *buffer;
  size_t length;
  size_t cert_off, cert_len;
  ksba_reader_t reader = NULL;
  ksba_cert_t cert = NULL;
  int rc;

  if (!hd)
    return gpg_error (GPG_ERR_INV_VALUE);
  if (!hd->found.blob)
    return gpg_error (GPG_ERR_NOTHING_FOUND);

  if (blob_get_type (hd->found.blob) != BLOBTYPE_X509)
    return gpg_error (GPG_ERR_WRONG_BLOB_TYPE);

  buffer = _keybox_get_blob_image (hd->found.blob, &length);
  if (length < 40)
    return gpg_error (GPG_ERR_TOO_SHORT);
  cert_off = get32 (buffer+8);
  cert_len = get32 (buffer+12);
  if (cert_off+cert_len > length)
    return gpg_error (GPG_ERR_TOO_SHORT);

  rc = ksba_reader_new (&reader);
  if (rc)
    return rc;
  rc = ksba_reader_set_mem (reader, buffer+cert_off, cert_len);
  if (rc)
    {
      ksba_reader_release (reader);
      /* fixme: need to map the error codes */
      return gpg_error (GPG_ERR_GENERAL);
    }

  rc = ksba_cert_new (&cert);
  if (rc)
    {
      ksba_reader_release (reader);
      return rc;
    }

  rc = ksba_cert_read_der (cert, reader);
  if (rc)
    {
      ksba_cert_release (cert);
      ksba_reader_release (reader);
      /* fixme: need to map the error codes */
      return gpg_error (GPG_ERR_GENERAL);
    }

  *r_cert = cert;
  ksba_reader_release (reader);
  return 0;
}
Esempio n. 5
0
        void get( const uint8_t *data )
        {
//for( int i = 1; i < BITMAP_HEADER_SIZE/2; i += 2 )
//    printf( "%02X: [%2d]: %02X %02X - %02X %02X\n", i*2, i, aHeader[i] & 0xFF, (aHeader[i] >> 8) & 0xFF, aHeader[i+1] & 0xFF, (aHeader[i+1] >> 8) & 0xFF );
            magic     = get16( data,  0 );
            bfSize    = get32( data,  2 );
            reserved  = get32( data,  6 );
            bfOffbits = get32( data, 10 );
        }
void get_tcp(struct TCPHeader* tcphead) {
  tcphead->src = get16();
  tcphead->dest = get16();
  tcphead->seqnum = get32();
  tcphead->acknum = get32();
  tcphead->byte0 = get8();
  tcphead->byte1 = get8();
  tcphead->winsize = get16();
  tcphead->checksum = get16();
  tcphead->urgpoint = get16();
}
Esempio n. 7
0
static int
read_coord(FILE *fh, img_point *pt)
{
   SVX_ASSERT(fh);
   SVX_ASSERT(pt);
   pt->x = get32(fh) / 100.0;
   pt->y = get32(fh) / 100.0;
   pt->z = get32(fh) / 100.0;
   if (ferror(fh) || feof(fh)) {
      img_errno = feof(fh) ? IMG_BADFORMAT : IMG_READERROR;
      return 0;
   }
   return 1;
}
Esempio n. 8
0
static unsigned long long getboxlen(const u_char *ptr) {
    unsigned value = get32(ptr);
    if ( value == 1 ) {
        return get64(ptr + 8);
    }
    return value;
}
Esempio n. 9
0
void uart_init ( void )
{
	unsigned int selector;

	selector = get32(GPFSEL1);
	selector &= ~(7<<12);                   // clean gpio14
	selector |= 2<<12;                      // set alt5 for gpio14
	selector &= ~(7<<15);                   // clean gpio15
	selector |= 2<<15;                      // set alt5 for gpio 15
	put32(GPFSEL1,selector);

	put32(GPPUD,0);
	delay(150);
	put32(GPPUDCLK0,(1<<14)|(1<<15));
	delay(150);
	put32(GPPUDCLK0,0);

	put32(AUX_ENABLES,1);                   //Enable mini uart (this also enables access to it registers)
	put32(AUX_MU_CNTL_REG,0);               //Disable auto flow control and disable receiver and transmitter (for now)
	put32(AUX_MU_IER_REG,0);                //Disable receive and transmit interrupts
	put32(AUX_MU_LCR_REG,3);                //Enable 8 bit mode
	put32(AUX_MU_MCR_REG,0);                //Set RTS line to be always high
	put32(AUX_MU_BAUD_REG,270);             //Set baund rate to 115200

	put32(AUX_MU_CNTL_REG,3);               //Finaly, enable transmitter and receiver
}
Esempio n. 10
0
void IoEvDNSRequest_callback(int result, char type, int count, int ttl, void *addresses, void *arg)
{
	IoEvDNSRequest *self = arg;
	//type is either DNS_IPv4_A or DNS_PTR or DNS_IPv6_AAAA

	IoObject_setSlot_to_(self, IOSYMBOL("ttl"), IONUMBER(ttl));

	if(result == DNS_ERR_NONE)
	{
		IoList *ioAddresses = IoList_new(IOSTATE);
		IoObject_setSlot_to_(self, IOSYMBOL("addresses"), ioAddresses);
		
		int i;
		for (i = 0; i < count; i ++)
		{
			//addresses needs to be cast according to type
			uint32_t a = ((uint32_t *)addresses)[i];
			struct in_addr addr;
			char *ip;
			addr.s_addr = htonl(get32(rr->rdata));
			ip = (char *)inet_ntoa(addr);
			IoList_rawAppend_(ioAddresses, IOSYMBOL(ip));
		}
	}
	else 
	{
		IoObject_setSlot_to_(self, IOSYMBOL("error"), IOSYMBOL("fail"));
	}

	
	IoMessage *m = IoMessage_newWithName_label_(IOSTATE, IOSYMBOL("handleResponse"), IOSYMBOL("IoEvDNSRequest"));
	IoMessage_locals_performOn_(m, self, self);
}
Esempio n. 11
0
uint32_t sftp_parse_uint32(struct sftpjob *job, uint32_t *ur) {
  if(job->left < 4)
    return SSH_FX_BAD_MESSAGE;
  *ur = get32(job->ptr);
  job->ptr += 4;
  job->left -= 4;
  return SSH_FX_OK;
}
Esempio n. 12
0
unsigned char spi_transfer8(unsigned char data, unsigned char cs) {
	put32(AUX_SPI0_CS, 0x000000B0 | cs);
	while (1) {
		if (get32(AUX_SPI0_CS) & (1 << 18)) {
			break;
		}
	}
	put8(AUX_SPI0_FIFO, data);
	while (1) {
		if (get32(AUX_SPI0_CS) & (1 << 16)) {
			break;
		}
	}
	data = get8(AUX_SPI0_FIFO);
	put32(AUX_SPI0_CS, 0x00000000);
	return data;
}
Esempio n. 13
0
void uart_send ( char c )
{
	while(1) {
		if(get32(AUX_MU_LSR_REG)&0x20) 
			break;
	}
	put32(AUX_MU_IO_REG,c);
}
Esempio n. 14
0
/* Compute the SHA-1 checksum of the rawdata in BLOB and put it into
   DIGEST. */
static int
hash_blob_rawdata (KEYBOXBLOB blob, unsigned char *digest)
{
  const unsigned char *buffer;
  size_t n, length;
  int type;
  ulong rawdata_off, rawdata_len;

  buffer = _keybox_get_blob_image (blob, &length);

  if (length < 32)
    return -1;
  n = get32 (buffer);
  if (n < length)
    length = n;  /* Blob larger than length in header - ignore the rest. */

  type = buffer[4];
  switch (type)
    {
    case KEYBOX_BLOBTYPE_PGP:
    case KEYBOX_BLOBTYPE_X509:
      break;

    case KEYBOX_BLOBTYPE_EMPTY:
    case KEYBOX_BLOBTYPE_HEADER:
    default:
      memset (digest, 0, 20);
      return 0;
    }

  if (length < 40)
    return -1;

  rawdata_off = get32 (buffer + 8);
  rawdata_len = get32 (buffer + 12);

  if (rawdata_off > length || rawdata_len > length
      || rawdata_off+rawdata_off > length)
    return -1; /* Out of bounds.  */

  gcry_md_hash_buffer (GCRY_MD_SHA1, digest, buffer+rawdata_off, rawdata_len);
  return 0;
}
Esempio n. 15
0
  bool findFDE(pint_t pc, pint_t &fdeStart, pint_t &data_base) {
    Range *n;
    for (;;) {
      pthread_rwlock_rdlock(&fdeTreeLock);
      n = (Range *)rb_tree_find_node(&segmentTree, &pc);
      pthread_rwlock_unlock(&fdeTreeLock);
      if (n != NULL)
        break;
      if (!needsReload)
        break;
      lazyReload();
    }
    if (n == NULL)
      return false;
    if (n->hdr_start == 0) {
      fdeStart = n->hdr_base;
      data_base = n->data_base;
      return true;
    }

    pint_t base = n->hdr_base;
    pint_t first = n->hdr_start;
    pint_t len = n->hdr_entries;
    while (len) {
      pint_t next = first + ((len + 1) / 2) * 8;
      pint_t nextPC = base + (int32_t)get32(next);
      if (nextPC == pc) {
        first = next;
        break;
      }
      if (nextPC < pc) {
        len -= (len + 1) / 2;
        first = next;
      } else if (len == 1)
        break;
      else
        len = (len + 1) / 2;
    }
    fdeStart = base + (int32_t)get32(first + 4);
    data_base = n->data_base;
    return true;
  }
static int
dump_header_blob (const byte *buffer, size_t length, FILE *fp)
{
  unsigned long n;

  if (length < 32)
    {
      fprintf (fp, "[blob too short]\n");
      return -1;
    }
  fprintf (fp, "Version: %d\n", buffer[5]);
  if ( memcmp (buffer+8, "KBXf", 4))
    fprintf (fp, "[Error: invalid magic number]\n");

  n = get32 (buffer+16);
  fprintf( fp, "created-at: %lu\n", n );
  n = get32 (buffer+20);
  fprintf( fp, "last-maint: %lu\n", n );

  return 0;
}
Esempio n. 17
0
static char*
crackfw(FWImage *i, uchar *data, uint size)
{
	uchar *p, *e;

	memset(i, 0, sizeof(*i));
	if(size < 4*6){
Tooshort:
		return "firmware image too short";
	}
	p = data;
	e = p + size;
	i->version = get32(p); p += 4;
	i->main.text.size = get32(p); p += 4;
	i->main.data.size = get32(p); p += 4;
	i->init.text.size = get32(p); p += 4;
	i->init.data.size = get32(p); p += 4;
	i->boot.text.size = get32(p); p += 4;
	i->main.text.data = p; p += i->main.text.size;
	i->main.data.data = p; p += i->main.data.size;
	i->init.text.data = p; p += i->init.text.size;
	i->init.data.data = p; p += i->init.data.size;
	i->boot.text.data = p; p += i->boot.text.size;
	if(p > e)
		goto Tooshort;
	return nil;
}
Esempio n. 18
0
static int
dump_header_blob (const byte *buffer, size_t length, FILE *fp)
{
  unsigned long n;

  if (length < 32)
    {
      fprintf (fp, "[blob too short]\n");
      return -1;
    }
  fprintf (fp, "Version: %d\n", buffer[5]);

  n = get16 (buffer + 6);
  fprintf( fp, "Flags:   %04lX", n);
  if (n)
    {
      int any = 0;

      fputs (" (", fp);
      if ((n & 2))
        {
          if (any)
            putc (',', fp);
          fputs ("openpgp", fp);
          any++;
        }
      putc (')', fp);
    }
  putc ('\n', fp);

  if ( memcmp (buffer+8, "KBXf", 4))
    fprintf (fp, "[Error: invalid magic number]\n");

  n = get32 (buffer+16);
  fprintf( fp, "created-at: %lu\n", n );
  n = get32 (buffer+20);
  fprintf( fp, "last-maint: %lu\n", n );

  return 0;
}
Esempio n. 19
0
void
loadstate(char *file)
{
	bp = Bopen(file, OREAD);
	if(bp == nil){
		message("open: %r");
		return;
	}
	Bread(bp, reg, sizeof(reg));
	Bread(bp, mem, sizeof(mem));
	Bread(bp, vram, sizeof(vram));
	Bread(bp, oam, sizeof(oam));
	Bread(bp, spcmem, sizeof(spcmem));
	Bread(bp, dsp, sizeof(dsp));
	get16s(cgram, nelem(cgram));
	ppuclock = get32();
	spcclock = get32();
	dspclock = get32();
	stimerclock = get32();
	rA = get16();
	rX = get16();
	rY = get16();
	rS = get16();
	rP = get8();
	rD = get16();
	rDB = get8()<<16;
	pc = get16();
	rPB = get8()<<16;
	emu = get8();
	irq = get8();
	nmi = get8();
	dma = get8();
	hdma = get32();
	wai = get8();
	mdr = get8();
	mdr1 = get8();
	mdr2 = get8();
	oamaddr = get16();
	vramlatch = get16();
	keylatch = get32();
	ppux = get16();
	ppuy = get16();
	htime = reg[0x4207] | reg[0x4208] << 8 & 0x100;
	vtime = reg[0x4209] | reg[0x420a] << 8 & 0x100;
	subcolor = get16();
	get16s(hofs, nelem(hofs));
	get16s(vofs, nelem(vofs));
	get16s((u16int*) m7, nelem(m7));
	sA = get8();
	sX = get8();
	sY = get8();
	sS = get8();
	sP = get8();
	dspstate = get8();
	dspcounter = get16();
	noise = get16();
	Bread(bp, spctimer, sizeof(spctimer));
	dspload();
	Bterm(bp);
}
Esempio n. 20
0
/** \internal
 *
 * Decodes the CBOR integer value when it is larger than the 16 bits available
 * in value->extra. This function requires that value->flags have the
 * CborIteratorFlag_IntegerValueTooLarge flag set.
 *
 * This function is also used to extract single- and double-precision floating
 * point values (SinglePrecisionFloat == Value32Bit and DoublePrecisionFloat ==
 * Value64Bit).
 */
uint64_t _cbor_value_decode_int64_internal(const CborValue *value)
{
    assert(value->flags & CborIteratorFlag_IntegerValueTooLarge ||
           value->type == CborFloatType || value->type == CborDoubleType);

    // since the additional information can only be Value32Bit or Value64Bit,
    // we just need to test for the one bit those two options differ
    assert((*value->ptr & SmallValueMask) == Value32Bit || (*value->ptr & SmallValueMask) == Value64Bit);
    if ((*value->ptr & 1) == (Value32Bit & 1))
        return get32(value->ptr + 1);

    assert((*value->ptr & SmallValueMask) == Value64Bit);
    return get64(value->ptr + 1);
}
Esempio n. 21
0
int
mpt_send_message(mpt_adap_t *adap, int length, time_t limit)
{
	U32		 doorbell;
	U32		*message = adap->shared->message;
	int		 state;
	int		 i;

	doorbell = rl(DOORBELL);
	state = doorbell & MPI_IOC_STATE_MASK;
	if (state == MPI_IOC_STATE_FAULT)
	{
		printf("\n%s: MPT Firmware Fault, code %04x\n",
			   adap->name, doorbell & MPI_DOORBELL_DATA_MASK);
		if (wFlag)
			fprintf(logFile, "%s:  MPT Firmware Fault, code %04x\n",
					adap->name, doorbell & MPI_DOORBELL_DATA_MASK);
		adap->restart_needed = TRUE;
		return 0;
	}
	if (state == MPI_IOC_STATE_RESET)
	{
		adap->restart_needed = TRUE;
		return 0;
	}
	if (doorbell & MPI_DOORBELL_ACTIVE)
	{
		printf("%s: Doorbell already active\n", adap->name);
		adap->restart_needed = TRUE;
		return 0;
	}
	wl(HOST_INTERRUPT_STATUS, 0);
	wl(DOORBELL, (MPI_FUNCTION_HANDSHAKE << MPI_DOORBELL_FUNCTION_SHIFT) |
				  ((length / 4) << MPI_DOORBELL_ADD_DWORDS_SHIFT));
	if (!mpt_wait_for_doorbell(adap, limit))
		return 0;
	wl(HOST_INTERRUPT_STATUS, 0);
	if (!mpt_wait_for_response(adap, limit))
		return 0;
	for (i = 0; i < length / 4; i++)
	{
		wl(DOORBELL, get32(message[i]));
		if (!mpt_wait_for_response(adap, limit))
			return 0;
	}

	return 1;
}
Esempio n. 22
0
/*
 * mpt_init_device_capabilities - initialize SCSI device capabilities.
 */
int
mpt_init_device_capabilities(mpt_adap_t *adap)
{
	SCSIPortPage0_t		*scsi_port_0 = (SCSIPortPage0_t *)adap->shared->config;
	SCSIPortPage2_t		*scsi_port_2 = (SCSIPortPage2_t *)adap->shared->config;
	int					 init_capabilities;
	int					 init_sync_period;
	int					 targ_capabilities;
	int					 targ_sync_period;
	int					 targ_device_flags;
	int					 targ;

	if (!mpt_get_config_page(adap, MPI_CONFIG_PAGETYPE_SCSI_PORT, 0, 0))
	{
		printf("%s: Failed to get SCSI Port Page 0\n", adap->name);
		return 0;
	}

	init_capabilities = get32(scsi_port_0->Capabilities);

	init_sync_period = MPI_SCSIPORTPAGE0_CAP_GET_MIN_SYNC_PERIOD(init_capabilities);

	if (!mpt_get_config_page(adap, MPI_CONFIG_PAGETYPE_SCSI_PORT, 2, 0))
	{
		printf("%s: Failed to get SCSI Port Page 2\n", adap->name);
		return 0;
	}

	for (targ = 0; targ < adap->max_targets; targ++)
	{
		targ_sync_period = scsi_port_2->DeviceSettings[targ].SyncFactor;
		targ_device_flags = get16(scsi_port_2->DeviceSettings[targ].DeviceFlags);
		targ_capabilities = init_capabilities;
		if (targ_sync_period == 0 || targ_sync_period > init_sync_period)
		{
			targ_capabilities &= ~MPI_SCSIDEVPAGE1_RP_MIN_SYNC_PERIOD_MASK;
			targ_capabilities |= targ_sync_period << MPI_SCSIDEVPAGE1_RP_SHIFT_MIN_SYNC_PERIOD;
		}
		if (targ_device_flags & MPI_SCSIPORTPAGE2_DEVICE_WIDE_DISABLE)
		{
			targ_capabilities &= ~MPI_SCSIDEVPAGE1_RP_WIDE;
		}
		adap->capabilities[targ] = targ_capabilities;
	}

	return 1;
}
Esempio n. 23
0
unsigned int spi_init(unsigned int cdiv, unsigned int cspins) {
	unsigned int spi;
	spi = get32(AUX_ENABLES);
	put32(AUX_ENABLES, spi | 2);
	if(cspins | 1) {
		gpio_fsel(GP7, ALT0);
	}
	if(cspins | 2) {
		gpio_fsel(GP8, ALT0);
	}
	gpio_fsel(GP9, ALT0);
	gpio_fsel(GP10, ALT0);
	gpio_fsel(GP11, ALT0);
	put32(AUX_SPI0_CS, 0x0000030);
	put32(AUX_SPI0_CLK, cdiv);

	return SYS_CLOCK / cdiv;
}
Esempio n. 24
0
void Http2Base::SettingsProc(const Http2_header* header) {
    const Setting_Frame *sf = (const Setting_Frame *)(header + 1);
    if((header->flags & ACK_F) == 0) {
        while((char *)sf-(char *)(header+1) < get24(header->length)){
            uint32_t value = get32(sf->value);
            switch(get16(sf->identifier)){
            case SETTINGS_HEADER_TABLE_SIZE:
                LOGD(DHTTP2, "set head table size:%d\n", value);
                request_table.set_dynamic_table_size_limit_max(value);
                break;
            case SETTINGS_INITIAL_WINDOW_SIZE:
                if(value >= (uint32_t)1<<31u){
                    LOGE("ERROR window overflow\n");
                    ErrProc(ERR_FLOW_CONTROL_ERROR);
                    return;
                }
                AdjustInitalFrameWindowSize((ssize_t)value - (ssize_t)remoteframewindowsize);
                remoteframewindowsize = value;
                LOGD(DHTTP2, "set inital frame window size:%d\n", remoteframewindowsize);
                break;
            case SETTINGS_MAX_FRAME_SIZE:
                if(value > 0xffffff || value < FRAMEBODYLIMIT){
                    LOGE("ERROR frame size overflow\n");
                    ErrProc(ERR_FRAME_SIZE_ERROR);
                    return;
                }
                remoteframebodylimit = value;
                LOGD(DHTTP2, "set frame body size limit: %d\n", remoteframebodylimit);
                break;
            default:
                LOG("Get a unkown setting(%d): %d\n", get16(sf->identifier), value);
                break;
            }
            sf++;
        }
        Http2_header *header_back = (Http2_header *)p_memdup(header, sizeof(Http2_header));
        set24(header_back->length, 0);
        header_back->flags |= ACK_F;
        PushFrame(header_back);
    }else if(get24(header->length) != 0){
        LOGE("ERROR setting ack with content\n");
        ErrProc(ERR_FRAME_SIZE_ERROR);
    }
}
Esempio n. 25
0
static int
read_v3label(img *pimg)
{
   char *q;
   long len = getc(pimg->fh);
   if (len == EOF) {
      img_errno = feof(pimg->fh) ? IMG_BADFORMAT : IMG_READERROR;
      return img_BAD;
   }
   if (len == 0xfe) {
      len += get16(pimg->fh);
      if (feof(pimg->fh)) {
	 img_errno = IMG_BADFORMAT;
	 return img_BAD;
      }
      if (ferror(pimg->fh)) {
	 img_errno = IMG_READERROR;
	 return img_BAD;
      }
   } else if (len == 0xff) {
      len = get32(pimg->fh);
      if (ferror(pimg->fh)) {
	 img_errno = IMG_READERROR;
	 return img_BAD;
      }
      if (feof(pimg->fh) || len < 0xfe + 0xffff) {
	 img_errno = IMG_BADFORMAT;
	 return img_BAD;
      }
   }

   if (!check_label_space(pimg, pimg->label_len + len + 1)) {
      img_errno = IMG_OUTOFMEMORY;
      return img_BAD;
   }
   q = pimg->label_buf + pimg->label_len;
   pimg->label_len += len;
   if (len && fread(q, len, 1, pimg->fh) != 1) {
      img_errno = feof(pimg->fh) ? IMG_BADFORMAT : IMG_READERROR;
      return img_BAD;
   }
   q[len] = '\0';
   return 0;
}
Esempio n. 26
0
/* Return one of the flags WHAT in VALUE from teh blob BUFFER of
   LENGTH bytes.  Return 0 on success or an raw error code. */
static gpg_err_code_t
get_flag_from_image (const unsigned char *buffer, size_t length,
                     int what, unsigned int *value)
{
  gpg_err_code_t ec;
  size_t pos, size;

  *value = 0;
  ec = _keybox_get_flag_location (buffer, length, what, &pos, &size);
  if (!ec)
    switch (size)
      {
      case 1: *value = buffer[pos]; break;
      case 2: *value = get16 (buffer + pos); break;
      case 4: *value = get32 (buffer + pos); break;
      default: ec = GPG_ERR_BUG; break;
      }

  return ec;
}
Esempio n. 27
0
static void decode_glowicon(struct DiskObject *diskobj, char *glow, LONG len)
{
  int imgno=0, gotface=0;
  struct { char width, height; UWORD dunno1, dunno2; } face;
  while(len>=8) {
    ULONG id = getu32(&glow);
    LONG clen = get32(&glow);
    char *chunk = glow;
    len -= 8;
    if(clen<0)
      clen = len;
    if(clen>len)
      break;
    switch(id) {
     case 0x46414345: /* FACE */
       if(clen>=6) {
	 face.width = 1+*chunk++;
	 face.height = 1+*chunk++;
	 face.dunno1 = getu16(&chunk);
	 face.dunno2 = getu16(&chunk);
	 gotface = 1;
	 diskobj->do_Gadget.Width = face.width;
	 diskobj->do_Gadget.Height = face.height;
       break;
       }
       break;
     case 0x494d4147: /* IMAG */
       if(!gotface || imgno>1)
	 break;
       decode_IMAG((unsigned char *)chunk, clen, face.width, face.height,
		   (imgno++? &diskobj->do_Gadget.SelectRender :
		    &diskobj->do_Gadget.GadgetRender));
       break;
    }
    if(clen&1)
      clen++;
    len -= clen;
    glow += clen;
  }
}
Esempio n. 28
0
static void ipip_receive(void *argp)
{

  int addrlen;
  int hdr_len;
  int l;
  int32 ipaddr;
  struct edv_t *edv;
  struct iface *ifp;
  struct ip *ipptr;
  struct mbuf *bp;
  struct sockaddr_in addr;
  uint8 buf[MAX_FRAME];
  uint8 *bufptr;

  ifp = (struct iface *) argp;
  edv = (struct edv_t *) ifp->edv;
  addrlen = sizeof(addr);
  l = recvfrom(edv->fd, (char *) (bufptr = buf), sizeof(buf), 0, (struct sockaddr *) &addr, &addrlen);
  if (edv->type == USE_IP) {
    if (l <= sizeof(struct ip)) goto Fail;
    ipptr = (struct ip *) bufptr;
    hdr_len = 4 * ipptr->ip_hl;
    bufptr += hdr_len;
    l -= hdr_len;
  }
  if (l <= 0) goto Fail;

  if ((ipaddr = get32(bufptr + 12)) && ismyaddr(ipaddr) == NULL)
    rt_add(ipaddr, 32, (int32) ntohl(addr.sin_addr.s_addr), ifp, 1L, 0x7fffffff / 1000, 0);

  bp = qdata(bufptr, l);
  net_route(ifp, &bp);
  return;

Fail:
  ifp->crcerrors++;
}
Esempio n. 29
0
/*
 * mpt_set_device_capabilities - set SCSI device capabilities.
 */
int
mpt_set_device_capabilities(mpt_adap_t *adap, int targ)
{
	SCSIDevicePage1_t	*scsi_device_1 = (SCSIDevicePage1_t *)adap->shared->config;

//	printf("%s: setting device capabilities\n", adap->name);

	bzero(scsi_device_1, sizeof(*scsi_device_1));

	/*
	 * Set the control bits we know we want, as well as the maximum
	 * synchronous offset and minimum synchronous period.
	 */
	scsi_device_1->RequestedParameters = get32(adap->capabilities[targ]);

	if (!mpt_set_config_page(adap, MPI_CONFIG_PAGETYPE_SCSI_DEVICE, 1, targ))
	{
		printf("%s: Failed to set SCSI Device Page 1 for %d\n",
			   adap->name, targ);
		return 0;
	}

	return 1;
}
Esempio n. 30
0
static struct DiskObject *int_load_do(char *filename)
{
  FILE *f;
  struct DiskObject *diskobj;
  char buf[78], *p=buf;
  int error=0;
  if((f=fopen(filename, "r"))) {
    if(1==fread(buf, 78, 1, f) &&
       (diskobj=calloc(1, sizeof(struct DiskObject)))) {
      diskobj->do_Magic=getu16(&p); diskobj->do_Version=getu16(&p);
      if(diskobj->do_Magic!=WB_DISKMAGIC) {
	free(diskobj);
	return NULL;
      }
      diskobj->do_Gadget.NextGadget=(struct Gadget *)getu32(&p);
      diskobj->do_Gadget.LeftEdge=get16(&p);
      diskobj->do_Gadget.TopEdge=get16(&p);
      diskobj->do_Gadget.Width=get16(&p); diskobj->do_Gadget.Height=get16(&p);
      diskobj->do_Gadget.Flags=getu16(&p);
      diskobj->do_Gadget.Activation=getu16(&p);
      diskobj->do_Gadget.GadgetType=getu16(&p);
      diskobj->do_Gadget.GadgetRender=(APTR)getu32(&p);
      diskobj->do_Gadget.SelectRender=(APTR)getu32(&p);
      diskobj->do_Gadget.GadgetText=(struct IntuiText *)getu32(&p);
      diskobj->do_Gadget.MutualExclude=get32(&p);
      diskobj->do_Gadget.SpecialInfo=(APTR)getu32(&p);
      diskobj->do_Gadget.GadgetID=getu16(&p);
      diskobj->do_Gadget.UserData=(APTR)getu32(&p);
      diskobj->do_Type=*p; p+=2;
      diskobj->do_DefaultTool=(char *)getu32(&p);
      diskobj->do_ToolTypes=(char **)getu32(&p);
      diskobj->do_CurrentX=get32(&p);
      diskobj->do_CurrentY=get32(&p);
      diskobj->do_DrawerData=(struct DrawerData *)getu32(&p);
      diskobj->do_ToolWindow=(char *)getu32(&p);
      diskobj->do_StackSize=get32(&p);
      
      if(diskobj->do_DrawerData) {
	struct DrawerData *dd;
	if(1==fread(buf, 56, 1, f) &&
	   (diskobj->do_DrawerData=dd=calloc(1, sizeof(struct DrawerData)))) {
	  p=buf;
	  dd->dd_NewWindow.LeftEdge=get16(&p);
	  dd->dd_NewWindow.TopEdge=get16(&p);
	  dd->dd_NewWindow.Width=get16(&p);
	  dd->dd_NewWindow.Height=get16(&p);
	  dd->dd_NewWindow.DetailPen=*p++;
	  dd->dd_NewWindow.BlockPen=*p++;
	  dd->dd_NewWindow.IDCMPFlags=getu32(&p);
	  dd->dd_NewWindow.Flags=getu32(&p);
	  dd->dd_NewWindow.FirstGadget=(struct Gadget *)getu32(&p);
	  dd->dd_NewWindow.CheckMark=(struct Image *)getu32(&p);
	  dd->dd_NewWindow.Title=(UBYTE *)getu32(&p);
	  dd->dd_NewWindow.Screen=(struct Screen *)getu32(&p);
	  dd->dd_NewWindow.BitMap=(struct BitMap *)getu32(&p);
	  dd->dd_NewWindow.MinWidth=get16(&p);
	  dd->dd_NewWindow.MinHeight=get16(&p);
	  dd->dd_NewWindow.MaxWidth=getu16(&p);
	  dd->dd_NewWindow.MaxHeight=getu16(&p);
	  dd->dd_NewWindow.Type=getu16(&p);
	  dd->dd_CurrentX=get32(&p);
	  dd->dd_CurrentY=get32(&p);
	} else error++;
      }

      if(!(diskobj->do_Gadget.GadgetRender=loadimage(f)))
	error++;
	
      if(diskobj->do_Gadget.Flags&2)
	if(!(diskobj->do_Gadget.SelectRender=loadimage(f)))
	  error++;
	else ;
      else if(diskobj->do_Gadget.Flags&1)
	if(!(diskobj->do_Gadget.SelectRender=
	     backfillimage((struct Image *)diskobj->do_Gadget.GadgetRender)))
	  error++;
	else ;
      else diskobj->do_Gadget.SelectRender=NULL;
      
      if(diskobj->do_DefaultTool)
	if(!(diskobj->do_DefaultTool=loadstring(f)))
	  error++;

      if(diskobj->do_ToolTypes)
	if(!(diskobj->do_ToolTypes=loadtooltypes(f)))
	  error++;

      if(diskobj->do_ToolWindow)
	if(!(diskobj->do_ToolWindow=loadstring(f)))
	  error++;

      if(diskobj->do_DrawerData && diskobj->do_Version) {
	char buf[6], *p=buf;
	if(1==fread(buf, 6, 1, f)) {
	  diskobj->do_DrawerData->dd_Flags=getu32(&p);
	  diskobj->do_DrawerData->dd_ViewModes=getu16(&p);
	}
      }

      if(diskobj->do_Version) {
	/* Check for GlowIcon */
	char buf[8], *p = buf, *glowicon;
	LONG len;
	if(1==fread(buf, 4, 1, f) && !strncmp(buf, "FORM", 4) &&
	   1==fread(buf, 8, 1, f) && !strncmp(buf+4, "ICON", 4) &&
	   (len = get32(&p))>4 && (glowicon = malloc(len))!=NULL) {
	  if(1==fread(glowicon, len-4, 1, f))
	    decode_glowicon(diskobj, glowicon, len-4);
	  free(glowicon);
	}
      }

      if(!error) {
	fclose(f);
	return diskobj;
      }

      FreeDiskObject(diskobj);
    }
    fclose(f);
    }
  return NULL;
}