Ejemplo n.º 1
0
/**
 * Function name:  send_csw_callback
 * Description:    Completion callback, which is called at the completion of a
 *                 command status wrapper (CSW) request (send_csw).
 * Parameters: 
 *     @request: (IN) Core request
 *
 * Return value: None
 * Scope:        Global
 **/
void send_csw_callback(request_t *request)
{
    fd_storage_t *fd = (fd_storage_t *)request->context;
    request_status_t status = request->status;

    DBG_V(DSLAVE_MS_USB, ("MASS: CSW sent %d out of %d.\n",
        request->bytes_transferred, request->transfer_size));

    /* Request is ready for next transfer */
    request->status = REQUEST_READY;

    if (status != REQUEST_COMPLETED ||
        request->bytes_transferred != request->transfer_size)
    {
        DBG_W(DSLAVE_MS_USB, ("MASS: Error sending CSW. Stalling IN.\n"));
        if (status != REQUEST_CANCELLED)
            core_abort_pipe(fd->core_ctx, fd->in_pipe);
        core_stall_pipe(fd->core_ctx, fd->in_pipe, 1);
    }
    else
    {
        jresult_t rc;

        /* Get next Command (CBW) */
        DBG_V(DSLAVE_MS_USB, ("MASS: Waiting for next CBW.\n"));
        clear_cmd_in_progress(fd);
        rc = post_read(fd, fd->cmd_request, USB_BULK_CB_WRAP_LEN, 
            cbw_read_complete, fd);
        if (rc)
        {
            DBG_E(DSLAVE_MS_USB, ("Failed to post next CBW (%d)\n", rc));
        }
    }
}
Ejemplo n.º 2
0
/**
 * Function name:  enable
 * Description:    Enables the mass storage function driver.
 * Parameters: 
 *     @context: (IN) FD context
 *
 * Return value: 0 on success, otherwise an error code
 * Scope:        Local
 **/
static jresult_t enable(context_t context)
{
    jresult_t rc = 0;
    jint_t i;
    fd_storage_t *fd = (fd_storage_t *)context;

    if (fd->state == STATE_ENABLED)
    {
        DBG_W(DSLAVE_MS_USB, ("enable: Trying to enable already enabled FD\n"));
        goto Exit;
    }

    for (i = 0; i < SCSI_TRANSFER_BUFFERS; i++)
        ALLOC_MSFD_REQUEST(i);

    /* Get the pipe numbers that the Core assigned to our descriptors */
    DBG_I(DSLAVE_MS_USB, ("FD: Pipe %p is %d.\n",
        &fd->fd_desc->interfaces[0].alt_ifs[0].pipes[0],
        fd->fd_desc->interfaces[0].alt_ifs[0].pipes[0].address));

    fd->out_pipe = &fd->fd_desc->interfaces[0].alt_ifs[0].pipes[0];
    fd->in_pipe  = &fd->fd_desc->interfaces[0].alt_ifs[0].pipes[1];

    rc = scsi_enable(fd->scsi_device);
    if (rc)
        goto Exit;

    rc = post_read(fd, fd->cmd_request, USB_BULK_CB_WRAP_LEN,
        cbw_read_complete, fd);
    if (rc)
    /* HSU addition: CR 159898 */
    {
        DBG_E(DSLAVE_MS_USB, ("Failed to post CBW on enable (%d)\n", rc));
        goto Exit;
    }
    /******* End HSU addition **************************/

    fd->state = STATE_ENABLED;

Exit:
    if (rc)
    {
        for (i = 0; i < SCSI_TRANSFER_BUFFERS; i++)
            FREE_MSFD_REQUEST(i);
    }

    return rc;
}
Ejemplo n.º 3
0
void network_client::handle_handshake(const boost::system::error_code& error) {
    if (error) {
        last_error_ = error;
        connected_ = false;
        return;
    }
    
    boost::asio::ip::tcp::no_delay no_delay(true);
    boost::asio::socket_base::non_blocking_io non_blocking_io(true);
    ssl_socket_->lowest_layer().io_control(non_blocking_io);
    ssl_socket_->lowest_layer().set_option(no_delay);
    
    connected_ = true;
    
    post_read();
}
Ejemplo n.º 4
0
void network_client::handle_read(const boost::system::error_code& error, size_t bytes_transferred) {
    if (error) {
        last_error_ = error;
        printf("%s", error.message().c_str());
        close();
        return;
    }
    
    if (bytes_transferred == 0) {
        last_error_ = boost::system::errc::make_error_code(boost::system::errc::connection_refused);
        close();
        return;
    }
    
    protocol_->handle_read(receive_buffer_.c_array(), bytes_transferred);
    
    
    post_read();
}
Ejemplo n.º 5
0
static void post_syscall(void *drcontext, int sysnum)
{
	switch (sysnum) {
	case SYS_open:
		post_open(drcontext);
		break;
	case SYS_close:
		post_close(drcontext);
		break;
	case SYS_read:
		post_read(drcontext);
		break;
	case SYS_write:
		post_write(drcontext);
		break;
	case SYS_pwrite64:
		post_pwrite64(drcontext);
		break;
	}
}
Ejemplo n.º 6
0
/**
  Works like the main function of the program, it calls almost all other functions
*/
void run()
{
    char **files = get_files_list();

    read_matrix_from_file(files[1], 1);
    if (error_flag == 1)
        return;

    read_matrix_from_file(files[2], 2);
    if (error_flag == 1)
        return;

    post_read();
    if (error_flag == 1)
        return;

    calculate_without_threads();
    calculate_element_by_element();
    calculate_row_by_row();
    write_matrix_to_file(files[3]);
    print_statistics();
}
Ejemplo n.º 7
0
void
handle_read(struct net_service* service, int ret, int err, struct read_session* rsession, size_t bytes)
{
    struct net_session* session;
    unsigned short index;
    unsigned int events;

    if(!rsession)
    {
        return;
    }

    if(rsession->id == 0)
    {
        release_read_session(rsession);
        return;
    }

    index = ffid_index(service->socket_ids, rsession->id);
    net_lock(&service->session_lock[index]);
    session = service->sessions[index];
    if(!session || session->id != rsession->id)
    {
        release_read_session(rsession);
        net_unlock(&service->session_lock[index]);
        return;
    }
    rsession->op = OP_NET_NONE;

    events = Eve_Read;
    if((!ret && err) || post_read(service, session) )
    {
        events |= Eve_Error;
        print_error();
    }
    push_queue(service, session, events);
    net_unlock(&service->session_lock[index]);
}
Ejemplo n.º 8
0
void network_client::handle_connect(const boost::system::error_code& error) {
    if (error) {
        last_error_ = error;
        connected_ = false;
        close();
        return;
    }
    
   
    if (use_ssl_) {
        ssl_socket_->async_handshake(boost::asio::ssl::stream_base::client,
                                     boost::bind(&network_client::handle_handshake, this, boost::asio::placeholders::error));
    } else {
        boost::asio::ip::tcp::no_delay no_delay(true);
        boost::asio::socket_base::non_blocking_io non_blocking_io(true);
        ssl_socket_->lowest_layer().io_control(non_blocking_io);
        ssl_socket_->lowest_layer().set_option(no_delay);
        
        connected_ = true;
        
        post_read();
    }
}
Ejemplo n.º 9
0
int main()
{
    char *some_memory[10]; /* an arrray of memory pointers */
    int exit_code = EXIT_FAILURE; /* set up exit code for failure */
    int i, j;

/* Call to mtrace routines in glibc library */
#ifdef MTRACE
    mtrace();  /* Turn on mtrace function */
#endif
    lmm_init();

    printf("Start of general malloc testing\n\n");

    printf("Start allocating 10 1k pieces of memory\n");
    for (i=0; i<10; i++)
    {
    some_memory[i] = (char *)malloc(ONE_K);
    printf ("Allocated a piece at 0x%x\n", (int)some_memory[i]);
    }
    printf("We have allocated some memory\n");
    printf("Now lets free part some memory\n");

    for (j=0; j<5; j++)
    {
    if (some_memory[j*2] != NULL) 
        {
        free(some_memory[j*2]);

        free(some_memory[j*2]);

        printf ("Freed a piece at 0x%x\n", (int)some_memory[j*2]);
        exit_code = EXIT_SUCCESS ;
        }
    }

    printf("\n\nNow let us check other functions\n\n");

#ifndef DMALLOC

    printf("Read after the end of the allocated string\n");

    post_read(); 

#endif

    printf("\nWrite after the end of the allocated string\n");

    post_write(); 

    printf ("\nRead before the allocated string\n");

    read_before(); 

#ifndef MTRACE

    printf("\nWrite before allocated area\n");

    write_before(); 

#endif

	lmm_dump_info();

    printf("\nMissed memory free of allocated string\n");

    miss_free();

#if !defined(MTRACE) && !defined(MEMWATCH) && !defined(DMALLOC)
    printf("\nUsing uninitialized memory\n");

    uninit_mem();

#endif

#ifdef MTRACE
    muntrace();  /* Turn off mtrace function */
#endif
	while(1);

    exit(exit_code);
}
Ejemplo n.º 10
0
/** 
 * Function name:  control_msg
 * Description:    Handles a mass storage class-specific endpoint 0 request.
 * Parameters: 
 *     @context: (IN) FD context
 *     @buffer:  (IN) Buffer containing the control request
 *
 * Return value: 0 on success, otherwise an error code
 * Scope:        Local
 **/
static jresult_t control_msg(void *context, void *buffer)
{
    jresult_t rc = JENOTSUP;
    fd_storage_t *fd = (fd_storage_t *)context;
    struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)buffer;

    switch (req->bRequest)
    {
    case USB_BULK_RESET_REQUEST:
        DBG_I(DSLAVE_MS_USB, ("MASS: Bulk Reset Request.\n"));

        if (req->wValue || req->wLength != 0) /* HSU fix */
        {
            DBG_E(DSLAVE_MS_USB, ("MASS: Invalid MS_RESET request.\n"));
            break;
        }

        clear_cmd_in_progress(fd);
        core_abort_pipe(fd->core_ctx, fd->in_pipe);
        core_abort_pipe(fd->core_ctx, fd->out_pipe);

        /* Clear Stalls from pipes */
        core_stall_pipe(fd->core_ctx, fd->in_pipe, 0);
        core_stall_pipe(fd->core_ctx, fd->out_pipe, 0);

        /* Even if it fails, we still Reset since the host wants it */
        rc = send_ep0_reply(fd, 0);

        rc = post_read(fd, fd->cmd_request, USB_BULK_CB_WRAP_LEN, 
            cbw_read_complete, fd);
        /* HSU addition: CR 159898 */
        if (rc)
        {
            DBG_E(DSLAVE_MS_USB, ("Failed to post CBW on RESET_REQUEST (%d)\n", rc));
        }
        /******* End HSU addition **************************/
        break;

    case USB_BULK_GET_MAX_LUN_REQUEST:
        DBG_I(DSLAVE_MS_USB, ("MASS: Get max LUNs request.\n"));

        if (req->wValue || req->wLength != 1) /* HSU fix */
        {
            DBG_E(DSLAVE_MS_USB, ("MASS: Invalid MS_GET_MAX_LUN request.\n"));
            break;
        }
        /* HSU addition: CR 159898 */
        /* Clear Stalls from pipes */
        core_abort_pipe(fd->core_ctx, fd->in_pipe);
        core_stall_pipe(fd->core_ctx, fd->in_pipe, 0);

        core_abort_pipe(fd->core_ctx, fd->out_pipe);
        core_stall_pipe(fd->core_ctx, fd->out_pipe, 0);

        rc = post_read(fd, fd->cmd_request, USB_BULK_CB_WRAP_LEN, 
            cbw_read_complete, fd);
        if (rc)
        {
            DBG_E(DSLAVE_MS_USB, ("Failed to post CBW on GET_MAX_LUN_REQUEST (%d)\n", rc));
        }
        /******* End HSU addition **************************/

        ((juint8_t *)(fd->ep0_request->buffer.vaddr))[0] = fd->total_luns - 1;
        rc = send_ep0_reply(fd, 1);
        break;
        
    default:
        DBG_W(DSLAVE_MS_USB, ("MASS: Unknown EP0 request.\n"));
    }

    return rc;
}