99bfdd81250e65b7bfa37f5088c4dd0a40cb6f48
[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 "cafragmentation.h"
23 #include "oic_malloc.h"
24 #include "oic_string.h"
25
26 #include <string.h>
27 #include <assert.h>
28
29
30 // Logging tag.
31 static char const TAG[] = "BLE_RECV";
32
33 static CAGattRecvInfo const g_null_info =
34     {
35         .peer = NULL
36     };
37
38 void CAGattRecvInfoInitialize(CAGattRecvInfo * info)
39 {
40     *info = g_null_info;
41 }
42
43 void CAGattRecvInfoDestroy(CAGattRecvInfo * info)
44 {
45     OICFree(info->peer);
46     *info = g_null_info;
47 }
48
49 bool CAGattRecv(CAGattRecvInfo * info,
50                 uint8_t const * data,
51                 uint32_t length)
52 {
53     uint32_t sent_length = 0;
54
55     ca_mutex_lock(info->context->lock);
56
57     bool const success =
58         info->on_packet_received(info->peer,
59                                  data,
60                                  length,
61                                  &sent_length) == CA_STATUS_OK;
62
63     ca_mutex_unlock(info->context->lock);
64
65     return success && length == sent_length;
66 }