9cadb89dd2ee42ef3ec41651afbc501b2478b084
[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, char const * data, uint32_t length)
50 {
51     uint32_t sent_length = 0;
52
53     ca_mutex_lock(info->context->lock);
54
55     bool const success =
56         info->on_packet_received(info->peer,
57                                  data,
58                                  length,
59                                  &sent_length) == CA_STATUS_OK;
60
61     ca_mutex_unlock(info->context->lock);
62
63     return success && length == sent_length;
64 }