1 /* 2 * Copyright (C) 2020 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 #ifndef CHPP_PLATFORM_LINK_H_ 18 #define CHPP_PLATFORM_LINK_H_ 19 20 #include <pthread.h> 21 #include <stdbool.h> 22 #include <stddef.h> 23 24 #include "chpp/mutex.h" 25 #include "chpp/notifier.h" 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 #define CHPP_PLATFORM_LINK_TX_MTU_BYTES 1280 32 #define CHPP_PLATFORM_LINK_RX_MTU_BYTES 1280 33 34 #define CHPP_PLATFORM_TRANSPORT_TIMEOUT_MS 1000 35 36 // Forward declaration 37 struct ChppTransportState; 38 39 struct ChppPlatformLinkParameters { 40 //! Indicates that the link to the remote endpoint has been established. 41 //! This simulates the establishment of the physical link, so 42 //! chppPlatformLinkSend() will fail if this field is set to false. 43 bool linkEstablished; 44 45 //! A pointer to the transport context of the remote endpoint. 46 struct ChppTransportState *remoteTransportContext; 47 48 //! A thread to use when sending data to the remote endpoint asynchronously. 49 pthread_t linkSendThread; 50 51 //! The notifier for linkSendThread. 52 struct ChppNotifier notifier; 53 54 //! The mutex to protect buf/bufLen. 55 struct ChppMutex mutex; 56 57 //! The temporary buffer to use to send data to the remote endpoint. 58 uint8_t buf[CHPP_PLATFORM_LINK_TX_MTU_BYTES]; 59 size_t bufLen; 60 61 //! The string name of the linkSendThread. 62 const char *linkThreadName; 63 64 //! The string name of the CHPP work thread. 65 const char *workThreadName; 66 }; 67 68 #ifdef __cplusplus 69 } 70 #endif 71 72 #endif // CHPP_PLATFORM_LINK_H_ 73