Home | History | Annotate | Download | only in driver
      1 /*
      2  * Copyright (C) 2006 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 /** \file
     18   This file consists of implementation of class AndroidUsbFileObject that
     19   encapsulates a common extension for all KMDF file object types.
     20 */
     21 #pragma data_seg()
     22 #pragma code_seg()
     23 
     24 #include "precomp.h"
     25 #include "android_usb_file_object.h"
     26 
     27 #pragma data_seg()
     28 #pragma code_seg("PAGE")
     29 
     30 AndroidUsbFileObject::AndroidUsbFileObject(AndroidUsbFileObjectType fo_type,
     31                                            AndroidUsbDeviceObject* dev_obj,
     32                                            WDFFILEOBJECT wdf_fo)
     33     : AndroidUsbWdfObject(AndroidUsbWdfObjectTypeFile),
     34       file_type_(fo_type),
     35       device_object_(dev_obj) {
     36   ASSERT_IRQL_PASSIVE();
     37   ASSERT(NULL != dev_obj);
     38   ASSERT(fo_type < AndroidUsbFileObjectTypeMax);
     39   ASSERT(NULL != wdf_fo);
     40   set_wdf_object(wdf_fo);
     41 }
     42 
     43 #pragma code_seg()
     44 
     45 AndroidUsbFileObject::~AndroidUsbFileObject() {
     46   ASSERT_IRQL_LOW_OR_DISPATCH();
     47 }
     48 
     49 #pragma code_seg("PAGE")
     50 
     51 NTSTATUS AndroidUsbFileObject::Initialize() {
     52   ASSERT_IRQL_LOW();
     53   ASSERT(NULL != wdf_file());
     54   if (NULL == wdf_file())
     55     return STATUS_INTERNAL_ERROR;
     56 
     57   // Register context for this file object
     58   return InitializeContext();
     59 }
     60 
     61 #pragma code_seg()
     62 
     63 void AndroidUsbFileObject::OnEvtIoRead(WDFREQUEST request,
     64                                        size_t length) {
     65   ASSERT_IRQL_LOW_OR_DISPATCH();
     66   ASSERT(WdfRequestGetFileObject(request) == wdf_file());
     67   // Complete zero reads with success
     68   if (0 == length) {
     69     WdfRequestCompleteWithInformation(request, STATUS_SUCCESS, 0);
     70     return;
     71   }
     72 
     73   WdfRequestComplete(request, STATUS_INVALID_DEVICE_REQUEST);
     74 }
     75 
     76 void AndroidUsbFileObject::OnEvtIoWrite(WDFREQUEST request,
     77                                         size_t length) {
     78   ASSERT_IRQL_LOW_OR_DISPATCH();
     79   ASSERT(WdfRequestGetFileObject(request) == wdf_file());
     80   // Complete zero writes with success
     81   if (0 == length) {
     82     WdfRequestCompleteWithInformation(request, STATUS_SUCCESS, 0);
     83     return;
     84   }
     85 
     86   WdfRequestComplete(request, STATUS_INVALID_DEVICE_REQUEST);
     87 }
     88 
     89 void AndroidUsbFileObject::OnEvtIoDeviceControl(WDFREQUEST request,
     90                                                 size_t output_buf_len,
     91                                                 size_t input_buf_len,
     92                                                 ULONG ioctl_code) {
     93   ASSERT_IRQL_LOW_OR_DISPATCH();
     94   ASSERT(WdfRequestGetFileObject(request) == wdf_file());
     95 
     96   WdfRequestComplete(request, STATUS_INVALID_DEVICE_REQUEST);
     97 }
     98 
     99 #pragma data_seg()
    100 #pragma code_seg()
    101