• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef HDC_USB_H
16 #define HDC_USB_H
17 #include "common.h"
18 
19 namespace Hdc {
20 class HdcUSBBase {
21 public:
22     HdcUSBBase(const bool serverOrDaemonIn, void *ptrMainBase);
23     virtual ~HdcUSBBase();
24     virtual bool ReadyForWorkThread(HSession hSession);
CancelUsbIo(HSession hSession)25     virtual void CancelUsbIo(HSession hSession) {};
26     int SendUSBBlock(HSession hSession, uint8_t *data, const int length);
27 
28 protected:
SendUSBRaw(HSession hSession,uint8_t * data,const int length)29     virtual int SendUSBRaw(HSession hSession, uint8_t *data, const int length)
30     {
31         return 0;
32     }
UsbToHdcProtocol(uv_stream_t * stream,uint8_t * appendData,int dataSize)33     virtual int UsbToHdcProtocol(uv_stream_t *stream, uint8_t *appendData, int dataSize)
34     {
35         return 0;
36     };
37     int SendToHdcStream(HSession hSession, uv_stream_t *stream, uint8_t *appendData, int dataSize);
38     int GetSafeUsbBlockSize(uint16_t wMaxPacketSizeSend);
39     bool IsUsbPacketHeader(uint8_t *ioBuf, int ioBytes);
40 
41     void *clsMainBase;
42     bool modRunning;
43     bool serverOrDaemon;
44     const string USB_PACKET_FLAG = "UB";  // must 2bytes
45 
46 private:
47     static void ReadUSB(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf);
48     vector<uint8_t> BuildPacketHeader(uint32_t sessionId, uint8_t option, uint32_t dataSize);
49     int CheckPacketOption(HSession hSession, uint8_t *appendData, int dataSize);
50     void PreSendUsbSoftReset(HSession hSession, uint32_t sessionIdOld);
51 };
52 }  // namespace Hdc
53 
54 #endif