Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / linux / recv.c
1 /******************************************************************
2  *
3  * Copyright 2015 Intel Corporation All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  ******************************************************************/
18
19 #include "recv.h"
20
21 #include "caremotehandler.h"
22 #include "oic_malloc.h"
23 #include "oic_string.h"
24
25 #include <string.h>
26 #include <assert.h>
27
28
29 // Logging tag.
30 static char const TAG[] = "BLE_RECV";
31
32 static CAGattRecvInfo const g_null_info =
33     {
34         .peer = NULL
35     };
36
37 void CAGattRecvInfoInitialize(CAGattRecvInfo * info)
38 {
39     *info = g_null_info;
40 }
41
42 void CAGattRecvInfoDestroy(CAGattRecvInfo * info)
43 {
44     OICFree(info->peer);
45     *info = g_null_info;
46 }
47
48 bool CAGattRecv(CAGattRecvInfo * info,
49                 uint8_t const * data,
50                 uint32_t length)
51 {
52     uint32_t sent_length = 0;
53
54     ca_mutex_lock(info->context->lock);
55
56     bool const success =
57         info->on_packet_received(info->peer,
58                                  data,
59                                  length,
60                                  &sent_length) == CA_STATUS_OK;
61
62     ca_mutex_unlock(info->context->lock);
63
64     return success && length == sent_length;
65 }