sdp.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. *
  4. * BlueZ - Bluetooth protocol stack for Linux
  5. *
  6. * Copyright (C) 2003-2010 Marcel Holtmann <marcel@holtmann.org>
  7. *
  8. *
  9. */
  10. #ifdef HAVE_CONFIG_H
  11. #include <config.h>
  12. #endif
  13. #include <stdio.h>
  14. #include <errno.h>
  15. #include <unistd.h>
  16. #include <signal.h>
  17. #include <sys/socket.h>
  18. #include "lib/bluetooth.h"
  19. #include "lib/sdp.h"
  20. #include "lib/sdp_lib.h"
  21. #include "cups.h"
  22. int sdp_search_hcrp(sdp_session_t *sdp, unsigned short *ctrl_psm, unsigned short *data_psm)
  23. {
  24. sdp_list_t *srch, *attrs, *rsp;
  25. uuid_t svclass;
  26. uint16_t attr1, attr2;
  27. int err;
  28. if (!sdp)
  29. return -1;
  30. sdp_uuid16_create(&svclass, HCR_PRINT_SVCLASS_ID);
  31. srch = sdp_list_append(NULL, &svclass);
  32. attr1 = SDP_ATTR_PROTO_DESC_LIST;
  33. attrs = sdp_list_append(NULL, &attr1);
  34. attr2 = SDP_ATTR_ADD_PROTO_DESC_LIST;
  35. attrs = sdp_list_append(attrs, &attr2);
  36. err = sdp_service_search_attr_req(sdp, srch, SDP_ATTR_REQ_INDIVIDUAL, attrs, &rsp);
  37. if (err)
  38. return -1;
  39. for (; rsp; rsp = rsp->next) {
  40. sdp_record_t *rec = (sdp_record_t *) rsp->data;
  41. sdp_list_t *protos;
  42. if (!sdp_get_access_protos(rec, &protos)) {
  43. unsigned short psm = sdp_get_proto_port(protos, L2CAP_UUID);
  44. if (psm > 0) {
  45. *ctrl_psm = psm;
  46. }
  47. }
  48. if (!sdp_get_add_access_protos(rec, &protos)) {
  49. unsigned short psm = sdp_get_proto_port(protos, L2CAP_UUID);
  50. if (psm > 0 && *ctrl_psm > 0) {
  51. *data_psm = psm;
  52. return 0;
  53. }
  54. }
  55. }
  56. return -1;
  57. }
  58. int sdp_search_spp(sdp_session_t *sdp, uint8_t *channel)
  59. {
  60. sdp_list_t *srch, *attrs, *rsp;
  61. uuid_t svclass;
  62. uint16_t attr;
  63. int err;
  64. if (!sdp)
  65. return -1;
  66. sdp_uuid16_create(&svclass, SERIAL_PORT_SVCLASS_ID);
  67. srch = sdp_list_append(NULL, &svclass);
  68. attr = SDP_ATTR_PROTO_DESC_LIST;
  69. attrs = sdp_list_append(NULL, &attr);
  70. err = sdp_service_search_attr_req(sdp, srch, SDP_ATTR_REQ_INDIVIDUAL, attrs, &rsp);
  71. if (err)
  72. return -1;
  73. for (; rsp; rsp = rsp->next) {
  74. sdp_record_t *rec = (sdp_record_t *) rsp->data;
  75. sdp_list_t *protos;
  76. if (!sdp_get_access_protos(rec, &protos)) {
  77. uint8_t ch = sdp_get_proto_port(protos, RFCOMM_UUID);
  78. if (ch > 0) {
  79. *channel = ch;
  80. return 0;
  81. }
  82. }
  83. }
  84. return -1;
  85. }