-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1909 lines (1505 loc) · 382 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 7.1.1">
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png">
<link rel="mask-icon" href="/images/safari_pinned_tab.svg" color="#222">
<link rel="stylesheet" href="/css/main.css">
<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/pace-js@1/themes/blue/pace-theme-minimal.css">
<script src="//cdn.jsdelivr.net/npm/pace-js@1/pace.min.js"></script>
<script id="hexo-configurations">
var NexT = window.NexT || {};
var CONFIG = {"hostname":"blog.liaoheng.me","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
</script>
<meta name="description" content="A developer">
<meta property="og:type" content="website">
<meta property="og:title" content="liaoheng`s blog">
<meta property="og:url" content="https://blog.liaoheng.me/index.html">
<meta property="og:site_name" content="liaoheng`s blog">
<meta property="og:description" content="A developer">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="liaoheng">
<meta name="twitter:card" content="summary">
<link rel="canonical" href="https://blog.liaoheng.me/">
<script id="page-configurations">
// https://hexo.io/docs/variables.html
CONFIG.page = {
sidebar: "",
isHome : true,
isPost : false,
lang : 'zh-CN'
};
</script>
<title>liaoheng`s blog</title>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-64FL8LWFL8"></script>
<script>
if (CONFIG.hostname === location.hostname) {
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-64FL8LWFL8');
}
</script>
<noscript>
<style>
.use-motion .brand,
.use-motion .menu-item,
.sidebar-inner,
.use-motion .post-block,
.use-motion .pagination,
.use-motion .comments,
.use-motion .post-header,
.use-motion .post-body,
.use-motion .collection-header { opacity: initial; }
.use-motion .site-title,
.use-motion .site-subtitle {
opacity: initial;
top: initial;
}
.use-motion .logo-line-before i { left: initial; }
.use-motion .logo-line-after i { right: initial; }
</style>
</noscript>
<link rel="alternate" href="/atom.xml" title="liaoheng`s blog" type="application/atom+xml">
</head>
<body itemscope itemtype="http://schema.org/WebPage">
<div class="container use-motion">
<div class="headband"></div>
<header class="header" itemscope itemtype="http://schema.org/WPHeader">
<div class="header-inner"><div class="site-brand-container">
<div class="site-nav-toggle">
<div class="toggle" aria-label="切换导航栏">
<span class="toggle-line toggle-line-first"></span>
<span class="toggle-line toggle-line-middle"></span>
<span class="toggle-line toggle-line-last"></span>
</div>
</div>
<div class="site-meta">
<a href="/" class="brand" rel="start">
<span class="logo-line-before"><i></i></span>
<h1 class="site-title">liaoheng`s blog</h1>
<span class="logo-line-after"><i></i></span>
</a>
</div>
<div class="site-nav-right">
<div class="toggle popup-trigger">
</div>
</div>
</div>
<nav class="site-nav">
<ul id="menu" class="main-menu menu">
<li class="menu-item menu-item-home">
<a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>
</li>
<li class="menu-item menu-item-archives">
<a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>
</li>
</ul>
</nav>
</div>
</header>
<div class="back-to-top">
<i class="fa fa-arrow-up"></i>
<span>0%</span>
</div>
<a href="https://github.com/liaoheng" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>
<main class="main">
<div class="main-inner">
<div class="content-wrap">
<div class="content index posts-expand">
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
<link itemprop="mainEntityOfPage" href="https://blog.liaoheng.me/2024/02/21/android-ripple/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.jpg">
<meta itemprop="name" content="liaoheng">
<meta itemprop="description" content="A developer">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="liaoheng`s blog">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2024/02/21/android-ripple/" class="post-title-link" itemprop="url">Android Ripple(波纹效果)</a>
</h2>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建时间:2024-02-21 13:49:59 / 修改时间:14:11:49" itemprop="dateCreated datePublished" datetime="2024-02-21T13:49:59+08:00">2024-02-21</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<blockquote>
<p>控件中的Ripple标签,即对应一个RippleDrawable,当它被设置为一个控件的background属性时,控件在按下时,即会显示水波效果</p>
</blockquote>
<h1 id="自定义"><a href="#自定义" class="headerlink" title="自定义"></a>自定义</h1><h2 id="没有边界的Ripple(Ripple-With-No-Mask)"><a href="#没有边界的Ripple(Ripple-With-No-Mask)" class="headerlink" title="没有边界的Ripple(Ripple With No Mask)"></a>没有边界的Ripple(Ripple With No Mask)</h2><p>波纹的内直径<code>就是</code>控件的长或者宽,实现内容如下,不需要任何操作即可。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">ripple</span> <span class="attr">xmlns:android</span>=<span class="string">"http://schemas.android.com/apk/res/android"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">android:color</span>=<span class="string">"?attr/colorControlHighlight"</span> /></span></span><br></pre></td></tr></table></figure>
<p><img data-src="https://pic.liaoheng.me/hc-pic/2024/02/fb5e3c11b575fa8e46d0847e7d3eea49.gif"></p>
<h2 id="有边界的Ripple(Ripple-With-Mask)"><a href="#有边界的Ripple(Ripple-With-Mask)" class="headerlink" title="有边界的Ripple(Ripple With Mask)"></a>有边界的Ripple(Ripple With Mask)</h2><p>波纹<code>不超过</code>控件的显示范围,实现内容如下,需要增加一个@android:id/mask配置,配置中的颜色就是波纹的背景色,会与ripple颜色重叠显示。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">ripple</span> <span class="attr">xmlns:android</span>=<span class="string">"http://schemas.android.com/apk/res/android"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">android:color</span>=<span class="string">"?attr/colorControlHighlight"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">item</span> <span class="attr">android:id</span>=<span class="string">"@android:id/mask"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">color</span> <span class="attr">android:color</span>=<span class="string">"@color/white"</span> /></span></span><br><span class="line"> <span class="tag"></<span class="name">item</span>></span></span><br><span class="line"><span class="tag"></<span class="name">ripple</span>></span></span><br></pre></td></tr></table></figure>
<p><img data-src="https://pic.liaoheng.me/hc-pic/2024/02/cb0c71e1f80ff24750032f3c05d2289c.gif"></p>
<h2 id="用图片作边界的Ripple(Ripple-With-Picture-Mask)"><a href="#用图片作边界的Ripple(Ripple-With-Picture-Mask)" class="headerlink" title="用图片作边界的Ripple(Ripple With Picture Mask)"></a>用图片作边界的Ripple(Ripple With Picture Mask)</h2><p>波纹<code>不超过</code>图片的显示范围,实现内容如下,需要增加一个@android:id/mask配置,配置中的图片就是波纹的背景,会与ripple颜色重叠显示。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">ripple</span> <span class="attr">xmlns:android</span>=<span class="string">"http://schemas.android.com/apk/res/android"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">android:color</span>=<span class="string">"?attr/colorControlHighlight"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">item</span> <span class="attr">android:id</span>=<span class="string">"@android:id/mask"</span> <span class="attr">android:drawable</span>=<span class="string">"@drawable/icon"</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">item</span>></span></span><br><span class="line"><span class="tag"></<span class="name">ripple</span>></span></span><br></pre></td></tr></table></figure>
<p><img data-src="https://pic.liaoheng.me/hc-pic/2024/02/bd440efc6f351d0cb406b131a7c69e59.gif"></p>
<h2 id="用形状作边界的Ripple(Ripple-With-Shape-Mask)"><a href="#用形状作边界的Ripple(Ripple-With-Shape-Mask)" class="headerlink" title="用形状作边界的Ripple(Ripple With Shape Mask)"></a>用形状作边界的Ripple(Ripple With Shape Mask)</h2><p>波纹<code>不超过</code>形状的显示范围,实现内容如下,需要增加一个@android:id/mask配置,配置中的形状就是波纹的背景,会与ripple颜色重叠显示。</p>
<ul>
<li>shape.xml<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">shape</span> <span class="attr">xmlns:android</span>=<span class="string">"http://schemas.android.com/apk/res/android"</span> </span></span><br><span class="line"><span class="tag"> <span class="attr">android:shape</span>=<span class="string">"rectangle"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">solid</span> <span class="attr">android:color</span>=<span class="string">"#ff9d77"</span>/></span></span><br><span class="line"> <span class="tag"><<span class="name">corners</span></span></span><br><span class="line"><span class="tag"> <span class="attr">android:bottomRightRadius</span>=<span class="string">"100dp"</span>/></span></span><br><span class="line"><span class="tag"></<span class="name">shape</span>></span></span><br></pre></td></tr></table></figure>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><?xml version=<span class="string">"1.0"</span> encoding=<span class="string">"utf-8"</span>?></span></span><br><span class="line"><span class="tag"><<span class="name">ripple</span> <span class="attr">xmlns:android</span>=<span class="string">"http://schemas.android.com/apk/res/android"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">android:color</span>=<span class="string">"#FF0000"</span> ></span></span><br><span class="line"> <span class="tag"><<span class="name">item</span></span></span><br><span class="line"><span class="tag"> <span class="attr">android:id</span>=<span class="string">"@android:id/mask"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">android:drawable</span>=<span class="string">"@drawable/shape"</span>/></span></span><br><span class="line"><span class="tag"></<span class="name">ripple</span>></span></span><br></pre></td></tr></table></figure>
<img data-src="https://pic.liaoheng.me/hc-pic/2024/02/ae148630116fff2c868330bbcd1c8cbb.gif"></li>
</ul>
<h2 id="搭配selector作为Ripple(Ripple-With-Selector)"><a href="#搭配selector作为Ripple(Ripple-With-Selector)" class="headerlink" title="搭配selector作为Ripple(Ripple With Selector)"></a>搭配selector作为Ripple(Ripple With Selector)</h2><blockquote>
<p>如果在一个ripple标签中,添加一个item,在item的内部写上<selector>标签,那么这个RippleDrawable在按下的时候,同时具有水波效果和selector指定的图层。</p>
</blockquote>
<p>波纹<code>不超过</code>Selector的显示范围,实现内容如下,需要增加一个@android:id/mask配置,配置中的Selector就是波纹的背景,会与ripple颜色重叠显示。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><?xml version=<span class="string">"1.0"</span> encoding=<span class="string">"utf-8"</span>?></span></span><br><span class="line"><span class="tag"><<span class="name">ripple</span> <span class="attr">xmlns:android</span>=<span class="string">"http://schemas.android.com/apk/res/android"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">android:color</span>=<span class="string">"#FF0000"</span> ></span></span><br><span class="line"> <span class="tag"><<span class="name">item</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">selector</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">item</span></span></span><br><span class="line"><span class="tag"> <span class="attr">android:drawable</span>=<span class="string">"@drawable/icon_p"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">android:state_pressed</span>=<span class="string">"true"</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">item</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">item</span></span></span><br><span class="line"><span class="tag"> <span class="attr">android:drawable</span>=<span class="string">"@drawable/icon_n"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">android:state_pressed</span>=<span class="string">"false"</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">item</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">selector</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">item</span>></span></span><br><span class="line"><span class="tag"></<span class="name">ripple</span>></span></span><br></pre></td></tr></table></figure>
<p><img data-src="https://pic.liaoheng.me/hc-pic/2024/02/171202fd7e581ad3d0d53296332cedb9.gif"></p>
<h1 id="系统默认"><a href="#系统默认" class="headerlink" title="系统默认"></a>系统默认</h1><p>在控件中设置背景如下:</p>
<ul>
<li>有边界:<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">ImageView</span></span></span><br><span class="line"><span class="tag"> <span class="attr">android:background</span>=<span class="string">"?selectableItemBackground"</span></span></span><br><span class="line"><span class="tag"> /></span></span><br></pre></td></tr></table></figure></li>
<li>无边界:<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">ImageView</span></span></span><br><span class="line"><span class="tag"> <span class="attr">android:background</span>=<span class="string">"?selectableItemBackgroundBorderless"</span></span></span><br><span class="line"><span class="tag"> /></span></span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="selectableItemBackground"><a href="#selectableItemBackground" class="headerlink" title="selectableItemBackground"></a>selectableItemBackground</h2><p>文件位于:<br><code>/sdk/android/platforms/android-29/data/res/drawable/item_background_material.xml</code></p>
<p>文件内容如下:</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">ripple</span> <span class="attr">xmlns:android</span>=<span class="string">"http://schemas.android.com/apk/res/android"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">android:color</span>=<span class="string">"?attr/colorControlHighlight"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">item</span> <span class="attr">android:id</span>=<span class="string">"@id/mask"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">color</span> <span class="attr">android:color</span>=<span class="string">"@color/white"</span> /></span></span><br><span class="line"> <span class="tag"></<span class="name">item</span>></span></span><br><span class="line"><span class="tag"></<span class="name">ripple</span>></span></span><br></pre></td></tr></table></figure>
<p>文件中的mask参数,用来控制波纹动画的背景或者说是边界,这里波纹动画只会在mask中显示,也就达到动画不超过控件的目的。</p>
<h2 id="selectableItemBackgroundBorderless"><a href="#selectableItemBackgroundBorderless" class="headerlink" title="selectableItemBackgroundBorderless"></a>selectableItemBackgroundBorderless</h2><p>文件位于:<br><code>/sdk/android/platforms/android-29/data/res/drawable/item_background_borderless_material.xml</code><br>文件内容如下:</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">ripple</span> <span class="attr">xmlns:android</span>=<span class="string">"http://schemas.android.com/apk/res/android"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">android:color</span>=<span class="string">"?attr/colorControlHighlight"</span> /></span></span><br></pre></td></tr></table></figure>
<p>文件中的没有mask参数,波纹动画效果会超过控件的大小。</p>
<h2 id="colorControlHighlight-attr-x2F-colorControlHighlight"><a href="#colorControlHighlight-attr-x2F-colorControlHighlight" class="headerlink" title="colorControlHighlight(?attr/colorControlHighlight)"></a>colorControlHighlight(?attr/colorControlHighlight)</h2><p>文件位于:<br><code>/sdk/android/platforms/android-29/data/res/color/ripple_material_light.xml</code>这里的light与<code>Theme.AppCompat.Light</code>有关。<br>文件内容如下:</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">selector</span> <span class="attr">xmlns:android</span>=<span class="string">"http://schemas.android.com/apk/res/android"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">item</span> <span class="attr">android:alpha</span>=<span class="string">"@dimen/highlight_alpha_material_light"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">android:color</span>=<span class="string">"@color/foreground_material_light"</span> /></span></span><br><span class="line"><span class="tag"></<span class="name">selector</span>></span></span><br></pre></td></tr></table></figure>
<h1 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h1><p><a target="_blank" rel="noopener" href="https://stackoverflow.com/questions/64654113/where-can-i-found-definition-for-selectableitembackgroundborderless-reference-at">where-can-i-found-definition-for-selectableitembackgroundborderless-reference-at</a></p>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
<link itemprop="mainEntityOfPage" href="https://blog.liaoheng.me/2022/04/11/traditional-bluetooth-protocol-stack-simple/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.jpg">
<meta itemprop="name" content="liaoheng">
<meta itemprop="description" content="A developer">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="liaoheng`s blog">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2022/04/11/traditional-bluetooth-protocol-stack-simple/" class="post-title-link" itemprop="url">传统蓝牙协议栈初探</a>
</h2>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建时间:2022-04-11 17:05:36" itemprop="dateCreated datePublished" datetime="2022-04-11T17:05:36+08:00">2022-04-11</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar-check"></i>
</span>
<span class="post-meta-item-text">更新于</span>
<time title="修改时间:2024-02-21 10:32:28" itemprop="dateModified" datetime="2024-02-21T10:32:28+08:00">2024-02-21</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h1 id="概述"><a href="#概述" class="headerlink" title="概述"></a>概述</h1><p>此文主要是简单的探索一下蓝牙电话和蓝牙音乐相关协议栈,所以很多细节并未涉及。</p>
<p>一般而言,我们把某个协议的实现代码称为协议栈(protocol stack),要理解协议栈需要先了解蓝牙的核心系统架构,如下图:</p>
<p><img data-src="https://s1.ax1x.com/2022/04/11/LV6Ybd.png"></p>
<p>也可简单的<strong>抽象为3层</strong>:<img data-src="https://s1.ax1x.com/2022/04/11/LV6JDH.png"></p>
<ul>
<li>**User Application(Host)**:User Application即应用层,也被称为Host,我们调用Bluetooth API就属于应用层,例如,<a target="_blank" rel="noopener" href="https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html">BluetoothAdapter</a>中提供的接口。</li>
<li><strong>HCI (Host controller Interface)<strong>:上层在调用蓝牙API时,</strong>不会直接操作蓝牙底层</strong>(Controller)相关接口,而是<strong>通过HCI下发对应操作的Command给Controller</strong>,然后底层执行命令后返回执行结果,<strong>即Controller发送Event给HCI,HCI再通知给应用层</strong>,HCI起到了一个<strong>中间层</strong>的作用。</li>
<li><strong>Controller</strong>:Controller是在最底层,硬件驱动。</li>
</ul>
<p>按照上面的定义,HCI与Host层中的协议实现就是<strong>蓝牙协议栈</strong>。</p>
<h2 id="HCI"><a href="#HCI" class="headerlink" title="HCI"></a>HCI</h2><blockquote>
<p> BLUETOOTH SPECIFICATION Version 4.2 [Vol 2, Part E] page 400 </p>
<p> HCI(HOST CONTROLLER INTERFACE):主机控制层接口,主要负责透过transport把协议栈的数据发送给蓝牙芯片,并且接受来自蓝牙芯片的数据,数据主要分为HCI COMMAND(HOST->CONTROLLER),HCI EVENT(HOST<-CONTROLLER),HCI ACL(HOST<->CONTROLLER),HCI SCO(这个有点些微差异,因为部分芯片的SCO数据不是透过TRANSPORT直接跟HOST沟通,而是通过特殊的引脚,PCM IN/OUT/SYNC/CLK脚来传输数据)</p>
</blockquote>
<p>HOST层的几乎所有数据最后都会通过HCI,所以我们通过HCI的日志就可以了解蓝牙协议栈中每个协议,手机中可以通过开发者模式打开HCI日志开关,推荐使用<strong>wireshark</strong>或者<strong>Frontline ComProbe Protocol Analysis System</strong>来分析HCI日志,下面给出来的的日志都是<strong>wireshark</strong>的结果。</p>
<p>HCI日志由各种数据包组成,我们需要了解其中的两种数据包如下:</p>
<h3 id="Command-数据包"><a href="#Command-数据包" class="headerlink" title="Command 数据包"></a>Command 数据包</h3><p>HCI Command数据包格式如下,开头的<strong>Opcode是区分不同类型的命令的唯一标识</strong>,Opcode由<strong>OpCode Group Field (OGF)</strong> 和 **OpCode Command Field (OCF)**组成。根据OGF的值,可以将HCI commands进行分类。OpCode 的计算公式为:<code>OpCode = OGF << 6 + OCF</code> <strong>。有了OpCode计算的方式,我们就可以</strong>通过OpCode过滤HCI log里面的指定类型的HCI Command。</p>
<p><img data-src="https://s1.ax1x.com/2022/04/11/LV608f.png"></p>
<p>一次HCI Command指令发送完成,通常两条数据包,一条是host给controller的指令,一条是controller给host的指令反馈,可以确定指令发送是成功的。</p>
<h3 id="Event-数据包"><a href="#Event-数据包" class="headerlink" title="Event 数据包"></a>Event 数据包</h3><p>HCI Event 数据包由controller发送给Host,其中可以是蓝牙设备的消息也可以是连接的蓝牙设备的消息。</p>
<p><img data-src="https://s1.ax1x.com/2022/04/11/LV6B28.png"></p>
<h1 id="设备连接"><a href="#设备连接" class="headerlink" title="设备连接"></a>设备连接</h1><h2 id="蓝牙设备状态"><a href="#蓝牙设备状态" class="headerlink" title="蓝牙设备状态"></a>蓝牙设备状态</h2><blockquote>
<p>BLUETOOTH SPECIFICATION Version 4.2 [Vol 2, Part B] page 159 </p>
</blockquote>
<p>扫描设备然后与之建立连接是蓝牙工作流程的第一步,所以先要了解一下蓝牙的状态如下图:</p>
<p><img data-src="https://s1.ax1x.com/2022/04/11/LV6wPP.png"></p>
<p>从<u>蓝牙状态转换图</u>中可以看出 STANDBY状体是蓝牙设备的默认状态。</p>
<p><strong>Page</strong>:这个子状态就是我们通常称为的连接(寻呼),进行连接/激活对应的slave的操作我们就称为page。</p>
<p><strong>Page scan</strong>:这个子状态是和page对应的,它就是等待被page的slave所处的状态,换句话说,若想被page到,我们就要处于page scan的状态。</p>
<p><strong>inquiry</strong>:这就是我们通常所说的扫描状态,这个状态的设备就是去扫描周围的设备。</p>
<p><strong>inquiry scan</strong>:这就是我们通常看到的可被发现的设备。体现在上层就是我们在android系统中点击设备可被周围什么发现,那设备就处于这样的状态。</p>
<h2 id="逻辑链路传输协议"><a href="#逻辑链路传输协议" class="headerlink" title="逻辑链路传输协议"></a>逻辑链路传输协议</h2><h3 id="ACL"><a href="#ACL" class="headerlink" title="ACL"></a>ACL</h3><blockquote>
<p>BLUETOOTH SPECIFICATION Version 4.2 [Vol 1, Part A] page 63 </p>
<p>The asynchronous connection-oriented (ACL) logical transport is used to carry<br>LMP and L2CAP control signaling and best effort asynchronous user data. The<br>ACL logical transport uses a 1-bit ARQN/SEQN scheme to provide simple<br>channel reliability. Every active slave device within a piconet has one ACL<br>logical transport to the piconet master, known as the default ACL. </p>
</blockquote>
<p>ACL全称<strong>BR/EDR Asynchronous Connection-oriented</strong>,定向连接,它既支持对称连接,也支持不对称连接(既可以一对一,也可以一对多)。主设备负责控制链路带宽,并决定微微网中的每个从设备可以占用多少带宽和连接的对称性。从设备只有被选中时才能传送数据。ACL链路也支持接收主设备发给微微网中所有从设备的广播消息。</p>
<p>建立ACL需要设备HCI之间进行的下面的操作,这个也与<strong>蓝牙状态</strong>息息相关。</p>
<h4 id="开始扫描"><a href="#开始扫描" class="headerlink" title="开始扫描"></a>开始扫描</h4><ul>
<li><p><strong>Host</strong>:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">LocalBluetoothManager.getInstance().getBluetoothAdapter().startScanning(<span class="literal">true</span>);</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>Controller</strong>:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line">#发送扫描指令</span><br><span class="line">> 103 4.351128 host controller HCI_CMD 9 Sent Inquiry</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Command - Inquiry</span><br><span class="line"> Command Opcode: Inquiry (0x0401)</span><br><span class="line"> 0000 01.. .... .... = Opcode Group Field: Link Control Commands (0x01)</span><br><span class="line"> .... ..00 0000 0001 = Opcode Command Field: Inquiry (0x001)</span><br><span class="line"> Parameter Total Length: 5</span><br><span class="line"> LAP: 0x9e8b33</span><br><span class="line"> Inquiry Length: 10 (12.8 sec)</span><br><span class="line"> Num Responses: 0</span><br><span class="line"> [Pending in frame: 104]</span><br><span class="line"> [Command-Pending Delta: 0.846ms]</span><br><span class="line"> [Response in frame: 429]</span><br><span class="line"> [Command-Response Delta: 12811.07ms]</span><br><span class="line"></span><br><span class="line">#HCI反馈扫描指令状态</span><br><span class="line">> 104 4.351974 controller host HCI_EVT 7 Rcvd Command Status (Inquiry)</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Command Status</span><br><span class="line"> Event Code: Command Status (0x0f)</span><br><span class="line"> Parameter Total Length: 4</span><br><span class="line"> Status: Pending (0x00)</span><br><span class="line"> Number of Allowed Command Packets: 1</span><br><span class="line"> Command Opcode: Inquiry (0x0401)</span><br><span class="line"> [Command in frame: 103]</span><br><span class="line"> [Response in frame: 429]</span><br><span class="line"> [Command-Pending Delta: 0.846ms]</span><br><span class="line"> [Pending-Response Delta: 12810.224ms]</span><br><span class="line"></span><br><span class="line">#HCI发送的扫描到的设备信息</span><br><span class="line">> 114 4.505582 controller host HCI_EVT 258 Rcvd Extended Inquiry Result</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Extended Inquiry Result</span><br><span class="line"> Event Code: Extended Inquiry Result (0x2f)</span><br><span class="line"> Parameter Total Length: 255</span><br><span class="line"> Number of responses: 1</span><br><span class="line"> BD_ADDR: XiaomiCo_77:c2:35 (00:00:00:00:00:00)</span><br><span class="line"> Page Scan Repetition Mode: R1 (0x01)</span><br><span class="line"> Reserved: 0x02</span><br><span class="line"> Class of Device: 0x5a020c (Phone:Smartphone - services: Networking Capturing ObjectTransfer Telephony)</span><br><span class="line"> .000 0000 0011 0100 = Clock Offset: 0x0034</span><br><span class="line"> RSSI: -88 dBm</span><br><span class="line"> Extended Inquiry Response Data</span><br><span class="line"> Device Name: +My Phone1234567890123456789012</span><br><span class="line"> 16-bit Service Class UUIDs</span><br><span class="line"> 32-bit Service Class UUIDs</span><br><span class="line"> 128-bit Service Class UUIDs</span><br><span class="line"> Unused</span><br><span class="line"></span><br></pre></td></tr></table></figure></li>
</ul>
<h4 id="停止扫描"><a href="#停止扫描" class="headerlink" title="停止扫描"></a>停止扫描</h4><ul>
<li><p><strong>Host</strong>:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">LocalBluetoothManager.getInstance().getBluetoothAdapter().stopScanning();</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>Controller</strong>:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">> 85 2.202129 host controller HCI_CMD 4 Sent Inquiry Cancel</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Command - Inquiry Cancel</span><br><span class="line"> Command Opcode: Inquiry Cancel (0x0402)</span><br><span class="line"> 0000 01.. .... .... = Opcode Group Field: Link Control Commands (0x01)</span><br><span class="line"> .... ..00 0000 0010 = Opcode Command Field: Inquiry Cancel (0x002)</span><br><span class="line"> Parameter Total Length: 0</span><br><span class="line"> [Response in frame: 86]</span><br><span class="line"> [Command-Response Delta: 2.051ms]</span><br><span class="line"></span><br><span class="line">> 86 2.204180 controller host HCI_EVT 7 Rcvd Command Complete (Inquiry Cancel)</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Command Complete</span><br><span class="line"> Event Code: Command Complete (0x0e)</span><br><span class="line"> Parameter Total Length: 4</span><br><span class="line"> Number of Allowed Command Packets: 1</span><br><span class="line"> Command Opcode: Inquiry Cancel (0x0402)</span><br><span class="line"> Status: Success (0x00)</span><br><span class="line"> [Command in frame: 85]</span><br><span class="line"> [Command-Response Delta: 2.051ms]</span><br></pre></td></tr></table></figure></li>
</ul>
<h4 id="完成扫描"><a href="#完成扫描" class="headerlink" title="完成扫描"></a>完成扫描</h4><ul>
<li><p><strong>Host</strong>:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">LocalBluetoothManager.getInstance().getEventManager().registerCallback(<span class="keyword">new</span> <span class="title class_">BluetoothCallback</span>() {</span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onScanningStateChanged</span><span class="params">(<span class="type">boolean</span> started)</span> {</span><br><span class="line"> } </span><br><span class="line">});</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>Controller</strong>:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">> 429 17.162198 controller host HCI_EVT 4 Rcvd Inquiry Complete</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Inquiry Complete</span><br><span class="line"> Event Code: Inquiry Complete (0x01)</span><br><span class="line"> Parameter Total Length: 1</span><br><span class="line"> Status: Success (0x00)</span><br><span class="line"> [Command in frame: 103]</span><br><span class="line"> [Pending in frame: 104]</span><br><span class="line"> [Pending-Response Delta: 12810.224ms]</span><br><span class="line"> [Command-Response Delta: 12811.07ms]</span><br></pre></td></tr></table></figure></li>
</ul>
<h4 id="设备配对"><a href="#设备配对" class="headerlink" title="设备配对"></a>设备配对</h4><p><img data-src="https://s1.ax1x.com/2022/04/11/LV6GKe.png"></p>
<h5 id="配对"><a href="#配对" class="headerlink" title="配对"></a>配对</h5><ul>
<li><p><strong>Host</strong>:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">CachedBluetoothDevice.startPairing();</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>Controller</strong>:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br></pre></td><td class="code"><pre><span class="line">#删除需要连接设备本地记忆的Link Key</span><br><span class="line">> 685 33.812149 host controller HCI_CMD 11 Sent Delete Stored Link Key</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Command - Delete Stored Link Key</span><br><span class="line"> Command Opcode: Delete Stored Link Key (0x0c12)</span><br><span class="line"> 0000 11.. .... .... = Opcode Group Field: Host Controller & Baseband Commands (0x03)</span><br><span class="line"> .... ..00 0001 0010 = Opcode Command Field: Delete Stored Link Key (0x012)</span><br><span class="line"> Parameter Total Length: 7</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Delete All Flag: Delete only Link Key for specified BD_ADDR (0x00)</span><br><span class="line"> [Response in frame: 686]</span><br><span class="line"> [Command-Response Delta: 2.147ms]</span><br><span class="line"></span><br><span class="line">#建立ACL连接</span><br><span class="line">> 687 33.814531 host controller HCI_CMD 17 Sent Create Connection</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Command - Create Connection</span><br><span class="line"> Command Opcode: Create Connection (0x0405)</span><br><span class="line"> Parameter Total Length: 13</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Packet Type: 0xcc18, DH5, DM5, DH3, DM3, DH1, DM1</span><br><span class="line"> Page Scan Repetition Mode: R1 (0x01)</span><br><span class="line"> Page Scan Mode: Mandatory Page Scan Mode (0x00)</span><br><span class="line"> .000 0010 0000 1000 = Clock Offset: 0x0208 (650 msec)</span><br><span class="line"> 1... .... .... .... = Clock_Offset_Valid_Flag: true (1)</span><br><span class="line"> Allow Role Switch: Local device may be master, or may become slave after accepting a master slave switch. (0x01)</span><br><span class="line"> [Pending in frame: 688]</span><br><span class="line"> [Command-Pending Delta: 0.965ms]</span><br><span class="line"> [Response in frame: 690]</span><br><span class="line"> [Command-Response Delta: 1118.609ms]</span><br><span class="line"></span><br><span class="line">#建立ACL连接成功</span><br><span class="line">> 690 34.933140 controller host HCI_EVT 14 Rcvd Connect Complete</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Connect Complete</span><br><span class="line"> Event Code: Connect Complete (0x03)</span><br><span class="line"> Parameter Total Length: 11</span><br><span class="line"> Status: Success (0x00)</span><br><span class="line"> Connection Handle: 0x0033</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Link Type: ACL connection (Data Channels) (0x01)</span><br><span class="line"> Encryption Mode: Encryption Disabled (0x00)</span><br><span class="line"> [Command in frame: 687]</span><br><span class="line"> [Pending in frame: 688]</span><br><span class="line"> [Pending-Response Delta: 1117.644ms]</span><br><span class="line"> [Command-Response Delta: 1118.609ms]</span><br><span class="line"></span><br><span class="line">#改变当前设备的角色,这里当前设备为从(Slave),连接设备为主(Master)</span><br><span class="line">> 689 34.929964 controller host HCI_EVT 11 Rcvd Role Change</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Role Change</span><br><span class="line"> Event Code: Role Change (0x12)</span><br><span class="line"> Parameter Total Length: 8</span><br><span class="line"> Status: Success (0x00)</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Role: Currently the Slave for specified BD_ADDR (0x01)</span><br><span class="line"></span><br><span class="line">#与设备建立连接之后,准备开始验证</span><br><span class="line">> 697 34.935615 host controller HCI_CMD 6 Sent Authentication Requested</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Command - Authentication Requested</span><br><span class="line"> Command Opcode: Authentication Requested (0x0411)</span><br><span class="line"> Parameter Total Length: 2</span><br><span class="line"> Connection Handle: 0x0033</span><br><span class="line"> [Pending in frame: 699]</span><br><span class="line"> [Command-Pending Delta: 0.917ms]</span><br><span class="line"> [Response in frame: 743]</span><br><span class="line"> [Command-Response Delta: 4291.694ms]</span><br><span class="line"></span><br><span class="line">#连接设备询问Link Key</span><br><span class="line">> 701 34.936976 controller host HCI_EVT 9 Rcvd Link Key Request</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Link Key Request</span><br><span class="line"> Event Code: Link Key Request (0x17)</span><br><span class="line"> Parameter Total Length: 6</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"></span><br><span class="line">#当前设备无Link Key,也就是未于连接设备配对过</span><br><span class="line">> 705 34.938603 host controller HCI_CMD 10 Sent Link Key Request Negative Reply</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Command - Link Key Request Negative Reply</span><br><span class="line"> Command Opcode: Link Key Request Negative Reply (0x040c)</span><br><span class="line"> 0000 01.. .... .... = Opcode Group Field: Link Control Commands (0x01)</span><br><span class="line"> .... ..00 0000 1100 = Opcode Command Field: Link Key Request Negative Reply (0x00c)</span><br><span class="line"> Parameter Total Length: 6</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> [Response in frame: 706]</span><br><span class="line"> [Command-Response Delta: 0.87ms]</span><br><span class="line"></span><br><span class="line">#使用的配对方式是`简单安全配对`SSP(Simple Secure Pairng), 就是直接弹配对码</span><br><span class="line"></span><br><span class="line">#连接设备询问当前设备的IO能力</span><br><span class="line">> 707 34.939729 controller host HCI_EVT 9 Rcvd IO Capability Request</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - IO Capability Request</span><br><span class="line"> Event Code: IO Capability Request (0x31)</span><br><span class="line"> Parameter Total Length: 6</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"></span><br><span class="line">#回复当前设备的IO能力</span><br><span class="line">>708 34.939897 host controller HCI_CMD 13 Sent IO Capability Request Reply</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Command - IO Capability Request Reply</span><br><span class="line"> Command Opcode: IO Capability Request Reply (0x042b)</span><br><span class="line"> 0000 01.. .... .... = Opcode Group Field: Link Control Commands (0x01)</span><br><span class="line"> .... ..00 0010 1011 = Opcode Command Field: IO Capability Request Reply (0x02b)</span><br><span class="line"> Parameter Total Length: 9</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> IO Capability: Display Yes/No (1)</span><br><span class="line"> OOB Data Present: OOB Authentication Data Not Present (0)</span><br><span class="line"> Authentication Requirements: MITM Protection Required - Dedicated Bonding. Use IO Capability To Determine Procedure, No Secure Connection (3)</span><br><span class="line"> [Response in frame: 709]</span><br><span class="line"> [Command-Response Delta: 0.811ms]</span><br><span class="line"></span><br><span class="line">######其它参数同步</span><br><span class="line"></span><br><span class="line">#连接设备的IO能力,io能力参数为Display Yes/No (0x01),需要用户确认</span><br><span class="line">> 737 36.532369 controller host HCI_EVT 12 Rcvd IO Capability Response</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - IO Capability Response</span><br><span class="line"> Event Code: IO Capability Response (0x32)</span><br><span class="line"> Parameter Total Length: 9</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> IO Capability: Display Yes/No (0x01)</span><br><span class="line"> OOB Data Present: OOB Authentication Data Not Present (0)</span><br><span class="line"> Authentication Requirements: MITM Protection Required - Dedicated Bonding. Use IO Capability To Determine Procedure, No Secure Connection (3)</span><br><span class="line"></span><br><span class="line">#当前设备接收到配对码信息,Numeric Value就是显示的配对码</span><br><span class="line">> 738 37.066181 controller host HCI_EVT 13 Rcvd User Confirmation Request</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - User Confirmation Request</span><br><span class="line"> Event Code: User Confirmation Request (0x33)</span><br><span class="line"> Parameter Total Length: 10</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Numeric Value: 446514</span><br><span class="line"></span><br><span class="line">#回复连接设备已接收到配对码信息</span><br><span class="line">> 739 37.096306 host controller HCI_CMD 10 Sent User Confirmation Request Reply</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Command - User Confirmation Request Reply</span><br><span class="line"> Command Opcode: User Confirmation Request Reply (0x042c)</span><br><span class="line"> 0000 01.. .... .... = Opcode Group Field: Link Control Commands (0x01)</span><br><span class="line"> .... ..00 0010 1100 = Opcode Command Field: User Confirmation Request Reply (0x02c)</span><br><span class="line"> Parameter Total Length: 6</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> [Response in frame: 740]</span><br><span class="line"> [Command-Response Delta: 1.46ms]</span><br><span class="line"></span><br><span class="line">#连接设备SSP验证成功</span><br><span class="line">> 741 39.215747 controller host HCI_EVT 10 Rcvd Simple Pairing Complete</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Simple Pairing Complete</span><br><span class="line"> Event Code: Simple Pairing Complete (0x36)</span><br><span class="line"> Parameter Total Length: 7</span><br><span class="line"> Status: Success (0x00)</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"></span><br><span class="line">#连接设备的Link Key,需要保存,用于下次连接</span><br><span class="line">> 742 39.226970 controller host HCI_EVT 26 Rcvd Link Key Notification</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Link Key Notification</span><br><span class="line"> Event Code: Link Key Notification (0x18)</span><br><span class="line"> Parameter Total Length: 23</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Link Key: bc31fb070e91eec2f2296fbf9bc8b518</span><br><span class="line"> Key Type: Unknown (0x08)</span><br><span class="line"></span><br><span class="line">#验证完成</span><br><span class="line">> 743 39.227309 controller host HCI_EVT 6 Rcvd Authentication Complete</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Authentication Complete</span><br><span class="line"> Event Code: Authentication Complete (0x06)</span><br><span class="line"> Parameter Total Length: 3</span><br><span class="line"> Status: Success (0x00)</span><br><span class="line"> Connection Handle: 0x0033</span><br><span class="line"> [Command in frame: 697]</span><br><span class="line"> [Pending in frame: 699]</span><br><span class="line"> [Pending-Response Delta: 4290.777ms]</span><br><span class="line"> [Command-Response Delta: 4291.694ms]</span><br></pre></td></tr></table></figure></li>
</ul>
<h5 id="被配对"><a href="#被配对" class="headerlink" title="被配对"></a>被配对</h5><ul>
<li><p><strong>Host</strong>:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">LocalBluetoothManager.getInstance().getEventManager().registerCallback(<span class="keyword">new</span> <span class="title class_">BluetoothCallback</span>() {</span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onDeviceBondStateChanged</span><span class="params">(CachedBluetoothDevice cachedDevice, <span class="type">int</span> bondState)</span> {</span><br><span class="line"> }</span><br><span class="line">});</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>Controller</strong>:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br></pre></td><td class="code"><pre><span class="line">#请求ACL连接</span><br><span class="line">> 326 21.946869 controller host HCI_EVT 13 Rcvd Connect Request</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Connect Request</span><br><span class="line"> Event Code: Connect Request (0x04)</span><br><span class="line"> Parameter Total Length: 10</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Class of Device: 0x5a020c (Phone:Smartphone - services: Networking Capturing ObjectTransfer Telephony)</span><br><span class="line"> Link Type: ACL connection (Data Channels) (0x01)</span><br><span class="line"></span><br><span class="line">#允许ACL连接</span><br><span class="line">> 327 21.947178 host controller HCI_CMD 11 Sent Accept Connection Request</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Command - Accept Connection Request</span><br><span class="line"> Command Opcode: Accept Connection Request (0x0409)</span><br><span class="line"> Parameter Total Length: 7</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Role: Remain the Slave for this connection. The LM will NOT perform the role switch. (0x01)</span><br><span class="line"> [Pending in frame: 328]</span><br><span class="line"> [Command-Pending Delta: 0.685ms]</span><br><span class="line"> [Response in frame: 329]</span><br><span class="line"> [Command-Response Delta: 4.432ms]</span><br><span class="line"></span><br><span class="line">#ACL连接成功</span><br><span class="line">> 329 21.951610 controller host HCI_EVT 14 Rcvd Connect Complete</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Connect Complete</span><br><span class="line"> Event Code: Connect Complete (0x03)</span><br><span class="line"> Parameter Total Length: 11</span><br><span class="line"> Status: Success (0x00)</span><br><span class="line"> Connection Handle: 0x0033</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Link Type: ACL connection (Data Channels) (0x01)</span><br><span class="line"> Encryption Mode: Encryption Disabled (0x00)</span><br><span class="line"> [Command in frame: 327]</span><br><span class="line"> [Pending in frame: 328]</span><br><span class="line"> [Pending-Response Delta: 3.747ms]</span><br><span class="line"> [Command-Response Delta: 4.432ms]</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">> 370 22.259461 controller host HCI_EVT 12 Rcvd IO Capability Response</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - IO Capability Response</span><br><span class="line"> Event Code: IO Capability Response (0x32)</span><br><span class="line"> Parameter Total Length: 9</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> IO Capability: Display Yes/No (0x01)</span><br><span class="line"> OOB Data Present: OOB Authentication Data Not Present (0)</span><br><span class="line"> Authentication Requirements: MITM Protection Required - Dedicated Bonding. Use IO Capability To Determine Procedure, No Secure Connection (3)</span><br><span class="line"></span><br><span class="line">> 371 22.259809 controller host HCI_EVT 9 Rcvd IO Capability Request</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - IO Capability Request</span><br><span class="line"> Event Code: IO Capability Request (0x31)</span><br><span class="line"> Parameter Total Length: 6</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"></span><br><span class="line">> 372 22.259982 host controller HCI_CMD 13 Sent IO Capability Request Reply</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Command - IO Capability Request Reply</span><br><span class="line"> Command Opcode: IO Capability Request Reply (0x042b)</span><br><span class="line"> Parameter Total Length: 9</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> IO Capability: Display Yes/No (1)</span><br><span class="line"> OOB Data Present: OOB Authentication Data Not Present (0)</span><br><span class="line"> Authentication Requirements: MITM Protection Required - Dedicated Bonding. Use IO Capability To Determine Procedure, No Secure Connection (3)</span><br><span class="line"> [Response in frame: 373]</span><br><span class="line"> [Command-Response Delta: 0.619ms]</span><br><span class="line"></span><br><span class="line">> 374 22.958223 controller host HCI_EVT 13 Rcvd User Confirmation Request</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - User Confirmation Request</span><br><span class="line"> Event Code: User Confirmation Request (0x33)</span><br><span class="line"> Parameter Total Length: 10</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Numeric Value: 804568</span><br><span class="line"></span><br><span class="line">> 375 23.069385 host controller HCI_CMD 10 Sent User Confirmation Request Reply</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Command - User Confirmation Request Reply</span><br><span class="line"> Command Opcode: User Confirmation Request Reply (0x042c)</span><br><span class="line"> Parameter Total Length: 6</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> [Response in frame: 376]</span><br><span class="line"> [Command-Response Delta: 1.81ms]</span><br><span class="line"></span><br><span class="line">#连接设备SSP验证成功</span><br><span class="line">> 377 26.919540 controller host HCI_EVT 10 Rcvd Simple Pairing Complete</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Simple Pairing Complete</span><br><span class="line"> Event Code: Simple Pairing Complete (0x36)</span><br><span class="line"> Parameter Total Length: 7</span><br><span class="line"> Status: Success (0x00)</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"></span><br><span class="line">#连接设备的Link Key,需要保存,用于下次连接</span><br><span class="line">> 378 26.926691 controller host HCI_EVT 26 Rcvd Link Key Notification</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Link Key Notification</span><br><span class="line"> Event Code: Link Key Notification (0x18)</span><br><span class="line"> Parameter Total Length: 23</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Link Key: 2160acf6b7403a97050f64de72570b1d</span><br><span class="line"> Key Type: Unknown (0x08)</span><br></pre></td></tr></table></figure></li>
</ul>
<h4 id="设备连接-1"><a href="#设备连接-1" class="headerlink" title="设备连接"></a>设备连接</h4><p><img data-src="https://s1.ax1x.com/2022/04/11/LV63vD.png"></p>
<h5 id="连接"><a href="#连接" class="headerlink" title="连接"></a>连接</h5><ul>
<li><p><strong>Host</strong>:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">CachedBluetoothDevice.conntect(<span class="literal">true</span>);</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>Controller</strong>:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br></pre></td><td class="code"><pre><span class="line">> 1214 47.023224 host controller HCI_CMD 17 Sent Create Connection</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Command - Create Connection</span><br><span class="line"> Command Opcode: Create Connection (0x0405)</span><br><span class="line"> Parameter Total Length: 13</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Packet Type: 0xcc18, DH5, DM5, DH3, DM3, DH1, DM1</span><br><span class="line"> Page Scan Repetition Mode: R1 (0x01)</span><br><span class="line"> Page Scan Mode: Mandatory Page Scan Mode (0x00)</span><br><span class="line"> .011 1001 0100 0100 = Clock Offset: 0x3944 (18325 msec)</span><br><span class="line"> 1... .... .... .... = Clock_Offset_Valid_Flag: true (1)</span><br><span class="line"> Allow Role Switch: Local device may be master, or may become slave after accepting a master slave switch. (0x01)</span><br><span class="line"> [Pending in frame: 1215]</span><br><span class="line"> [Command-Pending Delta: 1.458ms]</span><br><span class="line"> [Response in frame: 1217]</span><br><span class="line"> [Command-Response Delta: 1630.81ms]</span><br><span class="line"></span><br><span class="line">> 1216 48.646874 controller host HCI_EVT 11 Rcvd Role Change</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Role Change</span><br><span class="line"> Event Code: Role Change (0x12)</span><br><span class="line"> Parameter Total Length: 8</span><br><span class="line"> Status: Success (0x00)</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Role: Currently the Slave for specified BD_ADDR (0x01)</span><br><span class="line"></span><br><span class="line">> 1217 48.654034 controller host HCI_EVT 14 Rcvd Connect Complete</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Connect Complete</span><br><span class="line"> Event Code: Connect Complete (0x03)</span><br><span class="line"> Parameter Total Length: 11</span><br><span class="line"> Status: Success (0x00)</span><br><span class="line"> Connection Handle: 0x0033</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Link Type: ACL connection (Data Channels) (0x01)</span><br><span class="line"> Encryption Mode: Encryption Disabled (0x00)</span><br><span class="line"> [Command in frame: 1214]</span><br><span class="line"> [Pending in frame: 1215]</span><br><span class="line"> [Pending-Response Delta: 1629.352ms]</span><br><span class="line"> [Command-Response Delta: 1630.81ms]</span><br><span class="line"></span><br><span class="line">> 1278 48.812485 host controller HCI_CMD 6 Sent Authentication Requested</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Command - Authentication Requested</span><br><span class="line"> Command Opcode: Authentication Requested (0x0411)</span><br><span class="line"> Parameter Total Length: 2</span><br><span class="line"> Connection Handle: 0x0033</span><br><span class="line"> [Pending in frame: 1279]</span><br><span class="line"> [Command-Pending Delta: 0.945ms]</span><br><span class="line"> [Response in frame: 1283]</span><br><span class="line"> [Command-Response Delta: 16.693ms]</span><br><span class="line"></span><br><span class="line">> 1280 48.813892 controller host HCI_EVT 9 Rcvd Link Key Request</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Link Key Request</span><br><span class="line"> Event Code: Link Key Request (0x17)</span><br><span class="line"> Parameter Total Length: 6</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"></span><br><span class="line">> 1281 48.814039 host controller HCI_CMD 26 Sent Link Key Request Reply</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Command - Link Key Request Reply</span><br><span class="line"> Command Opcode: Link Key Request Reply (0x040b)</span><br><span class="line"> Parameter Total Length: 22</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Link Key: 2160acf6b7403a97050f64de72570b1d</span><br><span class="line"> [Response in frame: 1282]</span><br><span class="line"> [Command-Response Delta: 1.336ms]</span><br><span class="line"></span><br><span class="line">> 1282 48.815375 controller host HCI_EVT 13 Rcvd Command Complete (Link Key Request Reply)</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Command Complete</span><br><span class="line"> Event Code: Command Complete (0x0e)</span><br><span class="line"> Parameter Total Length: 10</span><br><span class="line"> Number of Allowed Command Packets: 1</span><br><span class="line"> Command Opcode: Link Key Request Reply (0x040b)</span><br><span class="line"> Status: Success (0x00)</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> [Command in frame: 1281]</span><br><span class="line"> [Command-Response Delta: 1.336ms]</span><br><span class="line"></span><br><span class="line">> 1283 48.829178 controller host HCI_EVT 6 Rcvd Authentication Complete</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Authentication Complete</span><br><span class="line"> Event Code: Authentication Complete (0x06)</span><br><span class="line"> Parameter Total Length: 3</span><br><span class="line"> Status: Success (0x00)</span><br><span class="line"> Connection Handle: 0x0033</span><br><span class="line"> [Command in frame: 1278]</span><br><span class="line"> [Pending in frame: 1279]</span><br><span class="line"> [Pending-Response Delta: 15.748ms]</span><br><span class="line"> [Command-Response Delta: 16.693ms]</span><br><span class="line"></span><br></pre></td></tr></table></figure></li>
</ul>
<h5 id="被连接"><a href="#被连接" class="headerlink" title="被连接"></a>被连接</h5><ul>
<li><p><strong>Host</strong>:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">LocalBluetoothManager.getInstance().getEventManager().registerCallback(<span class="keyword">new</span> <span class="title class_">BluetoothCallback</span>() {</span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onConnectionStateChanged</span><span class="params">(CachedBluetoothDevice cachedDevice, <span class="type">int</span> bondState)</span> {</span><br><span class="line"> }</span><br><span class="line">});</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>Controller</strong>:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line">> 1900 62.151696 controller host HCI_EVT 13 Rcvd Connect Request</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Connect Request</span><br><span class="line"> Event Code: Connect Request (0x04)</span><br><span class="line"> Parameter Total Length: 10</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Class of Device: 0x5a020c (Phone:Smartphone - services: Networking Capturing ObjectTransfer Telephony)</span><br><span class="line"> Link Type: ACL connection (Data Channels) (0x01)</span><br><span class="line"></span><br><span class="line">> 1901 62.152042 host controller HCI_CMD 11 Sent Accept Connection Request</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Command - Accept Connection Request</span><br><span class="line"> Command Opcode: Accept Connection Request (0x0409)</span><br><span class="line"> Parameter Total Length: 7</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Role: Remain the Slave for this connection. The LM will NOT perform the role switch. (0x01)</span><br><span class="line"> [Pending in frame: 1902]</span><br><span class="line"> [Command-Pending Delta: 0.748ms]</span><br><span class="line"> [Response in frame: 1903]</span><br><span class="line"> [Command-Response Delta: 4.455ms]</span><br><span class="line"></span><br><span class="line">> 1903 62.156497 controller host HCI_EVT 14 Rcvd Connect Complete</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Connect Complete</span><br><span class="line"> Event Code: Connect Complete (0x03)</span><br><span class="line"> Parameter Total Length: 11</span><br><span class="line"> Status: Success (0x00)</span><br><span class="line"> Connection Handle: 0x0032</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Link Type: ACL connection (Data Channels) (0x01)</span><br><span class="line"> Encryption Mode: Encryption Disabled (0x00)</span><br><span class="line"> [Command in frame: 1901]</span><br><span class="line"> [Pending in frame: 1902]</span><br><span class="line"> [Pending-Response Delta: 3.707ms]</span><br><span class="line"> [Command-Response Delta: 4.455ms]</span><br><span class="line"></span><br><span class="line">> 1968 62.415419 controller host HCI_EVT 9 Rcvd Link Key Request</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Link Key Request</span><br><span class="line"> Event Code: Link Key Request (0x17)</span><br><span class="line"> Parameter Total Length: 6</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"></span><br><span class="line">> 1969 62.415629 host controller HCI_CMD 26 Sent Link Key Request Reply</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Command - Link Key Request Reply</span><br><span class="line"> Command Opcode: Link Key Request Reply (0x040b)</span><br><span class="line"> Parameter Total Length: 22</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Link Key: 2160acf6b7403a97050f64de72570b1d</span><br><span class="line"> [Response in frame: 1971]</span><br><span class="line"> [Command-Response Delta: 0.934ms]</span><br><span class="line"></span><br><span class="line">> 1971 62.416563 controller host HCI_EVT 13 Rcvd Command Complete (Link Key Request Reply)</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Command Complete</span><br><span class="line"> Event Code: Command Complete (0x0e)</span><br><span class="line"> Parameter Total Length: 10</span><br><span class="line"> Number of Allowed Command Packets: 1</span><br><span class="line"> Command Opcode: Link Key Request Reply (0x040b)</span><br><span class="line"> Status: Success (0x00)</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> [Command in frame: 1969]</span><br><span class="line"> [Command-Response Delta: 0.934ms]</span><br><span class="line"></span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="SCO"><a href="#SCO" class="headerlink" title="SCO"></a>SCO</h3><blockquote>
<p>BLUETOOTH SPECIFICATION Version 4.2 [Vol 1, Part A] page 64 </p>
<p>The synchronous connection-oriented (SCO) logical transport is a symmetric,<br>point-to-point transport between the master and a specific slave. The SCO<br>logical transport reserves slots on the physical channel and can therefore be<br>considered as a circuit-switched connection between the master and the slave.<br>SCO logical transports carry 64 kb/s of information synchronized with the<br>piconet clock. Typically this information is an encoded voice stream. Three<br>different SCO configurations exist, offering a balance between robustness,<br>delay and bandwidth consumption. </p>
</blockquote>
<p>SCO全称<strong>BR/EDR Synchronous Connection-Oriented</strong>,利用保留时隙传送数据包。连接建立后,主设备和从设备可以不被选中就发送SCO数据包。SCO数据包既可以传送话音,也可以传送数据,但在传送数据时,只用于重发被损坏的那部分的数据。</p>
<h3 id="L2CAP"><a href="#L2CAP" class="headerlink" title="L2CAP"></a>L2CAP</h3><blockquote>
<p>BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part A] page 30 </p>
<p>L2CAP(Logical Link Control and Adaptation Protocol):逻辑链路控制与适配协议,将ACL数据分组交换为便于高层应用的数据分组格式,并提供协议复用和服务质量交换等功能。</p>
<p>通过协议多路复用、分段重组操作和组概念,向高层提供面向连接的和无连接的数据服务,L2CAP还屏蔽了低层传输协议中的很多特性,使得高层协议应用开发人员可以不必了解基层协议而进行开发。</p>
</blockquote>
<p><img data-src="https://s1.ax1x.com/2022/04/11/LV6sKg.png"></p>
<p>从架构图可以看出,L2CAP位于HCI与上层业务之间,在建立物理连接(ACL)之后,上层业务的通信和控制都由L2CAP协议与微微网(piconet )中其它蓝牙设备进行交互,类似HTTP协议的存在。</p>
<p>下图概括了两个设备L2CAP之间的连接过程:</p>
<p><img data-src="https://s1.ax1x.com/2022/04/11/LV6UUI.png"></p>
<h3 id="SDP"><a href="#SDP" class="headerlink" title="SDP"></a>SDP</h3><blockquote>
<p>BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part B] page 222 </p>
<p>The service discovery mechanism provides the means for client applications to<br>discover the existence of services provided by server applications as well as<br>the attributes of those services. The attributes of a service include the type or<br>class of service offered and the mechanism or protocol information needed to<br>utilize the service. </p>
</blockquote>
<p>全称是<strong>Service Discovery Protocol</strong>,服务发现协议,服务发现协议(SDP)为应用程序提供了一种方法来发现哪些服务可用,并确定这些可用服务的特征。</p>
<p><img data-src="https://s1.ax1x.com/2022/04/11/LV66bj.png"></p>
<p>从上图可知蓝牙设备中同时存在一个Client和Server,通过L2CAP协议与别的设备时行交互,通过<code>Service Search Attribute Request </code>命令查询对方设备支持的蓝牙服务,其工作流程如图:</p>
<p><img data-src="https://s1.ax1x.com/2022/04/11/LV6a5t.png"></p>
<p>通过HCI可以看到发现蓝牙服务过过程中的数据:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><span class="line">> 455 22.824346 localhost () XiaomiCo_6e:38:c5 (PHONE) SDP 29 Sent Service Search Attribute Request : L2CAP: Attribute Range (0x0000 - 0xffff) </span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Frame 455: 29 bytes on wire (232 bits), 29 bytes captured (232 bits)</span><br><span class="line">Bluetooth</span><br><span class="line">Bluetooth HCI H4</span><br><span class="line">Bluetooth HCI ACL Packet</span><br><span class="line">Bluetooth L2CAP Protocol</span><br><span class="line">Bluetooth SDP Protocol</span><br><span class="line"> PDU: Service Search Attribute Request (0x06)</span><br><span class="line"> Transaction Id: 0x0000</span><br><span class="line"> Parameter Length: 15</span><br><span class="line"> Service Search Pattern: L2CAP</span><br><span class="line"> Maximum Attribute Byte Count: 1008</span><br><span class="line"> Attribute ID List</span><br><span class="line"> Data Element: Sequence uint8 5 bytes</span><br><span class="line"> 0011 0... = Data Element Type: Sequence (6)</span><br><span class="line"> .... .101 = Data Element Size: uint8 (5)</span><br><span class="line"> Data Element Var Size: 5</span><br><span class="line"> Data Value</span><br><span class="line"> Data Element: Unsigned Integer 4 bytes</span><br><span class="line"> 0000 1... = Data Element Type: Unsigned Integer (1)</span><br><span class="line"> .... .010 = Data Element Size: 4 bytes (2)</span><br><span class="line"> Data Value</span><br><span class="line"> Attribute Range: 0x0000ffff</span><br><span class="line"> Attribute Range From: 0x0000</span><br><span class="line"> Attribute Range To: 0xffff</span><br><span class="line"> Continuation State: no (00)</span><br><span class="line"></span><br><span class="line">> 471 22.896191 XiaomiCo_6e:38:c5 (PHONE) localhost () SDP 281 Rcvd Service Search Attribute Response</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Frame 471: 281 bytes on wire (2248 bits), 281 bytes captured (2248 bits)</span><br><span class="line">Bluetooth</span><br><span class="line">Bluetooth HCI H4</span><br><span class="line">Bluetooth HCI ACL Packet</span><br><span class="line">Bluetooth L2CAP Protocol</span><br><span class="line">Bluetooth SDP Protocol</span><br><span class="line"> PDU: Service Search Attribute Response (0x07)</span><br><span class="line"> Transaction Id: 0x0001</span><br><span class="line"> Parameter Length: 267</span><br><span class="line"> Attribute List Byte Count: 264</span><br><span class="line"> Data Fragment</span><br><span class="line"> Continuation State: no (00)</span><br><span class="line"> [Reassembled Attribute List]</span><br><span class="line"> Attribute Lists [count = 14]</span><br><span class="line"> Data Element: Sequence uint16 1269 bytes</span><br><span class="line"> 0011 0... = Data Element Type: Sequence (6)</span><br><span class="line"> .... .110 = Data Element Size: uint16 (6)</span><br><span class="line"> Data Element Var Size: 1269</span><br><span class="line"> Data Value</span><br><span class="line"> Attribute List [count = 4] (Generic Attribute Profile)</span><br><span class="line"> Attribute List [count = 4] (Generic Access Profile)</span><br><span class="line"> Attribute List [count = 6] (Headset Audio Gateway)</span><br><span class="line"> Attribute List [count = 8] (Handsfree Audio Gateway)</span><br><span class="line"> Attribute List [count = 8] (A/V Remote Control Target)</span><br><span class="line"> Attribute List [count = 7] (Audio Source)</span><br><span class="line"> Attribute List [count = 11] (PAN NAP)</span><br><span class="line"> Attribute List [count = 9] (PAN PANU)</span><br><span class="line"> Attribute List [count = 7] (Phonebook Access Server)</span><br><span class="line"> Attribute List [count = 10] (Message Access Server)</span><br><span class="line"> Attribute List [count = 4] (Xiaomi Inc.)</span><br><span class="line"> Attribute List [count = 5] (CustomUUID: Unknown)</span><br><span class="line"> Attribute List [count = 8] (OBEX Object Push)</span><br><span class="line"> Attribute List [count = 4] (Unknown)</span><br></pre></td></tr></table></figure>
<h1 id="蓝牙电话"><a href="#蓝牙电话" class="headerlink" title="蓝牙电话"></a>蓝牙电话</h1><h2 id="PBAP-RFCOMM-x2F-OBEX"><a href="#PBAP-RFCOMM-x2F-OBEX" class="headerlink" title="PBAP(RFCOMM/OBEX)"></a>PBAP(RFCOMM/OBEX)</h2><blockquote>
<p>RFCOMM协议提供了对L2CAP协议上的串行端口的模拟。该协议基于ETSI标准GSM 07.10。</p>
<p>OBEX:Object Exchange的简称,对象交换协议,来源于红外通讯协议,但又不局限于具体的传输方式,后来被蓝牙组织SIG吸纳其中部分并进行优化处理作为蓝牙协议中的OBEX层用于蓝牙设备间的文件数据传输,如蓝牙传输文件(OPP)、同步电话簿(PBAP)和同步短信(MAP)等场景下都是以OBEX协议组织相关数据进行传输的。</p>
</blockquote>
<p>PBAP: Phone Book Access Profile的简称,<strong>电话本访问协议</strong>,用于同步手机这些具有电话本功能设备上的通讯录和通话记录等。</p>
<p>RFCOMM/OBEX和协议不属于蓝牙定义的规范 ,只是被蓝牙采纳,而PBAP协议包在OBEX协议之上封装而成。</p>
<h3 id="PBAP虚拟文件夹架构"><a href="#PBAP虚拟文件夹架构" class="headerlink" title="PBAP虚拟文件夹架构"></a>PBAP虚拟文件夹架构</h3><p>PBAP中通话数据文件是在虚拟文件夹架构下,访问通话数据时需要指定路径,下图为官方架构图:</p>
<p><img data-src="https://s1.ax1x.com/2022/04/11/LV6yrQ.png"></p>
<p>其中vcf的文件名称意义如下:</p>
<p><img data-src="https://s1.ax1x.com/2022/04/11/LV6gVs.png"></p>
<h3 id="建立连接-x2F-断开连接"><a href="#建立连接-x2F-断开连接" class="headerlink" title="建立连接/断开连接"></a>建立连接/断开连接</h3><p>只使用OBEX协议</p>
<h4 id="连接-1"><a href="#连接-1" class="headerlink" title="连接"></a>连接</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line">> 798 23.907353 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 40 Sent Connect - Phone Book Access Profile</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Frame 798: 40 bytes on wire (320 bits), 40 bytes captured (320 bits)</span><br><span class="line">Bluetooth</span><br><span class="line">Bluetooth HCI H4</span><br><span class="line">Bluetooth HCI ACL Packet</span><br><span class="line">Bluetooth L2CAP Protocol</span><br><span class="line">Bluetooth RFCOMM Protocol</span><br><span class="line">OBEX Protocol</span><br><span class="line"> [Profile: PBAP (4)]</span><br><span class="line"> [Current Path: ?]</span><br><span class="line"> .000 0000 = Opcode: Connect (0x00)</span><br><span class="line"> 1... .... = Final Flag: True</span><br><span class="line"> Packet Length: 26</span><br><span class="line"> [Response in Frame: 803]</span><br><span class="line"> Version: 1.0 (0x10)</span><br><span class="line"> Flags: 0x00</span><br><span class="line"> Max. Packet Length: 65534</span><br><span class="line"> Headers</span><br><span class="line"> Target: Phone Book Access Profile</span><br><span class="line"> Header Id: Target (0x46)</span><br><span class="line"> Length: 19</span><br><span class="line"> Value: 796135f0f0c511d809660800200c9a66: Phone Book Access Profile</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">> 803 23.917550 XiaomiCo_6e:38:c5 (PHONE) localhost () OBEX 45 Rcvd Success - Phone Book Access Profile</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Frame 803: 45 bytes on wire (360 bits), 45 bytes captured (360 bits)</span><br><span class="line">Bluetooth</span><br><span class="line">Bluetooth HCI H4</span><br><span class="line">Bluetooth HCI ACL Packet</span><br><span class="line">Bluetooth L2CAP Protocol</span><br><span class="line">Bluetooth RFCOMM Protocol</span><br><span class="line">OBEX Protocol</span><br><span class="line"> [Profile: PBAP (4)]</span><br><span class="line"> [Current Path: /]</span><br><span class="line"> .010 0000 = Response Code: Success (0x20)</span><br><span class="line"> 1... .... = Final Flag: True</span><br><span class="line"> Packet Length: 31</span><br><span class="line"> [Request in Frame: 798]</span><br><span class="line"> Version: 1.0 (0x10)</span><br><span class="line"> Flags: 0x00</span><br><span class="line"> Max. Packet Length: 65534</span><br><span class="line"> Headers</span><br><span class="line"> Connection Id: 1</span><br><span class="line"> Header Id: Connection Id (0xcb)</span><br><span class="line"> Connection ID: 1</span><br><span class="line"> Who: Phone Book Access Profile</span><br><span class="line"> Header Id: Who (0x4a)</span><br><span class="line"> Length: 19</span><br><span class="line"> Value: 796135f0f0c511d809660800200c9a66: Phone Book Access Profile</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="断开"><a href="#断开" class="headerlink" title="断开"></a>断开</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">> 1142 58.752933 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 22 Sent Disconnect</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">OBEX Protocol</span><br><span class="line"> [Profile: PBAP (4)]</span><br><span class="line"> [Current Path: /]</span><br><span class="line"> .000 0001 = Opcode: Disconnect (0x01)</span><br><span class="line"> 1... .... = Final Flag: True</span><br><span class="line"> Packet Length: 8</span><br><span class="line"> [Response in Frame: 1164]</span><br><span class="line"> Headers</span><br><span class="line"> Connection Id: 1</span><br><span class="line"> Header Id: Connection Id (0xcb)</span><br><span class="line"> Connection ID: 1</span><br><span class="line"></span><br><span class="line">> 1164 59.162598 XiaomiCo_6e:38:c5 (PHONE) localhost () OBEX 22 Rcvd Success</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">OBEX Protocol</span><br><span class="line"> [Profile: PBAP (4)]</span><br><span class="line"> [Current Path: /]</span><br><span class="line"> .010 0000 = Response Code: Success (0x20)</span><br><span class="line"> 1... .... = Final Flag: True</span><br><span class="line"> Packet Length: 8</span><br><span class="line"> [Request in Frame: 1142]</span><br><span class="line"> Headers</span><br><span class="line"> Connection Id: 1</span><br><span class="line"> Header Id: Connection Id (0xcb)</span><br><span class="line"> Connection ID: 1</span><br></pre></td></tr></table></figure>
<h3 id="设置访问虚拟文件夹路径"><a href="#设置访问虚拟文件夹路径" class="headerlink" title="设置访问虚拟文件夹路径"></a>设置访问虚拟文件夹路径</h3><p>在[PBAP协议规范]的<code>5.2 SetPhoneBook Function</code>章节,使用OBEX协议SetPath命令,通过obex.opcode=<strong>0x05</strong>判断。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"># $/</span><br><span class="line">> 808 24.023528 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 27 Sent Set Path ""</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">OBEX Protocol</span><br><span class="line"> [Profile: PBAP (4)]</span><br><span class="line"> [Current Path: /]</span><br><span class="line"> .000 0101 = Opcode: Set Path (0x05)</span><br><span class="line"> 1... .... = Final Flag: True</span><br><span class="line"> Packet Length: 13</span><br><span class="line"> [Response in Frame: 810]</span><br><span class="line"> Flags: 0x02</span><br><span class="line"> .... ...0 = Go back one folder (../) first: False</span><br><span class="line"> .... ..1. = Do not create folder, if not existing: True</span><br><span class="line"> Constants: 0x00</span><br><span class="line"> Headers</span><br><span class="line"> Connection Id: 1</span><br><span class="line"> Header Id: Connection Id (0xcb)</span><br><span class="line"> Connection ID: 1</span><br><span class="line"> Name: ""</span><br><span class="line"> Header Id: Name (0x01)</span><br><span class="line"> Length: 3</span><br><span class="line"> Name: </span><br><span class="line"></span><br><span class="line">> 810 24.065127 XiaomiCo_6e:38:c5 (PHONE) localhost () OBEX 22 Rcvd Success</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">OBEX Protocol</span><br><span class="line"> [Profile: PBAP (4)]</span><br><span class="line"> [Current Path: /]</span><br><span class="line"> .010 0000 = Response Code: Success (0x20)</span><br><span class="line"> 1... .... = Final Flag: True</span><br><span class="line"> Packet Length: 8</span><br><span class="line"> [Request in Frame: 808]</span><br><span class="line"> Headers</span><br><span class="line"> Connection Id: 1</span><br><span class="line"> Header Id: Connection Id (0xcb)</span><br><span class="line"> Connection ID: 1</span><br><span class="line"></span><br><span class="line"># $/telecom/</span><br><span class="line">> 811 24.078180 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 43 Sent Set Path "telecom"</span><br></pre></td></tr></table></figure>
<h3 id="获取通讯录数量"><a href="#获取通讯录数量" class="headerlink" title="获取通讯录数量"></a>获取通讯录数量</h3><p>在[PBAP协议规范]的<code>5.3 PullvCardListing Function</code>章节,通过obex.header=**<x-bt/vcard-listing>**判断。</p>
<h4 id="手机"><a href="#手机" class="headerlink" title="手机"></a>手机</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br></pre></td><td class="code"><pre><span class="line">> 808 24.023528 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 27 Sent Set Path ""</span><br><span class="line">> 811 24.078180 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 43 Sent Set Path "telecom"</span><br><span class="line"># $/telecom/pb/</span><br><span class="line">> 816 24.118267 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 70 Sent Get final "pb"</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">OBEX Protocol</span><br><span class="line"> [Profile: PBAP (4)]</span><br><span class="line"> [Current Path: /telecom]</span><br><span class="line"> .000 0011 = Opcode: Get (0x03)</span><br><span class="line"> 1... .... = Final Flag: True</span><br><span class="line"> Packet Length: 56</span><br><span class="line"> [Response in Frame: 818]</span><br><span class="line"> Headers</span><br><span class="line"> Connection Id: 1</span><br><span class="line"> Header Id: Connection Id (0xcb)</span><br><span class="line"> Connection ID: 1</span><br><span class="line"> Name: "pb"</span><br><span class="line"> Header Id: Name (0x01)</span><br><span class="line"> Length: 9</span><br><span class="line"> Name: pb</span><br><span class="line"> Type: "x-bt/vcard-listing"</span><br><span class="line"> Header Id: Type (0x42)</span><br><span class="line"> Length: 22</span><br><span class="line"> Type: x-bt/vcard-listing</span><br><span class="line"> Application Parameters</span><br><span class="line"> Header Id: Application Parameters (0x4c)</span><br><span class="line"> Length: 17</span><br><span class="line"> Parameter: Order #排序规则: { Alphabetical | Indexed | Phonetical }</span><br><span class="line"> Parameter Id: Order (0x01)</span><br><span class="line"> Parameter Length: 1</span><br><span class="line"> Max List Count: Indexed (0x00)</span><br><span class="line"> Parameter: Search Attribute #搜索: {Name | Number | Sound } 与 SearchValue配合,默认为Name</span><br><span class="line"> Parameter Id: Search Attribute (0x03)</span><br><span class="line"> Parameter Length: 1</span><br><span class="line"> Search Attribute: Name (0x00)</span><br><span class="line"> Parameter: Max List Count #最大条目数</span><br><span class="line"> Parameter Id: Max List Count (0x04)</span><br><span class="line"> Parameter Length: 2</span><br><span class="line"> Max List Count: 0 (0x0000)</span><br><span class="line"> Parameter: List Start Offset #偏移量</span><br><span class="line"> Parameter Id: List Start Offset (0x05)</span><br><span class="line"> Parameter Length: 2</span><br><span class="line"> List Start Offset: 0 (0x0000)</span><br><span class="line"></span><br><span class="line">> 818 24.332995 XiaomiCo_6e:38:c5 (PHONE) localhost () OBEX 29 Rcvd Success</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">OBEX Protocol</span><br><span class="line"> [Profile: PBAP (4)]</span><br><span class="line"> [Current Path: /telecom]</span><br><span class="line"> .010 0000 = Response Code: Success (0x20)</span><br><span class="line"> 1... .... = Final Flag: True</span><br><span class="line"> Packet Length: 15</span><br><span class="line"> [Request in Frame: 816]</span><br><span class="line"> Headers</span><br><span class="line"> Connection Id: 1</span><br><span class="line"> Header Id: Connection Id (0xcb)</span><br><span class="line"> Connection ID: 1</span><br><span class="line"> Application Parameters</span><br><span class="line"> Header Id: Application Parameters (0x4c)</span><br><span class="line"> Length: 7</span><br><span class="line"> Parameter: Phonebook Size</span><br><span class="line"> Parameter Id: Phonebook Size (0x08)</span><br><span class="line"> Parameter Length: 2</span><br><span class="line"> Phonebook Size: 71 (0x0047)</span><br></pre></td></tr></table></figure>
<h4 id="SIM1"><a href="#SIM1" class="headerlink" title="SIM1"></a>SIM1</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">> 819 24.336294 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 27 Sent Set Path ""</span><br><span class="line">> 822 24.379640 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 27 Sent Set Path ""</span><br><span class="line">> 825 24.430836 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 37 Sent Set Path "SIM1"</span><br><span class="line">> 828 24.481559 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 43 Sent Set Path "telecom"</span><br><span class="line"># $/SIM1/telecom/pb/</span><br><span class="line">> 831 24.532312 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 70 Sent Get final "pb"</span><br><span class="line"></span><br><span class="line">> 833 24.578831 XiaomiCo_6e:38:c5 (PHONE) localhost () OBEX 29 Rcvd Success</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">OBEX Protocol</span><br><span class="line"> [Profile: PBAP (4)]</span><br><span class="line"> [Current Path: /SIM1/telecom]</span><br><span class="line"> .010 0000 = Response Code: Success (0x20)</span><br><span class="line"> 1... .... = Final Flag: True</span><br><span class="line"> Packet Length: 15</span><br><span class="line"> [Request in Frame: 831]</span><br><span class="line"> Headers</span><br><span class="line"> Connection Id: 1</span><br><span class="line"> Header Id: Connection Id (0xcb)</span><br><span class="line"> Connection ID: 1</span><br><span class="line"> Application Parameters</span><br><span class="line"> Header Id: Application Parameters (0x4c)</span><br><span class="line"> Length: 7</span><br><span class="line"> Parameter: Phonebook Size</span><br><span class="line"> Parameter Id: Phonebook Size (0x08)</span><br><span class="line"> Parameter Length: 2</span><br><span class="line"> Phonebook Size: 1 (0x0001)</span><br></pre></td></tr></table></figure>
<h3 id="获取通讯录"><a href="#获取通讯录" class="headerlink" title="获取通讯录"></a>获取通讯录</h3><p>在[PBAP协议规范]的<code>5.3 PullvCardListing Function</code>章节,通过obex.header=<strong><x-bt/phonebook></strong> 判断,分页获取vCard格式。</p>
<h4 id="手机-1"><a href="#手机-1" class="headerlink" title="手机"></a>手机</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br></pre></td><td class="code"><pre><span class="line">> 834 24.580643 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 27 Sent Set Path ""</span><br><span class="line">#分页请求获取通讯录,从第1条数据开始,每页最多50条</span><br><span class="line">> 837 24.632264 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 97 Sent Get final "telecom/pb.vcf"</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">OBEX Protocol</span><br><span class="line"> [Profile: PBAP (4)]</span><br><span class="line"> [Current Path: /]</span><br><span class="line"> .000 0011 = Opcode: Get (0x03)</span><br><span class="line"> 1... .... = Final Flag: True</span><br><span class="line"> Packet Length: 83</span><br><span class="line"> [Response in Frame: 844]</span><br><span class="line"> Headers</span><br><span class="line"> Connection Id: 1</span><br><span class="line"> Header Id: Connection Id (0xcb)</span><br><span class="line"> Connection ID: 1</span><br><span class="line"> Name: "telecom/pb.vcf"</span><br><span class="line"> Header Id: Name (0x01)</span><br><span class="line"> Length: 33</span><br><span class="line"> Name: telecom/pb.vcf</span><br><span class="line"> Type: "x-bt/phonebook"</span><br><span class="line"> Header Id: Type (0x42)</span><br><span class="line"> Length: 18</span><br><span class="line"> Type: x-bt/phonebook</span><br><span class="line"> Application Parameters</span><br><span class="line"> Header Id: Application Parameters (0x4c)</span><br><span class="line"> Length: 24</span><br><span class="line"> Parameter: Max List Count #最大条目数,这里只读取50条</span><br><span class="line"> Parameter Id: Max List Count (0x04)</span><br><span class="line"> Parameter Length: 2</span><br><span class="line"> Max List Count: 50 (0x0032)</span><br><span class="line"> Parameter: List Start Offset #偏移量,这是从第1条开始读取</span><br><span class="line"> Parameter Id: List Start Offset (0x05)</span><br><span class="line"> Parameter Length: 2</span><br><span class="line"> List Start Offset: 1 (0x0001)</span><br><span class="line"> Parameter: Filter #用于指示所请求的vCard中包含的属性</span><br><span class="line"> Parameter Id: Filter (0x06)</span><br><span class="line"> Parameter Length: 8</span><br><span class="line"> Filter: 0x00000000</span><br><span class="line"> Filter: 0x008001af, vCard Version, Formatted Name, Structured Presentation of Name, Associated Image or Photo, Delivery Address, Telephone Number, Electronic Mail Address, Nickname</span><br><span class="line"> Parameter: Format #vCard文件格式版本,这是3.0</span><br><span class="line"> Parameter Id: Format (0x07)</span><br><span class="line"> Parameter Length: 1</span><br><span class="line"> Format: 3.0 (0x01)</span><br><span class="line"></span><br><span class="line">#传输数据片段</span><br><span class="line">> 839 24.764415 XiaomiCo_6e:38:c5 (PHONE) localhost () OBEX 1004 Rcvd OBEX fragment</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Frame 839: 1004 bytes on wire (8032 bits), 1004 bytes captured (8032 bits)</span><br><span class="line">Bluetooth</span><br><span class="line">Bluetooth HCI H4</span><br><span class="line">Bluetooth HCI ACL Packet</span><br><span class="line">Bluetooth L2CAP Protocol</span><br><span class="line">Bluetooth RFCOMM Protocol</span><br><span class="line">OBEX Protocol</span><br><span class="line"> [Profile: PBAP (4)]</span><br><span class="line"> [Current Path: /]</span><br><span class="line"> [Reassembled OBEX in frame: 844]</span><br><span class="line"> Data (990 bytes)</span><br><span class="line"></span><br><span class="line">...</span><br><span class="line">#传输成功</span><br><span class="line">> 844 24.794969 XiaomiCo_6e:38:c5 (PHONE) localhost () OBEX 182 Rcvd Success (x-bt/phonebook)</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">OBEX Protocol</span><br><span class="line"> [Profile: PBAP (4)]</span><br><span class="line"> [Current Path: /]</span><br><span class="line"> [6 OBEX Fragments (5117 bytes): #839(990), #840(990), #841(990), #842(990), #843(990), #844(167)] #6个数据片段,需要拼接对应Frame</span><br><span class="line"> .010 0000 = Response Code: Success (0x20)</span><br><span class="line"> 1... .... = Final Flag: True</span><br><span class="line"> Packet Length: 5117</span><br><span class="line"> [Request in Frame: 837]</span><br><span class="line"> Headers</span><br><span class="line"> Connection Id: 1</span><br><span class="line"> Header Id: Connection Id (0xcb)</span><br><span class="line"> Connection ID: 1</span><br><span class="line"> End Of Body</span><br><span class="line"> Header Id: End Of Body (0x49)</span><br><span class="line"> Length: 5109</span><br><span class="line"> Value: 424547494e3a56434152440d0a56455253494f4e3a332e300d0a4e3ae591a83be4baa6e6…</span><br><span class="line"> Line-based text data: x-bt/phonebook (320 lines)</span><br><span class="line"> BEGIN:VCARD\r\n</span><br><span class="line"> VERSION:3.0\r\n</span><br><span class="line"> N:张;三;;;\r\n</span><br><span class="line"> FN:张三\r\n</span><br><span class="line"> TEL;TYPE=CELL:22222222\r\n</span><br><span class="line"> END:VCARD\r\n</span><br><span class="line"> BEGIN:VCARD\r\n</span><br><span class="line"> VERSION:3.0\r\n</span><br><span class="line"> N:李四;;;;\r\n</span><br><span class="line"> FN:李四\r\n</span><br><span class="line"> TEL;TYPE=CELL:11111111\r\n</span><br><span class="line"> END:VCARD\r\n</span><br><span class="line"></span><br><span class="line">#请求获取vCard 3.0格式,并从第51条数据开始,最多50条</span><br><span class="line">> 847 24.875858 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 96 Sent Get final "telecom/pb.vcf"</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">OBEX Protocol</span><br><span class="line"> [Profile: PBAP (4)]</span><br><span class="line"> [Current Path: /]</span><br><span class="line"> .000 0011 = Opcode: Get (0x03)</span><br><span class="line"> 1... .... = Final Flag: True</span><br><span class="line"> Packet Length: 83</span><br><span class="line"> [Response in Frame: 850]</span><br><span class="line"> Headers</span><br><span class="line"> Connection Id: 1</span><br><span class="line"> Header Id: Connection Id (0xcb)</span><br><span class="line"> Connection ID: 1</span><br><span class="line"> Name: "telecom/pb.vcf"</span><br><span class="line"> Header Id: Name (0x01)</span><br><span class="line"> Length: 33</span><br><span class="line"> Name: telecom/pb.vcf</span><br><span class="line"> Type: "x-bt/phonebook"</span><br><span class="line"> Header Id: Type (0x42)</span><br><span class="line"> Length: 18</span><br><span class="line"> Type: x-bt/phonebook</span><br><span class="line"> Application Parameters</span><br><span class="line"> Header Id: Application Parameters (0x4c)</span><br><span class="line"> Length: 24</span><br><span class="line"> Parameter: Max List Count</span><br><span class="line"> Parameter Id: Max List Count (0x04)</span><br><span class="line"> Parameter Length: 2</span><br><span class="line"> Max List Count: 50 (0x0032)</span><br><span class="line"> Parameter: List Start Offset</span><br><span class="line"> Parameter Id: List Start Offset (0x05)</span><br><span class="line"> Parameter Length: 2</span><br><span class="line"> List Start Offset: 51 (0x0033)</span><br><span class="line"> Parameter: Filter</span><br><span class="line"> Parameter Id: Filter (0x06)</span><br><span class="line"> Parameter Length: 8</span><br><span class="line"> Filter: 0x00000000</span><br><span class="line"> Filter: 0x008001af, vCard Version, Formatted Name, Structured Presentation of Name, Associated Image or Photo, Delivery Address, Telephone Number, Electronic Mail Address, Nickname</span><br><span class="line"> Parameter: Format</span><br><span class="line"> Parameter Id: Format (0x07)</span><br><span class="line"> Parameter Length: 1</span><br><span class="line"> Format: 3.0 (0x01)</span><br><span class="line"></span><br><span class="line">> 849 24.953425 XiaomiCo_6e:38:c5 (PHONE) localhost () OBEX 1004 Rcvd OBEX fragment</span><br><span class="line"></span><br><span class="line"># 刚刚通过`Sent Get final "pb"`获取手机通讯录只有71条,现在只剩下21,这次就可以传输完成。</span><br><span class="line">> 850 24.960363 XiaomiCo_6e:38:c5 (PHONE) localhost () OBEX 940 Rcvd Success (x-bt/phonebook)</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">OBEX Protocol</span><br><span class="line"> [Profile: PBAP (4)]</span><br><span class="line"> [Current Path: /]</span><br><span class="line"> [2 OBEX Fragments (1915 bytes): #849(990), #850(925)]</span><br><span class="line"> .010 0000 = Response Code: Success (0x20)</span><br><span class="line"> 1... .... = Final Flag: True</span><br><span class="line"> Packet Length: 1915</span><br><span class="line"> [Request in Frame: 847]</span><br><span class="line"> Headers</span><br><span class="line"> Connection Id: 1</span><br><span class="line"> Header Id: Connection Id (0xcb)</span><br><span class="line"> Connection ID: 1</span><br><span class="line"> End Of Body</span><br><span class="line"> Header Id: End Of Body (0x49)</span><br><span class="line"> Length: 1907</span><br><span class="line"> Value: 424547494e3a56434152440d0a56455253494f4e3a332e300d0a4e3ae4bd993be4bf8ae7…</span><br><span class="line"> Line-based text data: x-bt/phonebook (122 lines)</span><br><span class="line"> BEGIN:VCARD\r\n</span><br><span class="line"> VERSION:3.0\r\n</span><br><span class="line"> N:张;三;;;\r\n</span><br><span class="line"> FN:张三\r\n</span><br><span class="line"> TEL;TYPE=CELL:22222222\r\n</span><br><span class="line"> END:VCARD\r\n</span><br><span class="line"> BEGIN:VCARD\r\n</span><br><span class="line"> VERSION:3.0\r\n</span><br><span class="line"> N:李四;;;;\r\n</span><br><span class="line"> FN:李四\r\n</span><br><span class="line"> TEL;TYPE=CELL:11111111\r\n</span><br><span class="line"> END:VCARD\r\n</span><br></pre></td></tr></table></figure>
<h4 id="SIM1-1"><a href="#SIM1-1" class="headerlink" title="SIM1"></a>SIM1</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">> 866 25.021131 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 107 Sent Get final "SIM1/telecom/pb.vcf"</span><br><span class="line">#这里手机直接拒绝了</span><br><span class="line">> 868 25.032728 XiaomiCo_6e:38:c5 (PHONE) localhost () OBEX 25 Rcvd Success</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">OBEX Protocol</span><br><span class="line"> [Profile: PBAP (4)]</span><br><span class="line"> [Current Path: /]</span><br><span class="line"> .010 0000 = Response Code: Success (0x20)</span><br><span class="line"> 1... .... = Final Flag: True</span><br><span class="line"> Packet Length: 11</span><br><span class="line"> [Request in Frame: 866]</span><br><span class="line"> Headers</span><br><span class="line"> Connection Id: 1</span><br><span class="line"> Header Id: Connection Id (0xcb)</span><br><span class="line"> Connection ID: 1</span><br><span class="line"> End Of Body</span><br><span class="line"> Header Id: End Of Body (0x49)</span><br><span class="line"> Length: 3</span><br><span class="line"> Value: <MISSING></span><br></pre></td></tr></table></figure>
<h3 id="获取通话记录"><a href="#获取通话记录" class="headerlink" title="获取通话记录"></a>获取通话记录</h3><p>在[PBAP协议规范]的<code>5.3 PullvCardListing Function</code>章节,通过obex.header=<strong><x-bt/phonebook></strong> 判断,分页获取vCard格式。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br></pre></td><td class="code"><pre><span class="line">> 869 25.071027 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 27 Sent Set Path ""</span><br><span class="line">> 882 25.125323 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 43 Sent Set Path "telecom"</span><br><span class="line"># $/telecom/cch/</span><br><span class="line">> 887 25.138796 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 72 Sent Get final "cch"</span><br><span class="line">> 895 25.222650 XiaomiCo_6e:38:c5 (PHONE) localhost () OBEX 29 Rcvd Success</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">OBEX Protocol</span><br><span class="line"> [Profile: PBAP (4)]</span><br><span class="line"> [Current Path: /telecom]</span><br><span class="line"> .010 0000 = Response Code: Success (0x20)</span><br><span class="line"> 1... .... = Final Flag: True</span><br><span class="line"> Packet Length: 15</span><br><span class="line"> [Request in Frame: 887]</span><br><span class="line"> Headers</span><br><span class="line"> Connection Id: 1</span><br><span class="line"> Header Id: Connection Id (0xcb)</span><br><span class="line"> Connection ID: 1</span><br><span class="line"> Application Parameters</span><br><span class="line"> Header Id: Application Parameters (0x4c)</span><br><span class="line"> Length: 7</span><br><span class="line"> Parameter: Phonebook Size</span><br><span class="line"> Parameter Id: Phonebook Size (0x08)</span><br><span class="line"> Parameter Length: 2</span><br><span class="line"> Phonebook Size: 2177 (0x0881)</span><br><span class="line"></span><br><span class="line">> 897 25.225643 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 27 Sent Set Path ""</span><br><span class="line">#分页获取通话记录,从第0条开始,每页最多50条</span><br><span class="line">> 919 25.279427 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 85 Sent Get final "telecom/cch.vcf"</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">OBEX Protocol</span><br><span class="line"> [Profile: PBAP (4)]</span><br><span class="line"> [Current Path: /]</span><br><span class="line"> .000 0011 = Opcode: Get (0x03)</span><br><span class="line"> 1... .... = Final Flag: True</span><br><span class="line"> Packet Length: 71</span><br><span class="line"> [Response in Frame: 935]</span><br><span class="line"> Headers</span><br><span class="line"> Connection Id: 1</span><br><span class="line"> Header Id: Connection Id (0xcb)</span><br><span class="line"> Connection ID: 1</span><br><span class="line"> Name: "telecom/cch.vcf"</span><br><span class="line"> Header Id: Name (0x01)</span><br><span class="line"> Length: 35</span><br><span class="line"> Name: telecom/cch.vcf</span><br><span class="line"> Type: "x-bt/phonebook"</span><br><span class="line"> Header Id: Type (0x42)</span><br><span class="line"> Length: 18</span><br><span class="line"> Type: x-bt/phonebook</span><br><span class="line"> Application Parameters</span><br><span class="line"> Header Id: Application Parameters (0x4c)</span><br><span class="line"> Length: 10</span><br><span class="line"> Parameter: Max List Count</span><br><span class="line"> Parameter Id: Max List Count (0x04)</span><br><span class="line"> Parameter Length: 2</span><br><span class="line"> Max List Count: 50 (0x0032)</span><br><span class="line"> Parameter: Format</span><br><span class="line"> Parameter Id: Format (0x07)</span><br><span class="line"> Parameter Length: 1</span><br><span class="line"> Format: 3.0 (0x01)</span><br><span class="line">> 935 25.381127 XiaomiCo_6e:38:c5 (PHONE) localhost () OBEX 132 Rcvd Success (x-bt/phonebook)</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">OBEX Protocol</span><br><span class="line"> [Profile: PBAP (4)]</span><br><span class="line"> [Current Path: /]</span><br><span class="line"> [8 OBEX Fragments (7048 bytes): #926(990), #927(990), #928(990), #929(990), #930(990), #931(990), #934(990), #935(118)]</span><br><span class="line"> .010 0000 = Response Code: Success (0x20)</span><br><span class="line"> 1... .... = Final Flag: True</span><br><span class="line"> Packet Length: 7048</span><br><span class="line"> [Request in Frame: 919]</span><br><span class="line"> Headers</span><br><span class="line"> Connection Id: 1</span><br><span class="line"> Header Id: Connection Id (0xcb)</span><br><span class="line"> Connection ID: 1</span><br><span class="line"> End Of Body</span><br><span class="line"> Header Id: End Of Body (0x49)</span><br><span class="line"> Length: 7040</span><br><span class="line"> Value: 424547494e3a56434152440d0a56455253494f4e3a332e300d0a464e3a0d0a4e3a0d0a54…</span><br><span class="line"> Line-based text data: x-bt/phonebook (350 lines)</span><br><span class="line"> BEGIN:VCARD\r\n</span><br><span class="line"> VERSION:3.0\r\n</span><br><span class="line"> FN:\r\n</span><br><span class="line"> N:\r\n</span><br><span class="line"> TEL;TYPE=0:10086\r\n</span><br><span class="line"> X-IRMC-CALL-DATETIME;TYPE=DIALED:20220317T161710\r\n</span><br><span class="line"> END:VCARD\r\n</span><br><span class="line"> BEGIN:VCARD\r\n</span><br><span class="line"> VERSION:3.0\r\n</span><br><span class="line"> FN:\r\n</span><br><span class="line"> N:\r\n</span><br><span class="line"> TEL;TYPE=0:02310050\r\n</span><br><span class="line"> X-IRMC-CALL-DATETIME;TYPE=MISSED:20220316T160142\r\n</span><br><span class="line"> END:VCARD\r\n</span><br><span class="line"></span><br><span class="line">#分页获取通话记录,从第50条开始,每页最多50条</span><br><span class="line">936 25.423573 localhost () XiaomiCo_6e:38:c5 (PHONE) OBEX 89 Sent Get final "telecom/cch.vcf"</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">OBEX Protocol</span><br><span class="line"> [Profile: PBAP (4)]</span><br><span class="line"> [Current Path: /]</span><br><span class="line"> .000 0011 = Opcode: Get (0x03)</span><br><span class="line"> 1... .... = Final Flag: True</span><br><span class="line"> Packet Length: 75</span><br><span class="line"> [Response in Frame: 947]</span><br><span class="line"> Headers</span><br><span class="line"> Connection Id: 1</span><br><span class="line"> Header Id: Connection Id (0xcb)</span><br><span class="line"> Connection ID: 1</span><br><span class="line"> Name: "telecom/cch.vcf"</span><br><span class="line"> Header Id: Name (0x01)</span><br><span class="line"> Length: 35</span><br><span class="line"> Name: telecom/cch.vcf</span><br><span class="line"> Type: "x-bt/phonebook"</span><br><span class="line"> Header Id: Type (0x42)</span><br><span class="line"> Length: 18</span><br><span class="line"> Type: x-bt/phonebook</span><br><span class="line"> Application Parameters</span><br><span class="line"> Header Id: Application Parameters (0x4c)</span><br><span class="line"> Length: 14</span><br><span class="line"> Parameter: Max List Count</span><br><span class="line"> Parameter Id: Max List Count (0x04)</span><br><span class="line"> Parameter Length: 2</span><br><span class="line"> Max List Count: 50 (0x0032)</span><br><span class="line"> Parameter: List Start Offset</span><br><span class="line"> Parameter Id: List Start Offset (0x05)</span><br><span class="line"> Parameter Length: 2</span><br><span class="line"> List Start Offset: 50 (0x0032)</span><br><span class="line"> Parameter: Format</span><br><span class="line"> Parameter Id: Format (0x07)</span><br><span class="line"> Parameter Length: 1</span><br><span class="line"> Format: 3.0 (0x01)</span><br><span class="line">> 947 25.516478 XiaomiCo_6e:38:c5 (PHONE) localhost () OBEX 810 Rcvd Success (x-bt/phonebook)</span><br></pre></td></tr></table></figure>
<h2 id="HFP-RFCOMM"><a href="#HFP-RFCOMM" class="headerlink" title="HFP(RFCOMM)"></a>HFP(RFCOMM)</h2><blockquote>
<p>HFP(Hands-free Profile),让蓝牙设备可以控制电话,如接听、挂断、拒接、语音拨号等,拒接、语音拨号要视蓝牙耳机及电话是否支持。</p>
<p>目前HFP的使用场景有车载蓝牙,耳机和PDA,定义了AG和HFP两种角色。<br>AG(Audio Gate)音频网关—音频设备输入输出网关<br>HF(Hands Free)免提—该设备作为音频网关的远程音频输入/输出机制,并可提供若干遥控功能。</p>
</blockquote>
<p>在车载蓝牙中,<strong>手机侧是AG</strong>,<strong>车载蓝牙侧是HF</strong>,在android源代码中,将AG侧称为HFP/AG,将HF侧称为HFPClient/HF。</p>
<h3 id="AT命令"><a href="#AT命令" class="headerlink" title="AT命令"></a>AT命令</h3><p>在HFP使用AT命令控制电话,其参考3GPP 27.007标准,命令规范为:</p>
<ul>
<li><p>每个命令行只有一个命令</p>
</li>
<li><p>AG侧默认不回显命令</p>
</li>
<li><p>AG使用冗长的格式返回结果</p>
</li>
<li><p>以下字符将被用于AT命令和返回结果格式中</p>
<ul>
<li><p><code><cr></code> 表示回车,也就是<code>\r</code>字符</p>
</li>
<li><p><code> <lf></code>表示换行,也就是<code>\n</code>字符</p>
</li>
</ul>
</li>
<li><p>从HF发送到AG的命令格式是:<code><AT command> <cr></code></p>
</li>
<li><p>从AG返回给HF的OK命令格式是:<code><cr><lf>OK<cr><lf></code></p>
</li>
<li><p>从AG到HF的ERROR命令是:<code><cr><lf>ERROR<cr><lf></code></p>
</li>
<li><p>从AG到HF的结果命令格式是:<code><cr><lf><result code><cr><lf></code></p>
</li>
</ul>
<p>HFP协议复用的AT命令:</p>
<ul>
<li><p>ATA:标准电话应答AT命令</p>
</li>
<li><p>ATDdd…dd;:用电话号码打电话</p>
</li>
<li><p>ATD>nnn…;:ATD扩展命令,记忆拨号</p>
</li>
<li><p>ERROR:错误指示符,语法,格式或者通信过程出错。</p>
</li>
<li><p>OK:命令的成功应答。</p>
</li>
<li><p>NO CARRIER, BUSY, NO ANSWER, DELAYED, BLACKLISTED:AT扩展命令,AG返回给HF。</p>
</li>
<li><p>RING:来电</p>
</li>
<li><p>AT+CCWA:calling waiting notification AT命令。AT+CCWA=<code>[<n>[,<mode>[,<class>]]]</code>,</p>
</li>
<li><p>+CCWA:Call Waiting notification返回结果码。只有<code><number></code>和<code><type></code>参数对HFP有意义,<code><number></code>是由双引号及其中的文本串组成。<code><type></code>是支持的电话格式,有如下值:</p>
<ul>
<li><p>128~143:国家或国际格式,</p>
</li>
<li><p>144~159:国际电话,包括国家码前缀。</p>
</li>
<li><p>160-175:国家码</p>
</li>
<li><p>AT+CHLD:通话保持,多方处理。AT+CHLD=<code><n></code>中<code><n></code>值覆盖0, 1, 1<code><idx></code>, 2, 2<code><idx></code>, 3 and 4,说明:</p>
<ul>
<li>0:释放所有保持电话或者设置用户的忙等待</li>
<li>1:释放正在通话的电话,接听保持或等待的电话</li>
<li>1<code><idx></code>:释放<code><idx></code>标识的电话</li>
<li>2:将所有活跃电话设置成保持并且接受其它电话。</li>
<li>2<code><idx></code>:请求接受<code><idx></code>标识电话,让其它电话保持。</li>
<li>3:增加一个保持电话到对话中</li>
<li>4:连接连个电话并且断开两个电话的订阅。HF侧可选。</li>
</ul>
</li>
<li><p>AT+CHLD=?:查询AG侧保持和多方会话。</p>
</li>
</ul>
</li>
<li><p>AT+CHUP:标准的挂断命令。AG会结束通话,也可用于拒接来电。</p>
</li>
<li><p>AT+CIND:<code>AT+CIND?</code>获取AG indicators当前的状态,`AT+CIND=?获取AG支持的indicator以及它们的次序。</p>
<ul>
<li>service: Service availability indication:<ul>
<li><code><value>=0</code> implies no service. No Home/Roam network available.</li>
<li><code><value>=1</code> implies presence of service. Home/Roam network available.</li>
</ul>
</li>
<li>call: Standard call status indicator: <ul>
<li><code><value>=0 </code>means there are no calls in progress </li>
<li><code><value>=1</code> means at least one call is in progress</li>
</ul>
</li>
<li>callsetup: Bluetooth proprietary call set up status indicator4. Support for this indicator is optional<br>for the HF. When supported, this indicator shall be used in conjunction with, and as an extension<br>of the standard call indicator. Possible values are as follows: <ul>
<li><code><value>=0</code> means not currently in call set up. </li>
<li><code><value>=1</code> means an incoming call process ongoing.</li>
<li><code><value>=2</code> means an outgoing call set up is ongoing. </li>
<li><code><value>=3</code> means remote party being alerted in an outgoing call.</li>
</ul>
</li>
<li>callheld: Bluetooth proprietary call hold status indicator. Support for this indicator is mandatory for<br>the AG, optional for the HF. Possible values are as follows: <ul>
<li>0= No calls held </li>
<li>1= Call is placed on hold or active/held calls swapped<br>(The AG has both an active AND a held call) </li>
<li>Call on hold, no active call</li>
</ul>
</li>
<li>signal: Signal Strength indicator: <ul>
<li><code><value>= </code>ranges from 0 to 5</li>
</ul>
</li>
<li>roam: Roaming status indicator: <ul>
<li><code><value>=0</code> means roaming is not active </li>
<li><code><value>=1</code> means a roaming is active</li>
</ul>
</li>
<li>battchg: Battery Charge indicator of AG: <ul>
<li><code><value>=</code>ranges from 0 to 5</li>
</ul>
</li>
</ul>
</li>
<li><p>+CIND:当前indicator的列表</p>
</li>
<li><p>AT+CLCC:列出当前电话命令,</p>
</li>
<li><p>+CLCC:当前call结果码,支持参数是</p>
<ul>
<li><p>idx:表示建立连接顺序或者接听电话的数字(从1开始)。</p>
</li>
<li><p>dir:0(outgoing),1(incoming)</p>
</li>
<li><p>status:</p>
<ul>
<li><p>0=Active</p>
</li>
<li><p>1=Held</p>
</li>
<li><p>2=Dialing(outgoing calls only)</p>
</li>
<li><p>3=Alerting(outgoing calls only)</p>
</li>
<li><p>4=Incoming(incoming calls only)</p>
</li>
<li><p>5=Waiting(incoming calls only)</p>
</li>
<li><p>6 = Call held by Response and Hold</p>
</li>
</ul>
</li>
<li><p>mode= 0 (Voice), 1 (Data), 2 (FAX)</p>
</li>
<li><p>mpty=</p>
<ul>
<li>0 - this call is NOT a member of a multi-party (conference) call</li>
<li>1 - this call IS a member of a multi-party (conference) call</li>
</ul>
</li>
<li><p>number (optional)</p>
</li>
<li><p>type (optional)</p>
</li>
</ul>
</li>
<li><p>AT+COPS: AT+COPS=3,0将被HF发送给AG</p>
</li>
<li><p>AT+CMEE: 使能+CME ERROR: <err>结果码</p>
</li>
<li><p>+CME ERROR</p>
<ul>
<li>+CME ERROR: 0 – AG failure</li>
</ul>
</li>
<li><p>AT+CLIP: Calling Line Identification notification 使能命令,It enables/disables the Calling Line Identification notification unsolicited result code 。</p>
</li>
<li><p>+CLIP : Standard “Calling Line Identification notification” unsolicited result code. </p>
</li>
<li><p>AT+CMER :Standard event reporting activation/deactivation AT command. </p>
</li>
<li><p>+CIEV: “indicator events reporting”结果码。<code><ind></code>,<code><value></code> result code ,对应AT+CIND 返回的列表中的参数和值。</p>
</li>
<li><p>AT+VTS: DTMF生成命令。</p>
</li>
<li><p>AT+CNUM: HF相应<code>+CNUM</code>命令</p>
<ul>
<li>AT+CNUM (Retrieve Subscriber Number Information)</li>
<li>AT+CNUM=? (Test Subscriber Number Information – Not Implemented)</li>
</ul>
</li>
<li><p>+CNUM: 用于将“ Subscriber Number Information ”从AG发送到HF的标准响应。</p>
</li>
</ul>
<p>HFP协议扩展的AT命令:</p>
<ul>
<li>AT+BIA (Bluetooth Indicators Activation) </li>
<li>AT+BINP (Bluetooth INPut) </li>
<li>AT+BLDN (Bluetooth Last Dialed Number) </li>
<li>AT+BVRA (Bluetooth Voice Recognition Activation) </li>
<li>+BVRA (Bluetooth Voice Recognition Activation) </li>
<li>AT+BRSF (Bluetooth Retrieve Supported Features) </li>
<li>+BRSF (Bluetooth Retrieve Supported Features) </li>
<li>AT+NREC (Noise Reduction and Echo Canceling) </li>
<li>AT+VGM (Gain of Microphone) </li>
<li>AT+VGS (Gain of Speaker) </li>
<li>+VGM (Gain of Microphone) </li>
<li>+VGS (Gain of Speaker) </li>
<li>+BSIR (Bluetooth Setting of In-band Ring tone) </li>
<li>AT+BTRH (Bluetooth Response and Hold Feature) </li>
<li>+BTRH (Bluetooth Response and Hold Feature) </li>
<li>AT+BCC (Bluetooth Codec Connection) </li>
<li>AT+BCS (Bluetooth Codec Selection) </li>
<li>+BCS (Bluetooth Codec Selection) </li>
<li>AT+BAC (Bluetooth Available Codecs) </li>
<li>AT+BIND (Bluetooth HF Indicators Feature) </li>
<li>+BIND (Bluetooth HF Indicators Feature) </li>
<li>AT+BIEV (Bluetooth HF Indicators Feature)</li>
</ul>
<h3 id="建立服务连接"><a href="#建立服务连接" class="headerlink" title="建立服务连接"></a>建立服务连接</h3><blockquote>
<p>Upon a user action or an internal event, either the HF or the AG may initiate a <strong>Service Level Connection</strong><br><strong>establishment</strong> procedure.<br>A Service Level Connection establishment requires the existence of a RFCOMM connection, that is, a<br>RFCOMM data link channel between the HF and the AG.<br>Both the HF and the AG may initiate the RFCOMM connection establishment. If there is no RFCOMM<br>session between the AG and the HF, the initiating device shall first initialize RFCOMM. </p>
</blockquote>
<p>连接过程如下:</p>
<p><img data-src="https://s1.ax1x.com/2022/04/11/LV6DxS.png"></p>
<ol>
<li><p>支持能力交换<br>首先HF发送AT+BRSF=< HF supported features >给AG,目的是首先通知AG其具有的能力,其次接收AG返回的其自身的BRSF能力。</p>
</li>
<li><p>Codec协商<br>如果HF支持Codec Negotiation特征,其会查看AG返回的BRSF中是否也支持该特性,如果都支持该特性,则HF将发送AT+BAC=< HF available codecs >命令给AG以告知其可用的codec。</p>
</li>
<li><p>AG Indicator<br>HF从AG接收到的BRSF,可以知道AG支持的Indicator,并按顺序拍好,这是因为根据3GPP 27.007规范,AG可以支持Hands-Free不支持的profile。HF使用AT+CIND=?测试命令接收AG支持的indicator以及它们的次序。<br>当HF获得必须的Indicator和它们的次序,它将通过AT+CIND?命令取得AG端正在使用indicator的状态。<br>当HF取得AG的indicator后,HF会使用AT+CMER使能AG的indicator状态跟新功能,AG会返回OK作为应答。当service,call或者call建立状态发生时,AG将发送和indicator相关的+CIEV结果码给HF。HF根据收到的+CIEV码来跟新其自身内部的indicator。<br>AG侧会一直保持indicator状态跟新功能使能直到收到AT+CMER指示其关闭或者HF和AG端的Service Level Connection连接断开。<br>当HF使能AG的indicator状态跟新,如果AG和HF都支持呼叫等待(Call waiting)和3方通信(3-way calling)。HF将发送AT+CHLD=?测试命令取得AG是如何支持这种功能的。如果HF或者AG其中之一不支持三方通信,AT+CHLD=?命令不会被发送。</p>
</li>
<li><p>HF Indicator<br>如果HF支持HF indicator,其会查看AG是否支持HF indicator。<br>如果HF和AG支持HF indicator特性,HF将发送AT+BIND=< HF supported HF indicators >通知HF侧支持的indicator,AG以OK应答。<br>当AG接收到HF告知的HF indicator特性,HF将发送AT+BIND=?请求AG侧支持的HF indicator。AG将会以+BIND和以OK结尾的应答。<br>当HF接收到AG支持的HF indicator,HF将会发送AT+BIND?命令确定HF目前使能的HF indicator。AG将会一次或多次以+BIND应答和以OK结尾的应答。<br>至此HF可能发送AT+BIEV命令告知AG其使能的HF indicator发生变化。<br>AG可以使用+BIND使能或者禁止任何HF indicator。</p>
</li>
<li><p>End of Service Level Connection</p>
<ul>
<li><p>HF需要知道Service Level Connection被完全建立,这可以通过以下几个方式:</p>
<ul>
<li>当且仅当AG通过+BRSF命令告知HF其支持的<code>"HF indicator"</code>,在HF收到AG通过<strong>AT+BIND?</strong>命令发来的其支持的<code>"HF indicator"</code>可认为完全建立。</li>
<li>当且仅当SDP服务发现AH和AG双方均支持<code>"Call waiting and 3-way calling"</code>,在HFAG通过<strong>AT+CHLD</strong>命令发来的其对呼叫等待和多方电话的支持,对这种情况,<code>"HF indicator"</code>不要设置该比特位,AG也不要在+BRSF命令中设置该比特位。</li>
<li>在HF使用<strong>AT+CMER</strong>命令成功启用<code>“Indicator status update”</code>功能,对这种情况SDP服务不应该设置<code>“Call waiting and 3-way calling”</code>比特位。<br>如果HF收到AG通过indicator指示当前有电话时,HF查询AG的接听和保持状态来判断是否是未接听电话。</li>
</ul>
</li>
<li><p>同样AG侧Service Level Connection完全建立也有几种情况:</p>
<ul>
<li><p>当且仅当HF indicator在HF被设置且AG侧支持的indicator已经通过+BRSF命令应答,则AG以**+BIND加OK结尾**的命令应答其使能的HF indicator时可认为Service Level Connection完全建立。</p>
</li>
<li><p>当且仅当<code>“Call waiting and 3-way calling”</code>比特在HF和AG的SDP服务中被置位,在AG通过**+CHLD加OK结尾**命令成功响应其对呼叫保持和多方电话支持时SLC会被完全建立。对这种情况,+BRSF不应该设置该HF indicator比特位。</p>
</li>
<li><p>AG已成功<strong>响应OK到AT + CMER</strong>命令(启用<code>“Indicator status update”</code>功能。)当<code>“Call waiting and 3-way calling”</code>位时,应适用这种情况未在支持的功能位图中设置为HF或AG,以及<code>“HF Indicators ”</code>对于通过+ BRSF交换的HF或AG的支持功能位图中未设置位的位图命令。</p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br></pre></td><td class="code"><pre><span class="line">#判断是否支持"Call waiting and 3-way calling"</span><br><span class="line">#AG发现HF, hfP支持的协议,HF支持"Call waiting and 3-way calling"</span><br><span class="line">> 596 17.850811 XiaomiCo_6e:38:c5 (PHONE) SANYOEle_62:35:bb (DEVICE) SDP 36 Rcvd Service Search Attribute Request : Handsfree: [Service Class ID List 0x0001] [Protocol Descriptor List 0x0004] [Bluetooth Profile Descriptor List 0x0009] [(HFP HS) Supported Features 0x0311] </span><br><span class="line">> 597 17.851437 SANYOEle_62:35:bb (DEVICE) XiaomiCo_6e:38:c5 (PHONE) SDP 69 Sent Service Search Attribute Response </span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth SDP Protocol</span><br><span class="line"> PDU: Service Search Attribute Response (0x07)</span><br><span class="line"> Transaction Id: 0x0000</span><br><span class="line"> Parameter Length: 55</span><br><span class="line"> Attribute List Byte Count: 52</span><br><span class="line"> Attribute Lists [count = 1]</span><br><span class="line"> Data Element: Sequence uint8 50 bytes</span><br><span class="line"> 0011 0... = Data Element Type: Sequence (6)</span><br><span class="line"> .... .101 = Data Element Size: uint8 (5)</span><br><span class="line"> Data Element Var Size: 50</span><br><span class="line"> Data Value</span><br><span class="line"> Attribute List [count = 4] (Handsfree)</span><br><span class="line"> Data Element: Sequence uint16 47 bytes</span><br><span class="line"> 0011 0... = Data Element Type: Sequence (6)</span><br><span class="line"> .... .110 = Data Element Size: uint16 (6)</span><br><span class="line"> Data Element Var Size: 47</span><br><span class="line"> Data Value</span><br><span class="line"> Service Attribute: Service Class ID List (0x1), value = Handsfree -> Generic Audio</span><br><span class="line"> Service Attribute: Protocol Descriptor List (0x4), value = L2CAP -> RFCOMM:2</span><br><span class="line"> Service Attribute: Bluetooth Profile Descriptor List (0x9), value = Handsfree 1.6</span><br><span class="line"> Service Attribute: (HFP HS) Supported Features (0x311), value = (EC and/or Nr Function) (Call Waiting or Three Way Calling) (CLI Presentation Capability) (Voice Recognition Activation) (Remote Volume Control) (Wide Band Speech) </span><br><span class="line"> Continuation State: no (00)</span><br><span class="line"></span><br><span class="line">#HF发现AG, hfP支持的协议,AG不支持"Call waiting and 3-way calling",只支持"3-way calling"</span><br><span class="line">> 637 18.017460 SANYOEle_62:35:bb (DEVICE) XiaomiCo_6e:38:c5 (PHONE) SDP 33 Sent Service Search Attribute Request : Handsfree Audio Gateway: [Service Class ID List 0x0001] [Bluetooth Profile Descriptor List 0x0009] [(HFP AG) Supported Features 0x0311] </span><br><span class="line">> 644 18.024689 XiaomiCo_6e:38:c5 (PHONE) SANYOEle_62:35:bb (DEVICE) SDP 52 Rcvd Service Search Attribute Response </span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth SDP Protocol</span><br><span class="line"> PDU: Service Search Attribute Response (0x07)</span><br><span class="line"> Transaction Id: 0x0000</span><br><span class="line"> Parameter Length: 38</span><br><span class="line"> Attribute List Byte Count: 35</span><br><span class="line"> Attribute Lists [count = 1]</span><br><span class="line"> Data Element: Sequence uint8 33 bytes</span><br><span class="line"> 0011 0... = Data Element Type: Sequence (6)</span><br><span class="line"> .... .101 = Data Element Size: uint8 (5)</span><br><span class="line"> Data Element Var Size: 33</span><br><span class="line"> Data Value</span><br><span class="line"> Attribute List [count = 3] (Handsfree Audio Gateway)</span><br><span class="line"> Data Element: Sequence uint16 30 bytes</span><br><span class="line"> 0011 0... = Data Element Type: Sequence (6)</span><br><span class="line"> .... .110 = Data Element Size: uint16 (6)</span><br><span class="line"> Data Element Var Size: 30</span><br><span class="line"> Data Value</span><br><span class="line"> Service Attribute: Service Class ID List (0x1), value = Handsfree Audio Gateway -> Generic Audio</span><br><span class="line"> Service Attribute: Bluetooth Profile Descriptor List (0x9), value = Handsfree 1.6</span><br><span class="line"> Service Attribute: (HFP AG) Supported Features (0x311), value = (Three Way Calling) (EC and/or Nr Function) (Voice Recognition Function) (Wide Band Speech) </span><br><span class="line"> Continuation State: no (00)</span><br><span class="line"></span><br><span class="line">#HFP建立连接</span><br><span class="line">#交换支持功能,AG和HF都不支持"HF indicator"</span><br><span class="line">> 634 18.012482 SANYOEle_62:35:bb (DEVICE) XiaomiCo_6e:38:c5 (PHONE) HFP 26 Sent AT+BRSF=255</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HFP Profile</span><br><span class="line"> [Role: HS - Headset (2)]</span><br><span class="line"> AT Stream: AT+BRSF=255\r</span><br><span class="line"> Command 0: +BRSF</span><br><span class="line"> Command Line Prefix: AT</span><br><span class="line"> Command: +BRSF (Bluetooth Retrieve Supported Features)</span><br><span class="line"> Type: Action Command (0x003d)</span><br><span class="line"> Parameters</span><br><span class="line"> HS supported features bitmask: 255</span><br><span class="line"> .... .... .... .... .... .... .... ...1 = EC and/or NR function: True</span><br><span class="line"> .... .... .... .... .... .... .... ..1. = Call waiting or 3-way calling: True</span><br><span class="line"> .... .... .... .... .... .... .... .1.. = CLI Presentation: True</span><br><span class="line"> .... .... .... .... .... .... .... 1... = Voice Recognition Activation: True</span><br><span class="line"> .... .... .... .... .... .... ...1 .... = Remote Volume Control: True</span><br><span class="line"> .... .... .... .... .... .... ..1. .... = Enhanced Call Status: True</span><br><span class="line"> .... .... .... .... .... .... .1.. .... = Enhanced Call Control: True</span><br><span class="line"> .... .... .... .... .... .... 1... .... = Codec Negotiation: True</span><br><span class="line"> .... .... .... .... .... ...0 .... .... = HF Indicators: False</span><br><span class="line"> .... .... .... .... .... ..0. .... .... = eSCO S4 (and T2) Settings Support: False</span><br><span class="line"> 0000 0000 0000 0000 0000 00.. .... .... = Reserved: 0x000000</span><br><span class="line">> 641 18.022446 XiaomiCo_6e:38:c5 (PHONE) SANYOEle_62:35:bb (DEVICE) HFP 28 Rcvd +BRSF: 871</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HFP Profile</span><br><span class="line"> [Role: AG - Audio Gate (1)]</span><br><span class="line"> AT Stream: \r\n+BRSF: 871\r\n</span><br><span class="line"> Command 0: +BRSF</span><br><span class="line"> Command: +BRSF (Bluetooth Retrieve Supported Features)</span><br><span class="line"> Type: Response (0x003a)</span><br><span class="line"> Parameters</span><br><span class="line"> AG supported features bitmask: 871</span><br><span class="line"> .... .... .... .... .... .... .... ...1 = Three Way Calling: True</span><br><span class="line"> .... .... .... .... .... .... .... ..1. = EC and/or NR function: True</span><br><span class="line"> .... .... .... .... .... .... .... .1.. = Voice Recognition Function: True</span><br><span class="line"> .... .... .... .... .... .... .... 0... = In-band Ring Tone: False</span><br><span class="line"> .... .... .... .... .... .... ...0 .... = Attach Number to Voice Tag: False</span><br><span class="line"> .... .... .... .... .... .... ..1. .... = Ability to Reject a Call: True</span><br><span class="line"> .... .... .... .... .... .... .1.. .... = Enhanced Call Status: True</span><br><span class="line"> .... .... .... .... .... .... 0... .... = Enhanced Call Control: False</span><br><span class="line"> .... .... .... .... .... ...1 .... .... = Extended Error Result Codes: True</span><br><span class="line"> .... .... .... .... .... ..1. .... .... = Codec Negotiation: True</span><br><span class="line"> .... .... .... .... .... .0.. .... .... = HF Indicators: False</span><br><span class="line"> .... .... .... .... .... 0... .... .... = eSCO S4 (and T2) Settings Support: False</span><br><span class="line"> 0000 0000 0000 0000 0000 .... .... .... = Reserved: 0x00000</span><br><span class="line"></span><br><span class="line">#AG和HF都支持"Codec Negotiation",HF告知AG其可用的Codec编码(CVSD)</span><br><span class="line">> 643 18.023696 SANYOEle_62:35:bb (DEVICE) XiaomiCo_6e:38:c5 (PHONE) HFP 23 Sent AT+BAC=1</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HFP Profile</span><br><span class="line"> [Role: HS - Headset (2)]</span><br><span class="line"> AT Stream: AT+BAC=1\r</span><br><span class="line"> Command 0: +BAC</span><br><span class="line"> Command Line Prefix: AT</span><br><span class="line"> Command: +BAC (Bluetooth Available Codecs)</span><br><span class="line"> Type: Action Command (0x003d)</span><br><span class="line"> Parameters</span><br><span class="line"> Codec: CVSD (1)</span><br><span class="line"></span><br><span class="line">#获取AG支持的indicator以及它们的次序</span><br><span class="line">> 649 18.029340 SANYOEle_62:35:bb (DEVICE) XiaomiCo_6e:38:c5 (PHONE) HFP 24 Sent AT+CIND=? </span><br><span class="line">> 652 18.035680 XiaomiCo_6e:38:c5 (PHONE) SANYOEle_62:35:bb (DEVICE) HFP 147 Rcvd +CIND: ("CALL",(0,1)),("CALLSETUP",(0-3)),("SERVICE",(0-1)),("SIGNAL",(0-5)),("ROAM",(0,1)),("BATTCHG",(0-5)),("CALLHELD",(0-2)) </span><br><span class="line"></span><br><span class="line">#获取AG indicators当前的状态</span><br><span class="line">> 654 18.037547 SANYOEle_62:35:bb (DEVICE) XiaomiCo_6e:38:c5 (PHONE) HFP 23 Sent AT+CIND? </span><br><span class="line">> 656 18.092460 XiaomiCo_6e:38:c5 (PHONE) SANYOEle_62:35:bb (DEVICE) HFP 38 Rcvd +CIND: 0,0,1,5,0,2,0</span><br><span class="line"></span><br><span class="line">#标志HFP连接建立</span><br><span class="line">#启用"Indicator status update"</span><br><span class="line">> 658 18.093591 SANYOEle_62:35:bb (DEVICE) XiaomiCo_6e:38:c5 (PHONE) HFP 30 Sent AT+CMER=3,0,0,1</span><br><span class="line">> 660 18.117156 XiaomiCo_6e:38:c5 (PHONE) SANYOEle_62:35:bb (DEVICE) HFP 20 Rcvd OK </span><br></pre></td></tr></table></figure>
<h3 id="HF拨打-挂断电话"><a href="#HF拨打-挂断电话" class="headerlink" title="HF拨打\挂断电话"></a>HF拨打\挂断电话</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">#HF拨打电话</span><br><span class="line">> 921 29.433324 SANYOEle_62:35:bb (DEVICE) XiaomiCo_6e:38:c5 (PHONE) HFP 24 Sent ATD10086; </span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HFP Profile</span><br><span class="line"> [Role: HS - Headset (2)]</span><br><span class="line"> AT Stream: ATD10086;\r</span><br><span class="line"> Command 0: D</span><br><span class="line"> Command Line Prefix: AT</span><br><span class="line"> Command: D (Dial)</span><br><span class="line"> [Expert Info (Warning/Protocol): Non mandatory type or command in this role]</span><br><span class="line"> Parameters: No</span><br><span class="line">> 924 30.778650 XiaomiCo_6e:38:c5 (PHONE) SANYOEle_62:35:bb (DEVICE) HFP 20 Rcvd OK</span><br><span class="line"></span><br><span class="line">#挂断电话</span><br><span class="line">> 965 37.723080 SANYOEle_62:35:bb (DEVICE) XiaomiCo_6e:38:c5 (PHONE) HFP 22 Sent AT+CHUP</span><br><span class="line">> 966 37.752000 XiaomiCo_6e:38:c5 (PHONE) SANYOEle_62:35:bb (DEVICE) HFP 20 Rcvd OK</span><br></pre></td></tr></table></figure>
<h3 id="HF获取通话电话列表"><a href="#HF获取通话电话列表" class="headerlink" title="HF获取通话电话列表"></a>HF获取通话电话列表</h3><p>会HF会轮询此命令</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">> 925 30.779082 SANYOEle_62:35:bb (DEVICE) XiaomiCo_6e:38:c5 (PHONE) HFP 22 Sent AT+CLCC </span><br><span class="line">> 929 30.820871 XiaomiCo_6e:38:c5 (PHONE) SANYOEle_62:35:bb (DEVICE) HFP 46 Rcvd +CLCC: 1,0,2,0,0,"10086",129 </span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HFP Profile</span><br><span class="line"> [Role: AG - Audio Gate (1)]</span><br><span class="line"> AT Stream: \r\n+CLCC: 1,0,2,0,0,"10086",129\r\n</span><br><span class="line"> Command 0: +CLCC</span><br><span class="line"> Command: +CLCC (Current Calls)</span><br><span class="line"> Type: Response (0x003a)</span><br><span class="line"> Parameters</span><br><span class="line"> ID: 1</span><br><span class="line"> Direction: Mobile Originated (0)</span><br><span class="line"> State: Dialing (2)</span><br><span class="line"> Mode: Voice (0)</span><br><span class="line"> Mpty: Call is not one of multiparty (conference) call parties (0)</span><br><span class="line"> Number: "10086"</span><br><span class="line"> Type: The phone number format may be a national or international format, and may contain prefix and/or escape digits. No changes on the number presentation are required. (129)</span><br></pre></td></tr></table></figure>
<h3 id="AG下发通话状态"><a href="#AG下发通话状态" class="headerlink" title="AG下发通话状态"></a>AG下发通话状态</h3><p>在开启<code>"Indicator status update"</code>(AT+CMER)之后,AG会主动下发当前的通话状态,<code>Indicator Index</code>对应+CIND返回的参数列表,<code>Indicator <idx></code>对应其值。</p>
<h4 id="拨打电话"><a href="#拨打电话" class="headerlink" title="拨打电话"></a>拨打电话</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">#CALLSETUP=2,拨号中</span><br><span class="line">> 1056 66.689969 XiaomiCo_6e:38:c5 (PHONE) SANYOEle_62:35:bb (DEVICE) HFP 27 Rcvd +CIEV: 2,2 </span><br></pre></td></tr></table></figure>
<h4 id="无通话或者挂断"><a href="#无通话或者挂断" class="headerlink" title="无通话或者挂断"></a>无通话或者挂断</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">#CALL=0,无通话</span><br><span class="line">1106 74.975552 XiaomiCo_6e:38:c5 (PHONE) SANYOEle_62:35:bb (DEVICE) HFP 27 Rcvd +CIEV: 1,0 </span><br></pre></td></tr></table></figure>
<h4 id="来电"><a href="#来电" class="headerlink" title="来电"></a>来电</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">#CALLSETUP=1,来电中</span><br><span class="line">> 1056 66.689969 XiaomiCo_6e:38:c5 (PHONE) SANYOEle_62:35:bb (DEVICE) HFP 27 Rcvd +CIEV: 2,1 </span><br></pre></td></tr></table></figure>
<h3 id="建立SCO-x2F-eSCO连接"><a href="#建立SCO-x2F-eSCO连接" class="headerlink" title="建立SCO/eSCO连接"></a>建立SCO/eSCO连接</h3><p>蓝牙电话的音频数据由SCO/eSCO协议传输,在HCI中无数据相关的日志。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br></pre></td><td class="code"><pre><span class="line">#HF选择编解码格式</span><br><span class="line">> 900 387.320548 XiaomiCo_6e:38:c5 (PHONE) localhost () HFP 24 Rcvd +BCS: 1 </span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HFP Profile</span><br><span class="line"> [Role: AG - Audio Gate (1)]</span><br><span class="line"> AT Stream: \r\n+BCS: 1\r\n</span><br><span class="line"> Command 0: +BCS</span><br><span class="line"> Command: +BCS (Bluetooth Codec Selection)</span><br><span class="line"> Type: Response (0x003a)</span><br><span class="line"> Parameters</span><br><span class="line"> Codec: CVSD (1)</span><br><span class="line">> 903 387.380459 localhost () XiaomiCo_6e:38:c5 (PHONE) HFP 23 Sent AT+BCS=1 </span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HFP Profile</span><br><span class="line"> [Role: HS - Headset (2)]</span><br><span class="line"> AT Stream: AT+BCS=1\r</span><br><span class="line"> Command 0: +BCS</span><br><span class="line"> Command Line Prefix: AT</span><br><span class="line"> Command: +BCS (Bluetooth Codec Selection)</span><br><span class="line"> Type: Action Command (0x003d)</span><br><span class="line"> Parameters</span><br><span class="line"> Codec: CVSD (1)</span><br><span class="line"></span><br><span class="line">#AG请求建立eSCO连接</span><br><span class="line">> 906 387.530834 controller host HCI_EVT 13 Rcvd Connect Request</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Connect Request</span><br><span class="line"> Event Code: Connect Request (0x04)</span><br><span class="line"> Parameter Total Length: 10</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Class of Device: 0x001f00 (Uncategorized: device code not specified:Unknown - services:)</span><br><span class="line"> Link Type: eSCO connection (Voice Channels) (0x02)</span><br><span class="line"></span><br><span class="line">#HF允许建立eSCO连接</span><br><span class="line">> 907 387.531078 host controller HCI_CMD 67 Sent Enhanced Accept Synchronous Connection Request</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Command - Enhanced Accept Synchronous Connection Request</span><br><span class="line"> Command Opcode: Enhanced Accept Synchronous Connection Request (0x043e)</span><br><span class="line"> 0000 01.. .... .... = Opcode Group Field: Link Control Commands (0x01)</span><br><span class="line"> .... ..00 0011 1110 = Opcode Command Field: Enhanced Accept Synchronous Connection Request (0x03e)</span><br><span class="line"> Parameter Total Length: 63</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Tx Bandwidth (bytes/s): 8000</span><br><span class="line"> Rx Bandwidth (bytes/s): 8000</span><br><span class="line"> Transmit Coding Format</span><br><span class="line"> Receive Coding Format</span><br><span class="line"> Transmit Codec Frame Size: 60</span><br><span class="line"> Receive Codec Frame Size: 60</span><br><span class="line"> Input Bandwidth: 16000</span><br><span class="line"> Output Bandwidth: 16000</span><br><span class="line"> Input Coding Format</span><br><span class="line"> Output Coding Format</span><br><span class="line"> Input Coded Data Size: 16</span><br><span class="line"> Output Coded Data Size: 16</span><br><span class="line"> Input PCM Data Format: 2's complement (0x02)</span><br><span class="line"> Output PCM Data Format: 2's complement (0x02)</span><br><span class="line"> Input PCM Sample Payload MSB Position: 0</span><br><span class="line"> Output PCM Sample Payload MSB Position: 0</span><br><span class="line"> Input Data Path: Vendor Specific</span><br><span class="line"> Output Data Path: Vendor Specific</span><br><span class="line"> Input Transport Unit Size: 16</span><br><span class="line"> Output Transport Unit Size: 16</span><br><span class="line"> Max. Latency (ms): 12</span><br><span class="line"> Packet Type: 0x03bf, 3-EV5 may NOT be used, 2-EV5 may NOT be used, 3-EV3 may NOT be used, EV5 may be used, EV4 may be used, EV3 may be used, HV3 may be used, HV2 may be used, HV1 may be used</span><br><span class="line"> Retransmission Effort: At least 1 retransmission, optimize for link quality (2)</span><br><span class="line"> [Pending in frame: 909]</span><br><span class="line"> [Command-Pending Delta: 1.38ms]</span><br><span class="line"> [Response in frame: 910]</span><br><span class="line"> [Command-Response Delta: 3.862ms]</span><br><span class="line"></span><br><span class="line">#eSCO连接成功</span><br><span class="line">> 910 387.534940 controller host HCI_EVT 20 Rcvd Synchronous Connection Complete</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth HCI Event - Synchronous Connection Complete</span><br><span class="line"> Event Code: Synchronous Connection Complete (0x2c)</span><br><span class="line"> Parameter Total Length: 17</span><br><span class="line"> Status: Success (0x00)</span><br><span class="line"> Connection Handle: 0x0e00</span><br><span class="line"> BD_ADDR: XiaomiCo_6e:38:c5 (00:00:00:00:00:00)</span><br><span class="line"> Link Type: eSCO connection (0x02)</span><br><span class="line"> Transmit Interval: 12 slots (7.5 msec)</span><br><span class="line"> Retransmit Window: 2 slots (1.25 msec)</span><br><span class="line"> Rx Packet Length: 60</span><br><span class="line"> Tx Packet Length: 60</span><br><span class="line"> Air Mode: CVSD (2)</span><br><span class="line"> [Command in frame: 907]</span><br><span class="line"> [Pending in frame: 909]</span><br><span class="line"> [Pending-Response Delta: 2.482ms]</span><br><span class="line"> [Command-Response Delta: 3.862ms]</span><br></pre></td></tr></table></figure>
<h1 id="蓝牙音乐"><a href="#蓝牙音乐" class="headerlink" title="蓝牙音乐"></a>蓝牙音乐</h1><h2 id="AVDTP"><a href="#AVDTP" class="headerlink" title="AVDTP"></a>AVDTP</h2><p><strong>AVDTP:AUDIO/VIDEO DISTRIBUTION TRANSPORT PROTOCOL(音视频分配传输协议)</strong> ,用于音乐数据流的建立与传输控制。</p>
<h3 id="建立连接"><a href="#建立连接" class="headerlink" title="建立连接"></a>建立连接</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">> 458 11.574257 SANYOEle_62:35:bb (DEVICE) XiaomiCo_6e:38:c5 (PHONE) L2CAP 17 Sent Connection Request (AVDTP, SCID: 0x0042)</span><br></pre></td></tr></table></figure>
<h3 id="数据流传输"><a href="#数据流传输" class="headerlink" title="数据流传输"></a>数据流传输</h3><p>数据流的生命状态:</p>
<p><img data-src="https://s1.ax1x.com/2022/04/11/LV6NVA.png"></p>
<h4 id="查找-Idle"><a href="#查找-Idle" class="headerlink" title="查找(Idle)"></a>查找(Idle)</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">#查询AG的所有音源</span><br><span class="line">> 468 11.652772 SANYOEle_62:35:bb (DEVICE) XiaomiCo_6e:38:c5 (PHONE) AVDTP 11 Sent Command - Discover</span><br><span class="line">> 469 11.722467 XiaomiCo_6e:38:c5 (PHONE) SANYOEle_62:35:bb (DEVICE) AVDTP 15 Rcvd ResponseAccept - Discover - items: 2</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth AVDTP Protocol</span><br><span class="line"> Signal: Discover (ResponseAccept)</span><br><span class="line"> ACP SEP [1 - Audio Source] item 1/2</span><br><span class="line"> 0000 01.. = SEID: 1</span><br><span class="line"> .... ..0. = In Use: False (0x0)</span><br><span class="line"> .... ...0 = RFA0: 0x0</span><br><span class="line"> 0000 .... = Media Type: Audio (0x0)</span><br><span class="line"> .... 0... = Type: Source (0x0)</span><br><span class="line"> .... .000 = RFA1: 0x0</span><br><span class="line"> ACP SEP [2 - Audio Source] item 2/2</span><br><span class="line"> 0000 10.. = SEID: 2</span><br><span class="line"> .... ..0. = In Use: False (0x0)</span><br><span class="line"> .... ...0 = RFA0: 0x0</span><br><span class="line"> 0000 .... = Media Type: Audio (0x0)</span><br><span class="line"> .... 0... = Type: Source (0x0)</span><br><span class="line"> .... .000 = RFA1: 0x0</span><br><span class="line"></span><br><span class="line">#获取音源详细信息</span><br><span class="line">> 470 11.722896 SANYOEle_62:35:bb (DEVICE) XiaomiCo_6e:38:c5 (PHONE) AVDTP 12 Sent Command - GetAllCapabilities - ACP SEID [1 - Audio Source]</span><br><span class="line">> 473 11.728705 XiaomiCo_6e:38:c5 (PHONE) SANYOEle_62:35:bb (DEVICE) AVDTP 23 Rcvd ResponseAccept - GetAllCapabilities - Audio SBC (44100 | Mono JointStereo | block: 4 8 12 16 | subbands: 8 | allocation: Loudness | bitpool: 2..53)</span><br><span class="line">> 474 11.728960 SANYOEle_62:35:bb (DEVICE) XiaomiCo_6e:38:c5 (PHONE) AVDTP 12 Sent Command - GetAllCapabilities - ACP SEID [2 - Audio Source]</span><br><span class="line">> 476 11.734811 XiaomiCo_6e:38:c5 (PHONE) SANYOEle_62:35:bb (DEVICE) AVDTP 25 Rcvd ResponseAccept - GetAllCapabilities - Audio MPEG-2,4 AAC</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth AVDTP Protocol</span><br><span class="line"> Signal: GetAllCapabilities (ResponseAccept)</span><br><span class="line"> 0010 .... = Transaction: 0x2</span><br><span class="line"> .... 00.. = Packet Type: Single (0x0)</span><br><span class="line"> .... ..10 = Message Type: ResponseAccept (0x2)</span><br><span class="line"> 00.. .... = RFA: 0x0</span><br><span class="line"> ..00 1100 = Signal: GetAllCapabilities (0x0c)</span><br><span class="line"> Capabilities</span><br><span class="line"> Service: Media Transport</span><br><span class="line"> Service: Media Codec - Audio MPEG-2,4 AAC</span><br><span class="line"> Service: Delay Reporting</span><br></pre></td></tr></table></figure>
<h4 id="设置-x2F-打开-Configured-x2F-Open"><a href="#设置-x2F-打开-Configured-x2F-Open" class="headerlink" title="设置/打开(Configured/Open)"></a>设置/打开(Configured/Open)</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">#选择对应音源</span><br><span class="line">> 477 11.735508 SANYOEle_62:35:bb (DEVICE) XiaomiCo_6e:38:c5 (PHONE) AVDTP 25 Sent Command - SetConfiguration - ACP SEID [2 - Audio Source] - INT SEID [2 - Audio Source] - Audio MPEG-2,4 AAC</span><br><span class="line">> 479 11.742210 XiaomiCo_6e:38:c5 (PHONE) SANYOEle_62:35:bb (DEVICE) AVDTP 11 Rcvd ResponseAccept - SetConfiguration</span><br><span class="line"></span><br><span class="line">#打开音源</span><br><span class="line">> 480 11.742538 SANYOEle_62:35:bb (DEVICE) XiaomiCo_6e:38:c5 (PHONE) AVDTP 12 Sent Command - Open - ACP SEID [2 - Audio Source]</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth AVDTP Protocol</span><br><span class="line"> Signal: Open (Command)</span><br><span class="line"> ACP SEID [2 - Audio Source]</span><br><span class="line">> 485 11.747312 XiaomiCo_6e:38:c5 (PHONE) SANYOEle_62:35:bb (DEVICE) AVDTP 11 Rcvd ResponseAccept - Open</span><br></pre></td></tr></table></figure>
<h4 id="开始传输-Streaming"><a href="#开始传输-Streaming" class="headerlink" title="开始传输(Streaming)"></a>开始传输(Streaming)</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">> 601 28.945727 XiaomiCo_f2:31:c7 (PHONE) SANYOEle_71:7b:5c (DEVICE) AVDTP 12 Rcvd Command - Start - ACP SEID [2 - Audio Sink]</span><br><span class="line">> 602 28.946025 SANYOEle_71:7b:5c (DEVICE) XiaomiCo_f2:31:c7 (PHONE) AVDTP 11 Sent ResponseAccept - Start</span><br></pre></td></tr></table></figure>
<h4 id="传输-Streaming"><a href="#传输-Streaming" class="headerlink" title="传输(Streaming)"></a>传输(Streaming)</h4><p>使用RTP协议传输数据,AVDTP协议本身不处理数据流。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">> 612 29.166322 XiaomiCo_f2:31:c7 (PHONE) SANYOEle_71:7b:5c (DEVICE) RTP 37 PT=Unknown, SSRC=0x2, Seq=1, Time=0</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Frame 612: 37 bytes on wire (296 bits), 37 bytes captured (296 bits)</span><br><span class="line">Bluetooth</span><br><span class="line">Bluetooth HCI H4</span><br><span class="line">Bluetooth HCI ACL Packet</span><br><span class="line">Bluetooth L2CAP Protocol</span><br><span class="line">Bluetooth A2DP Profile</span><br><span class="line"> [ACP SEID: 2]</span><br><span class="line"> [INT SEID: 2]</span><br><span class="line"> [Codec: MPEG-2,4 AAC (0x02)]</span><br><span class="line"> [Stream Start in Frame: 612]</span><br><span class="line"> [Stream End in Frame: 22786]</span><br><span class="line"> [Stream Number: 1]</span><br><span class="line">Real-Time Transport Protocol</span><br><span class="line"> [Stream setup by BT A2DP (frame 612)]</span><br><span class="line"> 10.. .... = Version: RFC 1889 Version (2)</span><br><span class="line"> ..0. .... = Padding: False</span><br><span class="line"> ...0 .... = Extension: False</span><br><span class="line"> .... 0000 = Contributing source identifiers count: 0</span><br><span class="line"> 0... .... = Marker: False</span><br><span class="line"> Payload type: Unknown (98)</span><br><span class="line"> Sequence number: 1</span><br><span class="line"> [Extended sequence number: 65537]</span><br><span class="line"> Timestamp: 0</span><br><span class="line"> Synchronization Source identifier: 0x00000002 (2)</span><br><span class="line">Data (16 bytes)</span><br><span class="line"> Data: 47fc0000b0908003000621100520a41c</span><br><span class="line"> [Length: 16]</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="暂停-Streaming"><a href="#暂停-Streaming" class="headerlink" title="暂停(Streaming)"></a>暂停(Streaming)</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">> 773 23.510436 localhost () XiaomiCo_6e:38:c5 (PHONE) AVDTP 11 Sent ResponseAccept - Suspend</span><br></pre></td></tr></table></figure>
<h4 id="释放-Closing"><a href="#释放-Closing" class="headerlink" title="释放(Closing)"></a>释放(Closing)</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">> 5692 96.414176 localhost () XiaomiCo_6e:38:c5 (PHONE) AVDTP 12 Sent Command - Close - ACP SEID [2 - Audio Source]</span><br></pre></td></tr></table></figure>
<h2 id="AVCTP"><a href="#AVCTP" class="headerlink" title="AVCTP"></a>AVCTP</h2><p>**AVCTP: Audio/Video Control Transport Protocol(音频/视频控制传输协议)**,用于蓝牙设备间音乐数据流功能的发现与控制,但是控制的具体功能逻辑不由AVCTP处理,其只发送命令。</p>
<p>发现由SDP协议完成,然后发起L2CAP通道连接蓝牙设备之间的AVCTP服务,如下:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">#发现</span><br><span class="line">> 134 0.964749 localhost () XiaomiCo_6e:38:c5 (PHONE) SDP 33 Sent Service Search Attribute Request : Audio Source: [Service Class ID List 0x0001] [Protocol Descriptor List 0x0004] [Bluetooth Profile Descriptor List 0x0009] </span><br><span class="line">> 139 0.981837 XiaomiCo_6e:38:c5 (PHONE) localhost () SDP 64 Rcvd Service Search Attribute Response </span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth SDP Protocol</span><br><span class="line"> PDU: Service Search Attribute Response (0x07)</span><br><span class="line"> Transaction Id: 0x0000</span><br><span class="line"> Parameter Length: 50</span><br><span class="line"> Attribute List Byte Count: 47</span><br><span class="line"> Attribute Lists [count = 1]</span><br><span class="line"> Data Element: Sequence uint8 45 bytes</span><br><span class="line"> 0011 0... = Data Element Type: Sequence (6)</span><br><span class="line"> .... .101 = Data Element Size: uint8 (5)</span><br><span class="line"> Data Element Var Size: 45</span><br><span class="line"> Data Value</span><br><span class="line"> Attribute List [count = 3] (Audio Source)</span><br><span class="line"> Data Element: Sequence uint16 42 bytes</span><br><span class="line"> 0011 0... = Data Element Type: Sequence (6)</span><br><span class="line"> .... .110 = Data Element Size: uint16 (6)</span><br><span class="line"> Data Element Var Size: 42</span><br><span class="line"> Data Value</span><br><span class="line"> Service Attribute: Service Class ID List (0x1), value = Audio Source</span><br><span class="line"> Attribute ID: Service Class ID List</span><br><span class="line"> Value</span><br><span class="line"> Service Attribute: Protocol Descriptor List (0x4), value = L2CAP:25 -> AVDTP (1.3)</span><br><span class="line"> Attribute ID: Protocol Descriptor List</span><br><span class="line"> Value</span><br><span class="line"> Service Attribute: Bluetooth Profile Descriptor List (0x9), value = Advanced Audio Distribution 1.3</span><br><span class="line"> Attribute ID: Bluetooth Profile Descriptor List</span><br><span class="line"> Value</span><br><span class="line"> Continuation State: no (00)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#连接</span><br><span class="line">> 147 1.006617 localhost () XiaomiCo_6e:38:c5 (PHONE) L2CAP 17 Sent Connection Request (AVDTP, SCID: 0x0043)</span><br><span class="line">> 155 1.017317 XiaomiCo_6e:38:c5 (PHONE) localhost () L2CAP 21 Rcvd Connection Response - Success (SCID: 0x0043, DCID: 0x0042)</span><br></pre></td></tr></table></figure>
<h2 id="AVRCP"><a href="#AVRCP" class="headerlink" title="AVRCP"></a>AVRCP</h2><p>**AVRCP:Audio/Video Remote Control Profile(音频/视频远程控制配置文件)**,用于控制蓝牙音乐的标准接口。</p>
<p>在AVRCP中,<strong>TG</strong>表示播放设备,<strong>CT</strong>表示控制设备。</p>
<h3 id="命令格式"><a href="#命令格式" class="headerlink" title="命令格式"></a>命令格式</h3><p>命令分为两个类型:VENDOR DEPENDENT 与PASS THROUGH,</p>
<ul>
<li><p>VENDOR DEPENDENT:通过<code>Ctype</code>与<code>PDU ID</code>来区分功能,<code>Ctype</code>有<strong>Control, Status , Notify</strong>,ACCEPTED,REJECTED, CHANGED,INTERIM,IMPLEMENTED,STABLE等。</p>
</li>
<li><p>PASS THROUGH:是播放控制命令,<code>Ctype</code>只有<strong>Control</strong>。</p>
</li>
</ul>
<p>其中请求命令<code>Ctype</code>为<strong>Notify</strong>,回复事件<code>Ctype</code>为<strong>Interim</strong>,事件通知<code>Ctype</code>为<strong>Changed</strong>。</p>
<h3 id="获取TG播放器支持功能"><a href="#获取TG播放器支持功能" class="headerlink" title="获取TG播放器支持功能"></a>获取TG播放器支持功能</h3><p><code>PDU ID</code>:GetFolderItems,通过<code>Scope</code>来区分功能,用于<strong>TG</strong>可以播放器列表与每个播放器支持的功能。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">> 307 1.551666 localhost () XiaomiCo_6e:38:c5 (PHONE) AVRCP 29 Sent Browsing: Command - GetFolderItems - Scope: MediaPlayerList, StartItem: 0x0000, EndItem: 0x0013</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth AVRCP Profile</span><br><span class="line"> PDU ID: GetFolderItems (0x71)</span><br><span class="line"> Parameter Length: 10</span><br><span class="line"> Scope: MediaPlayerList (0x00)</span><br><span class="line"> StartItem: 0</span><br><span class="line"> EndItem: 19</span><br><span class="line"> Attribute Count: All attributes are requested (0)</span><br><span class="line"> Attribute List</span><br><span class="line"></span><br><span class="line">> 326 1.651062 XiaomiCo_6e:38:c5 (PHONE) localhost () AVRCP 67 Rcvd Browsing: OK - GetFolderItems - UidCounter: 0x0000, NumberOfItems: 1</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth AVRCP Profile</span><br><span class="line"> PDU ID: GetFolderItems (0x71)</span><br><span class="line"> Parameter Length: 48</span><br><span class="line"> Status: OK (0x04)</span><br><span class="line"> UID Counter: 0x0000</span><br><span class="line"> Number Of Items: 1</span><br><span class="line"> Player: Music Player</span><br><span class="line"> Item Type: Media Player Item (0x01)</span><br><span class="line"> Item Length: 40</span><br><span class="line"> Player ID: 0</span><br><span class="line"> Major Player Type: Unknown (0x01)</span><br><span class="line"> Player SubType: Audio Book (0x00000001)</span><br><span class="line"> Play Status: Stopped (0x00)</span><br><span class="line"> Features</span><br><span class="line"> Not Used Features</span><br><span class="line"> .... ...1 = PASSTHROUGH Play: 0x1</span><br><span class="line"> .... ..1. = PASSTHROUGH Stop: 0x1</span><br><span class="line"> .... .1.. = PASSTHROUGH Pause: 0x1</span><br><span class="line"> ...1 .... = PASSTHROUGH Rewind: 0x1</span><br><span class="line"> ..1. .... = PASSTHROUGH FastForward: 0x1</span><br><span class="line"> 1... .... = PASSTHROUGH Forward: 0x1</span><br><span class="line"> .... ...1 = PASSTHROUGH Backward: 0x1</span><br><span class="line"> .... .1.. = Advanced Control Player: 0x1</span><br><span class="line"> Character Set: UTF-8 (106)</span><br><span class="line"> Displayable Name Length: 12</span><br><span class="line"> Displayable Name: Music Player</span><br></pre></td></tr></table></figure>
<h3 id="获取TG支持事件"><a href="#获取TG支持事件" class="headerlink" title="获取TG支持事件"></a>获取TG支持事件</h3><p><code>PDU ID</code>:GetCapabilities,用于<strong>TG</strong>可以支持的事件。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">> 288 1.233497 localhost () XiaomiCo_6e:38:c5 (PHONE) AVRCP 23 Sent Vendor dependent: Status - GetCapabilities(Events Supported)</span><br><span class="line">> 299 1.252688 XiaomiCo_6e:38:c5 (PHONE) localhost () AVRCP 30 Rcvd Vendor dependent: Stable - GetCapabilities(Events Supported) - Count: 6</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth AVRCP Profile</span><br><span class="line"> 0000 .... = Reserved: 0x0</span><br><span class="line"> .... 1100 = Ctype: Stable (0xc)</span><br><span class="line"> 0100 1... = Subunit Type: Panel (0x09)</span><br><span class="line"> .... .000 = Subunit ID: 0x0</span><br><span class="line"> Opcode: Vendor dependent (0x00)</span><br><span class="line"> Company ID: 00:19:58 (Bluetooth SIG, Inc.)</span><br><span class="line"> PDU ID: GetCapabilities (0x10)</span><br><span class="line"> 0000 00.. = RFA: 0x00</span><br><span class="line"> .... ..00 = Packet Type: Single (0x0)</span><br><span class="line"> Parameter Length: 8</span><br><span class="line"> Capability: Events Supported (0x03)</span><br><span class="line"> Capability Count: 0x06</span><br><span class="line"> Event ID: PlaybackStatusChanged (0x01)</span><br><span class="line"> Event ID: TrackChanged (0x02)</span><br><span class="line"> Event ID: PlaybackPositionChanged (0x05)</span><br><span class="line"> Event ID: AvailablePlayersChanged (0x0a)</span><br><span class="line"> Event ID: AddressedPlayerChanged (0x0b)</span><br><span class="line"> Event ID: NowPlayingContentChanged (0x09)</span><br><span class="line"> [Response Time: 19/1000ms]</span><br><span class="line"> [Command in frame: 288]</span><br></pre></td></tr></table></figure>
<h3 id="播放器状态"><a href="#播放器状态" class="headerlink" title="播放器状态"></a>播放器状态</h3><p><strong>CT</strong>端获取<strong>TC</strong>端播放状态,<code>Play Status</code>的参数由<code>GetFolderItems</code>原语获取,通过<code>Ctype</code>来区分操作。</p>
<h4 id="注册事件"><a href="#注册事件" class="headerlink" title="注册事件"></a>注册事件</h4><p><code>PDU ID</code>:RegisterNotification,<code>Event ID</code>为: PlaybackStatusChanged(<code>GetCapabilities</code>原语获取)。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">> 300 1.252942 localhost () XiaomiCo_6e:38:c5 (PHONE) AVRCP 27 Sent Vendor dependent: Notify - RegisterNotification - PlaybackStatusChanged</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth AVRCP Profile</span><br><span class="line"> 0000 .... = Reserved: 0x0</span><br><span class="line"> .... 0011 = Ctype: Notify (0x3)</span><br><span class="line"> 0100 1... = Subunit Type: Panel (0x09)</span><br><span class="line"> .... .000 = Subunit ID: 0x0</span><br><span class="line"> Opcode: Vendor dependent (0x00)</span><br><span class="line"> Company ID: 00:19:58 (Bluetooth SIG, Inc.)</span><br><span class="line"> PDU ID: RegisterNotification (0x31)</span><br><span class="line"> 0000 00.. = RFA: 0x00</span><br><span class="line"> .... ..00 = Packet Type: Single (0x0)</span><br><span class="line"> Parameter Length: 5</span><br><span class="line"> Event ID: PlaybackStatusChanged (0x01)</span><br><span class="line"> Interval: 0</span><br><span class="line"> [Response Time: 107/1000ms]</span><br><span class="line"> [Response in frame: 324]</span><br><span class="line"></span><br><span class="line">> 324 1.649874 XiaomiCo_6e:38:c5 (PHONE) localhost () AVRCP 24 Rcvd Vendor dependent: Interim - RegisterNotification - PlaybackStatusChanged - PlayStatus: Paused</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth AVRCP Profile</span><br><span class="line"> 0000 .... = Reserved: 0x0</span><br><span class="line"> .... 1111 = Ctype: Interim (0xf)</span><br><span class="line"> 0100 1... = Subunit Type: Panel (0x09)</span><br><span class="line"> .... .000 = Subunit ID: 0x0</span><br><span class="line"> Opcode: Vendor dependent (0x00)</span><br><span class="line"> Company ID: 00:19:58 (Bluetooth SIG, Inc.)</span><br><span class="line"> PDU ID: RegisterNotification (0x31)</span><br><span class="line"> 0000 00.. = RFA: 0x00</span><br><span class="line"> .... ..00 = Packet Type: Single (0x0)</span><br><span class="line"> Parameter Length: 2</span><br><span class="line"> Event ID: PlaybackStatusChanged (0x01)</span><br><span class="line"> Play Status: Paused (0x02)</span><br><span class="line"> [Response Time: 107/1000ms]</span><br><span class="line"> [Command in frame: 300]</span><br></pre></td></tr></table></figure>
<h4 id="事件通知"><a href="#事件通知" class="headerlink" title="事件通知"></a>事件通知</h4><p><code>PDU ID</code>:RegisterNotification,<code>Event ID</code>为: PlaybackStatusChanged,通过<code>Ctype</code>来区分功能。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">> 372 2.461590 XiaomiCo_6e:38:c5 (PHONE) localhost () AVRCP 24 Rcvd Vendor dependent: Changed - RegisterNotification - PlaybackStatusChanged - PlayStatus: Stopped</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth AVRCP Profile</span><br><span class="line"> 0000 .... = Reserved: 0x0</span><br><span class="line"> .... 1101 = Ctype: Changed (0xd)</span><br><span class="line"> 0100 1... = Subunit Type: Panel (0x09)</span><br><span class="line"> .... .000 = Subunit ID: 0x0</span><br><span class="line"> Opcode: Vendor dependent (0x00)</span><br><span class="line"> Company ID: 00:19:58 (Bluetooth SIG, Inc.)</span><br><span class="line"> PDU ID: RegisterNotification (0x31)</span><br><span class="line"> 0000 00.. = RFA: 0x00</span><br><span class="line"> .... ..00 = Packet Type: Single (0x0)</span><br><span class="line"> Parameter Length: 2</span><br><span class="line"> Event ID: PlaybackStatusChanged (0x01)</span><br><span class="line"> Play Status: Stopped (0x00)</span><br><span class="line"> [Response Time: 107/1000ms]</span><br><span class="line"> [Command in frame: 300]</span><br></pre></td></tr></table></figure>
<h4 id="主动获取"><a href="#主动获取" class="headerlink" title="主动获取"></a>主动获取</h4><p><code>PDU ID</code>:GetPlayStatus,往往与<code>RegisterNotification-TrackChanged</code>命令配合使用。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">> 466 18.051244 localhost () XiaomiCo_6e:38:c5 (PHONE) AVRCP 22 Sent Vendor dependent: Status - GetPlayStatus</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth AVRCP Profile</span><br><span class="line"> 0000 .... = Reserved: 0x0</span><br><span class="line"> .... 0001 = Ctype: Status (0x1)</span><br><span class="line"> 0100 1... = Subunit Type: Panel (0x09)</span><br><span class="line"> .... .000 = Subunit ID: 0x0</span><br><span class="line"> Opcode: Vendor dependent (0x00)</span><br><span class="line"> Company ID: 00:19:58 (Bluetooth SIG, Inc.)</span><br><span class="line"> PDU ID: GetPlayStatus (0x30)</span><br><span class="line"> 0000 00.. = RFA: 0x00</span><br><span class="line"> .... ..00 = Packet Type: Single (0x0)</span><br><span class="line"> Parameter Length: 0</span><br><span class="line"> [Response Time: 40/1000ms]</span><br><span class="line"> [Response in frame: 478]</span><br><span class="line"></span><br><span class="line">> 478 18.091970 XiaomiCo_6e:38:c5 (PHONE) localhost () AVRCP 31 Rcvd Vendor dependent: Stable - GetPlayStatus PlayStatus: Playing, SongPosition: 6118ms, SongLength: 175000ms</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth AVRCP Profile</span><br><span class="line"> 0000 .... = Reserved: 0x0</span><br><span class="line"> .... 1100 = Ctype: Stable (0xc)</span><br><span class="line"> 0100 1... = Subunit Type: Panel (0x09)</span><br><span class="line"> .... .000 = Subunit ID: 0x0</span><br><span class="line"> Opcode: Vendor dependent (0x00)</span><br><span class="line"> Company ID: 00:19:58 (Bluetooth SIG, Inc.)</span><br><span class="line"> PDU ID: GetPlayStatus (0x30)</span><br><span class="line"> 0000 00.. = RFA: 0x00</span><br><span class="line"> .... ..00 = Packet Type: Single (0x0)</span><br><span class="line"> Parameter Length: 9</span><br><span class="line"> Song Length: 175000</span><br><span class="line"> Song Position: 6118</span><br><span class="line"> Play Status: Playing (0x01)</span><br><span class="line"> [Response Time: 40/1000ms]</span><br><span class="line"> [Command in frame: 466]</span><br></pre></td></tr></table></figure>
<h3 id="播放进度"><a href="#播放进度" class="headerlink" title="播放进度"></a>播放进度</h3><p>使用<code>PDU ID</code>:GetPlayStatus,获取<strong>TG</strong>端播放进度,<strong>CT</strong>端轮循调用此命令。其中<code>Song Length</code>参数为音乐长度,<code>Song Position</code>为当前播放进度。日志参考<code>主动获取播放器</code>章节。</p>
<h3 id="音轨状态"><a href="#音轨状态" class="headerlink" title="音轨状态"></a>音轨状态</h3><p><strong>CT</strong>端获取<strong>TC</strong>端播放器音轨状态,状态有下面两种:</p>
<ul>
<li>无音轨:<code>Identifier: 0xffffffffffffffff (NOT SELECTED)</code></li>
<li>有音轨:<code>Identifier: 0x0000000000000000 (SELECTED)</code></li>
</ul>
<p><strong>音轨状态事件</strong>会在每次开始播放都会有事件,歌词就是通过发送<strong>音轨状态事件</strong>来完成的。</p>
<h4 id="注册事件-1"><a href="#注册事件-1" class="headerlink" title="注册事件"></a>注册事件</h4><p><code>PDU ID</code>:RegisterNotification,<code>Event ID</code>为: TrackChanged(<code>GetCapabilities</code>原语获取)。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">> 323 1.331254 localhost () XiaomiCo_6e:38:c5 (PHONE) AVRCP 27 Sent Vendor dependent: Notify - RegisterNotification - TrackChanged</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth AVRCP Profile</span><br><span class="line"> 0000 .... = Reserved: 0x0</span><br><span class="line"> .... 0011 = Ctype: Notify (0x3)</span><br><span class="line"> 0100 1... = Subunit Type: Panel (0x09)</span><br><span class="line"> .... .000 = Subunit ID: 0x0</span><br><span class="line"> Opcode: Vendor dependent (0x00)</span><br><span class="line"> Company ID: 00:19:58 (Bluetooth SIG, Inc.)</span><br><span class="line"> PDU ID: RegisterNotification (0x31)</span><br><span class="line"> 0000 00.. = RFA: 0x00</span><br><span class="line"> .... ..00 = Packet Type: Single (0x0)</span><br><span class="line"> Parameter Length: 5</span><br><span class="line"> Event ID: TrackChanged (0x02)</span><br><span class="line"> Interval: 0</span><br><span class="line"> [Response Time: 35/1000ms]</span><br><span class="line"> [Response in frame: 330]</span><br><span class="line"></span><br><span class="line">> 330 1.366518 XiaomiCo_6e:38:c5 (PHONE) localhost () AVRCP 31 Rcvd Vendor dependent: Interim - RegisterNotification - TrackChanged - 0xFFFFFFFFFFFFFFFF (NOT SELECTED)</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth AVRCP Profile</span><br><span class="line"> 0000 .... = Reserved: 0x0</span><br><span class="line"> .... 1111 = Ctype: Interim (0xf)</span><br><span class="line"> 0100 1... = Subunit Type: Panel (0x09)</span><br><span class="line"> .... .000 = Subunit ID: 0x0</span><br><span class="line"> Opcode: Vendor dependent (0x00)</span><br><span class="line"> Company ID: 00:19:58 (Bluetooth SIG, Inc.)</span><br><span class="line"> PDU ID: RegisterNotification (0x31)</span><br><span class="line"> 0000 00.. = RFA: 0x00</span><br><span class="line"> .... ..00 = Packet Type: Single (0x0)</span><br><span class="line"> Parameter Length: 9</span><br><span class="line"> Event ID: TrackChanged (0x02)</span><br><span class="line"> Identifier: 0xffffffffffffffff (NOT SELECTED)</span><br><span class="line"> [Response Time: 35/1000ms]</span><br><span class="line"> [Command in frame: 323]</span><br></pre></td></tr></table></figure>
<h4 id="事件通知-1"><a href="#事件通知-1" class="headerlink" title="事件通知"></a>事件通知</h4><p><code>PDU ID</code>:RegisterNotification,<code>Event ID</code>为: TrackChanged,通过<code>Ctype</code>来区分功能。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">> 451 18.026715 XiaomiCo_6e:38:c5 (PHONE) localhost () AVRCP 31 Rcvd Vendor dependent: Changed - RegisterNotification - TrackChanged - 0x0000000000000000 (SELECTED)</span><br></pre></td></tr></table></figure>
<h3 id="获取播放音轨的属性"><a href="#获取播放音轨的属性" class="headerlink" title="获取播放音轨的属性"></a>获取播放音轨的属性</h3><p>获取当前音轨,播放音乐的属性,如标题、歌手等信息。<code>Attribute List</code>请查看<a href="%E5%8F%82%E8%80%83">AVRCP协议规范</a>第26章节,往往与<code>RegisterNotification-TrackChanged</code>命令配合使用。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line">> 465 18.050915 localhost () XiaomiCo_6e:38:c5 (PHONE) AVRCP 59 Sent Vendor dependent: Status - GetElementAttributes - 0x0000000000000000 (PLAYING)</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth AVRCP Profile</span><br><span class="line"> 0000 .... = Reserved: 0x0</span><br><span class="line"> .... 0001 = Ctype: Status (0x1)</span><br><span class="line"> 0100 1... = Subunit Type: Panel (0x09)</span><br><span class="line"> .... .000 = Subunit ID: 0x0</span><br><span class="line"> Opcode: Vendor dependent (0x00)</span><br><span class="line"> Company ID: 00:19:58 (Bluetooth SIG, Inc.)</span><br><span class="line"> PDU ID: GetElementAttributes (0x20)</span><br><span class="line"> 0000 00.. = RFA: 0x00</span><br><span class="line"> .... ..00 = Packet Type: Single (0x0)</span><br><span class="line"> Parameter Length: 37</span><br><span class="line"> Identifier: 0x0000000000000000</span><br><span class="line"> Number of Attributes: 7</span><br><span class="line"> Attribute List</span><br><span class="line"> Attribute ID: Title (0x00000001)</span><br><span class="line"> Attribute ID: Artist (0x00000002)</span><br><span class="line"> Attribute ID: Album (0x00000003)</span><br><span class="line"> Attribute ID: Media Number (0x00000004)</span><br><span class="line"> Attribute ID: Total Number of Media (0x00000005)</span><br><span class="line"> Attribute ID: Genre (0x00000006)</span><br><span class="line"> Attribute ID: Playing Time (0x00000007)</span><br><span class="line"> [Response Time: 3/1000ms]</span><br><span class="line"> [Response in frame: 469]</span><br><span class="line"></span><br><span class="line">> 469 18.054345 XiaomiCo_6e:38:c5 (PHONE) localhost () AVRCP 127 Rcvd Vendor dependent: Stable - GetElementAttributes - Title: "Demons"</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth AVRCP Profile</span><br><span class="line"> 0000 .... = Reserved: 0x0</span><br><span class="line"> .... 1100 = Ctype: Stable (0xc)</span><br><span class="line"> 0100 1... = Subunit Type: Panel (0x09)</span><br><span class="line"> .... .000 = Subunit ID: 0x0</span><br><span class="line"> Opcode: Vendor dependent (0x00)</span><br><span class="line"> Company ID: 00:19:58 (Bluetooth SIG, Inc.)</span><br><span class="line"> PDU ID: GetElementAttributes (0x20)</span><br><span class="line"> 0000 00.. = RFA: 0x00</span><br><span class="line"> .... ..00 = Packet Type: Single (0x0)</span><br><span class="line"> Parameter Length: 105</span><br><span class="line"> Number of Attributes: 7</span><br><span class="line"> Attribute Entries</span><br><span class="line"> Attribute [ Title]: Demons</span><br><span class="line"> Attribute [ Artist]: Imagine Dragons</span><br><span class="line"> Attribute [ Album]: Continued Silence</span><br><span class="line"> Attribute [ Media Number]: 10</span><br><span class="line"> Attribute [Total Number of Media]: 18</span><br><span class="line"> Attribute [ Genre]: </span><br><span class="line"> Attribute [ Playing Time]: 175000</span><br><span class="line"> [Response Time: 3/1000ms]</span><br><span class="line"> [Command in frame: 465]</span><br></pre></td></tr></table></figure>
<h3 id="播放器控制"><a href="#播放器控制" class="headerlink" title="播放器控制"></a>播放器控制</h3><p><strong>CT</strong>控制<strong>TG</strong>播放器的相关命令,都是PASS THROUGH类型,通过<code>Operation ID</code>来区分功能,通过<code>Ctype</code>来区分操作。</p>
<h4 id="播放"><a href="#播放" class="headerlink" title="播放"></a>播放</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">> 298 1.252592 localhost () XiaomiCo_6e:38:c5 (PHONE) AVRCP 17 Sent Pass Through: Control - PLAY (Pushed)</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth AVRCP Profile</span><br><span class="line"> 0000 .... = Reserved: 0x0</span><br><span class="line"> .... 0000 = Ctype: Control (0x0)</span><br><span class="line"> 0100 1... = Subunit Type: Panel (0x09)</span><br><span class="line"> .... .000 = Subunit ID: 0x0</span><br><span class="line"> Opcode: Pass Through (0x7c)</span><br><span class="line"> 0... .... = State: Pushed (0x0)</span><br><span class="line"> .100 0100 = Operation ID: PLAY (0x44)</span><br><span class="line"> Data Length: 0x00</span><br><span class="line"> [Response Time: 14/200ms]</span><br><span class="line"> [Response in frame: 308]</span><br><span class="line"></span><br><span class="line">>308 1.266992 XiaomiCo_6e:38:c5 (PHONE) localhost () AVRCP 17 Rcvd Pass Through: Accepted - PLAY (Pushed)</span><br></pre></td></tr></table></figure>
<h4 id="暂停"><a href="#暂停" class="headerlink" title="暂停"></a>暂停</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">> 430 7.424245 localhost () XiaomiCo_6e:38:c5 (PHONE) AVRCP 17 Sent Pass Through: Control - PAUSE (Pushed)</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth AVRCP Profile</span><br><span class="line"> 0000 .... = Reserved: 0x0</span><br><span class="line"> .... 0000 = Ctype: Control (0x0)</span><br><span class="line"> 0100 1... = Subunit Type: Panel (0x09)</span><br><span class="line"> .... .000 = Subunit ID: 0x0</span><br><span class="line"> Opcode: Pass Through (0x7c)</span><br><span class="line"> 0... .... = State: Pushed (0x0)</span><br><span class="line"> .100 0110 = Operation ID: PAUSE (0x46)</span><br><span class="line"> Data Length: 0x00</span><br><span class="line"> [Response Time: 70/200ms]</span><br><span class="line"> [Response in frame: 434]</span><br><span class="line"></span><br><span class="line">> 434 7.494377 XiaomiCo_6e:38:c5 (PHONE) localhost () AVRCP 17 Rcvd Pass Through: Accepted - PAUSE (Pushed)</span><br></pre></td></tr></table></figure>
<h4 id="下一曲"><a href="#下一曲" class="headerlink" title="下一曲"></a>下一曲</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">> 1163 40.755874 localhost () XiaomiCo_6e:38:c5 (PHONE) AVRCP 17 Sent Pass Through: Control - BACKWARD (Pushed)</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth AVRCP Profile</span><br><span class="line"> 0000 .... = Reserved: 0x0</span><br><span class="line"> .... 0000 = Ctype: Control (0x0)</span><br><span class="line"> 0100 1... = Subunit Type: Panel (0x09)</span><br><span class="line"> .... .000 = Subunit ID: 0x0</span><br><span class="line"> Opcode: Pass Through (0x7c)</span><br><span class="line"> 0... .... = State: Pushed (0x0)</span><br><span class="line"> .100 1100 = Operation ID: BACKWARD (0x4c)</span><br><span class="line"> Data Length: 0x00</span><br><span class="line"> [Response Time: 15/200ms]</span><br><span class="line"> [Response in frame: 1168]</span><br><span class="line"></span><br><span class="line">> 1168 40.771498 XiaomiCo_6e:38:c5 (PHONE) localhost () AVRCP 17 Rcvd Pass Through: Accepted - BACKWARD (Pushed)</span><br></pre></td></tr></table></figure>
<h4 id="上一曲"><a href="#上一曲" class="headerlink" title="上一曲"></a>上一曲</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">> 969 37.736799 localhost () XiaomiCo_6e:38:c5 (PHONE) AVRCP 17 Sent Pass Through: Control - FORWARD (Pushed)</span><br><span class="line">---------------------------------------------------------------------------</span><br><span class="line">Bluetooth AVRCP Profile</span><br><span class="line"> 0000 .... = Reserved: 0x0</span><br><span class="line"> .... 0000 = Ctype: Control (0x0)</span><br><span class="line"> 0100 1... = Subunit Type: Panel (0x09)</span><br><span class="line"> .... .000 = Subunit ID: 0x0</span><br><span class="line"> Opcode: Pass Through (0x7c)</span><br><span class="line"> 0... .... = State: Pushed (0x0)</span><br><span class="line"> .100 1011 = Operation ID: FORWARD (0x4b)</span><br><span class="line"> Data Length: 0x00</span><br><span class="line"> [Response Time: 25/200ms]</span><br><span class="line"> [Response in frame: 976]</span><br><span class="line"></span><br><span class="line">> 976 37.762691 XiaomiCo_6e:38:c5 (PHONE) localhost () AVRCP 17 Rcvd Pass Through: Accepted - FORWARD (Pushed)</span><br></pre></td></tr></table></figure>
<h1 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h1><ul>
<li>蓝牙核心协议规范<a target="_blank" rel="noopener" href="https://www.bluetooth.org/DocMan/handlers/DownloadDoc.ashx?doc_id=286439">Core_v4.2.pdf</a></li>
<li>PBAP协议规范<a target="_blank" rel="noopener" href="https://www.bluetooth.com/specifications/specs/phone-book-access-profile-1-2-3/">PBAP_v1.2.3.pdf</a></li>
<li>HFP协议规范<a target="_blank" rel="noopener" href="https://www.bluetooth.com/specifications/specs/hands-free-profile-1-8/">HFP_v1.8.pdf</a></li>
<li>AVDTP协议规范<a target="_blank" rel="noopener" href="https://www.bluetooth.com/specifications/specs/a-v-distribution-transport-protocol-1-3/">AVDTP_SPEC_V13.pdf</a></li>
<li>AVCTP协议规范<a target="_blank" rel="noopener" href="https://www.bluetooth.com/specifications/specs/a-v-%e2%80%8b%e2%80%8bcontrol-transport-protocol-1-4/">AVCTP_SPEC_V14.pdf</a></li>
<li>AVRCP协议规范<a target="_blank" rel="noopener" href="https://www.bluetooth.com/specifications/specs/a-v-remote-control-profile-1-6-2/">AVRCP_v1.6.2.pdf</a></li>
<li><a target="_blank" rel="noopener" href="https://blog.csdn.net/wenzongliang/article/details/84689377">蓝牙物理链路类型:SCO和ACL链路与A2DP</a></li>
<li><a target="_blank" rel="noopener" href="https://blog.csdn.net/XiaoXiaoPengBo/article/details/107792407">安全简单配对</a></li>
<li><a target="_blank" rel="noopener" href="https://blog.csdn.net/u010657219/article/details/42192481">在HCI层看蓝牙的连接过程</a></li>
<li><a target="_blank" rel="noopener" href="https://www.cnblogs.com/libs-liu/p/9498952.html">蓝牙SDP协议概述 </a></li>
<li><a target="_blank" rel="noopener" href="https://blog.csdn.net/XiaoXiaoPengBo/article/details/108125755">RFCOMM协议概念介绍</a></li>
<li><a target="_blank" rel="noopener" href="https://blog.51cto.com/u_2982693/3521456">蓝牙的OBEX协议</a></li>
<li><a target="_blank" rel="noopener" href="https://blog.csdn.net/weixin_44260005/article/details/105223139">蓝牙电话之PBAP协议分析</a></li>
<li><a target="_blank" rel="noopener" href="https://blog.csdn.net/shichaog/article/details/52123439">蓝牙之八-HFP</a></li>
<li><a target="_blank" rel="noopener" href="https://blog.csdn.net/shichaog/article/details/52126415">蓝牙之九-AT命令</a></li>
</ul>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
<link itemprop="mainEntityOfPage" href="https://blog.liaoheng.me/2022/02/24/thread-block-and-suspend/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.jpg">
<meta itemprop="name" content="liaoheng">
<meta itemprop="description" content="A developer">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="liaoheng`s blog">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2022/02/24/thread-block-and-suspend/" class="post-title-link" itemprop="url">线程(进程)的阻塞与挂起</a>
</h2>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建时间:2022-02-24 14:10:13" itemprop="dateCreated datePublished" datetime="2022-02-24T14:10:13+08:00">2022-02-24</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar-check"></i>
</span>
<span class="post-meta-item-text">更新于</span>
<time title="修改时间:2024-02-21 12:35:23" itemprop="dateModified" datetime="2024-02-21T12:35:23+08:00">2024-02-21</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h1 id="阻塞与挂起"><a href="#阻塞与挂起" class="headerlink" title="阻塞与挂起"></a>阻塞与挂起</h1><h2 id="挂起-suspend"><a href="#挂起-suspend" class="headerlink" title="挂起(suspend)"></a>挂起(suspend)</h2><blockquote>
<p>是指在操作系统进程管理将前台的进程暂停(suspend)并转入后台的动作。将进程挂起可以让用户在前台执行其他的进程。挂起的进程通常释放除CPU以外已经占有的系统资源,如内存等。</p>
</blockquote>
<h2 id="阻塞-block"><a href="#阻塞-block" class="headerlink" title="阻塞(block)"></a>阻塞(block)</h2><blockquote>
<p>正在执行的进程由于发生某时间(如I/O请求、申请缓冲区失败等)暂时无法继续执行。此时引起进程调度,OS把处理机分配给另一个就绪进程,而让受阻进程处于暂停状态,一般将这种状态称为阻塞状态。</p>
</blockquote>
<h2 id="两者的区别"><a href="#两者的区别" class="headerlink" title="两者的区别"></a>两者的区别</h2><p><strong>挂起</strong>是一种主动行为,因此恢复也应该要主动完成;</p>
<p><strong>阻塞</strong>则是一种被动行为,恢复交由系统完成。而且挂起队列在操作系统里可以看成一个,而阻塞队列则是不同的事件或资源(如信号量)就有自己的队列。</p>
<p><img data-src="https://pic.liaoheng.me/hc-pic/2024/02/3c148cfcf29b361b01d9002250f52873.jpg"></p>
<ul>
<li>运行中<strong>挂起</strong>,进入<code>静止就绪</code>状态,<em>释放资源</em>,自身对换到外存中,不释放锁,也不释放CPU,比如sleep();</li>
<li>而运行中<strong>阻塞</strong>,进入<code>活动阻塞</code>状态,<em>释放资源</em>,释放锁,释放CPU,比如wait()。</li>
</ul>
<p>也就是说<strong>挂起</strong>在运行状态中要比<strong>阻塞</strong>靠前,<strong>挂起</strong>是一直在内存中定期运行自己,检查是否可以跳出当前状态;<strong>阻塞</strong>是自己不在运行,需要第三方检查自己是否可以跳出当前状态,在一定条件下也会由操作系统将其移出内存保存到外存中。</p>
<h2 id="Java中的线程与锁与其的关系"><a href="#Java中的线程与锁与其的关系" class="headerlink" title="Java中的线程与锁与其的关系"></a>Java中的线程与锁与其的关系</h2><p>Java 的 <a target="_blank" rel="noopener" href="https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.State.html">Thread.State</a> 中定义了线程的 6 种状态,分别如下:</p>
<ol>
<li>NEW 未启动的,不会出现在 dump 文件中 (可以通过 jstack命令查看线程堆栈)</li>
<li>RUNNABLE 正在 JVM 中执行的</li>
<li>BLOCKED 被阻塞,等待获取监视器锁进入 synchronized 代码块或者在调用Object.wait 之后重新进入 synchronized 代码块</li>
<li>WAITING 无限期等待另一个线程执行特定动作后唤醒它,也就是调用Object.wait 后会等待拥有同一个监视器锁的线程调用 notify/notifyAll来进行唤醒</li>
<li>TIMED_WAITING 有时限的等待另一个线程执行特定动作</li>
<li>TERMINATED 已经完成了执行</li>
</ol>
<h3 id="Thread-sleep"><a href="#Thread-sleep" class="headerlink" title="Thread.sleep"></a>Thread.sleep</h3><p>也就是说这是<code>挂起(suspend)</code>,作用域在线程,持有CPU。</p>
<h3 id="Object-wait-x2F-synchronized"><a href="#Object-wait-x2F-synchronized" class="headerlink" title="Object.wait/synchronized"></a>Object.wait/synchronized</h3><p>也就是说这是<code>阻塞(block)</code>,作用域在锁对象,释放CPU。</p>
<blockquote>
<p><code>wait/notify</code>是通过 JVM里的<strong>park/unpark</strong> 机制来实现的,在Linux下这种机制又是通过<strong>pthread_cond_wait/pthread_cond_signal</strong>实现。</p>
</blockquote>
<h3 id="Lock"><a href="#Lock" class="headerlink" title="Lock"></a>Lock</h3><p>也就是说这是<code>挂起(suspend)</code>,作用域在锁对象,持有CPU。</p>
<blockquote>
<p>Lock 用的是乐观锁机制。所谓乐观锁就是,每次不加锁而是假设没有冲突而去完成某项操作,如果因为冲突失败就重试,直到成功为止。</p>
</blockquote>
<h1 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h1><ul>
<li><a target="_blank" rel="noopener" href="https://blog.csdn.net/weixin_37641832/article/details/83217104">操作系统——CPU和内存、挂起和阻塞</a></li>
<li><a target="_blank" rel="noopener" href="https://generalthink.github.io/2019/10/10/analysis-java-object-wait-notify/">分析Java Object 中的 wait/notify</a></li>
<li><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/4c1ed2048985">synchronized(this/.class/Object),synchronize方法区别</a></li>
<li><a target="_blank" rel="noopener" href="https://www.baeldung.com/java-thread-lifecycle">Life Cycle of a Thread in Java</a></li>
<li><a target="_blank" rel="noopener" href="https://xie.infoq.cn/article/4e370ded27e4419d2a94a44b3">Synchronized 和 lock 区别</a></li>
</ul>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
<link itemprop="mainEntityOfPage" href="https://blog.liaoheng.me/2021/07/28/installation-arch-linux-summary/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.jpg">
<meta itemprop="name" content="liaoheng">
<meta itemprop="description" content="A developer">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="liaoheng`s blog">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2021/07/28/installation-arch-linux-summary/" class="post-title-link" itemprop="url">安装Arch Linux小结</a>
</h2>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建时间:2021-07-28 13:48:38" itemprop="dateCreated datePublished" datetime="2021-07-28T13:48:38+08:00">2021-07-28</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar-check"></i>
</span>
<span class="post-meta-item-text">更新于</span>
<time title="修改时间:2024-02-21 12:24:03" itemprop="dateModified" datetime="2024-02-21T12:24:03+08:00">2024-02-21</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<img data-src="https://archlinux.org/static/logos/archlinux-logo-dark-1200dpi.b42bd35d5916.png" style="zoom:5%;" />
<p>本人跟随<a target="_blank" rel="noopener" href="https://wiki.archlinux.org/title/Installation_guide_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)">Arch Linux官方安装指南</a>操作过程的一些记录。</p>
<h2 id="准备"><a href="#准备" class="headerlink" title="准备"></a>准备</h2><blockquote>
<p> 下载ISO文件并启动到 Live 环境,注意<a target="_blank" rel="noopener" href="https://wiki.archlinux.org/title/Unified_Extensible_Firmware_Interface_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)/Secure_Boot_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)">安全启动(Secure Boot)</a>的问题。</p>
</blockquote>
<p><a target="_blank" rel="noopener" href="https://archlinux.org/download/">官方下载地址</a></p>
<h3 id="验证启动模式-非必须"><a href="#验证启动模式-非必须" class="headerlink" title="验证启动模式(非必须)"></a>验证启动模式(非必须)</h3><p>请用下列命令列出 <a target="_blank" rel="noopener" href="https://wiki.archlinux.org/index.php/Efivars">efivars</a> 目录:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ls /sys/firmware/efi/efivars</span><br></pre></td></tr></table></figure>
<p>目录存在,操作系统使用UEFI模式启动,反之使用传统模式启动(BIOS,CSM)。</p>
<h3 id="网络连接"><a href="#网络连接" class="headerlink" title="网络连接"></a>网络连接</h3><p><strong>安装过程需要连接互联网</strong>,Live环境默认开启DHCP,其它方式可以参考<a target="_blank" rel="noopener" href="https://wiki.archlinux.org/index.php/Installation_guide_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)#%E8%BF%9E%E6%8E%A5%E5%88%B0%E5%9B%A0%E7%89%B9%E7%BD%91">连接到因特网</a>,</p>
<h3 id="更新系统时间"><a href="#更新系统时间" class="headerlink" title="更新系统时间"></a>更新系统时间</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">timedatectl set-ntp true</span><br></pre></td></tr></table></figure>
<h3 id="建立硬盘分区"><a href="#建立硬盘分区" class="headerlink" title="建立硬盘分区"></a>建立硬盘分区</h3><blockquote>
<p>使用<code>fdisk</code>分区,可以查看这篇<a target="_blank" rel="noopener" href="https://www.cnblogs.com/lsgxeva/p/9610003.html">博文</a>有详细的使用说明</p>
</blockquote>
<p>查看分区列表</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">fdisk -l</span><br></pre></td></tr></table></figure>
<p><img data-src="https://pic.liaoheng.me/hc-pic/2024/02/93503db3f240a11f738fc5c37e0287a2.png"></p>
<p>其中<code>/dev/sda</code>代表第一块物理磁盘(<code>/dev/sdb,/dev/sdc</code>与之类推)</p>
<p>操作对应磁盘(<code>/dev/sda</code>)分区</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">fdisk /dev/sda</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">进入fdisk应用命令行:</span></span><br><span class="line">g #如果没有分区表或者是MBR表先删除,创建一个新的空GPT分区表</span><br><span class="line">n #创建新的分区</span><br><span class="line">t #改变分区类型</span><br><span class="line">w #保存并退出</span><br></pre></td></tr></table></figure>
<p><img data-src="https://pic.liaoheng.me/hc-pic/2024/02/4811eca3d0b3a9f324247b14d39e571b.png"></p>
<p>新建分区之后需要指定分区类型,使用命令<code>t {partition number }</code>,可以参考下表配置分区:</p>