irlib.pp 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538
  1. {$MACRO ON}
  2. (******************************************************************************
  3. *
  4. * Copyright (c) 1994-1999 Palm, Inc. or its subsidiaries.
  5. * All rights reserved.
  6. *
  7. * Portions of this file are:
  8. * Copyright Counterpoint Systems Foundry, Inc. 1995, 1996
  9. *
  10. * File: IrLib.h
  11. *
  12. * Release: Palm OS SDK 4.0 (63220)
  13. *
  14. * Description:
  15. * Include file for PalmOS IrDA Library.
  16. *
  17. * History:
  18. * 5/23/97 Created by Gavin Peacock
  19. * 2/13/98 Merged with counterpoint libraries
  20. * 6/24/98 Added disconnect timeout opt for IrOpen,
  21. * remaining speeds. Added parentheses to control defines.
  22. *
  23. *****************************************************************************)
  24. unit irlib;
  25. interface
  26. uses palmos, libtraps, exgmgr, systemresources;
  27. // The Ir library is used as an Exchange library. ExgLib.h defines all the
  28. // primary entrypoints into the library. The rest of this include file defines the
  29. // direct stack API for apps not using the Exchange interface. The Stack API
  30. // comes after the Exchange library API in the library interface.
  31. // name of Ir library
  32. const
  33. irLibName = 'IrDA Library';
  34. // Specific scheme for IR exg lib
  35. const
  36. exgIrObexScheme = '_irobex';
  37. // Feature Creators and numbers, for use with the FtrGet() call. This
  38. // feature can be obtained to get the current version of the Ir Library
  39. const
  40. irFtrCreator = sysFileCIrLib;
  41. irFtrNumVersion = 0; // get version of Net Library
  42. // 0xMMmfsbbb, where MM is major version, m is minor version
  43. // f is bug fix, s is stage: 3-release,2-beta,1-alpha,0-development,
  44. // bbb is build number for non-releases
  45. // V1.12b3 would be: 0x01122003
  46. // V2.00a2 would be: 0x02001002
  47. // V1.01 would be: 0x01013000
  48. // Options values for IrOpen
  49. // BDDDxxxx xxxxxxxx xxxxxxxx xxxSSSSS
  50. // Where B=background mode, DDD=disconnect timeout, SSSSS=speed
  51. irOpenOptBackground = $80000000; // Unsupported background task use
  52. irOpenOptDisconnect3 = $10000000; // sets amount of time in seconds
  53. irOpenOptDisconnect8 = $20000000; // after no activity from other
  54. irOpenOptDisconnect12 = $30000000; // device before disconnect is
  55. irOpenOptDisconnect16 = $40000000; // initiated.
  56. irOpenOptDisconnect20 = $50000000; // default is 40 secs
  57. irOpenOptDisconnect25 = $60000000;
  58. irOpenOptDisconnect30 = $70000000;
  59. irOpenOptDisconnect40 = $00000000;
  60. irOpenOptSpeed115200 = $0000003F; // sets max negotiated baud rate
  61. irOpenOptSpeed57600 = $0000001F; // default is 57600
  62. irOpenOptSpeed38400 = $0000000F;
  63. irOpenOptSpeed19200 = $00000007;
  64. irOpenOptSpeed9600 = $00000003;
  65. // Option codes for ExgLibControl
  66. // These options are all unique to the Ir transport
  67. irGetScanningMode = exgLibCtlSpecificOp or 1; // returns scanning enabled
  68. irSetScanningMode = exgLibCtlSpecificOp or 2; // en/disables ir scanning mode
  69. irGetStatistics = exgLibCtlSpecificOp or 3; // returns performance stats
  70. irSetSerialMode = exgLibCtlSpecificOp or 4; // sets driver to use direct serial
  71. irSetBaudMask = exgLibCtlSpecificOp or 5; // set possible baud rates (irOpenOpts)
  72. irSetSupported = exgLibCtlSpecificOp or 6; // disables the ir not supported dialog
  73. irSuppressScanning = exgLibCtlSpecificOp or 7; // temporarily disabled beam receive
  74. irRestoreScanning = exgLibCtlSpecificOp or 8; // restore beam receive state
  75. // structure returned by irGetStatistics
  76. type
  77. IrStatsType = record
  78. recLineErrors: UInt16; // # of serial errors since library opend
  79. crcErrors: UInt16; // # of crc errors ...
  80. end;
  81. //-----------------------------------------------------------------------------
  82. // Ir library call ID's.
  83. //-----------------------------------------------------------------------------
  84. // These start after the old exchange library interface. If we add any more exchange
  85. // library traps, we'll have to separate the publicly accessible "IR Library" and the
  86. // IrOBEX exchange library.
  87. type
  88. IrLibTrapNumberEnum = Enum;
  89. const
  90. irLibTrapBind = sysLibTrapCustom + 10; // these start after the ObxLib interface...
  91. irLibTrapUnBind = Succ(irLibTrapBind);
  92. irLibTrapDiscoverReq = Succ(irLibTrapUnBind);
  93. irLibTrapConnectIrLap = Succ(irLibTrapDiscoverReq);
  94. irLibTrapDisconnectIrLap = Succ(irLibTrapConnectIrLap);
  95. irLibTrapConnectReq = Succ(irLibTrapDisconnectIrLap);
  96. irLibTrapConnectRsp = Succ(irLibTrapConnectReq);
  97. irLibTrapDataReq = Succ(irLibTrapConnectRsp);
  98. irLibTrapLocalBusy = Succ(irLibTrapDataReq);
  99. irLibTrapMaxTxSize = Succ(irLibTrapLocalBusy);
  100. irLibTrapMaxRxSize = Succ(irLibTrapMaxTxSize);
  101. irLibTrapSetDeviceInfo = Succ(irLibTrapMaxRxSize);
  102. irLibTrapIsNoProgress = Succ(irLibTrapSetDeviceInfo);
  103. irLibTrapIsRemoteBusy = Succ(irLibTrapIsNoProgress);
  104. irLibTrapIsMediaBusy = Succ(irLibTrapIsRemoteBusy);
  105. irLibTrapIsIrLapConnected = Succ(irLibTrapIsMediaBusy);
  106. irLibTrapTestReq = Succ(irLibTrapIsIrLapConnected);
  107. irLibTrapIAS_Add = Succ(irLibTrapTestReq);
  108. irLibTrapIAS_Query = Succ(irLibTrapIAS_Add);
  109. irLibTrapIAS_SetDeviceName = Succ(irLibTrapIAS_Query);
  110. irLibTrapIAS_Next = Succ(irLibTrapIAS_SetDeviceName);
  111. irLibTrapIrOpen = Succ(irLibTrapIAS_Next);
  112. irLibTrapHandleEvent = Succ(irLibTrapIrOpen);
  113. irLibTrapWaitForEvent = Succ(irLibTrapHandleEvent);
  114. irLibTrapLast = Succ(irLibTrapWaitForEvent);
  115. (****************************************************************************
  116. *
  117. * Types and Constants
  118. *
  119. ****************************************************************************)
  120. // Maximum size of packet that can be sent at connect time (ConnectReq or
  121. // ConnectRsp) for IrLMP and Tiny TP connections.
  122. const
  123. IR_MAX_CON_PACKET = 60;
  124. IR_MAX_TTP_CON_PACKET = 52;
  125. IR_MAX_TEST_PACKET = 376;
  126. IR_MAX_DEVICE_INFO = 23;
  127. // Size of the device list used in discovery process
  128. IR_DEVICE_LIST_SIZE = 6;
  129. (*---------------------------------------------------------------------------
  130. *
  131. * Maximum size of the XID info field used in a discovery frame. The XID
  132. * info field contains the device hints and nickname.
  133. *)
  134. IR_MAX_XID_LEN = 23;
  135. // Maximum allowed LSAP in IrLMP
  136. IR_MAX_LSAP = $6f;
  137. // The following are used to access the hint bits in the first byte
  138. // of the Device Info field of an XID frame (IrDeviceInfo).
  139. IR_HINT_PNP = $01;
  140. IR_HINT_PDA = $02;
  141. IR_HINT_COMPUTER = $04;
  142. IR_HINT_PRINTER = $08;
  143. IR_HINT_MODEM = $10;
  144. IR_HINT_FAX = $20;
  145. IR_HINT_LAN = $40;
  146. IR_HINT_EXT = $80;
  147. (* The following are used to access the hint bits in the second byte
  148. * of the Device Info field of an XID frame (IrDeviceInfo). Note
  149. * that LM_HINT_EXT works for all hint bytes.
  150. *)
  151. IR_HINT_TELEPHONY = $01;
  152. IR_HINT_FILE = $02;
  153. IR_HINT_IRCOMM = $04;
  154. IR_HINT_MESSAGE = $08;
  155. IR_HINT_HTTP = $10;
  156. IR_HINT_OBEX = $20;
  157. (*---------------------------------------------------------------------------
  158. *
  159. * Status of a stack operation or of the stack.
  160. *)
  161. type
  162. IrStatus = UInt8;
  163. const
  164. IR_STATUS_SUCCESS = 0; // Successful and complete
  165. IR_STATUS_FAILED = 1; // Operation failed
  166. IR_STATUS_PENDING = 2; // Successfully started but pending
  167. IR_STATUS_DISCONNECT = 3; // Link disconnected
  168. IR_STATUS_NO_IRLAP = 4; // No IrLAP Connection exists
  169. IR_STATUS_MEDIA_BUSY = 5; // IR Media is busy
  170. IR_STATUS_MEDIA_NOT_BUSY = 6; // IR Media is not busy
  171. IR_STATUS_NO_PROGRESS = 7; // IrLAP not making progress
  172. IR_STATUS_LINK_OK = 8; // No progress condition cleared
  173. // IR_STATUS_RESERVED1 = 9; // Reserved for future use
  174. // IR_STATUS_RESERVED2 = 10; // Reserved for future use
  175. (*---------------------------------------------------------------------------
  176. *
  177. * Character set for user strings. These are definitions for the character
  178. * set in Nicknames and in IAS attributes of type User String.
  179. *)
  180. type
  181. IrCharSet = UInt8;
  182. const
  183. IR_CHAR_ASCII = 0;
  184. IR_CHAR_ISO_8859_1 = 1;
  185. IR_CHAR_ISO_8859_2 = 2;
  186. IR_CHAR_ISO_8859_3 = 3;
  187. IR_CHAR_ISO_8859_4 = 4;
  188. IR_CHAR_ISO_8859_5 = 5;
  189. IR_CHAR_ISO_8859_6 = 6;
  190. IR_CHAR_ISO_8859_7 = 7;
  191. IR_CHAR_ISO_8859_8 = 8;
  192. IR_CHAR_ISO_8859_9 = 9;
  193. IR_CHAR_UNICODE = $ff;
  194. (*---------------------------------------------------------------------------
  195. *
  196. * All indication and confirmations are sent to the IrLMP/TTP connections
  197. * through one callback function. The types of the events passed are
  198. * defined below. Applications should ignore events listed as "reserved"
  199. * as well as events not listed at all, since we may add more events in
  200. * future versions of the IR library.
  201. *)
  202. type
  203. IrEvent = UInt8;
  204. const
  205. LEVENT_LM_CON_IND = 0;
  206. LEVENT_LM_DISCON_IND = 1;
  207. LEVENT_DATA_IND = 2;
  208. LEVENT_PACKET_HANDLED = 3;
  209. LEVENT_LAP_CON_IND = 4;
  210. LEVENT_LAP_DISCON_IND = 5;
  211. LEVENT_DISCOVERY_CNF = 6;
  212. LEVENT_LAP_CON_CNF = 7;
  213. LEVENT_LM_CON_CNF = 8;
  214. LEVENT_STATUS_IND = 9;
  215. LEVENT_TEST_IND = 10;
  216. LEVENT_TEST_CNF = 11;
  217. // LEVENT_RESERVED1 = 12; // reserved for future use
  218. LEVENT_LM_SEND_IND = 13; // added in Palm OS 4.0
  219. // LmConnect flags - used internally
  220. LCON_FLAGS_TTP = $02;
  221. (****************************************************************************
  222. *
  223. * IAS Types and Constants
  224. *
  225. ****************************************************************************)
  226. // Maximum size of a query that observes the IrDA Lite rules
  227. IR_MAX_QUERY_LEN = 61;
  228. // Maximum values for IAS fields. IR_MAX_IAS_NAME is the maximum allowable
  229. // size for IAS Object names and Attribute names.
  230. IR_MAX_IAS_NAME = 60;
  231. IR_MAX_ATTRIBUTES = 255;
  232. (* Maximum size of an IAS attribute that fits within the IrDA Lite rules.
  233. * Even though attribute values can be larger IrDA Lite highly recommends
  234. * that the total size of an attribute value fit within one 64 byte packet
  235. * thus, the allowable size is 56 bytes or less. This size is enforced by the
  236. * code.
  237. *)
  238. IR_MAX_IAS_ATTR_SIZE = 56;
  239. // Type of the IAS entry. This is the value returned for type when parsing
  240. // the results buffer after a successful IAS Query.
  241. IAS_ATTRIB_MISSING = 0;
  242. IAS_ATTRIB_INTEGER = 1;
  243. IAS_ATTRIB_OCTET_STRING = 2;
  244. IAS_ATTRIB_USER_STRING = 3;
  245. IAS_ATTRIB_UNDEFINED = $ff;
  246. // Ias Return Codes. One of these values will be found in the IAS Query
  247. // structure in the retCode field after a successful IAS Query.
  248. IAS_RET_SUCCESS = 0; // Query operation is successful
  249. IAS_RET_NO_SUCH_CLASS = 1; // Query failed no such class exists
  250. IAS_RET_NO_SUCH_ATTRIB = 2; // Query failed no such attribute exists
  251. IAS_RET_UNSUPPORTED = $ff; // Query failed operation is unsupported
  252. // IAS Get Value By Class opcode number
  253. IAS_GET_VALUE_BY_CLASS = 4;
  254. (****************************************************************************
  255. *
  256. * Data Structures
  257. *
  258. ****************************************************************************)
  259. // stack functions use a diferent type for booleans
  260. type
  261. BOOL = Int16;
  262. (*---------------------------------------------------------------------------
  263. *
  264. * ListEntry is used internally by the stack
  265. *)
  266. _ListEntry = record
  267. Flink: ^ListEntry;
  268. Blink: ^ListEntry;
  269. end;
  270. ListEntry = _ListEntry;
  271. // Forward declaration of the IrConnect structure
  272. IrConnectPtr = ^_hconnect;
  273. (*---------------------------------------------------------------------------
  274. *
  275. * Packet Structure for sending IrDA packets.
  276. *)
  277. _IrPacket = record
  278. (* The node field must be the first field in the structure. It is used
  279. * internally by the stack
  280. *)
  281. node: ListEntry;
  282. (* The buff field is used to point to a buffer of data to send and len
  283. * field indicates the number of bytes in buff.
  284. *)
  285. buff: ^UInt8;
  286. len: UInt16;
  287. (*================== For Internal Use Only =======================
  288. *
  289. * The following is used internally by the stack and should not be
  290. * modified by the upper layer.
  291. *
  292. *==================================================================*)
  293. origin: IrConnectPtr; // Pointer to connection which owns packet
  294. headerLen: UInt8; // Number of bytes in the header
  295. header: array [0..13] of UInt8; // Storage for the header
  296. reserved: UInt8; // Explicitly account for 16-bit alignment padding
  297. end;
  298. IrPacket = _IrPacket;
  299. (*---------------------------------------------------------------------------
  300. *
  301. * 32-bit Device Address
  302. *)
  303. IrDeviceAddr = record
  304. case Integer of
  305. 0: (u8: array [0..3] of UInt8);
  306. 1: (u16: array [0..1] of UInt16);
  307. 2: (u32: UInt32);
  308. end;
  309. (*---------------------------------------------------------------------------
  310. *
  311. * The information returned for each device discovered during discovery.
  312. * The maximum size of the xid field is 23. This holds the hints and
  313. * the nickname.
  314. *)
  315. IrDeviceInfo = record
  316. hDevice: IrDeviceAddr; // 32-bit address of device
  317. len: UInt8; // Length of xid
  318. xid: array [0..IR_MAX_XID_LEN-1] of UInt8; // XID information
  319. end;
  320. (*---------------------------------------------------------------------------
  321. *
  322. * List of Device Discovery info elements.
  323. *)
  324. IrDeviceList = record
  325. nItems: UInt8; // Number items in the list
  326. reserved: UInt8; // Explicitly account for 16-bit alignment padding
  327. dev: array [0..IR_DEVICE_LIST_SIZE-1] of IrDeviceInfo; // Fixed size in IrDA Lite
  328. end;
  329. (*---------------------------------------------------------------------------
  330. *
  331. * Callback Parameter Structure is used to pass information from the stack
  332. * to the upper layer of the stack (application). Not all fields are valid
  333. * at any given time. The type of event determines which fields are valid.
  334. *)
  335. IrCallBackParms = record
  336. event: IrEvent; // Event causing callback
  337. reserved1: UInt8; // Explicitly account for 16-bit alignment padding
  338. rxBuff: ^UInt8; // Receive buffer already advanced to app data
  339. rxLen: UInt16; // Length of data in receive buffer
  340. packet: ^IrPacket; // Pointer to packet being returned
  341. deviceList: ^IrDeviceList; // Pointer to discovery device list
  342. status: IrStatus; // Status of stack
  343. reserved2: UInt8; // Explicitly account for 16-bit alignment padding
  344. end;
  345. IrCallBackParmsPtr = ^IrCallBackParms;
  346. (* The definitions for the callback function is given below. How the
  347. * callback function is used in conjuction with the stack functions is
  348. * given below in the Callback Reference.
  349. *)
  350. IrCallBack = procedure(p1: IrConnectPtr; p2: IrCallBackParmsPtr);
  351. (*---------------------------------------------------------------------------
  352. *
  353. * Definition of IrConnect structure. This structure is used to manage an
  354. * IrLMP or Tiny TP connection.
  355. *)
  356. _hconnect = record
  357. lLsap: UInt8; // Local LSAP this connection will listen on
  358. rLsap: UInt8; // Remote Lsap
  359. (*================== For Internal Use Only =======================
  360. *
  361. * The following is used internally by the stack and should not be
  362. * modified by the user.
  363. *
  364. *==================================================================*)
  365. flags: UInt8; // Flags containing state, type, etc.
  366. reserved: UInt8; // Explicitly account for 16-bit alignment padding
  367. callBack: IrCallBack; // Pointer to callback function
  368. (* Tiny TP fields *)
  369. packet: IrPacket; // Packet for internal use
  370. packets: ListEntry; // List of packets to send
  371. sendCredit: UInt16; // Amount of credit from peer
  372. availCredit: UInt8; // Amount of credit to give to peer
  373. dataOff: UInt8; // Amount of data less than IrLAP size
  374. end;
  375. IrConnect = _hconnect;
  376. (****************************************************************************
  377. *
  378. * IAS Data Strucutres
  379. *
  380. ****************************************************************************)
  381. (*---------------------------------------------------------------------------
  382. *
  383. * The LmIasAttribute is a strucutre that holds one attribute of an IAS
  384. * object.
  385. *)
  386. _IrIasAttribute = record
  387. name: ^UInt8; // Pointer to name of attribute
  388. len: UInt8; // Length of attribute name
  389. reserved1: UInt8; // Explicitly account for 16-bit alignment padding
  390. value: ^UInt8; // Hardcode value (see below)
  391. valLen: UInt8; // Length of the value.
  392. reserved2: UInt8; // Explicitly account for 16-bit alignment padding
  393. end;
  394. IrIasAttribute = _IrIasAttribute;
  395. (* The value field of the IrIasAttribute structure is a hard coded string
  396. * which represents the actual bytes sent over the IR for the attribute
  397. * value. The value field contains all the bytes which represent an
  398. * attribute value based on the transmission format described in section
  399. * 4.3 of the IrLMP specification. An example of a user string is given
  400. * below.
  401. *
  402. * User String:
  403. * 1 byte type, 1 byte Char set, 1 byte length, length byte string
  404. *
  405. * Example of an user string "Hello World" in ASCII
  406. *
  407. * U8 helloString[] = {
  408. * IAS_ATTRIB_USER_STRING,IR_CHAR_ASCII,11,
  409. * 'H','e','l','l','o',' ','W','o','r','l','d'
  410. * };
  411. *)
  412. (*---------------------------------------------------------------------------
  413. *
  414. * The LmIasObject is storage for an IAS object managed by the local
  415. * IAS server.
  416. *)
  417. _IrIasObject = record
  418. name: ^UInt8; // Pointer to name of object
  419. len: UInt8; // Length of object name
  420. nAttribs: UInt8; // Number of attributes
  421. attribs: ^IrIasAttribute; // A pointer to an array of attributes
  422. end;
  423. IrIasObject = _IrIasObject;
  424. (*---------------------------------------------------------------------------
  425. *
  426. * Forward declaration of a structure used for performing IAS Queries so
  427. * that a callback type can be defined for use in the structure.
  428. *)
  429. type
  430. IrIasQueryCallBack = procedure(p: IrStatus);
  431. (*---------------------------------------------------------------------------
  432. *
  433. * Actual definition of the IrIasQuery structure.
  434. *)
  435. _IrIasQuery = record
  436. (* Query fields. The query buffer contains the class name and class
  437. * attribute whose value is being queried it is as follows:
  438. *
  439. * 1 byte - Length of class name
  440. * "Length" bytes - class name
  441. * 1 byte - length of attribute name
  442. * "Length" bytes - attribute name
  443. *
  444. * queryLen - contains the total number of byte in the query
  445. *)
  446. queryLen: UInt8; // Total length of the query
  447. reserved: UInt8; // Explicitly account for 16-bit alignment padding
  448. queryBuf: ^UInt8; // Points to buffer containing the query
  449. (* Fields for the query result *)
  450. resultBufSize: UInt16; // Size of the result buffer
  451. resultLen: UInt16; // Actual number of bytes in the result buffer
  452. listLen: UInt16; // Number of items in the result list.
  453. offset: UInt16; // Offset into results buffer
  454. retCode: UInt8; // Return code of operation
  455. overFlow: UInt8; // Set TRUE if result exceeded result buffer size
  456. result: ^UInt8; // Pointer to buffer containing result;
  457. (* Pointer to callback function *)
  458. callBack: IrIasQueryCallBack;
  459. end;
  460. IrIasQuery = _IrIasQuery;
  461. (****************************************************************************
  462. *
  463. * Function Reference
  464. *
  465. ****************************************************************************)
  466. (*---------------------------------------------------------------------------
  467. *
  468. * Prototype: Err IrOpen(UInt16 refnum, UInt32 options)
  469. *
  470. * Description: Open the Ir library. This allocates the global memory
  471. * for the ir stack and reserves and system resources it
  472. * requires. This must be done before any other ir libary
  473. * calls are made.
  474. *
  475. * Parameters: refNum - ir library refNum
  476. *
  477. * options - open options flags
  478. *
  479. *
  480. * Return Values: zero if no error or exgErrStackInit
  481. *
  482. *)
  483. function IrOpen(refnum: UInt16; options: UInt32): Err; syscall irLibTrapIrOpen;
  484. (*---------------------------------------------------------------------------
  485. *
  486. * Prototype: Err IrClose(UInt16 refnum)
  487. *
  488. * Description: Close the Ir library. This releases the global memory
  489. * for the ir stack and any system resources it uses.
  490. * This must be called when an application is done with the
  491. * ir library.
  492. *
  493. * Parameters: refNum - ir library refNum
  494. *
  495. * Return Values: zero if no error
  496. *
  497. *)
  498. function IrClose(refnum: UInt16): Err; syscall sysLibTrapClose;
  499. (*---------------------------------------------------------------------------
  500. *
  501. * Prototype: IrStatus IrBind(UInt16 refNum,IrConnect* con,
  502. * IrCallback callBack)
  503. *
  504. * Description: Obtain a local LSAP selector and register the connection
  505. * with the protocol stack. This IrConnect structure will be
  506. * initialized. Any values stored in the structure will be
  507. * lost. The assigned LSAP will be in the lLsap field of con.
  508. * The type of the connection will be set to IrLMP. The
  509. * IrConnect must be bound to the stack before it can be used.
  510. *
  511. * Parameters: refNum - ir library refNum
  512. *
  513. * con - pointer to IrConnect structure.
  514. *
  515. * callBack - pointer to a callBack function that handles
  516. * the indications and confirmation from the protocol stack.
  517. *
  518. * Return Values: IR_STATUS_SUCCESS - operation completed successfully.
  519. * The assigned LSAP can be found in con->lLsap.
  520. *
  521. * IR_STATUS_FAILED - the operation failed for one of the
  522. * following reasons:
  523. * - con is already bound to the stack
  524. * - no room in the connection table
  525. *)
  526. function IrBind(refNum: UInt16; var con: IrConnect; callBack: IrCallBack): IrStatus; syscall irLibTrapBind;
  527. (*---------------------------------------------------------------------------
  528. *
  529. * Prototype: IrStatus IrUnbind(UInt16 refNum,IrConnect* con)
  530. *
  531. * Description: Unbind the IrConnect structure from the protocol stack
  532. * freeing it's LSAP selector.
  533. *
  534. * Parameters: refNum - ir library refNum
  535. *
  536. * con - pointer to IrConnect structure to unbind
  537. *
  538. * Return Values: IR_STATUS_SUCCESS - operation competed succesfully
  539. *
  540. * IR_STATUS_FAILED - operation failed
  541. * either because the IrConnect structure was not bound
  542. * or the lLsap field contained an invalid number.
  543. *)
  544. function IrUnbind(refNum: UInt16; var con: IrConnect): IrStatus; syscall irLibTrapUnBind;
  545. (*---------------------------------------------------------------------------
  546. *
  547. * Prototype: IrStatus IrDiscoverReq(UInt16 refNum,IrConnect* con)
  548. *
  549. * Description: Start an IrLMP discovery process. The result will be
  550. * signaled via the callBack function specified in the
  551. * IrConnect structure with the event LEVENT_DISCOVERY_CNF.
  552. * Only one discovery can be invoked at a time.
  553. *
  554. * Parameters: refNum - ir library refNum
  555. *
  556. * con - pointer to a bound IrConnect structure.
  557. *
  558. * Return Values: IR_STATUS_PENDING - operation is started successfully
  559. * result returned via callback.
  560. *
  561. * IR_STATUS_MEDIA_BUSY - operation failed because the media
  562. * is busy. Media busy is caused by one of the following
  563. * reasons:
  564. * - Other devices are using the IR medium.
  565. * - A discovery process is already in progress
  566. * - An IrLAP connection exists.
  567. *
  568. * IR_STATUS_FAILED - operation failed
  569. * because the IrConnect structure is not bound to the stack.
  570. *)
  571. function IrDiscoverReq(refNum: UInt16; var con: IrConnect): IrStatus; syscall irLibTrapDiscoverReq;
  572. (*---------------------------------------------------------------------------
  573. *
  574. * Prototype: IrStatus IrConnectIrLap(UInt16 refNum,IrDeviceAddr deviceAddr)
  575. *
  576. * Description: Start an IrLAP connection. The result is signaled to all
  577. * bound IrConnect structures via the callback function. The
  578. * callback event is LEVENT_LAP_CON_CNF if successful or
  579. * LEVENT_LAP_DISCON_IND if unsuccessful.
  580. *
  581. * Parameters:: refNum - ir library refNum
  582. *
  583. * deviceAddr - 32-bit address of device to which connection
  584. * should be made.
  585. *
  586. * Return Values: IR_STATUS_PENDING - operation started successfully and
  587. * callback will be called with result.
  588. *
  589. * IR_STATUS_MEDIA_BUSY - operation failed to start because
  590. * the IR media is busy. Media busy is caused by one of the
  591. * following reasons:
  592. * - Other devices are using the IR medium.
  593. * - An IrLAP connection already exists
  594. * - A discovery process is in progress
  595. *)
  596. function IrConnectIrLap(refNum: UInt16; deviceAddr: IrDeviceAddr): IrStatus; syscall irLibTrapConnectIrLap;
  597. (*---------------------------------------------------------------------------
  598. *
  599. * Prototype: IrStatus IrDisconnectIrLap(UInt16 refNum)
  600. *
  601. * Description: Disconnect the IrLAP connection. When the IrLAP connection
  602. * goes down the callback of all bound IrConnect structures
  603. * is called with event LEVENT_LAP_DISCON_IND.
  604. *
  605. * Parameters: refNum - ir library refNum
  606. *
  607. * Return Values: IR_STATUS_PENDING - operation started successfully and
  608. * the all bound IrConnect structures will be called back
  609. * when complete.
  610. *
  611. * IR_STATUS_NO_IRLAP - operation failed because no IrLAP
  612. * connection exists.
  613. *)
  614. function IrDisconnectIrLap(refNum: UInt16): IrStatus; syscall irLibTrapDisconnectIrLap;
  615. (*---------------------------------------------------------------------------
  616. *
  617. * Prototype: IrStatus IrConnectReq(UInt16 refNum,
  618. * IrConnect* con,
  619. * IrPacket* packet,
  620. * UInt8 credit);
  621. *
  622. * Description: Request an IrLMP or TinyTP connection. The result is
  623. * is signaled via the callback specified in the IrConnect
  624. * structure. The callback event is LEVENT_LM_CON_CNF
  625. * indicates that the connection is up and LEVENT_LM_DISCON_IND
  626. * indicates that the connection failed. Before calling this
  627. * function the fields in the con structure must be properly
  628. * set.
  629. *
  630. * Parameters: refNum - ir library refNum
  631. *
  632. * con - pointer to IrConnect structure for handing the
  633. * the connection. The rLsap field must contain the LSAP
  634. * selector for the peer on the other device. Also the type
  635. * of the connection must be set. Use IR_SetConTypeLMP() to
  636. * set the type to an IrLMP conneciton or IR_SetConTypeTTP()
  637. * to set the type to a Tiny TP connection.
  638. *
  639. * packet - pointer to a packet that contains connection data.
  640. * Even if no connection data is needed the packet must point
  641. * to a valid IrPacket structure. The packet will be returned
  642. * via the callback with the LEVENT_PACKET_HANDLED event if no
  643. * errors occur. The maximum size of the packet is
  644. * IR_MAX_CON_PACKET for an IrLMP connection or
  645. * IR_MAX_TTP_CON_PACKET for a Tiny TP connection.
  646. *
  647. * credit - initial amount of credit advanced to the other side.
  648. * Must be less than 127. It is ANDed with 0x7f so if it is
  649. * greater than 127 unexpected results will occur. This
  650. * parameter is ignored if the Connection is an IrLMP connection.
  651. *
  652. * Return Values: IR_STATUS_PENDING - operation has been started successfully
  653. * and the result will be returned via the callback function with
  654. * the event LEVENT_LM_CON_CNF if the connection is made or
  655. * LEVENT_LM_DISCON_IND if connection fails. The packet is returned
  656. * via the callback with the event LEVENT_PACKET_HANDLED.
  657. *
  658. * IR_STATUS_FAILED - operation failed because of one of the
  659. * reasons below. Note that the packet is
  660. * available immediately:
  661. * - Connection is busy (already involved in a connection)
  662. * - IrConnect structure is not bound to the stack
  663. * - Packet size exceeds maximum allowed.
  664. *
  665. * IR_STATUS_NO_IRLAP - operation failed because there is no
  666. * IrLAP connection (the packet is available immediately).
  667. *)
  668. function IrConnectReq(refNum: UInt16; var con: IrConnect; var packet: IrPacket; credit: UInt8): IrStatus; syscall irLibTrapConnectReq;
  669. (*---------------------------------------------------------------------------
  670. *
  671. * Prototype: IrStatus IrConnectRsp(UInt16 refNum,
  672. * IrConnect* con,
  673. * IrPacket* packet,
  674. * UInt8 credit);
  675. *
  676. * Description: Accept an incoming connection that has been signaled via
  677. * the callback with the event LEVENT_LM_CON_IND. IR_ConnectRsp
  678. * can be called during the callback or later to accept
  679. * the connection. The type of the connection must already have
  680. * been set to IrLMP or Tiny TP before LEVENT_LM_CON_IND event.
  681. *
  682. * Parameters: refNum - ir library refNum
  683. *
  684. * con - pointer to IrConnect structure to managed connection.
  685. *
  686. * packet - pointer to a packet that contains connection data.
  687. * Even if no connection data is needed the packet must point
  688. * to a valid IrPacket structure. The packet will be returned
  689. * via the callback with the LEVENT_PACKET_HANDLED event if no
  690. * errors occur. The maximum size of the packet is
  691. * IR_MAX_CON_PACKET for an IrLMP connection or
  692. * IR_MAX_TTP_CON_PACKET for a Tiny TP connection.
  693. *
  694. * credit - initial amount of credit advanced to the other side.
  695. * Must be less than 127. It is ANDed with 0x7f so if it is
  696. * greater than 127 unexpected results will occur. This
  697. * parameter is ignored if the Connection is an IrLMP connection.
  698. *
  699. * Return Values: IR_STATUS_PENDING - response has been started successfully
  700. * and the packet is returned via the callback with the event
  701. * LEVENT_PACKET_HANDLED.
  702. *
  703. * IR_STATUS_FAILED - operation failed because of one of the
  704. * reasons below . Note that the packet is
  705. * available immediately:
  706. * - Connection is not in the proper state to require a
  707. * response.
  708. * - IrConnect structure is not bound to the stack
  709. * - Packet size exceeds maximum allowed.
  710. *
  711. * IR_STATUS_NO_IRLAP - operation failed because there is no
  712. * IrLAP connection (Packet is available immediately).
  713. *)
  714. function IrConnectRsp(refNum: UInt16; var con: IrConnect; var packet: IrPacket; credit: UInt8): IrStatus; syscall irLibTrapConnectRsp;
  715. (*---------------------------------------------------------------------------
  716. *
  717. * Prototype: IrStatus IR_DataReq(IrConnect* con,
  718. * IrPacket* packet);
  719. *
  720. * Description: Send a data packet. The packet is owned by the stack until
  721. * it is returned via the callback with event
  722. * LEVENT_PACKET_HANDLED. The largest packet that can be sent
  723. * is found by calling IR_MaxTxSize().
  724. *
  725. * Parameters: refNum - ir library refNum
  726. *
  727. * con - pointer to IrConnect structure that specifies the
  728. * connection over which the packet should be sent.
  729. *
  730. * packet - pointer to a packet that contains data to send.
  731. * The packet should exceed the max size found with
  732. * IR_MaxTxSize().
  733. *
  734. * Return Values: IR_STATUS_PENDING - packet has been queued by the stack.
  735. * The packet will be returned via the callback with event
  736. * LEVENT_PACKET_HANDLED.
  737. *
  738. *
  739. * IR_STATUS_FAILED - operation failed and packet is available
  740. * immediately. Operation failed for one of the following
  741. * reasons:
  742. * - IrConnect structure is not bound to the stack (error
  743. * checking only)
  744. * - packet exceeds the maximum size (error checking only)
  745. * - IrConnect does not represent an active connection
  746. *)
  747. function IrDataReq(refNum: UInt16; var con: IrConnect; var packet: IrPacket): IrStatus; syscall irLibTrapDataReq;
  748. (*---------------------------------------------------------------------------
  749. *
  750. * Prototype: void IrAdvanceCredit(IrConnect* con,
  751. * UInt8 credit);
  752. *
  753. * Description: Advance credit to the other side. The total amount of
  754. * credit should not exceed 127. The credit passed by this
  755. * function is added to existing available credit which is
  756. * the number that must not exceed 127. This function
  757. * only makes sense for a Tiny TP connection.
  758. *
  759. * Parameters: con - pointer to IrConnect structure representing
  760. * connection to which credit is advanced.
  761. *
  762. * credit - number of credit to advance.
  763. *
  764. * Return Values: void
  765. *)
  766. // IrAdvanceCredit(con, credit) {(con)->availCredit += (credit);}
  767. (*---------------------------------------------------------------------------
  768. *
  769. * Prototype: void IrLocalBusy(UInt16 refNum,BOOL flag);
  770. *
  771. * Description: Set the IrLAP local busy flag. If local busy is set to true
  772. * then the local IrLAP layer will send RNR frames to the other
  773. * side indicating it cannot receive any more data. If the
  774. * local busy is set to false IrLAP is ready to receive frames.
  775. * This function should not be used when using Tiny TP or when
  776. * multiple connections exist. It takes affect the next time
  777. * IrLAP sends an RR frame. If IrLAP has data to send the data
  778. * will be sent first so it should be used carefully.
  779. *
  780. * Parameters: refNum - ir library refNum
  781. *
  782. * flag - value (true or false) to set IrLAP's local busy flag.
  783. *
  784. * Return Values: void
  785. *)
  786. procedure IrLocalBusy(refNum: UInt16; flag: BOOL); syscall irLibTrapLocalBusy;
  787. (*---------------------------------------------------------------------------
  788. *
  789. * Prototype: void IrSetConTypeTTP(IrConnect* con)
  790. *
  791. * Description: Set the type of the connection to Tiny TP. This function
  792. * must be called after the IrConnect structure is bound to
  793. * the stack.
  794. *
  795. * Parameters: con - pointer to IrConnect structure.
  796. *
  797. * Return Values: void
  798. *)
  799. // IrSetConTypeTTP(con) { ((con)->flags |= LCON_FLAGS_TTP); }
  800. (*---------------------------------------------------------------------------
  801. *
  802. * Prototype: void IrSetConTypeLMP(IrConnect* con)
  803. *
  804. * Description: Set the type of the connection to IrLMP. This function
  805. * must be called after the IrConnect structure is bound to
  806. * the stack.
  807. *
  808. * Parameters: con - pointer to IrConnect structure.
  809. *
  810. * Return Values: void
  811. *)
  812. // IrSetConTypeLMP(con) { ((con)->flags &= ~LCON_FLAGS_TTP); }
  813. (*---------------------------------------------------------------------------
  814. *
  815. * Prototype: UInt16 IrMaxTxSize(UInt16 refNum,IrConnect* con);
  816. *
  817. * Description: Returns the maximum size allowed for a transmit packet.
  818. * The value returned is only valid for active connections.
  819. * The maximum size will vary for each connection and is based
  820. * on the negotiated IrLAP parameters and the type of the
  821. * connection.
  822. *
  823. * Parameters: refNum - ir library refNum
  824. *
  825. * con - pointer to IrConnect structure which represents
  826. * an active connection.
  827. *
  828. * Return Values: Maxmum number of bytes for a transmit packet.
  829. *)
  830. function IrMaxTxSize(refNum: UInt16; var con: IrConnect): UInt16; syscall irLibTrapMaxTxSize;
  831. (*---------------------------------------------------------------------------
  832. *
  833. * Prototype: IrMaxRxSize(UInt16 refNum,IrConnect* con);
  834. *
  835. * Description: Returns the maximum size buffer that can be sent by the
  836. * the other device. The value returned is only valid for
  837. * active connections. The maximum size will vary for
  838. * each connection and is based on the negotiated IrLAP
  839. * parameters and the type of the connection.
  840. *
  841. * Parameters: refNum - ir library refNum
  842. *
  843. * con - pointer to IrConnect structure which represents
  844. * an active connection.
  845. *
  846. * Return Values: Maxmum number of bytes that can be sent by the other
  847. * device (maximum bytes that can be received).
  848. *)
  849. function IrMaxRxSize(refNum: UInt16; var con: IrConnect): UInt16; syscall irLibTrapMaxRxSize;
  850. (*---------------------------------------------------------------------------
  851. *
  852. * Prototype: IrStatus IrSetDeviceInfo(UInt16 refNum,UInt8 *info,UInt8 len);
  853. *
  854. * Description: Set the XID info string used during discovery to the given
  855. * string and length. The XID info string contains hints and
  856. * the nickname of the device. The size cannot exceed
  857. * IR_MAX_DEVICE_INFO bytes.
  858. *
  859. * Parameters: refNum - ir library refNum
  860. *
  861. * info - pointer to array of bytes
  862. *
  863. * len - number of bytes pointed to by info
  864. *
  865. * Return Values: IR_STATUS_SUCCESS - operation is successful.
  866. *
  867. * IR_STATUS_FAILED - operation failed because info is too
  868. * big (Error Checking only).
  869. *)
  870. function IrSetDeviceInfo(refNum: UInt16; var info: UInt8; len: UInt8): IrStatus; syscall irLibTrapSetDeviceInfo;
  871. (*---------------------------------------------------------------------------
  872. *
  873. * Prototype: BOOL IrIsNoProgress(UInt16 refNum);
  874. *
  875. * Description: Return true if IrLAP is not making progress otherwise
  876. * return false (this is an optional function).
  877. *
  878. * Parameters: refNum - ir library refNum
  879. *
  880. * Return Values: true if IrLAP is not making progress, false otherwise.
  881. *)
  882. function IrIsNoProgress(refNum: UInt16): BOOL; syscall irLibTrapIsNoProgress;
  883. (*---------------------------------------------------------------------------
  884. *
  885. * Prototype: Boolean IrIsRemoteBusy(UInt16 refNum)
  886. *
  887. * Description: Return true if the other device's IrLAP is busy otherwise
  888. * return false (this is an optional function).
  889. *
  890. * Parameters: refNum - ir library refNum
  891. *
  892. * Return Values: true if the other device's IrLAP is busy, false otherwise.
  893. *)
  894. function IrIsRemoteBusy(refNum: UInt16): BOOL; syscall irLibTrapIsRemoteBusy;
  895. (*---------------------------------------------------------------------------
  896. *
  897. * Prototype: BOOL IrIsMediaBusy(UInt16 refNum);
  898. *
  899. * Description: Return true if the IR media is busy. Otherwise return false
  900. * (this is an optional function).
  901. *
  902. * Parameters: refNum - ir library refNum
  903. *
  904. * Return Values: true if IR media is busy, false otherwise.
  905. *)
  906. function IrIsMediaBusy(refNum: UInt16): BOOL; syscall irLibTrapIsMediaBusy;
  907. (*---------------------------------------------------------------------------
  908. *
  909. * Prototype: BOOL IrIsIrLapConnected(UInt16 refNum);
  910. *
  911. * Description: Return true if an IrLAP connection exists (this is an
  912. * optional function). Only available if IR_IS_LAP_FUNCS is
  913. * defined.
  914. *
  915. * Parameters: refNum - ir library refNum
  916. *
  917. * Return Values: true if IrLAP is connected, false otherwise.
  918. *)
  919. function IrIsIrLapConnected(refNum: UInt16): BOOL; syscall irLibTrapIsIrLapConnected;
  920. (*---------------------------------------------------------------------------
  921. *
  922. * Prototype: IrStatus IR_TestReq(IrDeviceAddr devAddr,
  923. * IrConnect* con,
  924. * IrPacket* packet)
  925. *
  926. * Description: Request a TEST command frame be sent in the NDM state. The
  927. * result is signaled via the callback specified in the
  928. * IrConnect structure. The callback event is LEVENT_TEST_CNF
  929. * and the status field indates the result of the operation.
  930. * IR_STATUS_SUCCESS indicates success and IR_STATUS_FAILED
  931. * indicates no response was received. A packet must be passed
  932. * containing the data to send in the TEST frame. The packet
  933. * is returned when the LEVENT_TEST_CNF event is given.
  934. *
  935. *
  936. * Parameters: refNum - ir library refNum
  937. *
  938. * devAddr - device address of device where TEST will be
  939. * sent. This address is not checked so it can be the
  940. * broadcast address or 0.
  941. *
  942. * con - pointer to IrConnect structure specifying the
  943. * callback function to call to report the result.
  944. *
  945. * packet - pointer to a packet that contains the data to
  946. * send in the TEST command packet. The maximum size data
  947. * that can be sent is IR_MAX_TEST_PACKET. Even if no
  948. * data is to be sent a valid packet must be passed.
  949. *
  950. *
  951. * Return Values: IR_STATUS_PENDING - operation has been started successfully
  952. * and the result will be returned via the callback function with
  953. * the event LEVENT_TEST_CNF. This is also the indication
  954. * returning the packet.
  955. *
  956. * IR_STATUS_FAILED - operation failed because of one of the
  957. * reasons below. Note that the packet is
  958. * available immediately:
  959. * - IrConnect structure is not bound to the stack
  960. * - Packet size exceeds maximum allowed.
  961. *
  962. * IR_STATUS_MEDIA_BUSY - operation failed because the media is
  963. * busy or the stack is not in the NDM state (the packet is
  964. * available immediately).
  965. *)
  966. function IrTestReq(refNum: UInt16; devAddr: IrDeviceAddr; var con: IrConnect; var packet: IrPacket): IrStatus; syscall irLibTrapTestReq;
  967. (****************************************************************************
  968. *
  969. * Callback Reference
  970. *
  971. ****************************************************************************)
  972. (*---------------------------------------------------------------------------
  973. *
  974. * The stack calls the application via a callback function stored in each
  975. * IrConnect structure. The callback function is called with a pointer to
  976. * the IrConnect structure and a pointer to a parameter structure. The
  977. * parameter structure contains an event field which indicates the reason
  978. * the callback is called and other parameters which have meaning based
  979. * on the event.
  980. *
  981. * The meaning of the events are as follows:
  982. *
  983. * LEVENT_LM_CON_IND - Other device has initiated a connection. IR_ConnectRsp
  984. * should be called to accept the connection. Any data associated with the
  985. * connection request can be found using fields rxBuff and rxLen for the
  986. * data pointer and length respectively.
  987. *
  988. * LEVENT_LM_DISCON_IND - The IrLMP/Tiny TP connection has been disconnected.
  989. * Any data associated with the disconnect indication can be found using
  990. * fields rxBuff and rxLen for the data pointer and length respectively.
  991. *
  992. * LEVENT_DATA_IND - Data has been received. The received data is accessed
  993. * using fields rxBuff and rxLen;
  994. *
  995. * LEVENT_PACKET_HANDLED - A packet is being returned. A pointer to the
  996. * packet exists in field packet.
  997. *
  998. * LEVENT_LAP_CON_IND - Indicates that the IrLAP connection has come up. The
  999. * callback of all bound IrConnect structures is called.
  1000. *
  1001. * LEVENT_LAP_DISCON_IND - Indicates that the IrLAP connection has gone
  1002. * down. This means that all IrLMP connections are also down. A callback
  1003. * with event LEVENT_LM_CON_IND will not be given. The callback function
  1004. * of all bound IrConnect structures is called.
  1005. *
  1006. * LEVENT_DISCOVERY_CNF - Indicates the completion of a discovery operation.
  1007. * The field deviceList points to the discovery list.
  1008. *
  1009. * LEVENT_LAP_CON_CNF - The requested IrLAP connection has been made
  1010. * successfully. The callback function of all bound IrConnect structures
  1011. * is called.
  1012. *
  1013. * LEVENT_LM_CON_CNF - The requested IrLMP/Tiny TP connection has been made
  1014. * successfully. Connection data from the other side is found using fields
  1015. * rxBuff and rxLen.
  1016. *
  1017. * LEVENT_STATUS_IND - Indicates that a status event from the stack has
  1018. * occured. The status field indicates the status generating the event.
  1019. * Possible statuses are as follows. Note this event is optional:
  1020. * IR_STATUS_NO_PROGRESS - means that IrLAP has no progress for 3 seconds
  1021. * threshold time (e.g. beam is blocked).
  1022. *
  1023. * IR_STATUS_LINK_OK - indicates that the no progress condition has
  1024. * cleared.
  1025. *
  1026. * IR_STATUS_MEDIA_NOT_BUSY - indicates that the IR media has
  1027. * transitioned from busy to not busy.
  1028. *
  1029. * LEVENT_TEST_IND - Indicates that a TEST command frame has been received.
  1030. * A pointer to the received data is in rxBuff and rxLen. A pointer to the
  1031. * packet that will be sent in response to the test command is in the packet
  1032. * field. The packet is currently setup to respond with the same data sent
  1033. * in the command TEST frame. If different data is desired as a response
  1034. * then modify the packet structure. This event is sent to the callback
  1035. * function in all bound IrConnect structures. The IAS connections ignore
  1036. * this event.
  1037. *
  1038. * LEVENT_TEST_CNF - Indicates that a TEST command has completed. The status
  1039. * field indicates if the test was successful. IR_STATUS_SUCCESS indicates
  1040. * that operation was successful and the data in the test response can be
  1041. * found by using the rxBuff and rxLen fields. IR_STATUS_FAILED indicates
  1042. * that no TEST response was received. The packet passed to perform the test
  1043. * command is passed back in the packet field and is now available (no
  1044. * separate packet handled event will occur).
  1045. *)
  1046. (* The following functions are used to extract U16 and U32 bit numbers
  1047. * from an IAS result. Only IasGetU16 is used internal by the stack
  1048. * but they are part of some of the IAS Query result macros. To enable
  1049. * the function versions define IR_IAS_GET_AS_FUNC
  1050. *)
  1051. (*---------------------------------------------------------------------------
  1052. *
  1053. * Prototype: IrStatus IrIAS_Add(UInt16 refNum,IrIasObject* obj)
  1054. *
  1055. * Description: Add an IAS Object to the IAS Database. The Object is
  1056. * is not copied so the memory for the object must exist
  1057. * for as long as the object is in the data base. The
  1058. * IAS database is designed to only allow objects with unique
  1059. * class names. The error checking version checks for this.
  1060. * Class names and attributes names must not exceed
  1061. * IR_MAX_IAS_NAME. Also attribute values must not exceed
  1062. * IR_MAX_IAS_ATTR_SIZE.
  1063. *
  1064. * Parameters: refNum - ir library reference number
  1065. *
  1066. * obj - pointer to an IrIasObject structure.
  1067. *
  1068. * Return Values: IR_STATUS_SUCCESS - operation is successful.
  1069. *
  1070. * IR_STATUS_FAILED - operation failed for one of the
  1071. * following reasons:
  1072. * - No space in the data base (see irconfig.h to
  1073. * increase the size of the IAS database).
  1074. * - An entry with the same class name already exists.
  1075. * Error check only.
  1076. * - The attributes of the object violate the IrDA Lite
  1077. * rules (attribute name exceeds IR_MAX_IAS_NAME or
  1078. * attribute value exceeds IR_MAX_IAS_ATTR_SIZE).
  1079. * Error check only.
  1080. * - The class name exceeds IR_MAX_IAS_NAME. Error check
  1081. * only
  1082. *)
  1083. function IrIAS_Add(refNum: UInt16; var obj: IrIasObject): IrStatus; syscall irLibTrapIAS_Add;
  1084. (*---------------------------------------------------------------------------
  1085. *
  1086. * Prototype: IrStatus IrIAS_Query(UInt16 refNum,IrIasQuery* token)
  1087. *
  1088. * Description: Make an IAS query of another devices IAS database. An IrLAP
  1089. * connection must exist to the other device. The IAS query
  1090. * token must be initialized as described below. The result is
  1091. * signaled by calling the callback function whose pointer
  1092. * exists in the IrIasQuery structure. Only one Query can be
  1093. * made at a time.
  1094. *
  1095. * Parameters: refNum - ir library reference number
  1096. *
  1097. * token - pointer to an IrIasQuery structure initialized
  1098. * as follows:
  1099. * - pointer to a callback function in which the result will
  1100. * signaled.
  1101. * - result points to a buffer large enough to hold the
  1102. * result of the query.
  1103. * - resultBufSize is set to the size of the result buffer.
  1104. * - queryBuf must point to a valid query.
  1105. * - queryLen is set to the number of bytes in queryBuf.
  1106. * The length must not exceed IR_MAX_QUERY_LEN.
  1107. *
  1108. * Return Values: IR_STATUS_PENDING - operation is started successfully and
  1109. * the result will be signaled via the calback function.
  1110. *
  1111. * IR_STATUS_FAILED - operation failed for one of the
  1112. * following reasons (Error check only):
  1113. * - The query exceeds IR_MAX_QUERY_LEN.
  1114. * - The result field of token is 0.
  1115. * - The resultBuffSize field of token is 0.
  1116. * - The callback field of token is 0.
  1117. * - A query is already in progress.
  1118. *
  1119. * IR_STATUS_NO_IRLAP - operation failed because there is no
  1120. * IrLAP connection.
  1121. *)
  1122. function IrIAS_Query(refNum: UInt16; var token: IrIasQuery): IrStatus; syscall irLibTrapIAS_Query;
  1123. (*---------------------------------------------------------------------------
  1124. *
  1125. * Prototype: IrStatus IrIAS_SetDeviceName(UInt16 refNum,UInt8 *name, UInt8 len)
  1126. *
  1127. * Description: Set the value field of the device name attribute of the
  1128. * "Device" object in the IAS Database. This function is only
  1129. * available if IR_IAS_DEVICE_NAME is defined.
  1130. *
  1131. * Parameters: name - pointer to an IAS value field for the device name
  1132. * attribute of the device object. It includes the attribute
  1133. * type, character set and device name. This value field should
  1134. * be a constant and the pointer must remain valid until
  1135. * IRIAS_SetDeviceName() is called with another pointer.
  1136. *
  1137. * len - total length of the value field. Maximum size allowed
  1138. * is IR_MAX_IAS_ATTR_SIZE.
  1139. *
  1140. * Return Values: IR_STATUS_SUCCESS - operation is successful.
  1141. *
  1142. * IR_STATUS_FAILED - len is too big or the value field is not
  1143. * a valid user string (Error Checking only).
  1144. *)
  1145. function IrIAS_SetDeviceName(refNum: UInt16; var name: UInt8; len: UInt8): IrStatus; syscall irLibTrapIAS_SetDeviceName;
  1146. (*---------------------------------------------------------------------------
  1147. *
  1148. * Below are some functions and macros for parsing the results buffer
  1149. * after a successfull IAS Query.
  1150. *)
  1151. (*---------------------------------------------------------------------------
  1152. *
  1153. * Prototype: void IrIAS_StartResult(IrIasQuery* token)
  1154. *
  1155. * Description: Put the internal pointer to the start of the
  1156. * result buffer.
  1157. *
  1158. * Parameters: token - pointer to an IrIasQuery structure
  1159. *
  1160. * Return Values: void
  1161. *)
  1162. // IrIAS_StartResult(t) ((t)->offset = 0)
  1163. (*---------------------------------------------------------------------------
  1164. *
  1165. * Prototype: U16 IRIAS_GetObjectID(IrIasQuery* token)
  1166. *
  1167. * Description: Return the unique object ID of the current result item.
  1168. *
  1169. * Parameters: token - pointer to an IrIasQuery structure
  1170. *
  1171. * Return Values: object ID
  1172. *)
  1173. // IrIAS_GetObjectID(t) IasGetU16((t)->result + (t)->offset)
  1174. (*---------------------------------------------------------------------------
  1175. *
  1176. * Prototype: U8 IrIAS_GetType(IrIasQuery* token)
  1177. *
  1178. * Description: Return the type of the current result item
  1179. *
  1180. * Parameters: token - pointer to an IrIasQuery structure
  1181. *
  1182. * Return Values: Type of result item such as IAS_ATTRIB_INTEGER,
  1183. * IAS_ATTRIB_OCTET_STRING or IAS_ATTRIB_USER_STRING.
  1184. *)
  1185. // IrIAS_GetType(t) ((t)->result[(t)->offset + 2])
  1186. (*---------------------------------------------------------------------------
  1187. *
  1188. * Prototype: U32 IrIAS_GetInteger(IrIasQuery* token)
  1189. *
  1190. * Description: Return an integer value assuming that the current result
  1191. * item is of type IAS_ATTRIB_INTEGER (call IRIAS_GetType() to
  1192. * determine the type of the current result item).
  1193. *
  1194. * Parameters: token - pointer to an IrIasQuery structure
  1195. *
  1196. * Return Values: Integer value.
  1197. *)
  1198. // IrIAS_GetInteger(t) IasGetU32((t)->result + (t)->offset + 3)
  1199. (*---------------------------------------------------------------------------
  1200. *
  1201. * Prototype: U8 IrIAS_GetIntLsap(IrIasQuery* token)
  1202. *
  1203. * Description: Return an integer value that represents an LSAP assuming
  1204. * that the current result item is of type IAS_ATTRIB_INTEGER
  1205. * (call IRIAS_GetType() to determine the type of the current
  1206. * result item). Usually integer values returned in a query
  1207. * are LSAP selectors.
  1208. *
  1209. * Parameters: token - pointer to an IrIasQuery structure
  1210. *
  1211. * Return Values: Integer value.
  1212. *)
  1213. // IrIAS_GetIntLsap(t) ((t)->result[(t)->offset + 6])
  1214. (*---------------------------------------------------------------------------
  1215. *
  1216. * Prototype: U16 IrIAS_GetOctetStringLen(IrIasQuery* token)
  1217. *
  1218. * Description: Get the length of an octet string assuming that the current
  1219. * result item is of type IAS_ATTRIB_OCTET_STRING (call
  1220. * IRIAS_GetType() to determine the type of the current result
  1221. * item).
  1222. *
  1223. * Parameters: token - pointer to an IrIasQuery structure
  1224. *
  1225. * Return Values: Length of octet string
  1226. *)
  1227. // IrIAS_GetOctetStringLen(t) IasGetU16((t)->result + (t)->offset + 3)
  1228. (*---------------------------------------------------------------------------
  1229. *
  1230. * Prototype: U8* IrIAS_GetOctetString(IrIasQuery* token)
  1231. *
  1232. * Description: Return a pointer to an octet string assuming that the
  1233. * current result item is of type IAS_ATTRIB_OCTET_STRING (call
  1234. * IRIAS_GetType() to determine the type of the current result
  1235. * item).
  1236. *
  1237. * Parameters: token - pointer to an IrIasQuery structure
  1238. *
  1239. * Return Values: pointer to octet string
  1240. *)
  1241. // IrIAS_GetOctetString(t) ((t)->result + (t)->offset + 5)
  1242. (*---------------------------------------------------------------------------
  1243. *
  1244. * Prototype: U8 IrIAS_GetUserStringLen(IrIasQuery* token)
  1245. *
  1246. * Description: Return the length of a user string assuming that the
  1247. * current result item is of type IAS_ATTRIB_USER_STRING (call
  1248. * IRIAS_GetType() to determine the type of the current result
  1249. * item).
  1250. *
  1251. * Parameters: token - pointer to an IrIasQuery structure
  1252. *
  1253. * Return Values: Length of user string
  1254. *)
  1255. // IrIAS_GetUserStringLen(t) ((t)->result[(t)->offset + 4])
  1256. (*---------------------------------------------------------------------------
  1257. *
  1258. * Prototype: IrCharSet IrIAS_GetUserStringCharSet(IrIasQuery* token)
  1259. *
  1260. * Description: Return the character set of the user string assuming that
  1261. * the current result item is of type IAS_ATTRIB_USER_STRING
  1262. * (call IRIAS_GetType() to determine the type of the current
  1263. * result item).
  1264. *
  1265. * Parameters: token - pointer to an IrIasQuery structure
  1266. *
  1267. * Return Values: Character set
  1268. *)
  1269. // IrIAS_GetUserStringCharSet(t) ((t)->result[(t)->offset + 3])
  1270. (*---------------------------------------------------------------------------
  1271. *
  1272. * Prototype: U8* IrIAS_GetUserString(IrIasQuery* token)
  1273. *
  1274. * Description: Return a pointer to a user string assuming that the
  1275. * current result item is of type IAS_ATTRIB_USER_STRING (call
  1276. * IRIAS_GetType() to determine the type of the current result
  1277. * item).
  1278. *
  1279. * Parameters: token - pointer to an IrIasQuery structure
  1280. *
  1281. * Return Values: Pointer to result string
  1282. *)
  1283. // IrIAS_GetUserString(t) ((t)->result + (t)->offset + 5)
  1284. (*---------------------------------------------------------------------------
  1285. *
  1286. * Prototype: UInt8 *IrIAS_Next(UInt16 refNum,IrIasQuery* token)
  1287. *
  1288. * Description: Move the internal pointer to the next result item. This
  1289. * function returns a pointer to the start of the next result
  1290. * item. If the poiinter is 0 then there are no more result
  1291. * items. Only available if IR_IAS_NEXT is defined.
  1292. *
  1293. * Parameters: refNum - library reference number
  1294. *
  1295. * token - pointer to an IrIasQuery structure
  1296. *
  1297. * Return Values: Pointer to the next result item or 0 if no more items.
  1298. *)
  1299. function IrIAS_Next(refNum: UInt16; var token: IrIasQuery): UInt8Ptr; syscall irLibTrapIAS_Next;
  1300. (****************************************************************************
  1301. *
  1302. * IAS Callback Reference
  1303. *
  1304. ****************************************************************************)
  1305. (*---------------------------------------------------------------------------
  1306. *
  1307. * The result of IAS query is signaled by calling the callback function
  1308. * pointed to by the callBack field of IrIasQuery structure. The callback
  1309. * has the following prototype:
  1310. *
  1311. * void callBack(IrStatus);
  1312. *
  1313. * The callback is called with a status as follows:
  1314. *
  1315. * IR_STATUS_SUCCESS - the query operation finished successfully and
  1316. * the results can be parsed
  1317. *
  1318. * IR_STATUS_DISCONNECT - the link or IrLMP connection was disconnected
  1319. * during the query so the results are not valid.
  1320. =========================================================================== *)
  1321. // The following two functions are only for advances uses - do not use these.
  1322. (*---------------------------------------------------------------------------
  1323. *
  1324. * Prototype: IrHandleEvent(UInt16 refnum)
  1325. *
  1326. * Description: MemHandle background task event (ony used for special cases)
  1327. * Normally you will not use this function
  1328. *
  1329. * Parameters: refNum - library reference number
  1330. **
  1331. * Return Values: Pointer to the next result item or 0 if no more items.
  1332. *)
  1333. function IrHandleEvent(refnum: UInt16): Boolean; syscall irLibTrapHandleEvent;
  1334. (*---------------------------------------------------------------------------
  1335. *
  1336. * Prototype: IrWaitForEvent(UInt16 libRefnum,Int32 timeout)
  1337. *
  1338. * Description: Wait for background task event (ony used for special cases)
  1339. * Normally you will not use this function
  1340. *
  1341. * Parameters: refNum - library reference number
  1342. *
  1343. * timeout - number of ticks to wait
  1344. *
  1345. * Return Values: Pointer to the next result item or 0 if no more items.
  1346. *)
  1347. function IrWaitForEvent(libRefnum: UInt16; timeout: Int32): Err; syscall irLibTrapWaitForEvent;
  1348. implementation
  1349. end.