Home | History | Annotate | Download | only in health

Lines Matching defs:mcl

100 static int send_sync_cmd(struct mcap_mcl *mcl, const void *buf, uint32_t size)
104 if (mcl->cc == NULL)
107 sock = g_io_channel_unix_get_fd(mcl->cc);
111 static int send_unsupported_cap_req(struct mcap_mcl *mcl)
120 sent = send_sync_cmd(mcl, cmd, sizeof(*cmd));
126 static int send_unsupported_set_req(struct mcap_mcl *mcl)
135 sent = send_sync_cmd(mcl, cmd, sizeof(*cmd));
151 void mcap_sync_init(struct mcap_mcl *mcl)
153 if (!mcl->mi->csp_enabled) {
154 mcl->csp = NULL;
158 mcl->csp = g_new0(struct mcap_csp, 1);
160 mcl->csp->rem_req_acc = 10000; /* safe divisor */
161 mcl->csp->set_data = NULL;
162 mcl->csp->csp_priv_data = NULL;
164 reset_tmstamp(mcl->csp, NULL, 0);
167 void mcap_sync_stop(struct mcap_mcl *mcl)
169 if (!mcl->csp)
172 if (mcl->csp->ind_timer)
173 g_source_remove(mcl->csp->ind_timer);
175 if (mcl->csp->set_timer)
176 g_source_remove(mcl->csp->set_timer);
178 if (mcl->csp->set_data)
179 g_free(mcl->csp->set_data);
181 if (mcl->csp->csp_priv_data)
182 g_free(mcl->csp->csp_priv_data);
184 mcl->csp->ind_timer = 0;
185 mcl->csp->set_timer = 0;
186 mcl->csp->set_data = NULL;
187 mcl->csp->csp_priv_data = NULL;
189 g_free(mcl->csp);
190 mcl->csp = NULL;
231 static gboolean read_btclock(struct mcap_mcl *mcl, uint32_t *btclock,
237 adapter = manager_find_adapter(&mcl->mi->src);
242 if (btd_adapter_read_clock(adapter, &mcl->addr, which, 1000,
249 static gboolean read_btclock_retry(struct mcap_mcl *mcl, uint32_t *btclock,
255 if (read_btclock(mcl, btclock, btaccuracy))
263 static gboolean get_btrole(struct mcap_mcl *mcl)
268 if (mcl->cc == NULL)
271 sock = g_io_channel_unix_get_fd(mcl->cc);
280 uint64_t mcap_get_timestamp(struct mcap_mcl *mcl,
286 if (!mcl->csp)
294 tmstamp = time_us(&now) - time_us(&mcl->csp->base_time)
295 + mcl->csp->base_tmstamp;
300 uint32_t mcap_get_btclock(struct mcap_mcl *mcl)
305 if (!mcl->csp)
308 if (!read_btclock_retry(mcl, &btclock, &accuracy))
314 static gboolean initialize_caps(struct mcap_mcl *mcl)
334 read_btclock_retry(mcl, &btclock, &btaccuracy);
342 if (!read_btclock(mcl, &btclock, &btaccuracy)) {
382 static struct csp_caps *caps(struct mcap_mcl *mcl)
385 if (!initialize_caps(mcl)) {
393 static int send_sync_cap_rsp(struct mcap_mcl *mcl, uint8_t rspcode,
410 sent = send_sync_cmd(mcl, rsp, sizeof(*rsp));
416 static void proc_sync_cap_req(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
425 send_sync_cap_rsp(mcl, MCAP_INVALID_PARAM_VALUE,
430 if (!caps(mcl)) {
431 send_sync_cap_rsp(mcl, MCAP_RESOURCE_UNAVAILABLE,
438 our_accuracy = caps(mcl)->ts_acc;
441 send_sync_cap_rsp(mcl, MCAP_RESOURCE_UNAVAILABLE,
446 if (!read_btclock_retry(mcl, &btclock, &btres)) {
447 send_sync_cap_rsp(mcl, MCAP_RESOURCE_UNAVAILABLE,
452 mcl->csp->remote_caps = 1;
453 mcl->csp->rem_req_acc = required_accuracy;
455 send_sync_cap_rsp(mcl, MCAP_SUCCESS, btres,
456 caps(mcl)->syncleadtime_ms,
457 caps(mcl)->ts_res, our_accuracy);
460 static int send_sync_set_rsp(struct mcap_mcl *mcl, uint8_t rspcode,
475 sent = send_sync_cmd(mcl, rsp, sizeof(*rsp));
481 static gboolean get_all_clocks(struct mcap_mcl *mcl, uint32_t *btclock,
490 if (!caps(mcl))
493 latency = caps(mcl)->preempt_thresh + 1;
495 while (latency > caps(mcl)->preempt_thresh && --retry >= 0) {
499 if (!read_btclock(mcl, btclock, &btres))
510 *timestamp = mcap_get_timestamp(mcl, base_time);
517 struct mcap_mcl *mcl;
527 mcl = user_data;
529 if (!caps(mcl))
532 if (!get_all_clocks(mcl, &btclock, &base_time, &tmstamp))
540 cmd->timestsa = htons(caps(mcl)->latency);
542 sent = send_sync_cmd(mcl, cmd, sizeof(*cmd));
550 struct mcap_mcl *mcl;
567 mcl = user_data;
569 if (!mcl->csp->set_data)
572 data = mcl->csp->set_data;
579 if (!caps(mcl)) {
580 send_sync_set_rsp(mcl, MCAP_UNSPECIFIED_ERROR, 0, 0, 0);
584 if (!get_all_clocks(mcl, &btclock, &base_time, &tmstamp)) {
585 send_sync_set_rsp(mcl, MCAP_UNSPECIFIED_ERROR, 0, 0, 0);
589 if (get_btrole(mcl) != role) {
590 send_sync_set_rsp(mcl, MCAP_INVALID_OPERATION, 0, 0, 0);
608 reset_tmstamp(mcl->csp, &base_time, new_tmstamp);
612 tmstampacc = caps(mcl)->latency + caps(mcl)->ts_acc;
614 if (mcl->csp->ind_timer) {
615 g_source_remove(mcl->csp->ind_timer);
616 mcl->csp->ind_timer = 0;
620 int when = ind_freq + caps(mcl)->syncleadtime_ms;
621 mcl->csp->ind_timer = g_timeout_add(when,
623 mcl);
626 send_sync_set_rsp(mcl, MCAP_SUCCESS, btclock, tmstamp, tmstampacc);
630 sync_send_indication(mcl);
635 static void proc_sync_set_req(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
646 send_sync_set_rsp(mcl, MCAP_INVALID_PARAM_VALUE, 0, 0, 0);
657 send_sync_set_rsp(mcl, MCAP_INVALID_PARAM_VALUE, 0, 0, 0);
662 send_sync_set_rsp(mcl, MCAP_INVALID_PARAM_VALUE, 0, 0, 0);
666 if (!mcl->csp->remote_caps) {
668 send_sync_set_rsp(mcl, MCAP_INVALID_PARAM_VALUE, 0, 0, 0);
672 if (!caps(mcl)) {
673 send_sync_set_rsp(mcl, MCAP_UNSPECIFIED_ERROR, 0, 0, 0);
677 if (!read_btclock_retry(mcl, &cur_btclock, &btres)) {
678 send_sync_set_rsp(mcl, MCAP_UNSPECIFIED_ERROR, 0, 0, 0);
689 send_sync_set_rsp(mcl, MCAP_INVALID_PARAM_VALUE,
699 send_sync_set_rsp(mcl, MCAP_INVALID_PARAM_VALUE,
702 } else if (phase2_delay < caps(mcl)->latency / 1000) {
704 send_sync_set_rsp(mcl, MCAP_INVALID_PARAM_VALUE,
713 ind_freq = (1000 * mcl->csp->rem_req_acc) / caps(mcl)->ts_acc;
715 if (ind_freq < MAX(caps(mcl)->latency * 2 / 1000, 100)) {
717 send_sync_set_rsp(mcl, MCAP_INVALID_PARAM_VALUE,
726 if (mcl->csp->ind_timer) {
728 g_source_remove(mcl->csp->ind_timer);
729 mcl->csp->ind_timer = 0;
732 if (!mcl->csp->set_data)
733 mcl->csp->set_data = g_new0(struct sync_set_data, 1);
735 set_data = (struct sync_set_data *) mcl
741 set_data->role = get_btrole(mcl);
748 when = phase2_delay + caps(mcl)->syncleadtime_ms;
749 mcl->csp->set_timer = g_timeout_add(when,
751 mcl);
753 proc_sync_set_req_phase2(mcl);
757 sync_send_indication(mcl);
760 static void proc_sync_cap_rsp(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
772 if (mcl->csp->csp_req != MCAP_MD_SYNC_CAP_REQ) {
777 if (!mcl->csp->csp_priv_data) {
782 cbdata = mcl->csp->csp_priv_data;
787 mcl->csp->csp_priv_data = NULL;
788 mcl->csp->csp_req = 0;
803 mcl->csp->local_caps = TRUE;
805 cb(mcl, mcap_err, btclockres, synclead, tmstampres, tmstampacc, NULL,
809 static void proc_sync_set_rsp(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
820 if (mcl->csp->csp_req != MCAP_MD_SYNC_SET_REQ) {
825 if (!mcl->csp->csp_priv_data) {
830 cbdata = mcl->csp->csp_priv_data;
835 mcl->csp->csp_priv_data = NULL;
836 mcl->csp->csp_req = 0;
852 cb(mcl, mcap_err, btclock, timestamp, accuracy, NULL, user_data);
855 static void proc_sync_info_ind(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
861 if (!mcl->csp->ind_expected) {
880 if (mcl->mi->mcl_sync_infoind_cb)
881 mcl->mi->mcl_sync_infoind_cb(mcl, &data);
884 void proc_sync_cmd(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
886 if (!mcl->mi->csp_enabled || !mcl->csp) {
889 send_unsupported_cap_req(mcl);
892 send_unsupported_set_req(mcl);
900 proc_sync_cap_req(mcl, cmd, len);
903 proc_sync_cap_rsp(mcl, cmd, len);
906 proc_sync_set_req(mcl, cmd, len);
909 proc_sync_set_rsp(mcl, cmd, len);
912 proc_sync_info_ind(mcl, cmd, len);
917 void mcap_sync_cap_req(struct mcap_mcl *mcl, uint16_t reqacc,
924 if (!mcl->mi->csp_enabled || !mcl->csp) {
932 if (mcl->csp->csp_req) {
940 mcl->csp->csp_req = MCAP_MD_SYNC_CAP_REQ;
949 mcl->csp->csp_priv_data = cbdata;
951 send_sync_cmd(mcl, cmd, sizeof(*cmd));
956 void mcap_sync_set_req(struct mcap_mcl *mcl, uint8_t update, uint32_t btclock,
963 if (!mcl->mi->csp_enabled || !mcl->csp) {
971 if (!mcl->csp->local_caps) {
979 if (mcl->csp->csp_req) {
987 mcl->csp->csp_req = MCAP_MD_SYNC_SET_REQ;
995 mcl->csp->ind_expected = update;
1000 mcl->csp->csp_priv_data = cbdata;
1002 send_sync_cmd(mcl, cmd, sizeof(*cmd));