Advertisement
Guest User

Untitled

a guest
Dec 7th, 2010
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.64 KB | None | 0 0
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #ifndef __OSDEP_SERVICE_H_
  21. #define __OSDEP_SERVICE_H_
  22.  
  23. #include <drv_conf.h>
  24. #include <basic_types.h>
  25. //#include <rtl871x_byteorder.h>
  26.  
  27. #define _SUCCESS 1
  28. #define _FAIL 0
  29.  
  30. #undef _TRUE
  31. #define _TRUE 1
  32.  
  33. #undef _FALSE
  34. #define _FALSE 0
  35.  
  36.  
  37. #ifdef PLATFORM_LINUX
  38. #include <linux/version.h>
  39. #include <linux/spinlock.h>
  40. #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26))
  41. #include <asm/semaphore.h>
  42. #else
  43. #include <linux/semaphore.h>
  44. #include <linux/sem.h>
  45. #include <linux/sched.h>
  46. #include <linux/netdevice.h>
  47. #include <linux/etherdevice.h>
  48. #include <net/iw_handler.h>
  49. #include <linux/proc_fs.h> // Necessary because we use the proc fs
  50. #endif
  51.  
  52. #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,22))
  53. #ifdef CONFIG_USB_SUSPEND
  54. #define CONFIG_AUTOSUSPEND 1
  55. #endif
  56. #endif
  57.  
  58.  
  59. #ifdef CONFIG_USB_HCI
  60. typedef struct urb * PURB;
  61. #endif
  62.  
  63. typedef struct semaphore _sema;
  64. typedef spinlock_t _lock;
  65. typedef struct semaphore _rwlock;
  66. typedef struct timer_list _timer;
  67.  
  68. struct __queue {
  69. struct list_head queue;
  70. _lock lock;
  71. };
  72.  
  73. typedef struct sk_buff _pkt;
  74. typedef unsigned char _buffer;
  75.  
  76. typedef struct __queue _queue;
  77. typedef struct list_head _list;
  78. typedef int _OS_STATUS;
  79. //typedef u32 _irqL;
  80. typedef unsigned long _irqL;
  81. typedef struct net_device * _nic_hdl;
  82.  
  83. typedef pid_t _thread_hdl_;
  84. typedef int thread_return;
  85. typedef void* thread_context;
  86.  
  87. #define thread_exit() complete_and_exit(NULL, 0)
  88.  
  89. typedef void timer_hdl_return;
  90. typedef void* timer_hdl_context;
  91. typedef struct work_struct _workitem;
  92.  
  93.  
  94. __inline static _list *get_next(_list *list)
  95. {
  96. return list->next;
  97. }
  98.  
  99. __inline static _list *get_list_head(_queue *queue)
  100. {
  101. return (&(queue->queue));
  102. }
  103.  
  104.  
  105. #define LIST_CONTAINOR(ptr, type, member) \
  106. ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
  107.  
  108.  
  109. __inline static void _enter_critical(_lock *plock, _irqL *pirqL)
  110. {
  111. spin_lock_irqsave(plock, *pirqL);
  112. }
  113.  
  114. __inline static void _exit_critical(_lock *plock, _irqL *pirqL)
  115. {
  116. spin_unlock_irqrestore(plock, *pirqL);
  117. }
  118.  
  119. __inline static void _enter_critical_ex(_lock *plock, _irqL *pirqL)
  120. {
  121. spin_lock_irqsave(plock, *pirqL);
  122. }
  123.  
  124. __inline static void _exit_critical_ex(_lock *plock, _irqL *pirqL)
  125. {
  126. spin_unlock_irqrestore(plock, *pirqL);
  127. }
  128.  
  129. __inline static void _enter_critical_bh(_lock *plock, _irqL *pirqL)
  130. {
  131. spin_lock_bh(plock);
  132. }
  133.  
  134. __inline static void _exit_critical_bh(_lock *plock, _irqL *pirqL)
  135. {
  136. spin_unlock_bh(plock);
  137. }
  138.  
  139. __inline static void _enter_hwio_critical(_rwlock *prwlock, _irqL *pirqL)
  140. {
  141. down(prwlock);
  142. }
  143.  
  144.  
  145. __inline static void _exit_hwio_critical(_rwlock *prwlock, _irqL *pirqL)
  146. {
  147. up(prwlock);
  148. }
  149.  
  150. __inline static void list_delete(_list *plist)
  151. {
  152.  
  153.  
  154.  
  155. list_del_init(plist);
  156.  
  157.  
  158.  
  159. }
  160.  
  161. __inline static void _init_timer(_timer *ptimer,_nic_hdl padapter,void *pfunc,void* cntx)
  162. {
  163. //setup_timer(ptimer, pfunc,(u32)cntx);
  164. ptimer->function = pfunc;
  165. ptimer->data = (u32)cntx;
  166. init_timer(ptimer);
  167. }
  168.  
  169. __inline static void _set_timer(_timer *ptimer,u32 delay_time)
  170. {
  171. if(!ptimer)
  172. panic("ptimer is NULL pointer...\n");
  173. mod_timer(ptimer , (jiffies+(delay_time*HZ/1000)));
  174. }
  175.  
  176. __inline static void _cancel_timer(_timer *ptimer,u8 *bcancelled)
  177. {
  178. del_timer_sync(ptimer);
  179. *bcancelled= _TRUE;//TRUE ==1; FALSE==0
  180. }
  181.  
  182. __inline static void _init_workitem(_workitem *pwork, void *pfunc, PVOID cntx)
  183. {
  184. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
  185. INIT_WORK(pwork, pfunc);
  186. #else
  187. INIT_WORK(pwork, pfunc,pwork);
  188. #endif
  189. }
  190.  
  191. __inline static void _set_workitem(_workitem *pwork)
  192. {
  193. schedule_work(pwork);
  194. }
  195.  
  196. #endif
  197.  
  198.  
  199. #ifdef PLATFORM_OS_XP
  200.  
  201. #include <ndis.h>
  202. #include <ntddk.h>
  203. #include <ntddsd.h>
  204. #include <ntddndis.h>
  205. #include <ntdef.h>
  206.  
  207.  
  208. typedef KSEMAPHORE _sema;
  209. typedef LIST_ENTRY _list;
  210. typedef NDIS_STATUS _OS_STATUS;
  211.  
  212.  
  213. typedef NDIS_SPIN_LOCK _lock;
  214.  
  215. typedef KMUTEX _rwlock;
  216.  
  217. typedef KIRQL _irqL;
  218.  
  219. // USB_PIPE for WINCE , but handle can be use just integer under windows
  220. typedef NDIS_HANDLE _nic_hdl;
  221.  
  222.  
  223. typedef NDIS_MINIPORT_TIMER _timer;
  224.  
  225. struct __queue {
  226. LIST_ENTRY queue;
  227. _lock lock;
  228. };
  229.  
  230. typedef NDIS_PACKET _pkt;
  231. typedef NDIS_BUFFER _buffer;
  232. typedef struct __queue _queue;
  233.  
  234. typedef PKTHREAD _thread_hdl_;
  235. typedef void thread_return;
  236. typedef void* thread_context;
  237.  
  238. typedef NDIS_WORK_ITEM _workitem;
  239.  
  240. #define thread_exit() PsTerminateSystemThread(STATUS_SUCCESS);
  241.  
  242. #define HZ 10000000
  243. #define SEMA_UPBND (0x7FFFFFFF) //8192
  244.  
  245. __inline static _list *get_next(_list *list)
  246. {
  247. return list->Flink;
  248. }
  249.  
  250. __inline static _list *get_list_head(_queue *queue)
  251. {
  252. return (&(queue->queue));
  253. }
  254.  
  255.  
  256. #define LIST_CONTAINOR(ptr, type, member) CONTAINING_RECORD(ptr, type, member)
  257.  
  258.  
  259. __inline static _enter_critical(_lock *plock, _irqL *pirqL)
  260. {
  261. NdisAcquireSpinLock(plock);
  262. }
  263.  
  264. __inline static _exit_critical(_lock *plock, _irqL *pirqL)
  265. {
  266. NdisReleaseSpinLock(plock);
  267. }
  268.  
  269.  
  270. __inline static _enter_critical_ex(_lock *plock, _irqL *pirqL)
  271. {
  272. NdisDprAcquireSpinLock(plock);
  273. }
  274.  
  275. __inline static _exit_critical_ex(_lock *plock, _irqL *pirqL)
  276. {
  277. NdisDprReleaseSpinLock(plock);
  278. }
  279.  
  280. __inline static void _enter_critical_bh(_lock *plock, _irqL *pirqL)
  281. {
  282. NdisDprAcquireSpinLock(plock);
  283. }
  284.  
  285. __inline static void _exit_critical_bh(_lock *plock, _irqL *pirqL)
  286. {
  287. NdisDprReleaseSpinLock(plock);
  288. }
  289.  
  290. __inline static _enter_hwio_critical(_rwlock *prwlock, _irqL *pirqL)
  291. {
  292. KeWaitForSingleObject(prwlock, Executive, KernelMode, FALSE, NULL);
  293. }
  294.  
  295.  
  296. __inline static _exit_hwio_critical(_rwlock *prwlock, _irqL *pirqL)
  297. {
  298. KeReleaseMutex(prwlock, FALSE);
  299. }
  300.  
  301.  
  302. __inline static void list_delete(_list *plist)
  303. {
  304. RemoveEntryList(plist);
  305. InitializeListHead(plist);
  306. }
  307.  
  308. __inline static void _init_timer(_timer *ptimer,_nic_hdl padapter,void *pfunc,PVOID cntx)
  309. {
  310. NdisMInitializeTimer(ptimer, padapter, pfunc, cntx);
  311. }
  312.  
  313. __inline static void _set_timer(_timer *ptimer,u32 delay_time)
  314. {
  315. NdisMSetTimer(ptimer,delay_time);
  316. }
  317.  
  318. __inline static void _cancel_timer(_timer *ptimer,u8 *bcancelled)
  319. {
  320. NdisMCancelTimer(ptimer,bcancelled);
  321. }
  322.  
  323. __inline static void _init_workitem(_workitem *pwork, void *pfunc, PVOID cntx)
  324. {
  325.  
  326. NdisInitializeWorkItem(pwork, pfunc, cntx);
  327. }
  328.  
  329. __inline static void _set_workitem(_workitem *pwork)
  330. {
  331. NdisScheduleWorkItem(pwork);
  332. }
  333.  
  334. #endif
  335.  
  336.  
  337. #ifdef PLATFORM_OS_CE
  338. #include <osdep_ce_service.h>
  339. #endif
  340.  
  341. #include <rtw_byteorder.h>
  342.  
  343. #ifndef BIT
  344. #define BIT(x) ( 1 << (x))
  345. #endif
  346.  
  347. extern u8* _rtw_malloc(u32 sz);
  348. extern void _rtw_mfree(u8 *pbuf, u32 sz);
  349. extern void _rtw_memcpy(void* dec, void* sour, u32 sz);
  350. extern int _rtw_memcmp(void *dst, void *src, u32 sz);
  351. extern void _rtw_memset(void *pbuf, int c, u32 sz);
  352.  
  353. extern void _rtw_init_listhead(_list *list);
  354. extern u32 rtw_is_list_empty(_list *phead);
  355. extern void rtw_list_insert_tail(_list *plist, _list *phead);
  356. extern void list_delete(_list *plist);
  357. extern void _rtw_init_sema(_sema *sema, int init_val);
  358. extern void _rtw_free_sema(_sema *sema);
  359. extern void _rtw_up_sema(_sema *sema);
  360. extern u32 _rtw_down_sema(_sema *sema);
  361. extern void _rtw_rwlock_init(_rwlock *prwlock);
  362. extern void _rtw_spinlock_init(_lock *plock);
  363. extern void _rtw_spinlock_free(_lock *plock);
  364. extern void _rtw_spinlock(_lock *plock);
  365. extern void _rtw_spinunlock(_lock *plock);
  366. extern void _rtw_spinlock_ex(_lock *plock);
  367. extern void _rtw_spinunlock_ex(_lock *plock);
  368. extern void _rtw_init_queue(_queue *pqueue);
  369. extern u32 _rtw_queue_empty(_queue *pqueue);
  370. extern u32 rtw_end_of_queue_search(_list *queue, _list *pelement);
  371. extern u32 rtw_get_current_time(void);
  372.  
  373. extern void rtw_sleep_schedulable(int ms);
  374.  
  375. extern void rtw_msleep_os(int ms);
  376. extern void rtw_usleep_os(int us);
  377. extern void rtw_mdelay_os(int ms);
  378. extern void rtw_udelay_os(int us);
  379.  
  380.  
  381.  
  382. __inline static unsigned char _cancel_timer_ex(_timer *ptimer)
  383. {
  384. #ifdef PLATFORM_LINUX
  385. return del_timer_sync(ptimer);
  386. #endif
  387.  
  388. #ifdef PLATFORM_WINDOWS
  389. u8 bcancelled;
  390.  
  391. _cancel_timer(ptimer, &bcancelled);
  392.  
  393. return bcancelled;
  394. #endif
  395. }
  396.  
  397. __inline static void thread_enter(void *context)
  398. {
  399. #ifdef PLATFORM_LINUX
  400. //struct net_device *pnetdev = (struct net_device *)context;
  401. //daemonize("%s", pnetdev->name);
  402. daemonize("%s", "RTKTHREAD");
  403. allow_signal(SIGTERM);
  404. #endif
  405. }
  406.  
  407. __inline static void flush_signals_thread(void)
  408. {
  409. #ifdef PLATFORM_LINUX
  410. if (signal_pending (current))
  411. {
  412. flush_signals(current);
  413. }
  414. #endif
  415. }
  416.  
  417. __inline static _OS_STATUS res_to_status(sint res)
  418. {
  419.  
  420.  
  421. #if defined (PLATFORM_LINUX) || defined (PLATFORM_MPIXEL)
  422. return res;
  423. #endif
  424.  
  425. #ifdef PLATFORM_WINDOWS
  426.  
  427. if (res == _SUCCESS)
  428. return NDIS_STATUS_SUCCESS;
  429. else
  430. return NDIS_STATUS_FAILURE;
  431.  
  432. #endif
  433.  
  434. }
  435.  
  436. __inline static u32 _RND4(u32 sz)
  437. {
  438.  
  439. u32 val;
  440.  
  441. val = ((sz >> 2) + ((sz & 3) ? 1: 0)) << 2;
  442.  
  443. return val;
  444.  
  445. }
  446.  
  447. __inline static u32 _RND8(u32 sz)
  448. {
  449.  
  450. u32 val;
  451.  
  452. val = ((sz >> 3) + ((sz & 7) ? 1: 0)) << 3;
  453.  
  454. return val;
  455.  
  456. }
  457.  
  458. __inline static u32 _RND128(u32 sz)
  459. {
  460.  
  461. u32 val;
  462.  
  463. val = ((sz >> 7) + ((sz & 127) ? 1: 0)) << 7;
  464.  
  465. return val;
  466.  
  467. }
  468.  
  469. __inline static u32 _RND256(u32 sz)
  470. {
  471.  
  472. u32 val;
  473.  
  474. val = ((sz >> 8) + ((sz & 255) ? 1: 0)) << 8;
  475.  
  476. return val;
  477.  
  478. }
  479.  
  480. __inline static u32 _RND512(u32 sz)
  481. {
  482.  
  483. u32 val;
  484.  
  485. val = ((sz >> 9) + ((sz & 511) ? 1: 0)) << 9;
  486.  
  487. return val;
  488.  
  489. }
  490.  
  491. __inline static u32 bitshift(u32 bitmask)
  492. {
  493. u32 i;
  494.  
  495. for (i = 0; i <= 31; i++)
  496. if (((bitmask>>i) & 0x1) == 1) break;
  497.  
  498. return i;
  499. }
  500.  
  501. #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
  502. #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
  503.  
  504. //#ifdef __GNUC__
  505. #ifdef PLATFORM_LINUX
  506. #define STRUCT_PACKED __attribute__ ((packed))
  507. #else
  508. #define STRUCT_PACKED
  509. #endif
  510.  
  511.  
  512. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement