-
Notifications
You must be signed in to change notification settings - Fork 6
/
rtbth_hlpr_linux.c
859 lines (673 loc) · 18.5 KB
/
rtbth_hlpr_linux.c
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
/*
*************************************************************************
* Ralink Technology Corporation
* 5F., No. 5, Taiyuan 1st St., Jhubei City,
* Hsinchu County 302,
* Taiwan, R.O.C.
*
* (c) Copyright 2012, Ralink Technology Corporation
*
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
*************************************************************************/
#include "include/rtbt_osabl.h"
#include "include/rt_linux.h"
static DEFINE_SPINLOCK(g_reslock);
/*******************************************************************************
Message dump/printing related functions.
*******************************************************************************/
int RtlStringCchPrintfA(
IN char *str,
IN int len,
IN const char *format,
...)
{
va_list args;
int i;
va_start(args, format);
i = vsnprintf(str, len, format, args);
va_end(args);
return i;
}
/*******************************************************************************
Memory operation related functions.
*******************************************************************************/
void *ral_mem_valloc(int size)
{
return vmalloc(size);
}
int ral_mem_vfree(void *ptr)
{
vfree(ptr);
return TRUE;
}
void *ral_mem_alloc(int size, RAL_MEM_FLAG memFlag)
{
void *pMemPtr = NULL;
if (memFlag == RAL_MEM_NORMAL)
pMemPtr = kmalloc(size, GFP_KERNEL);
return pMemPtr;
}
int ral_mem_free(void *ptr)
{
kfree(ptr);
return TRUE;
}
int RtlCopyMemory(
IN VOID *Destination,
IN const VOID *Source,
IN int Length)
{
return (int)memcpy(Destination, Source, Length);//sean wang linux, fix the build warning, type casting
}
VOID RtlZeroMemory(
IN VOID *Destination,
IN int Length)
{
memset(Destination, 0, Length);
}
VOID RtlFillMemory(
IN VOID *Destination,
IN int c,
IN int Length)
{
memset(Destination, c, Length);
}
int RtlCompareMemory(
IN VOID *s1,
IN VOID *s2,
IN int size)
{
return memcmp(s1, s2, size);
}
/*******************************************************************************
Lock/Synchronization related functions.
*******************************************************************************/
int ral_spin_lock(KSPIN_LOCK *pLock, unsigned long *irq_flag)
{
unsigned long local_flag;
if (!pLock->pOSLock) {
printk("Error, invalid lock structure!\n");
dump_stack();
return FALSE;
}
spin_lock_irqsave(&g_reslock, local_flag);
if (pLock->state == RES_INVALID) {
spin_unlock_irqrestore(&g_reslock, local_flag);
printk("Error, try to lock a invalid structure!\n");
return FALSE;
}
else {
pLock->ref_cnt++;
pLock->state = RES_INUSE;
}
spin_unlock_irqrestore(&g_reslock, local_flag);
spin_lock_irqsave((spinlock_t *)pLock->pOSLock, *irq_flag);
return TRUE;
}
int ral_spin_unlock(KSPIN_LOCK *pLock, unsigned long irq_flag)
{
unsigned long local_flag;
spin_unlock_irqrestore((spinlock_t *)pLock->pOSLock, irq_flag);
spin_lock_irqsave(&g_reslock, local_flag);
if (pLock->ref_cnt == 0) {
printk("Error, unlock a not acquired spin!\n");
dump_stack();
}
pLock->ref_cnt --;
if (pLock->state == RES_INUSE && pLock->ref_cnt == 0)
pLock->state = RES_VALID;
spin_unlock_irqrestore(&g_reslock, local_flag);
return TRUE;
}
int ral_spin_init(KSPIN_LOCK *pLock)
{
int flags;
spinlock_t *pSpinLock;
unsigned long irq_flags;
if (in_interrupt())
flags = GFP_ATOMIC;
else
flags = GFP_KERNEL;
memset(pLock, 0, sizeof(KSPIN_LOCK));
pSpinLock = kmalloc(sizeof(spinlock_t), flags);
if (pSpinLock){
pLock->pOSLock = pSpinLock;
spin_lock_init(pSpinLock);
spin_lock_irqsave(&g_reslock, irq_flags);
pLock->state = RES_VALID;
pLock->ref_cnt = 0;
spin_unlock_irqrestore(&g_reslock, irq_flags);
return 0;
}
return -1;
}
int ral_spin_deinit(KSPIN_LOCK *pLock)
{
unsigned long irq_flags;
if (pLock->pOSLock) {
spin_lock_irqsave(&g_reslock, irq_flags);
if (pLock->state == RES_INUSE) {
spin_unlock_irqrestore(&g_reslock, irq_flags);
printk("Error, free a in_used spin!\n");
dump_stack();
} else {
pLock->state = RES_INVALID;
spin_unlock_irqrestore(&g_reslock, irq_flags);
kfree(pLock->pOSLock);
pLock->pOSLock = NULL;
}
}
return TRUE;
}
/*
Work around to make Windows feel fun!
*/
// TODO: Shiang, following functions need to revised!!
int KeAcquireSpinLockAtDpcLevel(KSPIN_LOCK *pLock)
{
// Do spin lock in Dpc level, it actually just return directly.
//printk("%s(): TODO!!!\n", __FUNCTION__);
return TRUE;
}
int KeReleaseSpinLockFromDpcLevel(KSPIN_LOCK *pLock)
{
// Do spin lock in Dpc level, it actually just return directly.
//printk("%s(): TODO!!!\n", __FUNCTION__);
return TRUE;
}
/*******************************************************************************
Eventing system related functions.
*******************************************************************************/
LONG KeSetEvent(
INOUT KEVENT *Event,
IN KPRIORITY Increment,
IN BOOLEAN Wait)
{
return 0;
}
NTSTATUS KeWaitForSingleObject(
IN KEVENT *Object,
IN int WaitReason,
IN int WaitMode,
IN BOOLEAN Alertable,
IN PLARGE_INTEGER Timeout)
{
return 0;
}
NTSTATUS KeInitializeEvent(
IN KEVENT *pEventObj,
IN int Type,
IN EVENT_STATE init_state)
{
NTSTATUS status= STATUS_SUCCESS;
struct semaphore *pSema;
int initVal, flags;
/* First allocate the memory space for Event Object */
flags = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
pSema = kmalloc(sizeof(struct semaphore), flags);
if (pSema){
initVal = ((init_state == EVENT_LOCKED) ? 0 : 1);
printk("Create Event with status %s\n", (initVal == 1 ? "UNLOCKED" : "LOCKED"));
sema_init(pSema, initVal);
pEventObj->pOSEvent = pSema;
}
else
status = STATUS_FAILURE;
return status;
}
NTSTATUS KeDestoryEvent(
IN KEVENT *pEventObj)
{
if (pEventObj->pOSEvent)
kfree(pEventObj->pOSEvent);
return TRUE;
}
ULONG KeQuerySystemTime(LARGE_INTEGER *timeval)
{
ULONG nowTime = jiffies;
timeval->QuadPart = nowTime;
return nowTime;
}
// Unify all delay routine by using NdisStallExecution
VOID rtbt_usec_delay(
IN ULONG usec)
{
ULONG i;
for (i = 0; i < (usec / 50); i++)
udelay(50);
if (usec % 50)
udelay(usec % 50);
}
/*
*/
// TODO: Change this windows function to a generic function name
void KeStallExecutionProcessor(
IN ULONG usec)
{
rtbt_usec_delay(usec);
}
BOOLEAN KeSetTimer(
IN KTIMER *os_timer,
IN LARGE_INTEGER msec,
IN PKDPC Dpc)
{
struct timer_list *timer;
unsigned long irqflags, expires;
ral_spin_lock(&os_timer->lock, &irqflags);
if ((os_timer->state == RES_INVALID) || (!os_timer->pOSTimer)) {
printk("os_timer invalid state(%d) or timer structure(0x%p) is NULL!\n",
os_timer->state, os_timer->pOSTimer);
ral_spin_unlock(&os_timer->lock, irqflags);
return FALSE;
}
timer = os_timer->pOSTimer;
expires = msec.QuadPart * HZ / 1000;
timer->expires = jiffies + expires;
// printk("set timer->expires as 0x%x, original msec=0x%x, now jiffies=0x%x!\n", timer->expires, msec.QuadPart, jiffies);
if (timer_pending(timer))
mod_timer(timer, timer->expires);
else {
os_timer->dpc.func = (void *)Dpc->func;
os_timer->dpc.data = (long)Dpc->data;
add_timer(timer);
}
ral_spin_unlock(&os_timer->lock, irqflags);
return FALSE;
}
BOOLEAN KeCancelTimer(
IN KTIMER *os_timer)
{
int status;
unsigned long irqflags;
ral_spin_lock(&os_timer->lock, &irqflags);
if (os_timer->pOSTimer && (os_timer->state == RES_VALID)) {
status = del_timer_sync((struct timer_list *)os_timer->pOSTimer);
if (status < 0)
printk("%s(): del os timer failed(%d)!\n", __FUNCTION__, status);
}
ral_spin_unlock(&os_timer->lock, irqflags);
return TRUE;
}
INT KeFreeTimer(
IN PKTIMER os_timer)
{
struct timer_list *timer;
unsigned long irqflags;
if (os_timer->state == RES_INVALID)
return 0;
ral_spin_lock(&os_timer->lock, &irqflags);
os_timer->state = RES_INVALID;
ral_spin_unlock(&os_timer->lock, irqflags);
if (os_timer->pOSTimer) {
timer = (struct timer_list *)os_timer->pOSTimer;
if (timer_pending(timer))
del_timer_sync(timer);
kfree(timer);
os_timer->pOSTimer = NULL;
}
ral_spin_deinit(&os_timer->lock);
return 0;
}
INT ral_timer_init(
IN PKTIMER os_timer,
IN ULONG func)
{
unsigned long irqflags;
struct timer_list *timer;
memset(os_timer, 0, sizeof(KTIMER));
if (ral_spin_init(&os_timer->lock))
return -1;
os_timer->pOSTimer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
if (os_timer->pOSTimer) {
timer = os_timer->pOSTimer;
init_timer(timer);
timer->function = (void *)func;
timer->data = (unsigned long)os_timer;
ral_spin_lock(&os_timer->lock, &irqflags);
os_timer->state = RES_VALID;
ral_spin_unlock(&os_timer->lock, irqflags);
return 0;
} else {
ral_spin_deinit(&os_timer->lock);
return -1;
}
}
VOID KeInitializeDpc(
OUT PKDPC Dpc,
IN PKDEFERRED_ROUTINE DeferredRoutine,
IN PVOID DeferredContext)
{
Dpc->func = (PKDEFERRED_ROUTINE)DeferredRoutine;
Dpc->data = (ULONG)DeferredContext;
}
int ral_file_obj_init(PSTRING FileName, RAL_FILE **pFileHd)
{
/* struct file *pf; */
int status = STATUS_FAILURE;
*pFileHd = NULL;
return status;
}
/* this function only support for READ only. */
int ral_file_open(RAL_FILE *pFileHd, RTBT_FILE_OP_MODE opMode)
{
/* struct file *fp; */
int status = STATUS_FAILURE;
int flag;
if (pFileHd == NULL)
return status;
switch(opMode){
case RTBT_FOP_READ:
flag = 1; //O_RDONLY;
break;
default:
return STATUS_FAILURE;
}
return status;
}
int ral_file_read(RAL_FILE *pFileHd, void *pBuf, int len)
{
// TODO:
return FALSE;
}
int ral_file_write(RAL_FILE *pFileHd, void *pBuf, int len)
{
// TODO:
return FALSE;
}
int ral_file_close(RAL_FILE *pFileHd)
{
// TODO:
return FALSE;
}
int ral_file_obj_deinit(RAL_FILE *pFileHd)
{
// TODO:
return FALSE;
}
/*******************************************************************************
Task create/management/kill related functions.
*******************************************************************************/
NDIS_STATUS ral_task_kill(
IN KTHREAD *pTask)
{
int ret = STATUS_FAILURE;
RTBT_OS_TASK *pOSThread = (RTBT_OS_TASK *)pTask->pOSThread;
#ifdef KTHREAD_SUPPORT
if (pOSThread->kthread_task) {
kthread_stop(pOSThread->kthread_task);
ret = STATUS_SUCCESS;
}
#else
if(IS_VALID_PID(pOSThread->taskPID)) {
printk(KERN_WARNING "Terminate the task(%s) with pid(%d)!\n",
pOSThread->taskName, GET_PID_NUMBER(pOSThread->taskPID));
mb();
pOSThread->task_killed = 1;
mb();
ret = KILL_THREAD_PID(pOSThread->taskPID, SIGTERM, 1);
if (ret){
printk(KERN_WARNING "kill task(%s) with pid(%d) failed(retVal=%d)!\n",
pOSThread->taskName, GET_PID_NUMBER(pOSThread->taskPID), ret);
} else {
wait_for_completion(&pOSThread->taskComplete);
pOSThread->taskPID = THREAD_PID_INIT_VALUE;
pOSThread->task_killed = 0;
ret = STATUS_SUCCESS;
}
}
#endif
return ret;
}
INT ral_task_notify_exit(
IN KTHREAD *pTask)
{
RTBT_OS_TASK *pOSThread = (RTBT_OS_TASK *)pTask->pOSThread;
#ifndef KTHREAD_SUPPORT
complete_and_exit(&pOSThread->taskComplete, 0);
#endif
return 0;
}
void ral_task_customize(
IN KTHREAD *pTask)
{
RTBT_OS_TASK *pOSTask = (RTBT_OS_TASK *)pTask->pOSThread;
#ifndef KTHREAD_SUPPORT
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
//daemonize((PSTRING)&pOSTask->taskName[0]);
allow_signal(SIGTERM);
allow_signal(SIGKILL);
current->flags |= PF_NOFREEZE;
#else
unsigned long flags;
daemonize();
reparent_to_init();
strcpy(current->comm, &pOSTask->taskName[0]);
siginitsetinv(¤t->blocked, sigmask(SIGTERM) | sigmask(SIGKILL));
/* Allow interception of SIGKILL only
* Don't allow other signals to interrupt the transmission */
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,4,22)
spin_lock_irqsave(¤t->sigmask_lock, flags);
flush_signals(current);
recalc_sigpending(current);
spin_unlock_irqrestore(¤t->sigmask_lock, flags);
#endif
#endif
RTMP_GET_OS_PID(pOSTask->taskPID, current->pid);
/* signal that we've started the thread */
complete(&pOSTask->taskComplete);
#endif
}
int ral_task_attach(
IN KTHREAD *pTask,
IN RTBT_OS_TASK_CALLBACK fn,
IN ULONG arg)
{
RTBT_OS_TASK *pOSTask = (RTBT_OS_TASK *)pTask->pOSThread;
NDIS_STATUS status = STATUS_SUCCESS;
#ifndef KTHREAD_SUPPORT
pid_t pid_number = -1;
#endif // KTHREAD_SUPPORT //
#ifdef KTHREAD_SUPPORT
pOSTask->task_killed = 0;
pOSTask->kthread_task = NULL;
pOSTask->kthread_task = kthread_run(fn, (void *)arg, pOSTask->taskName);
if (IS_ERR(pOSTask->kthread_task))
status = STATUS_FAILURE;
#else
pid_number = kernel_thread(fn, (void *)arg, RTBT_OS_MGMT_TASK_FLAGS);
if (pid_number < 0) {
printk(KERN_WARNING "Attach task(%s) failed!\n", pOSTask->taskName);
status = STATUS_FAILURE;
} else {
// Wait for the thread to start
wait_for_completion(&pOSTask->taskComplete);
status = STATUS_SUCCESS;
}
#endif
printk("%s(): task attach done, status=%d\n", __FUNCTION__, status);
return status;
}
int ral_task_init(
IN KTHREAD *pTask,
IN PSTRING pTaskName,
IN VOID *pPriv)
{
int len;
RTBT_OS_TASK *pOSTask;
RTBT_ASSERT(pTask);
pTask->pOSThread = kmalloc(sizeof(RTBT_OS_TASK), GFP_KERNEL);
if (pTask->pOSThread == NULL)
return STATUS_FAILURE;
pOSTask = (RTBT_OS_TASK *)pTask->pOSThread;
#ifndef KTHREAD_SUPPORT
memset((PUCHAR)pOSTask, 0, sizeof(RTBT_OS_TASK));
#endif
len = strlen(pTaskName);
//len = len > (RTBT_OS_TASK_NAME_LEN -1) ? (RTBT_OS_TASK_NAME_LEN-1) : len;
memcpy(&pOSTask->taskName[0], pTaskName, len > (RTBT_OS_TASK_NAME_LEN -1) ? (RTBT_OS_TASK_NAME_LEN-1) : len);
pOSTask->priv = pPriv;
#ifndef KTHREAD_SUPPORT
RTMP_SEM_EVENT_INIT_LOCKED(&(pOSTask->taskSema));
pOSTask->taskPID = THREAD_PID_INIT_VALUE;
init_completion(&pOSTask->taskComplete);
#endif
return STATUS_SUCCESS;
}
int ral_task_deinit(
IN KTHREAD *pTask)
{
RTBT_OS_TASK *pOSTask;
RTBT_ASSERT(pTask);
if (pTask->refCnt > 1) {
DebugPrint(ERROR, DBG_MISC, "Err, pTask->refCnt=%d!\n", pTask->refCnt);
}
if (pTask->pOSThread) {
pOSTask = pTask->pOSThread;
RTMP_SEM_EVENT_DESTORY(&pOSTask->taskSema);
kfree(pTask->pOSThread);
pTask->pOSThread = NULL;
pTask->refCnt = 0;
}
return STATUS_SUCCESS;
}
#ifdef OS_ABL_SUPPORT
static struct rtbt_dev_entry *g_devlist = NULL;
static DEFINE_SPINLOCK(g_devlock);
void dump_dev_list(struct rtbt_dev_entry *devlist)
{
unsigned long irq_flag;
struct rtbt_dev_entry *dev_ent;
int cnt = 0;
int dump_all;
dump_all = devlist ? 0 : 1;
printk("Wrapper:dump the global dev list:\n");
spin_lock_irqsave(&g_devlock, irq_flag);
dev_ent = dump_all ? g_devlist : devlist;
while (dev_ent != NULL) {
struct ral_dev_id *dev_id;
printk("\tDevGroup[%d]:\n", cnt);
printk("\t\tinfType = %d\n", dev_ent->infType);
printk("\t\tdevType = %d\n", dev_ent->devType);
printk("\t\tdev_priv = 0x%p\n", dev_ent->dev_ops);
printk("\t\tos_priv = 0x%p\n", dev_ent->os_private);
printk("\t\tmlen = %d\n", dev_ent->mlen);
printk("\t\tdevIDList:\n");
if (dev_ent->pDevIDList) {
dev_id = dev_ent->pDevIDList;
while((dev_id->pid != 0) && (dev_id->vid != 0)) {
printk("\t\t\tPID:0x%02x, DID:0x%02x\n",
dev_id->pid, dev_id->vid);
dev_id++;
}
}
dev_ent = (dump_all ? dev_ent->next : NULL);
}
printk("\n\n");
spin_unlock_irqrestore(&g_devlock, irq_flag);
}
static int rtbt_dev_list_add(struct rtbt_dev_entry *devlist)
{
unsigned long irq_flag;
printk("%s(): add devlist from global list!\n", __FUNCTION__);
spin_lock_irqsave(&g_devlock, irq_flag);
devlist->next = g_devlist;
g_devlist = devlist;
spin_unlock_irqrestore(&g_devlock, irq_flag);
dump_dev_list(NULL);
return 0;
}
static int rtbt_dev_list_del(struct rtbt_dev_entry *devlist)
{
unsigned long irq_flag;
struct rtbt_dev_entry *head, *prev;
printk("%s(): remove devlist from global list!\n", __FUNCTION__);
spin_lock_irqsave(&g_devlock, irq_flag);
head = g_devlist;
while (head != NULL){
if (devlist == head)
break;
prev = head;
head = head->next;
}
if (head){
if (head == g_devlist)
g_devlist = head->next;
else
prev->next = head->next;
}
spin_unlock_irqrestore(&g_devlock, irq_flag);
dump_dev_list(NULL);
return 0;
}
static int __init rtbt_linux_init(void)
{
unsigned long irq_flag;
printk("-->%s()\n", __FUNCTION__);
spin_lock_init(&g_devlock);
spin_lock_init(&g_reslock);
spin_lock_irqsave(&g_devlock, irq_flag);
g_devlist = NULL;
spin_unlock_irqrestore(&g_devlock, irq_flag);
printk("<--%s(): g_devlist(@0x%lx)=0x%p!\n", __FUNCTION__, (ULONG)&g_devlist, g_devlist);
return 0;
}
static void __exit rtbt_linux_exit(void)
{
printk("-->%s()\n", __FUNCTION__);
while (g_devlist != NULL)
ral_os_unregister(g_devlist);
printk("<--%s(): g_devlist(@0x%lx)=0x%p!\n", __FUNCTION__, (ULONG)&g_devlist, g_devlist);
return;
}
MODULE_AUTHOR("Ralink Tech.");
MODULE_DESCRIPTION("Support for Ralink Bluetooth cards");
MODULE_SUPPORTED_DEVICE("Ralink Bluetooth cards");
MODULE_LICENSE("GPL");
module_init(rtbt_linux_init);
module_exit(rtbt_linux_exit);
#endif // OS_ABL_SUPPORT //
int ral_os_register(struct rtbt_dev_entry *pDevList)
{
int retVal = -1;
#ifdef OS_ABL_SUPPORT
rtbt_dev_list_add(pDevList);
#endif // OS_ABL_SUPPORT //
#ifdef RTBT_IFACE_PCI
if ((pDevList->infType == RAL_INF_PCI) &&
(pDevList->devType == RAL_DEV_BT)){
retVal = rtbt_iface_pci_hook(pDevList);
if (retVal)
printk("register device to OS failed\n");
}
#endif // RTBT_IFACE_PCI //
return retVal;
}
int ral_os_unregister(struct rtbt_dev_entry * pDevList)
{
int rv = -1;
#ifdef RTBT_IFACE_PCI
if (pDevList->infType == RAL_INF_PCI) {
rv = rtbt_iface_pci_unhook(pDevList);
if (rv)
printk("unregister device to OS failed\n");
}
#endif // RTBT_IFACE_PCI //
#ifdef OS_ABL_SUPPORT
rtbt_dev_list_del(pDevList);
#endif // OS_ABL_SUPPORT //
return rv;
}