示例#1
0
void push_eof(struct buffer_pool *bp)
{
  char* buff = malloc(SEND_BUFFSIZE);
  size_t header_size = sizeof(struct p2p_payload_hdr);
  struct p2p_payload_hdr *hdr = (void*)buff;
  hdr->seq = CPAPP_EOF;
  hdr->psize = 0;
  hdr->fseq = bp->f.fseq;
  printf("puts %d eof\n", bp->f.fseq);
  add_sum(buff, header_size);
  if(dr_sendto(sock_fd, buff, header_size, 0, (struct sockaddr*)&peer_addr, sizeof(struct sockaddr)) < 0) {
    perror("sendto()");
  }
  free(buff);
}
示例#2
0
void push_chunk(struct buffer_pool *bp, unsigned short i)
{
  char* buff = malloc(SEND_BUFFSIZE);
  size_t header_size = sizeof(struct p2p_payload_hdr);
  struct p2p_payload_hdr *hdr = (void*)buff;
  hdr->seq = i;
  hdr->psize = bp->node[i].datalen;
  printf("puts %d 0x%04x, %d, bytes of chunk\n", bp->f.fseq, i, hdr->psize);
  hdr->fseq = bp->f.fseq;
  memcpy(&buff[header_size], bp->node[i].buff, hdr->psize);
  add_sum(buff, hdr->psize + header_size);
  if(dr_sendto(sock_fd, buff, hdr->psize + header_size, 0, (struct sockaddr*)&peer_addr, sizeof(struct sockaddr)) < 0) {
    perror("sendto()");
  }
  free(buff);
}
示例#3
0
void push_fileinfo(struct buffer_pool *bp)
{
  char* buff = malloc(SEND_BUFFSIZE);
  size_t header_size = sizeof(struct p2p_payload_hdr);
  struct p2p_payload_hdr *hdr = (void*)buff;
  hdr->seq = CPAPP_IOF;
  hdr->psize = sizeof(struct fileinfo); //sizeof(bp->f);
  printf("puts %d bytes of fileinfo\n", hdr->psize);
  hdr->fseq = bp->f.fseq;
  memcpy(&buff[header_size], &bp->f, hdr->psize);
  add_sum(buff, hdr->psize + header_size);
  if(dr_sendto(sock_fd, buff, hdr->psize + header_size, 0, (struct sockaddr*)&peer_addr, sizeof(struct sockaddr)) < 0) {
    perror("sendto()");
  }
  free(buff);
}
示例#4
0
/*
*******************************************************************************
*                     __flash_to_part
*
* Description:
*    void
*
* Parameters:
*    void
*
* Return value:
*    void
*
* note:
*    void
*
*******************************************************************************
*/
static void __flash_to_uboot(void)
{
	struct spare_boot_head_t * temp_buf = (struct spare_boot_head_t *)trans_data.base_recv_buffer;
	char  response[68];
	u32 uboot_length = 0;
	u32 align_size = 0;
	u32 old_uboot_length = 0;
	u32 old_total_length = 0;

	if(strcmp((char*)temp_buf->boot_head.magic,"uboot"))
	{
		printf("sunxi fastboot error: there is not uboot file\n");
		sprintf(response, "FAILdownload:there is not uboot file \n");
		__sunxi_fastboot_send_status(response, strlen(response));
		return ;
	}
	printf("ready to download bytes 0x%x\n", trans_data.try_to_recv);
	if(temp_buf->boot_head.uboot_length == 0)
	{
		printf("==== uboot.bin ====\n");
		memcpy((char *)temp_buf , (char *)CONFIG_SYS_TEXT_BASE ,sizeof(struct spare_boot_head_t));
		old_uboot_length = temp_buf->boot_head.uboot_length;
		old_total_length = temp_buf->boot_head.length ;
		debug("old_uboot_length = %x \n",old_uboot_length);
		debug("old_total_length = %x \n",old_total_length);
		//align uboot
		align_size = temp_buf->boot_head.align_size;
		printf("align_size is 0x%x \n",align_size);

		uboot_length = (trans_data.try_to_recv + align_size) & (~(align_size - 1));
		temp_buf->boot_head.uboot_length = uboot_length;
		//copy sys_config from old uboot
		memcpy((char *)temp_buf + uboot_length , (char *)CONFIG_SYS_TEXT_BASE + old_uboot_length,old_total_length - old_uboot_length);
		//make check_sum again
		temp_buf->boot_head.check_sum = STAMP_VALUE;
		temp_buf->boot_head.length     = uboot_length +old_total_length - old_uboot_length;
		temp_buf->boot_head.check_sum = add_sum((char *)temp_buf,temp_buf->boot_head.length);
	}
	printf("uboot checksum is 0x%x \n",temp_buf->boot_head.check_sum);
	printf("download uboot ing ....\n");
	sunxi_sprite_download_uboot((char *)temp_buf,uboot_spare_head.boot_data.storage_type ,1);
	printf("sunxi fastboot: successed in downloading uboot \n");
	sprintf(response, "OKAY");
	__sunxi_fastboot_send_status(response, strlen(response));

	return ;
}
/*
************************************************************************************************************
*
*                                             function
*
*    name          :
*
*    parmeters     :
*
*    return        :
*
*    note          :  返回hash值
*
*
************************************************************************************************************
*/
unsigned int HashString( unsigned char *str, unsigned int dwHashType, unsigned int length )
{
//	unsigned char *key = (unsigned char *)str;
//	int ch;
//
//	while( length > 0 )
//	{
//		ch = *key++;
//		seed1 = cryptTable[(dwHashType << 8) + ch] ^ (seed1 + seed2);
//		seed2 = ch + seed1 + seed2 + (seed2 << 5) + 3;
//		length --;
//	}
//
//	return seed1;
	key += add_sum((void *)str, length);

	return (unsigned int)key;
}
/*
************************************************************************************************************
*
*                                             function
*
*    name          :
*
*    parmeters     :
*
*    return        :
*
*    note          :
*
*
************************************************************************************************************
*/
uint sunxi_sprite_part_rawdata_verify(uint base_start, long long base_bytes)
{
	uint checksum = 0;
	uint unaligned_bytes, last_time_bytes;
	uint rest_sectors;
	uint crt_start;
	char *tmp_buf = NULL;

	tmp_buf = (char *)malloc(VERIFY_ONCE_BYTES);
	if(!tmp_buf)
	{
		printf("sunxi sprite err: unable to malloc memory for verify\n");

		return 0;
	}
	crt_start       = base_start;
	rest_sectors    = (uint)((base_bytes + 511)>>9);
	unaligned_bytes = (uint)base_bytes & 0x1ff;

	debug("read total sectors %d\n", rest_sectors);
	debug("read part start %d\n", crt_start);
    while(rest_sectors >= VERIFY_ONCE_SECTORS)
    {
    	if(sunxi_sprite_read(crt_start, VERIFY_ONCE_SECTORS, tmp_buf) != VERIFY_ONCE_SECTORS)
    	{
    		printf("sunxi sprite: read flash error when verify\n");
			checksum = 0;

    		goto __rawdata_verify_err;
    	}
    	crt_start    += VERIFY_ONCE_SECTORS;
    	rest_sectors -= VERIFY_ONCE_SECTORS;
    	checksum     += add_sum(tmp_buf, VERIFY_ONCE_BYTES);
    	debug("check sum = 0x%x\n", checksum);
    }
    if(rest_sectors)
    {
    	if(sunxi_sprite_read(crt_start, rest_sectors, tmp_buf) != rest_sectors)
    	{
    		printf("sunxi sprite: read flash error when verify\n");
			checksum = 0;

    		goto __rawdata_verify_err;
    	}
    	if(unaligned_bytes)
    	{
    		last_time_bytes = (rest_sectors - 1) * 512 + unaligned_bytes;
    	}
    	else
    	{
    		last_time_bytes = rest_sectors * 512;
    	}
    	checksum += add_sum(tmp_buf, last_time_bytes);
		debug("check sum = 0x%x\n", checksum);
    }

__rawdata_verify_err:
	if(tmp_buf)
	{
		free(tmp_buf);
	}

	return checksum;

}