Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mle_service_interface.c Source File

mle_service_interface.c

00001 /*
00002  * Copyright (c) 2015-2017, Arm Limited and affiliates.
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * \file mle_service_interface.c
00020  * \brief Add short description about this file!!!
00021  *
00022  */
00023 
00024 #include "nsconfig.h"
00025 #include <string.h>
00026 #include <ns_types.h>
00027 #include "ns_trace.h"
00028 #include "eventOS_event.h"
00029 #include "eventOS_scheduler.h"
00030 #include "eventOS_event_timer.h"
00031 #include "nsdynmemLIB.h"
00032 #include "ns_list.h"
00033 #include "common_functions.h"
00034 #include "Service_Libs/mle_service/mle_service_interface.h"
00035 
00036 #define TRACE_GROUP "mleS"
00037 
00038 static service_instance_list_t srv_interface_list;
00039 
00040 service_instance_t *mle_service_interface_get(int8_t interface_id)
00041 {
00042     service_instance_t *srv_ptr = mle_service_interface_find(interface_id);
00043 
00044     if (!srv_ptr) {
00045         srv_ptr = ns_dyn_mem_alloc(sizeof(service_instance_t));
00046         if (srv_ptr) {
00047             ns_list_add_to_start(&srv_interface_list, srv_ptr);
00048             srv_ptr->interface_id = interface_id;
00049             srv_ptr->URT = 10; //1second
00050             srv_ptr->MRT = 50; //5 seconds
00051             srv_ptr->MRC = 3; //3 retry
00052             srv_ptr->token_bucket = 0;
00053             srv_ptr->token_bucket_ticks = 0;
00054             srv_ptr->token_bucket_size = 0;
00055             srv_ptr->token_bucket_rate = 0;
00056             srv_ptr->token_bucket_count = 0;
00057             srv_ptr->recv_security_bypass_cb = NULL;
00058         }
00059     }
00060 
00061     return srv_ptr;
00062 }
00063 
00064 
00065 service_instance_t *mle_service_interface_find(int8_t interface_id)
00066 {
00067     ns_list_foreach(service_instance_t, cur_ptr, &srv_interface_list) {
00068         if (cur_ptr->interface_id == interface_id) {
00069             return cur_ptr;
00070         }
00071     }
00072     return NULL;
00073 }
00074 
00075 int mle_service_interface_delete(int8_t interface_id)
00076 {
00077     ns_list_foreach(service_instance_t, cur_ptr, &srv_interface_list) {
00078         if (cur_ptr->interface_id == interface_id) {
00079             ns_list_remove(&srv_interface_list, cur_ptr);
00080             ns_dyn_mem_free(cur_ptr);
00081             return 0;
00082         }
00083     }
00084     return -1;
00085 }
00086 
00087 bool mle_service_interface_list_empty(void)
00088 {
00089     return ns_list_is_empty(&srv_interface_list);
00090 }
00091 
00092 bool mle_service_interface_timer_tick(uint16_t ticks, mle_service_interface_timer_cb *timeout_cb)
00093 {
00094     bool active_timer_needed = false;
00095 
00096     ns_list_foreach(service_instance_t, cur_ptr, &srv_interface_list) {
00097         if (timeout_cb(ticks, cur_ptr)) {
00098             active_timer_needed = true;
00099         }
00100     }
00101 
00102     return (active_timer_needed);
00103 }