Esempio n. 1
0
def stop_advertising(sock):
    if sock._raw_sdp_record is None:
        raise OSError("service isn't advertised, " \
                        "but trying to un-advertise")
    bt.set_service_raw(sock._raw_sdp_record, False, sock._sdp_handle)
    sock._raw_sdp_record = None
    sock._sdp_handle = None
Esempio n. 2
0
def stop_advertising (sock):
    if sock._raw_sdp_record is None:
        raise IOError ("service isn't advertised, " \
                        "but trying to un-advertise")
    bt.set_service_raw (sock._raw_sdp_record, False, sock._sdp_handle)
    sock._raw_sdp_record = None
    sock._sdp_handle = None
Esempio n. 3
0
def advertise_service (sock, name, service_id = "", service_classes = [], \
        profiles = [], provider = "", description = "", protocols = []):
    if service_id != "" and not is_valid_uuid(service_id):
        raise ValueError("invalid UUID specified for service_id")
    for uuid in service_classes:
        if not is_valid_uuid(uuid):
            raise ValueError("invalid UUID specified in service_classes")
    for uuid, version in profiles:
        if not is_valid_uuid(uuid) or version < 0 or version > 0xFFFF:
            raise ValueError("Invalid Profile Descriptor")
    for uuid in protocols:
        if not is_valid_uuid(uuid):
            raise ValueError("invalid UUID specified in protocols")

    if sock._raw_sdp_record is not None:
        raise OSError("service already advertised")

    avpairs = []

    # service UUID
    if len(service_id) > 0:
        avpairs.append(("UInt16", SERVICE_ID_ATTRID))
        avpairs.append(("UUID", service_id))

    # service class list
    if len(service_classes) > 0:
        seq = [("UUID", svc_class) for svc_class in service_classes]
        avpairs.append(("UInt16", SERVICE_CLASS_ID_LIST_ATTRID))
        avpairs.append(("ElemSeq", seq))

    # set protocol and port information
    assert sock._proto == RFCOMM
    addr, port = sock.getsockname()
    avpairs.append(("UInt16", PROTOCOL_DESCRIPTOR_LIST_ATTRID))
    l2cap_pd = ("ElemSeq", (("UUID", L2CAP_UUID), ))
    rfcomm_pd = ("ElemSeq", (("UUID", RFCOMM_UUID), ("UInt8", port)))
    proto_list = [l2cap_pd, rfcomm_pd]
    for proto_uuid in protocols:
        proto_list.append(("ElemSeq", (("UUID", proto_uuid), )))
    avpairs.append(("ElemSeq", proto_list))

    # make the service publicly browseable
    avpairs.append(("UInt16", BROWSE_GROUP_LIST_ATTRID))
    avpairs.append(("ElemSeq", (("UUID", PUBLIC_BROWSE_GROUP), )))

    # profile descriptor list
    if len(profiles) > 0:
        seq = [ ("ElemSeq", (("UUID",uuid), ("UInt16",version))) \
                for uuid, version in profiles ]
        avpairs.append(("UInt16", BLUETOOTH_PROFILE_DESCRIPTOR_LIST_ATTRID))
        avpairs.append(("ElemSeq", seq))

    # service name
    avpairs.append(("UInt16", SERVICE_NAME_ATTRID))
    avpairs.append(("String", name))

    # service description
    if len(description) > 0:
        avpairs.append(("UInt16", SERVICE_DESCRIPTION_ATTRID))
        avpairs.append(("String", description))

    # service provider
    if len(provider) > 0:
        avpairs.append(("UInt16", PROVIDER_NAME_ATTRID))
        avpairs.append(("String", provider))

    sock._raw_sdp_record = sdp_make_data_element("ElemSeq", avpairs)
    #    pr = sdp_parse_raw_record (sock._raw_sdp_record)
    #    for attrid, val in pr.items ():
    #        print "%5s: %s" % (attrid, val)
    #    print binascii.hexlify (sock._raw_sdp_record)
    #    print repr (sock._raw_sdp_record)

    sock._sdp_handle = bt.set_service_raw(sock._raw_sdp_record, True)
Esempio n. 4
0
def advertise_service (sock, name, service_id = "", service_classes = [], \
        profiles = [], provider = "", description = "", protocols = []):
    if service_id != "" and not is_valid_uuid (service_id):
        raise ValueError ("invalid UUID specified for service_id")
    for uuid in service_classes:
        if not is_valid_uuid (uuid):
            raise ValueError ("invalid UUID specified in service_classes")
    for uuid, version in profiles:
        if not is_valid_uuid (uuid) or  version < 0 or  version > 0xFFFF:
            raise ValueError ("Invalid Profile Descriptor")
    for uuid in protocols:
        if not is_valid_uuid (uuid):
            raise ValueError ("invalid UUID specified in protocols")        

    if sock._raw_sdp_record is not None:
        raise IOError ("service already advertised")

    avpairs = []

    # service UUID
    if len (service_id) > 0:
        avpairs.append (("UInt16", SERVICE_ID_ATTRID))
        avpairs.append (("UUID", service_id))

    # service class list
    if len (service_classes) > 0:
        seq = [ ("UUID", svc_class) for svc_class in service_classes ]
        avpairs.append (("UInt16", SERVICE_CLASS_ID_LIST_ATTRID))
        avpairs.append (("ElemSeq", seq))

    # set protocol and port information
    assert sock._proto == RFCOMM
    addr, port = sock.getsockname ()
    avpairs.append (("UInt16", PROTOCOL_DESCRIPTOR_LIST_ATTRID))
    l2cap_pd = ("ElemSeq", (("UUID", L2CAP_UUID),))
    rfcomm_pd = ("ElemSeq", (("UUID", RFCOMM_UUID), ("UInt8", port)))
    proto_list = [ l2cap_pd, rfcomm_pd ]
    for proto_uuid in protocols:
        proto_list.append (("ElemSeq", (("UUID", proto_uuid),)))
    avpairs.append (("ElemSeq", proto_list))

    # make the service publicly browseable
    avpairs.append (("UInt16", BROWSE_GROUP_LIST_ATTRID))
    avpairs.append (("ElemSeq", (("UUID", PUBLIC_BROWSE_GROUP),)))

    # profile descriptor list
    if len (profiles) > 0:
        seq = [ ("ElemSeq", (("UUID",uuid), ("UInt16",version))) \
                for uuid, version in profiles ]
        avpairs.append (("UInt16", 
            BLUETOOTH_PROFILE_DESCRIPTOR_LIST_ATTRID))
        avpairs.append (("ElemSeq", seq))

    # service name
    avpairs.append (("UInt16", SERVICE_NAME_ATTRID))
    avpairs.append (("String", name))

    # service description
    if len (description) > 0:
        avpairs.append (("UInt16", SERVICE_DESCRIPTION_ATTRID))
        avpairs.append (("String", description))
    
    # service provider
    if len (provider) > 0:
        avpairs.append (("UInt16", PROVIDER_NAME_ATTRID))
        avpairs.append (("String", provider))

    sock._raw_sdp_record = sdp_make_data_element ("ElemSeq", avpairs)
#    pr = sdp_parse_raw_record (sock._raw_sdp_record)
#    for attrid, val in pr.items ():
#        print "%5s: %s" % (attrid, val)
#    print binascii.hexlify (sock._raw_sdp_record)
#    print repr (sock._raw_sdp_record)

    sock._sdp_handle = bt.set_service_raw (sock._raw_sdp_record, True)