예제 #1
0
파일: res32.c 프로젝트: r6144/wine
/* load the next resource from the current file */
static void load_next_resource( DLLSPEC *spec )
{
    unsigned int hdr_size;
    struct resource *res = add_resource( spec );

    res->data_size = get_dword();
    hdr_size = get_dword();
    if (hdr_size & 3) fatal_error( "%s header size not aligned\n", input_buffer_filename );
    if (hdr_size < 32) fatal_error( "%s invalid header size %u\n", input_buffer_filename, hdr_size );

    res->data = input_buffer + input_buffer_pos - 2*sizeof(unsigned int) + hdr_size;
    if ((const unsigned char *)res->data < input_buffer ||
        (const unsigned char *)res->data >= input_buffer + input_buffer_size)
        fatal_error( "%s invalid header size %u\n", input_buffer_filename, hdr_size );
    get_string( &res->type );
    get_string( &res->name );
    if (input_buffer_pos & 2) get_word();  /* align to dword boundary */
    get_dword();                        /* skip data version */
    res->mem_options = get_word();
    res->lang = get_word();
    get_dword();                        /* skip version */
    get_dword();                        /* skip characteristics */

    input_buffer_pos = ((const unsigned char *)res->data - input_buffer) + ((res->data_size + 3) & ~3);
    input_buffer_pos = (input_buffer_pos + 3) & ~3;
    if (input_buffer_pos > input_buffer_size)
        fatal_error( "%s is a truncated file\n", input_buffer_filename );
}
예제 #2
0
/**************************************************************************
*                                                                         *
*                                                                         *
*                                                                         *
***************************************************************************/
void fat32_get_descriptor(FAT32_FAT_DESCRIPTOR* desc, const uint8_t partition_num)
{
	FAT32_DEVICE_PARTITION_DESCRIPTOR partition_info;
	
//#ifdef 	FAT32_USE_IDE
	fat32_get_device_partition_info(&partition_info, partition_num);
	fat32_device_read_sector(partition_info.start_lba, 1, buffer);
//#endif
/*
#ifdef FAT32_USE_MMC
	fat32_device_read_sector(0, 1, buffer);
	partition_info.start_lba = 0;
	partition_info.n_sector = get_dword(buffer + 0x20);
#endif
*/
	// FAT32
	desc->bytes_per_sector 			= get_word(buffer + 0x0b);
	desc->sector_per_cluster 		= buffer[0x0d];
	desc->n_reserved_sector 		= get_word(buffer + 0x0e);
	desc->n_fat 					= buffer[0x10];
	desc->sector_per_fat 			= get_dword(buffer + 0x24);
	desc->n_root_entry 				= get_dword(buffer + 0x11);
	desc->root_cluster 				= get_dword(buffer + 0x2c);
	desc->volume_signature 			= get_word(buffer + 0x01fe);
	desc->fat_start_sector 			= partition_info.start_lba + desc->n_reserved_sector;
	desc->fat_start_data_sector		= desc->fat_start_sector + (desc->n_fat * desc->sector_per_fat);
	desc->root_dir 					= (desc->root_cluster - 0x02) * desc->sector_per_cluster + (desc->fat_start_data_sector);
	
	desc->current_dir_start_lba 	= desc->root_dir;
	desc->current_dir_start_cluster = desc->root_cluster;
	
	//EdbgOutputDebugString("sector per cluster = %d\r\n", desc->sector_per_cluster);
	//EdbgOutputDebugString("bytes per sector = %d\r\n", desc->bytes_per_sector);
	return;
}
예제 #3
0
/**************************************************************************
*                                                                         *
*                                                                         *
*                                                                         *
***************************************************************************/
void fat32_get_device_partition_info(FAT32_DEVICE_PARTITION_DESCRIPTOR* p_desc, const uint8_t p_num)
{
	uint8_t i;
	uint8_t partition_info[16];
	
	fat32_device_read_sector(0, 1, buffer);
	
	// 파티션 정보는 16바이트로 구성되어 있다
	for (i=0; i<=15; i++)
	{
		partition_info[i] = buffer[446 + (p_num * 16) + i];
	}

	// 부트플래그	
	if (partition_info[0] == 0x80)
		p_desc->boot_flag = 1;
	else
		p_desc->boot_flag = 0;
		
	p_desc->type_code = partition_info[4];
	p_desc->start_lba = get_dword(partition_info + 8);
	p_desc->n_sector = get_dword(partition_info + 12);
	
	return;
}
예제 #4
0
STATIC_PREFIX void debug_write_reg(int argc, char * argv[])
{
    unsigned  reg;
    unsigned  val;
    if(argc<3)
    {
        serial_puts("FAIL:Wrong write reg command\n");
        return;
    }
    if(get_dword(argv[1],&reg)||get_dword(argv[2],&val))
    {
        serial_puts("FAIL:Wrong reg addr=");
        serial_puts(argv[1]);
        serial_puts(" or val=");
        serial_puts(argv[2]);
        serial_putc('\n');
        return;
    }
    serial_puts("OK:Write ");
    serial_put_hex(reg,32);
    serial_putc('=');
    serial_put_hex(val,32);
    serial_putc('\n');
    writel(val,reg);
}
예제 #5
0
/**********************************************************************
 *	    ConvertMenu32To16   (KERNEL.616)
 */
VOID WINAPI ConvertMenu32To16( LPVOID menu32, DWORD size, LPVOID menu16 )
{
    WORD version, headersize, flags, level = 1;

    version = get_word( &menu32 );
    headersize = get_word( &menu32 );
    put_word( &menu16, version );
    put_word( &menu16, headersize );
    if ( headersize )
    {
        memcpy( menu16, menu32, headersize );
        menu16 = (BYTE *)menu16 + headersize;
        menu32 = (BYTE *)menu32 + headersize;
    }

    while ( level )
        if ( version == 0 )  /* standard */
        {
            flags = get_word( &menu32 );
            put_word( &menu16, flags );
            if ( !(flags & MF_POPUP) )
                put_word( &menu16, get_word( &menu32 ) );  /* ID */
            else
                level++;

            WideCharToMultiByte( CP_ACP, 0, (LPWSTR)menu32, -1, (LPSTR)menu16, 0x7fffffff, NULL, NULL );
            menu16 = (LPSTR)menu16 + strlen( (LPSTR)menu16 ) + 1;
            menu32 = (LPWSTR)menu32 + strlenW( (LPWSTR)menu32 ) + 1;

            if ( flags & MF_END )
                level--;
        }
        else  /* extended */
        {
            put_dword( &menu16, get_dword( &menu32 ) );  /* fType */
            put_dword( &menu16, get_dword( &menu32 ) );  /* fState */
            put_word( &menu16, get_dword( &menu32 ) );   /* ID */
            flags = get_word( &menu32 );
            put_byte(&menu16,flags);

            WideCharToMultiByte( CP_ACP, 0, (LPWSTR)menu32, -1, (LPSTR)menu16, 0x7fffffff, NULL, NULL );
            menu16 = (LPSTR)menu16 + strlen( (LPSTR)menu16 ) + 1;
            menu32 = (LPWSTR)menu32 + strlenW( (LPWSTR)menu32 ) + 1;

            /* align on DWORD boundary (32-bit only) */
            menu32 = (LPVOID)(((UINT_PTR)menu32 + 3) & ~3);

            /* If popup, transfer helpid */
            if ( flags & 1)
            {
                put_dword( &menu16, get_dword( &menu32 ) );
                level++;
            }

            if ( flags & MF_END )
                level--;
        }
}
예제 #6
0
STATIC_PREFIX void debugrom_save_to_spi(int argc, char * argv[])
{
    spi_init();
    if(argc!=4)
        return;
    unsigned dest,src,size;
    if(get_dword(argv[1],&dest)||get_dword(argv[2],&src) || get_dword(argv[3],&size))
        return;
    spi_program(dest,src,size);
}
예제 #7
0
// ---
DATA_PROC HDATA DATA_PARAM DATA_Deserialize( AVP_Serialize_Data* opt, void* buffer, AVP_dword size_in, AVP_dword* size_out ) {

	AVP_word            magic;
	AVP_Data*           data = 0;
	AVP_Serialize_Data  sd;
	AVP_Serialize_Data* psd;
	Serialize           sz;

	if ( !buffer || !size_in ) {
		_RPT0( _CRT_ASSERT, "Bad parameters" );
		return 0;
	}

	if ( opt )
		psd = opt;
	else {
		psd = &sd;
		memset( psd, 0, sizeof(AVP_Serialize_Data) );
	}

	init_get_bytes( &sz, buffer, size_in, psd->proc, psd->user_data );

	if ( get_word (&sz, &magic) != sizeof(magic) || magic != 0xadad ) {
		if ( size_out )
			*size_out = sz.tsize;
		return 0;
	}

	if ( get_dword (&sz, &psd->version) != sizeof(psd->version) || psd->version != 1 ) {
		if ( size_out )
			*size_out = sz.tsize;
		return 0;
	}

	if ( get_dword (&sz, &sz.crc_cluster) != sizeof(sz.crc_cluster) ) {
		if ( size_out )
			*size_out = sz.tsize;
		return 0;
	}

	sz.crc = -1;

	if ( !DATA_Get(&sz,0,&data) || !data || !flush_get_bytes(&sz) ) {
		if ( data ) {
			DATA_Remove( (HDATA)data, 0 );
			data = 0;
		}
		else
			flush_get_bytes( &sz );
	}
	if ( size_out )
		*size_out = sz.tsize;

	return DATA_HANDLE(data);
}
예제 #8
0
 DWORD get_id() const
 {
   DWORD id;
   if ( get_dword(t_symIndexId, &id) != S_OK )
     INTERR(30211);
   return id;
 }
예제 #9
0
// ---
static AVP_dword DATA_PARAM flush_get_bytes( Serialize* sz ) {
	if ( sz->crc_cluster && sz->crc_len != 0 && sz->crc != (AVP_dword)-1 ) {
		AVP_dword crc_saved;
		AVP_dword crc_counted = sz->crc;

		sz->crc_len = 0;
		if ( get_dword(sz, &crc_saved) == sizeof(sz->crc) && crc_saved == crc_counted ) {
			/*
			if ( sz->proc ) {
			if ( sz->proc(sz->buffer,sz->csize,sz->data) && sz->csize == out_size )
			return sz->tsize;
			else
			return 0;
			}
			else
			return sz->tsize;
			*/
			return sz->tsize;
		}
		else
			return 0;
	}
	else
		return sz->tsize;
}                 
예제 #10
0
/**
 * Tests 'store_dword()' and 'get_dword()'.
 */
void test_store_get_dword()
{
    allocate();
    uint32_t dummy_value = 0xFF00FF00;
    store_dword(ram, DUMMY_OFFSET, dummy_value);
    CU_ASSERT(dummy_value == get_dword(ram, DUMMY_OFFSET));
    deallocate();
}
예제 #11
0
파일: res32.c 프로젝트: bilboed/wine
/* all values must be zero except header size */
static int check_header(void)
{
    unsigned int size;

    if (get_dword()) return 0;        /* data size */
    size = get_dword();               /* header size */
    if (size == 0x20000000) byte_swapped = 1;
    else if (size != 0x20) return 0;
    if (get_word() != 0xffff || get_word()) return 0;  /* type, must be id 0 */
    if (get_word() != 0xffff || get_word()) return 0;  /* name, must be id 0 */
    if (get_dword()) return 0;        /* data version */
    if (get_word()) return 0;         /* mem options */
    if (get_word()) return 0;         /* language */
    if (get_dword()) return 0;        /* version */
    if (get_dword()) return 0;        /* characteristics */
    return 1;
}
예제 #12
0
STATIC_PREFIX void debugrom_ddr_init(int argc, char * argv[])
{
    
    unsigned i=0;
    if(argv[1])
        get_dword(argv[1],&i);
    //ddr_pll_init(&__ddr_setting);
    m6_ddr_init_test(i);
    
}
예제 #13
0
STATIC_PREFIX void clk_msr(int argc, char * argv[])
{
    
    unsigned id;
    
    serial_puts(argv[1]);
    
    serial_puts("(Mhz)=");
    get_dword(argv[1],&id);
    serial_put_dword(clk_util_clk_msr(id));
    
}
예제 #14
0
파일: res32.c 프로젝트: AlexSteel/wine
static void dump_res_data( const struct resource *res )
{
    unsigned int i = 0;
    unsigned int size = (res->data_size + 3) & ~3;

    if (!size) return;

    input_buffer = res->data;
    input_buffer_pos  = 0;
    input_buffer_size = size;

    output( "\t.long " );
    while (size > 4)
    {
        if ((i++ % 16) == 15) output( "0x%08x\n\t.long ", get_dword() );
        else output( "0x%08x,", get_dword() );
        size -= 4;
    }
    output( "0x%08x\n", get_dword() );
    assert( input_buffer_pos == input_buffer_size );
}
예제 #15
0
/**
 * A utility function to avoid duplication when testing pop() implementations.
 *
 * @param push_value TODO
 * @param pop_mode TODO
 * @param storage_location TODO
 * @param source_location TODO
 */
void
pop_test_util(uint32_t push_value, uint8_t pop_mode, uint32_t storage_location,
              int source_location)
{
    allocate();
    push(push_value);

    if (source_location == SOURCE_IMMEDIATE)
    {
        store_dword(ram, NEXT_INSTR, NEXT2_INSTR);

        if (storage_location == NEXT3_INSTR)
            store_dword(ram, NEXT2_INSTR, NEXT3_INSTR);

        exec(create_instruction(INSTR_POP, pop_mode, EMPTY_BYTE,
                                EMPTY_BYTE));
    }
    else
    {
        //  We can point the register to next instruction by default
        r[TEST_REGISTER] = NEXT_INSTR;

        if (storage_location == NEXT2_INSTR)
            store_dword(ram, NEXT_INSTR, NEXT2_INSTR);

        exec(create_instruction(INSTR_POP, pop_mode, EMPTY_BYTE,
                                TEST_REGISTER));
    }

    if (storage_location == REGISTER_LOCATION)
    {
        CU_ASSERT(push_value == r[TEST_REGISTER]);
    }
    else
    {
        switch (push_value)
        {
            case DUMMY_VALUE_32:
            CU_ASSERT(push_value == get_dword(ram, storage_location));
                break;
            case DUMMY_VALUE_16:
            CU_ASSERT(push_value == get_word(ram, storage_location));
                break;
            case DUMMY_VALUE_8:
            CU_ASSERT(push_value == get_byte(ram, storage_location));
                break;
            default:
            CU_FAIL("Invalid push_value");
        }
    }

    deallocate();
}
예제 #16
0
파일: samusrgrp.c 프로젝트: marioli/chntpw
int cmd_usrgrp(char *user, char *grp, int what, int human)
{
  int numgrp;
  int rid = 0;
  char *resolveduser = NULL;
  char *resolvedgroup = NULL;
  char s[200];

  numgrp = strtol(grp, NULL, 0);

  if ((H_SAM < 0) || (!user)) return(1);

  if (*user == '0' && *(user+1) == 'x') sscanf(user,"%i",&rid);
  
  if (!rid) { /* Look up username */
    /* Extract the unnamed value out of the username-key, value is RID  */
    snprintf(s,180,"\\SAM\\Domains\\Account\\Users\\Names\\%s\\@",user);
    rid = get_dword(hive[H_SAM],0,s, TPF_VK_EXACT|TPF_VK_SHORT);
    if (rid == -1) {
      printf("User <%s> not found\n",user);
      return(1);
    }
  }

  /* At this point we have a RID, so get the real username it maps to just to show it */
  resolveduser = sam_get_username(hive[H_SAM], rid);
  if (!resolveduser) return(1);  /* Fails if RID does not exists */

  resolvedgroup = sam_get_groupname(hive[H_SAM], numgrp);
  if (!resolvedgroup) return(1);  /* Fails if GID does not exists */


  if (human) printf("%s user <%s> with RID = %d (0x%0x) %s group <%s> with GID = %d (0x%x)\n",
		    (what == 1 ? "Add" : "Remove"),
		    resolveduser,
		    rid, rid,
		    (what == 1 ? "to" : "from"),
		    resolvedgroup,
		    numgrp, numgrp );

  FREE(resolveduser);
  FREE(resolvedgroup);

  switch (what) {
  case 1: return(!sam_add_user_to_grp(hive[H_SAM] ,rid, numgrp)); break;
  case 2: return(!sam_remove_user_from_grp(hive[H_SAM] ,rid, numgrp)); break;
  }


  return(0);

}
예제 #17
0
STATIC_PREFIX void start_arc(int argc,char * argv[] )
{
    unsigned addr;
    spi_init();
    get_dword(argv[1],&addr);
    /** copy ARM code*/
    memcpy((void*)0x49008000,(const void*)0x49000000,16*1024);
    writel((0x49008000>>14)&0xf,0xc810001c);
    /** copy ARC code*/
    memcpy((void*)0x49008000,(const void*)addr,16*1024);
    writel(0x1<<4,0xc8100020);
    writel(0x7fffffff,P_AO_RTI_STATUS_REG0);
    serial_puts("start up ARC\n");
//    writel(0x51001,0xc8100030);
    writel(1,P_AO_RTI_STATUS_REG1);
    writel(0x1,0xc1109964);
    writel(0x0,0xc1109964);
    unsigned a,b;
    unsigned timer_base;
    a=b=0x7fffffff;
    serial_puts("ARM is Live\n");
    timer_base=get_timer(0);
    do{
        a=readl(P_AO_RTI_STATUS_REG0);
        if((a&0x80000000)|| ((a==b)&&(get_timer(timer_base)<10000000)))
        {
            continue;
        }
        timer_base=get_timer(0);
        b=a;
        serial_puts("ARM is Live: ");
        serial_put_dword(a);
        switch(a&0xffff)
        {
            case 0: 
                serial_puts("ARM Exit Sleep Mode\n");
                break;
            
        }
       
        
    }while(a);
    
    
}
예제 #18
0
STATIC_PREFIX void caculate_sum(int argc,char * argv[] )
{
	int i;
	unsigned short sum=0;
	unsigned * magic;
	unsigned addr;
	get_dword(argv[1],&addr);
	volatile unsigned short *buf=(volatile unsigned short*)addr;
	for(i=0;i<0x1b0/2;i++)
	{
		sum^=buf[i];
	}

	for(i=256;i<CHECK_SIZE/2;i++)
	{
		sum^=buf[i];
	}
	buf[0x1b8/2]=sum;
	magic=(unsigned *)&buf[0x1b0/2];
}
예제 #19
0
STATIC_PREFIX void debug_read_reg(int argc, char * argv[])
{
    unsigned  reg;
    if(argc<2)
    {
        serial_puts("FAIL:Wrong read reg command\n");
        return;
    }
    if(get_dword(argv[1],&reg))
    {
        serial_puts("FAIL:Wrong reg addr=");
        serial_puts(argv[1]);
        serial_putc('\n');
        return;
    }
    serial_puts("OK:Read ");
    serial_put_hex(reg,32);
    serial_putc('=');
    serial_put_hex(readl(reg),32);
    serial_putc('\n');
}
예제 #20
0
파일: chmfile.c 프로젝트: WangGL1985/chmsee
static void
chmfile_windows_info(struct chmFile *cfd, ChmFile *chmfile)
{
  struct chmUnitInfo ui;
  unsigned char buffer[4096];
  size_t size = 0;
  u_int32_t entries, entry_size;
  u_int32_t hhc, hhk, title, home;

  if (chm_resolve_object(cfd, "/#WINDOWS", &ui) != CHM_RESOLVE_SUCCESS)
    return;

  size = chm_retrieve_object(cfd, &ui, buffer, 0L, 8);

  if (size < 8)
    return;

  entries = get_dword(buffer);
  if (entries < 1)
    return;

  entry_size = get_dword(buffer + 4);
  size = chm_retrieve_object(cfd, &ui, buffer, 8L, entry_size);
  if (size < entry_size)
    return;

  hhc = get_dword(buffer + 0x60);
  hhk = get_dword(buffer + 0x64);
  home = get_dword(buffer + 0x68);
  title = get_dword(buffer + 0x14);

  if (chm_resolve_object(cfd, "/#STRINGS", &ui) != CHM_RESOLVE_SUCCESS)
    return;

  size = chm_retrieve_object(cfd, &ui, buffer, 0L, 4096);

  if (!size)
    return;

  if (chmfile->hhc == NULL && hhc)
    chmfile->hhc = g_strdup_printf("/%s", buffer + hhc);
  if (chmfile->hhk == NULL && hhk)
    chmfile->hhk = g_strdup_printf("/%s", buffer + hhk);
  if (chmfile->home == NULL && home)
    chmfile->home = g_strdup_printf("/%s", buffer + home);
  if (chmfile->title == NULL && title)
    chmfile->title = g_strdup((char *)buffer + title);
}
예제 #21
0
/**************************************************************************
*                                                                         *
*                                                                         *
*                                                                         *
***************************************************************************/
uint32_t fat32_get_next_cluster(FAT32_FAT_DESCRIPTOR* fat_desc, const uint32_t current_cluster)
{
	
	static uint8_t 		fat_buffer[512];
	static uint32_t		prev_cluster = 0xffffffff;
	
	uint32_t		fat_pos;
	uint32_t		fat_offset;
	uint32_t		next_cluster;
	
	fat_offset = current_cluster / 0x80;
	
	// 최근에 읽은 클러스터를 다시 읽는 경우 기존의 데이터를 재활용한다(속도 향상)
	if (prev_cluster != fat_offset)	
	{
		fat32_device_read_sector(fat_desc->fat_start_sector + fat_offset, 1, fat_buffer);
		prev_cluster = fat_offset;
	}
		
	fat_pos = (current_cluster - (fat_offset * 0x80)) * 4;
	next_cluster = get_dword(fat_buffer + fat_pos);
	
	return next_cluster;
}
예제 #22
0
//format:id + len + block_id + zipflag + size + crc (for all data)
//    zipflag = 'Z': zipped data(only available for upg all, block_id = 0xFF),
//    zipfleg = other char, normal data
static void cmd_handle_transfer()
{
  u32 i = 0, id, index = 0, crc = CRC_INIT, zip = 0, tcrc = 0, seq = 0, seqtmp = 0;
  u32 total = 0, got = 0, len = 0;
  u8 *buff = (u8 *)(upg_cfg.flash_map_start);
  u8 *p = NULL;
  u8 start[10] = {0, };

  if(TRUE == upg_cfg.upg_all_flag)   //update all flash data
  {
    if(P2P_CMD_UPG_ALL != cmd_buff[2])
    {
      cmd_response(CMD_ERROR, P2P_CMD_TRANSFER, CMD_TRANS_UPGALL_ID_ERR);
      return;
    }

    total = get_dword(&cmd_buff[4]);
    if(total > upg_cfg.upg_all_size)
    {
      cmd_response(CMD_ERROR, P2P_CMD_TRANSFER, CMD_TRANS_UPGALL_LEN_ERR);
      return;
    }

    zip = ('Z' == cmd_buff[3]) ? 1 : 0; //check if zipped data
    if(zip)                        //if zipped data, store to bk place first.
    {
      upg_cfg.data_bk_start = upg_cfg.flash_map_start + upg_cfg.upg_all_size + 100 * 1024;
      buff = (u8 *)upg_cfg.data_bk_start;
    }
  }
  else   //update blocks
  {
    id = cmd_buff[2];
    if('Z' == cmd_buff[3])        //not support zipped block data
    {
      cmd_response(CMD_ERROR, P2P_CMD_TRANSFER, CMD_TRANS_ZIPPED_FOR_BLOCK);
      return;
    }
    total = get_dword(&cmd_buff[4]);
    //OS_PRINTK("total =%x\n",total);
    //check if size right with prev stored info
    if(BOOTLOADER_BLOCK_ID == id)
    {
      index = 0xFF;  //do not check total crc below for bootloader
    }
    else
    {
      for(i = 0; i < slave_info.block_num; i++)
      {
        if(slave_info.blocks[i].id == id)
        {
          if(slave_info.blocks[i].size != total) //check if the size is the same as informed bofore
          {
            cmd_response(CMD_ERROR, P2P_CMD_TRANSFER, CMD_TRANS_BLOCK_LEN_ERR);
            return;
          }
          else //record the block index for total crc check later
          {
            if(flash_mapping_type == 2)
            {
              //find the block start addr
              buff += (slave_info.blocks[i].base_addr + slave_info.dmh_start_addr);
            }
            else
            {
              buff += slave_info.blocks[i].base_addr; //find the block start addr
            }
            index = i;
            break;
          }
        }
      }
    }
    if(i >= slave_info.block_num)
    {
      cmd_response(CMD_ERROR, P2P_CMD_TRANSFER, CMD_TRANS_ID_NOT_EXIST);
      return;
    }
  }

  cmd_response(CMD_OK, 0, 0);        // respond command
  p = buff;
  got = 0;                          //actual got bytes
  flush_data();

  seq = 0;         //record data packet sequence
  while(got < total)
  {
    len = (total - got > P2P_PACKET_SIZE) ? P2P_PACKET_SIZE : total - got;

    //get packet start indicator
    start[0] = 0;      //start indecator 1
    start[1] = 0;      //start indecator 2
    start[2] = 0;      //sequence high byte
    start[3] = 0;      //sequence low byte

    if((SUCCESS != read_data(start, 4, 1000))
      || (P2P_START_INDICATOR != start[0])
      || (P2P_START_INDICATOR2 != start[1]))
    {
      continue;
    }

    //seq in slave should always >= seqs in master,
    //becasue master never trans a new packet before acked!
    seqtmp = (start[2] << 8 | start[3]);
    if(seqtmp != seq)
    {
      if(seqtmp == (seq - 1)) //the ack is lost
      {
        read_data(p, len + 4, 1000);
        cmd_response(CMD_ACK, (seq >> 8) & 0xFF, seq & 0xff); //ack the sequence
        continue;
      }
      else                  //not the start indicator, but the data
      {
        read_data(p, len + 4, 1000);
        continue;
      }
    }
예제 #23
0
//format:for blocks: ID+len+block num +{id, size}+{id, size}....
//       for upg all:ID+len+block num(=1) +P2P_CMD_UPG_ALL+size
static void cmd_handle_inform()
{
  u32 i, size, num = 0, tmp = 0;
  u32 dmh_start = 0, blk_start = 0, tmp_addr = 0;
  u8 *p = NULL;
  u8 *map_base = NULL;

  struct blk_info newblk[P2P_MAX_BLOCKS];

  if((1 == cmd_buff[2])
    && (P2P_CMD_UPG_ALL == cmd_buff[3]))                      //upgrade all
  {
    upg_cfg.upg_all_flag = TRUE;
    upg_cfg.upg_all_size = get_dword(&cmd_buff[4]);
    cmd_response(CMD_OK, 0, 0);
#ifndef WIN32
    //if (upg_cfg.upg_all_size > (512*KBYTES)) //for >512K size, sdram must >2M
    //  upg_cfg.flash_map_start = SDRAM_2M_THRESHOLD;
#endif
    return;
  }

  upg_cfg.upg_all_flag = FALSE;

  // Must call collect info first
  if(0 == slave_info.flash_size)
  {
    cmd_response(CMD_ERROR, P2P_CMD_INFORM, CMD_INFORM_NO_INFO);
    return;
  }
  num = cmd_buff[2];     //block number to upgrade
  p = &cmd_buff[3];      //start: blk id + new blk size

  for(i = 0; i < num; i++)
  {
    newblk[i].block_id = p[i * 5];
    newblk[i].size = get_dword(&p[i * 5 + 1]);
  }


  map_base = (u8 *)upg_cfg.flash_map_start;

  //check if bootloader is needed to upg
  size = find_id(newblk, num, BOOTLOADER_BLOCK_ID);

  if(0 != size)  //bootloader need upg
  {
    upg_cfg.start_burn_addr = 0;
    dmh_start = size + 256; //reserve space in ram
    slave_info.dmh_start_addr = size + 256;
  }
  else  //just record where start to burn flash, save some time if bootloader is not need to upg
  {
    upg_cfg.start_burn_addr = slave_info.bootloader_size + 256 * 1024;

    if(flash_mapping_type == 2)
    {
      dmh_start = dmh_start_offset;
    }
    else
    {
      dmh_start = slave_info.bootloader_size;
    }
  }

  if(flash_mapping_type == 2)
  {
    blk_start = dmh_start + (28 + slave_info.block_num * slave_info.bh_size);
    // 1k alignment
    blk_start = ((blk_start + (1024) - 1) / 1024) * 1024;
  }
  else
  {
    //record the real block data start address
    blk_start = dmh_start + (12 + slave_info.block_num * slave_info.bh_size);
  }

  for(i = 0; i < slave_info.block_num; i++)
  {
    size = find_id(newblk, num, slave_info.blocks[i].id);

    if(0 != size)     //block to upgrade, update its size, update
    {
      slave_info.blocks[i].size = size;
    }
    else  //block not to upgrade, record its flash base addr, not update
    {
      if(flash_mapping_type == 2)
      {
        tmp_addr = slave_info.blocks[i].base_addr + dmh_start_offset;
      }
      else
      {
        tmp_addr = slave_info.blocks[i].base_addr;
      }
    }
    if((BLOCK_TYPE_IW == slave_info.blocks[i].type)
      || (BLOCK_TYPE_PIECE == slave_info.blocks[i].type))
    {
      //align IW to 64K position
      tmp = (blk_start + (FLASH_SECTION_SIZE - 1)) / FLASH_SECTION_SIZE * FLASH_SECTION_SIZE;
      if(tmp > blk_start)
      {
        memset(map_base + blk_start, 0xFF, tmp - blk_start);
      }
      blk_start = tmp;
    }
    #if 0
    if((i != 0)
      && (BLOCK_TYPE_IW != slave_info.blocks[i].type))
    {
      slave_info.blocks[i].base_addr =
        slave_info.blocks[i - 1].base_addr + slave_info.blocks[i - 1].size;
    }
    #endif
    slave_info.blocks[i].base_addr = blk_start;
    blk_start += slave_info.blocks[i].size;

    if(0 == size)  //block do not upgrade, copy from flash to construct new flash map
    {
      if(SUCCESS != charsto_read(p_charsto, tmp_addr,
                                 map_base + blk_start - slave_info.blocks[i].size,
                                 slave_info.blocks[i].size))
      {
        cmd_response(CMD_ERROR, P2P_CMD_INFORM, CMD_INFORM_READ_FLASH_ERR);
        return;
      }
    }

    if(flash_mapping_type == 2)
     slave_info.blocks[i].base_addr -= dmh_start;
  }

  //MAP Construct: fill the dmh to ram at last
  p = (u8 *)&slave_info;
  p += fieldoffset(upg_slave_info, sdram_size);
  if(flash_mapping_type == 2)
  {
    memcpy(map_base + dmh_start, dmh_tag_2, 12);
    memcpy(map_base + dmh_start + 12, dmh_man_blocks_size_2, 4);
    memcpy(map_base + dmh_start + 16, p, (12 + slave_info.block_num * slave_info.bh_size));
  }
  else
  {
    memcpy(map_base + dmh_start, p, (12 + slave_info.block_num * slave_info.bh_size));
  }
  cmd_response(CMD_OK, 0, 0);

  return;
}
예제 #24
0
static s32 check_crc(void)
{
#ifndef GET_FLASH_DATA_BY_DRIVER
  u32 dmh_start_addr = 0, block_base_addr = 0;
  u32 flash_size = 0, block_num = 0, bh_size = 0;
  u32 i, crc = 0, bcrc = 0, bid = 0, baddr = 0, bsize = 0;

  dmh_start_addr = *(u32 *)(FLASHSTART_ADDR + DMH_START_OFFSET) + FLASHSTART_ADDR;
  flash_size = *(u32 *)(dmh_start_addr + DMH_FLASH_SIZE_OFFSET); //flash size
  block_num = *(u16 *)(dmh_start_addr + DMH_BLOCKNUM_OFFSET); //total block count
  bh_size = *(u16 *)(dmh_start_addr + DMH_BHSIZE_OFFSET); //each block header size

  if((!flash_size)
    || (!block_num)
    || (!bh_size)
    || (block_num * bh_size > flash_size))
  {
    return -1; //dmh info error
  }
  block_base_addr = dmh_start_addr + 12; //block header start addr
  for(i = 0; i < block_num; i++)
  {
    bcrc = *(u32 *)(block_base_addr + i * bh_size + BLOCK_CRC_OFFSET);
    if(bcrc == NO_CRC)  // NCRC
    {
      continue;
    }

    bid = *(u8 *)(block_base_addr + i * bh_size + BLOCK_ID_OFFSET);
    baddr = *(u32 *)(block_base_addr + i * bh_size + BLOCK_BASEADDR_OFFSET);
    bsize = *(u32 *)(block_base_addr + i * bh_size + BLOCK_SIZE_OFFSET);

    if((!baddr)
      || (!bsize)
      || (baddr > flash_size)
      || (bsize > flash_size))
    {
      return -1;  //dmh info error
    }

    crc = crc_fast_calculate(CRC_MODE, CRC_INIT, (u8 *)(baddr + FLASHSTART_ADDR), bsize);
    if(crc != bcrc)
    {
      return -2; //crc error
    }
  }
  return 0;
#else
  u32 dmh_start_addr = 0, block_base_addr = 0;
  u32 flash_size = 0, sdram_size = 0, block_num = 0, bh_size = 0;
  u32 i = 0, crc = 0, bcrc = 0, bid = 0, baddr = 0, bsize = 0;
  u8 buff[1024] = {0, };
  u8 *bk = NULL;

  /*get dmh_start_add*/
  if(flash_mapping_type == 2)
  {
    dmh_start_addr = dmh_start_offset;
    if(SUCCESS != charsto_read(p_charsto, dmh_start_addr + 16, buff, 12))
    {
      return -3;
    }
  }
  else
  {
    if(SUCCESS != charsto_read(p_charsto, DMH_START_OFFSET, buff, 4))
    {
      return -3;
    }
    dmh_start_addr = get_dword(buff);
    if(SUCCESS != charsto_read(p_charsto, dmh_start_addr, buff, 12))
    {
      return -3;
    }
    if(0 != dmh_start_addr % FLASH_SECTION_SIZE)
    {
      return -1;
    }
  }

  flash_size = get_dword(&buff[DMH_FLASH_SIZE_OFFSET]);
  sdram_size = get_dword(&buff[DMH_SDRAM_SIZE_OFFSET]);
  block_num = get_word(&buff[DMH_BLOCKNUM_OFFSET]);
  bh_size = get_word(&buff[DMH_BHSIZE_OFFSET]);

  if((!sdram_size)
    || (!flash_size)
    || (!block_num)
    || (!bh_size)
    || (block_num * bh_size > flash_size))
  {
    return -1; //dmh info error
  }
  if(flash_mapping_type == 2)
  {
    block_base_addr = dmh_start_addr + 12 + 16;
  }
  else
  {
    block_base_addr = dmh_start_addr + 12;
  }
#ifndef WIN32
  // if (sdram_size > SDRAM_2M_THRESHOLD) // if sdram > 2M,
  //   upg_cfg.flash_map_start = SDRAM_2M_THRESHOLD;
#endif
  upg_cfg.data_bk_start = upg_cfg.flash_map_start + flash_size + 100 * 1024;
  bk = (u8 *)upg_cfg.data_bk_start;

  if(SUCCESS != charsto_read(p_charsto, block_base_addr, buff, block_num * bh_size))
  {
    return -3;
  }

  for(i = 0; i < block_num; i++)
  {
    bcrc = get_dword(buff + i * bh_size + BLOCK_CRC_OFFSET);
    if(bcrc == NO_CRC)  // NCRC
    {
      continue;
    }

    bid = get_dword(buff + i * bh_size + BLOCK_ID_OFFSET);

    baddr = get_dword(buff + i * bh_size + BLOCK_BASEADDR_OFFSET);
    if(flash_mapping_type == 2)
    {
      baddr += dmh_start_addr;
    }
    bsize = get_dword(buff + i * bh_size + BLOCK_SIZE_OFFSET);

    if((!baddr)
      || (!bsize)
      || (baddr > flash_size)
      || (bsize > flash_size))
    {
      return -1;  //dmh info error
    }
    if(SUCCESS != charsto_read(p_charsto, baddr, bk, bsize))
    {
      return -3;
    }
    crc = crc_fast_calculate(CRC_MODE, CRC_INIT, bk, bsize);
    if(crc != bcrc)
    {
      test_tmp = i;
      return -2;
    }
  }
  return 0;
#endif
}
예제 #25
0
static s32 flash_mapping_type_test(void)
{
  u32 i = 0, j = 0;
  u32 ret;
  u8 buff[1024] = {0, };
  u8 dmh_indicator[12] = "*^_^*DM(^o^)";
  u32 dmh_man_blocks_size = 0;
  u32 h_start_offset_0 = 0;

  if(SUCCESS != charsto_read(p_charsto, 0, buff, sizeof(buff)))
  {
    return -3;
  }
  for(i = 0; i < sizeof(buff); i++)
  {
    ret = memcmp(buff + i, dmh_indicator, 12);
    if(ret == 0)
    {
      flash_mapping_type = 2;
      dmh_man_blocks_size = get_dword(&buff[DMH_MAN_BLOCKS_SIZE_OFFSET + i]);
      break;
    }
  }

  h_start_offset_0 = 256 * 1024;

  if(i == sizeof(buff))
  {
    flash_mapping_type = 1;
    return 0;
  }

  if(flash_mapping_type == 2)
  {
    //The second DMH address is k allign case.
    for(i = 0; i < 20; i++)
    {
      if(SUCCESS !=
         charsto_read(p_charsto,
                      (i *
                       1024) + dmh_start_offset_0 + dmh_man_blocks_size + 0xC + h_start_offset_0,
                      buff, sizeof(buff)))
      {
        return -3;
      }
      ret = memcmp(buff, dmh_indicator, 12);
      if(ret == 0)
      {
        dmh_start_offset =
          (i * 1024) + dmh_start_offset_0 + dmh_man_blocks_size + 0xC + h_start_offset_0;
        return SUCCESS;
      }
    }
    //The second DMH address is not K allign case.
    for(i = 0; i < 20; i++)
    {
      if(SUCCESS !=
         charsto_read(p_charsto,
                      (i * 1024) + dmh_start_offset_0 + dmh_man_blocks_size + h_start_offset_0,
                      buff, sizeof(buff)))
      {
        return -3;
      }
      for(j = 0; j < sizeof(buff); j++)
      {
        ret = memcmp(buff + j, dmh_indicator, 12);
        if(ret == 0)
        {
          dmh_start_offset =
            (i * 1024) + j + dmh_start_offset_0 + dmh_man_blocks_size + h_start_offset_0;
          return SUCCESS;
        }
      }
    }
  }

  return ERR_FAILURE;
}
예제 #26
0
static AVP_dword DATA_PARAM ReadPropertyItem( Serialize* sz, AVP_byte type, void* val ) {
	AVP_word size;
	AVP_byte tmp;
	AVP_Bin_Item* v;

	switch( type ) {
		case avpt_nothing : return 1;

		// Byte-sized types
		case avpt_char    :
		case avpt_byte    :
		case avpt_group   : return get_byte(sz, (AVP_byte *) val);

		case avpt_bool    : 
			size = (AVP_word)get_byte( sz, &tmp);
			*(AVP_bool *)val = tmp;
			return size;

		// Word-sized types            
		case avpt_wchar   :
		case avpt_short   :
		case avpt_word    : return get_word(sz, (AVP_word *) val);

		// Dword-sized types      
		case avpt_long    :
		case avpt_dword   :
		case avpt_int     :
		case avpt_uint    : return get_dword( sz, (AVP_dword*)val );

		// QWord-sized types
		case avpt_qword   :
		case avpt_longlong: return get_qword( sz, (AVP_qword*)val );

		// size_t-sized types
		case avpt_size_t  : return get_size_t( sz, (AVP_size_t*)val );

		// Custom structures
		case avpt_date    : return get_date(sz, (AVP_date *)val);
		case avpt_time    : return get_time(sz, (AVP_time *)val);
		case avpt_datetime: return get_datetime(sz, (AVP_datetime *) val);

		// String
		case avpt_str :                           
			if ( get_word( sz, &size) == sizeof(size) ) {
				if ( size != USHRT_MAX ) {
					AVP_char * ptr = allocator( size + sizeof(AVP_char) );
					_ASSERT( ptr );
					*(AVP_char **)val = ptr;

					if ( get_bytes(sz,ptr,size) == size ) {
						ptr[size] = 0;
						return sizeof(size) + size;
					}
					else {
						ptr[0] = 0;
						return 0;
					}
				}
				else
					return sizeof(size);
			}
			else
				return 0;

		// Windows unicode string
		case avpt_wstr :
			if ( get_word( sz, &size) == sizeof(size) ) {
				if ( size != USHRT_MAX ) {
					AVP_wchar * ptr = allocator( size + sizeof(AVP_wchar) );
					_ASSERT( ptr );
					*(AVP_wchar **)val = ptr;

					if ( get_bytes(sz,ptr,size) == size ) {
						ptr[size/sizeof(AVP_wchar)] = 0;
						convert_wchar_string ((wchar_t*) ptr);
						return sizeof(size) + size;
					}
					else {
						ptr[0] = 0;
						return 0;
					}
				}
				else
					return sizeof(size);
			}
			else
				return 0;

		case avpt_bin :
			v = val;
			v->size = 0;
			if ( get_word( sz, &size) == sizeof(size) )
			{
				v->size = size;
				if ( v->size ) {
					v->data = allocator( v->size );
					_ASSERT( v->data );
				}
				else
					v->data = 0;
				if ( !v->size || (get_bytes(sz,v->data,v->size) == v->size) ) 
					return sizeof(v->size) + v->size;
				else 
					return 0;
			}
			else
				return 0;

		default :
			_RPT0( _CRT_ASSERT, "Bad property type" );
			return 0;
	}

	return size ? size + sizeof(AVP_Property) : 0;
}
예제 #27
0
static s32 get_info(upg_slave_info *info)
{
#ifndef GET_FLASH_DATA_BY_DRIVER
  u32 dmh_start = 0, dmh_start_addr = 0, block_base_addr = 0;
  u32 flash_size = 0, sdram_size = 0, block_num = 0, bh_size = 0;

  dmh_start = *(u32 *)(FLASHSTART_ADDR + DMH_START_OFFSET); //dmh start offset in flash

  dmh_start_addr = dmh_start + FLASHSTART_ADDR; //absolute DMH start address
  sdram_size = *(u32 *)(dmh_start_addr + DMH_SDRAM_SIZE_OFFSET);
  flash_size = *(u32 *)(dmh_start_addr + DMH_FLASH_SIZE_OFFSET);
  block_num = *(u16 *)(dmh_start_addr + DMH_BLOCKNUM_OFFSET); //total block count
  bh_size = *(u16 *)(dmh_start_addr + DMH_BHSIZE_OFFSET); //each block header size

  block_base_addr = dmh_start_addr + 12; //absolute addr of block header start

  if((!flash_size)
    || (!block_num)
    || (!bh_size)
    || (flash_size % FLASH_SECTION_SIZE)
    || (block_num * bh_size > flash_size)
    || (block_num > P2P_MAX_BLOCKS))
  {
    return -1; //dmh info error
  }

  info->sdram_size = sdram_size;
  info->flash_size = flash_size;
  info->bootloader_size = dmh_start;
  info->dmh_start_addr = dmh_start;
  info->block_num = block_num;
  info->bh_size = bh_size;
  memcpy((u8 *)(info->blocks), (u8 *)block_base_addr, block_num * bh_size);
  //if (sdram_size > SDRAM_2M_THRESHOLD)
  //  upg_cfg.flash_map_start = SDRAM_2M_THRESHOLD;

  upg_cfg.data_bk_start = upg_cfg.flash_map_start + flash_size + 100 * 1024;
  return 0;
#else
  u32 dmh_start_addr = 0, block_base_addr = 0;
  u32 flash_size = 0, sdram_size = 0, block_num = 0, bh_size = 0;
  u8 buff[1024] = {0, };

  if(flash_mapping_type == 2)
  {
    if(SUCCESS != charsto_read(p_charsto, 8, buff, 4))
    {
      return -3;
    }
    info->bootloader_size = get_dword(&buff[0]);

    memset(buff, 0x00, sizeof(buff));

    dmh_start_addr = dmh_start_offset;
    if(0 != dmh_start_addr % FLASH_SECTION_SIZE)
    {
      return -1;
    }

    if(SUCCESS != charsto_read(p_charsto, dmh_start_addr, buff, 16))
    {
      return -3;
    }

    memcpy(dmh_tag_2, buff, 12);
    memcpy(dmh_man_blocks_size_2, buff + 12, 4);

    memset(buff, 0x00, sizeof(buff));
    if(SUCCESS != charsto_read(p_charsto, dmh_start_addr + 16, buff, 12))
    {
      return -3;
    }
    block_base_addr = dmh_start_addr + 12 + 16; //offset in flash
  }
  else
  {
    if(SUCCESS != charsto_read(p_charsto, DMH_START_OFFSET, buff, 4))
    {
      return -3;
    }
    dmh_start_addr = get_dword(buff);

    if(0 != dmh_start_addr % FLASH_SECTION_SIZE)
    {
      return -1;
    }
    if(SUCCESS != charsto_read(p_charsto, dmh_start_addr, buff, 12))
    {
      return -3;
    }
    block_base_addr = dmh_start_addr + 12; //offset in flash
    info->bootloader_size = dmh_start_addr;
  }

  sdram_size = get_dword(&buff[DMH_SDRAM_SIZE_OFFSET]);
  flash_size = get_dword(&buff[DMH_FLASH_SIZE_OFFSET]);
  block_num = get_word(&buff[DMH_BLOCKNUM_OFFSET]);
  bh_size = get_word(&buff[DMH_BHSIZE_OFFSET]);

  if((!flash_size)
    || (!block_num)
    || (!bh_size)
    || (flash_size % FLASH_SECTION_SIZE)
    || (block_num * bh_size > flash_size)
    || (block_base_addr > flash_size)
    || (block_num > P2P_MAX_BLOCKS))
  {
    return -1; //dmh info error
  }
  info->dmh_start_addr = dmh_start_addr;
  info->sdram_size = sdram_size;
  info->flash_size = flash_size;
  info->block_num = block_num;
  info->bh_size = bh_size;

  if(SUCCESS != charsto_read(p_charsto, block_base_addr,
                             (u8 *)(info->blocks), block_num * bh_size))
  {
    return -3;
  }
#ifndef WIN32
  if(sdram_size > SDRAM_2M_THRESHOLD)
  {
    upg_cfg.flash_map_start = SDRAM_2M_THRESHOLD;
  }
#endif
  upg_cfg.data_bk_start = upg_cfg.flash_map_start + flash_size + 100 * 1024;

  return 0;
#endif
}
예제 #28
0
//format:id + len + block_id + zipflag + size + crc (for all data)
//    zipflag = 'Z': zipped data(only available for upg all, block_id = 0xFF),
//    zipfleg = other char, normal data
static void diamond_set_hw()
{
  u32 data_size = get_dword(&cmd_buff[2]);
  u8 start[2] = {0};
  u32 crc = 0;
  u32 cal_crc = 0;
  hw_cfg_t hw_cfg = {0};
  if(data_size == sizeof(hw_cfg_t))
  {
    cmd_response(DM_RES_ERR, DM_ST_SET_HW, DM_ERR_DATA_SIZE);
    return;
  }
   diamond_fp_enable(FALSE);

  //get packet start indicator
  start[0] = 0;        //start indecator 1
  start[1] = 0;        //start indecator 2
  flush_data();

  if((SUCCESS != read_data(start, 2, 4000))
    || (DM_INDICATOR1 != start[0])
    || (DM_INDICATOR2 != start[1]))
  {
    cmd_response(DM_RES_ERR, DM_ST_SET_HW, DM_ERR_INDICATOR);
    flush_data();
    diamond_fp_enable(TRUE);
    return;
  }
  //get data
  if(SUCCESS != read_data((u8 *)&hw_cfg, sizeof(hw_cfg_t), 4000))
  {
    cmd_response(DM_RES_ERR, DM_ST_SET_HW, DM_ERR_TIMEOUT);
    flush_data();
    diamond_fp_enable(TRUE);
    return;
  }

  //get crc
  if(SUCCESS != read_data((u8 *)&crc, 4, 4000))
  {
    cmd_response(DM_RES_ERR, DM_ST_SET_HW, DM_ERR_TIMEOUT);
    flush_data();
    diamond_fp_enable(TRUE);
    return;
  }

  //check crc
  cal_crc = crc_fast_calculate(CRC_MODE, CRC_INIT, (u8 *)&hw_cfg, sizeof(hw_cfg_t));
  if(crc != cal_crc)
  {
    cmd_response(DM_RES_ERR, DM_ST_SET_HW, DM_ERR_CRC);
    flush_data();
    diamond_fp_enable(TRUE);
    return;
  }

  diamond_fp_enable(TRUE);

  memcpy(&diamond_cfg.hw_cfg, &hw_cfg, sizeof(hw_cfg_t));

  //try to config project.
  if(diamond_set())
  {
    cmd_response(DM_RES_OK, DM_ST_SET_HW, DM_ERR_NONE);
  }
  else
  {
    cmd_response(DM_RES_ERR, DM_ST_SET_HW, DM_ERR_NONE);
  }
  return;
}
예제 #29
0
int iKX::init(int device,int ignore_winmm)
{
    int i=0;
    char string[1024];
    int ret=-1;

    if(device_num!=-1) // double init
    {
     strcpy(error_name,"interface already initialized");
     debug("iKX init(): already initialized\n");
     return -7;
    }

    strcpy(error_name,"no error");

    // asio init
    asio_inited=0;
    last_asio_voice=-1;

    asio_method=0;

     asio_iks_property=NULL;
     asio_secondary_buffer=NULL;
     asio_prim_buffer=NULL;
     asio_ds=NULL;

     pRenderEnumerator=0;
     pRenderFilter=0;
     pRenderPin=0;

    memset(asio_mem_table,0,sizeof(asio_mem_table));

    memset(&guid_,0,sizeof(guid_));

    device_num=device;
    
    HDEVINFO hInfo=SetupDiGetClassDevs((GUID *)&KSCATEGORY_AUDIO,NULL,NULL,DIGCF_DEVICEINTERFACE |DIGCF_PRESENT);
    
    if(hInfo==INVALID_HANDLE_VALUE)
    { 
     debug("iKX init(): setupdigetclassdevs failed [%x]\n",GetLastError());
     strcpy(error_name,"error enumerating devices");
     return ret; 
    }
    
    SP_DEVINFO_DATA devinfo;
    devinfo.cbSize=sizeof(devinfo);

    while(SetupDiEnumDeviceInfo(hInfo,i,&devinfo))
    {
        i++;
        if(SetupDiGetDeviceInstanceId(hInfo,&devinfo,string,sizeof(string),NULL))
        {
            if(
               (strstr(string,"VEN_1102&DEV_0002")==NULL) &&
               (strstr(string,"VEN_1102&DEV_0004")==NULL) &&
               (strstr(string,"VEN_1102&DEV_0008")==NULL) 
              ) // FIXME: bad test, actually :(
            { 
              continue; 
            }
        }
        else
        {
         continue;
         }

        SP_DEVICE_INTERFACE_DATA data;
        data.cbSize=sizeof(data);
        int j=0;
        while(SetupDiEnumDeviceInterfaces(hInfo,&devinfo,(GUID *)&KSCATEGORY_AUDIO,j++,&data)==TRUE)
        {
            DWORD ReqLen=0;
            SetupDiGetInterfaceDeviceDetail (
                hInfo,
                &data,
                NULL,
                0,
                &ReqLen,
            NULL
            );

                PSP_INTERFACE_DEVICE_DETAIL_DATA m_Detail = PSP_INTERFACE_DEVICE_DETAIL_DATA(new char[ReqLen]);

                if ( m_Detail )
                {
                        m_Detail->cbSize = sizeof SP_INTERFACE_DEVICE_DETAIL_DATA;

                        if(SetupDiGetInterfaceDeviceDetail (
                            hInfo,
                            &data,
                            m_Detail,
                            ReqLen,
                            &ReqLen,
                            NULL
                            )==TRUE)
                        {
                            if(strstr(m_Detail->DevicePath,"kx_topo1")!=NULL)
                            {
                             HKEY key=SetupDiOpenDeviceInterfaceRegKey(hInfo,&data,0,KEY_ALL_ACCESS);
                             if(key!=INVALID_HANDLE_VALUE)
                             {
                                      DWORD type; type=REG_SZ;
                                      char tmp_str[256];
                                      DWORD len; len=(DWORD)sizeof(tmp_str);
                                      if(RegQueryValueEx(key,"FriendlyName",NULL,&type,(unsigned char *)tmp_str,&len)==ERROR_SUCCESS)
                                      {
                                        strncpy(mixer_name,tmp_str,sizeof(mixer_name));
                                      }
                                      RegCloseKey(key);
                             }
                             strncpy(topo_path,m_Detail->DevicePath,sizeof(topo_path));
                            } else
                            if(strstr(m_Detail->DevicePath,"kx_wave0")!=NULL)
                            {
                             HKEY key=SetupDiOpenDeviceInterfaceRegKey(hInfo,&data,0,KEY_ALL_ACCESS);
                             if(key!=INVALID_HANDLE_VALUE)
                             {
                                      DWORD type; type=REG_SZ;
                                      char tmp_str[256];
                                      DWORD len; len=(DWORD)sizeof(tmp_str);
                                      if(RegQueryValueEx(key,"FriendlyName",NULL,&type,(unsigned char *)tmp_str,&len)==ERROR_SUCCESS)
                                      {
                                        strncpy(wave_name,tmp_str,sizeof(wave_name));

                                        strncpy(wave23_name,tmp_str,sizeof(wave_name));
                                        char *p=strstr(wave23_name," 0/1");
                                        if(p)
                                        {
                                         *p=0;
                                         strcpy(wave45_name,wave23_name);
                                         strcpy(wave67_name,wave23_name);
                                         strcpy(waveHQ_name,wave23_name);

                                         strcat(wave23_name," 2/3");
                                         strcat(wave45_name," 4/5");
                                         strcat(wave67_name," 6/7");
                                         strcat(waveHQ_name," HQ");
                                        }
                                        else
                                        {
                                         wave23_name[0]=0;
                                         debug("ikX API: not all the 4 wave devices were found... strange\n");
                                        }
                                      }
                                      RegCloseKey(key);
                             }
                             strncpy(wave_path,m_Detail->DevicePath,sizeof(wave_path));
                            } else
                            if(strstr(m_Detail->DevicePath,"kx_uart2")!=NULL)
                            {
                             //strncpy(uart2_path,m_Detail->DevicePath,sizeof(uart2_path));
                             HKEY key=SetupDiOpenDeviceInterfaceRegKey(hInfo,&data,0,KEY_ALL_ACCESS);
                             if(key!=INVALID_HANDLE_VALUE)
                             {
                                      DWORD type; type=REG_SZ;
                                      char tmp_str[256];
                                      DWORD len; len=(DWORD)sizeof(tmp_str);
                                      if(RegQueryValueEx(key,"FriendlyName",NULL,&type,(unsigned char *)tmp_str,&len)==ERROR_SUCCESS)
                                      {
                                        strncpy(uart2_name,tmp_str,sizeof(uart2_name));
                                      }
                                      RegCloseKey(key);
                             }
                            } else
                            if(strstr(m_Detail->DevicePath,"kx_uart1")!=NULL)
                            {
                             //strncpy(uart_path,m_Detail->DevicePath,sizeof(uart_path));
                             HKEY key=SetupDiOpenDeviceInterfaceRegKey(hInfo,&data,0,KEY_ALL_ACCESS);
                             if(key!=INVALID_HANDLE_VALUE)
                             {
                                      DWORD type; type=REG_SZ;
                                      char tmp_str[256];
                                      DWORD len; len=(DWORD)sizeof(tmp_str);
                                      if(RegQueryValueEx(key,"FriendlyName",NULL,&type,(unsigned char *)tmp_str,&len)==ERROR_SUCCESS)
                                      {
                                        strncpy(uart_name,tmp_str,sizeof(uart_name));
                                      }
                                      RegCloseKey(key);
                             }
                            } else
                            if(strstr(m_Detail->DevicePath,"kx_ctrl")!=NULL)
                            {
                             //strncpy(ctrl_path,m_Detail->DevicePath,sizeof(ctrl_path));
                             HKEY key=SetupDiOpenDeviceInterfaceRegKey(hInfo,&data,0,KEY_ALL_ACCESS);
                             if(key!=INVALID_HANDLE_VALUE)
                             {
                                      DWORD type; type=REG_SZ;
                                      char tmp_str[256];
                                      DWORD len; len=(DWORD)sizeof(tmp_str);
                                      if(RegQueryValueEx(key,"FriendlyName",NULL,&type,(unsigned char *)tmp_str,&len)==ERROR_SUCCESS)
                                      {
                                        strncpy(ctrl_name,tmp_str,sizeof(ctrl_name));
                                      }
                                      RegCloseKey(key);
                             }
                            } else
                            if(strstr(m_Detail->DevicePath,"kx_synth2")!=NULL)
                            {
                             //strncpy(synth2_path,m_Detail->DevicePath,sizeof(synth2_path));
                             HKEY key=SetupDiOpenDeviceInterfaceRegKey(hInfo,&data,0,KEY_ALL_ACCESS);
                             if(key!=INVALID_HANDLE_VALUE)
                             {
                                      DWORD type; type=REG_SZ;
                                      char tmp_str[256];
                                      DWORD len; len=(DWORD)sizeof(tmp_str);
                                      if(RegQueryValueEx(key,"FriendlyName",NULL,&type,(unsigned char *)tmp_str,&len)==ERROR_SUCCESS)
                                      {
                                        strncpy(synth2_name,tmp_str,sizeof(synth2_name));
                                      }
                                      RegCloseKey(key);
                             }
                            } else
                            if(strstr(m_Detail->DevicePath,"kx_synth1")!=NULL)
                            {
                             //strncpy(synth_path,m_Detail->DevicePath,sizeof(synth_path));
                             HKEY key=SetupDiOpenDeviceInterfaceRegKey(hInfo,&data,0,KEY_ALL_ACCESS);
                             if(key!=INVALID_HANDLE_VALUE)
                             {
                                      DWORD type; type=REG_SZ;
                                      char tmp_str[256];
                                      DWORD len; len=(DWORD)sizeof(tmp_str);
                                      if(RegQueryValueEx(key,"FriendlyName",NULL,&type,(unsigned char *)tmp_str,&len)==ERROR_SUCCESS)
                                      {
                                        strncpy(synth_name,tmp_str,sizeof(synth_name));
                                      }
                                      RegCloseKey(key);
                             }
                            }
                        } // if(SetupDiGetInterfaceDeviceDetail)
                        delete m_Detail;
                } // if detail -- SetupDiGetInterfaceDeviceDetail
       } // while enum interfaces

       if(wave_path[0] && topo_path[0]) // have necessary interfaces:
       {
           if(device!=0)
           { 
             device--; 
             // clean-up:
             mixer_name[0]=0; topo_path[0]=0;
             wave_name[0]=0;
             wave23_name[0]=0;
             wave45_name[0]=0;
             wave67_name[0]=0;
             waveHQ_name[0]=0;  wave_path[0]=0;
             synth_name[0]=0;
             synth2_name[0]=0;
             uart_name[0]=0;
             uart2_name[0]=0;
             ctrl_name[0]=0;

             continue; 
           }
           // right device with correct # found:
           break;
       }
    } // enum dev info
    SetupDiDestroyDeviceInfoList(hInfo);

    if(wave_path[0])
    {
        hWave = (void *)CreateFile(
        wave_path,
        GENERIC_READ,
        FILE_SHARE_READ | FILE_SHARE_WRITE,
        NULL,
        OPEN_EXISTING,
        0,
        NULL
        );
        if((HANDLE)hWave == INVALID_HANDLE_VALUE)
        {
                debug("iKX init(): error opening wave device [%x]\n",GetLastError());
                strcpy(error_name,"error opening wave device");
        return GetLastError();
        }   
    } 

    if(topo_path[0])
    {
        hTopo = (void *)CreateFile(
        topo_path,
        GENERIC_READ,
        FILE_SHARE_READ | FILE_SHARE_WRITE,
        NULL,
        OPEN_EXISTING,
        0,
        NULL
        );
        if((HANDLE)hTopo == INVALID_HANDLE_VALUE)
        {
            debug("iKX init() error opening topology device [%x]\n",GetLastError());
            strcpy(error_name,"error opening topology device");
        return GetLastError();
        }   
    } 

    if(hTopo && hWave)
    {
                char card_name[KX_MAX_STRING];
                get_string(KX_STR_CARD_NAME,card_name);

                if(!mixer_name[0])
                 sprintf(mixer_name,"kX Mixer %s 0/1",card_name);
                if(!wave_name[0])
                  sprintf(wave_name,"kX Wave %s 0/1",card_name);
                if(!wave23_name[0])
                  sprintf(wave23_name,"kX Wave %s 2/3",card_name);
                if(!wave45_name[0])
                  sprintf(wave45_name,"kX Wave %s 4/5",card_name);
                if(!wave67_name[0])
                  sprintf(wave67_name,"kX Wave %s 6/7",card_name);
                if(!waveHQ_name[0])
                  sprintf(waveHQ_name,"kX Wave %s HQ",card_name);
                if(!uart2_name[0])
                  sprintf(uart2_name,"kX Uart2 %s",card_name);
                if(!uart_name[0])
                  sprintf(uart_name,"kX Uart %s",card_name);
                if(!synth_name[0])
                  sprintf(synth_name,"kX Synth %s",card_name);
                if(!synth2_name[0])
                  sprintf(synth2_name,"kX Synth2 %s",card_name);
                if(!ctrl_name[0])
                  sprintf(ctrl_name,"kX Control %s",card_name);

        ret=init_winmm();
        if(!ignore_winmm)
        {
         if(ret)
         {
          debug("iKX init() error initializing WinMM subsystem [%x]\n",GetLastError());
          strcpy(error_name,"error initializing WinMM subsystem");
         }
        }
        else
        {
         debug("iKX init(): ignore_winmm=1; btw, result was: %d [mixer_num=%d %d %d %d]\n",ret,mixer_handler[0],mixer_handler[1],mixer_handler[2],mixer_handler[3]);
//       if(mixer_handler[0]==-1)
//        mixer_num[0]=0;
        }
    }
    else
    {
     strcpy(error_name,"kX device not found");
    }

    if(ret==0)
    {
        // set emulation
        is_10k2=0;
    if(get_dword(KX_DWORD_IS_10K2,(dword *)&is_10k2))
    {
     debug("iKX init(): incorrect driver version\n");
     strcpy(error_name,"incorrect driver version");
     ret=-100;
    }

        // set device name
        if(get_string(KX_STR_CARD_NAME,device_name))
         ret=-200;
    }

    return ret;
}
예제 #30
0
// ---
static AVP_dword DATA_PARAM get_bytes( Serialize* sz, void* val, AVP_dword size ) {

	AVP_dword loaded = 0;

	if ( !size )
		return 0;

	if ( sz->crc_cluster && sz->crc_not_in_use && sz->crc_len + size >= sz->crc_cluster ) {
		AVP_dword crc_counted;
		AVP_dword crc_saved;
		AVP_dword r_size = sz->crc_cluster - sz->crc_len;
		AVP_dword s_size;
		sz->crc_not_in_use = 0;
		s_size = r_size ? get_bytes( sz, val, r_size ) : 0;
		sz->crc_not_in_use = 1;
		crc_counted = sz->crc;
		sz->crc_len = 0;

		if ( s_size == r_size && get_dword( sz, &crc_saved) == sizeof(sz->crc) && crc_saved == crc_counted ) {
			sz->crc = -1;
			sz->crc_len = 0;
			r_size = size - r_size;
			loaded = s_size + ( r_size ? get_bytes(sz,((AVP_byte*)val)+s_size,r_size) : 0 );
		}
	}
	else {
		if ( sz->bsize > sz->csize + size ) {
			memcpy( val, sz->buffer+sz->csize, size );
			if ( sz->crc_cluster ) {
				sz->crc = CountCRC32WithCRC( size, (AVP_byte*)val, sz->crc );
				sz->crc_len += size;
			}
			sz->csize += size;
			sz->tsize += size;
			loaded = size;
		}
		else {
			while( size ) {
				AVP_dword rest = sz->bsize - sz->csize;
				if ( rest > size )
					rest = size;
				if ( rest ) {
					memcpy( val, sz->buffer+sz->csize, rest );
					if ( sz->crc_cluster ) {
						sz->crc = CountCRC32WithCRC( rest, (AVP_byte*)val, sz->crc );
						sz->crc_len += rest;
					}
					*((AVP_byte**)&val) += rest;
					size -= rest;
					sz->csize += rest;
					sz->tsize += rest;
					loaded += rest;
				}

				if ( sz->csize == sz->bsize ) {
					if ( sz->buff_loaded && sz->bsize	== 0 )
						return 0;
					sz->buff_loaded = 1;
					sz->bsize = 0;
					sz->csize = 0;
					if ( sz->proc ) {
						if ( !sz->proc(sz->buffer,sz->rsize,&sz->bsize,sz->data) ) 
							return 0;
					}
				}
			}
		}
	}
	return loaded;
}