rymanluk commented on a change in pull request #440: LL: Support for Periodic Sync URL: https://github.com/apache/mynewt-nimble/pull/440#discussion_r284369963
########## File path: nimble/controller/src/ble_ll_sync.c ########## @@ -0,0 +1,1449 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <stdbool.h> +#include <stdint.h> +#include <assert.h> + +#include "syscfg/syscfg.h" + +#include "controller/ble_ll.h" +#include "controller/ble_ll_hci.h" +#include "controller/ble_ll_sync.h" +#include "controller/ble_ll_utils.h" +#include "controller/ble_ll_sched.h" +#include "controller/ble_ll_whitelist.h" +#include "controller/ble_ll_scan.h" + +#include "nimble/ble.h" +#include "nimble/hci_common.h" +#include "nimble/ble_hci_trans.h" + +#include "stats/stats.h" + +#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PERIODIC_ADV) + +#define BLE_LL_SYNC_CNT MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_SYNC_CNT) + +#define BLE_LL_SYNC_SM_FLAG_ON_LIST 0x01 +#define BLE_LL_SYNC_SM_FLAG_PENDING 0x02 +#define BLE_LL_SYNC_SM_FLAG_ESTABLISHING 0x04 +#define BLE_LL_SYNC_SM_FLAG_ESTABLISHED 0x08 +#define BLE_LL_SYNC_SM_FLAG_SET_ANCHOR 0x10 +#define BLE_LL_SYNC_SM_FLAG_OFFSET_300 0x20 + +#define BLE_LL_SYNC_CHMAP_LEN 5 +#define BLE_LL_SYNC_ITVL_USECS 1250 + +struct ble_ll_sync_sm { + uint8_t flags; + + uint8_t adv_sid; + uint8_t adv_addr[BLE_DEV_ADDR_LEN]; + uint8_t adv_addr_type; + + uint8_t sca; + uint8_t chanmap[BLE_LL_SYNC_CHMAP_LEN]; + uint8_t num_used_chans; + + uint8_t chan_index; + uint8_t chan_chain; + + uint8_t phy_mode; + + uint16_t skip; + uint32_t timeout; + + uint16_t itvl; + uint8_t itvl_usecs; + uint32_t itvl_ticks; + + uint32_t crcinit; /* only 3 bytes are used */ + uint16_t event_cntr; + uint16_t channel_id; + uint32_t access_addr; + + uint32_t last_anchor_point; + uint32_t anchor_point; + uint8_t anchor_point_usecs; + uint32_t window_widening; + + struct ble_ll_sched_item sch; + + uint8_t *next_report; + + struct ble_npl_event sync_ev_end; +}; + +static uint16_t sync_skip; +static uint16_t sync_timeout_us; +static bool sync_pending; + +static struct ble_ll_sync_sm ble_ll_sync_sm[BLE_LL_SYNC_CNT]; +static struct ble_ll_sync_sm *ble_ll_sync_sm_establishing; +static struct ble_ll_sync_sm *ble_ll_sync_sm_current; +static uint8_t *g_ble_ll_sync_comp_ev; + +static uint8_t +ble_ll_sync_get_handle(struct ble_ll_sync_sm *sm) +{ + /* handle number is offset in global array */ + return sm - ble_ll_sync_sm; +} + +static void +ble_ll_sync_sm_clear(struct ble_ll_sync_sm *sm) +{ + if (sm->flags & (BLE_LL_SYNC_SM_FLAG_ESTABLISHING | + BLE_LL_SYNC_SM_FLAG_ESTABLISHED)) { + ble_ll_sched_rmv_elem(&sm->sch); + ble_npl_eventq_remove(&g_ble_ll_data.ll_evq, &sm->sync_ev_end); + } + + if (sm->next_report) { + ble_hci_trans_buf_free(sm->next_report); + } + + memset(sm, 0, sizeof(*sm)); +} + +static uint8_t +phy_mode_to_hci(int8_t phy_mode) Review comment: missing prefix ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services