Lines Matching +full:break +full:- +full:control

1 /*-
4 * SPDX-License-Identifier: BSD-2-Clause
67 server_init(server_p srv, char const *control) in server_init() argument
76 assert(control != NULL); in server_init()
80 /* Open control socket */ in server_init()
81 if (unlink(control) < 0 && errno != ENOENT) { in server_init()
83 control, strerror(errno), errno); in server_init()
84 return (-1); in server_init()
89 log_crit("Could not create control socket. %s (%d)", in server_init()
91 return (-1); in server_init()
97 strlcpy(un.sun_path, control, sizeof(un.sun_path)); in server_init()
100 log_crit("Could not bind control socket. %s (%d)", in server_init()
103 return (-1); in server_init()
106 if (chmod(control, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) < 0) { in server_init()
107 log_crit("Could not change permissions on control socket. " \ in server_init()
110 return (-1); in server_init()
114 log_crit("Could not listen on control socket. %s (%d)", in server_init()
117 return (-1); in server_init()
126 return (-1); in server_init()
135 return (-1); in server_init()
149 return (-1); in server_init()
157 return (-1); in server_init()
161 srv->imtu = (imtu > SDP_LOCAL_MTU)? imtu : SDP_LOCAL_MTU; in server_init()
162 srv->req = (uint8_t *) calloc(srv->imtu, sizeof(srv->req[0])); in server_init()
163 if (srv->req == NULL) { in server_init()
167 return (-1); in server_init()
171 srv->fdidx = (fd_idx_p) calloc(FD_SETSIZE, sizeof(srv->fdidx[0])); in server_init()
172 if (srv->fdidx == NULL) { in server_init()
174 free(srv->req); in server_init()
177 return (-1); in server_init()
180 /* Register Service Discovery profile (attach it to control socket) */ in server_init()
183 free(srv->fdidx); in server_init()
184 free(srv->req); in server_init()
187 return (-1); in server_init()
191 * If we got here then everything is fine. Add both control sockets in server_init()
195 FD_ZERO(&srv->fdset); in server_init()
196 srv->maxfd = (unsock > l2sock)? unsock : l2sock; in server_init()
198 FD_SET(unsock, &srv->fdset); in server_init()
199 srv->fdidx[unsock].valid = 1; in server_init()
200 srv->fdidx[unsock].server = 1; in server_init()
201 srv->fdidx[unsock].control = 1; in server_init()
202 srv->fdidx[unsock].priv = 0; in server_init()
203 srv->fdidx[unsock].rsp_cs = 0; in server_init()
204 srv->fdidx[unsock].rsp_size = 0; in server_init()
205 srv->fdidx[unsock].rsp_limit = 0; in server_init()
206 srv->fdidx[unsock].omtu = SDP_LOCAL_MTU; in server_init()
207 srv->fdidx[unsock].rsp = NULL; in server_init()
209 FD_SET(l2sock, &srv->fdset); in server_init()
210 srv->fdidx[l2sock].valid = 1; in server_init()
211 srv->fdidx[l2sock].server = 1; in server_init()
212 srv->fdidx[l2sock].control = 0; in server_init()
213 srv->fdidx[l2sock].priv = 0; in server_init()
214 srv->fdidx[l2sock].rsp_cs = 0; in server_init()
215 srv->fdidx[l2sock].rsp_size = 0; in server_init()
216 srv->fdidx[l2sock].rsp_limit = 0; in server_init()
217 srv->fdidx[l2sock].omtu = 0; /* unknown */ in server_init()
218 srv->fdidx[l2sock].rsp = NULL; in server_init()
234 for (fd = 0; fd < srv->maxfd + 1; fd ++) in server_shutdown()
235 if (srv->fdidx[fd].valid) in server_shutdown()
238 free(srv->req); in server_shutdown()
239 free(srv->fdidx); in server_shutdown()
257 memcpy(&fdset, &srv->fdset, sizeof(fdset)); in server_do()
258 n = select(srv->maxfd + 1, &fdset, NULL, NULL, NULL); in server_do()
264 srv->maxfd + 1, &fdset, strerror(errno), errno); in server_do()
266 return (-1); in server_do()
270 for (fd = 0; fd < srv->maxfd + 1 && n > 0; fd ++) { in server_do()
274 assert(srv->fdidx[fd].valid); in server_do()
275 n --; in server_do()
277 if (srv->fdidx[fd].server) in server_do()
305 srv->fdidx[fd].control? "control" : "L2CAP", in server_accept_client()
310 assert(!FD_ISSET(cfd, &srv->fdset)); in server_accept_client()
311 assert(!srv->fdidx[cfd].valid); in server_accept_client()
315 if (!srv->fdidx[fd].control) { in server_accept_client()
317 size = sizeof(srv->req_sa); in server_accept_client()
318 if (getsockname(cfd,(struct sockaddr*)&srv->req_sa,&size) < 0) { in server_accept_client()
365 priv = (strcmp(pw->pw_name, "root") == 0); in server_accept_client()
370 memcpy(&srv->req_sa.l2cap_bdaddr, NG_HCI_BDADDR_ANY, in server_accept_client()
371 sizeof(srv->req_sa.l2cap_bdaddr)); in server_accept_client()
373 omtu = srv->fdidx[fd].omtu; in server_accept_client()
389 FD_SET(cfd, &srv->fdset); in server_accept_client()
390 if (srv->maxfd < cfd) in server_accept_client()
391 srv->maxfd = cfd; in server_accept_client()
392 srv->fdidx[cfd].valid = 1; in server_accept_client()
393 srv->fdidx[cfd].server = 0; in server_accept_client()
394 srv->fdidx[cfd].control = srv->fdidx[fd].control; in server_accept_client()
395 srv->fdidx[cfd].priv = priv; in server_accept_client()
396 srv->fdidx[cfd].rsp_cs = 0; in server_accept_client()
397 srv->fdidx[cfd].rsp_size = 0; in server_accept_client()
398 srv->fdidx[cfd].rsp_limit = 0; in server_accept_client()
399 srv->fdidx[cfd].omtu = omtu; in server_accept_client()
400 srv->fdidx[cfd].rsp = rsp; in server_accept_client()
410 sdp_pdu_p pdu = (sdp_pdu_p) srv->req; in server_process_request()
413 assert(srv->imtu > 0); in server_process_request()
414 assert(srv->req != NULL); in server_process_request()
415 assert(FD_ISSET(fd, &srv->fdset)); in server_process_request()
416 assert(srv->fdidx[fd].valid); in server_process_request()
417 assert(!srv->fdidx[fd].server); in server_process_request()
418 assert(srv->fdidx[fd].rsp != NULL); in server_process_request()
419 assert(srv->fdidx[fd].omtu >= NG_L2CAP_MTU_MINIMUM); in server_process_request()
422 len = read(fd, srv->req, srv->imtu); in server_process_request()
427 srv->fdidx[fd].control? "control" : "L2CAP", in server_process_request()
429 return (-1); in server_process_request()
433 srv->fdidx[fd].control? "control" : "L2CAP"); in server_process_request()
434 return (-1); in server_process_request()
438 sizeof(*pdu) + (pdu->len = ntohs(pdu->len)) == len) { in server_process_request()
439 switch (pdu->pid) { in server_process_request()
442 break; in server_process_request()
446 break; in server_process_request()
450 break; in server_process_request()
454 break; in server_process_request()
458 break; in server_process_request()
462 break; in server_process_request()
466 break; in server_process_request()
472 switch (pdu->pid) { in server_process_request()
475 break; in server_process_request()
479 break; in server_process_request()
483 break; in server_process_request()
487 break; in server_process_request()
491 break; in server_process_request()
495 break; in server_process_request()
499 break; in server_process_request()
504 "pdu->pid=%d, pdu->tid=%d, error=%d", in server_process_request()
505 srv->fdidx[fd].control? "control" : "L2CAP", in server_process_request()
506 pdu->pid, ntohs(pdu->tid), error); in server_process_request()
509 "pdu->pid=%d, pdu->tid=%d, pdu->len=%d, len=%d, " \ in server_process_request()
511 srv->fdidx[fd].control? "control" : "L2CAP", in server_process_request()
512 pdu->pid, ntohs(pdu->tid), pdu->len, len, error); in server_process_request()
517 "socket, pdu->pid=%d, pdu->tid=%d, error=%d", in server_process_request()
518 srv->fdidx[fd].control? "control" : "L2CAP", in server_process_request()
519 pdu->pid, ntohs(pdu->tid), error); in server_process_request()
524 srv->fdidx[fd].rsp_cs = 0; in server_process_request()
525 srv->fdidx[fd].rsp_size = 0; in server_process_request()
526 srv->fdidx[fd].rsp_limit = 0; in server_process_request()
548 rsp.pdu.tid = ((sdp_pdu_p)(srv->req))->tid; in server_send_error_response()
568 assert(FD_ISSET(fd, &srv->fdset)); in server_close_fd()
569 assert(srv->fdidx[fd].valid); in server_close_fd()
573 FD_CLR(fd, &srv->fdset); in server_close_fd()
574 if (fd == srv->maxfd) in server_close_fd()
575 srv->maxfd --; in server_close_fd()
577 if (srv->fdidx[fd].rsp != NULL) in server_close_fd()
578 free(srv->fdidx[fd].rsp); in server_close_fd()
580 memset(&srv->fdidx[fd], 0, sizeof(srv->fdidx[fd])); in server_close_fd()
587 if (provider->fd == fd) in server_close_fd()