Exemple #1
0
void server_answer(http_request_t req, socket_t * clientSocket,db_t * db)
{
    if(!strncmp(req.uri,"/db/editw/",10))
    {
            edit_row(req,clientSocket, db);
    }
    else
    if(!strncmp(req.uri,"/db/edit/",9))
    {
        edit(req,clientSocket, db);
    }
    else
    if(strpbrk(req.uri,"0123456789"))
    {
        if(!strcmp(req.method,"GET"))
        get_row(req,clientSocket, db);
        else
        if(!strcmp(req.method,"DELETE"))
        db_delete(req,db);
    }
    else
    if(!strncmp(req.uri,"/db/paste/",10))
    {
        if(!strcmp(req.method,"GET"))
        post_new_row_get(req,clientSocket);
        else
            if(!strcmp(req.method,"POST"))
            post_new_row_post(req,clientSocket,db);
    }
    else
    if (!strcmp(req.uri, "/db"))
        {
            start_page(clientSocket,db);
        }
    else
        if(!strncmp(req.uri,"/db/",4))
    {
        get_bd(req,clientSocket,db);
    }

}
/**
 * mu3d_hal_prepare_rx_gpd - prepare rx gpd/bd
 * @args - arg1: gpd address, arg2: data buffer address, arg3: data length, arg4: ep number, arg5: with bd or not, arg6: write hwo bit or not,  arg7: write ioc bit or not
 */
TGPD *mu3d_hal_prepare_rx_gpd(TGPD *gpd, dma_addr_t pBuf, DEV_UINT32 data_len,
			      DEV_UINT8 ep_num, DEV_UINT8 _is_bdp, DEV_UINT8 isHWO,
			      DEV_UINT8 ioc, DEV_UINT8 bps, DEV_UINT32 cMaxPacketSize)
{
	DEV_UINT32 offset;
	DEV_INT32 i;
	DEV_INT32 bd_num;
	DEV_UINT32 length;

	TBD *bd_next;
	TBD *bd_head;
	TBD *bd;
	DEV_UINT8 *pBuffer;

	/*If data length is less than the GPD buffer size, just use GPD */
	if (data_len < GPD_BUF_SIZE) {
		_is_bdp = 0;
	}

	os_printk(K_INFO, "%s gpd=%p, epnum=%d, len=%d, _is_bdp=%d, maxp=%d\n", __func__,
		  gpd, ep_num, data_len, _is_bdp, cMaxPacketSize);

	if (!_is_bdp) {
		/*Set actual data point to "DATA Buffer" */
		TGPD_SET_DATA(gpd, pBuf);
		/*Clear "BDP(Buffer Descriptor Present)" flag */
		TGPD_CLR_FORMAT_BDP(gpd);
	} else {
		/*Get the first BD */
		bd_head = (TBD *) get_bd(USB_RX, ep_num);
		os_printk(K_INFO, "bd_head=x%p\n", bd_head);

		bd = bd_head;
		os_memset(bd, 0, sizeof(TBD));

		/*Date length for transfer */
		length = data_len;

		/*Point of data buffer */
		pBuffer = (DEV_UINT8 *) (pBuf);

		/*The size of BD buffer */
		offset = BD_BUF_SIZE;

		/*Count how many BD this transfer need. */
		bd_num = (!(length % offset)) ? (length / offset) : ((length / offset) + 1);

		os_printk(K_INFO, "%s bd_num=%d\n", __func__, bd_num);

		/*Insert data into each BD */
		for (i = 0; i < bd_num; i++) {
			os_printk(K_INFO, "%s bd[%d]=%p\n", __func__, i, bd);
			if (i == (bd_num - 1)) {
				TBD_SET_BUF_LEN(bd, 0);	/*Set "Transferred Data Length" = 0 */

				/*The last one's data buffer lengnth must be precise, or the GPD will never done unless ZLP or short packet. */
				/*"Allow Data Buffer Length" = the rest of data length* */
				length =
				    (!(length % cMaxPacketSize)) ? (length) : ((length /
										cMaxPacketSize) +
									       1) * cMaxPacketSize;
				TBD_SET_DataBUF_LEN(bd, length);

				TBD_SET_DATA(bd, pBuffer);	/*Store the data pointer to "Data Buffer" */

				TBD_SET_FLAGS_EOL(bd);	/*Set "EOL" */
				TBD_SET_NEXT(bd, 0);	/*Set "Next BD pointer" = 0 */
				TBD_SET_CHKSUM(bd, CHECKSUM_LENGTH);	/*Set "BD Checksum" */

				/*Flush the data of BD stuct to device */
				dma_sync_single_for_device(NULL,
							   bd_virt_to_phys(bd, USB_RX, ep_num),
							   sizeof(TBD), DMA_BIDIRECTIONAL);

				break;
			} else {
				TBD_SET_BUF_LEN(bd, 0);	/*Set "Transferred Data Length" = 0 */

				/*"Allow Data Buffer Length" = the MAX BD transfer size */
				TBD_SET_DataBUF_LEN(bd, offset);

				TBD_SET_DATA(bd, pBuffer);	/*Store the data pointer to "Data Buffer" */

				TBD_CLR_FLAGS_EOL(bd);	/*Clear "EOL" */
				/*Get the next BD */
				bd_next = (TBD *) get_bd(USB_RX, ep_num);
				os_memset(bd_next, 0, sizeof(TBD));

				/*Set "Next BD pointer" as the next BD */
				TBD_SET_NEXT(bd, bd_virt_to_phys(bd_next, USB_RX, ep_num));
				TBD_SET_CHKSUM(bd, CHECKSUM_LENGTH);	/*Set BD Checksum */

				/*Flush the data of BD stuct to device */
				dma_sync_single_for_device(NULL,
							   bd_virt_to_phys(bd, USB_RX, ep_num),
							   sizeof(TBD), DMA_BIDIRECTIONAL);

				/*Calculate the left data length */
				length -= offset;

				/*Move to pointer of buffer */
				pBuffer += offset;

				/*Move to next BD */
				bd = bd_next;
			}
		}

		/*Set the BD pointer into "BD Pointer" at GPD */
		TGPD_SET_DATA(gpd, bd_virt_to_phys(bd_head, USB_RX, ep_num));

		/*Set "BDP(Buffer Descriptor Present)" flag */
		TGPD_SET_FORMAT_BDP(gpd);
	}

	os_printk(K_INFO, "%s GPD data_length=%d\n", __func__, data_len);

	/*
	 * Set "Allow Data Buffer Length" =
	 * 0        (If data length > GPD buffer length, use BDs),
	 * data_len (If data length < GPD buffer length, only use GPD)
	 */
	TGPD_SET_DataBUF_LEN(gpd, data_len);
	/* TGPD_SET_DataBUF_LEN(gpd, gpd_buf_size); */

	/*Set "Transferred Data Length" = 0 */
	TGPD_SET_BUF_LEN(gpd, 0);

	/*Default: bps=false */
	if (bps)
		TGPD_SET_FORMAT_BPS(gpd);
	else
		TGPD_CLR_FORMAT_BPS(gpd);

	/*Default: ioc=true */
	if (ioc)
		TGPD_SET_FORMAT_IOC(gpd);
	else
		TGPD_CLR_FORMAT_IOC(gpd);

	/*Get the next GPD */
	Rx_gpd_end[ep_num] = get_gpd(USB_RX, ep_num);
	os_printk(K_INFO, "%s Rx_gpd_end[%d]=%p\n", __func__, ep_num, Tx_gpd_end[ep_num]);

	/*Initialize the new GPD */
	os_memset(Rx_gpd_end[ep_num], 0, sizeof(TGPD));

	/*Clear "HWO(Hardware Own)" flag */
	TGPD_CLR_FLAGS_HWO(Rx_gpd_end[ep_num]);

	/*Set Next GDP pointer to the next GPD */
	TGPD_SET_NEXT(gpd, mu3d_hal_gpd_virt_to_phys(Rx_gpd_end[ep_num], USB_RX, ep_num));

	/*Default: isHWO=true */
	if (isHWO) {
		TGPD_SET_CHKSUM(gpd, CHECKSUM_LENGTH);	/*Set GPD Checksum */
		TGPD_SET_FLAGS_HWO(gpd);	/*Set HWO flag */
	} else {
		TGPD_CLR_FLAGS_HWO(gpd);
		TGPD_SET_CHKSUM_HWO(gpd, CHECKSUM_LENGTH);
	}

	/* os_printk(K_DEBUG,"Rx gpd info { HWO %d, Next_GPD %x ,DataBufferLength %d, DataBuffer %x, Recived Len %d, Endpoint %d, TGL %d, ZLP %d}\n", */
	/* (DEV_UINT32)TGPD_GET_FLAG(gpd), (DEV_UINT32)TGPD_GET_NEXT(gpd), */
	/* (DEV_UINT32)TGPD_GET_DataBUF_LEN(gpd), (DEV_UINT32)TGPD_GET_DATA(gpd), */
	/* (DEV_UINT32)TGPD_GET_BUF_LEN(gpd), (DEV_UINT32)TGPD_GET_EPaddr(gpd), */
	/* (DEV_UINT32)TGPD_GET_TGL(gpd), (DEV_UINT32)TGPD_GET_ZLP(gpd)); */

	/*Flush the data of GPD stuct to device */
	dma_sync_single_for_device(NULL, mu3d_hal_gpd_virt_to_phys(gpd, USB_RX, ep_num),
				   sizeof(TGPD), DMA_BIDIRECTIONAL);

	return gpd;
}
/**
 * mu3d_hal_prepare_tx_gpd - prepare tx gpd/bd
 * @args - arg1: gpd address, arg2: data buffer address, arg3: data length, arg4: ep number, arg5: with bd or not, arg6: write hwo bit or not,  arg7: write ioc bit or not
 */
TGPD *mu3d_hal_prepare_tx_gpd(TGPD *gpd, dma_addr_t pBuf, DEV_UINT32 data_len,
			      DEV_UINT8 ep_num, DEV_UINT8 _is_bdp, DEV_UINT8 isHWO,
			      DEV_UINT8 ioc, DEV_UINT8 bps, DEV_UINT8 zlp)
{
	DEV_UINT32 offset;
	DEV_INT32 i;
	DEV_INT32 bd_num;
	DEV_UINT32 length;

	TBD *bd_next;
	TBD *bd_head;
	TBD *bd;
	DEV_UINT8 *pBuffer;

	/*If data length is less than the GPD buffer size, just use GPD */
	/* if (data_len <= GPD_BUF_SIZE) { */
	/* _is_bdp = 0; */
	/* } */

	os_printk(K_INFO, "%s gpd=%p, epnum=%d, len=%d, _is_bdp=%d\n", __func__,
		  gpd, ep_num, data_len, _is_bdp);

	if (!_is_bdp) {
		/*Set actual data point to "DATA Buffer" */
		TGPD_SET_DATA(gpd, pBuf);
		/*Clear "BDP(Buffer Descriptor Present)" flag */
		TGPD_CLR_FORMAT_BDP(gpd);
	} else {
		/*Get the first BD */
		bd_head = (TBD *) get_bd(USB_TX, ep_num);
		os_printk(K_INFO, "bd_head=x%p\n", bd_head);

		bd = bd_head;
		os_memset(bd, 0, sizeof(TBD));

		/*Date length for transfer */
		length = data_len;

		/*Point of data buffer */
		pBuffer = (DEV_UINT8 *) (pBuf);

		/*The size of BD buffer */
		offset = BD_BUF_SIZE;

		/*Count how many BD this transfer need. */
		bd_num = (!(length % offset)) ? (length / offset) : ((length / offset) + 1);

		os_printk(K_INFO, "bd_num=%d\n", bd_num);

		/*If the size of BD buffer is bigger than the length of actual transfer, use the actual length */
		if (offset > length)
			offset = length;

		/*Insert data into each BD */
		for (i = 0; i < bd_num; i++) {
			os_printk(K_INFO, "bd[%d]=%p\n", i, bd);
			if (i == (bd_num - 1)) {	/*The last BD */
				TBD_SET_EXT_LEN(bd, 0);	/*"BD Extension Length" = 0. Does not use BD EXT!! */
				TBD_SET_BUF_LEN(bd, length);	/*"Data Buffer Length" = the rest of data length */
				TBD_SET_DATA(bd, pBuffer);	/*Store the data pointer to "Data Buffer" */

				TBD_SET_FLAGS_EOL(bd);	/*Set "EOL" */
				TBD_SET_NEXT(bd, 0);	/*Set "Next BD pointer" = 0 */
				TBD_SET_CHKSUM(bd, CHECKSUM_LENGTH);	/*Set "BD Checksum" */

				/*Flush the data of BD stuct to device */
				dma_sync_single_for_device(NULL,
							   bd_virt_to_phys(bd, USB_RX, ep_num),
							   sizeof(TBD), DMA_BIDIRECTIONAL);

				/*There is no data left to be transfered by GPD */
				/* data_len=length; */
				data_len = 0;

				/*There is no data left to insert BD */
				length = 0;
			} else {
				TBD_SET_EXT_LEN(bd, 0);	/*"BD Extension length" = 0. Does not use BD EXT!! */
				TBD_SET_BUF_LEN(bd, offset);	/*"Data Buffer Length" = the MAX BD transfer size */
				TBD_SET_DATA(bd, pBuffer);	/*Store the data pointer to "Data Buffer" */

				TBD_CLR_FLAGS_EOL(bd);	/*Clear "EOL" */
				/*Get the next BD */
				bd_next = (TBD *) get_bd(USB_TX, ep_num);
				os_memset(bd_next, 0, sizeof(TBD));

				/*Set "Next BD pointer" as the next BD */
				TBD_SET_NEXT(bd, bd_virt_to_phys(bd_next, USB_TX, ep_num));
				TBD_SET_CHKSUM(bd, CHECKSUM_LENGTH);	/*Set BD Checksum */

				/*Flush the data of BD stuct to device */
				dma_sync_single_for_device(NULL,
							   bd_virt_to_phys(bd, USB_RX, ep_num),
							   sizeof(TBD), DMA_BIDIRECTIONAL);

				/*Calculate the left data length */
				length -= offset;

				/*Move to pointer of buffer */
				pBuffer += offset;

				/*Move to next BD */
				bd = bd_next;
			}
		}

		/*Set the BD pointer into "BD Pointer" at GPD */
		TGPD_SET_DATA(gpd, bd_virt_to_phys(bd_head, USB_TX, ep_num));

		/*Set "BDP(Buffer Descriptor Present)" flag */
		TGPD_SET_FORMAT_BDP(gpd);
	}

	os_printk(K_INFO, "%s GPD data_length=%d\n", __func__, data_len);

	/*
	 * "Data Buffer Length" =
	 * 0        (If data length > GPD buffer length, use BDs),
	 * data_len (If data length < GPD buffer length, only use GPD)
	 */
	TGPD_SET_BUF_LEN(gpd, data_len);

	/*"GPD extension length" = 0. Does not use GPD EXT!! */
	TGPD_SET_EXT_LEN(gpd, 0);

	/*Default: zlp=false, except type=ISOC */
	if (zlp)
		TGPD_SET_FORMAT_ZLP(gpd);
	else
		TGPD_CLR_FORMAT_ZLP(gpd);

	/*Default: bps=false */
	if (bps)
		TGPD_SET_FORMAT_BPS(gpd);
	else
		TGPD_CLR_FORMAT_BPS(gpd);

	/*Default: ioc=true */
	if (ioc)
		TGPD_SET_FORMAT_IOC(gpd);
	else
		TGPD_CLR_FORMAT_IOC(gpd);

	/*Get the next GPD */
	Tx_gpd_end[ep_num] = get_gpd(USB_TX, ep_num);
	os_printk(K_INFO, "Tx_gpd_end[%d]=%p\n", ep_num, Tx_gpd_end[ep_num]);

	/*Initialize the new GPD */
	os_memset(Tx_gpd_end[ep_num], 0, sizeof(TGPD));

	/*Clear "HWO(Hardware Own)" flag */
	TGPD_CLR_FLAGS_HWO(Tx_gpd_end[ep_num]);

	/*Set "Next GDP pointer" as the next GPD */
	TGPD_SET_NEXT(gpd, mu3d_hal_gpd_virt_to_phys(Tx_gpd_end[ep_num], USB_TX, ep_num));

	/*Default: isHWO=true */
	if (isHWO) {
		TGPD_SET_CHKSUM(gpd, CHECKSUM_LENGTH);	/*Set GPD Checksum */
		TGPD_SET_FLAGS_HWO(gpd);	/*Set HWO flag */
	} else {
		TGPD_CLR_FLAGS_HWO(gpd);
		TGPD_SET_CHKSUM_HWO(gpd, CHECKSUM_LENGTH);
	}

	/*Flush the data of GPD stuct to device */
	dma_sync_single_for_device(NULL, mu3d_hal_gpd_virt_to_phys(gpd, USB_TX, ep_num),
				   sizeof(TGPD), DMA_BIDIRECTIONAL);

#if defined(USB_RISC_CACHE_ENABLED)
	os_flushinvalidateDcache();
#endif

	return gpd;
}