Lines Matching refs:p_port
71 tPORT* p_port = &rfc_cb.port.port[port_index]; in port_allocate_port() local
72 if (!p_port->in_use) { in port_allocate_port()
74 memset(p_port, 0, sizeof(tPORT)); in port_allocate_port()
75 p_port->in_use = true; in port_allocate_port()
77 p_port->handle = port_index + static_cast<uint8_t>(1); in port_allocate_port()
79 port_set_defaults(p_port); in port_allocate_port()
80 p_port->rfc.port_timer = alarm_new("rfcomm_port.port_timer"); in port_allocate_port()
81 p_port->dlci = dlci; in port_allocate_port()
82 p_port->bd_addr = bd_addr; in port_allocate_port()
87 __func__, port_index, p_port, rfc_cb.rfc.last_port_index, in port_allocate_port()
89 return p_port; in port_allocate_port()
105 void port_set_defaults(tPORT* p_port) { in port_set_defaults() argument
106 p_port->ev_mask = 0; in port_set_defaults()
107 p_port->p_callback = nullptr; in port_set_defaults()
108 p_port->port_ctrl = 0; in port_set_defaults()
109 p_port->error = 0; in port_set_defaults()
110 p_port->line_status = 0; in port_set_defaults()
111 p_port->rx_flag_ev_pending = false; in port_set_defaults()
112 p_port->peer_mtu = RFCOMM_DEFAULT_MTU; in port_set_defaults()
114 p_port->user_port_pars = default_port_pars; in port_set_defaults()
115 p_port->peer_port_pars = default_port_pars; in port_set_defaults()
117 p_port->credit_tx = 0; in port_set_defaults()
118 p_port->credit_rx = 0; in port_set_defaults()
120 memset(&p_port->local_ctrl, 0, sizeof(p_port->local_ctrl)); in port_set_defaults()
121 memset(&p_port->peer_ctrl, 0, sizeof(p_port->peer_ctrl)); in port_set_defaults()
122 memset(&p_port->rx, 0, sizeof(p_port->rx)); in port_set_defaults()
123 memset(&p_port->tx, 0, sizeof(p_port->tx)); in port_set_defaults()
125 p_port->tx.queue = fixed_queue_new(SIZE_MAX); in port_set_defaults()
126 p_port->rx.queue = fixed_queue_new(SIZE_MAX); in port_set_defaults()
140 void port_select_mtu(tPORT* p_port) { in port_select_mtu() argument
144 if (p_port->mtu == 0) { in port_select_mtu()
146 packet_size = btm_get_max_packet_size(p_port->bd_addr); in port_select_mtu()
149 LOG(WARNING) << __func__ << ": bad packet size 0 for" << p_port->bd_addr; in port_select_mtu()
150 p_port->mtu = RFCOMM_DEFAULT_MTU; in port_select_mtu()
166 p_port->mtu = ((L2CAP_MTU_SIZE + L2CAP_PKT_OVERHEAD) / packet_size * in port_select_mtu()
170 __func__, p_port->mtu); in port_select_mtu()
172 p_port->mtu = L2CAP_MTU_SIZE - RFCOMM_DATA_OVERHEAD; in port_select_mtu()
174 p_port->mtu); in port_select_mtu()
178 RFCOMM_TRACE_DEBUG("%s: application selected %d", __func__, p_port->mtu); in port_select_mtu()
180 p_port->credit_rx_max = (PORT_RX_HIGH_WM / p_port->mtu); in port_select_mtu()
181 if (p_port->credit_rx_max > PORT_RX_BUF_HIGH_WM) in port_select_mtu()
182 p_port->credit_rx_max = PORT_RX_BUF_HIGH_WM; in port_select_mtu()
183 p_port->credit_rx_low = (PORT_RX_LOW_WM / p_port->mtu); in port_select_mtu()
184 if (p_port->credit_rx_low > PORT_RX_BUF_LOW_WM) in port_select_mtu()
185 p_port->credit_rx_low = PORT_RX_BUF_LOW_WM; in port_select_mtu()
186 p_port->rx_buf_critical = (PORT_RX_CRITICAL_WM / p_port->mtu); in port_select_mtu()
187 if (p_port->rx_buf_critical > PORT_RX_BUF_CRITICAL_WM) in port_select_mtu()
188 p_port->rx_buf_critical = PORT_RX_BUF_CRITICAL_WM; in port_select_mtu()
191 p_port->credit_rx_max, p_port->credit_rx_low, p_port->rx_buf_critical); in port_select_mtu()
203 void port_release_port(tPORT* p_port) { in port_release_port() argument
205 p_port, p_port->rfc.state, p_port->keep_port_handle); in port_release_port()
209 while ((p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_port->rx.queue)) != in port_release_port()
213 p_port->rx.queue_size = 0; in port_release_port()
215 while ((p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_port->tx.queue)) != in port_release_port()
219 p_port->tx.queue_size = 0; in port_release_port()
222 alarm_cancel(p_port->rfc.port_timer); in port_release_port()
224 p_port->state = PORT_STATE_CLOSED; in port_release_port()
226 if (p_port->rfc.state == RFC_STATE_CLOSED) { in port_release_port()
227 if (p_port->rfc.p_mcb) { in port_release_port()
228 p_port->rfc.p_mcb->port_handles[p_port->dlci] = 0; in port_release_port()
231 rfc_check_mcb_active(p_port->rfc.p_mcb); in port_release_port()
234 rfc_port_timer_stop(p_port); in port_release_port()
237 fixed_queue_free(p_port->tx.queue, nullptr); in port_release_port()
238 p_port->tx.queue = nullptr; in port_release_port()
239 fixed_queue_free(p_port->rx.queue, nullptr); in port_release_port()
240 p_port->rx.queue = nullptr; in port_release_port()
243 if (p_port->keep_port_handle) { in port_release_port()
245 p_port->handle); in port_release_port()
248 uint32_t mask = p_port->ev_mask; in port_release_port()
249 tPORT_CALLBACK* p_port_cb = p_port->p_callback; in port_release_port()
250 tPORT_STATE user_port_pars = p_port->user_port_pars; in port_release_port()
252 port_set_defaults(p_port); in port_release_port()
255 p_port->ev_mask = mask; in port_release_port()
256 p_port->p_callback = p_port_cb; in port_release_port()
257 p_port->user_port_pars = user_port_pars; in port_release_port()
258 p_port->mtu = p_port->keep_mtu; in port_release_port()
260 p_port->state = PORT_STATE_OPENING; in port_release_port()
261 p_port->rfc.p_mcb = nullptr; in port_release_port()
262 if (p_port->is_server) p_port->dlci &= 0xfe; in port_release_port()
264 p_port->local_ctrl.modem_signal = p_port->default_signal_state; in port_release_port()
265 p_port->bd_addr = RawAddress::kAny; in port_release_port()
267 RFCOMM_TRACE_DEBUG("%s Clean-up handle: %d", __func__, p_port->handle); in port_release_port()
268 alarm_free(p_port->rfc.port_timer); in port_release_port()
269 memset(p_port, 0, sizeof(tPORT)); in port_release_port()
382 uint32_t port_flow_control_user(tPORT* p_port) { in port_flow_control_user() argument
388 bool fc = p_port->tx.peer_fc || !p_port->rfc.p_mcb || in port_flow_control_user()
389 !p_port->rfc.p_mcb->peer_ready || in port_flow_control_user()
390 (p_port->tx.queue_size > PORT_TX_HIGH_WM) || in port_flow_control_user()
391 (fixed_queue_length(p_port->tx.queue) > PORT_TX_BUF_HIGH_WM); in port_flow_control_user()
393 if (p_port->tx.user_fc == fc) return (0); in port_flow_control_user()
395 p_port->tx.user_fc = fc; in port_flow_control_user()
414 uint32_t port_get_signal_changes(tPORT* p_port, uint8_t old_signals, in port_get_signal_changes() argument
439 return (p_port->ev_mask & events); in port_get_signal_changes()
453 void port_flow_control_peer(tPORT* p_port, bool enable, uint16_t count) { in port_flow_control_peer() argument
454 if (!p_port->rfc.p_mcb) return; in port_flow_control_peer()
457 if (p_port->rfc.p_mcb->flow == PORT_FC_CREDIT) { in port_flow_control_peer()
461 if (count > p_port->credit_rx) { in port_flow_control_peer()
462 p_port->credit_rx = 0; in port_flow_control_peer()
464 p_port->credit_rx -= count; in port_flow_control_peer()
470 if ((p_port->credit_rx <= p_port->credit_rx_low) && !p_port->rx.user_fc && in port_flow_control_peer()
471 (p_port->credit_rx_max > p_port->credit_rx)) { in port_flow_control_peer()
472 rfc_send_credit(p_port->rfc.p_mcb, p_port->dlci, in port_flow_control_peer()
473 (uint8_t)(p_port->credit_rx_max - p_port->credit_rx)); in port_flow_control_peer()
475 p_port->credit_rx = p_port->credit_rx_max; in port_flow_control_peer()
477 p_port->rx.peer_fc = false; in port_flow_control_peer()
483 if (p_port->p_data_callback || p_port->p_data_co_callback) { in port_flow_control_peer()
484 p_port->rx.peer_fc = true; in port_flow_control_peer()
487 else if (fixed_queue_length(p_port->rx.queue) >= p_port->credit_rx_max) { in port_flow_control_peer()
488 p_port->rx.peer_fc = true; in port_flow_control_peer()
498 if (p_port->rx.peer_fc && (p_port->rx.queue_size < PORT_RX_LOW_WM) && in port_flow_control_peer()
499 (fixed_queue_length(p_port->rx.queue) < PORT_RX_BUF_LOW_WM)) { in port_flow_control_peer()
500 p_port->rx.peer_fc = false; in port_flow_control_peer()
503 if (!p_port->rx.user_fc) in port_flow_control_peer()
504 RFCOMM_FlowReq(p_port->rfc.p_mcb, p_port->dlci, true); in port_flow_control_peer()
510 if (p_port->p_data_callback || p_port->p_data_co_callback) { in port_flow_control_peer()
511 p_port->rx.peer_fc = true; in port_flow_control_peer()
512 RFCOMM_FlowReq(p_port->rfc.p_mcb, p_port->dlci, false); in port_flow_control_peer()
516 else if (((p_port->rx.queue_size > PORT_RX_HIGH_WM) || in port_flow_control_peer()
517 (fixed_queue_length(p_port->rx.queue) > PORT_RX_BUF_HIGH_WM)) && in port_flow_control_peer()
518 !p_port->rx.peer_fc) { in port_flow_control_peer()
521 p_port->rx.peer_fc = true; in port_flow_control_peer()
522 RFCOMM_FlowReq(p_port->rfc.p_mcb, p_port->dlci, false); in port_flow_control_peer()