Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  manager.rs

  Sprache: Rust
 

// Copyright 2023 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::ffi;
use crate::llcp::iso;
use crate::packets::{hci, llcp};
use std::collections::HashMap;
use std::convert::TryFrom;
use thiserror::Error;

struct Link {
    acl_connection_handle: u16,
    role: hci::Role,
}

pub struct LinkLayer {
    ops: ffi::ControllerOps,
    links: HashMap<u16, Link>,
    iso: iso::IsoManager,
}

#[derive(Error, Debug)]
pub enum LinkLayerError {
    #[error("Unknown peer")]
    UnknownPeer,
    #[error("Link already exists")]
    LinkAlreadyExists,
    #[error("Unhandled HCI packet")]
    UnhandledHciPacket,
    #[error("Invalid HCI packet")]
    InvalidHciPacket,
    #[error("Invalid LLCP packet")]
    InvalidLlcpPacket,
}

impl LinkLayer {
    pub fn new(ops: ffi::ControllerOps) -> LinkLayer {
        let iso = iso::IsoManager::new(ops.clone());
        LinkLayer { ops, links: HashMap::new(), iso }
    }

    pub fn add_link(
        &mut self,
        acl_connection_handle: u16,
        _peer_address: hci::Address,
        role: hci::Role,
    ) -> Result<(), LinkLayerError> {
        if self.links.contains_key(&acl_connection_handle) {
            return Err(LinkLayerError::LinkAlreadyExists);
        }

        self.links
            .insert(acl_connection_handle, Link { acl_connection_handle, role });
        self.iso.add_acl_connection(acl_connection_handle, role);
        Ok(())
    }

    pub fn remove_link(
        &mut self,
        acl_connection_handle: u16,
        reason: u8,
    ) -> Result<(), LinkLayerError> {
        if self.links.remove(&acl_connection_handle).is_none() {
            return Err(LinkLayerError::UnknownPeer);
        }

        let reason = hci::ErrorCode::try_from(reason)
            .unwrap_or(hci::ErrorCode::RemoteUserTerminatedConnection);
        self.iso
            .remove_acl_connection(acl_connection_handle, reason);
        Ok(())
    }

    pub fn tick(&mut self) {}

    pub fn ingest_hci(&mut self, packet: hci::Command) -> Result<(), LinkLayerError> {
        use hci::CommandChild::*;
        match packet.specialize() {
            Ok(Disconnect(packet)) => self.iso.hci_disconnect(packet),
            Ok(LeSetCigParameters(packet)) => self.iso.hci_le_set_cig_parameters(packet),
            Ok(LeSetCigParametersTest(packet)) => self.iso.hci_le_set_cig_parameters_test(packet),
            Ok(LeCreateCis(packet)) => self.iso.hci_le_create_cis(packet),
            Ok(LeRemoveCig(packet)) => self.iso.hci_le_remove_cig(packet),
            Ok(LeAcceptCisRequest(packet)) => self.iso.hci_le_accept_cis_request(packet),
            Ok(LeRejectCisRequest(packet)) => self.iso.hci_le_reject_cis_request(packet),
            Ok(LeSetupIsoDataPath(packet)) => self.iso.hci_le_setup_iso_data_path(packet),
            Ok(LeRemoveIsoDataPath(packet)) => self.iso.hci_le_remove_iso_data_path(packet),
            _ => Err(LinkLayerError::UnhandledHciPacket)?,
        };
        Ok(())
    }

    pub fn ingest_llcp(
        &mut self,
        acl_connection_handle: u16,
        packet: llcp::LlcpPacket,
    ) -> Result<(), LinkLayerError> {
        use llcp::LlcpPacketChild::*;
        match packet.specialize() {
            Ok(RejectExtInd(packet)) => match llcp::Opcode::try_from(packet.reject_opcode()) {
                Ok(llcp::Opcode::LlCisReq) => {
                    self.iso.ll_reject_ext_ind(acl_connection_handle, packet)
                }
                _ => unreachable!(),
            },
            Ok(CisReq(packet)) => self.iso.ll_cis_req(acl_connection_handle, packet),
            Ok(CisRsp(packet)) => self.iso.ll_cis_rsp(acl_connection_handle, packet),
            Ok(CisInd(packet)) => self.iso.ll_cis_ind(acl_connection_handle, packet),
            Ok(CisTerminateInd(packet)) => {
                self.iso.ll_cis_terminate_ind(acl_connection_handle, packet)
            }
            _ => unimplemented!(),
        }
        Ok(())
    }

    pub fn get_cis_connection_handle(&self, cig_id: u8, cis_id: u8) -> Option<u16> {
        self.iso
            .get_cis_connection_handle(|cis| cis.cig_id == cig_id && cis.cis_id == cis_id)
    }

    pub fn get_cis(&self, cis_connection_handle: u16) -> Option<&iso::Cis> {
        self.iso.get_cis(cis_connection_handle)
    }
}

Messung V0.5 in Prozent
C=86 H=97 G=91

¤ Dauer der Verarbeitung: 0.12 Sekunden  (vorverarbeitet am  2026-06-27) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik